2001-03-16 Simon Josefsson <simon@josefsson.org>
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-group)
33 (require 'gnus-spec)
34 (require 'gnus-range)
35 (require 'gnus-int)
36 (require 'gnus-undo)
37 (require 'gnus-util)
38 (require 'mm-decode)
39 ;; Recursive :-(.
40 ;; (require 'gnus-art)
41 (require 'nnoo)
42 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
43 (autoload 'gnus-cache-write-active "gnus-cache")
44 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
45 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
46 (autoload 'mm-uu-dissect "mm-uu")
47
48 (defcustom gnus-kill-summary-on-exit t
49   "*If non-nil, kill the summary buffer when you exit from it.
50 If nil, the summary will become a \"*Dead Summary*\" buffer, and
51 it will be killed sometime later."
52   :group 'gnus-summary-exit
53   :type 'boolean)
54
55 (defcustom gnus-fetch-old-headers nil
56   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
57 If an unread article in the group refers to an older, already read (or
58 just marked as read) article, the old article will not normally be
59 displayed in the Summary buffer.  If this variable is non-nil, Gnus
60 will attempt to grab the headers to the old articles, and thereby
61 build complete threads.  If it has the value `some', only enough
62 headers to connect otherwise loose threads will be displayed.  This
63 variable can also be a number.  In that case, no more than that number
64 of old headers will be fetched.  If it has the value `invisible', all
65 old headers will be fetched, but none will be displayed.
66
67 The server has to support NOV for any of this to work."
68   :group 'gnus-thread
69   :type '(choice (const :tag "off" nil)
70                  (const some)
71                  number
72                  (sexp :menu-tag "other" t)))
73
74 (defcustom gnus-refer-thread-limit 200
75   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
76 If t, fetch all the available old headers."
77   :group 'gnus-thread
78   :type '(choice number
79                  (sexp :menu-tag "other" t)))
80
81 (defcustom gnus-summary-make-false-root 'adopt
82   "*nil means that Gnus won't gather loose threads.
83 If the root of a thread has expired or been read in a previous
84 session, the information necessary to build a complete thread has been
85 lost.  Instead of having many small sub-threads from this original thread
86 scattered all over the summary buffer, Gnus can gather them.
87
88 If non-nil, Gnus will try to gather all loose sub-threads from an
89 original thread into one large thread.
90
91 If this variable is non-nil, it should be one of `none', `adopt',
92 `dummy' or `empty'.
93
94 If this variable is `none', Gnus will not make a false root, but just
95 present the sub-threads after another.
96 If this variable is `dummy', Gnus will create a dummy root that will
97 have all the sub-threads as children.
98 If this variable is `adopt', Gnus will make one of the \"children\"
99 the parent and mark all the step-children as such.
100 If this variable is `empty', the \"children\" are printed with empty
101 subject fields.  (Or rather, they will be printed with a string
102 given by the `gnus-summary-same-subject' variable.)"
103   :group 'gnus-thread
104   :type '(choice (const :tag "off" nil)
105                  (const none)
106                  (const dummy)
107                  (const adopt)
108                  (const empty)))
109
110 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
111   "*A regexp to match subjects to be excluded from loose thread gathering.
112 As loose thread gathering is done on subjects only, that means that
113 there can be many false gatherings performed.  By rooting out certain
114 common subjects, gathering might become saner."
115   :group 'gnus-thread
116   :type 'regexp)
117
118 (defcustom gnus-summary-gather-subject-limit nil
119   "*Maximum length of subject comparisons when gathering loose threads.
120 Use nil to compare full subjects.  Setting this variable to a low
121 number will help gather threads that have been corrupted by
122 newsreaders chopping off subject lines, but it might also mean that
123 unrelated articles that have subject that happen to begin with the
124 same few characters will be incorrectly gathered.
125
126 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
127 comparing subjects."
128   :group 'gnus-thread
129   :type '(choice (const :tag "off" nil)
130                  (const fuzzy)
131                  (sexp :menu-tag "on" t)))
132
133 (defcustom gnus-simplify-subject-functions nil
134   "List of functions taking a string argument that simplify subjects.
135 The functions are applied recursively.
136
137 Useful functions to put in this list include: `gnus-simplify-subject-re',
138 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
139   :group 'gnus-thread
140   :type '(repeat function))
141
142 (defcustom gnus-simplify-ignored-prefixes nil
143   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  regexp))
147
148 (defcustom gnus-build-sparse-threads nil
149   "*If non-nil, fill in the gaps in threads.
150 If `some', only fill in the gaps that are needed to tie loose threads
151 together.  If `more', fill in all leaf nodes that Gnus can find.  If
152 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const some)
156                  (const more)
157                  (sexp :menu-tag "all" t)))
158
159 (defcustom gnus-summary-thread-gathering-function
160   'gnus-gather-threads-by-subject
161   "*Function used for gathering loose threads.
162 There are two pre-defined functions: `gnus-gather-threads-by-subject',
163 which only takes Subjects into consideration; and
164 `gnus-gather-threads-by-references', which compared the References
165 headers of the articles to find matches."
166   :group 'gnus-thread
167   :type '(radio (function-item gnus-gather-threads-by-subject)
168                 (function-item gnus-gather-threads-by-references)
169                 (function :tag "other")))
170
171 (defcustom gnus-summary-same-subject ""
172   "*String indicating that the current article has the same subject as the previous.
173 This variable will only be used if the value of
174 `gnus-summary-make-false-root' is `empty'."
175   :group 'gnus-summary-format
176   :type 'string)
177
178 (defcustom gnus-summary-goto-unread t
179   "*If t, many commands will go to the next unread article.
180 This applies to marking commands as well as other commands that
181 \"naturally\" select the next article, like, for instance, `SPC' at
182 the end of an article.
183
184 If nil, the marking commands do NOT go to the next unread article
185 (they go to the next article instead).  If `never', commands that
186 usually go to the next unread article, will go to the next article,
187 whether it is read or not."
188   :group 'gnus-summary-marks
189   :link '(custom-manual "(gnus)Setting Marks")
190   :type '(choice (const :tag "off" nil)
191                  (const never)
192                  (sexp :menu-tag "on" t)))
193
194 (defcustom gnus-summary-default-score 0
195   "*Default article score level.
196 All scores generated by the score files will be added to this score.
197 If this variable is nil, scoring will be disabled."
198   :group 'gnus-score-default
199   :type '(choice (const :tag "disable")
200                  integer))
201
202 (defcustom gnus-summary-zcore-fuzz 0
203   "*Fuzziness factor for the zcore in the summary buffer.
204 Articles with scores closer than this to `gnus-summary-default-score'
205 will not be marked."
206   :group 'gnus-summary-format
207   :type 'integer)
208
209 (defcustom gnus-simplify-subject-fuzzy-regexp nil
210   "*Strings to be removed when doing fuzzy matches.
211 This can either be a regular expression or list of regular expressions
212 that will be removed from subject strings if fuzzy subject
213 simplification is selected."
214   :group 'gnus-thread
215   :type '(repeat regexp))
216
217 (defcustom gnus-show-threads t
218   "*If non-nil, display threads in summary mode."
219   :group 'gnus-thread
220   :type 'boolean)
221
222 (defcustom gnus-thread-hide-subtree nil
223   "*If non-nil, hide all threads initially.
224 If threads are hidden, you have to run the command
225 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
226 to expose hidden threads."
227   :group 'gnus-thread
228   :type 'boolean)
229
230 (defcustom gnus-thread-hide-killed t
231   "*If non-nil, hide killed threads automatically."
232   :group 'gnus-thread
233   :type 'boolean)
234
235 (defcustom gnus-thread-ignore-subject t
236   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
237 If nil, articles that have different subjects from their parents will
238 start separate threads."
239   :group 'gnus-thread
240   :type 'boolean)
241
242 (defcustom gnus-thread-operation-ignore-subject t
243   "*If non-nil, subjects will be ignored when doing thread commands.
244 This affects commands like `gnus-summary-kill-thread' and
245 `gnus-summary-lower-thread'.
246
247 If this variable is nil, articles in the same thread with different
248 subjects will not be included in the operation in question.  If this
249 variable is `fuzzy', only articles that have subjects that are fuzzily
250 equal will be included."
251   :group 'gnus-thread
252   :type '(choice (const :tag "off" nil)
253                  (const fuzzy)
254                  (sexp :tag "on" t)))
255
256 (defcustom gnus-thread-indent-level 4
257   "*Number that says how much each sub-thread should be indented."
258   :group 'gnus-thread
259   :type 'integer)
260
261 (defcustom gnus-auto-extend-newsgroup t
262   "*If non-nil, extend newsgroup forward and backward when requested."
263   :group 'gnus-summary-choose
264   :type 'boolean)
265
266 (defcustom gnus-auto-select-first t
267   "*If nil, don't select the first unread article when entering a group.
268 If this variable is `best', select the highest-scored unread article
269 in the group.  If t, select the first unread article.
270
271 This variable can also be a function to place point on a likely
272 subject line.  Useful values include `gnus-summary-first-unread-subject',
273 `gnus-summary-first-unread-article' and
274 `gnus-summary-best-unread-article'.
275
276 If you want to prevent automatic selection of the first unread article
277 in some newsgroups, set the variable to nil in
278 `gnus-select-group-hook'."
279   :group 'gnus-group-select
280   :type '(choice (const :tag "none" nil)
281                  (const best)
282                  (sexp :menu-tag "first" t)
283                  (function-item gnus-summary-first-unread-subject)
284                  (function-item gnus-summary-first-unread-article)
285                  (function-item gnus-summary-best-unread-article)))
286
287 (defcustom gnus-auto-select-next t
288   "*If non-nil, offer to go to the next group from the end of the previous.
289 If the value is t and the next newsgroup is empty, Gnus will exit
290 summary mode and go back to group mode.  If the value is neither nil
291 nor t, Gnus will select the following unread newsgroup.  In
292 particular, if the value is the symbol `quietly', the next unread
293 newsgroup will be selected without any confirmation, and if it is
294 `almost-quietly', the next group will be selected without any
295 confirmation if you are located on the last article in the group.
296 Finally, if this variable is `slightly-quietly', the `Z n' command
297 will go to the next group without confirmation."
298   :group 'gnus-summary-maneuvering
299   :type '(choice (const :tag "off" nil)
300                  (const quietly)
301                  (const almost-quietly)
302                  (const slightly-quietly)
303                  (sexp :menu-tag "on" t)))
304
305 (defcustom gnus-auto-select-same nil
306   "*If non-nil, select the next article with the same subject.
307 If there are no more articles with the same subject, go to
308 the first unread article."
309   :group 'gnus-summary-maneuvering
310   :type 'boolean)
311
312 (defcustom gnus-summary-check-current nil
313   "*If non-nil, consider the current article when moving.
314 The \"unread\" movement commands will stay on the same line if the
315 current article is unread."
316   :group 'gnus-summary-maneuvering
317   :type 'boolean)
318
319 (defcustom gnus-auto-center-summary t
320   "*If non-nil, always center the current summary buffer.
321 In particular, if `vertical' do only vertical recentering.  If non-nil
322 and non-`vertical', do both horizontal and vertical recentering."
323   :group 'gnus-summary-maneuvering
324   :type '(choice (const :tag "none" nil)
325                  (const vertical)
326                  (integer :tag "height")
327                  (sexp :menu-tag "both" t)))
328
329 (defcustom gnus-show-all-headers nil
330   "*If non-nil, don't hide any headers."
331   :group 'gnus-article-hiding
332   :group 'gnus-article-headers
333   :type 'boolean)
334
335 (defcustom gnus-summary-ignore-duplicates nil
336   "*If non-nil, ignore articles with identical Message-ID headers."
337   :group 'gnus-summary
338   :type 'boolean)
339
340 (defcustom gnus-single-article-buffer t
341   "*If non-nil, display all articles in the same buffer.
342 If nil, each group will get its own article buffer."
343   :group 'gnus-article-various
344   :type 'boolean)
345
346 (defcustom gnus-break-pages t
347   "*If non-nil, do page breaking on articles.
348 The page delimiter is specified by the `gnus-page-delimiter'
349 variable."
350   :group 'gnus-article-various
351   :type 'boolean)
352
353 (defcustom gnus-move-split-methods nil
354   "*Variable used to suggest where articles are to be moved to.
355 It uses the same syntax as the `gnus-split-methods' variable.
356 However, whereas `gnus-split-methods' specifies file names as targets,
357 this variable specifies group names."
358   :group 'gnus-summary-mail
359   :type '(repeat (choice (list :value (fun) function)
360                          (cons :value ("" "") regexp (repeat string))
361                          (sexp :value nil))))
362
363 (defcustom gnus-unread-mark ?  ;Whitespace
364   "*Mark used for unread articles."
365   :group 'gnus-summary-marks
366   :type 'character)
367
368 (defcustom gnus-ticked-mark ?!
369   "*Mark used for ticked articles."
370   :group 'gnus-summary-marks
371   :type 'character)
372
373 (defcustom gnus-dormant-mark ??
374   "*Mark used for dormant articles."
375   :group 'gnus-summary-marks
376   :type 'character)
377
378 (defcustom gnus-del-mark ?r
379   "*Mark used for del'd articles."
380   :group 'gnus-summary-marks
381   :type 'character)
382
383 (defcustom gnus-read-mark ?R
384   "*Mark used for read articles."
385   :group 'gnus-summary-marks
386   :type 'character)
387
388 (defcustom gnus-expirable-mark ?E
389   "*Mark used for expirable articles."
390   :group 'gnus-summary-marks
391   :type 'character)
392
393 (defcustom gnus-killed-mark ?K
394   "*Mark used for killed articles."
395   :group 'gnus-summary-marks
396   :type 'character)
397
398 (defcustom gnus-souped-mark ?F
399   "*Mark used for killed articles."
400   :group 'gnus-summary-marks
401   :type 'character)
402
403 (defcustom gnus-kill-file-mark ?X
404   "*Mark used for articles killed by kill files."
405   :group 'gnus-summary-marks
406   :type 'character)
407
408 (defcustom gnus-low-score-mark ?Y
409   "*Mark used for articles with a low score."
410   :group 'gnus-summary-marks
411   :type 'character)
412
413 (defcustom gnus-catchup-mark ?C
414   "*Mark used for articles that are caught up."
415   :group 'gnus-summary-marks
416   :type 'character)
417
418 (defcustom gnus-replied-mark ?A
419   "*Mark used for articles that have been replied to."
420   :group 'gnus-summary-marks
421   :type 'character)
422
423 (defcustom gnus-cached-mark ?*
424   "*Mark used for articles that are in the cache."
425   :group 'gnus-summary-marks
426   :type 'character)
427
428 (defcustom gnus-saved-mark ?S
429   "*Mark used for articles that have been saved to."
430   :group 'gnus-summary-marks
431   :type 'character)
432
433 (defcustom gnus-no-mark ?  ;Whitespace
434   "*Mark used for articles that have no other secondary mark."
435   :group 'gnus-summary-marks
436   :type 'character)
437
438 (defcustom gnus-ancient-mark ?O
439   "*Mark used for ancient articles."
440   :group 'gnus-summary-marks
441   :type 'character)
442
443 (defcustom gnus-sparse-mark ?Q
444   "*Mark used for sparsely reffed articles."
445   :group 'gnus-summary-marks
446   :type 'character)
447
448 (defcustom gnus-canceled-mark ?G
449   "*Mark used for canceled articles."
450   :group 'gnus-summary-marks
451   :type 'character)
452
453 (defcustom gnus-duplicate-mark ?M
454   "*Mark used for duplicate articles."
455   :group 'gnus-summary-marks
456   :type 'character)
457
458 (defcustom gnus-undownloaded-mark ?@
459   "*Mark used for articles that weren't downloaded."
460   :group 'gnus-summary-marks
461   :type 'character)
462
463 (defcustom gnus-downloadable-mark ?%
464   "*Mark used for articles that are to be downloaded."
465   :group 'gnus-summary-marks
466   :type 'character)
467
468 (defcustom gnus-unsendable-mark ?=
469   "*Mark used for articles that won't be sent."
470   :group 'gnus-summary-marks
471   :type 'character)
472
473 (defcustom gnus-score-over-mark ?+
474   "*Score mark used for articles with high scores."
475   :group 'gnus-summary-marks
476   :type 'character)
477
478 (defcustom gnus-score-below-mark ?-
479   "*Score mark used for articles with low scores."
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-empty-thread-mark ?  ;Whitespace
484   "*There is no thread under the article."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-not-empty-thread-mark ?=
489   "*There is a thread under the article."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-view-pseudo-asynchronously nil
494   "*If non-nil, Gnus will view pseudo-articles asynchronously."
495   :group 'gnus-extract-view
496   :type 'boolean)
497
498 (defcustom gnus-auto-expirable-marks
499   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
500         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
501         gnus-souped-mark gnus-duplicate-mark)
502   "*The list of marks converted into expiration if a group is auto-expirable."
503   :version "21.1"
504   :group 'gnus-summary
505   :type '(repeat character))
506
507 (defcustom gnus-inhibit-user-auto-expire t
508   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
509   :version "21.1"
510   :group 'gnus-summary
511   :type 'boolean)
512
513 (defcustom gnus-view-pseudos nil
514   "*If `automatic', pseudo-articles will be viewed automatically.
515 If `not-confirm', pseudos will be viewed automatically, and the user
516 will not be asked to confirm the command."
517   :group 'gnus-extract-view
518   :type '(choice (const :tag "off" nil)
519                  (const automatic)
520                  (const not-confirm)))
521
522 (defcustom gnus-view-pseudos-separately t
523   "*If non-nil, one pseudo-article will be created for each file to be viewed.
524 If nil, all files that use the same viewing command will be given as a
525 list of parameters to that command."
526   :group 'gnus-extract-view
527   :type 'boolean)
528
529 (defcustom gnus-insert-pseudo-articles t
530   "*If non-nil, insert pseudo-articles when decoding articles."
531   :group 'gnus-extract-view
532   :type 'boolean)
533
534 (defcustom gnus-summary-dummy-line-format
535   "  %(:                          :%) %S\n"
536   "*The format specification for the dummy roots in the summary buffer.
537 It works along the same lines as a normal formatting string,
538 with some simple extensions.
539
540 %S  The subject"
541   :group 'gnus-threading
542   :type 'string)
543
544 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
545   "*The format specification for the summary mode line.
546 It works along the same lines as a normal formatting string,
547 with some simple extensions:
548
549 %G  Group name
550 %p  Unprefixed group name
551 %A  Current article number
552 %z  Current article score
553 %V  Gnus version
554 %U  Number of unread articles in the group
555 %e  Number of unselected articles in the group
556 %Z  A string with unread/unselected article counts
557 %g  Shortish group name
558 %S  Subject of the current article
559 %u  User-defined spec
560 %s  Current score file name
561 %d  Number of dormant articles
562 %r  Number of articles that have been marked as read in this session
563 %E  Number of articles expunged by the score files"
564   :group 'gnus-summary-format
565   :type 'string)
566
567 (defcustom gnus-list-identifiers nil
568   "Regexp that matches list identifiers to be removed from subject.
569 This can also be a list of regexps."
570   :version "21.1"
571   :group 'gnus-summary-format
572   :group 'gnus-article-hiding
573   :type '(choice (const :tag "none" nil)
574                  (regexp :value ".*")
575                  (repeat :value (".*") regexp)))
576
577 (defcustom gnus-summary-mark-below 0
578   "*Mark all articles with a score below this variable as read.
579 This variable is local to each summary buffer and usually set by the
580 score file."
581   :group 'gnus-score-default
582   :type 'integer)
583
584 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
585   "*List of functions used for sorting articles in the summary buffer.
586
587 Each function takes two articles and returns non-nil if the first
588 article should be sorted before the other.  If you use more than one
589 function, the primary sort function should be the last.  You should
590 probably always include `gnus-article-sort-by-number' in the list of
591 sorting functions -- preferably first.  Also note that sorting by date
592 is often much slower than sorting by number, and the sorting order is
593 very similar.  (Sorting by date means sorting by the time the message
594 was sent, sorting by number means sorting by arrival time.)
595
596 Ready-made functions include `gnus-article-sort-by-number',
597 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
598 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
599
600 When threading is turned on, the variable `gnus-thread-sort-functions'
601 controls how articles are sorted."
602   :group 'gnus-summary-sort
603   :type '(repeat (choice (function-item gnus-article-sort-by-number)
604                          (function-item gnus-article-sort-by-author)
605                          (function-item gnus-article-sort-by-subject)
606                          (function-item gnus-article-sort-by-date)
607                          (function-item gnus-article-sort-by-score)
608                          (function :tag "other"))))
609
610 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
611   "*List of functions used for sorting threads in the summary buffer.
612 By default, threads are sorted by article number.
613
614 Each function takes two threads and returns non-nil if the first
615 thread should be sorted before the other.  If you use more than one
616 function, the primary sort function should be the last.  You should
617 probably always include `gnus-thread-sort-by-number' in the list of
618 sorting functions -- preferably first.  Also note that sorting by date
619 is often much slower than sorting by number, and the sorting order is
620 very similar.  (Sorting by date means sorting by the time the message
621 was sent, sorting by number means sorting by arrival time.)
622
623 Ready-made functions include `gnus-thread-sort-by-number',
624 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
625 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
626 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
627
628 When threading is turned off, the variable
629 `gnus-article-sort-functions' controls how articles are sorted."
630   :group 'gnus-summary-sort
631   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
632                          (function-item gnus-thread-sort-by-author)
633                          (function-item gnus-thread-sort-by-subject)
634                          (function-item gnus-thread-sort-by-date)
635                          (function-item gnus-thread-sort-by-score)
636                          (function-item gnus-thread-sort-by-total-score)
637                          (function :tag "other"))))
638
639 (defcustom gnus-thread-score-function '+
640   "*Function used for calculating the total score of a thread.
641
642 The function is called with the scores of the article and each
643 subthread and should then return the score of the thread.
644
645 Some functions you can use are `+', `max', or `min'."
646   :group 'gnus-summary-sort
647   :type 'function)
648
649 (defcustom gnus-summary-expunge-below nil
650   "All articles that have a score less than this variable will be expunged.
651 This variable is local to the summary buffers."
652   :group 'gnus-score-default
653   :type '(choice (const :tag "off" nil)
654                  integer))
655
656 (defcustom gnus-thread-expunge-below nil
657   "All threads that have a total score less than this variable will be expunged.
658 See `gnus-thread-score-function' for en explanation of what a
659 \"thread score\" is.
660
661 This variable is local to the summary buffers."
662   :group 'gnus-threading
663   :group 'gnus-score-default
664   :type '(choice (const :tag "off" nil)
665                  integer))
666
667 (defcustom gnus-summary-mode-hook nil
668   "*A hook for Gnus summary mode.
669 This hook is run before any variables are set in the summary buffer."
670   :options '(turn-on-gnus-mailing-list-mode)
671   :group 'gnus-summary-various
672   :type 'hook)
673
674 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
675 (when (featurep 'xemacs)
676   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
677   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
678   (add-hook 'gnus-summary-mode-hook
679             'gnus-xmas-switch-horizontal-scrollbar-off))
680
681 (defcustom gnus-summary-menu-hook nil
682   "*Hook run after the creation of the summary mode menu."
683   :group 'gnus-summary-visual
684   :type 'hook)
685
686 (defcustom gnus-summary-exit-hook nil
687   "*A hook called on exit from the summary buffer.
688 It will be called with point in the group buffer."
689   :group 'gnus-summary-exit
690   :type 'hook)
691
692 (defcustom gnus-summary-prepare-hook nil
693   "*A hook called after the summary buffer has been generated.
694 If you want to modify the summary buffer, you can use this hook."
695   :group 'gnus-summary-various
696   :type 'hook)
697
698 (defcustom gnus-summary-prepared-hook nil
699   "*A hook called as the last thing after the summary buffer has been generated."
700   :group 'gnus-summary-various
701   :type 'hook)
702
703 (defcustom gnus-summary-generate-hook nil
704   "*A hook run just before generating the summary buffer.
705 This hook is commonly used to customize threading variables and the
706 like."
707   :group 'gnus-summary-various
708   :type 'hook)
709
710 (defcustom gnus-select-group-hook nil
711   "*A hook called when a newsgroup is selected.
712
713 If you'd like to simplify subjects like the
714 `gnus-summary-next-same-subject' command does, you can use the
715 following hook:
716
717  (setq gnus-select-group-hook
718       (list
719         (lambda ()
720           (mapcar (lambda (header)
721                      (mail-header-set-subject
722                       header
723                       (gnus-simplify-subject
724                        (mail-header-subject header) 're-only)))
725                   gnus-newsgroup-headers))))"
726   :group 'gnus-group-select
727   :type 'hook)
728
729 (defcustom gnus-select-article-hook nil
730   "*A hook called when an article is selected."
731   :group 'gnus-summary-choose
732   :type 'hook)
733
734 (defcustom gnus-visual-mark-article-hook
735   (list 'gnus-highlight-selected-summary)
736   "*Hook run after selecting an article in the summary buffer.
737 It is meant to be used for highlighting the article in some way.  It
738 is not run if `gnus-visual' is nil."
739   :group 'gnus-summary-visual
740   :type 'hook)
741
742 (defcustom gnus-parse-headers-hook nil
743   "*A hook called before parsing the headers."
744   :group 'gnus-various
745   :type 'hook)
746
747 (defcustom gnus-exit-group-hook nil
748   "*A hook called when exiting summary mode.
749 This hook is not called from the non-updating exit commands like `Q'."
750   :group 'gnus-various
751   :type 'hook)
752
753 (defcustom gnus-summary-update-hook
754   (list 'gnus-summary-highlight-line)
755   "*A hook called when a summary line is changed.
756 The hook will not be called if `gnus-visual' is nil.
757
758 The default function `gnus-summary-highlight-line' will
759 highlight the line according to the `gnus-summary-highlight'
760 variable."
761   :group 'gnus-summary-visual
762   :type 'hook)
763
764 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
765   "*A hook called when an article is selected for the first time.
766 The hook is intended to mark an article as read (or unread)
767 automatically when it is selected."
768   :group 'gnus-summary-choose
769   :type 'hook)
770
771 (defcustom gnus-group-no-more-groups-hook nil
772   "*A hook run when returning to group mode having no more (unread) groups."
773   :group 'gnus-group-select
774   :type 'hook)
775
776 (defcustom gnus-ps-print-hook nil
777   "*A hook run before ps-printing something from Gnus."
778   :group 'gnus-summary
779   :type 'hook)
780
781 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
782   "Face used for highlighting the current article in the summary buffer."
783   :group 'gnus-summary-visual
784   :type 'face)
785
786 (defcustom gnus-summary-highlight
787   '(((= mark gnus-canceled-mark)
788      . gnus-summary-cancelled-face)
789     ((and (> score default)
790           (or (= mark gnus-dormant-mark)
791               (= mark gnus-ticked-mark)))
792      . gnus-summary-high-ticked-face)
793     ((and (< score default)
794           (or (= mark gnus-dormant-mark)
795               (= mark gnus-ticked-mark)))
796      . gnus-summary-low-ticked-face)
797     ((or (= mark gnus-dormant-mark)
798          (= mark gnus-ticked-mark))
799      . gnus-summary-normal-ticked-face)
800     ((and (> score default) (= mark gnus-ancient-mark))
801      . gnus-summary-high-ancient-face)
802     ((and (< score default) (= mark gnus-ancient-mark))
803      . gnus-summary-low-ancient-face)
804     ((= mark gnus-ancient-mark)
805      . gnus-summary-normal-ancient-face)
806     ((and (> score default) (= mark gnus-unread-mark))
807      . gnus-summary-high-unread-face)
808     ((and (< score default) (= mark gnus-unread-mark))
809      . gnus-summary-low-unread-face)
810     ((= mark gnus-unread-mark)
811      . gnus-summary-normal-unread-face)
812     ((and (> score default) (memq mark (list gnus-downloadable-mark
813                                              gnus-undownloaded-mark)))
814      . gnus-summary-high-unread-face)
815     ((and (< score default) (memq mark (list gnus-downloadable-mark
816                                              gnus-undownloaded-mark)))
817      . gnus-summary-low-unread-face)
818     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
819      . gnus-summary-normal-unread-face)
820     ((> score default)
821      . gnus-summary-high-read-face)
822     ((< score default)
823      . gnus-summary-low-read-face)
824     (t
825      . gnus-summary-normal-read-face))
826   "*Controls the highlighting of summary buffer lines.
827
828 A list of (FORM . FACE) pairs.  When deciding how a a particular
829 summary line should be displayed, each form is evaluated.  The content
830 of the face field after the first true form is used.  You can change
831 how those summary lines are displayed, by editing the face field.
832
833 You can use the following variables in the FORM field.
834
835 score:   The articles score
836 default: The default article score.
837 below:   The score below which articles are automatically marked as read.
838 mark:    The articles mark."
839   :group 'gnus-summary-visual
840   :type '(repeat (cons (sexp :tag "Form" nil)
841                        face)))
842
843 (defcustom gnus-alter-header-function nil
844   "Function called to allow alteration of article header structures.
845 The function is called with one parameter, the article header vector,
846 which it may alter in any way.")
847
848 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
849   "Variable that says which function should be used to decode a string with encoded words.")
850
851 (defcustom gnus-extra-headers nil
852   "*Extra headers to parse."
853   :version "21.1"
854   :group 'gnus-summary
855   :type '(repeat symbol))
856
857 (defcustom gnus-ignored-from-addresses
858   (and user-mail-address (regexp-quote user-mail-address))
859   "*Regexp of From headers that may be suppressed in favor of To headers."
860   :version "21.1"
861   :group 'gnus-summary
862   :type 'regexp)
863
864 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
865   "List of charsets that should be ignored.
866 When these charsets are used in the \"charset\" parameter, the
867 default charset will be used instead."
868   :version "21.1"
869   :type '(repeat symbol)
870   :group 'gnus-charset)
871
872 (gnus-define-group-parameter
873  ignored-charsets
874  :type list
875  :function-document
876  "Return the ignored charsets of GROUP."
877  :variable gnus-group-ignored-charsets-alist
878  :variable-default 
879  '(("alt\\.chinese\\.text" iso-8859-1))
880  :variable-document
881  "Alist of regexps (to match group names) and charsets that should be ignored.
882 When these charsets are used in the \"charset\" parameter, the
883 default charset will be used instead."
884  :variable-group gnus-charset
885  :variable-type '(repeat (cons (regexp :tag "Group")
886                                (repeat symbol)))
887  :parameter-type '(choice :tag "Ignored charsets" 
888                           :value nil
889                           (repeat (symbol)))
890  :parameter-document       "\
891 List of charsets that should be ignored.
892
893 When these charsets are used in the \"charset\" parameter, the
894 default charset will be used instead.")
895
896 (defcustom gnus-group-highlight-words-alist nil
897   "Alist of group regexps and highlight regexps.
898 This variable uses the same syntax as `gnus-emphasis-alist'."
899   :version "21.1"
900   :type '(repeat (cons (regexp :tag "Group")
901                        (repeat (list (regexp :tag "Highlight regexp")
902                                      (number :tag "Group for entire word" 0)
903                                      (number :tag "Group for displayed part" 0)
904                                      (symbol :tag "Face"
905                                              gnus-emphasis-highlight-words)))))
906   :group 'gnus-summary-visual)
907
908 (defcustom gnus-summary-show-article-charset-alist
909   nil
910   "Alist of number and charset.
911 The article will be shown with the charset corresponding to the
912 numbered argument.
913 For example: ((1 . cn-gb-2312) (2 . big5))."
914   :version "21.1"
915   :type '(repeat (cons (number :tag "Argument" 1)
916                        (symbol :tag "Charset")))
917   :group 'gnus-charset)
918
919 (defcustom gnus-preserve-marks t
920   "Whether marks are preserved when moving, copying and respooling messages."
921   :version "21.1"
922   :type 'boolean
923   :group 'gnus-summary-marks)
924
925 (defcustom gnus-alter-articles-to-read-function nil
926   "Function to be called to alter the list of articles to be selected."
927   :type '(choice (const nil) function)
928   :group 'gnus-summary)
929
930 (defcustom gnus-orphan-score nil
931   "*All orphans get this score added.  Set in the score file."
932   :group 'gnus-score-default
933   :type '(choice (const nil)
934                  integer))
935
936 (defcustom gnus-summary-save-parts-default-mime "image/.*"
937   "*A regexp to match MIME parts when saving multiple parts of a message
938 with gnus-summary-save-parts (X m). This regexp will be used by default
939 when prompting the user for which type of files to save."
940   :group 'gnus-summary
941   :type 'regexp)
942
943
944 (defcustom gnus-summary-save-parts-default-mime "image/.*"
945   "*A regexp to match MIME parts when saving multiple parts of a message
946 with gnus-summary-save-parts (X m). This regexp will be used by default
947 when prompting the user for which type of files to save."
948   :group 'gnus-summary
949   :type 'regexp)
950
951
952 ;;; Internal variables
953
954 (defvar gnus-article-mime-handles nil)
955 (defvar gnus-article-decoded-p nil)
956 (defvar gnus-article-charset nil)
957 (defvar gnus-article-ignored-charsets nil)
958 (defvar gnus-scores-exclude-files nil)
959 (defvar gnus-page-broken nil)
960 (defvar gnus-inhibit-mime-unbuttonizing nil)
961
962 (defvar gnus-original-article nil)
963 (defvar gnus-article-internal-prepare-hook nil)
964 (defvar gnus-newsgroup-process-stack nil)
965
966 (defvar gnus-thread-indent-array nil)
967 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
968 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
969   "Function called to sort the articles within a thread after it has been gathered together.")
970
971 (defvar gnus-summary-save-parts-type-history nil)
972 (defvar gnus-summary-save-parts-last-directory nil)
973
974 (defvar gnus-summary-save-parts-type-history nil)
975 (defvar gnus-summary-save-parts-last-directory nil)
976
977 ;; Avoid highlighting in kill files.
978 (defvar gnus-summary-inhibit-highlight nil)
979 (defvar gnus-newsgroup-selected-overlay nil)
980 (defvar gnus-inhibit-limiting nil)
981 (defvar gnus-newsgroup-adaptive-score-file nil)
982 (defvar gnus-current-score-file nil)
983 (defvar gnus-current-move-group nil)
984 (defvar gnus-current-copy-group nil)
985 (defvar gnus-current-crosspost-group nil)
986
987 (defvar gnus-newsgroup-dependencies nil)
988 (defvar gnus-newsgroup-adaptive nil)
989 (defvar gnus-summary-display-article-function nil)
990 (defvar gnus-summary-highlight-line-function nil
991   "Function called after highlighting a summary line.")
992
993 (defvar gnus-summary-line-format-alist
994   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
995     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
996     (?s gnus-tmp-subject-or-nil ?s)
997     (?n gnus-tmp-name ?s)
998     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
999         ?s)
1000     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1001             gnus-tmp-from) ?s)
1002     (?F gnus-tmp-from ?s)
1003     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1004     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1005     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1006     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1007     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1008     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1009     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1010     (?L gnus-tmp-lines ?d)
1011     (?I gnus-tmp-indentation ?s)
1012     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1013     (?R gnus-tmp-replied ?c)
1014     (?\[ gnus-tmp-opening-bracket ?c)
1015     (?\] gnus-tmp-closing-bracket ?c)
1016     (?\> (make-string gnus-tmp-level ? ) ?s)
1017     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1018     (?i gnus-tmp-score ?d)
1019     (?z gnus-tmp-score-char ?c)
1020     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1021     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1022     (?U gnus-tmp-unread ?c)
1023     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header) ?s)
1024     (?t (gnus-summary-number-of-articles-in-thread
1025          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1026         ?d)
1027     (?e (gnus-summary-number-of-articles-in-thread
1028          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1029         ?c)
1030     (?u gnus-tmp-user-defined ?s)
1031     (?P (gnus-pick-line-number) ?d))
1032   "An alist of format specifications that can appear in summary lines.
1033 These are paired with what variables they correspond with, along with
1034 the type of the variable (string, integer, character, etc).")
1035
1036 (defvar gnus-summary-dummy-line-format-alist
1037   `((?S gnus-tmp-subject ?s)
1038     (?N gnus-tmp-number ?d)
1039     (?u gnus-tmp-user-defined ?s)))
1040
1041 (defvar gnus-summary-mode-line-format-alist
1042   `((?G gnus-tmp-group-name ?s)
1043     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1044     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1045     (?A gnus-tmp-article-number ?d)
1046     (?Z gnus-tmp-unread-and-unselected ?s)
1047     (?V gnus-version ?s)
1048     (?U gnus-tmp-unread-and-unticked ?d)
1049     (?S gnus-tmp-subject ?s)
1050     (?e gnus-tmp-unselected ?d)
1051     (?u gnus-tmp-user-defined ?s)
1052     (?d (length gnus-newsgroup-dormant) ?d)
1053     (?t (length gnus-newsgroup-marked) ?d)
1054     (?r (length gnus-newsgroup-reads) ?d)
1055     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1056     (?E gnus-newsgroup-expunged-tally ?d)
1057     (?s (gnus-current-score-file-nondirectory) ?s)))
1058
1059 (defvar gnus-last-search-regexp nil
1060   "Default regexp for article search command.")
1061
1062 (defvar gnus-last-shell-command nil
1063   "Default shell command on article.")
1064
1065 (defvar gnus-newsgroup-begin nil)
1066 (defvar gnus-newsgroup-end nil)
1067 (defvar gnus-newsgroup-last-rmail nil)
1068 (defvar gnus-newsgroup-last-mail nil)
1069 (defvar gnus-newsgroup-last-folder nil)
1070 (defvar gnus-newsgroup-last-file nil)
1071 (defvar gnus-newsgroup-auto-expire nil)
1072 (defvar gnus-newsgroup-active nil)
1073
1074 (defvar gnus-newsgroup-data nil)
1075 (defvar gnus-newsgroup-data-reverse nil)
1076 (defvar gnus-newsgroup-limit nil)
1077 (defvar gnus-newsgroup-limits nil)
1078
1079 (defvar gnus-newsgroup-unreads nil
1080   "List of unread articles in the current newsgroup.")
1081
1082 (defvar gnus-newsgroup-unselected nil
1083   "List of unselected unread articles in the current newsgroup.")
1084
1085 (defvar gnus-newsgroup-reads nil
1086   "Alist of read articles and article marks in the current newsgroup.")
1087
1088 (defvar gnus-newsgroup-expunged-tally nil)
1089
1090 (defvar gnus-newsgroup-marked nil
1091   "List of ticked articles in the current newsgroup (a subset of unread art).")
1092
1093 (defvar gnus-newsgroup-killed nil
1094   "List of ranges of articles that have been through the scoring process.")
1095
1096 (defvar gnus-newsgroup-cached nil
1097   "List of articles that come from the article cache.")
1098
1099 (defvar gnus-newsgroup-saved nil
1100   "List of articles that have been saved.")
1101
1102 (defvar gnus-newsgroup-kill-headers nil)
1103
1104 (defvar gnus-newsgroup-replied nil
1105   "List of articles that have been replied to in the current newsgroup.")
1106
1107 (defvar gnus-newsgroup-expirable nil
1108   "List of articles in the current newsgroup that can be expired.")
1109
1110 (defvar gnus-newsgroup-processable nil
1111   "List of articles in the current newsgroup that can be processed.")
1112
1113 (defvar gnus-newsgroup-downloadable nil
1114   "List of articles in the current newsgroup that can be processed.")
1115
1116 (defvar gnus-newsgroup-undownloaded nil
1117   "List of articles in the current newsgroup that haven't been downloaded..")
1118
1119 (defvar gnus-newsgroup-unsendable nil
1120   "List of articles in the current newsgroup that won't be sent.")
1121
1122 (defvar gnus-newsgroup-bookmarks nil
1123   "List of articles in the current newsgroup that have bookmarks.")
1124
1125 (defvar gnus-newsgroup-dormant nil
1126   "List of dormant articles in the current newsgroup.")
1127
1128 (defvar gnus-newsgroup-scored nil
1129   "List of scored articles in the current newsgroup.")
1130
1131 (defvar gnus-newsgroup-headers nil
1132   "List of article headers in the current newsgroup.")
1133
1134 (defvar gnus-newsgroup-threads nil)
1135
1136 (defvar gnus-newsgroup-prepared nil
1137   "Whether the current group has been prepared properly.")
1138
1139 (defvar gnus-newsgroup-ancient nil
1140   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1141
1142 (defvar gnus-newsgroup-sparse nil)
1143
1144 (defvar gnus-current-article nil)
1145 (defvar gnus-article-current nil)
1146 (defvar gnus-current-headers nil)
1147 (defvar gnus-have-all-headers nil)
1148 (defvar gnus-last-article nil)
1149 (defvar gnus-newsgroup-history nil)
1150 (defvar gnus-newsgroup-charset nil)
1151 (defvar gnus-newsgroup-ephemeral-charset nil)
1152 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1153
1154 (defvar gnus-article-before-search nil)
1155
1156 (defconst gnus-summary-local-variables
1157   '(gnus-newsgroup-name
1158     gnus-newsgroup-begin gnus-newsgroup-end
1159     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1160     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1161     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1162     gnus-newsgroup-unselected gnus-newsgroup-marked
1163     gnus-newsgroup-reads gnus-newsgroup-saved
1164     gnus-newsgroup-replied gnus-newsgroup-expirable
1165     gnus-newsgroup-processable gnus-newsgroup-killed
1166     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1167     gnus-newsgroup-unsendable
1168     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1169     gnus-newsgroup-headers gnus-newsgroup-threads
1170     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1171     gnus-current-article gnus-current-headers gnus-have-all-headers
1172     gnus-last-article gnus-article-internal-prepare-hook
1173     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1174     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1175     gnus-thread-expunge-below
1176     gnus-score-alist gnus-current-score-file
1177     (gnus-summary-expunge-below . global)
1178     (gnus-summary-mark-below . global)
1179     (gnus-orphan-score . global)
1180     gnus-newsgroup-active gnus-scores-exclude-files
1181     gnus-newsgroup-history gnus-newsgroup-ancient
1182     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1183     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1184     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1185     (gnus-newsgroup-expunged-tally . 0)
1186     gnus-cache-removable-articles gnus-newsgroup-cached
1187     gnus-newsgroup-data gnus-newsgroup-data-reverse
1188     gnus-newsgroup-limit gnus-newsgroup-limits
1189     gnus-newsgroup-charset)
1190   "Variables that are buffer-local to the summary buffers.")
1191
1192 (defvar gnus-newsgroup-variables nil
1193   "Variables that have separate values in the newsgroups.")
1194
1195 ;; Byte-compiler warning.
1196 (eval-when-compile (defvar gnus-article-mode-map))
1197
1198 ;; MIME stuff.
1199
1200 (defvar gnus-decode-encoded-word-methods
1201   '(mail-decode-encoded-word-string)
1202   "List of methods used to decode encoded words.
1203
1204 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item is
1205 FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1206 (REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1207 whose names match REGEXP.
1208
1209 For example:
1210 ((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1211  mail-decode-encoded-word-string
1212  (\"chinese\" . rfc1843-decode-string))")
1213
1214 (defvar gnus-decode-encoded-word-methods-cache nil)
1215
1216 (defun gnus-multi-decode-encoded-word-string (string)
1217   "Apply the functions from `gnus-encoded-word-methods' that match."
1218   (unless (and gnus-decode-encoded-word-methods-cache
1219                (eq gnus-newsgroup-name
1220                    (car gnus-decode-encoded-word-methods-cache)))
1221     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1222     (mapcar (lambda (x)
1223               (if (symbolp x)
1224                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1225                 (if (and gnus-newsgroup-name
1226                          (string-match (car x) gnus-newsgroup-name))
1227                     (nconc gnus-decode-encoded-word-methods-cache
1228                            (list (cdr x))))))
1229           gnus-decode-encoded-word-methods))
1230   (let ((xlist gnus-decode-encoded-word-methods-cache))
1231     (pop xlist)
1232     (while xlist
1233       (setq string (funcall (pop xlist) string))))
1234   string)
1235
1236 ;; Subject simplification.
1237
1238 (defun gnus-simplify-whitespace (str)
1239   "Remove excessive whitespace from STR."
1240   (let ((mystr str))
1241     ;; Multiple spaces.
1242     (while (string-match "[ \t][ \t]+" mystr)
1243       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1244                           " "
1245                           (substring mystr (match-end 0)))))
1246     ;; Leading spaces.
1247     (when (string-match "^[ \t]+" mystr)
1248       (setq mystr (substring mystr (match-end 0))))
1249     ;; Trailing spaces.
1250     (when (string-match "[ \t]+$" mystr)
1251       (setq mystr (substring mystr 0 (match-beginning 0))))
1252     mystr))
1253
1254 (defsubst gnus-simplify-subject-re (subject)
1255   "Remove \"Re:\" from subject lines."
1256   (if (string-match message-subject-re-regexp subject)
1257       (substring subject (match-end 0))
1258     subject))
1259
1260 (defun gnus-simplify-subject (subject &optional re-only)
1261   "Remove `Re:' and words in parentheses.
1262 If RE-ONLY is non-nil, strip leading `Re:'s only."
1263   (let ((case-fold-search t))           ;Ignore case.
1264     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1265     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1266       (setq subject (substring subject (match-end 0))))
1267     ;; Remove uninteresting prefixes.
1268     (when (and (not re-only)
1269                gnus-simplify-ignored-prefixes
1270                (string-match gnus-simplify-ignored-prefixes subject))
1271       (setq subject (substring subject (match-end 0))))
1272     ;; Remove words in parentheses from end.
1273     (unless re-only
1274       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1275         (setq subject (substring subject 0 (match-beginning 0)))))
1276     ;; Return subject string.
1277     subject))
1278
1279 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1280 ;; all whitespace.
1281 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1282   (goto-char (point-min))
1283   (while (re-search-forward regexp nil t)
1284     (replace-match (or newtext ""))))
1285
1286 (defun gnus-simplify-buffer-fuzzy ()
1287   "Simplify string in the buffer fuzzily.
1288 The string in the accessible portion of the current buffer is simplified.
1289 It is assumed to be a single-line subject.
1290 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1291 matter is removed.  Additional things can be deleted by setting
1292 `gnus-simplify-subject-fuzzy-regexp'."
1293   (let ((case-fold-search t)
1294         (modified-tick))
1295     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1296
1297     (while (not (eq modified-tick (buffer-modified-tick)))
1298       (setq modified-tick (buffer-modified-tick))
1299       (cond
1300        ((listp gnus-simplify-subject-fuzzy-regexp)
1301         (mapcar 'gnus-simplify-buffer-fuzzy-step
1302                 gnus-simplify-subject-fuzzy-regexp))
1303        (gnus-simplify-subject-fuzzy-regexp
1304         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1305       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1306       (gnus-simplify-buffer-fuzzy-step
1307        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1308       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1309
1310     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1311     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1312     (gnus-simplify-buffer-fuzzy-step " $")
1313     (gnus-simplify-buffer-fuzzy-step "^ +")))
1314
1315 (defun gnus-simplify-subject-fuzzy (subject)
1316   "Simplify a subject string fuzzily.
1317 See `gnus-simplify-buffer-fuzzy' for details."
1318   (save-excursion
1319     (gnus-set-work-buffer)
1320     (let ((case-fold-search t))
1321       ;; Remove uninteresting prefixes.
1322       (when (and gnus-simplify-ignored-prefixes
1323                  (string-match gnus-simplify-ignored-prefixes subject))
1324         (setq subject (substring subject (match-end 0))))
1325       (insert subject)
1326       (inline (gnus-simplify-buffer-fuzzy))
1327       (buffer-string))))
1328
1329 (defsubst gnus-simplify-subject-fully (subject)
1330   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1331   (cond
1332    (gnus-simplify-subject-functions
1333     (gnus-map-function gnus-simplify-subject-functions subject))
1334    ((null gnus-summary-gather-subject-limit)
1335     (gnus-simplify-subject-re subject))
1336    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1337     (gnus-simplify-subject-fuzzy subject))
1338    ((numberp gnus-summary-gather-subject-limit)
1339     (gnus-limit-string (gnus-simplify-subject-re subject)
1340                        gnus-summary-gather-subject-limit))
1341    (t
1342     subject)))
1343
1344 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1345   "Check whether two subjects are equal.
1346 If optional argument simple-first is t, first argument is already
1347 simplified."
1348   (cond
1349    ((null simple-first)
1350     (equal (gnus-simplify-subject-fully s1)
1351            (gnus-simplify-subject-fully s2)))
1352    (t
1353     (equal s1
1354            (gnus-simplify-subject-fully s2)))))
1355
1356 (defun gnus-summary-bubble-group ()
1357   "Increase the score of the current group.
1358 This is a handy function to add to `gnus-summary-exit-hook' to
1359 increase the score of each group you read."
1360   (gnus-group-add-score gnus-newsgroup-name))
1361
1362 \f
1363 ;;;
1364 ;;; Gnus summary mode
1365 ;;;
1366
1367 (put 'gnus-summary-mode 'mode-class 'special)
1368
1369 (defvar gnus-article-commands-menu)
1370
1371 (when t
1372   ;; Non-orthogonal keys
1373
1374   (gnus-define-keys gnus-summary-mode-map
1375     " " gnus-summary-next-page
1376     "\177" gnus-summary-prev-page
1377     [delete] gnus-summary-prev-page
1378     [backspace] gnus-summary-prev-page
1379     "\r" gnus-summary-scroll-up
1380     "\M-\r" gnus-summary-scroll-down
1381     "n" gnus-summary-next-unread-article
1382     "p" gnus-summary-prev-unread-article
1383     "N" gnus-summary-next-article
1384     "P" gnus-summary-prev-article
1385     "\M-\C-n" gnus-summary-next-same-subject
1386     "\M-\C-p" gnus-summary-prev-same-subject
1387     "\M-n" gnus-summary-next-unread-subject
1388     "\M-p" gnus-summary-prev-unread-subject
1389     "." gnus-summary-first-unread-article
1390     "," gnus-summary-best-unread-article
1391     "\M-s" gnus-summary-search-article-forward
1392     "\M-r" gnus-summary-search-article-backward
1393     "<" gnus-summary-beginning-of-article
1394     ">" gnus-summary-end-of-article
1395     "j" gnus-summary-goto-article
1396     "^" gnus-summary-refer-parent-article
1397     "\M-^" gnus-summary-refer-article
1398     "u" gnus-summary-tick-article-forward
1399     "!" gnus-summary-tick-article-forward
1400     "U" gnus-summary-tick-article-backward
1401     "d" gnus-summary-mark-as-read-forward
1402     "D" gnus-summary-mark-as-read-backward
1403     "E" gnus-summary-mark-as-expirable
1404     "\M-u" gnus-summary-clear-mark-forward
1405     "\M-U" gnus-summary-clear-mark-backward
1406     "k" gnus-summary-kill-same-subject-and-select
1407     "\C-k" gnus-summary-kill-same-subject
1408     "\M-\C-k" gnus-summary-kill-thread
1409     "\M-\C-l" gnus-summary-lower-thread
1410     "e" gnus-summary-edit-article
1411     "#" gnus-summary-mark-as-processable
1412     "\M-#" gnus-summary-unmark-as-processable
1413     "\M-\C-t" gnus-summary-toggle-threads
1414     "\M-\C-s" gnus-summary-show-thread
1415     "\M-\C-h" gnus-summary-hide-thread
1416     "\M-\C-f" gnus-summary-next-thread
1417     "\M-\C-b" gnus-summary-prev-thread
1418     [(meta down)] gnus-summary-next-thread
1419     [(meta up)] gnus-summary-prev-thread
1420     "\M-\C-u" gnus-summary-up-thread
1421     "\M-\C-d" gnus-summary-down-thread
1422     "&" gnus-summary-execute-command
1423     "c" gnus-summary-catchup-and-exit
1424     "\C-w" gnus-summary-mark-region-as-read
1425     "\C-t" gnus-summary-toggle-truncation
1426     "?" gnus-summary-mark-as-dormant
1427     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1428     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1429     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1430     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1431     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1432     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1433     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1434     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1435     "=" gnus-summary-expand-window
1436     "\C-x\C-s" gnus-summary-reselect-current-group
1437     "\M-g" gnus-summary-rescan-group
1438     "w" gnus-summary-stop-page-breaking
1439     "\C-c\C-r" gnus-summary-caesar-message
1440     "f" gnus-summary-followup
1441     "F" gnus-summary-followup-with-original
1442     "C" gnus-summary-cancel-article
1443     "r" gnus-summary-reply
1444     "R" gnus-summary-reply-with-original
1445     "\C-c\C-f" gnus-summary-mail-forward
1446     "o" gnus-summary-save-article
1447     "\C-o" gnus-summary-save-article-mail
1448     "|" gnus-summary-pipe-output
1449     "\M-k" gnus-summary-edit-local-kill
1450     "\M-K" gnus-summary-edit-global-kill
1451     ;; "V" gnus-version
1452     "\C-c\C-d" gnus-summary-describe-group
1453     "q" gnus-summary-exit
1454     "Q" gnus-summary-exit-no-update
1455     "\C-c\C-i" gnus-info-find-node
1456     gnus-mouse-2 gnus-mouse-pick-article
1457     "m" gnus-summary-mail-other-window
1458     "a" gnus-summary-post-news
1459     "x" gnus-summary-limit-to-unread
1460     "s" gnus-summary-isearch-article
1461     "t" gnus-summary-toggle-header
1462     "g" gnus-summary-show-article
1463     "l" gnus-summary-goto-last-article
1464     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1465     "\C-d" gnus-summary-enter-digest-group
1466     "\M-\C-d" gnus-summary-read-document
1467     "\M-\C-e" gnus-summary-edit-parameters
1468     "\M-\C-a" gnus-summary-customize-parameters
1469     "\C-c\C-b" gnus-bug
1470     "*" gnus-cache-enter-article
1471     "\M-*" gnus-cache-remove-article
1472     "\M-&" gnus-summary-universal-argument
1473     "\C-l" gnus-recenter
1474     "I" gnus-summary-increase-score
1475     "L" gnus-summary-lower-score
1476     "\M-i" gnus-symbolic-argument
1477     "h" gnus-summary-select-article-buffer
1478
1479     "b" gnus-article-view-part
1480     "\M-t" gnus-summary-toggle-display-buttonized
1481
1482     "V" gnus-summary-score-map
1483     "X" gnus-uu-extract-map
1484     "S" gnus-summary-send-map)
1485
1486   ;; Sort of orthogonal keymap
1487   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1488     "t" gnus-summary-tick-article-forward
1489     "!" gnus-summary-tick-article-forward
1490     "d" gnus-summary-mark-as-read-forward
1491     "r" gnus-summary-mark-as-read-forward
1492     "c" gnus-summary-clear-mark-forward
1493     " " gnus-summary-clear-mark-forward
1494     "e" gnus-summary-mark-as-expirable
1495     "x" gnus-summary-mark-as-expirable
1496     "?" gnus-summary-mark-as-dormant
1497     "b" gnus-summary-set-bookmark
1498     "B" gnus-summary-remove-bookmark
1499     "#" gnus-summary-mark-as-processable
1500     "\M-#" gnus-summary-unmark-as-processable
1501     "S" gnus-summary-limit-include-expunged
1502     "C" gnus-summary-catchup
1503     "H" gnus-summary-catchup-to-here
1504     "\C-c" gnus-summary-catchup-all
1505     "k" gnus-summary-kill-same-subject-and-select
1506     "K" gnus-summary-kill-same-subject
1507     "P" gnus-uu-mark-map)
1508
1509   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1510     "c" gnus-summary-clear-above
1511     "u" gnus-summary-tick-above
1512     "m" gnus-summary-mark-above
1513     "k" gnus-summary-kill-below)
1514
1515   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1516     "/" gnus-summary-limit-to-subject
1517     "n" gnus-summary-limit-to-articles
1518     "w" gnus-summary-pop-limit
1519     "s" gnus-summary-limit-to-subject
1520     "a" gnus-summary-limit-to-author
1521     "u" gnus-summary-limit-to-unread
1522     "m" gnus-summary-limit-to-marks
1523     "M" gnus-summary-limit-exclude-marks
1524     "v" gnus-summary-limit-to-score
1525     "*" gnus-summary-limit-include-cached
1526     "D" gnus-summary-limit-include-dormant
1527     "T" gnus-summary-limit-include-thread
1528     "d" gnus-summary-limit-exclude-dormant
1529     "t" gnus-summary-limit-to-age
1530     "x" gnus-summary-limit-to-extra
1531     "E" gnus-summary-limit-include-expunged
1532     "c" gnus-summary-limit-exclude-childless-dormant
1533     "C" gnus-summary-limit-mark-excluded-as-read
1534     "o" gnus-summary-insert-old-articles
1535     "N" gnus-summary-insert-new-articles)
1536
1537   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1538     "n" gnus-summary-next-unread-article
1539     "p" gnus-summary-prev-unread-article
1540     "N" gnus-summary-next-article
1541     "P" gnus-summary-prev-article
1542     "\C-n" gnus-summary-next-same-subject
1543     "\C-p" gnus-summary-prev-same-subject
1544     "\M-n" gnus-summary-next-unread-subject
1545     "\M-p" gnus-summary-prev-unread-subject
1546     "f" gnus-summary-first-unread-article
1547     "b" gnus-summary-best-unread-article
1548     "j" gnus-summary-goto-article
1549     "g" gnus-summary-goto-subject
1550     "l" gnus-summary-goto-last-article
1551     "o" gnus-summary-pop-article)
1552
1553   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1554     "k" gnus-summary-kill-thread
1555     "l" gnus-summary-lower-thread
1556     "i" gnus-summary-raise-thread
1557     "T" gnus-summary-toggle-threads
1558     "t" gnus-summary-rethread-current
1559     "^" gnus-summary-reparent-thread
1560     "s" gnus-summary-show-thread
1561     "S" gnus-summary-show-all-threads
1562     "h" gnus-summary-hide-thread
1563     "H" gnus-summary-hide-all-threads
1564     "n" gnus-summary-next-thread
1565     "p" gnus-summary-prev-thread
1566     "u" gnus-summary-up-thread
1567     "o" gnus-summary-top-thread
1568     "d" gnus-summary-down-thread
1569     "#" gnus-uu-mark-thread
1570     "\M-#" gnus-uu-unmark-thread)
1571
1572   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1573     "g" gnus-summary-prepare
1574     "c" gnus-summary-insert-cached-articles)
1575
1576   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1577     "c" gnus-summary-catchup-and-exit
1578     "C" gnus-summary-catchup-all-and-exit
1579     "E" gnus-summary-exit-no-update
1580     "Q" gnus-summary-exit
1581     "Z" gnus-summary-exit
1582     "n" gnus-summary-catchup-and-goto-next-group
1583     "R" gnus-summary-reselect-current-group
1584     "G" gnus-summary-rescan-group
1585     "N" gnus-summary-next-group
1586     "s" gnus-summary-save-newsrc
1587     "P" gnus-summary-prev-group)
1588
1589   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1590     " " gnus-summary-next-page
1591     "n" gnus-summary-next-page
1592     "\177" gnus-summary-prev-page
1593     [delete] gnus-summary-prev-page
1594     "p" gnus-summary-prev-page
1595     "\r" gnus-summary-scroll-up
1596     "\M-\r" gnus-summary-scroll-down
1597     "<" gnus-summary-beginning-of-article
1598     ">" gnus-summary-end-of-article
1599     "b" gnus-summary-beginning-of-article
1600     "e" gnus-summary-end-of-article
1601     "^" gnus-summary-refer-parent-article
1602     "r" gnus-summary-refer-parent-article
1603     "D" gnus-summary-enter-digest-group
1604     "R" gnus-summary-refer-references
1605     "T" gnus-summary-refer-thread
1606     "g" gnus-summary-show-article
1607     "s" gnus-summary-isearch-article
1608     "P" gnus-summary-print-article
1609     "M" gnus-mailing-list-insinuate
1610     "t" gnus-article-babel)
1611
1612   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1613     "b" gnus-article-add-buttons
1614     "B" gnus-article-add-buttons-to-head
1615     "o" gnus-article-treat-overstrike
1616     "e" gnus-article-emphasize
1617     "w" gnus-article-fill-cited-article
1618     "Q" gnus-article-fill-long-lines
1619     "C" gnus-article-capitalize-sentences
1620     "c" gnus-article-remove-cr
1621     "q" gnus-article-de-quoted-unreadable
1622     "6" gnus-article-de-base64-unreadable
1623     "Z" gnus-article-decode-HZ
1624     "h" gnus-article-wash-html
1625     "s" gnus-summary-force-verify-and-decrypt
1626     "f" gnus-article-display-x-face
1627     "l" gnus-summary-stop-page-breaking
1628     "r" gnus-summary-caesar-message
1629     "t" gnus-summary-toggle-header
1630     "v" gnus-summary-verbose-headers
1631     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1632     "p" gnus-article-verify-x-pgp-sig
1633     "d" gnus-article-treat-dumbquotes)
1634
1635   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1636     "a" gnus-article-hide
1637     "h" gnus-article-hide-headers
1638     "b" gnus-article-hide-boring-headers
1639     "s" gnus-article-hide-signature
1640     "c" gnus-article-hide-citation
1641     "C" gnus-article-hide-citation-in-followups
1642     "l" gnus-article-hide-list-identifiers
1643     "p" gnus-article-hide-pgp
1644     "B" gnus-article-strip-banner
1645     "P" gnus-article-hide-pem
1646     "\C-c" gnus-article-hide-citation-maybe)
1647
1648   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1649     "a" gnus-article-highlight
1650     "h" gnus-article-highlight-headers
1651     "c" gnus-article-highlight-citation
1652     "s" gnus-article-highlight-signature)
1653
1654   (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1655     "w" gnus-article-decode-mime-words
1656     "c" gnus-article-decode-charset
1657     "v" gnus-mime-view-all-parts
1658     "b" gnus-article-view-part)
1659
1660   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1661     "z" gnus-article-date-ut
1662     "u" gnus-article-date-ut
1663     "l" gnus-article-date-local
1664     "p" gnus-article-date-english
1665     "e" gnus-article-date-lapsed
1666     "o" gnus-article-date-original
1667     "i" gnus-article-date-iso8601
1668     "s" gnus-article-date-user)
1669
1670   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1671     "t" gnus-article-remove-trailing-blank-lines
1672     "l" gnus-article-strip-leading-blank-lines
1673     "m" gnus-article-strip-multiple-blank-lines
1674     "a" gnus-article-strip-blank-lines
1675     "A" gnus-article-strip-all-blank-lines
1676     "s" gnus-article-strip-leading-space
1677     "e" gnus-article-strip-trailing-space
1678     "w" gnus-article-remove-leading-whitespace)
1679
1680   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1681     "v" gnus-version
1682     "f" gnus-summary-fetch-faq
1683     "d" gnus-summary-describe-group
1684     "h" gnus-summary-describe-briefly
1685     "i" gnus-info-find-node)
1686
1687   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1688     "e" gnus-summary-expire-articles
1689     "\M-\C-e" gnus-summary-expire-articles-now
1690     "\177" gnus-summary-delete-article
1691     [delete] gnus-summary-delete-article
1692     [backspace] gnus-summary-delete-article
1693     "m" gnus-summary-move-article
1694     "r" gnus-summary-respool-article
1695     "w" gnus-summary-edit-article
1696     "c" gnus-summary-copy-article
1697     "B" gnus-summary-crosspost-article
1698     "q" gnus-summary-respool-query
1699     "t" gnus-summary-respool-trace
1700     "i" gnus-summary-import-article
1701     "I" gnus-summary-create-article
1702     "p" gnus-summary-article-posted-p)
1703
1704   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1705     "o" gnus-summary-save-article
1706     "m" gnus-summary-save-article-mail
1707     "F" gnus-summary-write-article-file
1708     "r" gnus-summary-save-article-rmail
1709     "f" gnus-summary-save-article-file
1710     "b" gnus-summary-save-article-body-file
1711     "h" gnus-summary-save-article-folder
1712     "v" gnus-summary-save-article-vm
1713     "p" gnus-summary-pipe-output
1714     "s" gnus-soup-add-article)
1715
1716   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1717     "b" gnus-summary-display-buttonized
1718     "m" gnus-summary-repair-multipart
1719     "v" gnus-article-view-part
1720     "o" gnus-article-save-part
1721     "c" gnus-article-copy-part
1722     "C" gnus-article-view-part-as-charset
1723     "e" gnus-article-externalize-part
1724     "E" gnus-article-encrypt-body
1725     "i" gnus-article-inline-part
1726     "|" gnus-article-pipe-part))
1727
1728 (defvar gnus-article-post-menu nil)
1729
1730 (defun gnus-summary-make-menu-bar ()
1731   (gnus-turn-off-edit-menu 'summary)
1732
1733   (unless (boundp 'gnus-summary-misc-menu)
1734
1735     (easy-menu-define
1736      gnus-summary-kill-menu gnus-summary-mode-map ""
1737      (cons
1738       "Score"
1739       (nconc
1740        (list
1741         ["Customize" gnus-score-customize t])
1742        (gnus-make-score-map 'increase)
1743        (gnus-make-score-map 'lower)
1744        '(("Mark"
1745           ["Kill below" gnus-summary-kill-below t]
1746           ["Mark above" gnus-summary-mark-above t]
1747           ["Tick above" gnus-summary-tick-above t]
1748           ["Clear above" gnus-summary-clear-above t])
1749          ["Current score" gnus-summary-current-score t]
1750          ["Set score" gnus-summary-set-score t]
1751          ["Switch current score file..." gnus-score-change-score-file t]
1752          ["Set mark below..." gnus-score-set-mark-below t]
1753          ["Set expunge below..." gnus-score-set-expunge-below t]
1754          ["Edit current score file" gnus-score-edit-current-scores t]
1755          ["Edit score file" gnus-score-edit-file t]
1756          ["Trace score" gnus-score-find-trace t]
1757          ["Find words" gnus-score-find-favourite-words t]
1758          ["Rescore buffer" gnus-summary-rescore t]
1759          ["Increase score..." gnus-summary-increase-score t]
1760          ["Lower score..." gnus-summary-lower-score t]))))
1761
1762     ;; Define both the Article menu in the summary buffer and the equivalent
1763     ;; Commands menu in the article buffer here for consistency.
1764     (let ((innards
1765            `(("Hide"
1766               ["All" gnus-article-hide t]
1767               ["Headers" gnus-article-hide-headers t]
1768               ["Signature" gnus-article-hide-signature t]
1769               ["Citation" gnus-article-hide-citation t]
1770               ["List identifiers" gnus-article-hide-list-identifiers t]
1771               ["PGP" gnus-article-hide-pgp t]
1772               ["Banner" gnus-article-strip-banner t]
1773               ["Boring headers" gnus-article-hide-boring-headers t])
1774              ("Highlight"
1775               ["All" gnus-article-highlight t]
1776               ["Headers" gnus-article-highlight-headers t]
1777               ["Signature" gnus-article-highlight-signature t]
1778               ["Citation" gnus-article-highlight-citation t])
1779              ("MIME"
1780               ["Words" gnus-article-decode-mime-words t]
1781               ["Charset" gnus-article-decode-charset t]
1782               ["QP" gnus-article-de-quoted-unreadable t]
1783               ["Base64" gnus-article-de-base64-unreadable t]
1784               ["View all" gnus-mime-view-all-parts t]
1785               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
1786               ["Encrypt body" gnus-article-encrypt-body t])
1787              ("Date"
1788               ["Local" gnus-article-date-local t]
1789               ["ISO8601" gnus-article-date-iso8601 t]
1790               ["UT" gnus-article-date-ut t]
1791               ["Original" gnus-article-date-original t]
1792               ["Lapsed" gnus-article-date-lapsed t]
1793               ["User-defined" gnus-article-date-user t])
1794              ("Washing"
1795               ("Remove Blanks"
1796                ["Leading" gnus-article-strip-leading-blank-lines t]
1797                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1798                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1799                ["All of the above" gnus-article-strip-blank-lines t]
1800                ["All" gnus-article-strip-all-blank-lines t]
1801                ["Leading space" gnus-article-strip-leading-space t]
1802                ["Trailing space" gnus-article-strip-trailing-space t]
1803                ["Leading space in headers" 
1804                 gnus-article-remove-leading-whitespace t])
1805               ["Overstrike" gnus-article-treat-overstrike t]
1806               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1807               ["Emphasis" gnus-article-emphasize t]
1808               ["Word wrap" gnus-article-fill-cited-article t]
1809               ["Fill long lines" gnus-article-fill-long-lines t]
1810               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1811               ["CR" gnus-article-remove-cr t]
1812               ["Show X-Face" gnus-article-display-x-face t]
1813               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
1814               ["Base64" gnus-article-de-base64-unreadable t]
1815               ["Rot 13" gnus-summary-caesar-message
1816                ,@(if (featurep 'xemacs) '(t)
1817                    '(:help "\"Caesar rotate\" article by 13"))]
1818               ["Unix pipe" gnus-summary-pipe-message t]
1819               ["Add buttons" gnus-article-add-buttons t]
1820               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1821               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1822               ["Verbose header" gnus-summary-verbose-headers t]
1823               ["Toggle header" gnus-summary-toggle-header t]
1824               ["Html" gnus-article-wash-html t]
1825               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1826               ["HZ" gnus-article-decode-HZ t])
1827              ("Output"
1828               ["Save in default format" gnus-summary-save-article
1829                ,@(if (featurep 'xemacs) '(t)
1830                    '(:help "Save article using default method"))]
1831               ["Save in file" gnus-summary-save-article-file
1832                ,@(if (featurep 'xemacs) '(t)
1833                    '(:help "Save article in file"))]
1834               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1835               ["Save in MH folder" gnus-summary-save-article-folder t]
1836               ["Save in VM folder" gnus-summary-save-article-vm t]
1837               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1838               ["Save body in file" gnus-summary-save-article-body-file t]
1839               ["Pipe through a filter" gnus-summary-pipe-output t]
1840               ["Add to SOUP packet" gnus-soup-add-article t]
1841               ["Print" gnus-summary-print-article t])
1842              ("Backend"
1843               ["Respool article..." gnus-summary-respool-article t]
1844               ["Move article..." gnus-summary-move-article
1845                (gnus-check-backend-function
1846                 'request-move-article gnus-newsgroup-name)]
1847               ["Copy article..." gnus-summary-copy-article t]
1848               ["Crosspost article..." gnus-summary-crosspost-article
1849                (gnus-check-backend-function
1850                 'request-replace-article gnus-newsgroup-name)]
1851               ["Import file..." gnus-summary-import-article t]
1852               ["Create article..." gnus-summary-create-article t]
1853               ["Check if posted" gnus-summary-article-posted-p t]
1854               ["Edit article" gnus-summary-edit-article
1855                (not (gnus-group-read-only-p))]
1856               ["Delete article" gnus-summary-delete-article
1857                (gnus-check-backend-function
1858                 'request-expire-articles gnus-newsgroup-name)]
1859               ["Query respool" gnus-summary-respool-query t]
1860               ["Trace respool" gnus-summary-respool-trace t]
1861               ["Delete expirable articles" gnus-summary-expire-articles-now
1862                (gnus-check-backend-function
1863                 'request-expire-articles gnus-newsgroup-name)])
1864              ("Extract"
1865               ["Uudecode" gnus-uu-decode-uu
1866                ,@(if (featurep 'xemacs) '(t)
1867                    '(:help "Decode uuencoded article(s)"))]
1868               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1869               ["Unshar" gnus-uu-decode-unshar t]
1870               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1871               ["Save" gnus-uu-decode-save t]
1872               ["Binhex" gnus-uu-decode-binhex t]
1873               ["Postscript" gnus-uu-decode-postscript t])
1874              ("Cache"
1875               ["Enter article" gnus-cache-enter-article t]
1876               ["Remove article" gnus-cache-remove-article t])
1877              ["Translate" gnus-article-babel t]
1878              ["Select article buffer" gnus-summary-select-article-buffer t]
1879              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1880              ["Isearch article..." gnus-summary-isearch-article t]
1881              ["Beginning of the article" gnus-summary-beginning-of-article t]
1882              ["End of the article" gnus-summary-end-of-article t]
1883              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1884              ["Fetch referenced articles" gnus-summary-refer-references t]
1885              ["Fetch current thread" gnus-summary-refer-thread t]
1886              ["Fetch article with id..." gnus-summary-refer-article t]
1887              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1888              ["Redisplay" gnus-summary-show-article t])))
1889       (easy-menu-define
1890        gnus-summary-article-menu gnus-summary-mode-map ""
1891        (cons "Article" innards))
1892
1893       (if (not (keymapp gnus-summary-article-menu))
1894           (easy-menu-define
1895             gnus-article-commands-menu gnus-article-mode-map ""
1896             (cons "Commands" innards))
1897         ;; in Emacs, don't share menu.
1898         (setq gnus-article-commands-menu 
1899               (copy-keymap gnus-summary-article-menu))
1900         (define-key gnus-article-mode-map [menu-bar commands]
1901           (cons "Commands" gnus-article-commands-menu))))
1902
1903     (easy-menu-define
1904      gnus-summary-thread-menu gnus-summary-mode-map ""
1905      '("Threads"
1906        ["Toggle threading" gnus-summary-toggle-threads t]
1907        ["Hide threads" gnus-summary-hide-all-threads t]
1908        ["Show threads" gnus-summary-show-all-threads t]
1909        ["Hide thread" gnus-summary-hide-thread t]
1910        ["Show thread" gnus-summary-show-thread t]
1911        ["Go to next thread" gnus-summary-next-thread t]
1912        ["Go to previous thread" gnus-summary-prev-thread t]
1913        ["Go down thread" gnus-summary-down-thread t]
1914        ["Go up thread" gnus-summary-up-thread t]
1915        ["Top of thread" gnus-summary-top-thread t]
1916        ["Mark thread as read" gnus-summary-kill-thread t]
1917        ["Lower thread score" gnus-summary-lower-thread t]
1918        ["Raise thread score" gnus-summary-raise-thread t]
1919        ["Rethread current" gnus-summary-rethread-current t]))
1920
1921     (easy-menu-define
1922      gnus-summary-post-menu gnus-summary-mode-map ""
1923      `("Post"
1924        ["Post an article" gnus-summary-post-news
1925         ,@(if (featurep 'xemacs) '(t)
1926             '(:help "Post an article"))]
1927        ["Followup" gnus-summary-followup
1928         ,@(if (featurep 'xemacs) '(t)
1929             '(:help "Post followup to this article"))]
1930        ["Followup and yank" gnus-summary-followup-with-original
1931         ,@(if (featurep 'xemacs) '(t)
1932             '(:help "Post followup to this article, quoting its contents"))]
1933        ["Supersede article" gnus-summary-supersede-article t]
1934        ["Cancel article" gnus-summary-cancel-article
1935         ,@(if (featurep 'xemacs) '(t)
1936             '(:help "Cancel an article you posted"))]
1937        ["Reply" gnus-summary-reply t]
1938        ["Reply and yank" gnus-summary-reply-with-original t]
1939        ["Wide reply" gnus-summary-wide-reply t]
1940        ["Wide reply and yank" gnus-summary-wide-reply-with-original
1941         ,@(if (featurep 'xemacs) '(t)
1942             '(:help "Mail a reply, quoting this article"))]
1943        ["Mail forward" gnus-summary-mail-forward t]
1944        ["Post forward" gnus-summary-post-forward t]
1945        ["Digest and mail" gnus-uu-digest-mail-forward t]
1946        ["Digest and post" gnus-uu-digest-post-forward t]
1947        ["Resend message" gnus-summary-resend-message t]
1948        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
1949        ["Send a mail" gnus-summary-mail-other-window t]
1950        ["Uuencode and post" gnus-uu-post-news
1951         ,@(if (featurep 'xemacs) '(t)
1952             '(:help "Post a uuencoded article"))]
1953        ["Followup via news" gnus-summary-followup-to-mail t]
1954        ["Followup via news and yank"
1955         gnus-summary-followup-to-mail-with-original t]
1956        ;;("Draft"
1957        ;;["Send" gnus-summary-send-draft t]
1958        ;;["Send bounced" gnus-resend-bounced-mail t])
1959        ))
1960
1961     (cond 
1962      ((not (keymapp gnus-summary-post-menu))
1963       (setq gnus-article-post-menu gnus-summary-post-menu))
1964      ((not gnus-article-post-menu)
1965       ;; Don't share post menu.
1966       (setq gnus-article-post-menu
1967             (copy-keymap gnus-summary-post-menu))))
1968     (define-key gnus-article-mode-map [menu-bar post]
1969       (cons "Post" gnus-article-post-menu))
1970
1971     (easy-menu-define
1972      gnus-summary-misc-menu gnus-summary-mode-map ""
1973      `("Misc"
1974        ("Mark Read"
1975         ["Mark as read" gnus-summary-mark-as-read-forward t]
1976         ["Mark same subject and select"
1977          gnus-summary-kill-same-subject-and-select t]
1978         ["Mark same subject" gnus-summary-kill-same-subject t]
1979         ["Catchup" gnus-summary-catchup
1980          ,@(if (featurep 'xemacs) '(t)
1981              '(:help "Mark unread articles in this group as read"))]
1982         ["Catchup all" gnus-summary-catchup-all t]
1983         ["Catchup to here" gnus-summary-catchup-to-here t]
1984         ["Catchup region" gnus-summary-mark-region-as-read t]
1985         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
1986        ("Mark Various"
1987         ["Tick" gnus-summary-tick-article-forward t]
1988         ["Mark as dormant" gnus-summary-mark-as-dormant t]
1989         ["Remove marks" gnus-summary-clear-mark-forward t]
1990         ["Set expirable mark" gnus-summary-mark-as-expirable t]
1991         ["Set bookmark" gnus-summary-set-bookmark t]
1992         ["Remove bookmark" gnus-summary-remove-bookmark t])
1993        ("Mark Limit"
1994         ["Marks..." gnus-summary-limit-to-marks t]
1995         ["Subject..." gnus-summary-limit-to-subject t]
1996         ["Author..." gnus-summary-limit-to-author t]
1997         ["Age..." gnus-summary-limit-to-age t]
1998         ["Extra..." gnus-summary-limit-to-extra t]
1999         ["Score" gnus-summary-limit-to-score t]
2000         ["Unread" gnus-summary-limit-to-unread t]
2001         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2002         ["Articles" gnus-summary-limit-to-articles t]
2003         ["Pop limit" gnus-summary-pop-limit t]
2004         ["Show dormant" gnus-summary-limit-include-dormant t]
2005         ["Hide childless dormant"
2006          gnus-summary-limit-exclude-childless-dormant t]
2007         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2008         ["Hide marked" gnus-summary-limit-exclude-marks t]
2009         ["Show expunged" gnus-summary-limit-include-expunged t])
2010        ("Process Mark"
2011         ["Set mark" gnus-summary-mark-as-processable t]
2012         ["Remove mark" gnus-summary-unmark-as-processable t]
2013         ["Remove all marks" gnus-summary-unmark-all-processable t]
2014         ["Mark above" gnus-uu-mark-over t]
2015         ["Mark series" gnus-uu-mark-series t]
2016         ["Mark region" gnus-uu-mark-region t]
2017         ["Unmark region" gnus-uu-unmark-region t]
2018         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2019         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2020         ["Mark all" gnus-uu-mark-all t]
2021         ["Mark buffer" gnus-uu-mark-buffer t]
2022         ["Mark sparse" gnus-uu-mark-sparse t]
2023         ["Mark thread" gnus-uu-mark-thread t]
2024         ["Unmark thread" gnus-uu-unmark-thread t]
2025         ("Process Mark Sets"
2026          ["Kill" gnus-summary-kill-process-mark t]
2027          ["Yank" gnus-summary-yank-process-mark
2028           gnus-newsgroup-process-stack]
2029          ["Save" gnus-summary-save-process-mark t]))
2030        ("Scroll article"
2031         ["Page forward" gnus-summary-next-page
2032          ,@(if (featurep 'xemacs) '(t)
2033              '(:help "Show next page of article"))]
2034         ["Page backward" gnus-summary-prev-page
2035          ,@(if (featurep 'xemacs) '(t)
2036              '(:help "Show previous page of article"))]
2037         ["Line forward" gnus-summary-scroll-up t])
2038        ("Move"
2039         ["Next unread article" gnus-summary-next-unread-article t]
2040         ["Previous unread article" gnus-summary-prev-unread-article t]
2041         ["Next article" gnus-summary-next-article t]
2042         ["Previous article" gnus-summary-prev-article t]
2043         ["Next unread subject" gnus-summary-next-unread-subject t]
2044         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2045         ["Next article same subject" gnus-summary-next-same-subject t]
2046         ["Previous article same subject" gnus-summary-prev-same-subject t]
2047         ["First unread article" gnus-summary-first-unread-article t]
2048         ["Best unread article" gnus-summary-best-unread-article t]
2049         ["Go to subject number..." gnus-summary-goto-subject t]
2050         ["Go to article number..." gnus-summary-goto-article t]
2051         ["Go to the last article" gnus-summary-goto-last-article t]
2052         ["Pop article off history" gnus-summary-pop-article t])
2053        ("Sort"
2054         ["Sort by number" gnus-summary-sort-by-number t]
2055         ["Sort by author" gnus-summary-sort-by-author t]
2056         ["Sort by subject" gnus-summary-sort-by-subject t]
2057         ["Sort by date" gnus-summary-sort-by-date t]
2058         ["Sort by score" gnus-summary-sort-by-score t]
2059         ["Sort by lines" gnus-summary-sort-by-lines t]
2060         ["Sort by characters" gnus-summary-sort-by-chars t])
2061        ("Help"
2062         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2063         ["Describe group" gnus-summary-describe-group t]
2064         ["Read manual" gnus-info-find-node t])
2065        ("Modes"
2066         ["Pick and read" gnus-pick-mode t]
2067         ["Binary" gnus-binary-mode t])
2068        ("Regeneration"
2069         ["Regenerate" gnus-summary-prepare t]
2070         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2071         ["Toggle threading" gnus-summary-toggle-threads t])
2072        ["See old articles" gnus-summary-insert-old-articles t]
2073        ["See new articles" gnus-summary-insert-new-articles t]
2074        ["Filter articles..." gnus-summary-execute-command t]
2075        ["Run command on subjects..." gnus-summary-universal-argument t]
2076        ["Search articles forward..." gnus-summary-search-article-forward t]
2077        ["Search articles backward..." gnus-summary-search-article-backward t]
2078        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2079        ["Expand window" gnus-summary-expand-window t]
2080        ["Expire expirable articles" gnus-summary-expire-articles
2081         (gnus-check-backend-function
2082          'request-expire-articles gnus-newsgroup-name)]
2083        ["Edit local kill file" gnus-summary-edit-local-kill t]
2084        ["Edit main kill file" gnus-summary-edit-global-kill t]
2085        ["Edit group parameters" gnus-summary-edit-parameters t]
2086        ["Customize group parameters" gnus-summary-customize-parameters t]
2087        ["Send a bug report" gnus-bug t]
2088        ("Exit"
2089         ["Catchup and exit" gnus-summary-catchup-and-exit
2090          ,@(if (featurep 'xemacs) '(t)
2091              '(:help "Mark unread articles in this group as read, then exit"))]
2092         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2093         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2094         ["Exit group" gnus-summary-exit
2095          ,@(if (featurep 'xemacs) '(t)
2096              '(:help "Exit current group, return to group selection mode"))]
2097         ["Exit group without updating" gnus-summary-exit-no-update t]
2098         ["Exit and goto next group" gnus-summary-next-group t]
2099         ["Exit and goto prev group" gnus-summary-prev-group t]
2100         ["Reselect group" gnus-summary-reselect-current-group t]
2101         ["Rescan group" gnus-summary-rescan-group t]
2102         ["Update dribble" gnus-summary-save-newsrc t])))
2103
2104     (gnus-run-hooks 'gnus-summary-menu-hook)))
2105
2106 (defvar gnus-summary-tool-bar-map nil)
2107
2108 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2109 (defun gnus-summary-make-tool-bar ()
2110   (if (and (fboundp 'tool-bar-add-item-from-menu)
2111            (default-value 'tool-bar-mode)
2112            (not gnus-summary-tool-bar-map))
2113       (setq gnus-summary-tool-bar-map
2114             (let ((tool-bar-map (make-sparse-keymap))
2115                   (load-path (mm-image-load-path)))
2116               (tool-bar-add-item-from-menu
2117                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2118               (tool-bar-add-item-from-menu
2119                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2120               (tool-bar-add-item-from-menu
2121                'gnus-summary-post-news "post" gnus-summary-mode-map)
2122               (tool-bar-add-item-from-menu
2123                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2124               (tool-bar-add-item-from-menu
2125                'gnus-summary-followup "followup" gnus-summary-mode-map)
2126               (tool-bar-add-item-from-menu
2127                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2128               (tool-bar-add-item-from-menu
2129                'gnus-summary-reply "reply" gnus-summary-mode-map)
2130               (tool-bar-add-item-from-menu
2131                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2132               (tool-bar-add-item-from-menu
2133                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2134               (tool-bar-add-item-from-menu
2135                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2136               (tool-bar-add-item-from-menu
2137                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2138               (tool-bar-add-item-from-menu
2139                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2140               (tool-bar-add-item-from-menu
2141                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2142               (tool-bar-add-item-from-menu
2143                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2144               (tool-bar-add-item-from-menu
2145                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2146               tool-bar-map)))
2147   (if gnus-summary-tool-bar-map
2148       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2149
2150 (defun gnus-score-set-default (var value)
2151   "A version of set that updates the GNU Emacs menu-bar."
2152   (set var value)
2153   ;; It is the message that forces the active status to be updated.
2154   (message ""))
2155
2156 (defun gnus-make-score-map (type)
2157   "Make a summary score map of type TYPE."
2158   (if t
2159       nil
2160     (let ((headers '(("author" "from" string)
2161                      ("subject" "subject" string)
2162                      ("article body" "body" string)
2163                      ("article head" "head" string)
2164                      ("xref" "xref" string)
2165                      ("extra header" "extra" string)
2166                      ("lines" "lines" number)
2167                      ("followups to author" "followup" string)))
2168           (types '((number ("less than" <)
2169                            ("greater than" >)
2170                            ("equal" =))
2171                    (string ("substring" s)
2172                            ("exact string" e)
2173                            ("fuzzy string" f)
2174                            ("regexp" r))))
2175           (perms '(("temporary" (current-time-string))
2176                    ("permanent" nil)
2177                    ("immediate" now)))
2178           header)
2179       (list
2180        (apply
2181         'nconc
2182         (list
2183          (if (eq type 'lower)
2184              "Lower score"
2185            "Increase score"))
2186         (let (outh)
2187           (while headers
2188             (setq header (car headers))
2189             (setq outh
2190                   (cons
2191                    (apply
2192                     'nconc
2193                     (list (car header))
2194                     (let ((ts (cdr (assoc (nth 2 header) types)))
2195                           outt)
2196                       (while ts
2197                         (setq outt
2198                               (cons
2199                                (apply
2200                                 'nconc
2201                                 (list (caar ts))
2202                                 (let ((ps perms)
2203                                       outp)
2204                                   (while ps
2205                                     (setq outp
2206                                           (cons
2207                                            (vector
2208                                             (caar ps)
2209                                             (list
2210                                              'gnus-summary-score-entry
2211                                              (nth 1 header)
2212                                              (if (or (string= (nth 1 header)
2213                                                               "head")
2214                                                      (string= (nth 1 header)
2215                                                               "body"))
2216                                                  ""
2217                                                (list 'gnus-summary-header
2218                                                      (nth 1 header)))
2219                                              (list 'quote (nth 1 (car ts)))
2220                                              (list 'gnus-score-delta-default
2221                                                    nil)
2222                                              (nth 1 (car ps))
2223                                              t)
2224                                             t)
2225                                            outp))
2226                                     (setq ps (cdr ps)))
2227                                   (list (nreverse outp))))
2228                                outt))
2229                         (setq ts (cdr ts)))
2230                       (list (nreverse outt))))
2231                    outh))
2232             (setq headers (cdr headers)))
2233           (list (nreverse outh))))))))
2234
2235 \f
2236
2237 (defun gnus-summary-mode (&optional group)
2238   "Major mode for reading articles.
2239
2240 All normal editing commands are switched off.
2241 \\<gnus-summary-mode-map>
2242 Each line in this buffer represents one article.  To read an
2243 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2244 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2245 respectively.
2246
2247 You can also post articles and send mail from this buffer.  To
2248 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2249 of an article, type `\\[gnus-summary-reply]'.
2250
2251 There are approx. one gazillion commands you can execute in this
2252 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2253
2254 The following commands are available:
2255
2256 \\{gnus-summary-mode-map}"
2257   (interactive)
2258   (kill-all-local-variables)
2259   (when (gnus-visual-p 'summary-menu 'menu)
2260     (gnus-summary-make-menu-bar)
2261     (gnus-summary-make-tool-bar))
2262   (gnus-summary-make-local-variables)
2263   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2264     (gnus-summary-make-local-variables))
2265   (gnus-make-thread-indent-array)
2266   (gnus-simplify-mode-line)
2267   (setq major-mode 'gnus-summary-mode)
2268   (setq mode-name "Summary")
2269   (make-local-variable 'minor-mode-alist)
2270   (use-local-map gnus-summary-mode-map)
2271   (buffer-disable-undo)
2272   (setq buffer-read-only t)             ;Disable modification
2273   (setq truncate-lines t)
2274   (setq selective-display t)
2275   (setq selective-display-ellipses t)   ;Display `...'
2276   (gnus-summary-set-display-table)
2277   (gnus-set-default-directory)
2278   (setq gnus-newsgroup-name group)
2279   (make-local-variable 'gnus-summary-line-format)
2280   (make-local-variable 'gnus-summary-line-format-spec)
2281   (make-local-variable 'gnus-summary-dummy-line-format)
2282   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2283   (make-local-variable 'gnus-summary-mark-positions)
2284   (make-local-hook 'pre-command-hook)
2285   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2286   (gnus-run-hooks 'gnus-summary-mode-hook)
2287   (turn-on-gnus-mailing-list-mode)
2288   (mm-enable-multibyte-mule4)
2289   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2290   (gnus-update-summary-mark-positions))
2291
2292 (defun gnus-summary-make-local-variables ()
2293   "Make all the local summary buffer variables."
2294   (let (global)
2295     (dolist (local gnus-summary-local-variables)
2296       (if (consp local)
2297           (progn
2298             (if (eq (cdr local) 'global)
2299                 ;; Copy the global value of the variable.
2300                 (setq global (symbol-value (car local)))
2301               ;; Use the value from the list.
2302               (setq global (eval (cdr local))))
2303             (set (make-local-variable (car local)) global))
2304         ;; Simple nil-valued local variable.
2305         (set (make-local-variable local) nil)))))
2306
2307 (defun gnus-summary-clear-local-variables ()
2308   (let ((locals gnus-summary-local-variables))
2309     (while locals
2310       (if (consp (car locals))
2311           (and (vectorp (caar locals))
2312                (set (caar locals) nil))
2313         (and (vectorp (car locals))
2314              (set (car locals) nil)))
2315       (setq locals (cdr locals)))))
2316
2317 ;; Summary data functions.
2318
2319 (defmacro gnus-data-number (data)
2320   `(car ,data))
2321
2322 (defmacro gnus-data-set-number (data number)
2323   `(setcar ,data ,number))
2324
2325 (defmacro gnus-data-mark (data)
2326   `(nth 1 ,data))
2327
2328 (defmacro gnus-data-set-mark (data mark)
2329   `(setcar (nthcdr 1 ,data) ,mark))
2330
2331 (defmacro gnus-data-pos (data)
2332   `(nth 2 ,data))
2333
2334 (defmacro gnus-data-set-pos (data pos)
2335   `(setcar (nthcdr 2 ,data) ,pos))
2336
2337 (defmacro gnus-data-header (data)
2338   `(nth 3 ,data))
2339
2340 (defmacro gnus-data-set-header (data header)
2341   `(setf (nth 3 ,data) ,header))
2342
2343 (defmacro gnus-data-level (data)
2344   `(nth 4 ,data))
2345
2346 (defmacro gnus-data-unread-p (data)
2347   `(= (nth 1 ,data) gnus-unread-mark))
2348
2349 (defmacro gnus-data-read-p (data)
2350   `(/= (nth 1 ,data) gnus-unread-mark))
2351
2352 (defmacro gnus-data-pseudo-p (data)
2353   `(consp (nth 3 ,data)))
2354
2355 (defmacro gnus-data-find (number)
2356   `(assq ,number gnus-newsgroup-data))
2357
2358 (defmacro gnus-data-find-list (number &optional data)
2359   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2360      (memq (assq ,number bdata)
2361            bdata)))
2362
2363 (defmacro gnus-data-make (number mark pos header level)
2364   `(list ,number ,mark ,pos ,header ,level))
2365
2366 (defun gnus-data-enter (after-article number mark pos header level offset)
2367   (let ((data (gnus-data-find-list after-article)))
2368     (unless data
2369       (error "No such article: %d" after-article))
2370     (setcdr data (cons (gnus-data-make number mark pos header level)
2371                        (cdr data)))
2372     (setq gnus-newsgroup-data-reverse nil)
2373     (gnus-data-update-list (cddr data) offset)))
2374
2375 (defun gnus-data-enter-list (after-article list &optional offset)
2376   (when list
2377     (let ((data (and after-article (gnus-data-find-list after-article)))
2378           (ilist list))
2379       (if (not (or data
2380                    after-article))
2381           (let ((odata gnus-newsgroup-data))
2382             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2383             (when offset
2384               (gnus-data-update-list odata offset)))
2385         ;; Find the last element in the list to be spliced into the main
2386         ;; list.
2387         (while (cdr list)
2388           (setq list (cdr list)))
2389         (if (not data)
2390             (progn
2391               (setcdr list gnus-newsgroup-data)
2392               (setq gnus-newsgroup-data ilist)
2393               (when offset
2394                 (gnus-data-update-list (cdr list) offset)))
2395           (setcdr list (cdr data))
2396           (setcdr data ilist)
2397           (when offset
2398             (gnus-data-update-list (cdr list) offset))))
2399       (setq gnus-newsgroup-data-reverse nil))))
2400
2401 (defun gnus-data-remove (article &optional offset)
2402   (let ((data gnus-newsgroup-data))
2403     (if (= (gnus-data-number (car data)) article)
2404         (progn
2405           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2406                 gnus-newsgroup-data-reverse nil)
2407           (when offset
2408             (gnus-data-update-list gnus-newsgroup-data offset)))
2409       (while (cdr data)
2410         (when (= (gnus-data-number (cadr data)) article)
2411           (setcdr data (cddr data))
2412           (when offset
2413             (gnus-data-update-list (cdr data) offset))
2414           (setq data nil
2415                 gnus-newsgroup-data-reverse nil))
2416         (setq data (cdr data))))))
2417
2418 (defmacro gnus-data-list (backward)
2419   `(if ,backward
2420        (or gnus-newsgroup-data-reverse
2421            (setq gnus-newsgroup-data-reverse
2422                  (reverse gnus-newsgroup-data)))
2423      gnus-newsgroup-data))
2424
2425 (defun gnus-data-update-list (data offset)
2426   "Add OFFSET to the POS of all data entries in DATA."
2427   (setq gnus-newsgroup-data-reverse nil)
2428   (while data
2429     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2430     (setq data (cdr data))))
2431
2432 (defun gnus-summary-article-pseudo-p (article)
2433   "Say whether this article is a pseudo article or not."
2434   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2435
2436 (defmacro gnus-summary-article-sparse-p (article)
2437   "Say whether this article is a sparse article or not."
2438   `(memq ,article gnus-newsgroup-sparse))
2439
2440 (defmacro gnus-summary-article-ancient-p (article)
2441   "Say whether this article is a sparse article or not."
2442   `(memq ,article gnus-newsgroup-ancient))
2443
2444 (defun gnus-article-parent-p (number)
2445   "Say whether this article is a parent or not."
2446   (let ((data (gnus-data-find-list number)))
2447     (and (cdr data)                     ; There has to be an article after...
2448          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2449             (gnus-data-level (nth 1 data))))))
2450
2451 (defun gnus-article-children (number)
2452   "Return a list of all children to NUMBER."
2453   (let* ((data (gnus-data-find-list number))
2454          (level (gnus-data-level (car data)))
2455          children)
2456     (setq data (cdr data))
2457     (while (and data
2458                 (= (gnus-data-level (car data)) (1+ level)))
2459       (push (gnus-data-number (car data)) children)
2460       (setq data (cdr data)))
2461     children))
2462
2463 (defmacro gnus-summary-skip-intangible ()
2464   "If the current article is intangible, then jump to a different article."
2465   '(let ((to (get-text-property (point) 'gnus-intangible)))
2466      (and to (gnus-summary-goto-subject to))))
2467
2468 (defmacro gnus-summary-article-intangible-p ()
2469   "Say whether this article is intangible or not."
2470   '(get-text-property (point) 'gnus-intangible))
2471
2472 (defun gnus-article-read-p (article)
2473   "Say whether ARTICLE is read or not."
2474   (not (or (memq article gnus-newsgroup-marked)
2475            (memq article gnus-newsgroup-unreads)
2476            (memq article gnus-newsgroup-unselected)
2477            (memq article gnus-newsgroup-dormant))))
2478
2479 ;; Some summary mode macros.
2480
2481 (defmacro gnus-summary-article-number ()
2482   "The article number of the article on the current line.
2483 If there isn's an article number here, then we return the current
2484 article number."
2485   '(progn
2486      (gnus-summary-skip-intangible)
2487      (or (get-text-property (point) 'gnus-number)
2488          (gnus-summary-last-subject))))
2489
2490 (defmacro gnus-summary-article-header (&optional number)
2491   "Return the header of article NUMBER."
2492   `(gnus-data-header (gnus-data-find
2493                       ,(or number '(gnus-summary-article-number)))))
2494
2495 (defmacro gnus-summary-thread-level (&optional number)
2496   "Return the level of thread that starts with article NUMBER."
2497   `(if (and (eq gnus-summary-make-false-root 'dummy)
2498             (get-text-property (point) 'gnus-intangible))
2499        0
2500      (gnus-data-level (gnus-data-find
2501                        ,(or number '(gnus-summary-article-number))))))
2502
2503 (defmacro gnus-summary-article-mark (&optional number)
2504   "Return the mark of article NUMBER."
2505   `(gnus-data-mark (gnus-data-find
2506                     ,(or number '(gnus-summary-article-number)))))
2507
2508 (defmacro gnus-summary-article-pos (&optional number)
2509   "Return the position of the line of article NUMBER."
2510   `(gnus-data-pos (gnus-data-find
2511                    ,(or number '(gnus-summary-article-number)))))
2512
2513 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2514 (defmacro gnus-summary-article-subject (&optional number)
2515   "Return current subject string or nil if nothing."
2516   `(let ((headers
2517           ,(if number
2518                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2519              '(gnus-data-header (assq (gnus-summary-article-number)
2520                                       gnus-newsgroup-data)))))
2521      (and headers
2522           (vectorp headers)
2523           (mail-header-subject headers))))
2524
2525 (defmacro gnus-summary-article-score (&optional number)
2526   "Return current article score."
2527   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2528                   gnus-newsgroup-scored))
2529        gnus-summary-default-score 0))
2530
2531 (defun gnus-summary-article-children (&optional number)
2532   "Return a list of article numbers that are children of article NUMBER."
2533   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2534          (level (gnus-data-level (car data)))
2535          l children)
2536     (while (and (setq data (cdr data))
2537                 (> (setq l (gnus-data-level (car data))) level))
2538       (and (= (1+ level) l)
2539            (push (gnus-data-number (car data))
2540                  children)))
2541     (nreverse children)))
2542
2543 (defun gnus-summary-article-parent (&optional number)
2544   "Return the article number of the parent of article NUMBER."
2545   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2546                                     (gnus-data-list t)))
2547          (level (gnus-data-level (car data))))
2548     (if (zerop level)
2549         ()                              ; This is a root.
2550       ;; We search until we find an article with a level less than
2551       ;; this one.  That function has to be the parent.
2552       (while (and (setq data (cdr data))
2553                   (not (< (gnus-data-level (car data)) level))))
2554       (and data (gnus-data-number (car data))))))
2555
2556 (defun gnus-unread-mark-p (mark)
2557   "Say whether MARK is the unread mark."
2558   (= mark gnus-unread-mark))
2559
2560 (defun gnus-read-mark-p (mark)
2561   "Say whether MARK is one of the marks that mark as read.
2562 This is all marks except unread, ticked, dormant, and expirable."
2563   (not (or (= mark gnus-unread-mark)
2564            (= mark gnus-ticked-mark)
2565            (= mark gnus-dormant-mark)
2566            (= mark gnus-expirable-mark))))
2567
2568 (defmacro gnus-article-mark (number)
2569   "Return the MARK of article NUMBER.
2570 This macro should only be used when computing the mark the \"first\"
2571 time; i.e., when generating the summary lines.  After that,
2572 `gnus-summary-article-mark' should be used to examine the
2573 marks of articles."
2574   `(cond
2575     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2576     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2577     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2578     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2579     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2580     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2581     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2582     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2583            gnus-ancient-mark))))
2584
2585 ;; Saving hidden threads.
2586
2587 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2588 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2589
2590 (defmacro gnus-save-hidden-threads (&rest forms)
2591   "Save hidden threads, eval FORMS, and restore the hidden threads."
2592   (let ((config (make-symbol "config")))
2593     `(let ((,config (gnus-hidden-threads-configuration)))
2594        (unwind-protect
2595            (save-excursion
2596              ,@forms)
2597          (gnus-restore-hidden-threads-configuration ,config)))))
2598
2599 (defun gnus-data-compute-positions ()
2600   "Compute the positions of all articles."
2601   (setq gnus-newsgroup-data-reverse nil)
2602   (let ((data gnus-newsgroup-data))
2603     (save-excursion
2604       (gnus-save-hidden-threads
2605         (gnus-summary-show-all-threads)
2606         (goto-char (point-min))
2607         (while data
2608           (while (get-text-property (point) 'gnus-intangible)
2609             (forward-line 1))
2610           (gnus-data-set-pos (car data) (+ (point) 3))
2611           (setq data (cdr data))
2612           (forward-line 1))))))
2613
2614 (defun gnus-hidden-threads-configuration ()
2615   "Return the current hidden threads configuration."
2616   (save-excursion
2617     (let (config)
2618       (goto-char (point-min))
2619       (while (search-forward "\r" nil t)
2620         (push (1- (point)) config))
2621       config)))
2622
2623 (defun gnus-restore-hidden-threads-configuration (config)
2624   "Restore hidden threads configuration from CONFIG."
2625   (save-excursion
2626     (let (point buffer-read-only)
2627       (while (setq point (pop config))
2628         (when (and (< point (point-max))
2629                    (goto-char point)
2630                    (eq (char-after) ?\n))
2631           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2632
2633 ;; Various summary mode internalish functions.
2634
2635 (defun gnus-mouse-pick-article (e)
2636   (interactive "e")
2637   (mouse-set-point e)
2638   (gnus-summary-next-page nil t))
2639
2640 (defun gnus-summary-set-display-table ()
2641   "Change the display table.
2642 Odd characters have a tendency to mess
2643 up nicely formatted displays - we make all possible glyphs
2644 display only a single character."
2645
2646   ;; We start from the standard display table, if any.
2647   (let ((table (or (copy-sequence standard-display-table)
2648                    (make-display-table)))
2649         (i 32))
2650     ;; Nix out all the control chars...
2651     (while (>= (setq i (1- i)) 0)
2652       (aset table i [??]))
2653     ;; ... but not newline and cr, of course.  (cr is necessary for the
2654     ;; selective display).
2655     (aset table ?\n nil)
2656     (aset table ?\r nil)
2657     ;; We keep TAB as well.
2658     (aset table ?\t nil)
2659     ;; We nix out any glyphs over 126 that are not set already.
2660     (let ((i 256))
2661       (while (>= (setq i (1- i)) 127)
2662         ;; Only modify if the entry is nil.
2663         (unless (aref table i)
2664           (aset table i [??]))))
2665     (setq buffer-display-table table)))
2666
2667 (defun gnus-summary-buffer-name (group)
2668   "Return the summary buffer name of GROUP."
2669   (concat "*Summary " group "*"))
2670
2671 (defun gnus-summary-setup-buffer (group)
2672   "Initialize summary buffer."
2673   (let ((buffer (gnus-summary-buffer-name group)))
2674     (if (get-buffer buffer)
2675         (progn
2676           (set-buffer buffer)
2677           (setq gnus-summary-buffer (current-buffer))
2678           (not gnus-newsgroup-prepared))
2679       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2680       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2681       (gnus-summary-mode group)
2682       (when gnus-carpal
2683         (gnus-carpal-setup-buffer 'summary))
2684       (unless gnus-single-article-buffer
2685         (make-local-variable 'gnus-article-buffer)
2686         (make-local-variable 'gnus-article-current)
2687         (make-local-variable 'gnus-original-article-buffer))
2688       (setq gnus-newsgroup-name group)
2689       ;; Set any local variables in the group parameters.
2690       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2691       t)))
2692
2693 (defun gnus-set-global-variables ()
2694   "Set the global equivalents of the buffer-local variables.
2695 They are set to the latest values they had.  These reflect the summary
2696 buffer that was in action when the last article was fetched."
2697   (when (eq major-mode 'gnus-summary-mode)
2698     (setq gnus-summary-buffer (current-buffer))
2699     (let ((name gnus-newsgroup-name)
2700           (marked gnus-newsgroup-marked)
2701           (unread gnus-newsgroup-unreads)
2702           (headers gnus-current-headers)
2703           (data gnus-newsgroup-data)
2704           (summary gnus-summary-buffer)
2705           (article-buffer gnus-article-buffer)
2706           (original gnus-original-article-buffer)
2707           (gac gnus-article-current)
2708           (reffed gnus-reffed-article-number)
2709           (score-file gnus-current-score-file)
2710           (default-charset gnus-newsgroup-charset)
2711           vlist)
2712       (let ((locals gnus-newsgroup-variables))
2713         (while locals
2714           (if (consp (car locals))
2715               (push (eval (caar locals)) vlist)
2716             (push (eval (car locals)) vlist))
2717           (setq locals (cdr locals)))
2718         (setq vlist (nreverse vlist)))
2719       (save-excursion
2720         (set-buffer gnus-group-buffer)
2721         (setq gnus-newsgroup-name name
2722               gnus-newsgroup-marked marked
2723               gnus-newsgroup-unreads unread
2724               gnus-current-headers headers
2725               gnus-newsgroup-data data
2726               gnus-article-current gac
2727               gnus-summary-buffer summary
2728               gnus-article-buffer article-buffer
2729               gnus-original-article-buffer original
2730               gnus-reffed-article-number reffed
2731               gnus-current-score-file score-file
2732               gnus-newsgroup-charset default-charset)
2733         (let ((locals gnus-newsgroup-variables))
2734           (while locals
2735             (if (consp (car locals))
2736                 (set (caar locals) (pop vlist))
2737               (set (car locals) (pop vlist)))
2738             (setq locals (cdr locals))))
2739         ;; The article buffer also has local variables.
2740         (when (gnus-buffer-live-p gnus-article-buffer)
2741           (set-buffer gnus-article-buffer)
2742           (setq gnus-summary-buffer summary))))))
2743
2744 (defun gnus-summary-article-unread-p (article)
2745   "Say whether ARTICLE is unread or not."
2746   (memq article gnus-newsgroup-unreads))
2747
2748 (defun gnus-summary-first-article-p (&optional article)
2749   "Return whether ARTICLE is the first article in the buffer."
2750   (if (not (setq article (or article (gnus-summary-article-number))))
2751       nil
2752     (eq article (caar gnus-newsgroup-data))))
2753
2754 (defun gnus-summary-last-article-p (&optional article)
2755   "Return whether ARTICLE is the last article in the buffer."
2756   (if (not (setq article (or article (gnus-summary-article-number))))
2757       ;; All non-existent numbers are the last article.  :-)
2758       t
2759     (not (cdr (gnus-data-find-list article)))))
2760
2761 (defun gnus-make-thread-indent-array ()
2762   (let ((n 200))
2763     (unless (and gnus-thread-indent-array
2764                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2765       (setq gnus-thread-indent-array (make-vector 201 "")
2766             gnus-thread-indent-array-level gnus-thread-indent-level)
2767       (while (>= n 0)
2768         (aset gnus-thread-indent-array n
2769               (make-string (* n gnus-thread-indent-level) ? ))
2770         (setq n (1- n))))))
2771
2772 (defun gnus-update-summary-mark-positions ()
2773   "Compute where the summary marks are to go."
2774   (save-excursion
2775     (when (gnus-buffer-exists-p gnus-summary-buffer)
2776       (set-buffer gnus-summary-buffer))
2777     (let ((gnus-replied-mark 129)
2778           (gnus-score-below-mark 130)
2779           (gnus-score-over-mark 130)
2780           (gnus-download-mark 131)
2781           (spec gnus-summary-line-format-spec)
2782           gnus-visual pos)
2783       (save-excursion
2784         (gnus-set-work-buffer)
2785         (let ((gnus-summary-line-format-spec spec)
2786               (gnus-newsgroup-downloadable '((0 . t))))
2787           (gnus-summary-insert-line
2788            [0 "" "" "" "" "" 0 0 "" nil]  0 nil 128 t nil "" nil 1)
2789           (goto-char (point-min))
2790           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2791                                              (- (point) 2)))))
2792           (goto-char (point-min))
2793           (push (cons 'replied (and (search-forward "\201" nil t)
2794                                     (- (point) 2)))
2795                 pos)
2796           (goto-char (point-min))
2797           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2798                 pos)
2799           (goto-char (point-min))
2800           (push (cons 'download
2801                       (and (search-forward "\203" nil t) (- (point) 2)))
2802                 pos)))
2803       (setq gnus-summary-mark-positions pos))))
2804
2805 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2806   "Insert a dummy root in the summary buffer."
2807   (beginning-of-line)
2808   (gnus-add-text-properties
2809    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2810    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2811
2812 (defun gnus-summary-from-or-to-or-newsgroups (header)
2813   (let ((to (cdr (assq 'To (mail-header-extra header))))
2814         (newsgroups (cdr (assq 'Newsgroups (mail-header-extra header))))
2815         (mail-parse-charset gnus-newsgroup-charset)
2816         (mail-parse-ignored-charsets
2817          (save-excursion (set-buffer gnus-summary-buffer)
2818                          gnus-newsgroup-ignored-charsets)))
2819     (cond
2820      ((and to
2821            gnus-ignored-from-addresses
2822            (string-match gnus-ignored-from-addresses
2823                          (mail-header-from header)))
2824       (concat "-> "
2825               (or (car (funcall gnus-extract-address-components
2826                                 (funcall
2827                                  gnus-decode-encoded-word-function to)))
2828                   (funcall gnus-decode-encoded-word-function to))))
2829      ((and newsgroups
2830            gnus-ignored-from-addresses
2831            (string-match gnus-ignored-from-addresses
2832                          (mail-header-from header)))
2833       (concat "=> " newsgroups))
2834      (t
2835       (or (car (funcall gnus-extract-address-components
2836                         (mail-header-from header)))
2837           (mail-header-from header))))))
2838
2839 (defun gnus-summary-insert-line (gnus-tmp-header
2840                                  gnus-tmp-level gnus-tmp-current
2841                                  gnus-tmp-unread gnus-tmp-replied
2842                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2843                                  &optional gnus-tmp-dummy gnus-tmp-score
2844                                  gnus-tmp-process)
2845   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2846          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2847          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2848          (gnus-tmp-score-char
2849           (if (or (null gnus-summary-default-score)
2850                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2851                       gnus-summary-zcore-fuzz))
2852               ?  ;Whitespace
2853             (if (< gnus-tmp-score gnus-summary-default-score)
2854                 gnus-score-below-mark gnus-score-over-mark)))
2855          (gnus-tmp-replied
2856           (cond (gnus-tmp-process gnus-process-mark)
2857                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2858                  gnus-cached-mark)
2859                 (gnus-tmp-replied gnus-replied-mark)
2860                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2861                  gnus-saved-mark)
2862                 (t gnus-no-mark)))
2863          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2864          (gnus-tmp-name
2865           (cond
2866            ((string-match "<[^>]+> *$" gnus-tmp-from)
2867             (let ((beg (match-beginning 0)))
2868               (or (and (string-match "^\".+\"" gnus-tmp-from)
2869                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2870                   (substring gnus-tmp-from 0 beg))))
2871            ((string-match "(.+)" gnus-tmp-from)
2872             (substring gnus-tmp-from
2873                        (1+ (match-beginning 0)) (1- (match-end 0))))
2874            (t gnus-tmp-from)))
2875          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2876          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2877          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2878          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2879          (buffer-read-only nil))
2880     (when (string= gnus-tmp-name "")
2881       (setq gnus-tmp-name gnus-tmp-from))
2882     (unless (numberp gnus-tmp-lines)
2883       (setq gnus-tmp-lines 0))
2884     (gnus-put-text-property
2885      (point)
2886      (progn (eval gnus-summary-line-format-spec) (point))
2887      'gnus-number gnus-tmp-number)
2888     (when (gnus-visual-p 'summary-highlight 'highlight)
2889       (forward-line -1)
2890       (gnus-run-hooks 'gnus-summary-update-hook)
2891       (forward-line 1))))
2892
2893 (defun gnus-summary-update-line (&optional dont-update)
2894   "Update summary line after change."
2895   (when (and gnus-summary-default-score
2896              (not gnus-summary-inhibit-highlight))
2897     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
2898            (article (gnus-summary-article-number))
2899            (score (gnus-summary-article-score article)))
2900       (unless dont-update
2901         (if (and gnus-summary-mark-below
2902                  (< (gnus-summary-article-score)
2903                     gnus-summary-mark-below))
2904             ;; This article has a low score, so we mark it as read.
2905             (when (memq article gnus-newsgroup-unreads)
2906               (gnus-summary-mark-article-as-read gnus-low-score-mark))
2907           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
2908             ;; This article was previously marked as read on account
2909             ;; of a low score, but now it has risen, so we mark it as
2910             ;; unread.
2911             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
2912         (gnus-summary-update-mark
2913          (if (or (null gnus-summary-default-score)
2914                  (<= (abs (- score gnus-summary-default-score))
2915                      gnus-summary-zcore-fuzz))
2916              ?  ;Whitespace
2917            (if (< score gnus-summary-default-score)
2918                gnus-score-below-mark gnus-score-over-mark))
2919          'score))
2920       ;; Do visual highlighting.
2921       (when (gnus-visual-p 'summary-highlight 'highlight)
2922         (gnus-run-hooks 'gnus-summary-update-hook)))))
2923
2924 (defvar gnus-tmp-new-adopts nil)
2925
2926 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
2927   "Return the number of articles in THREAD.
2928 This may be 0 in some cases -- if none of the articles in
2929 the thread are to be displayed."
2930   (let* ((number
2931           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
2932           (cond
2933            ((not (listp thread))
2934             1)
2935            ((and (consp thread) (cdr thread))
2936             (apply
2937              '+ 1 (mapcar
2938                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
2939            ((null thread)
2940             1)
2941            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
2942             1)
2943            (t 0))))
2944     (when (and level (zerop level) gnus-tmp-new-adopts)
2945       (incf number
2946             (apply '+ (mapcar
2947                        'gnus-summary-number-of-articles-in-thread
2948                        gnus-tmp-new-adopts))))
2949     (if char
2950         (if (> number 1) gnus-not-empty-thread-mark
2951           gnus-empty-thread-mark)
2952       number)))
2953
2954 (defun gnus-summary-set-local-parameters (group)
2955   "Go through the local params of GROUP and set all variable specs in that list."
2956   (let ((params (gnus-group-find-parameter group))
2957         elem)
2958     (while params
2959       (setq elem (car params)
2960             params (cdr params))
2961       (and (consp elem)                 ; Has to be a cons.
2962            (consp (cdr elem))           ; The cdr has to be a list.
2963            (symbolp (car elem))         ; Has to be a symbol in there.
2964            (not (memq (car elem) '(quit-config))) ; Ignore quit-config.
2965            (ignore-errors               ; So we set it.
2966              (make-local-variable (car elem))
2967              (set (car elem) (eval (nth 1 elem))))))))
2968
2969 (defun gnus-summary-read-group (group &optional show-all no-article
2970                                       kill-buffer no-display backward
2971                                       select-articles)
2972   "Start reading news in newsgroup GROUP.
2973 If SHOW-ALL is non-nil, already read articles are also listed.
2974 If NO-ARTICLE is non-nil, no article is selected initially.
2975 If NO-DISPLAY, don't generate a summary buffer."
2976   (let (result)
2977     (while (and group
2978                 (null (setq result
2979                             (let ((gnus-auto-select-next nil))
2980                               (or (gnus-summary-read-group-1
2981                                    group show-all no-article
2982                                    kill-buffer no-display
2983                                    select-articles)
2984                                   (setq show-all nil
2985                                         select-articles nil)))))
2986                 (eq gnus-auto-select-next 'quietly))
2987       (set-buffer gnus-group-buffer)
2988       ;; The entry function called above goes to the next
2989       ;; group automatically, so we go two groups back
2990       ;; if we are searching for the previous group.
2991       (when backward
2992         (gnus-group-prev-unread-group 2))
2993       (if (not (equal group (gnus-group-group-name)))
2994           (setq group (gnus-group-group-name))
2995         (setq group nil)))
2996     result))
2997
2998 (defun gnus-summary-read-group-1 (group show-all no-article
2999                                         kill-buffer no-display
3000                                         &optional select-articles)
3001   ;; Killed foreign groups can't be entered.
3002   ;;  (when (and (not (gnus-group-native-p group))
3003   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3004   ;;    (error "Dead non-native groups can't be entered"))
3005   (gnus-message 5 "Retrieving newsgroup: %s..." 
3006                 (gnus-group-decoded-name group))
3007   (let* ((new-group (gnus-summary-setup-buffer group))
3008          (quit-config (gnus-group-quit-config group))
3009          (did-select (and new-group (gnus-select-newsgroup
3010                                      group show-all select-articles))))
3011     (cond
3012      ;; This summary buffer exists already, so we just select it.
3013      ((not new-group)
3014       (gnus-set-global-variables)
3015       (when kill-buffer
3016         (gnus-kill-or-deaden-summary kill-buffer))
3017       (gnus-configure-windows 'summary 'force)
3018       (gnus-set-mode-line 'summary)
3019       (gnus-summary-position-point)
3020       (message "")
3021       t)
3022      ;; We couldn't select this group.
3023      ((null did-select)
3024       (when (and (eq major-mode 'gnus-summary-mode)
3025                  (not (equal (current-buffer) kill-buffer)))
3026         (kill-buffer (current-buffer))
3027         (if (not quit-config)
3028             (progn
3029               ;; Update the info -- marks might need to be removed,
3030               ;; for instance.
3031               (gnus-summary-update-info)
3032               (set-buffer gnus-group-buffer)
3033               (gnus-group-jump-to-group group)
3034               (gnus-group-next-unread-group 1))
3035           (gnus-handle-ephemeral-exit quit-config)))
3036       (let ((grpinfo (gnus-get-info group)))
3037         (if (null (gnus-info-read grpinfo))
3038             (gnus-message 3 "Group %s contains no messages" 
3039                           (gnus-group-decoded-name group))
3040           (gnus-message 3 "Can't select group")))
3041       nil)
3042      ;; The user did a `C-g' while prompting for number of articles,
3043      ;; so we exit this group.
3044      ((eq did-select 'quit)
3045       (and (eq major-mode 'gnus-summary-mode)
3046            (not (equal (current-buffer) kill-buffer))
3047            (kill-buffer (current-buffer)))
3048       (when kill-buffer
3049         (gnus-kill-or-deaden-summary kill-buffer))
3050       (if (not quit-config)
3051           (progn
3052             (set-buffer gnus-group-buffer)
3053             (gnus-group-jump-to-group group)
3054             (gnus-group-next-unread-group 1)
3055             (gnus-configure-windows 'group 'force))
3056         (gnus-handle-ephemeral-exit quit-config))
3057       ;; Finally signal the quit.
3058       (signal 'quit nil))
3059      ;; The group was successfully selected.
3060      (t
3061       (gnus-set-global-variables)
3062       ;; Save the active value in effect when the group was entered.
3063       (setq gnus-newsgroup-active
3064             (gnus-copy-sequence
3065              (gnus-active gnus-newsgroup-name)))
3066       ;; You can change the summary buffer in some way with this hook.
3067       (gnus-run-hooks 'gnus-select-group-hook)
3068       (gnus-update-format-specifications
3069        nil 'summary 'summary-mode 'summary-dummy)
3070       (gnus-update-summary-mark-positions)
3071       ;; Do score processing.
3072       (when gnus-use-scoring
3073         (gnus-possibly-score-headers))
3074       ;; Check whether to fill in the gaps in the threads.
3075       (when gnus-build-sparse-threads
3076         (gnus-build-sparse-threads))
3077       ;; Find the initial limit.
3078       (if gnus-show-threads
3079           (if show-all
3080               (let ((gnus-newsgroup-dormant nil))
3081                 (gnus-summary-initial-limit show-all))
3082             (gnus-summary-initial-limit show-all))
3083         ;; When untreaded, all articles are always shown.
3084         (setq gnus-newsgroup-limit
3085               (mapcar
3086                (lambda (header) (mail-header-number header))
3087                gnus-newsgroup-headers)))
3088       ;; Generate the summary buffer.
3089       (unless no-display
3090         (gnus-summary-prepare))
3091       (when gnus-use-trees
3092         (gnus-tree-open group)
3093         (setq gnus-summary-highlight-line-function
3094               'gnus-tree-highlight-article))
3095       ;; If the summary buffer is empty, but there are some low-scored
3096       ;; articles or some excluded dormants, we include these in the
3097       ;; buffer.
3098       (when (and (zerop (buffer-size))
3099                  (not no-display))
3100         (cond (gnus-newsgroup-dormant
3101                (gnus-summary-limit-include-dormant))
3102               ((and gnus-newsgroup-scored show-all)
3103                (gnus-summary-limit-include-expunged t))))
3104       ;; Function `gnus-apply-kill-file' must be called in this hook.
3105       (gnus-run-hooks 'gnus-apply-kill-hook)
3106       (if (and (zerop (buffer-size))
3107                (not no-display))
3108           (progn
3109             ;; This newsgroup is empty.
3110             (gnus-summary-catchup-and-exit nil t)
3111             (gnus-message 6 "No unread news")
3112             (when kill-buffer
3113               (gnus-kill-or-deaden-summary kill-buffer))
3114             ;; Return nil from this function.
3115             nil)
3116         ;; Hide conversation thread subtrees.  We cannot do this in
3117         ;; gnus-summary-prepare-hook since kill processing may not
3118         ;; work with hidden articles.
3119         (and gnus-show-threads
3120              gnus-thread-hide-subtree
3121              (gnus-summary-hide-all-threads))
3122         (when kill-buffer
3123           (gnus-kill-or-deaden-summary kill-buffer))
3124         ;; Show first unread article if requested.
3125         (if (and (not no-article)
3126                  (not no-display)
3127                  gnus-newsgroup-unreads
3128                  gnus-auto-select-first)
3129             (progn
3130               (gnus-configure-windows 'summary)
3131               (cond
3132                ((eq gnus-auto-select-first 'best)
3133                 (gnus-summary-best-unread-article))
3134                ((eq gnus-auto-select-first t)
3135                 (gnus-summary-first-unread-article))
3136                ((gnus-functionp gnus-auto-select-first)
3137                 (funcall gnus-auto-select-first))))
3138           ;; Don't select any articles, just move point to the first
3139           ;; article in the group.
3140           (goto-char (point-min))
3141           (gnus-summary-position-point)
3142           (gnus-configure-windows 'summary 'force)
3143           (gnus-set-mode-line 'summary))
3144         (when (get-buffer-window gnus-group-buffer t)
3145           ;; Gotta use windows, because recenter does weird stuff if
3146           ;; the current buffer ain't the displayed window.
3147           (let ((owin (selected-window)))
3148             (select-window (get-buffer-window gnus-group-buffer t))
3149             (when (gnus-group-goto-group group)
3150               (recenter))
3151             (select-window owin)))
3152         ;; Mark this buffer as "prepared".
3153         (setq gnus-newsgroup-prepared t)
3154         (gnus-run-hooks 'gnus-summary-prepared-hook)
3155         t)))))
3156
3157 (defun gnus-summary-prepare ()
3158   "Generate the summary buffer."
3159   (interactive)
3160   (let ((buffer-read-only nil))
3161     (erase-buffer)
3162     (setq gnus-newsgroup-data nil
3163           gnus-newsgroup-data-reverse nil)
3164     (gnus-run-hooks 'gnus-summary-generate-hook)
3165     ;; Generate the buffer, either with threads or without.
3166     (when gnus-newsgroup-headers
3167       (gnus-summary-prepare-threads
3168        (if gnus-show-threads
3169            (gnus-sort-gathered-threads
3170             (funcall gnus-summary-thread-gathering-function
3171                      (gnus-sort-threads
3172                       (gnus-cut-threads (gnus-make-threads)))))
3173          ;; Unthreaded display.
3174          (gnus-sort-articles gnus-newsgroup-headers))))
3175     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3176     ;; Call hooks for modifying summary buffer.
3177     (goto-char (point-min))
3178     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3179
3180 (defsubst gnus-general-simplify-subject (subject)
3181   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3182   (setq subject
3183         (cond
3184          ;; Truncate the subject.
3185          (gnus-simplify-subject-functions
3186           (gnus-map-function gnus-simplify-subject-functions subject))
3187          ((numberp gnus-summary-gather-subject-limit)
3188           (setq subject (gnus-simplify-subject-re subject))
3189           (if (> (length subject) gnus-summary-gather-subject-limit)
3190               (substring subject 0 gnus-summary-gather-subject-limit)
3191             subject))
3192          ;; Fuzzily simplify it.
3193          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3194           (gnus-simplify-subject-fuzzy subject))
3195          ;; Just remove the leading "Re:".
3196          (t
3197           (gnus-simplify-subject-re subject))))
3198
3199   (if (and gnus-summary-gather-exclude-subject
3200            (string-match gnus-summary-gather-exclude-subject subject))
3201       nil                               ; This article shouldn't be gathered
3202     subject))
3203
3204 (defun gnus-summary-simplify-subject-query ()
3205   "Query where the respool algorithm would put this article."
3206   (interactive)
3207   (gnus-summary-select-article)
3208   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3209
3210 (defun gnus-gather-threads-by-subject (threads)
3211   "Gather threads by looking at Subject headers."
3212   (if (not gnus-summary-make-false-root)
3213       threads
3214     (let ((hashtb (gnus-make-hashtable 1024))
3215           (prev threads)
3216           (result threads)
3217           subject hthread whole-subject)
3218       (while threads
3219         (setq subject (gnus-general-simplify-subject
3220                        (setq whole-subject (mail-header-subject
3221                                             (caar threads)))))
3222         (when subject
3223           (if (setq hthread (gnus-gethash subject hashtb))
3224               (progn
3225                 ;; We enter a dummy root into the thread, if we
3226                 ;; haven't done that already.
3227                 (unless (stringp (caar hthread))
3228                   (setcar hthread (list whole-subject (car hthread))))
3229                 ;; We add this new gathered thread to this gathered
3230                 ;; thread.
3231                 (setcdr (car hthread)
3232                         (nconc (cdar hthread) (list (car threads))))
3233                 ;; Remove it from the list of threads.
3234                 (setcdr prev (cdr threads))
3235                 (setq threads prev))
3236             ;; Enter this thread into the hash table.
3237             (gnus-sethash subject threads hashtb)))
3238         (setq prev threads)
3239         (setq threads (cdr threads)))
3240       result)))
3241
3242 (defun gnus-gather-threads-by-references (threads)
3243   "Gather threads by looking at References headers."
3244   (let ((idhashtb (gnus-make-hashtable 1024))
3245         (thhashtb (gnus-make-hashtable 1024))
3246         (prev threads)
3247         (result threads)
3248         ids references id gthread gid entered ref)
3249     (while threads
3250       (when (setq references (mail-header-references (caar threads)))
3251         (setq id (mail-header-id (caar threads))
3252               ids (gnus-split-references references)
3253               entered nil)
3254         (while (setq ref (pop ids))
3255           (setq ids (delete ref ids))
3256           (if (not (setq gid (gnus-gethash ref idhashtb)))
3257               (progn
3258                 (gnus-sethash ref id idhashtb)
3259                 (gnus-sethash id threads thhashtb))
3260             (setq gthread (gnus-gethash gid thhashtb))
3261             (unless entered
3262               ;; We enter a dummy root into the thread, if we
3263               ;; haven't done that already.
3264               (unless (stringp (caar gthread))
3265                 (setcar gthread (list (mail-header-subject (caar gthread))
3266                                       (car gthread))))
3267               ;; We add this new gathered thread to this gathered
3268               ;; thread.
3269               (setcdr (car gthread)
3270                       (nconc (cdar gthread) (list (car threads)))))
3271             ;; Add it into the thread hash table.
3272             (gnus-sethash id gthread thhashtb)
3273             (setq entered t)
3274             ;; Remove it from the list of threads.
3275             (setcdr prev (cdr threads))
3276             (setq threads prev))))
3277       (setq prev threads)
3278       (setq threads (cdr threads)))
3279     result))
3280
3281 (defun gnus-sort-gathered-threads (threads)
3282   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3283   (let ((result threads))
3284     (while threads
3285       (when (stringp (caar threads))
3286         (setcdr (car threads)
3287                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3288       (setq threads (cdr threads)))
3289     result))
3290
3291 (defun gnus-thread-loop-p (root thread)
3292   "Say whether ROOT is in THREAD."
3293   (let ((stack (list thread))
3294         (infloop 0)
3295         th)
3296     (while (setq thread (pop stack))
3297       (setq th (cdr thread))
3298       (while (and th
3299                   (not (eq (caar th) root)))
3300         (pop th))
3301       (if th
3302           ;; We have found a loop.
3303           (let (ref-dep)
3304             (setcdr thread (delq (car th) (cdr thread)))
3305             (if (boundp (setq ref-dep (intern "none"
3306                                               gnus-newsgroup-dependencies)))
3307                 (setcdr (symbol-value ref-dep)
3308                         (nconc (cdr (symbol-value ref-dep))
3309                                (list (car th))))
3310               (set ref-dep (list nil (car th))))
3311             (setq infloop 1
3312                   stack nil))
3313         ;; Push all the subthreads onto the stack.
3314         (push (cdr thread) stack)))
3315     infloop))
3316
3317 (defun gnus-make-threads ()
3318   "Go through the dependency hashtb and find the roots.  Return all threads."
3319   (let (threads)
3320     (while (catch 'infloop
3321              (mapatoms
3322               (lambda (refs)
3323                 ;; Deal with self-referencing References loops.
3324                 (when (and (car (symbol-value refs))
3325                            (not (zerop
3326                                  (apply
3327                                   '+
3328                                   (mapcar
3329                                    (lambda (thread)
3330                                      (gnus-thread-loop-p
3331                                       (car (symbol-value refs)) thread))
3332                                    (cdr (symbol-value refs)))))))
3333                   (setq threads nil)
3334                   (throw 'infloop t))
3335                 (unless (car (symbol-value refs))
3336                   ;; These threads do not refer back to any other articles,
3337                   ;; so they're roots.
3338                   (setq threads (append (cdr (symbol-value refs)) threads))))
3339               gnus-newsgroup-dependencies)))
3340     threads))
3341
3342 ;; Build the thread tree.
3343 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3344   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3345
3346 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3347 if it was already present.
3348
3349 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3350 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3351 Message-IDs will be renamed be renamed to a unique Message-ID before
3352 being entered.
3353
3354 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3355   (let* ((id (mail-header-id header))
3356          (id-dep (and id (intern id dependencies)))
3357          ref ref-dep ref-header)
3358     ;; Enter this `header' in the `dependencies' table.
3359     (cond
3360      ((not id-dep)
3361       (setq header nil))
3362      ;; The first two cases do the normal part: enter a new `header'
3363      ;; in the `dependencies' table.
3364      ((not (boundp id-dep))
3365       (set id-dep (list header)))
3366      ((null (car (symbol-value id-dep)))
3367       (setcar (symbol-value id-dep) header))
3368
3369      ;; From here the `header' was already present in the
3370      ;; `dependencies' table.
3371      (force-new
3372       ;; Overrides an existing entry;
3373       ;; just set the header part of the entry.
3374       (setcar (symbol-value id-dep) header))
3375
3376      ;; Renames the existing `header' to a unique Message-ID.
3377      ((not gnus-summary-ignore-duplicates)
3378       ;; An article with this Message-ID has already been seen.
3379       ;; We rename the Message-ID.
3380       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3381            (list header))
3382       (mail-header-set-id header id))
3383
3384      ;; The last case ignores an existing entry, except it adds any
3385      ;; additional Xrefs (in case the two articles came from different
3386      ;; servers.
3387      ;; Also sets `header' to `nil' meaning that the `dependencies'
3388      ;; table was *not* modified.
3389      (t
3390       (mail-header-set-xref
3391        (car (symbol-value id-dep))
3392        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3393                    "")
3394                (or (mail-header-xref header) "")))
3395       (setq header nil)))
3396
3397     (when header
3398       ;; First check if that we are not creating a References loop.
3399       (setq ref (gnus-parent-id (mail-header-references header)))
3400       (while (and ref
3401                   (setq ref-dep (intern-soft ref dependencies))
3402                   (boundp ref-dep)
3403                   (setq ref-header (car (symbol-value ref-dep))))
3404         (if (string= id ref)
3405             ;; Yuk!  This is a reference loop.  Make the article be a
3406             ;; root article.
3407             (progn
3408               (mail-header-set-references (car (symbol-value id-dep)) "none")
3409               (setq ref nil))
3410           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3411       (setq ref (gnus-parent-id (mail-header-references header)))
3412       (setq ref-dep (intern (or ref "none") dependencies))
3413       (if (boundp ref-dep)
3414           (setcdr (symbol-value ref-dep)
3415                   (nconc (cdr (symbol-value ref-dep))
3416                          (list (symbol-value id-dep))))
3417         (set ref-dep (list nil (symbol-value id-dep)))))
3418     header))
3419
3420 (defun gnus-build-sparse-threads ()
3421   (let ((headers gnus-newsgroup-headers)
3422         (mail-parse-charset gnus-newsgroup-charset)
3423         (gnus-summary-ignore-duplicates t)
3424         header references generation relations
3425         subject child end new-child date)
3426     ;; First we create an alist of generations/relations, where
3427     ;; generations is how much we trust the relation, and the relation
3428     ;; is parent/child.
3429     (gnus-message 7 "Making sparse threads...")
3430     (save-excursion
3431       (nnheader-set-temp-buffer " *gnus sparse threads*")
3432       (while (setq header (pop headers))
3433         (when (and (setq references (mail-header-references header))
3434                    (not (string= references "")))
3435           (insert references)
3436           (setq child (mail-header-id header)
3437                 subject (mail-header-subject header)
3438                 date (mail-header-date header)
3439                 generation 0)
3440           (while (search-backward ">" nil t)
3441             (setq end (1+ (point)))
3442             (when (search-backward "<" nil t)
3443               (setq new-child (buffer-substring (point) end))
3444               (push (list (incf generation)
3445                           child (setq child new-child)
3446                           subject date)
3447                     relations)))
3448           (when child
3449             (push (list (1+ generation) child nil subject) relations))
3450           (erase-buffer)))
3451       (kill-buffer (current-buffer)))
3452     ;; Sort over trustworthiness.
3453     (mapcar
3454      (lambda (relation)
3455        (when (gnus-dependencies-add-header
3456               (make-full-mail-header
3457                gnus-reffed-article-number
3458                (nth 3 relation) "" (or (nth 4 relation) "")
3459                (nth 1 relation)
3460                (or (nth 2 relation) "") 0 0 "")
3461               gnus-newsgroup-dependencies nil)
3462          (push gnus-reffed-article-number gnus-newsgroup-limit)
3463          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3464          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3465                gnus-newsgroup-reads)
3466          (decf gnus-reffed-article-number)))
3467      (sort relations 'car-less-than-car))
3468     (gnus-message 7 "Making sparse threads...done")))
3469
3470 (defun gnus-build-old-threads ()
3471   ;; Look at all the articles that refer back to old articles, and
3472   ;; fetch the headers for the articles that aren't there.  This will
3473   ;; build complete threads - if the roots haven't been expired by the
3474   ;; server, that is.
3475   (let ((mail-parse-charset gnus-newsgroup-charset)
3476         id heads)
3477     (mapatoms
3478      (lambda (refs)
3479        (when (not (car (symbol-value refs)))
3480          (setq heads (cdr (symbol-value refs)))
3481          (while heads
3482            (if (memq (mail-header-number (caar heads))
3483                      gnus-newsgroup-dormant)
3484                (setq heads (cdr heads))
3485              (setq id (symbol-name refs))
3486              (while (and (setq id (gnus-build-get-header id))
3487                          (not (car (gnus-id-to-thread id)))))
3488              (setq heads nil)))))
3489      gnus-newsgroup-dependencies)))
3490
3491 ;; This function has to be called with point after the article number
3492 ;; on the beginning of the line.
3493 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3494   (let ((eol (gnus-point-at-eol))
3495         (buffer (current-buffer))
3496         header)
3497
3498     ;; overview: [num subject from date id refs chars lines misc]
3499     (unwind-protect
3500         (progn
3501           (narrow-to-region (point) eol)
3502           (unless (eobp)
3503             (forward-char))
3504
3505           (setq header
3506                 (make-full-mail-header
3507                  number                 ; number
3508                  (funcall gnus-decode-encoded-word-function
3509                           (nnheader-nov-field)) ; subject
3510                  (funcall gnus-decode-encoded-word-function
3511                           (nnheader-nov-field)) ; from
3512                  (nnheader-nov-field)   ; date
3513                  (nnheader-nov-read-message-id) ; id
3514                  (nnheader-nov-field)   ; refs
3515                  (nnheader-nov-read-integer) ; chars
3516                  (nnheader-nov-read-integer) ; lines
3517                  (unless (eobp)
3518                    (if (looking-at "Xref: ")
3519                        (goto-char (match-end 0)))
3520                    (nnheader-nov-field)) ; Xref
3521                  (nnheader-nov-parse-extra)))) ; extra
3522
3523       (widen))
3524
3525     (when gnus-alter-header-function
3526       (funcall gnus-alter-header-function header))
3527     (gnus-dependencies-add-header header dependencies force-new)))
3528
3529 (defun gnus-build-get-header (id)
3530   "Look through the buffer of NOV lines and find the header to ID.
3531 Enter this line into the dependencies hash table, and return
3532 the id of the parent article (if any)."
3533   (let ((deps gnus-newsgroup-dependencies)
3534         found header)
3535     (prog1
3536         (save-excursion
3537           (set-buffer nntp-server-buffer)
3538           (let ((case-fold-search nil))
3539             (goto-char (point-min))
3540             (while (and (not found)
3541                         (search-forward id nil t))
3542               (beginning-of-line)
3543               (setq found (looking-at
3544                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3545                                    (regexp-quote id))))
3546               (or found (beginning-of-line 2)))
3547             (when found
3548               (beginning-of-line)
3549               (and
3550                (setq header (gnus-nov-parse-line
3551                              (read (current-buffer)) deps))
3552                (gnus-parent-id (mail-header-references header))))))
3553       (when header
3554         (let ((number (mail-header-number header)))
3555           (push number gnus-newsgroup-limit)
3556           (push header gnus-newsgroup-headers)
3557           (if (memq number gnus-newsgroup-unselected)
3558               (progn
3559                 (push number gnus-newsgroup-unreads)
3560                 (setq gnus-newsgroup-unselected
3561                       (delq number gnus-newsgroup-unselected)))
3562             (push number gnus-newsgroup-ancient)))))))
3563
3564 (defun gnus-build-all-threads ()
3565   "Read all the headers."
3566   (let ((gnus-summary-ignore-duplicates t)
3567         (mail-parse-charset gnus-newsgroup-charset)
3568         (dependencies gnus-newsgroup-dependencies)
3569         header article)
3570     (save-excursion
3571       (set-buffer nntp-server-buffer)
3572       (let ((case-fold-search nil))
3573         (goto-char (point-min))
3574         (while (not (eobp))
3575           (ignore-errors
3576             (setq article (read (current-buffer))
3577                   header (gnus-nov-parse-line article dependencies)))
3578           (when header
3579             (save-excursion
3580               (set-buffer gnus-summary-buffer)
3581               (push header gnus-newsgroup-headers)
3582               (if (memq (setq article (mail-header-number header))
3583                         gnus-newsgroup-unselected)
3584                   (progn
3585                     (push article gnus-newsgroup-unreads)
3586                     (setq gnus-newsgroup-unselected
3587                           (delq article gnus-newsgroup-unselected)))
3588                 (push article gnus-newsgroup-ancient)))
3589             (forward-line 1)))))))
3590
3591 (defun gnus-summary-update-article-line (article header)
3592   "Update the line for ARTICLE using HEADERS."
3593   (let* ((id (mail-header-id header))
3594          (thread (gnus-id-to-thread id)))
3595     (unless thread
3596       (error "Article in no thread"))
3597     ;; Update the thread.
3598     (setcar thread header)
3599     (gnus-summary-goto-subject article)
3600     (let* ((datal (gnus-data-find-list article))
3601            (data (car datal))
3602            (length (when (cdr datal)
3603                      (- (gnus-data-pos data)
3604                         (gnus-data-pos (cadr datal)))))
3605            (buffer-read-only nil)
3606            (level (gnus-summary-thread-level)))
3607       (gnus-delete-line)
3608       (gnus-summary-insert-line
3609        header level nil (gnus-article-mark article)
3610        (memq article gnus-newsgroup-replied)
3611        (memq article gnus-newsgroup-expirable)
3612        ;; Only insert the Subject string when it's different
3613        ;; from the previous Subject string.
3614        (if (and
3615             gnus-show-threads
3616             (gnus-subject-equal
3617              (condition-case ()
3618                  (mail-header-subject
3619                   (gnus-data-header
3620                    (cadr
3621                     (gnus-data-find-list
3622                      article
3623                      (gnus-data-list t)))))
3624                ;; Error on the side of excessive subjects.
3625                (error ""))
3626              (mail-header-subject header)))
3627            ""
3628          (mail-header-subject header))
3629        nil (cdr (assq article gnus-newsgroup-scored))
3630        (memq article gnus-newsgroup-processable))
3631       (when length
3632         (gnus-data-update-list
3633          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3634
3635 (defun gnus-summary-update-article (article &optional iheader)
3636   "Update ARTICLE in the summary buffer."
3637   (set-buffer gnus-summary-buffer)
3638   (let* ((header (gnus-summary-article-header article))
3639          (id (mail-header-id header))
3640          (data (gnus-data-find article))
3641          (thread (gnus-id-to-thread id))
3642          (references (mail-header-references header))
3643          (parent
3644           (gnus-id-to-thread
3645            (or (gnus-parent-id
3646                 (when (and references
3647                            (not (equal "" references)))
3648                   references))
3649                "none")))
3650          (buffer-read-only nil)
3651          (old (car thread)))
3652     (when thread
3653       (unless iheader
3654         (setcar thread nil)
3655         (when parent
3656           (delq thread parent)))
3657       (if (gnus-summary-insert-subject id header)
3658           ;; Set the (possibly) new article number in the data structure.
3659           (gnus-data-set-number data (gnus-id-to-article id))
3660         (setcar thread old)
3661         nil))))
3662
3663 (defun gnus-rebuild-thread (id &optional line)
3664   "Rebuild the thread containing ID.
3665 If LINE, insert the rebuilt thread starting on line LINE."
3666   (let ((buffer-read-only nil)
3667         old-pos current thread data)
3668     (if (not gnus-show-threads)
3669         (setq thread (list (car (gnus-id-to-thread id))))
3670       ;; Get the thread this article is part of.
3671       (setq thread (gnus-remove-thread id)))
3672     (setq old-pos (gnus-point-at-bol))
3673     (setq current (save-excursion
3674                     (and (zerop (forward-line -1))
3675                          (gnus-summary-article-number))))
3676     ;; If this is a gathered thread, we have to go some re-gathering.
3677     (when (stringp (car thread))
3678       (let ((subject (car thread))
3679             roots thr)
3680         (setq thread (cdr thread))
3681         (while thread
3682           (unless (memq (setq thr (gnus-id-to-thread
3683                                    (gnus-root-id
3684                                     (mail-header-id (caar thread)))))
3685                         roots)
3686             (push thr roots))
3687           (setq thread (cdr thread)))
3688         ;; We now have all (unique) roots.
3689         (if (= (length roots) 1)
3690             ;; All the loose roots are now one solid root.
3691             (setq thread (car roots))
3692           (setq thread (cons subject (gnus-sort-threads roots))))))
3693     (let (threads)
3694       ;; We then insert this thread into the summary buffer.
3695       (when line
3696         (goto-char (point-min))
3697         (forward-line (1- line)))
3698       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3699         (if gnus-show-threads
3700             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3701           (gnus-summary-prepare-unthreaded thread))
3702         (setq data (nreverse gnus-newsgroup-data))
3703         (setq threads gnus-newsgroup-threads))
3704       ;; We splice the new data into the data structure.
3705       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3706       ;;!!! then we want to insert at the beginning of the buffer.
3707       ;;!!! That happens to be true with Gnus now, but that may
3708       ;;!!! change in the future.  Perhaps.
3709       (gnus-data-enter-list
3710        (if line nil current) data (- (point) old-pos))
3711       (setq gnus-newsgroup-threads
3712             (nconc threads gnus-newsgroup-threads))
3713       (gnus-data-compute-positions))))
3714
3715 (defun gnus-number-to-header (number)
3716   "Return the header for article NUMBER."
3717   (let ((headers gnus-newsgroup-headers))
3718     (while (and headers
3719                 (not (= number (mail-header-number (car headers)))))
3720       (pop headers))
3721     (when headers
3722       (car headers))))
3723
3724 (defun gnus-parent-headers (in-headers &optional generation)
3725   "Return the headers of the GENERATIONeth parent of HEADERS."
3726   (unless generation
3727     (setq generation 1))
3728   (let ((parent t)
3729         (headers in-headers)
3730         references)
3731     (while (and parent
3732                 (not (zerop generation))
3733                 (setq references (mail-header-references headers)))
3734       (setq headers (if (and references
3735                              (setq parent (gnus-parent-id references)))
3736                         (car (gnus-id-to-thread parent))
3737                       nil))
3738       (decf generation))
3739     (and (not (eq headers in-headers))
3740          headers)))
3741
3742 (defun gnus-id-to-thread (id)
3743   "Return the (sub-)thread where ID appears."
3744   (gnus-gethash id gnus-newsgroup-dependencies))
3745
3746 (defun gnus-id-to-article (id)
3747   "Return the article number of ID."
3748   (let ((thread (gnus-id-to-thread id)))
3749     (when (and thread
3750                (car thread))
3751       (mail-header-number (car thread)))))
3752
3753 (defun gnus-id-to-header (id)
3754   "Return the article headers of ID."
3755   (car (gnus-id-to-thread id)))
3756
3757 (defun gnus-article-displayed-root-p (article)
3758   "Say whether ARTICLE is a root(ish) article."
3759   (let ((level (gnus-summary-thread-level article))
3760         (refs (mail-header-references  (gnus-summary-article-header article)))
3761         particle)
3762     (cond
3763      ((null level) nil)
3764      ((zerop level) t)
3765      ((null refs) t)
3766      ((null (gnus-parent-id refs)) t)
3767      ((and (= 1 level)
3768            (null (setq particle (gnus-id-to-article
3769                                  (gnus-parent-id refs))))
3770            (null (gnus-summary-thread-level particle)))))))
3771
3772 (defun gnus-root-id (id)
3773   "Return the id of the root of the thread where ID appears."
3774   (let (last-id prev)
3775     (while (and id (setq prev (car (gnus-id-to-thread id))))
3776       (setq last-id id
3777             id (gnus-parent-id (mail-header-references prev))))
3778     last-id))
3779
3780 (defun gnus-articles-in-thread (thread)
3781   "Return the list of articles in THREAD."
3782   (cons (mail-header-number (car thread))
3783         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3784
3785 (defun gnus-remove-thread (id &optional dont-remove)
3786   "Remove the thread that has ID in it."
3787   (let (headers thread last-id)
3788     ;; First go up in this thread until we find the root.
3789     (setq last-id (gnus-root-id id)
3790           headers (message-flatten-list (gnus-id-to-thread last-id)))
3791     ;; We have now found the real root of this thread.  It might have
3792     ;; been gathered into some loose thread, so we have to search
3793     ;; through the threads to find the thread we wanted.
3794     (let ((threads gnus-newsgroup-threads)
3795           sub)
3796       (while threads
3797         (setq sub (car threads))
3798         (if (stringp (car sub))
3799             ;; This is a gathered thread, so we look at the roots
3800             ;; below it to find whether this article is in this
3801             ;; gathered root.
3802             (progn
3803               (setq sub (cdr sub))
3804               (while sub
3805                 (when (member (caar sub) headers)
3806                   (setq thread (car threads)
3807                         threads nil
3808                         sub nil))
3809                 (setq sub (cdr sub))))
3810           ;; It's an ordinary thread, so we check it.
3811           (when (eq (car sub) (car headers))
3812             (setq thread sub
3813                   threads nil)))
3814         (setq threads (cdr threads)))
3815       ;; If this article is in no thread, then it's a root.
3816       (if thread
3817           (unless dont-remove
3818             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3819         (setq thread (gnus-id-to-thread last-id)))
3820       (when thread
3821         (prog1
3822             thread                      ; We return this thread.
3823           (unless dont-remove
3824             (if (stringp (car thread))
3825                 (progn
3826                   ;; If we use dummy roots, then we have to remove the
3827                   ;; dummy root as well.
3828                   (when (eq gnus-summary-make-false-root 'dummy)
3829                     ;; We go to the dummy root by going to
3830                     ;; the first sub-"thread", and then one line up.
3831                     (gnus-summary-goto-article
3832                      (mail-header-number (caadr thread)))
3833                     (forward-line -1)
3834                     (gnus-delete-line)
3835                     (gnus-data-compute-positions))
3836                   (setq thread (cdr thread))
3837                   (while thread
3838                     (gnus-remove-thread-1 (car thread))
3839                     (setq thread (cdr thread))))
3840               (gnus-remove-thread-1 thread))))))))
3841
3842 (defun gnus-remove-thread-1 (thread)
3843   "Remove the thread THREAD recursively."
3844   (let ((number (mail-header-number (pop thread)))
3845         d)
3846     (setq thread (reverse thread))
3847     (while thread
3848       (gnus-remove-thread-1 (pop thread)))
3849     (when (setq d (gnus-data-find number))
3850       (goto-char (gnus-data-pos d))
3851       (gnus-summary-show-thread)
3852       (gnus-data-remove
3853        number
3854        (- (gnus-point-at-bol)
3855           (prog1
3856               (1+ (gnus-point-at-eol))
3857             (gnus-delete-line)))))))
3858
3859 (defun gnus-sort-threads-1 (threads func)
3860   (sort (mapcar (lambda (thread)
3861                   (cons (car thread)
3862                         (and (cdr thread)
3863                              (gnus-sort-threads-1 (cdr thread) func))))
3864                 threads) func))
3865
3866 (defun gnus-sort-threads (threads)
3867   "Sort THREADS."
3868   (if (not gnus-thread-sort-functions)
3869       threads
3870     (gnus-message 8 "Sorting threads...")
3871     (prog1
3872         (gnus-sort-threads-1
3873          threads
3874          (gnus-make-sort-function gnus-thread-sort-functions))
3875       (gnus-message 8 "Sorting threads...done"))))
3876
3877 (defun gnus-sort-articles (articles)
3878   "Sort ARTICLES."
3879   (when gnus-article-sort-functions
3880     (gnus-message 7 "Sorting articles...")
3881     (prog1
3882         (setq gnus-newsgroup-headers
3883               (sort articles (gnus-make-sort-function
3884                               gnus-article-sort-functions)))
3885       (gnus-message 7 "Sorting articles...done"))))
3886
3887 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
3888 (defmacro gnus-thread-header (thread)
3889   "Return header of first article in THREAD.
3890 Note that THREAD must never, ever be anything else than a variable -
3891 using some other form will lead to serious barfage."
3892   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
3893   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
3894   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
3895         (vector thread) 2))
3896
3897 (defsubst gnus-article-sort-by-number (h1 h2)
3898   "Sort articles by article number."
3899   (< (mail-header-number h1)
3900      (mail-header-number h2)))
3901
3902 (defun gnus-thread-sort-by-number (h1 h2)
3903   "Sort threads by root article number."
3904   (gnus-article-sort-by-number
3905    (gnus-thread-header h1) (gnus-thread-header h2)))
3906
3907 (defsubst gnus-article-sort-by-lines (h1 h2)
3908   "Sort articles by article Lines header."
3909   (< (mail-header-lines h1)
3910      (mail-header-lines h2)))
3911
3912 (defun gnus-thread-sort-by-lines (h1 h2)
3913   "Sort threads by root article Lines header."
3914   (gnus-article-sort-by-lines
3915    (gnus-thread-header h1) (gnus-thread-header h2)))
3916
3917 (defsubst gnus-article-sort-by-chars (h1 h2)
3918   "Sort articles by octet length."
3919   (< (mail-header-chars h1)
3920      (mail-header-chars h2)))
3921
3922 (defun gnus-thread-sort-by-chars (h1 h2)
3923   "Sort threads by root article octet length."
3924   (gnus-article-sort-by-chars
3925    (gnus-thread-header h1) (gnus-thread-header h2)))
3926
3927 (defsubst gnus-article-sort-by-author (h1 h2)
3928   "Sort articles by root author."
3929   (string-lessp
3930    (let ((extract (funcall
3931                    gnus-extract-address-components
3932                    (mail-header-from h1))))
3933      (or (car extract) (cadr extract) ""))
3934    (let ((extract (funcall
3935                    gnus-extract-address-components
3936                    (mail-header-from h2))))
3937      (or (car extract) (cadr extract) ""))))
3938
3939 (defun gnus-thread-sort-by-author (h1 h2)
3940   "Sort threads by root author."
3941   (gnus-article-sort-by-author
3942    (gnus-thread-header h1)  (gnus-thread-header h2)))
3943
3944 (defsubst gnus-article-sort-by-subject (h1 h2)
3945   "Sort articles by root subject."
3946   (string-lessp
3947    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
3948    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
3949
3950 (defun gnus-thread-sort-by-subject (h1 h2)
3951   "Sort threads by root subject."
3952   (gnus-article-sort-by-subject
3953    (gnus-thread-header h1) (gnus-thread-header h2)))
3954
3955 (defsubst gnus-article-sort-by-date (h1 h2)
3956   "Sort articles by root article date."
3957   (time-less-p
3958    (gnus-date-get-time (mail-header-date h1))
3959    (gnus-date-get-time (mail-header-date h2))))
3960
3961 (defun gnus-thread-sort-by-date (h1 h2)
3962   "Sort threads by root article date."
3963   (gnus-article-sort-by-date
3964    (gnus-thread-header h1) (gnus-thread-header h2)))
3965
3966 (defsubst gnus-article-sort-by-score (h1 h2)
3967   "Sort articles by root article score.
3968 Unscored articles will be counted as having a score of zero."
3969   (> (or (cdr (assq (mail-header-number h1)
3970                     gnus-newsgroup-scored))
3971          gnus-summary-default-score 0)
3972      (or (cdr (assq (mail-header-number h2)
3973                     gnus-newsgroup-scored))
3974          gnus-summary-default-score 0)))
3975
3976 (defun gnus-thread-sort-by-score (h1 h2)
3977   "Sort threads by root article score."
3978   (gnus-article-sort-by-score
3979    (gnus-thread-header h1) (gnus-thread-header h2)))
3980
3981 (defun gnus-thread-sort-by-total-score (h1 h2)
3982   "Sort threads by the sum of all scores in the thread.
3983 Unscored articles will be counted as having a score of zero."
3984   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
3985
3986 (defun gnus-thread-total-score (thread)
3987   ;; This function find the total score of THREAD.
3988   (cond ((null thread)
3989          0)
3990         ((consp thread)
3991          (if (stringp (car thread))
3992              (apply gnus-thread-score-function 0
3993                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
3994            (gnus-thread-total-score-1 thread)))
3995         (t
3996          (gnus-thread-total-score-1 (list thread)))))
3997
3998 (defun gnus-thread-total-score-1 (root)
3999   ;; This function find the total score of the thread below ROOT.
4000   (setq root (car root))
4001   (apply gnus-thread-score-function
4002          (or (append
4003               (mapcar 'gnus-thread-total-score
4004                       (cdr (gnus-id-to-thread (mail-header-id root))))
4005               (when (> (mail-header-number root) 0)
4006                 (list (or (cdr (assq (mail-header-number root)
4007                                      gnus-newsgroup-scored))
4008                           gnus-summary-default-score 0))))
4009              (list gnus-summary-default-score)
4010              '(0))))
4011
4012 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4013 (defvar gnus-tmp-prev-subject nil)
4014 (defvar gnus-tmp-false-parent nil)
4015 (defvar gnus-tmp-root-expunged nil)
4016 (defvar gnus-tmp-dummy-line nil)
4017
4018 (eval-when-compile (defvar gnus-tmp-header))
4019 (defun gnus-extra-header (type &optional header)
4020   "Return the extra header of TYPE."
4021   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4022       ""))
4023
4024 (defun gnus-summary-prepare-threads (threads)
4025   "Prepare summary buffer from THREADS and indentation LEVEL.
4026 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4027 or a straight list of headers."
4028   (gnus-message 7 "Generating summary...")
4029
4030   (setq gnus-newsgroup-threads threads)
4031   (beginning-of-line)
4032
4033   (let ((gnus-tmp-level 0)
4034         (default-score (or gnus-summary-default-score 0))
4035         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4036         thread number subject stack state gnus-tmp-gathered beg-match
4037         new-roots gnus-tmp-new-adopts thread-end
4038         gnus-tmp-header gnus-tmp-unread
4039         gnus-tmp-replied gnus-tmp-subject-or-nil
4040         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4041         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4042         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket)
4043
4044     (setq gnus-tmp-prev-subject nil)
4045
4046     (if (vectorp (car threads))
4047         ;; If this is a straight (sic) list of headers, then a
4048         ;; threaded summary display isn't required, so we just create
4049         ;; an unthreaded one.
4050         (gnus-summary-prepare-unthreaded threads)
4051
4052       ;; Do the threaded display.
4053
4054       (while (or threads stack gnus-tmp-new-adopts new-roots)
4055
4056         (if (and (= gnus-tmp-level 0)
4057                  (or (not stack)
4058                      (= (caar stack) 0))
4059                  (not gnus-tmp-false-parent)
4060                  (or gnus-tmp-new-adopts new-roots))
4061             (if gnus-tmp-new-adopts
4062                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4063                       thread (list (car gnus-tmp-new-adopts))
4064                       gnus-tmp-header (caar thread)
4065                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4066               (when new-roots
4067                 (setq thread (list (car new-roots))
4068                       gnus-tmp-header (caar thread)
4069                       new-roots (cdr new-roots))))
4070
4071           (if threads
4072               ;; If there are some threads, we do them before the
4073               ;; threads on the stack.
4074               (setq thread threads
4075                     gnus-tmp-header (caar thread))
4076             ;; There were no current threads, so we pop something off
4077             ;; the stack.
4078             (setq state (car stack)
4079                   gnus-tmp-level (car state)
4080                   thread (cdr state)
4081                   stack (cdr stack)
4082                   gnus-tmp-header (caar thread))))
4083
4084         (setq gnus-tmp-false-parent nil)
4085         (setq gnus-tmp-root-expunged nil)
4086         (setq thread-end nil)
4087
4088         (if (stringp gnus-tmp-header)
4089             ;; The header is a dummy root.
4090             (cond
4091              ((eq gnus-summary-make-false-root 'adopt)
4092               ;; We let the first article adopt the rest.
4093               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4094                                                (cddar thread)))
4095               (setq gnus-tmp-gathered
4096                     (nconc (mapcar
4097                             (lambda (h) (mail-header-number (car h)))
4098                             (cddar thread))
4099                            gnus-tmp-gathered))
4100               (setq thread (cons (list (caar thread)
4101                                        (cadar thread))
4102                                  (cdr thread)))
4103               (setq gnus-tmp-level -1
4104                     gnus-tmp-false-parent t))
4105              ((eq gnus-summary-make-false-root 'empty)
4106               ;; We print adopted articles with empty subject fields.
4107               (setq gnus-tmp-gathered
4108                     (nconc (mapcar
4109                             (lambda (h) (mail-header-number (car h)))
4110                             (cddar thread))
4111                            gnus-tmp-gathered))
4112               (setq gnus-tmp-level -1))
4113              ((eq gnus-summary-make-false-root 'dummy)
4114               ;; We remember that we probably want to output a dummy
4115               ;; root.
4116               (setq gnus-tmp-dummy-line gnus-tmp-header)
4117               (setq gnus-tmp-prev-subject gnus-tmp-header))
4118              (t
4119               ;; We do not make a root for the gathered
4120               ;; sub-threads at all.
4121               (setq gnus-tmp-level -1)))
4122
4123           (setq number (mail-header-number gnus-tmp-header)
4124                 subject (mail-header-subject gnus-tmp-header))
4125
4126           (cond
4127            ;; If the thread has changed subject, we might want to make
4128            ;; this subthread into a root.
4129            ((and (null gnus-thread-ignore-subject)
4130                  (not (zerop gnus-tmp-level))
4131                  gnus-tmp-prev-subject
4132                  (not (inline
4133                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4134             (setq new-roots (nconc new-roots (list (car thread)))
4135                   thread-end t
4136                   gnus-tmp-header nil))
4137            ;; If the article lies outside the current limit,
4138            ;; then we do not display it.
4139            ((not (memq number gnus-newsgroup-limit))
4140             (setq gnus-tmp-gathered
4141                   (nconc (mapcar
4142                           (lambda (h) (mail-header-number (car h)))
4143                           (cdar thread))
4144                          gnus-tmp-gathered))
4145             (setq gnus-tmp-new-adopts (if (cdar thread)
4146                                           (append gnus-tmp-new-adopts
4147                                                   (cdar thread))
4148                                         gnus-tmp-new-adopts)
4149                   thread-end t
4150                   gnus-tmp-header nil)
4151             (when (zerop gnus-tmp-level)
4152               (setq gnus-tmp-root-expunged t)))
4153            ;; Perhaps this article is to be marked as read?
4154            ((and gnus-summary-mark-below
4155                  (< (or (cdr (assq number gnus-newsgroup-scored))
4156                         default-score)
4157                     gnus-summary-mark-below)
4158                  ;; Don't touch sparse articles.
4159                  (not (gnus-summary-article-sparse-p number))
4160                  (not (gnus-summary-article-ancient-p number)))
4161             (setq gnus-newsgroup-unreads
4162                   (delq number gnus-newsgroup-unreads))
4163             (if gnus-newsgroup-auto-expire
4164                 (push number gnus-newsgroup-expirable)
4165               (push (cons number gnus-low-score-mark)
4166                     gnus-newsgroup-reads))))
4167
4168           (when gnus-tmp-header
4169             ;; We may have an old dummy line to output before this
4170             ;; article.
4171             (when (and gnus-tmp-dummy-line
4172                        (gnus-subject-equal
4173                         gnus-tmp-dummy-line
4174                         (mail-header-subject gnus-tmp-header)))
4175               (gnus-summary-insert-dummy-line
4176                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4177               (setq gnus-tmp-dummy-line nil))
4178
4179             ;; Compute the mark.
4180             (setq gnus-tmp-unread (gnus-article-mark number))
4181
4182             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4183                                   gnus-tmp-header gnus-tmp-level)
4184                   gnus-newsgroup-data)
4185
4186             ;; Actually insert the line.
4187             (setq
4188              gnus-tmp-subject-or-nil
4189              (cond
4190               ((and gnus-thread-ignore-subject
4191                     gnus-tmp-prev-subject
4192                     (not (inline (gnus-subject-equal
4193                                   gnus-tmp-prev-subject subject))))
4194                subject)
4195               ((zerop gnus-tmp-level)
4196                (if (and (eq gnus-summary-make-false-root 'empty)
4197                         (memq number gnus-tmp-gathered)
4198                         gnus-tmp-prev-subject
4199                         (inline (gnus-subject-equal
4200                                  gnus-tmp-prev-subject subject)))
4201                    gnus-summary-same-subject
4202                  subject))
4203               (t gnus-summary-same-subject)))
4204             (if (and (eq gnus-summary-make-false-root 'adopt)
4205                      (= gnus-tmp-level 1)
4206                      (memq number gnus-tmp-gathered))
4207                 (setq gnus-tmp-opening-bracket ?\<
4208                       gnus-tmp-closing-bracket ?\>)
4209               (setq gnus-tmp-opening-bracket ?\[
4210                     gnus-tmp-closing-bracket ?\]))
4211             (setq
4212              gnus-tmp-indentation
4213              (aref gnus-thread-indent-array gnus-tmp-level)
4214              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4215              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4216                                 gnus-summary-default-score 0)
4217              gnus-tmp-score-char
4218              (if (or (null gnus-summary-default-score)
4219                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4220                          gnus-summary-zcore-fuzz))
4221                  ?  ;Whitespace
4222                (if (< gnus-tmp-score gnus-summary-default-score)
4223                    gnus-score-below-mark gnus-score-over-mark))
4224              gnus-tmp-replied
4225              (cond ((memq number gnus-newsgroup-processable)
4226                     gnus-process-mark)
4227                    ((memq number gnus-newsgroup-cached)
4228                     gnus-cached-mark)
4229                    ((memq number gnus-newsgroup-replied)
4230                     gnus-replied-mark)
4231                    ((memq number gnus-newsgroup-saved)
4232                     gnus-saved-mark)
4233                    (t gnus-no-mark))
4234              gnus-tmp-from (mail-header-from gnus-tmp-header)
4235              gnus-tmp-name
4236              (cond
4237               ((string-match "<[^>]+> *$" gnus-tmp-from)
4238                (setq beg-match (match-beginning 0))
4239                (or (and (string-match "^\".+\"" gnus-tmp-from)
4240                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4241                    (substring gnus-tmp-from 0 beg-match)))
4242               ((string-match "(.+)" gnus-tmp-from)
4243                (substring gnus-tmp-from
4244                           (1+ (match-beginning 0)) (1- (match-end 0))))
4245               (t gnus-tmp-from)))
4246             (when (string= gnus-tmp-name "")
4247               (setq gnus-tmp-name gnus-tmp-from))
4248             (unless (numberp gnus-tmp-lines)
4249               (setq gnus-tmp-lines 0))
4250             (gnus-put-text-property
4251              (point)
4252              (progn (eval gnus-summary-line-format-spec) (point))
4253              'gnus-number number)
4254             (when gnus-visual-p
4255               (forward-line -1)
4256               (gnus-run-hooks 'gnus-summary-update-hook)
4257               (forward-line 1))
4258
4259             (setq gnus-tmp-prev-subject subject)))
4260
4261         (when (nth 1 thread)
4262           (push (cons (max 0 gnus-tmp-level) (nthcdr 1 thread)) stack))
4263         (incf gnus-tmp-level)
4264         (setq threads (if thread-end nil (cdar thread)))
4265         (unless threads
4266           (setq gnus-tmp-level 0)))))
4267   (gnus-message 7 "Generating summary...done"))
4268
4269 (defun gnus-summary-prepare-unthreaded (headers)
4270   "Generate an unthreaded summary buffer based on HEADERS."
4271   (let (header number mark)
4272
4273     (beginning-of-line)
4274
4275     (while headers
4276       ;; We may have to root out some bad articles...
4277       (when (memq (setq number (mail-header-number
4278                                 (setq header (pop headers))))
4279                   gnus-newsgroup-limit)
4280         ;; Mark article as read when it has a low score.
4281         (when (and gnus-summary-mark-below
4282                    (< (or (cdr (assq number gnus-newsgroup-scored))
4283                           gnus-summary-default-score 0)
4284                       gnus-summary-mark-below)
4285                    (not (gnus-summary-article-ancient-p number)))
4286           (setq gnus-newsgroup-unreads
4287                 (delq number gnus-newsgroup-unreads))
4288           (if gnus-newsgroup-auto-expire
4289               (push number gnus-newsgroup-expirable)
4290             (push (cons number gnus-low-score-mark)
4291                   gnus-newsgroup-reads)))
4292
4293         (setq mark (gnus-article-mark number))
4294         (push (gnus-data-make number mark (1+ (point)) header 0)
4295               gnus-newsgroup-data)
4296         (gnus-summary-insert-line
4297          header 0 number
4298          mark (memq number gnus-newsgroup-replied)
4299          (memq number gnus-newsgroup-expirable)
4300          (mail-header-subject header) nil
4301          (cdr (assq number gnus-newsgroup-scored))
4302          (memq number gnus-newsgroup-processable))))))
4303
4304 (defun gnus-summary-remove-list-identifiers ()
4305   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4306   (let ((regexp (if (consp gnus-list-identifiers)
4307                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4308                   gnus-list-identifiers))
4309         changed subject)
4310     (when regexp
4311       (dolist (header gnus-newsgroup-headers)
4312         (setq subject (mail-header-subject header)
4313               changed nil)
4314         (while (string-match
4315                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4316                 subject)
4317           (setq subject
4318                 (concat (substring subject 0 (match-beginning 2))
4319                         (substring subject (match-end 0)))
4320                 changed t))
4321         (when (and changed
4322                    (string-match
4323                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4324           (setq subject
4325                 (concat (substring subject 0 (match-beginning 1))
4326                         (substring subject (match-end 1)))))
4327         (when changed
4328           (mail-header-set-subject header subject))))))
4329
4330 (defun gnus-fetch-headers (articles)
4331   "Fetch headers of ARTICLES."
4332   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4333     (gnus-message 5 "Fetching headers for %s..." name)
4334     (prog1
4335         (if (eq 'nov
4336                 (setq gnus-headers-retrieved-by
4337                       (gnus-retrieve-headers
4338                        articles gnus-newsgroup-name
4339                        ;; We might want to fetch old headers, but
4340                        ;; not if there is only 1 article.
4341                        (and (or (and
4342                                  (not (eq gnus-fetch-old-headers 'some))
4343                                  (not (numberp gnus-fetch-old-headers)))
4344                                 (> (length articles) 1))
4345                           gnus-fetch-old-headers))))
4346             (gnus-get-newsgroup-headers-xover
4347              articles nil nil gnus-newsgroup-name t)
4348           (gnus-get-newsgroup-headers))
4349       (gnus-message 5 "Fetching headers for %s...done" name))))
4350
4351 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4352   "Select newsgroup GROUP.
4353 If READ-ALL is non-nil, all articles in the group are selected.
4354 If SELECT-ARTICLES, only select those articles from GROUP."
4355   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4356          ;;!!! Dirty hack; should be removed.
4357          (gnus-summary-ignore-duplicates
4358           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4359               t
4360             gnus-summary-ignore-duplicates))
4361          (info (nth 2 entry))
4362          articles fetched-articles cached)
4363
4364     (unless (gnus-check-server
4365              (setq gnus-current-select-method
4366                    (gnus-find-method-for-group group)))
4367       (error "Couldn't open server"))
4368
4369     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4370         (gnus-activate-group group)     ; Or we can activate it...
4371         (progn                          ; Or we bug out.
4372           (when (equal major-mode 'gnus-summary-mode)
4373             (kill-buffer (current-buffer)))
4374           (error "Couldn't activate group %s: %s"
4375                  group (gnus-status-message group))))
4376
4377     (unless (gnus-request-group group t)
4378       (when (equal major-mode 'gnus-summary-mode)
4379         (kill-buffer (current-buffer)))
4380       (error "Couldn't request group %s: %s"
4381              group (gnus-status-message group)))
4382
4383     (setq gnus-newsgroup-name group)
4384     (setq gnus-newsgroup-unselected nil)
4385     (setq gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4386     (gnus-summary-setup-default-charset)
4387
4388     ;; Adjust and set lists of article marks.
4389     (when info
4390       (gnus-adjust-marked-articles info))
4391
4392     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4393     (when (gnus-virtual-group-p group)
4394       (setq cached gnus-newsgroup-cached))
4395
4396     (setq gnus-newsgroup-unreads
4397           (gnus-set-difference
4398            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4399            gnus-newsgroup-dormant))
4400
4401     (setq gnus-newsgroup-processable nil)
4402
4403     (gnus-update-read-articles group gnus-newsgroup-unreads)
4404
4405     (if (setq articles select-articles)
4406         (setq gnus-newsgroup-unselected
4407               (gnus-sorted-intersection
4408                gnus-newsgroup-unreads
4409                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4410       (setq articles (gnus-articles-to-read group read-all)))
4411
4412     (cond
4413      ((null articles)
4414       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4415       'quit)
4416      ((eq articles 0) nil)
4417      (t
4418       ;; Init the dependencies hash table.
4419       (setq gnus-newsgroup-dependencies
4420             (gnus-make-hashtable (length articles)))
4421       (gnus-set-global-variables)
4422       ;; Retrieve the headers and read them in.
4423       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4424
4425       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4426       (when cached
4427         (setq gnus-newsgroup-cached cached))
4428
4429       ;; Suppress duplicates?
4430       (when gnus-suppress-duplicates
4431         (gnus-dup-suppress-articles))
4432
4433       ;; Set the initial limit.
4434       (setq gnus-newsgroup-limit (copy-sequence articles))
4435       ;; Remove canceled articles from the list of unread articles.
4436       (setq gnus-newsgroup-unreads
4437             (gnus-set-sorted-intersection
4438              gnus-newsgroup-unreads
4439              (setq fetched-articles
4440                    (mapcar (lambda (headers) (mail-header-number headers))
4441                            gnus-newsgroup-headers))))
4442       ;; Removed marked articles that do not exist.
4443       (gnus-update-missing-marks
4444        (gnus-sorted-complement fetched-articles articles))
4445       ;; We might want to build some more threads first.
4446       (when (and gnus-fetch-old-headers
4447                  (eq gnus-headers-retrieved-by 'nov))
4448         (if (eq gnus-fetch-old-headers 'invisible)
4449             (gnus-build-all-threads)
4450           (gnus-build-old-threads)))
4451       ;; Let the Gnus agent mark articles as read.
4452       (when gnus-agent
4453         (gnus-agent-get-undownloaded-list))
4454       ;; Remove list identifiers from subject
4455       (when gnus-list-identifiers
4456         (gnus-summary-remove-list-identifiers))
4457       ;; Check whether auto-expire is to be done in this group.
4458       (setq gnus-newsgroup-auto-expire
4459             (gnus-group-auto-expirable-p group))
4460       ;; Set up the article buffer now, if necessary.
4461       (unless gnus-single-article-buffer
4462         (gnus-article-setup-buffer))
4463       ;; First and last article in this newsgroup.
4464       (when gnus-newsgroup-headers
4465         (setq gnus-newsgroup-begin
4466               (mail-header-number (car gnus-newsgroup-headers))
4467               gnus-newsgroup-end
4468               (mail-header-number
4469                (gnus-last-element gnus-newsgroup-headers))))
4470       ;; GROUP is successfully selected.
4471       (or gnus-newsgroup-headers t)))))
4472
4473 (defun gnus-articles-to-read (group &optional read-all)
4474   "Find out what articles the user wants to read."
4475   (let* ((articles
4476           ;; Select all articles if `read-all' is non-nil, or if there
4477           ;; are no unread articles.
4478           (if (or read-all
4479                   (and (zerop (length gnus-newsgroup-marked))
4480                        (zerop (length gnus-newsgroup-unreads)))
4481                   (eq (gnus-group-find-parameter group 'display)
4482                       'all))
4483               (or
4484                (gnus-uncompress-range (gnus-active group))
4485                (gnus-cache-articles-in-group group))
4486             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4487                           (copy-sequence gnus-newsgroup-unreads))
4488                   '<)))
4489          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4490          (scored (length scored-list))
4491          (number (length articles))
4492          (marked (+ (length gnus-newsgroup-marked)
4493                     (length gnus-newsgroup-dormant)))
4494          (select
4495           (cond
4496            ((numberp read-all)
4497             read-all)
4498            (t
4499             (condition-case ()
4500                 (cond
4501                  ((and (or (<= scored marked) (= scored number))
4502                        (numberp gnus-large-newsgroup)
4503                        (> number gnus-large-newsgroup))
4504                   (let ((input
4505                          (read-string
4506                           (format
4507                            "How many articles from %s (default %d): "
4508                            (gnus-limit-string gnus-newsgroup-name 35)
4509                            number))))
4510                     (if (string-match "^[ \t]*$" input) number input)))
4511                  ((and (> scored marked) (< scored number)
4512                        (> (- scored number) 20))
4513                   (let ((input
4514                          (read-string
4515                           (format "%s %s (%d scored, %d total): "
4516                                   "How many articles from"
4517                                   group scored number))))
4518                     (if (string-match "^[ \t]*$" input)
4519                         number input)))
4520                  (t number))
4521               (quit
4522                (message "Quit getting the articles to read")
4523                nil))))))
4524     (setq select (if (stringp select) (string-to-number select) select))
4525     (if (or (null select) (zerop select))
4526         select
4527       (if (and (not (zerop scored)) (<= (abs select) scored))
4528           (progn
4529             (setq articles (sort scored-list '<))
4530             (setq number (length articles)))
4531         (setq articles (copy-sequence articles)))
4532
4533       (when (< (abs select) number)
4534         (if (< select 0)
4535             ;; Select the N oldest articles.
4536             (setcdr (nthcdr (1- (abs select)) articles) nil)
4537           ;; Select the N most recent articles.
4538           (setq articles (nthcdr (- number select) articles))))
4539       (setq gnus-newsgroup-unselected
4540             (gnus-sorted-intersection
4541              gnus-newsgroup-unreads
4542              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4543       (when gnus-alter-articles-to-read-function
4544         (setq gnus-newsgroup-unreads
4545               (sort
4546                (funcall gnus-alter-articles-to-read-function
4547                         gnus-newsgroup-name gnus-newsgroup-unreads)
4548                '<)))
4549       articles)))
4550
4551 (defun gnus-killed-articles (killed articles)
4552   (let (out)
4553     (while articles
4554       (when (inline (gnus-member-of-range (car articles) killed))
4555         (push (car articles) out))
4556       (setq articles (cdr articles)))
4557     out))
4558
4559 (defun gnus-uncompress-marks (marks)
4560   "Uncompress the mark ranges in MARKS."
4561   (let ((uncompressed '(score bookmark))
4562         out)
4563     (while marks
4564       (if (memq (caar marks) uncompressed)
4565           (push (car marks) out)
4566         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4567       (setq marks (cdr marks)))
4568     out))
4569
4570 (defun gnus-adjust-marked-articles (info)
4571   "Set all article lists and remove all marks that are no longer valid."
4572   (let* ((marked-lists (gnus-info-marks info))
4573          (active (gnus-active (gnus-info-group info)))
4574          (min (car active))
4575          (max (cdr active))
4576          (types gnus-article-mark-lists)
4577          (uncompressed '(score bookmark killed))
4578          marks var articles article mark)
4579
4580     (while marked-lists
4581       (setq marks (pop marked-lists))
4582       (set (setq var (intern (format "gnus-newsgroup-%s"
4583                                      (car (rassq (setq mark (car marks))
4584                                                  types)))))
4585            (if (memq (car marks) uncompressed) (cdr marks)
4586              (gnus-uncompress-range (cdr marks))))
4587
4588       (setq articles (symbol-value var))
4589
4590       ;; All articles have to be subsets of the active articles.
4591       (cond
4592        ;; Adjust "simple" lists.
4593        ((memq mark '(tick dormant expire reply save))
4594         (while articles
4595           (when (or (< (setq article (pop articles)) min) (> article max))
4596             (set var (delq article (symbol-value var))))))
4597        ;; Adjust assocs.
4598        ((memq mark uncompressed)
4599         (when (not (listp (cdr (symbol-value var))))
4600           (set var (list (symbol-value var))))
4601         (when (not (listp (cdr articles)))
4602           (setq articles (list articles)))
4603         (while articles
4604           (when (or (not (consp (setq article (pop articles))))
4605                     (< (car article) min)
4606                     (> (car article) max))
4607             (set var (delq article (symbol-value var))))))))))
4608
4609 (defun gnus-update-missing-marks (missing)
4610   "Go through the list of MISSING articles and remove them from the mark lists."
4611   (when missing
4612     (let ((types gnus-article-mark-lists)
4613           var m)
4614       ;; Go through all types.
4615       (while types
4616         (setq var (intern (format "gnus-newsgroup-%s" (car (pop types)))))
4617         (when (symbol-value var)
4618           ;; This list has articles.  So we delete all missing articles
4619           ;; from it.
4620           (setq m missing)
4621           (while m
4622             (set var (delq (pop m) (symbol-value var)))))))))
4623
4624 (defun gnus-update-marks ()
4625   "Enter the various lists of marked articles into the newsgroup info list."
4626   (let ((types gnus-article-mark-lists)
4627         (info (gnus-get-info gnus-newsgroup-name))
4628         (uncompressed '(score bookmark killed))
4629         type list newmarked symbol delta-marks)
4630     (when info
4631       ;; Add all marks lists to the list of marks lists.
4632       (while (setq type (pop types))
4633         (setq list (symbol-value
4634                     (setq symbol
4635                           (intern (format "gnus-newsgroup-%s"
4636                                           (car type))))))
4637
4638         (when list
4639           ;; Get rid of the entries of the articles that have the
4640           ;; default score.
4641           (when (and (eq (cdr type) 'score)
4642                      gnus-save-score
4643                      list)
4644             (let* ((arts list)
4645                    (prev (cons nil list))
4646                    (all prev))
4647               (while arts
4648                 (if (or (not (consp (car arts)))
4649                         (= (cdar arts) gnus-summary-default-score))
4650                     (setcdr prev (cdr arts))
4651                   (setq prev arts))
4652                 (setq arts (cdr arts)))
4653               (setq list (cdr all)))))
4654
4655         (unless (memq (cdr type) uncompressed)
4656           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4657
4658         (when (gnus-check-backend-function
4659                'request-set-mark gnus-newsgroup-name)
4660           ;; propagate flags to server, with the following exceptions:
4661           ;; uncompressed:s are not proper flags (they are cons cells)
4662           ;; cache is a internal gnus flag
4663           ;; download are local to one gnus installation (well)
4664           ;; unsend are for nndraft groups only
4665           ;; xxx: generality of this?  this suits nnimap anyway
4666           (unless (memq (cdr type) (append '(cache download unsend)
4667                                            uncompressed))
4668             (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4669                    (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4670                    (add (gnus-remove-from-range
4671                          (gnus-copy-sequence list) old)))
4672               (when add
4673                 (push (list add 'add (list (cdr type))) delta-marks))
4674               (when del
4675                 (push (list del 'del (list (cdr type))) delta-marks)))))
4676
4677         (when list
4678           (push (cons (cdr type) list) newmarked)))
4679
4680       (when delta-marks
4681         (unless (gnus-check-group gnus-newsgroup-name)
4682           (error "Can't open server for %s" gnus-newsgroup-name))
4683         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4684
4685       ;; Enter these new marks into the info of the group.
4686       (if (nthcdr 3 info)
4687           (setcar (nthcdr 3 info) newmarked)
4688         ;; Add the marks lists to the end of the info.
4689         (when newmarked
4690           (setcdr (nthcdr 2 info) (list newmarked))))
4691
4692       ;; Cut off the end of the info if there's nothing else there.
4693       (let ((i 5))
4694         (while (and (> i 2)
4695                     (not (nth i info)))
4696           (when (nthcdr (decf i) info)
4697             (setcdr (nthcdr i info) nil)))))))
4698
4699 (defun gnus-set-mode-line (where)
4700   "Set the mode line of the article or summary buffers.
4701 If WHERE is `summary', the summary mode line format will be used."
4702   ;; Is this mode line one we keep updated?
4703   (when (and (memq where gnus-updated-mode-lines)
4704              (symbol-value
4705               (intern (format "gnus-%s-mode-line-format-spec" where))))
4706     (let (mode-string)
4707       (save-excursion
4708         ;; We evaluate this in the summary buffer since these
4709         ;; variables are buffer-local to that buffer.
4710         (set-buffer gnus-summary-buffer)
4711         ;; We bind all these variables that are used in the `eval' form
4712         ;; below.
4713         (let* ((mformat (symbol-value
4714                          (intern
4715                           (format "gnus-%s-mode-line-format-spec" where))))
4716                (gnus-tmp-group-name (gnus-group-decoded-name 
4717                                      gnus-newsgroup-name))
4718                (gnus-tmp-article-number (or gnus-current-article 0))
4719                (gnus-tmp-unread gnus-newsgroup-unreads)
4720                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
4721                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
4722                (gnus-tmp-unread-and-unselected
4723                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
4724                             (zerop gnus-tmp-unselected))
4725                        "")
4726                       ((zerop gnus-tmp-unselected)
4727                        (format "{%d more}" gnus-tmp-unread-and-unticked))
4728                       (t (format "{%d(+%d) more}"
4729                                  gnus-tmp-unread-and-unticked
4730                                  gnus-tmp-unselected))))
4731                (gnus-tmp-subject
4732                 (if (and gnus-current-headers
4733                          (vectorp gnus-current-headers))
4734                     (gnus-mode-string-quote
4735                      (mail-header-subject gnus-current-headers))
4736                   ""))
4737                bufname-length max-len
4738                gnus-tmp-header);; passed as argument to any user-format-funcs
4739           (setq mode-string (eval mformat))
4740           (setq bufname-length (if (string-match "%b" mode-string)
4741                                    (- (length
4742                                        (buffer-name
4743                                         (if (eq where 'summary)
4744                                             nil
4745                                           (get-buffer gnus-article-buffer))))
4746                                       2)
4747                                  0))
4748           (setq max-len (max 4 (if gnus-mode-non-string-length
4749                                    (- (window-width)
4750                                       gnus-mode-non-string-length
4751                                       bufname-length)
4752                                  (length mode-string))))
4753           ;; We might have to chop a bit of the string off...
4754           (when (> (length mode-string) max-len)
4755             (setq mode-string
4756                   (concat (truncate-string-to-width mode-string (- max-len 3))
4757                           "...")))
4758           ;; Pad the mode string a bit.
4759           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
4760       ;; Update the mode line.
4761       (setq mode-line-buffer-identification
4762             (gnus-mode-line-buffer-identification (list mode-string)))
4763       (set-buffer-modified-p t))))
4764
4765 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
4766   "Go through the HEADERS list and add all Xrefs to a hash table.
4767 The resulting hash table is returned, or nil if no Xrefs were found."
4768   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
4769          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
4770          (xref-hashtb (gnus-make-hashtable))
4771          start group entry number xrefs header)
4772     (while headers
4773       (setq header (pop headers))
4774       (when (and (setq xrefs (mail-header-xref header))
4775                  (not (memq (setq number (mail-header-number header))
4776                             unreads)))
4777         (setq start 0)
4778         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
4779           (setq start (match-end 0))
4780           (setq group (if prefix
4781                           (concat prefix (substring xrefs (match-beginning 1)
4782                                                     (match-end 1)))
4783                         (substring xrefs (match-beginning 1) (match-end 1))))
4784           (setq number
4785                 (string-to-int (substring xrefs (match-beginning 2)
4786                                           (match-end 2))))
4787           (if (setq entry (gnus-gethash group xref-hashtb))
4788               (setcdr entry (cons number (cdr entry)))
4789             (gnus-sethash group (cons number nil) xref-hashtb)))))
4790     (and start xref-hashtb)))
4791
4792 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
4793   "Look through all the headers and mark the Xrefs as read."
4794   (let ((virtual (gnus-virtual-group-p from-newsgroup))
4795         name entry info xref-hashtb idlist method nth4)
4796     (save-excursion
4797       (set-buffer gnus-group-buffer)
4798       (when (setq xref-hashtb
4799                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
4800         (mapatoms
4801          (lambda (group)
4802            (unless (string= from-newsgroup (setq name (symbol-name group)))
4803              (setq idlist (symbol-value group))
4804              ;; Dead groups are not updated.
4805              (and (prog1
4806                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
4807                             info (nth 2 entry))
4808                     (when (stringp (setq nth4 (gnus-info-method info)))
4809                       (setq nth4 (gnus-server-to-method nth4))))
4810                   ;; Only do the xrefs if the group has the same
4811                   ;; select method as the group we have just read.
4812                   (or (gnus-methods-equal-p
4813                        nth4 (gnus-find-method-for-group from-newsgroup))
4814                       virtual
4815                       (equal nth4 (setq method (gnus-find-method-for-group
4816                                                 from-newsgroup)))
4817                       (and (equal (car nth4) (car method))
4818                            (equal (nth 1 nth4) (nth 1 method))))
4819                   gnus-use-cross-reference
4820                   (or (not (eq gnus-use-cross-reference t))
4821                       virtual
4822                       ;; Only do cross-references on subscribed
4823                       ;; groups, if that is what is wanted.
4824                       (<= (gnus-info-level info) gnus-level-subscribed))
4825                   (gnus-group-make-articles-read name idlist))))
4826          xref-hashtb)))))
4827
4828 (defun gnus-compute-read-articles (group articles)
4829   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4830          (info (nth 2 entry))
4831          (active (gnus-active group))
4832          ninfo)
4833     (when entry
4834       ;; First peel off all invalid article numbers.
4835       (when active
4836         (let ((ids articles)
4837               id first)
4838           (while (setq id (pop ids))
4839             (when (and first (> id (cdr active)))
4840               ;; We'll end up in this situation in one particular
4841               ;; obscure situation.  If you re-scan a group and get
4842               ;; a new article that is cross-posted to a different
4843               ;; group that has not been re-scanned, you might get
4844               ;; crossposted article that has a higher number than
4845               ;; Gnus believes possible.  So we re-activate this
4846               ;; group as well.  This might mean doing the
4847               ;; crossposting thingy will *increase* the number
4848               ;; of articles in some groups.  Tsk, tsk.
4849               (setq active (or (gnus-activate-group group) active)))
4850             (when (or (> id (cdr active))
4851                       (< id (car active)))
4852               (setq articles (delq id articles))))))
4853       ;; If the read list is nil, we init it.
4854       (if (and active
4855                (null (gnus-info-read info))
4856                (> (car active) 1))
4857           (setq ninfo (cons 1 (1- (car active))))
4858         (setq ninfo (gnus-info-read info)))
4859       ;; Then we add the read articles to the range.
4860       (gnus-add-to-range
4861        ninfo (setq articles (sort articles '<))))))
4862
4863 (defun gnus-group-make-articles-read (group articles)
4864   "Update the info of GROUP to say that ARTICLES are read."
4865   (let* ((num 0)
4866          (entry (gnus-gethash group gnus-newsrc-hashtb))
4867          (info (nth 2 entry))
4868          (active (gnus-active group))
4869          range)
4870     (when entry
4871       (setq range (gnus-compute-read-articles group articles))
4872       (save-excursion
4873         (set-buffer gnus-group-buffer)
4874         (gnus-undo-register
4875           `(progn
4876              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
4877              (gnus-info-set-read ',info ',(gnus-info-read info))
4878              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
4879              (gnus-group-update-group ,group t))))
4880       ;; Add the read articles to the range.
4881       (gnus-info-set-read info range)
4882       ;; Then we have to re-compute how many unread
4883       ;; articles there are in this group.
4884       (when active
4885         (cond
4886          ((not range)
4887           (setq num (- (1+ (cdr active)) (car active))))
4888          ((not (listp (cdr range)))
4889           (setq num (- (cdr active) (- (1+ (cdr range))
4890                                        (car range)))))
4891          (t
4892           (while range
4893             (if (numberp (car range))
4894                 (setq num (1+ num))
4895               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
4896             (setq range (cdr range)))
4897           (setq num (- (cdr active) num))))
4898         ;; Update the number of unread articles.
4899         (setcar entry num)
4900         ;; Update the group buffer.
4901         (gnus-group-update-group group t)))))
4902
4903 (defvar gnus-newsgroup-none-id 0)
4904
4905 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
4906   (let ((cur nntp-server-buffer)
4907         (dependencies
4908          (or dependencies
4909              (save-excursion (set-buffer gnus-summary-buffer)
4910                              gnus-newsgroup-dependencies)))
4911         headers id end ref
4912         (mail-parse-charset gnus-newsgroup-charset)
4913         (mail-parse-ignored-charsets
4914          (save-excursion (condition-case nil
4915                              (set-buffer gnus-summary-buffer)
4916                            (error))
4917                          gnus-newsgroup-ignored-charsets)))
4918     (save-excursion
4919       (set-buffer nntp-server-buffer)
4920       ;; Translate all TAB characters into SPACE characters.
4921       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
4922       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
4923       (gnus-run-hooks 'gnus-parse-headers-hook)
4924       (let ((case-fold-search t)
4925             in-reply-to header p lines chars)
4926         (goto-char (point-min))
4927         ;; Search to the beginning of the next header.  Error messages
4928         ;; do not begin with 2 or 3.
4929         (while (re-search-forward "^[23][0-9]+ " nil t)
4930           (setq id nil
4931                 ref nil)
4932           ;; This implementation of this function, with nine
4933           ;; search-forwards instead of the one re-search-forward and
4934           ;; a case (which basically was the old function) is actually
4935           ;; about twice as fast, even though it looks messier.  You
4936           ;; can't have everything, I guess.  Speed and elegance
4937           ;; doesn't always go hand in hand.
4938           (setq
4939            header
4940            (vector
4941             ;; Number.
4942             (prog1
4943                 (read cur)
4944               (end-of-line)
4945               (setq p (point))
4946               (narrow-to-region (point)
4947                                 (or (and (search-forward "\n.\n" nil t)
4948                                          (- (point) 2))
4949                                     (point))))
4950             ;; Subject.
4951             (progn
4952               (goto-char p)
4953               (if (search-forward "\nsubject: " nil t)
4954                   (funcall gnus-decode-encoded-word-function
4955                            (nnheader-header-value))
4956                 "(none)"))
4957             ;; From.
4958             (progn
4959               (goto-char p)
4960               (if (or (search-forward "\nfrom: " nil t)
4961                       (search-forward "\nfrom:" nil t))
4962                   (funcall gnus-decode-encoded-word-function
4963                            (nnheader-header-value))
4964                 "(nobody)"))
4965             ;; Date.
4966             (progn
4967               (goto-char p)
4968               (if (search-forward "\ndate: " nil t)
4969                   (nnheader-header-value) ""))
4970             ;; Message-ID.
4971             (progn
4972               (goto-char p)
4973               (setq id (if (re-search-forward
4974                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
4975                            ;; We do it this way to make sure the Message-ID
4976                            ;; is (somewhat) syntactically valid.
4977                            (buffer-substring (match-beginning 1)
4978                                              (match-end 1))
4979                          ;; If there was no message-id, we just fake one
4980                          ;; to make subsequent routines simpler.
4981                          (nnheader-generate-fake-message-id))))
4982             ;; References.
4983             (progn
4984               (goto-char p)
4985               (if (search-forward "\nreferences: " nil t)
4986                   (progn
4987                     (setq end (point))
4988                     (prog1
4989                         (nnheader-header-value)
4990                       (setq ref
4991                             (buffer-substring
4992                              (progn
4993                                (end-of-line)
4994                                (search-backward ">" end t)
4995                                (1+ (point)))
4996                              (progn
4997                                (search-backward "<" end t)
4998                                (point))))))
4999                 ;; Get the references from the in-reply-to header if there
5000                 ;; were no references and the in-reply-to header looks
5001                 ;; promising.
5002                 (if (and (search-forward "\nin-reply-to: " nil t)
5003                          (setq in-reply-to (nnheader-header-value))
5004                          (string-match "<[^>]+>" in-reply-to))
5005                     (let (ref2)
5006                       (setq ref (substring in-reply-to (match-beginning 0)
5007                                            (match-end 0)))
5008                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5009                         (setq ref2 (substring in-reply-to (match-beginning 0)
5010                                               (match-end 0)))
5011                         (when (> (length ref2) (length ref))
5012                           (setq ref ref2)))
5013                       ref)
5014                   (setq ref nil))))
5015             ;; Chars.
5016             (progn
5017               (goto-char p)
5018               (if (search-forward "\nchars: " nil t)
5019                   (if (numberp (setq chars (ignore-errors (read cur))))
5020                       chars 0)
5021                 0))
5022             ;; Lines.
5023             (progn
5024               (goto-char p)
5025               (if (search-forward "\nlines: " nil t)
5026                   (if (numberp (setq lines (ignore-errors (read cur))))
5027                       lines 0)
5028                 0))
5029             ;; Xref.
5030             (progn
5031               (goto-char p)
5032               (and (search-forward "\nxref: " nil t)
5033                    (nnheader-header-value)))
5034             ;; Extra.
5035             (when gnus-extra-headers
5036               (let ((extra gnus-extra-headers)
5037                     out)
5038                 (while extra
5039                   (goto-char p)
5040                   (when (search-forward
5041                          (concat "\n" (symbol-name (car extra)) ": ") nil t)
5042                     (push (cons (car extra) (nnheader-header-value))
5043                           out))
5044                   (pop extra))
5045                 out))))
5046           (when (equal id ref)
5047             (setq ref nil))
5048
5049           (when gnus-alter-header-function
5050             (funcall gnus-alter-header-function header)
5051             (setq id (mail-header-id header)
5052                   ref (gnus-parent-id (mail-header-references header))))
5053
5054           (when (setq header
5055                       (gnus-dependencies-add-header
5056                        header dependencies force-new))
5057             (push header headers))
5058           (goto-char (point-max))
5059           (widen))
5060         (nreverse headers)))))
5061
5062 ;; Goes through the xover lines and returns a list of vectors
5063 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5064                                                   force-new dependencies
5065                                                   group also-fetch-heads)
5066   "Parse the news overview data in the server buffer.
5067 Return a list of headers that match SEQUENCE (see
5068 `nntp-retrieve-headers')."
5069   ;; Get the Xref when the users reads the articles since most/some
5070   ;; NNTP servers do not include Xrefs when using XOVER.
5071   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5072   (let ((mail-parse-charset gnus-newsgroup-charset)
5073         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5074         (cur nntp-server-buffer)
5075         (dependencies (or dependencies gnus-newsgroup-dependencies))
5076         number headers header)
5077     (save-excursion
5078       (set-buffer nntp-server-buffer)
5079       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5080       ;; Allow the user to mangle the headers before parsing them.
5081       (gnus-run-hooks 'gnus-parse-headers-hook)
5082       (goto-char (point-min))
5083       (while (not (eobp))
5084         (condition-case ()
5085             (while (and sequence (not (eobp)))
5086               (setq number (read cur))
5087               (while (and sequence
5088                           (< (car sequence) number))
5089                 (setq sequence (cdr sequence)))
5090               (and sequence
5091                    (eq number (car sequence))
5092                    (progn
5093                      (setq sequence (cdr sequence))
5094                      (setq header (inline
5095                                     (gnus-nov-parse-line
5096                                      number dependencies force-new))))
5097                    (push header headers))
5098               (forward-line 1))
5099           (error
5100            (gnus-error 4 "Strange nov line (%d)"
5101                        (count-lines (point-min) (point)))))
5102         (forward-line 1))
5103       ;; A common bug in inn is that if you have posted an article and
5104       ;; then retrieves the active file, it will answer correctly --
5105       ;; the new article is included.  However, a NOV entry for the
5106       ;; article may not have been generated yet, so this may fail.
5107       ;; We work around this problem by retrieving the last few
5108       ;; headers using HEAD.
5109       (if (or (not also-fetch-heads)
5110               (not sequence))
5111           ;; We (probably) got all the headers.
5112           (nreverse headers)
5113         (let ((gnus-nov-is-evil t))
5114           (nconc
5115            (nreverse headers)
5116            (when (gnus-retrieve-headers sequence group)
5117              (gnus-get-newsgroup-headers))))))))
5118
5119 (defun gnus-article-get-xrefs ()
5120   "Fill in the Xref value in `gnus-current-headers', if necessary.
5121 This is meant to be called in `gnus-article-internal-prepare-hook'."
5122   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5123                                  gnus-current-headers)))
5124     (or (not gnus-use-cross-reference)
5125         (not headers)
5126         (and (mail-header-xref headers)
5127              (not (string= (mail-header-xref headers) "")))
5128         (let ((case-fold-search t)
5129               xref)
5130           (save-restriction
5131             (nnheader-narrow-to-headers)
5132             (goto-char (point-min))
5133             (when (or (and (not (eobp))
5134                            (eq (downcase (char-after)) ?x)
5135                            (looking-at "Xref:"))
5136                       (search-forward "\nXref:" nil t))
5137               (goto-char (1+ (match-end 0)))
5138               (setq xref (buffer-substring (point)
5139                                            (progn (end-of-line) (point))))
5140               (mail-header-set-xref headers xref)))))))
5141
5142 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5143   "Find article ID and insert the summary line for that article.
5144 OLD-HEADER can either be a header or a line number to insert
5145 the subject line on."
5146   (let* ((line (and (numberp old-header) old-header))
5147          (old-header (and (vectorp old-header) old-header))
5148          (header (cond ((and old-header use-old-header)
5149                         old-header)
5150                        ((and (numberp id)
5151                              (gnus-number-to-header id))
5152                         (gnus-number-to-header id))
5153                        (t
5154                         (gnus-read-header id))))
5155          (number (and (numberp id) id))
5156          d)
5157     (when header
5158       ;; Rebuild the thread that this article is part of and go to the
5159       ;; article we have fetched.
5160       (when (and (not gnus-show-threads)
5161                  old-header)
5162         (when (and number
5163                    (setq d (gnus-data-find (mail-header-number old-header))))
5164           (goto-char (gnus-data-pos d))
5165           (gnus-data-remove
5166            number
5167            (- (gnus-point-at-bol)
5168               (prog1
5169                   (1+ (gnus-point-at-eol))
5170                 (gnus-delete-line))))))
5171       (when old-header
5172         (mail-header-set-number header (mail-header-number old-header)))
5173       (setq gnus-newsgroup-sparse
5174             (delq (setq number (mail-header-number header))
5175                   gnus-newsgroup-sparse))
5176       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5177       (push number gnus-newsgroup-limit)
5178       (gnus-rebuild-thread (mail-header-id header) line)
5179       (gnus-summary-goto-subject number nil t))
5180     (when (and (numberp number)
5181                (> number 0))
5182       ;; We have to update the boundaries even if we can't fetch the
5183       ;; article if ID is a number -- so that the next `P' or `N'
5184       ;; command will fetch the previous (or next) article even
5185       ;; if the one we tried to fetch this time has been canceled.
5186       (when (> number gnus-newsgroup-end)
5187         (setq gnus-newsgroup-end number))
5188       (when (< number gnus-newsgroup-begin)
5189         (setq gnus-newsgroup-begin number))
5190       (setq gnus-newsgroup-unselected
5191             (delq number gnus-newsgroup-unselected)))
5192     ;; Report back a success?
5193     (and header (mail-header-number header))))
5194
5195 ;;; Process/prefix in the summary buffer
5196
5197 (defun gnus-summary-work-articles (n)
5198   "Return a list of articles to be worked upon.
5199 The prefix argument, the list of process marked articles, and the
5200 current article will be taken into consideration."
5201   (save-excursion
5202     (set-buffer gnus-summary-buffer)
5203     (cond
5204      (n
5205       ;; A numerical prefix has been given.
5206       (setq n (prefix-numeric-value n))
5207       (let ((backward (< n 0))
5208             (n (abs (prefix-numeric-value n)))
5209             articles article)
5210         (save-excursion
5211           (while
5212               (and (> n 0)
5213                    (push (setq article (gnus-summary-article-number))
5214                          articles)
5215                    (if backward
5216                        (gnus-summary-find-prev nil article)
5217                      (gnus-summary-find-next nil article)))
5218             (decf n)))
5219         (nreverse articles)))
5220      ((and (gnus-region-active-p) (mark))
5221       (message "region active")
5222       ;; Work on the region between point and mark.
5223       (let ((max (max (point) (mark)))
5224             articles article)
5225         (save-excursion
5226           (goto-char (min (min (point) (mark))))
5227           (while
5228               (and
5229                (push (setq article (gnus-summary-article-number)) articles)
5230                (gnus-summary-find-next nil article)
5231                (< (point) max)))
5232           (nreverse articles))))
5233      (gnus-newsgroup-processable
5234       ;; There are process-marked articles present.
5235       ;; Save current state.
5236       (gnus-summary-save-process-mark)
5237       ;; Return the list.
5238       (reverse gnus-newsgroup-processable))
5239      (t
5240       ;; Just return the current article.
5241       (list (gnus-summary-article-number))))))
5242
5243 (defmacro gnus-summary-iterate (arg &rest forms)
5244   "Iterate over the process/prefixed articles and do FORMS.
5245 ARG is the interactive prefix given to the command.  FORMS will be
5246 executed with point over the summary line of the articles."
5247   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5248     `(let ((,articles (gnus-summary-work-articles ,arg)))
5249        (while ,articles
5250          (gnus-summary-goto-subject (car ,articles))
5251          ,@forms
5252          (pop ,articles)))))
5253
5254 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5255 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5256
5257 (defun gnus-summary-save-process-mark ()
5258   "Push the current set of process marked articles on the stack."
5259   (interactive)
5260   (push (copy-sequence gnus-newsgroup-processable)
5261         gnus-newsgroup-process-stack))
5262
5263 (defun gnus-summary-kill-process-mark ()
5264   "Push the current set of process marked articles on the stack and unmark."
5265   (interactive)
5266   (gnus-summary-save-process-mark)
5267   (gnus-summary-unmark-all-processable))
5268
5269 (defun gnus-summary-yank-process-mark ()
5270   "Pop the last process mark state off the stack and restore it."
5271   (interactive)
5272   (unless gnus-newsgroup-process-stack
5273     (error "Empty mark stack"))
5274   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5275
5276 (defun gnus-summary-process-mark-set (set)
5277   "Make SET into the current process marked articles."
5278   (gnus-summary-unmark-all-processable)
5279   (while set
5280     (gnus-summary-set-process-mark (pop set))))
5281
5282 ;;; Searching and stuff
5283
5284 (defun gnus-summary-search-group (&optional backward use-level)
5285   "Search for next unread newsgroup.
5286 If optional argument BACKWARD is non-nil, search backward instead."
5287   (save-excursion
5288     (set-buffer gnus-group-buffer)
5289     (when (gnus-group-search-forward
5290            backward nil (if use-level (gnus-group-group-level) nil))
5291       (gnus-group-group-name))))
5292
5293 (defun gnus-summary-best-group (&optional exclude-group)
5294   "Find the name of the best unread group.
5295 If EXCLUDE-GROUP, do not go to this group."
5296   (save-excursion
5297     (set-buffer gnus-group-buffer)
5298     (save-excursion
5299       (gnus-group-best-unread-group exclude-group))))
5300
5301 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5302   (if backward (gnus-summary-find-prev)
5303     (let* ((dummy (gnus-summary-article-intangible-p))
5304            (article (or article (gnus-summary-article-number)))
5305            (arts (gnus-data-find-list article))
5306            result)
5307       (when (and (not dummy)
5308                  (or (not gnus-summary-check-current)
5309                      (not unread)
5310                      (not (gnus-data-unread-p (car arts)))))
5311         (setq arts (cdr arts)))
5312       (when (setq result
5313                   (if unread
5314                       (progn
5315                         (while arts
5316                           (when (or (and undownloaded
5317                                          (eq gnus-undownloaded-mark
5318                                              (gnus-data-mark (car arts))))
5319                                     (gnus-data-unread-p (car arts)))
5320                             (setq result (car arts)
5321                                   arts nil))
5322                           (setq arts (cdr arts)))
5323                         result)
5324                     (car arts)))
5325         (goto-char (gnus-data-pos result))
5326         (gnus-data-number result)))))
5327
5328 (defun gnus-summary-find-prev (&optional unread article)
5329   (let* ((eobp (eobp))
5330          (article (or article (gnus-summary-article-number)))
5331          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5332          result)
5333     (when (and (not eobp)
5334                (or (not gnus-summary-check-current)
5335                    (not unread)
5336                    (not (gnus-data-unread-p (car arts)))))
5337       (setq arts (cdr arts)))
5338     (when (setq result
5339                 (if unread
5340                     (progn
5341                       (while arts
5342                         (when (gnus-data-unread-p (car arts))
5343                           (setq result (car arts)
5344                                 arts nil))
5345                         (setq arts (cdr arts)))
5346                       result)
5347                   (car arts)))
5348       (goto-char (gnus-data-pos result))
5349       (gnus-data-number result))))
5350
5351 (defun gnus-summary-find-subject (subject &optional unread backward article)
5352   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5353          (article (or article (gnus-summary-article-number)))
5354          (articles (gnus-data-list backward))
5355          (arts (gnus-data-find-list article articles))
5356          result)
5357     (when (or (not gnus-summary-check-current)
5358               (not unread)
5359               (not (gnus-data-unread-p (car arts))))
5360       (setq arts (cdr arts)))
5361     (while arts
5362       (and (or (not unread)
5363                (gnus-data-unread-p (car arts)))
5364            (vectorp (gnus-data-header (car arts)))
5365            (gnus-subject-equal
5366             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5367            (setq result (car arts)
5368                  arts nil))
5369       (setq arts (cdr arts)))
5370     (and result
5371          (goto-char (gnus-data-pos result))
5372          (gnus-data-number result))))
5373
5374 (defun gnus-summary-search-forward (&optional unread subject backward)
5375   "Search forward for an article.
5376 If UNREAD, look for unread articles.  If SUBJECT, look for
5377 articles with that subject.  If BACKWARD, search backward instead."
5378   (cond (subject (gnus-summary-find-subject subject unread backward))
5379         (backward (gnus-summary-find-prev unread))
5380         (t (gnus-summary-find-next unread))))
5381
5382 (defun gnus-recenter (&optional n)
5383   "Center point in window and redisplay frame.
5384 Also do horizontal recentering."
5385   (interactive "P")
5386   (when (and gnus-auto-center-summary
5387              (not (eq gnus-auto-center-summary 'vertical)))
5388     (gnus-horizontal-recenter))
5389   (recenter n))
5390
5391 (defun gnus-summary-recenter ()
5392   "Center point in the summary window.
5393 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5394 displayed, no centering will be performed."
5395   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5396   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5397   (interactive)
5398   (let* ((top (cond ((< (window-height) 4) 0)
5399                     ((< (window-height) 7) 1)
5400                     (t (if (numberp gnus-auto-center-summary)
5401                            gnus-auto-center-summary
5402                          2))))
5403          (height (1- (window-height)))
5404          (bottom (save-excursion (goto-char (point-max))
5405                                  (forward-line (- height))
5406                                  (point)))
5407          (window (get-buffer-window (current-buffer))))
5408     ;; The user has to want it.
5409     (when gnus-auto-center-summary
5410       (when (get-buffer-window gnus-article-buffer)
5411         ;; Only do recentering when the article buffer is displayed,
5412         ;; Set the window start to either `bottom', which is the biggest
5413         ;; possible valid number, or the second line from the top,
5414         ;; whichever is the least.
5415         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5416           (if (> bottom top-pos)
5417               ;; Keep the second line from the top visible
5418               (set-window-start window top-pos t)
5419             ;; Try to keep the bottom line visible; if it's partially
5420             ;; obscured, either scroll one more line to make it fully
5421             ;; visible, or revert to using TOP-POS.
5422             (save-excursion
5423               (goto-char (point-max))
5424               (forward-line -1)
5425               (let ((last-line-start (point)))
5426                 (goto-char bottom)
5427                 (set-window-start window (point) t)
5428                 (when (not (pos-visible-in-window-p last-line-start window))
5429                   (forward-line 1)
5430                   (set-window-start window (min (point) top-pos) t)))))))
5431       ;; Do horizontal recentering while we're at it.
5432       (when (and (get-buffer-window (current-buffer) t)
5433                  (not (eq gnus-auto-center-summary 'vertical)))
5434         (let ((selected (selected-window)))
5435           (select-window (get-buffer-window (current-buffer) t))
5436           (gnus-summary-position-point)
5437           (gnus-horizontal-recenter)
5438           (select-window selected))))))
5439
5440 (defun gnus-summary-jump-to-group (newsgroup)
5441   "Move point to NEWSGROUP in group mode buffer."
5442   ;; Keep update point of group mode buffer if visible.
5443   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5444       (save-window-excursion
5445         ;; Take care of tree window mode.
5446         (when (get-buffer-window gnus-group-buffer)
5447           (pop-to-buffer gnus-group-buffer))
5448         (gnus-group-jump-to-group newsgroup))
5449     (save-excursion
5450       ;; Take care of tree window mode.
5451       (if (get-buffer-window gnus-group-buffer)
5452           (pop-to-buffer gnus-group-buffer)
5453         (set-buffer gnus-group-buffer))
5454       (gnus-group-jump-to-group newsgroup))))
5455
5456 ;; This function returns a list of article numbers based on the
5457 ;; difference between the ranges of read articles in this group and
5458 ;; the range of active articles.
5459 (defun gnus-list-of-unread-articles (group)
5460   (let* ((read (gnus-info-read (gnus-get-info group)))
5461          (active (or (gnus-active group) (gnus-activate-group group)))
5462          (last (cdr active))
5463          first nlast unread)
5464     ;; If none are read, then all are unread.
5465     (if (not read)
5466         (setq first (car active))
5467       ;; If the range of read articles is a single range, then the
5468       ;; first unread article is the article after the last read
5469       ;; article.  Sounds logical, doesn't it?
5470       (if (and (not (listp (cdr read)))
5471                (or (< (car read) (car active))
5472                    (progn (setq read (list read))
5473                           nil)))
5474           (setq first (max (car active) (1+ (cdr read))))
5475         ;; `read' is a list of ranges.
5476         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5477                                   (caar read)))
5478                   1)
5479           (setq first (car active)))
5480         (while read
5481           (when first
5482             (while (< first nlast)
5483               (push first unread)
5484               (setq first (1+ first))))
5485           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5486           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5487           (setq read (cdr read)))))
5488     ;; And add the last unread articles.
5489     (while (<= first last)
5490       (push first unread)
5491       (setq first (1+ first)))
5492     ;; Return the list of unread articles.
5493     (delq 0 (nreverse unread))))
5494
5495 (defun gnus-list-of-read-articles (group)
5496   "Return a list of unread, unticked and non-dormant articles."
5497   (let* ((info (gnus-get-info group))
5498          (marked (gnus-info-marks info))
5499          (active (gnus-active group)))
5500     (and info active
5501          (gnus-set-difference
5502           (gnus-sorted-complement
5503            (gnus-uncompress-range active)
5504            (gnus-list-of-unread-articles group))
5505           (append
5506            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5507            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5508
5509 ;; Various summary commands
5510
5511 (defun gnus-summary-select-article-buffer ()
5512   "Reconfigure windows to show article buffer."
5513   (interactive)
5514   (if (not (gnus-buffer-live-p gnus-article-buffer))
5515       (error "There is no article buffer for this summary buffer")
5516     (gnus-configure-windows 'article)
5517     (select-window (get-buffer-window gnus-article-buffer))))
5518
5519 (defun gnus-summary-universal-argument (arg)
5520   "Perform any operation on all articles that are process/prefixed."
5521   (interactive "P")
5522   (let ((articles (gnus-summary-work-articles arg))
5523         func article)
5524     (if (eq
5525          (setq
5526           func
5527           (key-binding
5528            (read-key-sequence
5529             (substitute-command-keys
5530              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5531          'undefined)
5532         (gnus-error 1 "Undefined key")
5533       (save-excursion
5534         (while articles
5535           (gnus-summary-goto-subject (setq article (pop articles)))
5536           (let (gnus-newsgroup-processable)
5537             (command-execute func))
5538           (gnus-summary-remove-process-mark article)))))
5539   (gnus-summary-position-point))
5540
5541 (defun gnus-summary-toggle-truncation (&optional arg)
5542   "Toggle truncation of summary lines.
5543 With arg, turn line truncation on iff arg is positive."
5544   (interactive "P")
5545   (setq truncate-lines
5546         (if (null arg) (not truncate-lines)
5547           (> (prefix-numeric-value arg) 0)))
5548   (redraw-display))
5549
5550 (defun gnus-summary-reselect-current-group (&optional all rescan)
5551   "Exit and then reselect the current newsgroup.
5552 The prefix argument ALL means to select all articles."
5553   (interactive "P")
5554   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5555     (error "Ephemeral groups can't be reselected"))
5556   (let ((current-subject (gnus-summary-article-number))
5557         (group gnus-newsgroup-name))
5558     (setq gnus-newsgroup-begin nil)
5559     (gnus-summary-exit)
5560     ;; We have to adjust the point of group mode buffer because
5561     ;; point was moved to the next unread newsgroup by exiting.
5562     (gnus-summary-jump-to-group group)
5563     (when rescan
5564       (save-excursion
5565         (gnus-group-get-new-news-this-group 1)))
5566     (gnus-group-read-group all t)
5567     (gnus-summary-goto-subject current-subject nil t)))
5568
5569 (defun gnus-summary-rescan-group (&optional all)
5570   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5571   (interactive "P")
5572   (gnus-summary-reselect-current-group all t))
5573
5574 (defun gnus-summary-update-info (&optional non-destructive)
5575   (save-excursion
5576     (let ((group gnus-newsgroup-name))
5577       (when group
5578         (when gnus-newsgroup-kill-headers
5579           (setq gnus-newsgroup-killed
5580                 (gnus-compress-sequence
5581                  (nconc
5582                   (gnus-set-sorted-intersection
5583                    (gnus-uncompress-range gnus-newsgroup-killed)
5584                    (setq gnus-newsgroup-unselected
5585                          (sort gnus-newsgroup-unselected '<)))
5586                   (setq gnus-newsgroup-unreads
5587                         (sort gnus-newsgroup-unreads '<)))
5588                  t)))
5589         (unless (listp (cdr gnus-newsgroup-killed))
5590           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5591         (let ((headers gnus-newsgroup-headers))
5592           ;; Set the new ranges of read articles.
5593           (save-excursion
5594             (set-buffer gnus-group-buffer)
5595             (gnus-undo-force-boundary))
5596           (gnus-update-read-articles
5597            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5598           ;; Set the current article marks.
5599           (let ((gnus-newsgroup-scored
5600                  (if (and (not gnus-save-score)
5601                           (not non-destructive))
5602                      nil
5603                    gnus-newsgroup-scored)))
5604             (save-excursion
5605               (gnus-update-marks)))
5606           ;; Do the cross-ref thing.
5607           (when gnus-use-cross-reference
5608             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5609           ;; Do not switch windows but change the buffer to work.
5610           (set-buffer gnus-group-buffer)
5611           (unless (gnus-ephemeral-group-p group)
5612             (gnus-group-update-group group)))))))
5613
5614 (defun gnus-summary-save-newsrc (&optional force)
5615   "Save the current number of read/marked articles in the dribble buffer.
5616 The dribble buffer will then be saved.
5617 If FORCE (the prefix), also save the .newsrc file(s)."
5618   (interactive "P")
5619   (gnus-summary-update-info t)
5620   (if force
5621       (gnus-save-newsrc-file)
5622     (gnus-dribble-save)))
5623
5624 (defun gnus-summary-exit (&optional temporary)
5625   "Exit reading current newsgroup, and then return to group selection mode.
5626 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5627   (interactive)
5628   (gnus-set-global-variables)
5629   (when (gnus-buffer-live-p gnus-article-buffer)
5630     (save-excursion
5631       (set-buffer gnus-article-buffer)
5632       (mm-destroy-parts gnus-article-mime-handles)
5633       ;; Set it to nil for safety reason.
5634       (setq gnus-article-mime-handle-alist nil)
5635       (setq gnus-article-mime-handles nil)))
5636   (gnus-kill-save-kill-buffer)
5637   (gnus-async-halt-prefetch)
5638   (let* ((group gnus-newsgroup-name)
5639          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5640          (mode major-mode)
5641          (group-point nil)
5642          (buf (current-buffer)))
5643     (unless quit-config
5644       ;; Do adaptive scoring, and possibly save score files.
5645       (when gnus-newsgroup-adaptive
5646         (gnus-score-adaptive))
5647       (when gnus-use-scoring
5648         (gnus-score-save)))
5649     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5650     ;; If we have several article buffers, we kill them at exit.
5651     (unless gnus-single-article-buffer
5652       (gnus-kill-buffer gnus-original-article-buffer)
5653       (setq gnus-article-current nil))
5654     (when gnus-use-cache
5655       (gnus-cache-possibly-remove-articles)
5656       (gnus-cache-save-buffers))
5657     (gnus-async-prefetch-remove-group group)
5658     (when gnus-suppress-duplicates
5659       (gnus-dup-enter-articles))
5660     (when gnus-use-trees
5661       (gnus-tree-close group))
5662     (when gnus-use-cache
5663       (gnus-cache-write-active))
5664     ;; Remove entries for this group.
5665     (nnmail-purge-split-history (gnus-group-real-name group))
5666     ;; Make all changes in this group permanent.
5667     (unless quit-config
5668       (gnus-run-hooks 'gnus-exit-group-hook)
5669       (gnus-summary-update-info))
5670     (gnus-close-group group)
5671     ;; Make sure where we were, and go to next newsgroup.
5672     (set-buffer gnus-group-buffer)
5673     (unless quit-config
5674       (gnus-group-jump-to-group group))
5675     (gnus-run-hooks 'gnus-summary-exit-hook)
5676     (unless (or quit-config
5677                 ;; If this group has disappeared from the summary
5678                 ;; buffer, don't skip forwards.
5679                 (not (string= group (gnus-group-group-name))))
5680       (gnus-group-next-unread-group 1))
5681     (setq group-point (point))
5682     (if temporary
5683         nil                             ;Nothing to do.
5684       ;; If we have several article buffers, we kill them at exit.
5685       (unless gnus-single-article-buffer
5686         (gnus-kill-buffer gnus-article-buffer)
5687         (gnus-kill-buffer gnus-original-article-buffer)
5688         (setq gnus-article-current nil))
5689       (set-buffer buf)
5690       (if (not gnus-kill-summary-on-exit)
5691           (gnus-deaden-summary)
5692         ;; We set all buffer-local variables to nil.  It is unclear why
5693         ;; this is needed, but if we don't, buffer-local variables are
5694         ;; not garbage-collected, it seems.  This would the lead to en
5695         ;; ever-growing Emacs.
5696         (gnus-summary-clear-local-variables)
5697         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5698           (gnus-summary-clear-local-variables))
5699         (when (get-buffer gnus-article-buffer)
5700           (bury-buffer gnus-article-buffer))
5701         ;; We clear the global counterparts of the buffer-local
5702         ;; variables as well, just to be on the safe side.
5703         (set-buffer gnus-group-buffer)
5704         (gnus-summary-clear-local-variables)
5705         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5706           (gnus-summary-clear-local-variables))
5707         ;; Return to group mode buffer.
5708         (when (eq mode 'gnus-summary-mode)
5709           (gnus-kill-buffer buf)))
5710       (setq gnus-current-select-method gnus-select-method)
5711       (pop-to-buffer gnus-group-buffer)
5712       (if (not quit-config)
5713           (progn
5714             (goto-char group-point)
5715             (gnus-configure-windows 'group 'force))
5716         (gnus-handle-ephemeral-exit quit-config))
5717       ;; Clear the current group name.
5718       (unless quit-config
5719         (setq gnus-newsgroup-name nil)))))
5720
5721 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
5722 (defun gnus-summary-exit-no-update (&optional no-questions)
5723   "Quit reading current newsgroup without updating read article info."
5724   (interactive)
5725   (let* ((group gnus-newsgroup-name)
5726          (quit-config (gnus-group-quit-config group)))
5727     (when (or no-questions
5728               gnus-expert-user
5729               (gnus-y-or-n-p "Discard changes to this group and exit? "))
5730       (gnus-async-halt-prefetch)
5731       (mapcar 'funcall
5732               (delq 'gnus-summary-expire-articles
5733                     (copy-sequence gnus-summary-prepare-exit-hook)))
5734       (when (gnus-buffer-live-p gnus-article-buffer)
5735         (save-excursion
5736           (set-buffer gnus-article-buffer)
5737           (mm-destroy-parts gnus-article-mime-handles)
5738           ;; Set it to nil for safety reason.
5739           (setq gnus-article-mime-handle-alist nil)
5740           (setq gnus-article-mime-handles nil)))
5741       ;; If we have several article buffers, we kill them at exit.
5742       (unless gnus-single-article-buffer
5743         (gnus-kill-buffer gnus-article-buffer)
5744         (gnus-kill-buffer gnus-original-article-buffer)
5745         (setq gnus-article-current nil))
5746       (if (not gnus-kill-summary-on-exit)
5747           (gnus-deaden-summary)
5748         (gnus-close-group group)
5749         (gnus-summary-clear-local-variables)
5750         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5751           (gnus-summary-clear-local-variables))
5752         (set-buffer gnus-group-buffer)
5753         (gnus-summary-clear-local-variables)
5754         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5755           (gnus-summary-clear-local-variables))
5756         (when (get-buffer gnus-summary-buffer)
5757           (kill-buffer gnus-summary-buffer)))
5758       (unless gnus-single-article-buffer
5759         (setq gnus-article-current nil))
5760       (when gnus-use-trees
5761         (gnus-tree-close group))
5762       (gnus-async-prefetch-remove-group group)
5763       (when (get-buffer gnus-article-buffer)
5764         (bury-buffer gnus-article-buffer))
5765       ;; Return to the group buffer.
5766       (gnus-configure-windows 'group 'force)
5767       ;; Clear the current group name.
5768       (setq gnus-newsgroup-name nil)
5769       (when (equal (gnus-group-group-name) group)
5770         (gnus-group-next-unread-group 1))
5771       (when quit-config
5772         (gnus-handle-ephemeral-exit quit-config)))))
5773
5774 (defun gnus-handle-ephemeral-exit (quit-config)
5775   "Handle movement when leaving an ephemeral group.
5776 The state which existed when entering the ephemeral is reset."
5777   (if (not (buffer-name (car quit-config)))
5778       (gnus-configure-windows 'group 'force)
5779     (set-buffer (car quit-config))
5780     (cond ((eq major-mode 'gnus-summary-mode)
5781            (gnus-set-global-variables))
5782           ((eq major-mode 'gnus-article-mode)
5783            (save-excursion
5784              ;; The `gnus-summary-buffer' variable may point
5785              ;; to the old summary buffer when using a single
5786              ;; article buffer.
5787              (unless (gnus-buffer-live-p gnus-summary-buffer)
5788                (set-buffer gnus-group-buffer))
5789              (set-buffer gnus-summary-buffer)
5790              (gnus-set-global-variables))))
5791     (if (or (eq (cdr quit-config) 'article)
5792             (eq (cdr quit-config) 'pick))
5793         (progn
5794           ;; The current article may be from the ephemeral group
5795           ;; thus it is best that we reload this article
5796           (gnus-summary-show-article)
5797           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
5798               (gnus-configure-windows 'pick 'force)
5799             (gnus-configure-windows (cdr quit-config) 'force)))
5800       (gnus-configure-windows (cdr quit-config) 'force))
5801     (when (eq major-mode 'gnus-summary-mode)
5802       (gnus-summary-next-subject 1 nil t)
5803       (gnus-summary-recenter)
5804       (gnus-summary-position-point))))
5805
5806 ;;; Dead summaries.
5807
5808 (defvar gnus-dead-summary-mode-map nil)
5809
5810 (unless gnus-dead-summary-mode-map
5811   (setq gnus-dead-summary-mode-map (make-keymap))
5812   (suppress-keymap gnus-dead-summary-mode-map)
5813   (substitute-key-definition
5814    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
5815   (let ((keys '("\C-d" "\r" "\177" [delete])))
5816     (while keys
5817       (define-key gnus-dead-summary-mode-map
5818         (pop keys) 'gnus-summary-wake-up-the-dead))))
5819
5820 (defvar gnus-dead-summary-mode nil
5821   "Minor mode for Gnus summary buffers.")
5822
5823 (defun gnus-dead-summary-mode (&optional arg)
5824   "Minor mode for Gnus summary buffers."
5825   (interactive "P")
5826   (when (eq major-mode 'gnus-summary-mode)
5827     (make-local-variable 'gnus-dead-summary-mode)
5828     (setq gnus-dead-summary-mode
5829           (if (null arg) (not gnus-dead-summary-mode)
5830             (> (prefix-numeric-value arg) 0)))
5831     (when gnus-dead-summary-mode
5832       (gnus-add-minor-mode
5833        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
5834
5835 (defun gnus-deaden-summary ()
5836   "Make the current summary buffer into a dead summary buffer."
5837   ;; Kill any previous dead summary buffer.
5838   (when (and gnus-dead-summary
5839              (buffer-name gnus-dead-summary))
5840     (save-excursion
5841       (set-buffer gnus-dead-summary)
5842       (when gnus-dead-summary-mode
5843         (kill-buffer (current-buffer)))))
5844   ;; Make this the current dead summary.
5845   (setq gnus-dead-summary (current-buffer))
5846   (gnus-dead-summary-mode 1)
5847   (let ((name (buffer-name)))
5848     (when (string-match "Summary" name)
5849       (rename-buffer
5850        (concat (substring name 0 (match-beginning 0)) "Dead "
5851                (substring name (match-beginning 0)))
5852        t)
5853       (bury-buffer))))
5854
5855 (defun gnus-kill-or-deaden-summary (buffer)
5856   "Kill or deaden the summary BUFFER."
5857   (save-excursion
5858     (when (and (buffer-name buffer)
5859                (not gnus-single-article-buffer))
5860       (save-excursion
5861         (set-buffer buffer)
5862         (gnus-kill-buffer gnus-article-buffer)
5863         (gnus-kill-buffer gnus-original-article-buffer)))
5864     (cond (gnus-kill-summary-on-exit
5865            (when (and gnus-use-trees
5866                       (gnus-buffer-exists-p buffer))
5867              (save-excursion
5868                (set-buffer buffer)
5869                (gnus-tree-close gnus-newsgroup-name)))
5870            (gnus-kill-buffer buffer))
5871           ((gnus-buffer-exists-p buffer)
5872            (save-excursion
5873              (set-buffer buffer)
5874              (gnus-deaden-summary))))))
5875
5876 (defun gnus-summary-wake-up-the-dead (&rest args)
5877   "Wake up the dead summary buffer."
5878   (interactive)
5879   (gnus-dead-summary-mode -1)
5880   (let ((name (buffer-name)))
5881     (when (string-match "Dead " name)
5882       (rename-buffer
5883        (concat (substring name 0 (match-beginning 0))
5884                (substring name (match-end 0)))
5885        t)))
5886   (gnus-message 3 "This dead summary is now alive again"))
5887
5888 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
5889 (defun gnus-summary-fetch-faq (&optional faq-dir)
5890   "Fetch the FAQ for the current group.
5891 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
5892 in."
5893   (interactive
5894    (list
5895     (when current-prefix-arg
5896       (completing-read
5897        "Faq dir: " (and (listp gnus-group-faq-directory)
5898                         (mapcar (lambda (file) (list file))
5899                                 gnus-group-faq-directory))))))
5900   (let (gnus-faq-buffer)
5901     (when (setq gnus-faq-buffer
5902                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
5903       (gnus-configure-windows 'summary-faq))))
5904
5905 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
5906 (defun gnus-summary-describe-group (&optional force)
5907   "Describe the current newsgroup."
5908   (interactive "P")
5909   (gnus-group-describe-group force gnus-newsgroup-name))
5910
5911 (defun gnus-summary-describe-briefly ()
5912   "Describe summary mode commands briefly."
5913   (interactive)
5914   (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info        \\[gnus-summary-describe-briefly]:This help")))
5915
5916 ;; Walking around group mode buffer from summary mode.
5917
5918 (defun gnus-summary-next-group (&optional no-article target-group backward)
5919   "Exit current newsgroup and then select next unread newsgroup.
5920 If prefix argument NO-ARTICLE is non-nil, no article is selected
5921 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
5922 previous group instead."
5923   (interactive "P")
5924   ;; Stop pre-fetching.
5925   (gnus-async-halt-prefetch)
5926   (let ((current-group gnus-newsgroup-name)
5927         (current-buffer (current-buffer))
5928         entered)
5929     ;; First we semi-exit this group to update Xrefs and all variables.
5930     ;; We can't do a real exit, because the window conf must remain
5931     ;; the same in case the user is prompted for info, and we don't
5932     ;; want the window conf to change before that...
5933     (gnus-summary-exit t)
5934     (while (not entered)
5935       ;; Then we find what group we are supposed to enter.
5936       (set-buffer gnus-group-buffer)
5937       (gnus-group-jump-to-group current-group)
5938       (setq target-group
5939             (or target-group
5940                 (if (eq gnus-keep-same-level 'best)
5941                     (gnus-summary-best-group gnus-newsgroup-name)
5942                   (gnus-summary-search-group backward gnus-keep-same-level))))
5943       (if (not target-group)
5944           ;; There are no further groups, so we return to the group
5945           ;; buffer.
5946           (progn
5947             (gnus-message 5 "Returning to the group buffer")
5948             (setq entered t)
5949             (when (gnus-buffer-live-p current-buffer)
5950               (set-buffer current-buffer)
5951               (gnus-summary-exit))
5952             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
5953         ;; We try to enter the target group.
5954         (gnus-group-jump-to-group target-group)
5955         (let ((unreads (gnus-group-group-unread)))
5956           (if (and (or (eq t unreads)
5957                        (and unreads (not (zerop unreads))))
5958                    (gnus-summary-read-group
5959                     target-group nil no-article
5960                     (and (buffer-name current-buffer) current-buffer)
5961                     nil backward))
5962               (setq entered t)
5963             (setq current-group target-group
5964                   target-group nil)))))))
5965
5966 (defun gnus-summary-prev-group (&optional no-article)
5967   "Exit current newsgroup and then select previous unread newsgroup.
5968 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
5969   (interactive "P")
5970   (gnus-summary-next-group no-article nil t))
5971
5972 ;; Walking around summary lines.
5973
5974 (defun gnus-summary-first-subject (&optional unread undownloaded)
5975   "Go to the first unread subject.
5976 If UNREAD is non-nil, go to the first unread article.
5977 Returns the article selected or nil if there are no unread articles."
5978   (interactive "P")
5979   (prog1
5980       (cond
5981        ;; Empty summary.
5982        ((null gnus-newsgroup-data)
5983         (gnus-message 3 "No articles in the group")
5984         nil)
5985        ;; Pick the first article.
5986        ((not unread)
5987         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
5988         (gnus-data-number (car gnus-newsgroup-data)))
5989        ;; No unread articles.
5990        ((null gnus-newsgroup-unreads)
5991         (gnus-message 3 "No more unread articles")
5992         nil)
5993        ;; Find the first unread article.
5994        (t
5995         (let ((data gnus-newsgroup-data))
5996           (while (and data
5997                       (and (not (and undownloaded
5998                                      (eq gnus-undownloaded-mark
5999                                          (gnus-data-mark (car data)))))
6000                            (not (gnus-data-unread-p (car data)))))
6001             (setq data (cdr data)))
6002           (when data
6003             (goto-char (gnus-data-pos (car data)))
6004             (gnus-data-number (car data))))))
6005     (gnus-summary-position-point)))
6006
6007 (defun gnus-summary-next-subject (n &optional unread dont-display)
6008   "Go to next N'th summary line.
6009 If N is negative, go to the previous N'th subject line.
6010 If UNREAD is non-nil, only unread articles are selected.
6011 The difference between N and the actual number of steps taken is
6012 returned."
6013   (interactive "p")
6014   (let ((backward (< n 0))
6015         (n (abs n)))
6016     (while (and (> n 0)
6017                 (if backward
6018                     (gnus-summary-find-prev unread)
6019                   (gnus-summary-find-next unread)))
6020       (unless (zerop (setq n (1- n)))
6021         (gnus-summary-show-thread)))
6022     (when (/= 0 n)
6023       (gnus-message 7 "No more%s articles"
6024                     (if unread " unread" "")))
6025     (unless dont-display
6026       (gnus-summary-recenter)
6027       (gnus-summary-position-point))
6028     n))
6029
6030 (defun gnus-summary-next-unread-subject (n)
6031   "Go to next N'th unread summary line."
6032   (interactive "p")
6033   (gnus-summary-next-subject n t))
6034
6035 (defun gnus-summary-prev-subject (n &optional unread)
6036   "Go to previous N'th summary line.
6037 If optional argument UNREAD is non-nil, only unread article is selected."
6038   (interactive "p")
6039   (gnus-summary-next-subject (- n) unread))
6040
6041 (defun gnus-summary-prev-unread-subject (n)
6042   "Go to previous N'th unread summary line."
6043   (interactive "p")
6044   (gnus-summary-next-subject (- n) t))
6045
6046 (defun gnus-summary-goto-subject (article &optional force silent)
6047   "Go the subject line of ARTICLE.
6048 If FORCE, also allow jumping to articles not currently shown."
6049   (interactive "nArticle number: ")
6050   (let ((b (point))
6051         (data (gnus-data-find article)))
6052     ;; We read in the article if we have to.
6053     (and (not data)
6054          force
6055          (gnus-summary-insert-subject
6056           article
6057           (if (or (numberp force) (vectorp force)) force)
6058           t)
6059          (setq data (gnus-data-find article)))
6060     (goto-char b)
6061     (if (not data)
6062         (progn
6063           (unless silent
6064             (gnus-message 3 "Can't find article %d" article))
6065           nil)
6066       (goto-char (gnus-data-pos data))
6067       (gnus-summary-position-point)
6068       article)))
6069
6070 ;; Walking around summary lines with displaying articles.
6071
6072 (defun gnus-summary-expand-window (&optional arg)
6073   "Make the summary buffer take up the entire Emacs frame.
6074 Given a prefix, will force an `article' buffer configuration."
6075   (interactive "P")
6076   (if arg
6077       (gnus-configure-windows 'article 'force)
6078     (gnus-configure-windows 'summary 'force)))
6079
6080 (defun gnus-summary-display-article (article &optional all-header)
6081   "Display ARTICLE in article buffer."
6082   (when (gnus-buffer-live-p gnus-article-buffer)
6083     (with-current-buffer gnus-article-buffer
6084       (mm-enable-multibyte-mule4)))
6085   (gnus-set-global-variables)
6086   (when (gnus-buffer-live-p gnus-article-buffer)
6087     (with-current-buffer gnus-article-buffer
6088       (setq gnus-article-charset gnus-newsgroup-charset)
6089       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6090       (mm-enable-multibyte-mule4)))
6091   (if (null article)
6092       nil
6093     (prog1
6094         (if gnus-summary-display-article-function
6095             (funcall gnus-summary-display-article-function article all-header)
6096           (gnus-article-prepare article all-header))
6097       (gnus-run-hooks 'gnus-select-article-hook)
6098       (when (and gnus-current-article
6099                  (not (zerop gnus-current-article)))
6100         (gnus-summary-goto-subject gnus-current-article))
6101       (gnus-summary-recenter)
6102       (when (and gnus-use-trees gnus-show-threads)
6103         (gnus-possibly-generate-tree article)
6104         (gnus-highlight-selected-tree article))
6105       ;; Successfully display article.
6106       (gnus-article-set-window-start
6107        (cdr (assq article gnus-newsgroup-bookmarks))))))
6108
6109 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6110   "Select the current article.
6111 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6112 non-nil, the article will be re-fetched even if it already present in
6113 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6114 be displayed."
6115   ;; Make sure we are in the summary buffer to work around bbdb bug.
6116   (unless (eq major-mode 'gnus-summary-mode)
6117     (set-buffer gnus-summary-buffer))
6118   (let ((article (or article (gnus-summary-article-number)))
6119         (all-headers (not (not all-headers))) ;Must be T or NIL.
6120         gnus-summary-display-article-function)
6121     (and (not pseudo)
6122          (gnus-summary-article-pseudo-p article)
6123          (error "This is a pseudo-article"))
6124     (save-excursion
6125       (set-buffer gnus-summary-buffer)
6126       (if (or (and gnus-single-article-buffer
6127                    (or (null gnus-current-article)
6128                        (null gnus-article-current)
6129                        (null (get-buffer gnus-article-buffer))
6130                        (not (eq article (cdr gnus-article-current)))
6131                        (not (equal (car gnus-article-current)
6132                                    gnus-newsgroup-name))))
6133               (and (not gnus-single-article-buffer)
6134                    (or (null gnus-current-article)
6135                        (not (eq gnus-current-article article))))
6136               force)
6137           ;; The requested article is different from the current article.
6138           (progn
6139             (gnus-summary-display-article article all-headers)
6140             (when (gnus-buffer-live-p gnus-article-buffer)
6141                (with-current-buffer gnus-article-buffer
6142                 (if (not gnus-article-decoded-p) ;; a local variable
6143                     (mm-disable-multibyte-mule4))))
6144             (when (or all-headers gnus-show-all-headers)
6145               (gnus-article-show-all-headers))
6146             (gnus-article-set-window-start
6147              (cdr (assq article gnus-newsgroup-bookmarks)))
6148             article)
6149         (when (or all-headers gnus-show-all-headers)
6150           (gnus-article-show-all-headers))
6151         'old))))
6152
6153 (defun gnus-summary-force-verify-and-decrypt ()
6154   (interactive)
6155   (let ((mm-verify-option 'known)
6156         (mm-decrypt-option 'known))
6157     (gnus-summary-select-article nil 'force)))
6158
6159 (defun gnus-summary-set-current-mark (&optional current-mark)
6160   "Obsolete function."
6161   nil)
6162
6163 (defun gnus-summary-next-article (&optional unread subject backward push)
6164   "Select the next article.
6165 If UNREAD, only unread articles are selected.
6166 If SUBJECT, only articles with SUBJECT are selected.
6167 If BACKWARD, the previous article is selected instead of the next."
6168   (interactive "P")
6169   (cond
6170    ;; Is there such an article?
6171    ((and (gnus-summary-search-forward unread subject backward)
6172          (or (gnus-summary-display-article (gnus-summary-article-number))
6173              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6174     (gnus-summary-position-point))
6175    ;; If not, we try the first unread, if that is wanted.
6176    ((and subject
6177          gnus-auto-select-same
6178          (gnus-summary-first-unread-article))
6179     (gnus-summary-position-point)
6180     (gnus-message 6 "Wrapped"))
6181    ;; Try to get next/previous article not displayed in this group.
6182    ((and gnus-auto-extend-newsgroup
6183          (not unread) (not subject))
6184     (gnus-summary-goto-article
6185      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6186      nil (count-lines (point-min) (point))))
6187    ;; Go to next/previous group.
6188    (t
6189     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6190       (gnus-summary-jump-to-group gnus-newsgroup-name))
6191     (let ((cmd last-command-char)
6192           (point
6193            (save-excursion
6194              (set-buffer gnus-group-buffer)
6195              (point)))
6196           (group
6197            (if (eq gnus-keep-same-level 'best)
6198                (gnus-summary-best-group gnus-newsgroup-name)
6199              (gnus-summary-search-group backward gnus-keep-same-level))))
6200       ;; For some reason, the group window gets selected.  We change
6201       ;; it back.
6202       (select-window (get-buffer-window (current-buffer)))
6203       ;; Select next unread newsgroup automagically.
6204       (cond
6205        ((or (not gnus-auto-select-next)
6206             (not cmd))
6207         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6208        ((or (eq gnus-auto-select-next 'quietly)
6209             (and (eq gnus-auto-select-next 'slightly-quietly)
6210                  push)
6211             (and (eq gnus-auto-select-next 'almost-quietly)
6212                  (gnus-summary-last-article-p)))
6213         ;; Select quietly.
6214         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6215             (gnus-summary-exit)
6216           (gnus-message 7 "No more%s articles (%s)..."
6217                         (if unread " unread" "")
6218                         (if group (concat "selecting " group)
6219                           "exiting"))
6220           (gnus-summary-next-group nil group backward)))
6221        (t
6222         (when (gnus-key-press-event-p last-input-event)
6223           (gnus-summary-walk-group-buffer
6224            gnus-newsgroup-name cmd unread backward point))))))))
6225
6226 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6227   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6228                       (?\C-p (gnus-group-prev-unread-group 1))))
6229         (cursor-in-echo-area t)
6230         keve key group ended)
6231     (save-excursion
6232       (set-buffer gnus-group-buffer)
6233       (goto-char start)
6234       (setq group
6235             (if (eq gnus-keep-same-level 'best)
6236                 (gnus-summary-best-group gnus-newsgroup-name)
6237               (gnus-summary-search-group backward gnus-keep-same-level))))
6238     (while (not ended)
6239       (gnus-message
6240        5 "No more%s articles%s" (if unread " unread" "")
6241        (if (and group
6242                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6243            (format " (Type %s for %s [%s])"
6244                    (single-key-description cmd) group
6245                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6246          (format " (Type %s to exit %s)"
6247                  (single-key-description cmd)
6248                  gnus-newsgroup-name)))
6249       ;; Confirm auto selection.
6250       (setq key (car (setq keve (gnus-read-event-char))))
6251       (setq ended t)
6252       (cond
6253        ((assq key keystrokes)
6254         (let ((obuf (current-buffer)))
6255           (switch-to-buffer gnus-group-buffer)
6256           (when group
6257             (gnus-group-jump-to-group group))
6258           (eval (cadr (assq key keystrokes)))
6259           (setq group (gnus-group-group-name))
6260           (switch-to-buffer obuf))
6261         (setq ended nil))
6262        ((equal key cmd)
6263         (if (or (not group)
6264                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6265             (gnus-summary-exit)
6266           (gnus-summary-next-group nil group backward)))
6267        (t
6268         (push (cdr keve) unread-command-events))))))
6269
6270 (defun gnus-summary-next-unread-article ()
6271   "Select unread article after current one."
6272   (interactive)
6273   (gnus-summary-next-article
6274    (or (not (eq gnus-summary-goto-unread 'never))
6275        (gnus-summary-last-article-p (gnus-summary-article-number)))
6276    (and gnus-auto-select-same
6277         (gnus-summary-article-subject))))
6278
6279 (defun gnus-summary-prev-article (&optional unread subject)
6280   "Select the article after the current one.
6281 If UNREAD is non-nil, only unread articles are selected."
6282   (interactive "P")
6283   (gnus-summary-next-article unread subject t))
6284
6285 (defun gnus-summary-prev-unread-article ()
6286   "Select unread article before current one."
6287   (interactive)
6288   (gnus-summary-prev-article
6289    (or (not (eq gnus-summary-goto-unread 'never))
6290        (gnus-summary-first-article-p (gnus-summary-article-number)))
6291    (and gnus-auto-select-same
6292         (gnus-summary-article-subject))))
6293
6294 (defun gnus-summary-next-page (&optional lines circular)
6295   "Show next page of the selected article.
6296 If at the end of the current article, select the next article.
6297 LINES says how many lines should be scrolled up.
6298
6299 If CIRCULAR is non-nil, go to the start of the article instead of
6300 selecting the next article when reaching the end of the current
6301 article."
6302   (interactive "P")
6303   (setq gnus-summary-buffer (current-buffer))
6304   (gnus-set-global-variables)
6305   (let ((article (gnus-summary-article-number))
6306         (article-window (get-buffer-window gnus-article-buffer t))
6307         endp)
6308     ;; If the buffer is empty, we have no article.
6309     (unless article
6310       (error "No article to select"))
6311     (gnus-configure-windows 'article)
6312     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6313         (if (and (eq gnus-summary-goto-unread 'never)
6314                  (not (gnus-summary-last-article-p article)))
6315             (gnus-summary-next-article)
6316           (gnus-summary-next-unread-article))
6317       (if (or (null gnus-current-article)
6318               (null gnus-article-current)
6319               (/= article (cdr gnus-article-current))
6320               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6321           ;; Selected subject is different from current article's.
6322           (gnus-summary-display-article article)
6323         (when article-window
6324           (gnus-eval-in-buffer-window gnus-article-buffer
6325             (setq endp (gnus-article-next-page lines)))
6326           (when endp
6327             (cond (circular
6328                    (gnus-summary-beginning-of-article))
6329                   (lines
6330                    (gnus-message 3 "End of message"))
6331                   ((null lines)
6332                    (if (and (eq gnus-summary-goto-unread 'never)
6333                             (not (gnus-summary-last-article-p article)))
6334                        (gnus-summary-next-article)
6335                      (gnus-summary-next-unread-article))))))))
6336     (gnus-summary-recenter)
6337     (gnus-summary-position-point)))
6338
6339 (defun gnus-summary-prev-page (&optional lines move)
6340   "Show previous page of selected article.
6341 Argument LINES specifies lines to be scrolled down.
6342 If MOVE, move to the previous unread article if point is at
6343 the beginning of the buffer."
6344   (interactive "P")
6345   (let ((article (gnus-summary-article-number))
6346         (article-window (get-buffer-window gnus-article-buffer t))
6347         endp)
6348     (gnus-configure-windows 'article)
6349     (if (or (null gnus-current-article)
6350             (null gnus-article-current)
6351             (/= article (cdr gnus-article-current))
6352             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6353         ;; Selected subject is different from current article's.
6354         (gnus-summary-display-article article)
6355       (gnus-summary-recenter)
6356       (when article-window
6357         (gnus-eval-in-buffer-window gnus-article-buffer
6358           (setq endp (gnus-article-prev-page lines)))
6359         (when (and move endp)
6360           (cond (lines
6361                  (gnus-message 3 "Beginning of message"))
6362                 ((null lines)
6363                  (if (and (eq gnus-summary-goto-unread 'never)
6364                           (not (gnus-summary-first-article-p article)))
6365                      (gnus-summary-prev-article)
6366                    (gnus-summary-prev-unread-article))))))))
6367   (gnus-summary-position-point))
6368
6369 (defun gnus-summary-prev-page-or-article (&optional lines)
6370   "Show previous page of selected article.
6371 Argument LINES specifies lines to be scrolled down.
6372 If at the beginning of the article, go to the next article."
6373   (interactive "P")
6374   (gnus-summary-prev-page lines t))
6375
6376 (defun gnus-summary-scroll-up (lines)
6377   "Scroll up (or down) one line current article.
6378 Argument LINES specifies lines to be scrolled up (or down if negative)."
6379   (interactive "p")
6380   (gnus-configure-windows 'article)
6381   (gnus-summary-show-thread)
6382   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6383     (gnus-eval-in-buffer-window gnus-article-buffer
6384       (cond ((> lines 0)
6385              (when (gnus-article-next-page lines)
6386                (gnus-message 3 "End of message")))
6387             ((< lines 0)
6388              (gnus-article-prev-page (- lines))))))
6389   (gnus-summary-recenter)
6390   (gnus-summary-position-point))
6391
6392 (defun gnus-summary-scroll-down (lines)
6393   "Scroll down (or up) one line current article.
6394 Argument LINES specifies lines to be scrolled down (or up if negative)."
6395   (interactive "p")
6396   (gnus-summary-scroll-up (- lines)))
6397
6398 (defun gnus-summary-next-same-subject ()
6399   "Select next article which has the same subject as current one."
6400   (interactive)
6401   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6402
6403 (defun gnus-summary-prev-same-subject ()
6404   "Select previous article which has the same subject as current one."
6405   (interactive)
6406   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6407
6408 (defun gnus-summary-next-unread-same-subject ()
6409   "Select next unread article which has the same subject as current one."
6410   (interactive)
6411   (gnus-summary-next-article t (gnus-summary-article-subject)))
6412
6413 (defun gnus-summary-prev-unread-same-subject ()
6414   "Select previous unread article which has the same subject as current one."
6415   (interactive)
6416   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6417
6418 (defun gnus-summary-first-unread-article ()
6419   "Select the first unread article.
6420 Return nil if there are no unread articles."
6421   (interactive)
6422   (prog1
6423       (when (gnus-summary-first-subject t)
6424         (gnus-summary-show-thread)
6425         (gnus-summary-first-subject t)
6426         (gnus-summary-display-article (gnus-summary-article-number)))
6427     (gnus-summary-position-point)))
6428
6429 (defun gnus-summary-first-unread-subject ()
6430   "Place the point on the subject line of the first unread article.
6431 Return nil if there are no unread articles."
6432   (interactive)
6433   (prog1
6434       (when (gnus-summary-first-subject t)
6435         (gnus-summary-show-thread)
6436         (gnus-summary-first-subject t))
6437     (gnus-summary-position-point)))
6438
6439 (defun gnus-summary-first-article ()
6440   "Select the first article.
6441 Return nil if there are no articles."
6442   (interactive)
6443   (prog1
6444       (when (gnus-summary-first-subject)
6445         (gnus-summary-show-thread)
6446         (gnus-summary-first-subject)
6447         (gnus-summary-display-article (gnus-summary-article-number)))
6448     (gnus-summary-position-point)))
6449
6450 (defun gnus-summary-best-unread-article ()
6451   "Select the unread article with the highest score."
6452   (interactive)
6453   (let ((best -1000000)
6454         (data gnus-newsgroup-data)
6455         article score)
6456     (while data
6457       (and (gnus-data-unread-p (car data))
6458            (> (setq score
6459                     (gnus-summary-article-score (gnus-data-number (car data))))
6460               best)
6461            (setq best score
6462                  article (gnus-data-number (car data))))
6463       (setq data (cdr data)))
6464     (prog1
6465         (if article
6466             (gnus-summary-goto-article article)
6467           (error "No unread articles"))
6468       (gnus-summary-position-point))))
6469
6470 (defun gnus-summary-last-subject ()
6471   "Go to the last displayed subject line in the group."
6472   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6473     (when article
6474       (gnus-summary-goto-subject article))))
6475
6476 (defun gnus-summary-goto-article (article &optional all-headers force)
6477   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6478 If ALL-HEADERS is non-nil, no header lines are hidden.
6479 If FORCE, go to the article even if it isn't displayed.  If FORCE
6480 is a number, it is the line the article is to be displayed on."
6481   (interactive
6482    (list
6483     (completing-read
6484      "Article number or Message-ID: "
6485      (mapcar (lambda (number) (list (int-to-string number)))
6486              gnus-newsgroup-limit))
6487     current-prefix-arg
6488     t))
6489   (prog1
6490       (if (and (stringp article)
6491                (string-match "@" article))
6492           (gnus-summary-refer-article article)
6493         (when (stringp article)
6494           (setq article (string-to-number article)))
6495         (if (gnus-summary-goto-subject article force)
6496             (gnus-summary-display-article article all-headers)
6497           (gnus-message 4 "Couldn't go to article %s" article) nil))
6498     (gnus-summary-position-point)))
6499
6500 (defun gnus-summary-goto-last-article ()
6501   "Go to the previously read article."
6502   (interactive)
6503   (prog1
6504       (when gnus-last-article
6505         (gnus-summary-goto-article gnus-last-article nil t))
6506     (gnus-summary-position-point)))
6507
6508 (defun gnus-summary-pop-article (number)
6509   "Pop one article off the history and go to the previous.
6510 NUMBER articles will be popped off."
6511   (interactive "p")
6512   (let (to)
6513     (setq gnus-newsgroup-history
6514           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6515     (if to
6516         (gnus-summary-goto-article (car to) nil t)
6517       (error "Article history empty")))
6518   (gnus-summary-position-point))
6519
6520 ;; Summary commands and functions for limiting the summary buffer.
6521
6522 (defun gnus-summary-limit-to-articles (n)
6523   "Limit the summary buffer to the next N articles.
6524 If not given a prefix, use the process marked articles instead."
6525   (interactive "P")
6526   (prog1
6527       (let ((articles (gnus-summary-work-articles n)))
6528         (setq gnus-newsgroup-processable nil)
6529         (gnus-summary-limit articles))
6530     (gnus-summary-position-point)))
6531
6532 (defun gnus-summary-pop-limit (&optional total)
6533   "Restore the previous limit.
6534 If given a prefix, remove all limits."
6535   (interactive "P")
6536   (when total
6537     (setq gnus-newsgroup-limits
6538           (list (mapcar (lambda (h) (mail-header-number h))
6539                         gnus-newsgroup-headers))))
6540   (unless gnus-newsgroup-limits
6541     (error "No limit to pop"))
6542   (prog1
6543       (gnus-summary-limit nil 'pop)
6544     (gnus-summary-position-point)))
6545
6546 (defun gnus-summary-limit-to-subject (subject &optional header)
6547   "Limit the summary buffer to articles that have subjects that match a regexp."
6548   (interactive "sLimit to subject (regexp): ")
6549   (unless header
6550     (setq header "subject"))
6551   (when (not (equal "" subject))
6552     (prog1
6553         (let ((articles (gnus-summary-find-matching
6554                          (or header "subject") subject 'all)))
6555           (unless articles
6556             (error "Found no matches for \"%s\"" subject))
6557           (gnus-summary-limit articles))
6558       (gnus-summary-position-point))))
6559
6560 (defun gnus-summary-limit-to-author (from)
6561   "Limit the summary buffer to articles that have authors that match a regexp."
6562   (interactive "sLimit to author (regexp): ")
6563   (gnus-summary-limit-to-subject from "from"))
6564
6565 (defun gnus-summary-limit-to-age (age &optional younger-p)
6566   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6567 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6568 articles that are younger than AGE days."
6569   (interactive
6570    (let ((younger current-prefix-arg)
6571          (days-got nil)
6572          days)
6573      (while (not days-got)
6574        (setq days (if younger
6575                       (read-string "Limit to articles within (in days): ")
6576                     (read-string "Limit to articles older than (in days): ")))
6577        (when (> (length days) 0)
6578          (setq days (read days)))
6579        (if (numberp days)
6580            (setq days-got t)
6581          (message "Please enter a number.")
6582          (sleep-for 1)))
6583      (list days younger)))
6584   (prog1
6585       (let ((data gnus-newsgroup-data)
6586             (cutoff (days-to-time age))
6587             articles d date is-younger)
6588         (while (setq d (pop data))
6589           (when (and (vectorp (gnus-data-header d))
6590                      (setq date (mail-header-date (gnus-data-header d))))
6591             (setq is-younger (time-less-p
6592                               (time-since (condition-case ()
6593                                               (date-to-time date)
6594                                             (error '(0 0))))
6595                               cutoff))
6596             (when (if younger-p
6597                       is-younger
6598                     (not is-younger))
6599               (push (gnus-data-number d) articles))))
6600         (gnus-summary-limit (nreverse articles)))
6601     (gnus-summary-position-point)))
6602
6603 (defun gnus-summary-limit-to-extra (header regexp)
6604   "Limit the summary buffer to articles that match an 'extra' header."
6605   (interactive
6606    (let ((header
6607           (intern
6608            (gnus-completing-read
6609             (symbol-name (car gnus-extra-headers))
6610             "Limit extra header:"
6611             (mapcar (lambda (x)
6612                       (cons (symbol-name x) x))
6613                     gnus-extra-headers)
6614             nil
6615             t))))
6616      (list header
6617            (read-string (format "Limit to header %s (regexp): " header)))))
6618   (when (not (equal "" regexp))
6619     (prog1
6620         (let ((articles (gnus-summary-find-matching
6621                          (cons 'extra header) regexp 'all)))
6622           (unless articles
6623             (error "Found no matches for \"%s\"" regexp))
6624           (gnus-summary-limit articles))
6625       (gnus-summary-position-point))))
6626
6627 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6628 (make-obsolete
6629  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6630
6631 (defun gnus-summary-limit-to-unread (&optional all)
6632   "Limit the summary buffer to articles that are not marked as read.
6633 If ALL is non-nil, limit strictly to unread articles."
6634   (interactive "P")
6635   (if all
6636       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6637     (gnus-summary-limit-to-marks
6638      ;; Concat all the marks that say that an article is read and have
6639      ;; those removed.
6640      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6641            gnus-killed-mark gnus-kill-file-mark
6642            gnus-low-score-mark gnus-expirable-mark
6643            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6644            gnus-duplicate-mark gnus-souped-mark)
6645      'reverse)))
6646
6647 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6648 (make-obsolete 'gnus-summary-delete-marked-with
6649                'gnus-summary-limit-exlude-marks)
6650
6651 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6652   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6653 If REVERSE, limit the summary buffer to articles that are marked
6654 with MARKS.  MARKS can either be a string of marks or a list of marks.
6655 Returns how many articles were removed."
6656   (interactive "sMarks: ")
6657   (gnus-summary-limit-to-marks marks t))
6658
6659 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6660   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6661 If REVERSE (the prefix), limit the summary buffer to articles that are
6662 not marked with MARKS.  MARKS can either be a string of marks or a
6663 list of marks.
6664 Returns how many articles were removed."
6665   (interactive "sMarks: \nP")
6666   (prog1
6667       (let ((data gnus-newsgroup-data)
6668             (marks (if (listp marks) marks
6669                      (append marks nil))) ; Transform to list.
6670             articles)
6671         (while data
6672           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6673                   (memq (gnus-data-mark (car data)) marks))
6674             (push (gnus-data-number (car data)) articles))
6675           (setq data (cdr data)))
6676         (gnus-summary-limit articles))
6677     (gnus-summary-position-point)))
6678
6679 (defun gnus-summary-limit-to-score (&optional score)
6680   "Limit to articles with score at or above SCORE."
6681   (interactive "P")
6682   (setq score (if score
6683                   (prefix-numeric-value score)
6684                 (or gnus-summary-default-score 0)))
6685   (let ((data gnus-newsgroup-data)
6686         articles)
6687     (while data
6688       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6689                 score)
6690         (push (gnus-data-number (car data)) articles))
6691       (setq data (cdr data)))
6692     (prog1
6693         (gnus-summary-limit articles)
6694       (gnus-summary-position-point))))
6695
6696 (defun gnus-summary-limit-include-thread (id)
6697   "Display all the hidden articles that in the current thread."
6698   (interactive (list (mail-header-id (gnus-summary-article-header))))
6699   (let ((articles (gnus-articles-in-thread
6700                    (gnus-id-to-thread (gnus-root-id id)))))
6701     (prog1
6702         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
6703       (gnus-summary-position-point))))
6704
6705 (defun gnus-summary-limit-include-dormant ()
6706   "Display all the hidden articles that are marked as dormant.
6707 Note that this command only works on a subset of the articles currently
6708 fetched for this group."
6709   (interactive)
6710   (unless gnus-newsgroup-dormant
6711     (error "There are no dormant articles in this group"))
6712   (prog1
6713       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
6714     (gnus-summary-position-point)))
6715
6716 (defun gnus-summary-limit-exclude-dormant ()
6717   "Hide all dormant articles."
6718   (interactive)
6719   (prog1
6720       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
6721     (gnus-summary-position-point)))
6722
6723 (defun gnus-summary-limit-exclude-childless-dormant ()
6724   "Hide all dormant articles that have no children."
6725   (interactive)
6726   (let ((data (gnus-data-list t))
6727         articles d children)
6728     ;; Find all articles that are either not dormant or have
6729     ;; children.
6730     (while (setq d (pop data))
6731       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
6732                 (and (setq children
6733                            (gnus-article-children (gnus-data-number d)))
6734                      (let (found)
6735                        (while children
6736                          (when (memq (car children) articles)
6737                            (setq children nil
6738                                  found t))
6739                          (pop children))
6740                        found)))
6741         (push (gnus-data-number d) articles)))
6742     ;; Do the limiting.
6743     (prog1
6744         (gnus-summary-limit articles)
6745       (gnus-summary-position-point))))
6746
6747 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
6748   "Mark all unread excluded articles as read.
6749 If ALL, mark even excluded ticked and dormants as read."
6750   (interactive "P")
6751   (let ((articles (gnus-sorted-complement
6752                    (sort
6753                     (mapcar (lambda (h) (mail-header-number h))
6754                             gnus-newsgroup-headers)
6755                     '<)
6756                    (sort gnus-newsgroup-limit '<)))
6757         article)
6758     (setq gnus-newsgroup-unreads
6759           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
6760     (if all
6761         (setq gnus-newsgroup-dormant nil
6762               gnus-newsgroup-marked nil
6763               gnus-newsgroup-reads
6764               (nconc
6765                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
6766                gnus-newsgroup-reads))
6767       (while (setq article (pop articles))
6768         (unless (or (memq article gnus-newsgroup-dormant)
6769                     (memq article gnus-newsgroup-marked))
6770           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
6771
6772 (defun gnus-summary-limit (articles &optional pop)
6773   (if pop
6774       ;; We pop the previous limit off the stack and use that.
6775       (setq articles (car gnus-newsgroup-limits)
6776             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
6777     ;; We use the new limit, so we push the old limit on the stack.
6778     (push gnus-newsgroup-limit gnus-newsgroup-limits))
6779   ;; Set the limit.
6780   (setq gnus-newsgroup-limit articles)
6781   (let ((total (length gnus-newsgroup-data))
6782         (data (gnus-data-find-list (gnus-summary-article-number)))
6783         (gnus-summary-mark-below nil)   ; Inhibit this.
6784         found)
6785     ;; This will do all the work of generating the new summary buffer
6786     ;; according to the new limit.
6787     (gnus-summary-prepare)
6788     ;; Hide any threads, possibly.
6789     (and gnus-show-threads
6790          gnus-thread-hide-subtree
6791          (gnus-summary-hide-all-threads))
6792     ;; Try to return to the article you were at, or one in the
6793     ;; neighborhood.
6794     (when data
6795       ;; We try to find some article after the current one.
6796       (while data
6797         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
6798           (setq data nil
6799                 found t))
6800         (setq data (cdr data))))
6801     (unless found
6802       ;; If there is no data, that means that we were after the last
6803       ;; article.  The same goes when we can't find any articles
6804       ;; after the current one.
6805       (goto-char (point-max))
6806       (gnus-summary-find-prev))
6807     (gnus-set-mode-line 'summary)
6808     ;; We return how many articles were removed from the summary
6809     ;; buffer as a result of the new limit.
6810     (- total (length gnus-newsgroup-data))))
6811
6812 (defsubst gnus-invisible-cut-children (threads)
6813   (let ((num 0))
6814     (while threads
6815       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
6816         (incf num))
6817       (pop threads))
6818     (< num 2)))
6819
6820 (defsubst gnus-cut-thread (thread)
6821   "Go forwards in the thread until we find an article that we want to display."
6822   (when (or (eq gnus-fetch-old-headers 'some)
6823             (eq gnus-fetch-old-headers 'invisible)
6824             (numberp gnus-fetch-old-headers)
6825             (eq gnus-build-sparse-threads 'some)
6826             (eq gnus-build-sparse-threads 'more))
6827     ;; Deal with old-fetched headers and sparse threads.
6828     (while (and
6829             thread
6830             (or
6831              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
6832              (gnus-summary-article-ancient-p
6833               (mail-header-number (car thread))))
6834             (if (or (<= (length (cdr thread)) 1)
6835                     (eq gnus-fetch-old-headers 'invisible))
6836                 (setq gnus-newsgroup-limit
6837                       (delq (mail-header-number (car thread))
6838                             gnus-newsgroup-limit)
6839                       thread (cadr thread))
6840               (when (gnus-invisible-cut-children (cdr thread))
6841                 (let ((th (cdr thread)))
6842                   (while th
6843                     (if (memq (mail-header-number (caar th))
6844                               gnus-newsgroup-limit)
6845                         (setq thread (car th)
6846                               th nil)
6847                       (setq th (cdr th))))))))))
6848   thread)
6849
6850 (defun gnus-cut-threads (threads)
6851   "Cut off all uninteresting articles from the beginning of threads."
6852   (when (or (eq gnus-fetch-old-headers 'some)
6853             (eq gnus-fetch-old-headers 'invisible)
6854             (numberp gnus-fetch-old-headers)
6855             (eq gnus-build-sparse-threads 'some)
6856             (eq gnus-build-sparse-threads 'more))
6857     (let ((th threads))
6858       (while th
6859         (setcar th (gnus-cut-thread (car th)))
6860         (setq th (cdr th)))))
6861   ;; Remove nixed out threads.
6862   (delq nil threads))
6863
6864 (defun gnus-summary-initial-limit (&optional show-if-empty)
6865   "Figure out what the initial limit is supposed to be on group entry.
6866 This entails weeding out unwanted dormants, low-scored articles,
6867 fetch-old-headers verbiage, and so on."
6868   ;; Most groups have nothing to remove.
6869   (if (or gnus-inhibit-limiting
6870           (and (null gnus-newsgroup-dormant)
6871                (not (eq gnus-fetch-old-headers 'some))
6872                (not (numberp gnus-fetch-old-headers))
6873                (not (eq gnus-fetch-old-headers 'invisible))
6874                (null gnus-summary-expunge-below)
6875                (not (eq gnus-build-sparse-threads 'some))
6876                (not (eq gnus-build-sparse-threads 'more))
6877                (null gnus-thread-expunge-below)
6878                (not gnus-use-nocem)))
6879       ()                                ; Do nothing.
6880     (push gnus-newsgroup-limit gnus-newsgroup-limits)
6881     (setq gnus-newsgroup-limit nil)
6882     (mapatoms
6883      (lambda (node)
6884        (unless (car (symbol-value node))
6885          ;; These threads have no parents -- they are roots.
6886          (let ((nodes (cdr (symbol-value node)))
6887                thread)
6888            (while nodes
6889              (if (and gnus-thread-expunge-below
6890                       (< (gnus-thread-total-score (car nodes))
6891                          gnus-thread-expunge-below))
6892                  (gnus-expunge-thread (pop nodes))
6893                (setq thread (pop nodes))
6894                (gnus-summary-limit-children thread))))))
6895      gnus-newsgroup-dependencies)
6896     ;; If this limitation resulted in an empty group, we might
6897     ;; pop the previous limit and use it instead.
6898     (when (and (not gnus-newsgroup-limit)
6899                show-if-empty)
6900       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
6901     gnus-newsgroup-limit))
6902
6903 (defun gnus-summary-limit-children (thread)
6904   "Return 1 if this subthread is visible and 0 if it is not."
6905   ;; First we get the number of visible children to this thread.  This
6906   ;; is done by recursing down the thread using this function, so this
6907   ;; will really go down to a leaf article first, before slowly
6908   ;; working its way up towards the root.
6909   (when thread
6910     (let ((children
6911            (if (cdr thread)
6912                (apply '+ (mapcar 'gnus-summary-limit-children
6913                                  (cdr thread)))
6914              0))
6915           (number (mail-header-number (car thread)))
6916           score)
6917       (if (and
6918            (not (memq number gnus-newsgroup-marked))
6919            (or
6920             ;; If this article is dormant and has absolutely no visible
6921             ;; children, then this article isn't visible.
6922             (and (memq number gnus-newsgroup-dormant)
6923                  (zerop children))
6924             ;; If this is "fetch-old-headered" and there is no
6925             ;; visible children, then we don't want this article.
6926             (and (or (eq gnus-fetch-old-headers 'some)
6927                      (numberp gnus-fetch-old-headers))
6928                  (gnus-summary-article-ancient-p number)
6929                  (zerop children))
6930             ;; If this is "fetch-old-headered" and `invisible', then
6931             ;; we don't want this article.
6932             (and (eq gnus-fetch-old-headers 'invisible)
6933                  (gnus-summary-article-ancient-p number))
6934             ;; If this is a sparsely inserted article with no children,
6935             ;; we don't want it.
6936             (and (eq gnus-build-sparse-threads 'some)
6937                  (gnus-summary-article-sparse-p number)
6938                  (zerop children))
6939             ;; If we use expunging, and this article is really
6940             ;; low-scored, then we don't want this article.
6941             (when (and gnus-summary-expunge-below
6942                        (< (setq score
6943                                 (or (cdr (assq number gnus-newsgroup-scored))
6944                                     gnus-summary-default-score))
6945                           gnus-summary-expunge-below))
6946               ;; We increase the expunge-tally here, but that has
6947               ;; nothing to do with the limits, really.
6948               (incf gnus-newsgroup-expunged-tally)
6949               ;; We also mark as read here, if that's wanted.
6950               (when (and gnus-summary-mark-below
6951                          (< score gnus-summary-mark-below))
6952                 (setq gnus-newsgroup-unreads
6953                       (delq number gnus-newsgroup-unreads))
6954                 (if gnus-newsgroup-auto-expire
6955                     (push number gnus-newsgroup-expirable)
6956                   (push (cons number gnus-low-score-mark)
6957                         gnus-newsgroup-reads)))
6958               t)
6959             ;; Check NoCeM things.
6960             (if (and gnus-use-nocem
6961                      (gnus-nocem-unwanted-article-p
6962                       (mail-header-id (car thread))))
6963                 (progn
6964                   (setq gnus-newsgroup-unreads
6965                         (delq number gnus-newsgroup-unreads))
6966                   t))))
6967           ;; Nope, invisible article.
6968           0
6969         ;; Ok, this article is to be visible, so we add it to the limit
6970         ;; and return 1.
6971         (push number gnus-newsgroup-limit)
6972         1))))
6973
6974 (defun gnus-expunge-thread (thread)
6975   "Mark all articles in THREAD as read."
6976   (let* ((number (mail-header-number (car thread))))
6977     (incf gnus-newsgroup-expunged-tally)
6978     ;; We also mark as read here, if that's wanted.
6979     (setq gnus-newsgroup-unreads
6980           (delq number gnus-newsgroup-unreads))
6981     (if gnus-newsgroup-auto-expire
6982         (push number gnus-newsgroup-expirable)
6983       (push (cons number gnus-low-score-mark)
6984             gnus-newsgroup-reads)))
6985   ;; Go recursively through all subthreads.
6986   (mapcar 'gnus-expunge-thread (cdr thread)))
6987
6988 ;; Summary article oriented commands
6989
6990 (defun gnus-summary-refer-parent-article (n)
6991   "Refer parent article N times.
6992 If N is negative, go to ancestor -N instead.
6993 The difference between N and the number of articles fetched is returned."
6994   (interactive "p")
6995   (let ((skip 1)
6996         error header ref)
6997     (when (not (natnump n))
6998       (setq skip (abs n)
6999             n 1))
7000     (while (and (> n 0)
7001                 (not error))
7002       (setq header (gnus-summary-article-header))
7003       (if (and (eq (mail-header-number header)
7004                    (cdr gnus-article-current))
7005                (equal gnus-newsgroup-name
7006                       (car gnus-article-current)))
7007           ;; If we try to find the parent of the currently
7008           ;; displayed article, then we take a look at the actual
7009           ;; References header, since this is slightly more
7010           ;; reliable than the References field we got from the
7011           ;; server.
7012           (save-excursion
7013             (set-buffer gnus-original-article-buffer)
7014             (nnheader-narrow-to-headers)
7015             (unless (setq ref (message-fetch-field "references"))
7016               (setq ref (message-fetch-field "in-reply-to")))
7017             (widen))
7018         (setq ref
7019               ;; It's not the current article, so we take a bet on
7020               ;; the value we got from the server.
7021               (mail-header-references header)))
7022       (if (and ref
7023                (not (equal ref "")))
7024           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7025             (gnus-message 1 "Couldn't find parent"))
7026         (gnus-message 1 "No references in article %d"
7027                       (gnus-summary-article-number))
7028         (setq error t))
7029       (decf n))
7030     (gnus-summary-position-point)
7031     n))
7032
7033 (defun gnus-summary-refer-references ()
7034   "Fetch all articles mentioned in the References header.
7035 Return the number of articles fetched."
7036   (interactive)
7037   (let ((ref (mail-header-references (gnus-summary-article-header)))
7038         (current (gnus-summary-article-number))
7039         (n 0))
7040     (if (or (not ref)
7041             (equal ref ""))
7042         (error "No References in the current article")
7043       ;; For each Message-ID in the References header...
7044       (while (string-match "<[^>]*>" ref)
7045         (incf n)
7046         ;; ... fetch that article.
7047         (gnus-summary-refer-article
7048          (prog1 (match-string 0 ref)
7049            (setq ref (substring ref (match-end 0))))))
7050       (gnus-summary-goto-subject current)
7051       (gnus-summary-position-point)
7052       n)))
7053
7054 (defun gnus-summary-refer-thread (&optional limit)
7055   "Fetch all articles in the current thread.
7056 If LIMIT (the numerical prefix), fetch that many old headers instead
7057 of what's specified by the `gnus-refer-thread-limit' variable."
7058   (interactive "P")
7059   (let ((id (mail-header-id (gnus-summary-article-header)))
7060         (limit (if limit (prefix-numeric-value limit)
7061                  gnus-refer-thread-limit)))
7062     ;; We want to fetch LIMIT *old* headers, but we also have to
7063     ;; re-fetch all the headers in the current buffer, because many of
7064     ;; them may be undisplayed.  So we adjust LIMIT.
7065     (when (numberp limit)
7066       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7067     (unless (eq gnus-fetch-old-headers 'invisible)
7068       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7069       ;; Retrieve the headers and read them in.
7070       (if (eq (gnus-retrieve-headers
7071                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7072               'nov)
7073           (gnus-build-all-threads)
7074         (error "Can't fetch thread from backends that don't support NOV"))
7075       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7076     (gnus-summary-limit-include-thread id)))
7077
7078 (defun gnus-summary-refer-article (message-id)
7079   "Fetch an article specified by MESSAGE-ID."
7080   (interactive "sMessage-ID: ")
7081   (when (and (stringp message-id)
7082              (not (zerop (length message-id))))
7083     ;; Construct the correct Message-ID if necessary.
7084     ;; Suggested by tale@pawl.rpi.edu.
7085     (unless (string-match "^<" message-id)
7086       (setq message-id (concat "<" message-id)))
7087     (unless (string-match ">$" message-id)
7088       (setq message-id (concat message-id ">")))
7089     (let* ((header (gnus-id-to-header message-id))
7090            (sparse (and header
7091                         (gnus-summary-article-sparse-p
7092                          (mail-header-number header))
7093                         (memq (mail-header-number header)
7094                               gnus-newsgroup-limit)))
7095            number)
7096       (cond
7097        ;; If the article is present in the buffer we just go to it.
7098        ((and header
7099              (or (not (gnus-summary-article-sparse-p
7100                        (mail-header-number header)))
7101                  sparse))
7102         (prog1
7103             (gnus-summary-goto-article
7104              (mail-header-number header) nil t)
7105           (when sparse
7106             (gnus-summary-update-article (mail-header-number header)))))
7107        (t
7108         ;; We fetch the article.
7109         (catch 'found
7110           (dolist (gnus-override-method (gnus-refer-article-methods))
7111             (gnus-check-server gnus-override-method)
7112             ;; Fetch the header, and display the article.
7113             (when (setq number (gnus-summary-insert-subject message-id))
7114               (gnus-summary-select-article nil nil nil number)
7115               (throw 'found t)))
7116           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7117
7118 (defun gnus-refer-article-methods ()
7119   "Return a list of referrable methods."
7120   (cond
7121    ;; No method, so we default to current and native.
7122    ((null gnus-refer-article-method)
7123     (list gnus-current-select-method gnus-select-method))
7124    ;; Current.
7125    ((eq 'current gnus-refer-article-method)
7126     (list gnus-current-select-method))
7127    ;; List of select methods.
7128    ((not (and (symbolp (car gnus-refer-article-method))
7129               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7130     (let (out)
7131       (dolist (method gnus-refer-article-method)
7132         (push (if (eq 'current method)
7133                   gnus-current-select-method
7134                 method)
7135               out))
7136       (nreverse out)))
7137    ;; One single select method.
7138    (t
7139     (list gnus-refer-article-method))))
7140
7141 (defun gnus-summary-edit-parameters ()
7142   "Edit the group parameters of the current group."
7143   (interactive)
7144   (gnus-group-edit-group gnus-newsgroup-name 'params))
7145
7146 (defun gnus-summary-customize-parameters ()
7147   "Customize the group parameters of the current group."
7148   (interactive)
7149   (gnus-group-customize gnus-newsgroup-name))
7150
7151 (defun gnus-summary-enter-digest-group (&optional force)
7152   "Enter an nndoc group based on the current article.
7153 If FORCE, force a digest interpretation.  If not, try
7154 to guess what the document format is."
7155   (interactive "P")
7156   (let ((conf gnus-current-window-configuration))
7157     (save-excursion
7158       (gnus-summary-select-article))
7159     (setq gnus-current-window-configuration conf)
7160     (let* ((name (format "%s-%d"
7161                          (gnus-group-prefixed-name
7162                           gnus-newsgroup-name (list 'nndoc ""))
7163                          (save-excursion
7164                            (set-buffer gnus-summary-buffer)
7165                            gnus-current-article)))
7166            (ogroup gnus-newsgroup-name)
7167            (params (append (gnus-info-params (gnus-get-info ogroup))
7168                            (list (cons 'to-group ogroup))
7169                            (list (cons 'save-article-group ogroup))))
7170            (case-fold-search t)
7171            (buf (current-buffer))
7172            dig to-address)
7173       (save-excursion
7174         (set-buffer gnus-original-article-buffer)
7175         ;; Have the digest group inherit the main mail address of
7176         ;; the parent article.
7177         (when (setq to-address (or (message-fetch-field "reply-to")
7178                                    (message-fetch-field "from")))
7179           (setq params (append
7180                         (list (cons 'to-address
7181                                     (funcall gnus-decode-encoded-word-function
7182                                              to-address))))))
7183         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7184         (insert-buffer-substring gnus-original-article-buffer)
7185         ;; Remove lines that may lead nndoc to misinterpret the
7186         ;; document type.
7187         (narrow-to-region
7188          (goto-char (point-min))
7189          (or (search-forward "\n\n" nil t) (point)))
7190         (goto-char (point-min))
7191         (delete-matching-lines "^Path:\\|^From ")
7192         (widen))
7193       (unwind-protect
7194           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7195                     (gnus-newsgroup-ephemeral-ignored-charsets
7196                      gnus-newsgroup-ignored-charsets))
7197                 (gnus-group-read-ephemeral-group
7198                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7199                               (nndoc-article-type
7200                                ,(if force 'mbox 'guess))) t))
7201               ;; Make all postings to this group go to the parent group.
7202               (nconc (gnus-info-params (gnus-get-info name))
7203                      params)
7204             ;; Couldn't select this doc group.
7205             (switch-to-buffer buf)
7206             (gnus-set-global-variables)
7207             (gnus-configure-windows 'summary)
7208             (gnus-message 3 "Article couldn't be entered?"))
7209         (kill-buffer dig)))))
7210
7211 (defun gnus-summary-read-document (n)
7212   "Open a new group based on the current article(s).
7213 This will allow you to read digests and other similar
7214 documents as newsgroups.
7215 Obeys the standard process/prefix convention."
7216   (interactive "P")
7217   (let* ((articles (gnus-summary-work-articles n))
7218          (ogroup gnus-newsgroup-name)
7219          (params (append (gnus-info-params (gnus-get-info ogroup))
7220                          (list (cons 'to-group ogroup))))
7221          article group egroup groups vgroup)
7222     (while (setq article (pop articles))
7223       (setq group (format "%s-%d" gnus-newsgroup-name article))
7224       (gnus-summary-remove-process-mark article)
7225       (when (gnus-summary-display-article article)
7226         (save-excursion
7227           (with-temp-buffer
7228             (insert-buffer-substring gnus-original-article-buffer)
7229             ;; Remove some headers that may lead nndoc to make
7230             ;; the wrong guess.
7231             (message-narrow-to-head)
7232             (goto-char (point-min))
7233             (delete-matching-lines "^\\(Path\\):\\|^From ")
7234             (widen)
7235             (if (setq egroup
7236                       (gnus-group-read-ephemeral-group
7237                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7238                                      (nndoc-article-type guess))
7239                        t nil t))
7240                 (progn
7241                   ;; Make all postings to this group go to the parent group.
7242                   (nconc (gnus-info-params (gnus-get-info egroup))
7243                          params)
7244                   (push egroup groups))
7245               ;; Couldn't select this doc group.
7246               (gnus-error 3 "Article couldn't be entered"))))))
7247     ;; Now we have selected all the documents.
7248     (cond
7249      ((not groups)
7250       (error "None of the articles could be interpreted as documents"))
7251      ((gnus-group-read-ephemeral-group
7252        (setq vgroup (format
7253                      "nnvirtual:%s-%s" gnus-newsgroup-name
7254                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7255        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7256        t
7257        (cons (current-buffer) 'summary)))
7258      (t
7259       (error "Couldn't select virtual nndoc group")))))
7260
7261 (defun gnus-summary-isearch-article (&optional regexp-p)
7262   "Do incremental search forward on the current article.
7263 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7264   (interactive "P")
7265   (gnus-summary-select-article)
7266   (gnus-configure-windows 'article)
7267   (gnus-eval-in-buffer-window gnus-article-buffer
7268     (save-restriction
7269       (widen)
7270       (isearch-forward regexp-p))))
7271
7272 (defun gnus-summary-search-article-forward (regexp &optional backward)
7273   "Search for an article containing REGEXP forward.
7274 If BACKWARD, search backward instead."
7275   (interactive
7276    (list (read-string
7277           (format "Search article %s (regexp%s): "
7278                   (if current-prefix-arg "backward" "forward")
7279                   (if gnus-last-search-regexp
7280                       (concat ", default " gnus-last-search-regexp)
7281                     "")))
7282          current-prefix-arg))
7283   (if (string-equal regexp "")
7284       (setq regexp (or gnus-last-search-regexp ""))
7285     (setq gnus-last-search-regexp regexp)
7286     (setq gnus-article-before-search gnus-current-article))
7287   ;; Intentionally set gnus-last-article.
7288   (setq gnus-last-article gnus-article-before-search)
7289   (let ((gnus-last-article gnus-last-article))
7290     (if (gnus-summary-search-article regexp backward)
7291         (gnus-summary-show-thread)
7292       (error "Search failed: \"%s\"" regexp))))
7293
7294 (defun gnus-summary-search-article-backward (regexp)
7295   "Search for an article containing REGEXP backward."
7296   (interactive
7297    (list (read-string
7298           (format "Search article backward (regexp%s): "
7299                   (if gnus-last-search-regexp
7300                       (concat ", default " gnus-last-search-regexp)
7301                     "")))))
7302   (gnus-summary-search-article-forward regexp 'backward))
7303
7304 (defun gnus-summary-search-article (regexp &optional backward)
7305   "Search for an article containing REGEXP.
7306 Optional argument BACKWARD means do search for backward.
7307 `gnus-select-article-hook' is not called during the search."
7308   ;; We have to require this here to make sure that the following
7309   ;; dynamic binding isn't shadowed by autoloading.
7310   (require 'gnus-async)
7311   (require 'gnus-art)
7312   (let ((gnus-select-article-hook nil)  ;Disable hook.
7313         (gnus-article-prepare-hook nil)
7314         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7315         (gnus-use-article-prefetch nil)
7316         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7317         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7318         (sum (current-buffer))
7319         (gnus-display-mime-function nil)
7320         (found nil)
7321         point)
7322     (gnus-save-hidden-threads
7323       (gnus-summary-select-article)
7324       (set-buffer gnus-article-buffer)
7325       (goto-char (window-point (get-buffer-window (current-buffer))))
7326       (when backward
7327         (forward-line -1))
7328       (while (not found)
7329         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7330         (if (if backward
7331                 (re-search-backward regexp nil t)
7332               (re-search-forward regexp nil t))
7333             ;; We found the regexp.
7334             (progn
7335               (setq found 'found)
7336               (beginning-of-line)
7337               (set-window-start
7338                (get-buffer-window (current-buffer))
7339                (point))
7340               (forward-line 1)
7341               (set-window-point
7342                (get-buffer-window (current-buffer))
7343                (point))
7344               (set-buffer sum)
7345               (setq point (point)))
7346           ;; We didn't find it, so we go to the next article.
7347           (set-buffer sum)
7348           (setq found 'not)
7349           (while (eq found 'not)
7350             (if (not (if backward (gnus-summary-find-prev)
7351                        (gnus-summary-find-next)))
7352                 ;; No more articles.
7353                 (setq found t)
7354               ;; Select the next article and adjust point.
7355               (unless (gnus-summary-article-sparse-p
7356                        (gnus-summary-article-number))
7357                 (setq found nil)
7358                 (gnus-summary-select-article)
7359                 (set-buffer gnus-article-buffer)
7360                 (widen)
7361                 (goto-char (if backward (point-max) (point-min))))))))
7362       (gnus-message 7 ""))
7363     ;; Return whether we found the regexp.
7364     (when (eq found 'found)
7365       (goto-char point)
7366       (gnus-summary-show-thread)
7367       (gnus-summary-goto-subject gnus-current-article)
7368       (gnus-summary-position-point)
7369       t)))
7370
7371 (defun gnus-summary-find-matching (header regexp &optional backward unread
7372                                           not-case-fold)
7373   "Return a list of all articles that match REGEXP on HEADER.
7374 The search stars on the current article and goes forwards unless
7375 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7376 If UNREAD is non-nil, only unread articles will
7377 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7378 in the comparisons."
7379   (let ((data (if (eq backward 'all) gnus-newsgroup-data
7380                 (gnus-data-find-list
7381                  (gnus-summary-article-number) (gnus-data-list backward))))
7382         (case-fold-search (not not-case-fold))
7383         articles d func)
7384     (if (consp header)
7385         (if (eq (car header) 'extra)
7386             (setq func
7387                   `(lambda (h)
7388                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7389                          "")))
7390           (error "%s is an invalid header" header))
7391       (unless (fboundp (intern (concat "mail-header-" header)))
7392         (error "%s is not a valid header" header))
7393       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7394     (while data
7395       (setq d (car data))
7396       (and (or (not unread)             ; We want all articles...
7397                (gnus-data-unread-p d))  ; Or just unreads.
7398            (vectorp (gnus-data-header d)) ; It's not a pseudo.
7399            (string-match regexp (funcall func (gnus-data-header d))) ; Match.
7400            (push (gnus-data-number d) articles)) ; Success!
7401       (setq data (cdr data)))
7402     (nreverse articles)))
7403
7404 (defun gnus-summary-execute-command (header regexp command &optional backward)
7405   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7406 If HEADER is an empty string (or nil), the match is done on the entire
7407 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7408   (interactive
7409    (list (let ((completion-ignore-case t))
7410            (completing-read
7411             "Header name: "
7412             (mapcar (lambda (string) (list string))
7413                     '("Number" "Subject" "From" "Lines" "Date"
7414                       "Message-ID" "Xref" "References" "Body"))
7415             nil 'require-match))
7416          (read-string "Regexp: ")
7417          (read-key-sequence "Command: ")
7418          current-prefix-arg))
7419   (when (equal header "Body")
7420     (setq header ""))
7421   ;; Hidden thread subtrees must be searched as well.
7422   (gnus-summary-show-all-threads)
7423   ;; We don't want to change current point nor window configuration.
7424   (save-excursion
7425     (save-window-excursion
7426       (gnus-message 6 "Executing %s..." (key-description command))
7427       ;; We'd like to execute COMMAND interactively so as to give arguments.
7428       (gnus-execute header regexp
7429                     `(call-interactively ',(key-binding command))
7430                     backward)
7431       (gnus-message 6 "Executing %s...done" (key-description command)))))
7432
7433 (defun gnus-summary-beginning-of-article ()
7434   "Scroll the article back to the beginning."
7435   (interactive)
7436   (gnus-summary-select-article)
7437   (gnus-configure-windows 'article)
7438   (gnus-eval-in-buffer-window gnus-article-buffer
7439     (widen)
7440     (goto-char (point-min))
7441     (when gnus-page-broken
7442       (gnus-narrow-to-page))))
7443
7444 (defun gnus-summary-end-of-article ()
7445   "Scroll to the end of the article."
7446   (interactive)
7447   (gnus-summary-select-article)
7448   (gnus-configure-windows 'article)
7449   (gnus-eval-in-buffer-window gnus-article-buffer
7450     (widen)
7451     (goto-char (point-max))
7452     (recenter -3)
7453     (when gnus-page-broken
7454       (gnus-narrow-to-page))))
7455
7456 (defun gnus-summary-print-article (&optional filename n)
7457   "Generate and print a PostScript image of the N next (mail) articles.
7458
7459 If N is negative, print the N previous articles.  If N is nil and articles
7460 have been marked with the process mark, print these instead.
7461
7462 If the optional first argument FILENAME is nil, send the image to the
7463 printer.  If FILENAME is a string, save the PostScript image in a file with
7464 that name.  If FILENAME is a number, prompt the user for the name of the file
7465 to save in."
7466   (interactive (list (ps-print-preprint current-prefix-arg)))
7467   (dolist (article (gnus-summary-work-articles n))
7468     (gnus-summary-select-article nil nil 'pseudo article)
7469     (gnus-eval-in-buffer-window gnus-article-buffer
7470       (let ((buffer (generate-new-buffer " *print*")))
7471         (unwind-protect
7472             (progn
7473               (copy-to-buffer buffer (point-min) (point-max))
7474               (set-buffer buffer)
7475               (gnus-article-delete-invisible-text)
7476               (when (gnus-visual-p 'article-highlight 'highlight)
7477                 ;; Copy-to-buffer doesn't copy overlay.  So redo
7478                 ;; highlight.
7479                 (let ((gnus-article-buffer buffer))
7480                   (gnus-article-highlight-citation t)
7481                   (gnus-article-highlight-signature)))
7482               (let ((ps-left-header
7483                      (list
7484                       (concat "("
7485                               (mail-header-subject gnus-current-headers) ")")
7486                       (concat "("
7487                               (mail-header-from gnus-current-headers) ")")))
7488                     (ps-right-header
7489                      (list
7490                       "/pagenumberstring load"
7491                       (concat "("
7492                               (mail-header-date gnus-current-headers) ")"))))
7493                 (gnus-run-hooks 'gnus-ps-print-hook)
7494                 (save-excursion
7495                   (ps-spool-buffer-with-faces))))
7496           (kill-buffer buffer))))
7497     (gnus-summary-remove-process-mark article))
7498   (ps-despool filename))
7499
7500 (defun gnus-summary-show-article (&optional arg)
7501   "Force re-fetching of the current article.
7502 If ARG (the prefix) is a number, show the article with the charset
7503 defined in `gnus-summary-show-article-charset-alist', or the charset
7504 inputed.
7505 If ARG (the prefix) is non-nil and not a number, show the raw article
7506 without any article massaging functions being run."
7507   (interactive "P")
7508   (cond
7509    ((numberp arg)
7510     (let ((gnus-newsgroup-charset
7511            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7512                (read-coding-system "Charset: ")))
7513           (gnus-newsgroup-ignored-charsets 'gnus-all))
7514       (gnus-summary-select-article nil 'force)
7515       (let ((deps gnus-newsgroup-dependencies)
7516             head header)
7517         (save-excursion
7518           (set-buffer gnus-original-article-buffer)
7519           (save-restriction
7520             (message-narrow-to-head)
7521             (setq head (buffer-string)))
7522           (with-temp-buffer
7523             (insert (format "211 %d Article retrieved.\n"
7524                             (cdr gnus-article-current)))
7525             (insert head)
7526             (insert ".\n")
7527             (let ((nntp-server-buffer (current-buffer)))
7528               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7529         (gnus-data-set-header
7530          (gnus-data-find (cdr gnus-article-current))
7531          header)
7532         (gnus-summary-update-article-line
7533          (cdr gnus-article-current) header))))
7534    ((not arg)
7535     ;; Select the article the normal way.
7536     (gnus-summary-select-article nil 'force))
7537    (t
7538     ;; We have to require this here to make sure that the following
7539     ;; dynamic binding isn't shadowed by autoloading.
7540     (require 'gnus-async)
7541     (require 'gnus-art)
7542     ;; Bind the article treatment functions to nil.
7543     (let ((gnus-have-all-headers t)
7544           gnus-article-prepare-hook
7545           gnus-article-decode-hook
7546           gnus-display-mime-function
7547           gnus-break-pages)
7548       ;; Destroy any MIME parts.
7549       (when (gnus-buffer-live-p gnus-article-buffer)
7550         (save-excursion
7551           (set-buffer gnus-article-buffer)
7552           (mm-destroy-parts gnus-article-mime-handles)
7553           ;; Set it to nil for safety reason.
7554           (setq gnus-article-mime-handle-alist nil)
7555           (setq gnus-article-mime-handles nil)))
7556       (gnus-summary-select-article nil 'force))))
7557   (gnus-summary-goto-subject gnus-current-article)
7558   (gnus-summary-position-point))
7559
7560 (defun gnus-summary-verbose-headers (&optional arg)
7561   "Toggle permanent full header display.
7562 If ARG is a positive number, turn header display on.
7563 If ARG is a negative number, turn header display off."
7564   (interactive "P")
7565   (setq gnus-show-all-headers
7566         (cond ((or (not (numberp arg))
7567                    (zerop arg))
7568                (not gnus-show-all-headers))
7569               ((natnump arg)
7570                t)))
7571   (gnus-summary-show-article))
7572
7573 (defun gnus-summary-toggle-header (&optional arg)
7574   "Show the headers if they are hidden, or hide them if they are shown.
7575 If ARG is a positive number, show the entire header.
7576 If ARG is a negative number, hide the unwanted header lines."
7577   (interactive "P")
7578   (save-excursion
7579     (set-buffer gnus-article-buffer)
7580     (save-restriction
7581       (let* ((buffer-read-only nil)
7582              (inhibit-point-motion-hooks t)
7583              hidden e)
7584         (setq hidden
7585               (if (numberp arg)
7586                   (>= arg 0)
7587                 (save-restriction
7588                   (article-narrow-to-head)
7589                   (gnus-article-hidden-text-p 'headers))))
7590         (goto-char (point-min))
7591         (when (search-forward "\n\n" nil t)
7592           (delete-region (point-min) (1- (point))))
7593         (goto-char (point-min))
7594         (save-excursion
7595           (set-buffer gnus-original-article-buffer)
7596           (goto-char (point-min))
7597           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
7598         (insert-buffer-substring gnus-original-article-buffer 1 e)
7599         (save-restriction
7600           (narrow-to-region (point-min) (point))
7601           (article-decode-encoded-words)
7602           (if  hidden
7603               (let ((gnus-treat-hide-headers nil)
7604                     (gnus-treat-hide-boring-headers nil))
7605                 (setq gnus-article-wash-types
7606                       (delq 'headers gnus-article-wash-types))
7607                 (gnus-treat-article 'head))
7608             (gnus-treat-article 'head)))
7609         (gnus-set-mode-line 'article)))))
7610
7611 (defun gnus-summary-show-all-headers ()
7612   "Make all header lines visible."
7613   (interactive)
7614   (gnus-article-show-all-headers))
7615
7616 (defun gnus-summary-caesar-message (&optional arg)
7617   "Caesar rotate the current article by 13.
7618 The numerical prefix specifies how many places to rotate each letter
7619 forward."
7620   (interactive "P")
7621   (gnus-summary-select-article)
7622   (let ((mail-header-separator ""))
7623     (gnus-eval-in-buffer-window gnus-article-buffer
7624       (save-restriction
7625         (widen)
7626         (let ((start (window-start))
7627               buffer-read-only)
7628           (message-caesar-buffer-body arg)
7629           (set-window-start (get-buffer-window (current-buffer)) start))))))
7630
7631 (defun gnus-summary-stop-page-breaking ()
7632   "Stop page breaking in the current article."
7633   (interactive)
7634   (gnus-summary-select-article)
7635   (gnus-eval-in-buffer-window gnus-article-buffer
7636     (widen)
7637     (when (gnus-visual-p 'page-marker)
7638       (let ((buffer-read-only nil))
7639         (gnus-remove-text-with-property 'gnus-prev)
7640         (gnus-remove-text-with-property 'gnus-next))
7641       (setq gnus-page-broken nil))))
7642
7643 (defun gnus-summary-move-article (&optional n to-newsgroup
7644                                             select-method action)
7645   "Move the current article to a different newsgroup.
7646 If N is a positive number, move the N next articles.
7647 If N is a negative number, move the N previous articles.
7648 If N is nil and any articles have been marked with the process mark,
7649 move those articles instead.
7650 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7651 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7652 re-spool using this method.
7653
7654 For this function to work, both the current newsgroup and the
7655 newsgroup that you want to move to have to support the `request-move'
7656 and `request-accept' functions.
7657
7658 ACTION can be either `move' (the default), `crosspost' or `copy'."
7659   (interactive "P")
7660   (unless action
7661     (setq action 'move))
7662   ;; Disable marking as read.
7663   (let (gnus-mark-article-hook)
7664     (save-window-excursion
7665       (gnus-summary-select-article)))
7666   ;; Check whether the source group supports the required functions.
7667   (cond ((and (eq action 'move)
7668               (not (gnus-check-backend-function
7669                     'request-move-article gnus-newsgroup-name)))
7670          (error "The current group does not support article moving"))
7671         ((and (eq action 'crosspost)
7672               (not (gnus-check-backend-function
7673                     'request-replace-article gnus-newsgroup-name)))
7674          (error "The current group does not support article editing")))
7675   (let ((articles (gnus-summary-work-articles n))
7676         (prefix (if (gnus-check-backend-function
7677                     'request-move-article gnus-newsgroup-name)
7678                     (gnus-group-real-prefix gnus-newsgroup-name)
7679                   ""))
7680         (names '((move "Move" "Moving")
7681                  (copy "Copy" "Copying")
7682                  (crosspost "Crosspost" "Crossposting")))
7683         (copy-buf (save-excursion
7684                     (nnheader-set-temp-buffer " *copy article*")))
7685         art-group to-method new-xref article to-groups)
7686     (unless (assq action names)
7687       (error "Unknown action %s" action))
7688     ;; Read the newsgroup name.
7689     (when (and (not to-newsgroup)
7690                (not select-method))
7691       (setq to-newsgroup
7692             (gnus-read-move-group-name
7693              (cadr (assq action names))
7694              (symbol-value (intern (format "gnus-current-%s-group" action)))
7695              articles prefix))
7696       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
7697     (setq to-method (or select-method
7698                         (gnus-server-to-method
7699                          (gnus-group-method to-newsgroup))))
7700     ;; Check the method we are to move this article to...
7701     (unless (gnus-check-backend-function
7702              'request-accept-article (car to-method))
7703       (error "%s does not support article copying" (car to-method)))
7704     (unless (gnus-check-server to-method)
7705       (error "Can't open server %s" (car to-method)))
7706     (gnus-message 6 "%s to %s: %s..."
7707                   (caddr (assq action names))
7708                   (or (car select-method) to-newsgroup) articles)
7709     (while articles
7710       (setq article (pop articles))
7711       (setq
7712        art-group
7713        (cond
7714         ;; Move the article.
7715         ((eq action 'move)
7716          ;; Remove this article from future suppression.
7717          (gnus-dup-unsuppress-article article)
7718          (gnus-request-move-article
7719           article                       ; Article to move
7720           gnus-newsgroup-name           ; From newsgroup
7721           (nth 1 (gnus-find-method-for-group
7722                   gnus-newsgroup-name)) ; Server
7723           (list 'gnus-request-accept-article
7724                 to-newsgroup (list 'quote select-method)
7725                 (not articles) t)       ; Accept form
7726           (not articles)))              ; Only save nov last time
7727         ;; Copy the article.
7728         ((eq action 'copy)
7729          (save-excursion
7730            (set-buffer copy-buf)
7731            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
7732              (gnus-request-accept-article
7733               to-newsgroup select-method (not articles) t))))
7734         ;; Crosspost the article.
7735         ((eq action 'crosspost)
7736          (let ((xref (message-tokenize-header
7737                       (mail-header-xref (gnus-summary-article-header article))
7738                       " ")))
7739            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
7740                                   ":" article))
7741            (unless xref
7742              (setq xref (list (system-name))))
7743            (setq new-xref
7744                  (concat
7745                   (mapconcat 'identity
7746                              (delete "Xref:" (delete new-xref xref))
7747                              " ")
7748                   " " new-xref))
7749            (save-excursion
7750              (set-buffer copy-buf)
7751              ;; First put the article in the destination group.
7752              (gnus-request-article-this-buffer article gnus-newsgroup-name)
7753              (when (consp (setq art-group
7754                                 (gnus-request-accept-article
7755                                  to-newsgroup select-method (not articles))))
7756                (setq new-xref (concat new-xref " " (car art-group)
7757                                       ":" (cdr art-group)))
7758                ;; Now we have the new Xrefs header, so we insert
7759                ;; it and replace the new article.
7760                (nnheader-replace-header "Xref" new-xref)
7761                (gnus-request-replace-article
7762                 (cdr art-group) to-newsgroup (current-buffer))
7763                art-group))))))
7764       (cond
7765        ((not art-group)
7766         (gnus-message 1 "Couldn't %s article %s: %s"
7767                       (cadr (assq action names)) article
7768                       (nnheader-get-report (car to-method))))
7769        ((eq art-group 'junk)
7770         (when (eq action 'move)
7771           (gnus-summary-mark-article article gnus-canceled-mark)
7772           (gnus-message 4 "Deleted article %s" article)))
7773        (t
7774         (let* ((pto-group (gnus-group-prefixed-name
7775                            (car art-group) to-method))
7776                (entry
7777                 (gnus-gethash pto-group gnus-newsrc-hashtb))
7778                (info (nth 2 entry))
7779                (to-group (gnus-info-group info))
7780                to-marks)
7781           ;; Update the group that has been moved to.
7782           (when (and info
7783                      (memq action '(move copy)))
7784             (unless (member to-group to-groups)
7785               (push to-group to-groups))
7786
7787             (unless (memq article gnus-newsgroup-unreads)
7788               (push 'read to-marks)
7789               (gnus-info-set-read
7790                info (gnus-add-to-range (gnus-info-read info)
7791                                        (list (cdr art-group)))))
7792
7793             ;; See whether the article is to be put in the cache.
7794             (let ((marks gnus-article-mark-lists)
7795                   (to-article (cdr art-group)))
7796
7797               ;; Enter the article into the cache in the new group,
7798               ;; if that is required.
7799               (when gnus-use-cache
7800                 (gnus-cache-possibly-enter-article
7801                  to-group to-article
7802                  (memq article gnus-newsgroup-marked)
7803                  (memq article gnus-newsgroup-dormant)
7804                  (memq article gnus-newsgroup-unreads)))
7805
7806               (when gnus-preserve-marks
7807                 ;; Copy any marks over to the new group.
7808                 (when (and (equal to-group gnus-newsgroup-name)
7809                            (not (memq article gnus-newsgroup-unreads)))
7810                   ;; Mark this article as read in this group.
7811                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
7812                   (setcdr (gnus-active to-group) to-article)
7813                   (setcdr gnus-newsgroup-active to-article))
7814
7815                 (while marks
7816                   (when (memq article (symbol-value
7817                                        (intern (format "gnus-newsgroup-%s"
7818                                                        (caar marks)))))
7819                     (push (cdar marks) to-marks)
7820                     ;; If the other group is the same as this group,
7821                     ;; then we have to add the mark to the list.
7822                     (when (equal to-group gnus-newsgroup-name)
7823                       (set (intern (format "gnus-newsgroup-%s" (caar marks)))
7824                            (cons to-article
7825                                  (symbol-value
7826                                   (intern (format "gnus-newsgroup-%s"
7827                                                   (caar marks)))))))
7828                     ;; Copy the marks to other group.
7829                     (gnus-add-marked-articles
7830                      to-group (cdar marks) (list to-article) info))
7831                   (setq marks (cdr marks)))
7832
7833                 (gnus-request-set-mark to-group (list (list (list to-article)
7834                                                             'set
7835                                                             to-marks))))
7836
7837               (gnus-dribble-enter
7838                (concat "(gnus-group-set-info '"
7839                        (gnus-prin1-to-string (gnus-get-info to-group))
7840                        ")"))))
7841
7842           ;; Update the Xref header in this article to point to
7843           ;; the new crossposted article we have just created.
7844           (when (eq action 'crosspost)
7845             (save-excursion
7846               (set-buffer copy-buf)
7847               (gnus-request-article-this-buffer article gnus-newsgroup-name)
7848               (nnheader-replace-header "Xref" new-xref)
7849               (gnus-request-replace-article
7850                article gnus-newsgroup-name (current-buffer)))))
7851
7852         ;;;!!!Why is this necessary?
7853         (set-buffer gnus-summary-buffer)
7854
7855         (gnus-summary-goto-subject article)
7856         (when (eq action 'move)
7857           (gnus-summary-mark-article article gnus-canceled-mark))))
7858       (gnus-summary-remove-process-mark article))
7859     ;; Re-activate all groups that have been moved to.
7860     (while to-groups
7861       (save-excursion
7862         (set-buffer gnus-group-buffer)
7863         (when (gnus-group-goto-group (car to-groups) t)
7864           (gnus-group-get-new-news-this-group 1 t))
7865         (pop to-groups)))
7866
7867     (gnus-kill-buffer copy-buf)
7868     (gnus-summary-position-point)
7869     (gnus-set-mode-line 'summary)))
7870
7871 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
7872   "Move the current article to a different newsgroup.
7873 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
7874 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
7875 re-spool using this method."
7876   (interactive "P")
7877   (gnus-summary-move-article n to-newsgroup select-method 'copy))
7878
7879 (defun gnus-summary-crosspost-article (&optional n)
7880   "Crosspost the current article to some other group."
7881   (interactive "P")
7882   (gnus-summary-move-article n nil nil 'crosspost))
7883
7884 (defcustom gnus-summary-respool-default-method nil
7885   "Default method for respooling an article.
7886 If nil, use to the current newsgroup method."
7887   :type '(choice (gnus-select-method :value (nnml ""))
7888                  (const nil))
7889   :group 'gnus-summary-mail)
7890
7891 (defun gnus-summary-respool-article (&optional n method)
7892   "Respool the current article.
7893 The article will be squeezed through the mail spooling process again,
7894 which means that it will be put in some mail newsgroup or other
7895 depending on `nnmail-split-methods'.
7896 If N is a positive number, respool the N next articles.
7897 If N is a negative number, respool the N previous articles.
7898 If N is nil and any articles have been marked with the process mark,
7899 respool those articles instead.
7900
7901 Respooling can be done both from mail groups and \"real\" newsgroups.
7902 In the former case, the articles in question will be moved from the
7903 current group into whatever groups they are destined to.  In the
7904 latter case, they will be copied into the relevant groups."
7905   (interactive
7906    (list current-prefix-arg
7907          (let* ((methods (gnus-methods-using 'respool))
7908                 (methname
7909                  (symbol-name (or gnus-summary-respool-default-method
7910                                   (car (gnus-find-method-for-group
7911                                         gnus-newsgroup-name)))))
7912                 (method
7913                  (gnus-completing-read
7914                   methname "What backend do you want to use when respooling?"
7915                   methods nil t nil 'gnus-mail-method-history))
7916                 ms)
7917            (cond
7918             ((zerop (length (setq ms (gnus-servers-using-backend
7919                                       (intern method)))))
7920              (list (intern method) ""))
7921             ((= 1 (length ms))
7922              (car ms))
7923             (t
7924              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
7925                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
7926                            ms-alist))))))))
7927   (unless method
7928     (error "No method given for respooling"))
7929   (if (assoc (symbol-name
7930               (car (gnus-find-method-for-group gnus-newsgroup-name)))
7931              (gnus-methods-using 'respool))
7932       (gnus-summary-move-article n nil method)
7933     (gnus-summary-copy-article n nil method)))
7934
7935 (defun gnus-summary-import-article (file &optional edit)
7936   "Import an arbitrary file into a mail newsgroup."
7937   (interactive "fImport file: \nP")
7938   (let ((group gnus-newsgroup-name)
7939         (now (current-time))
7940         atts lines group-art)
7941     (unless (gnus-check-backend-function 'request-accept-article group)
7942       (error "%s does not support article importing" group))
7943     (or (file-readable-p file)
7944         (not (file-regular-p file))
7945         (error "Can't read %s" file))
7946     (save-excursion
7947       (set-buffer (gnus-get-buffer-create " *import file*"))
7948       (erase-buffer)
7949       (nnheader-insert-file-contents file)
7950       (goto-char (point-min))
7951       (unless (nnheader-article-p)
7952         ;; This doesn't look like an article, so we fudge some headers.
7953         (setq atts (file-attributes file)
7954               lines (count-lines (point-min) (point-max)))
7955         (insert "From: " (read-string "From: ") "\n"
7956                 "Subject: " (read-string "Subject: ") "\n"
7957                 "Date: " (message-make-date (nth 5 atts)) "\n"
7958                 "Message-ID: " (message-make-message-id) "\n"
7959                 "Lines: " (int-to-string lines) "\n"
7960                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
7961       (setq group-art (gnus-request-accept-article group nil t))
7962       (kill-buffer (current-buffer)))
7963     (setq gnus-newsgroup-active (gnus-activate-group group))
7964     (forward-line 1)
7965     (gnus-summary-goto-article (cdr group-art) nil t)
7966     (when edit
7967       (gnus-summary-edit-article))))
7968
7969 (defun gnus-summary-create-article ()
7970   "Create an article in a mail newsgroup."
7971   (interactive)
7972   (let ((group gnus-newsgroup-name)
7973         (now (current-time))
7974         group-art)
7975     (unless (gnus-check-backend-function 'request-accept-article group)
7976       (error "%s does not support article importing" group))
7977     (save-excursion
7978       (set-buffer (gnus-get-buffer-create " *import file*"))
7979       (erase-buffer)
7980       (goto-char (point-min))
7981       ;; This doesn't look like an article, so we fudge some headers.
7982       (insert "From: " (read-string "From: ") "\n"
7983               "Subject: " (read-string "Subject: ") "\n"
7984               "Date: " (message-make-date now) "\n"
7985               "Message-ID: " (message-make-message-id) "\n")
7986       (setq group-art (gnus-request-accept-article group nil t))
7987       (kill-buffer (current-buffer)))
7988     (setq gnus-newsgroup-active (gnus-activate-group group))
7989     (forward-line 1)
7990     (gnus-summary-goto-article (cdr group-art) nil t)
7991     (gnus-summary-edit-article)))
7992
7993 (defun gnus-summary-article-posted-p ()
7994   "Say whether the current (mail) article is available from news as well.
7995 This will be the case if the article has both been mailed and posted."
7996   (interactive)
7997   (let ((id (mail-header-references (gnus-summary-article-header)))
7998         (gnus-override-method (car (gnus-refer-article-methods))))
7999     (if (gnus-request-head id "")
8000         (gnus-message 2 "The current message was found on %s"
8001                       gnus-override-method)
8002       (gnus-message 2 "The current message couldn't be found on %s"
8003                     gnus-override-method)
8004       nil)))
8005
8006 (defun gnus-summary-expire-articles (&optional now)
8007   "Expire all articles that are marked as expirable in the current group."
8008   (interactive)
8009   (when (gnus-check-backend-function
8010          'request-expire-articles gnus-newsgroup-name)
8011     ;; This backend supports expiry.
8012     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8013            (expirable (if total
8014                           (progn
8015                             ;; We need to update the info for
8016                             ;; this group for `gnus-list-of-read-articles'
8017                             ;; to give us the right answer.
8018                             (gnus-run-hooks 'gnus-exit-group-hook)
8019                             (gnus-summary-update-info)
8020                             (gnus-list-of-read-articles gnus-newsgroup-name))
8021                         (setq gnus-newsgroup-expirable
8022                               (sort gnus-newsgroup-expirable '<))))
8023            (expiry-wait (if now 'immediate
8024                           (gnus-group-find-parameter
8025                            gnus-newsgroup-name 'expiry-wait)))
8026            (nnmail-expiry-target
8027             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8028                 nnmail-expiry-target))
8029            es)
8030       (when expirable
8031         ;; There are expirable articles in this group, so we run them
8032         ;; through the expiry process.
8033         (gnus-message 6 "Expiring articles...")
8034         (unless (gnus-check-group gnus-newsgroup-name)
8035           (error "Can't open server for %s" gnus-newsgroup-name))
8036         ;; The list of articles that weren't expired is returned.
8037         (save-excursion
8038           (if expiry-wait
8039               (let ((nnmail-expiry-wait-function nil)
8040                     (nnmail-expiry-wait expiry-wait))
8041                 (setq es (gnus-request-expire-articles
8042                           expirable gnus-newsgroup-name)))
8043             (setq es (gnus-request-expire-articles
8044                       expirable gnus-newsgroup-name)))
8045           (unless total
8046             (setq gnus-newsgroup-expirable es))
8047           ;; We go through the old list of expirable, and mark all
8048           ;; really expired articles as nonexistent.
8049           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8050             (let ((gnus-use-cache nil))
8051               (while expirable
8052                 (unless (memq (car expirable) es)
8053                   (when (gnus-data-find (car expirable))
8054                     (gnus-summary-mark-article
8055                      (car expirable) gnus-canceled-mark)))
8056                 (setq expirable (cdr expirable))))))
8057         (gnus-message 6 "Expiring articles...done")))))
8058
8059 (defun gnus-summary-expire-articles-now ()
8060   "Expunge all expirable articles in the current group.
8061 This means that *all* articles that are marked as expirable will be
8062 deleted forever, right now."
8063   (interactive)
8064   (or gnus-expert-user
8065       (gnus-yes-or-no-p
8066        "Are you really, really, really sure you want to delete all these messages? ")
8067       (error "Phew!"))
8068   (gnus-summary-expire-articles t))
8069
8070 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8071 (defun gnus-summary-delete-article (&optional n)
8072   "Delete the N next (mail) articles.
8073 This command actually deletes articles.  This is not a marking
8074 command.  The article will disappear forever from your life, never to
8075 return.
8076 If N is negative, delete backwards.
8077 If N is nil and articles have been marked with the process mark,
8078 delete these instead."
8079   (interactive "P")
8080   (unless (gnus-check-backend-function 'request-expire-articles
8081                                        gnus-newsgroup-name)
8082     (error "The current newsgroup does not support article deletion"))
8083   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8084     (error "Couldn't open server"))
8085   ;; Compute the list of articles to delete.
8086   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8087         not-deleted)
8088     (if (and gnus-novice-user
8089              (not (gnus-yes-or-no-p
8090                    (format "Do you really want to delete %s forever? "
8091                            (if (> (length articles) 1)
8092                                (format "these %s articles" (length articles))
8093                              "this article")))))
8094         ()
8095       ;; Delete the articles.
8096       (setq not-deleted (gnus-request-expire-articles
8097                          articles gnus-newsgroup-name 'force))
8098       (while articles
8099         (gnus-summary-remove-process-mark (car articles))
8100         ;; The backend might not have been able to delete the article
8101         ;; after all.
8102         (unless (memq (car articles) not-deleted)
8103           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8104         (setq articles (cdr articles)))
8105       (when not-deleted
8106         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8107     (gnus-summary-position-point)
8108     (gnus-set-mode-line 'summary)
8109     not-deleted))
8110
8111 (defun gnus-summary-edit-article (&optional arg)
8112   "Edit the current article.
8113 This will have permanent effect only in mail groups.
8114 If ARG is nil, edit the decoded articles.
8115 If ARG is 1, edit the raw articles.
8116 If ARG is 2, edit the raw articles even in read-only groups.
8117 If ARG is 3, edit the articles with the current handles.
8118 Otherwise, allow editing of articles even in read-only
8119 groups."
8120   (interactive "P")
8121   (let (force raw current-handles)
8122     (cond
8123      ((null arg))
8124      ((eq arg 1) (setq raw t))
8125      ((eq arg 2) (setq raw t
8126                        force t))
8127      ((eq arg 3) (setq current-handles
8128                        (and (gnus-buffer-live-p gnus-article-buffer)
8129                             (with-current-buffer gnus-article-buffer
8130                               (prog1
8131                                   gnus-article-mime-handles
8132                                   (setq gnus-article-mime-handles nil))))))
8133      (t (setq force t)))
8134     (if (and raw (not force) (equal gnus-newsgroup-name "nndraft:drafts"))
8135         (error "Can't edit the raw article in group nndraft:drafts."))
8136     (save-excursion
8137       (set-buffer gnus-summary-buffer)
8138       (let ((mail-parse-charset gnus-newsgroup-charset)
8139             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8140         (gnus-set-global-variables)
8141         (when (and (not force)
8142                    (gnus-group-read-only-p))
8143           (error "The current newsgroup does not support article editing"))
8144         (gnus-summary-show-article t)
8145         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
8146           (with-current-buffer gnus-article-buffer
8147             (mm-enable-multibyte-mule4)))
8148         (if (equal gnus-newsgroup-name "nndraft:drafts")
8149             (setq raw t))
8150         (gnus-article-edit-article
8151          (if raw 'ignore
8152            `(lambda ()
8153               (let ((mbl mml-buffer-list))
8154                 (setq mml-buffer-list nil)
8155                 (mime-to-mml ,'current-handles)
8156                 (make-local-hook 'kill-buffer-hook)
8157                 (let ((mbl1 mml-buffer-list))
8158                   (setq mml-buffer-list mbl)
8159                   (set (make-local-variable 'mml-buffer-list) mbl1))
8160                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
8161          `(lambda (no-highlight)
8162             (let ((mail-parse-charset ',gnus-newsgroup-charset)
8163                   (message-options message-options)
8164                   (message-options-set-recipient)
8165                   (mail-parse-ignored-charsets
8166                    ',gnus-newsgroup-ignored-charsets))
8167               ,(if (not raw) '(progn
8168                                 (mml-to-mime)
8169                                 (mml-destroy-buffers)
8170                                 (remove-hook 'kill-buffer-hook
8171                                              'mml-destroy-buffers t)
8172                                 (kill-local-variable 'mml-buffer-list)))
8173               (gnus-summary-edit-article-done
8174                ,(or (mail-header-references gnus-current-headers) "")
8175                ,(gnus-group-read-only-p)
8176                ,gnus-summary-buffer no-highlight))))))))
8177
8178 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8179
8180 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8181                                                  no-highlight)
8182   "Make edits to the current article permanent."
8183   (interactive)
8184   (save-excursion
8185     ;; The buffer restriction contains the entire article if it exists.
8186     (when (article-goto-body)
8187       (let ((lines (count-lines (point) (point-max)))
8188             (length (- (point-max) (point)))
8189             (case-fold-search t)
8190             (body (copy-marker (point))))
8191         (goto-char (point-min))
8192         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8193           (delete-region (match-beginning 1) (match-end 1))
8194           (insert (number-to-string length)))
8195         (goto-char (point-min))
8196         (when (re-search-forward
8197                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8198           (delete-region (match-beginning 1) (match-end 1))
8199           (insert (number-to-string length)))
8200         (goto-char (point-min))
8201         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8202           (delete-region (match-beginning 1) (match-end 1))
8203           (insert (number-to-string lines))))))
8204   ;; Replace the article.
8205   (let ((buf (current-buffer)))
8206     (with-temp-buffer
8207       (insert-buffer-substring buf)
8208
8209       (if (and (not read-only)
8210                (not (gnus-request-replace-article
8211                      (cdr gnus-article-current) (car gnus-article-current)
8212                      (current-buffer) t)))
8213           (error "Couldn't replace article")
8214         ;; Update the summary buffer.
8215         (if (and references
8216                  (equal (message-tokenize-header references " ")
8217                         (message-tokenize-header
8218                          (or (message-fetch-field "references") "") " ")))
8219             ;; We only have to update this line.
8220             (save-excursion
8221               (save-restriction
8222                 (message-narrow-to-head)
8223                 (let ((head (buffer-string))
8224                       header)
8225                   (with-temp-buffer
8226                     (insert (format "211 %d Article retrieved.\n"
8227                                     (cdr gnus-article-current)))
8228                     (insert head)
8229                     (insert ".\n")
8230                     (let ((nntp-server-buffer (current-buffer)))
8231                       (setq header (car (gnus-get-newsgroup-headers
8232                                          (save-excursion
8233                                            (set-buffer gnus-summary-buffer)
8234                                            gnus-newsgroup-dependencies)
8235                                          t))))
8236                     (save-excursion
8237                       (set-buffer gnus-summary-buffer)
8238                       (gnus-data-set-header
8239                        (gnus-data-find (cdr gnus-article-current))
8240                        header)
8241                       (gnus-summary-update-article-line
8242                        (cdr gnus-article-current) header))))))
8243           ;; Update threads.
8244           (set-buffer (or buffer gnus-summary-buffer))
8245           (gnus-summary-update-article (cdr gnus-article-current)))
8246         ;; Prettify the article buffer again.
8247         (unless no-highlight
8248           (save-excursion
8249             (set-buffer gnus-article-buffer)
8250             ;;;!!! Fix this -- article should be rehighlighted.
8251             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8252             (set-buffer gnus-original-article-buffer)
8253             (gnus-request-article
8254              (cdr gnus-article-current)
8255              (car gnus-article-current) (current-buffer))))
8256         ;; Prettify the summary buffer line.
8257         (when (gnus-visual-p 'summary-highlight 'highlight)
8258           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8259
8260 (defun gnus-summary-edit-wash (key)
8261   "Perform editing command KEY in the article buffer."
8262   (interactive
8263    (list
8264     (progn
8265       (message "%s" (concat (this-command-keys) "- "))
8266       (read-char))))
8267   (message "")
8268   (gnus-summary-edit-article)
8269   (execute-kbd-macro (concat (this-command-keys) key))
8270   (gnus-article-edit-done))
8271
8272 ;;; Respooling
8273
8274 (defun gnus-summary-respool-query (&optional silent trace)
8275   "Query where the respool algorithm would put this article."
8276   (interactive)
8277   (let (gnus-mark-article-hook)
8278     (gnus-summary-select-article)
8279     (save-excursion
8280       (set-buffer gnus-original-article-buffer)
8281       (save-restriction
8282         (message-narrow-to-head)
8283         (let ((groups (nnmail-article-group 'identity trace)))
8284           (unless silent
8285             (if groups
8286                 (message "This message would go to %s"
8287                          (mapconcat 'car groups ", "))
8288               (message "This message would go to no groups"))
8289             groups))))))
8290
8291 (defun gnus-summary-respool-trace ()
8292   "Trace where the respool algorithm would put this article.
8293 Display a buffer showing all fancy splitting patterns which matched."
8294   (interactive)
8295   (gnus-summary-respool-query nil t))
8296
8297 ;; Summary marking commands.
8298
8299 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8300   "Mark articles which has the same subject as read, and then select the next.
8301 If UNMARK is positive, remove any kind of mark.
8302 If UNMARK is negative, tick articles."
8303   (interactive "P")
8304   (when unmark
8305     (setq unmark (prefix-numeric-value unmark)))
8306   (let ((count
8307          (gnus-summary-mark-same-subject
8308           (gnus-summary-article-subject) unmark)))
8309     ;; Select next unread article.  If auto-select-same mode, should
8310     ;; select the first unread article.
8311     (gnus-summary-next-article t (and gnus-auto-select-same
8312                                       (gnus-summary-article-subject)))
8313     (gnus-message 7 "%d article%s marked as %s"
8314                   count (if (= count 1) " is" "s are")
8315                   (if unmark "unread" "read"))))
8316
8317 (defun gnus-summary-kill-same-subject (&optional unmark)
8318   "Mark articles which has the same subject as read.
8319 If UNMARK is positive, remove any kind of mark.
8320 If UNMARK is negative, tick articles."
8321   (interactive "P")
8322   (when unmark
8323     (setq unmark (prefix-numeric-value unmark)))
8324   (let ((count
8325          (gnus-summary-mark-same-subject
8326           (gnus-summary-article-subject) unmark)))
8327     ;; If marked as read, go to next unread subject.
8328     (when (null unmark)
8329       ;; Go to next unread subject.
8330       (gnus-summary-next-subject 1 t))
8331     (gnus-message 7 "%d articles are marked as %s"
8332                   count (if unmark "unread" "read"))))
8333
8334 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8335   "Mark articles with same SUBJECT as read, and return marked number.
8336 If optional argument UNMARK is positive, remove any kinds of marks.
8337 If optional argument UNMARK is negative, mark articles as unread instead."
8338   (let ((count 1))
8339     (save-excursion
8340       (cond
8341        ((null unmark)                   ; Mark as read.
8342         (while (and
8343                 (progn
8344                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8345                   (gnus-summary-show-thread) t)
8346                 (gnus-summary-find-subject subject))
8347           (setq count (1+ count))))
8348        ((> unmark 0)                    ; Tick.
8349         (while (and
8350                 (progn
8351                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8352                   (gnus-summary-show-thread) t)
8353                 (gnus-summary-find-subject subject))
8354           (setq count (1+ count))))
8355        (t                               ; Mark as unread.
8356         (while (and
8357                 (progn
8358                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8359                   (gnus-summary-show-thread) t)
8360                 (gnus-summary-find-subject subject))
8361           (setq count (1+ count)))))
8362       (gnus-set-mode-line 'summary)
8363       ;; Return the number of marked articles.
8364       count)))
8365
8366 (defun gnus-summary-mark-as-processable (n &optional unmark)
8367   "Set the process mark on the next N articles.
8368 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8369 the process mark instead.  The difference between N and the actual
8370 number of articles marked is returned."
8371   (interactive "P")
8372   (if (and (null n) (gnus-region-active-p))
8373       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8374     (setq n (prefix-numeric-value n))
8375     (let ((backward (< n 0))
8376           (n (abs n)))
8377       (while (and
8378               (> n 0)
8379               (if unmark
8380                 (gnus-summary-remove-process-mark
8381                  (gnus-summary-article-number))
8382                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8383               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8384         (setq n (1- n)))
8385       (when (/= 0 n)
8386         (gnus-message 7 "No more articles"))
8387       (gnus-summary-recenter)
8388       (gnus-summary-position-point)
8389       n)))
8390
8391 (defun gnus-summary-unmark-as-processable (n)
8392   "Remove the process mark from the next N articles.
8393 If N is negative, unmark backward instead.  The difference between N and
8394 the actual number of articles unmarked is returned."
8395   (interactive "P")
8396   (gnus-summary-mark-as-processable n t))
8397
8398 (defun gnus-summary-unmark-all-processable ()
8399   "Remove the process mark from all articles."
8400   (interactive)
8401   (save-excursion
8402     (while gnus-newsgroup-processable
8403       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8404   (gnus-summary-position-point))
8405
8406 (defun gnus-summary-add-mark (article type)
8407   "Mark ARTICLE with a mark of TYPE."
8408   (let ((vtype (car (assq type gnus-article-mark-lists)))
8409         var)
8410     (if (not vtype)
8411         (error "No such mark type: %s" type)
8412       (setq var (intern (format "gnus-newsgroup-%s" type)))
8413       (set var (cons article (symbol-value var)))
8414       (if (memq type '(processable cached replied saved))
8415           (gnus-summary-update-secondary-mark article)
8416         ;;; !!! This is bobus.  We should find out what primary
8417         ;;; !!! mark we want to set.
8418         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8419
8420 (defun gnus-summary-mark-as-expirable (n)
8421   "Mark N articles forward as expirable.
8422 If N is negative, mark backward instead.  The difference between N and
8423 the actual number of articles marked is returned."
8424   (interactive "p")
8425   (gnus-summary-mark-forward n gnus-expirable-mark))
8426
8427 (defun gnus-summary-mark-article-as-replied (article)
8428   "Mark ARTICLE replied and update the summary line."
8429   (push article gnus-newsgroup-replied)
8430   (let ((buffer-read-only nil))
8431     (when (gnus-summary-goto-subject article nil t)
8432       (gnus-summary-update-secondary-mark article))))
8433
8434 (defun gnus-summary-set-bookmark (article)
8435   "Set a bookmark in current article."
8436   (interactive (list (gnus-summary-article-number)))
8437   (when (or (not (get-buffer gnus-article-buffer))
8438             (not gnus-current-article)
8439             (not gnus-article-current)
8440             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8441     (error "No current article selected"))
8442   ;; Remove old bookmark, if one exists.
8443   (let ((old (assq article gnus-newsgroup-bookmarks)))
8444     (when old
8445       (setq gnus-newsgroup-bookmarks
8446             (delq old gnus-newsgroup-bookmarks))))
8447   ;; Set the new bookmark, which is on the form
8448   ;; (article-number . line-number-in-body).
8449   (push
8450    (cons article
8451          (save-excursion
8452            (set-buffer gnus-article-buffer)
8453            (count-lines
8454             (min (point)
8455                  (save-excursion
8456                    (goto-char (point-min))
8457                    (search-forward "\n\n" nil t)
8458                    (point)))
8459             (point))))
8460    gnus-newsgroup-bookmarks)
8461   (gnus-message 6 "A bookmark has been added to the current article."))
8462
8463 (defun gnus-summary-remove-bookmark (article)
8464   "Remove the bookmark from the current article."
8465   (interactive (list (gnus-summary-article-number)))
8466   ;; Remove old bookmark, if one exists.
8467   (let ((old (assq article gnus-newsgroup-bookmarks)))
8468     (if old
8469         (progn
8470           (setq gnus-newsgroup-bookmarks
8471                 (delq old gnus-newsgroup-bookmarks))
8472           (gnus-message 6 "Removed bookmark."))
8473       (gnus-message 6 "No bookmark in current article."))))
8474
8475 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8476 (defun gnus-summary-mark-as-dormant (n)
8477   "Mark N articles forward as dormant.
8478 If N is negative, mark backward instead.  The difference between N and
8479 the actual number of articles marked is returned."
8480   (interactive "p")
8481   (gnus-summary-mark-forward n gnus-dormant-mark))
8482
8483 (defun gnus-summary-set-process-mark (article)
8484   "Set the process mark on ARTICLE and update the summary line."
8485   (setq gnus-newsgroup-processable
8486         (cons article
8487               (delq article gnus-newsgroup-processable)))
8488   (when (gnus-summary-goto-subject article)
8489     (gnus-summary-show-thread)
8490     (gnus-summary-goto-subject article)
8491     (gnus-summary-update-secondary-mark article)))
8492
8493 (defun gnus-summary-remove-process-mark (article)
8494   "Remove the process mark from ARTICLE and update the summary line."
8495   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8496   (when (gnus-summary-goto-subject article)
8497     (gnus-summary-show-thread)
8498     (gnus-summary-goto-subject article)
8499     (gnus-summary-update-secondary-mark article)))
8500
8501 (defun gnus-summary-set-saved-mark (article)
8502   "Set the process mark on ARTICLE and update the summary line."
8503   (push article gnus-newsgroup-saved)
8504   (when (gnus-summary-goto-subject article)
8505     (gnus-summary-update-secondary-mark article)))
8506
8507 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8508   "Mark N articles as read forwards.
8509 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8510 The difference between N and the actual number of articles marked is
8511 returned.
8512 Iff NO-EXPIRE, auto-expiry will be inhibited."
8513   (interactive "p")
8514   (gnus-summary-show-thread)
8515   (let ((backward (< n 0))
8516         (gnus-summary-goto-unread
8517          (and gnus-summary-goto-unread
8518               (not (eq gnus-summary-goto-unread 'never))
8519               (not (memq mark (list gnus-unread-mark
8520                                     gnus-ticked-mark gnus-dormant-mark)))))
8521         (n (abs n))
8522         (mark (or mark gnus-del-mark)))
8523     (while (and (> n 0)
8524                 (gnus-summary-mark-article nil mark no-expire)
8525                 (zerop (gnus-summary-next-subject
8526                         (if backward -1 1)
8527                         (and gnus-summary-goto-unread
8528                              (not (eq gnus-summary-goto-unread 'never)))
8529                         t)))
8530       (setq n (1- n)))
8531     (when (/= 0 n)
8532       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
8533     (gnus-summary-recenter)
8534     (gnus-summary-position-point)
8535     (gnus-set-mode-line 'summary)
8536     n))
8537
8538 (defun gnus-summary-mark-article-as-read (mark)
8539   "Mark the current article quickly as read with MARK."
8540   (let ((article (gnus-summary-article-number)))
8541     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8542     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8543     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8544     (push (cons article mark) gnus-newsgroup-reads)
8545     ;; Possibly remove from cache, if that is used.
8546     (when gnus-use-cache
8547       (gnus-cache-enter-remove-article article))
8548     ;; Allow the backend to change the mark.
8549     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8550     ;; Check for auto-expiry.
8551     (when (and gnus-newsgroup-auto-expire
8552                (memq mark gnus-auto-expirable-marks))
8553       (setq mark gnus-expirable-mark)
8554       ;; Let the backend know about the mark change.
8555       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8556       (push article gnus-newsgroup-expirable))
8557     ;; Set the mark in the buffer.
8558     (gnus-summary-update-mark mark 'unread)
8559     t))
8560
8561 (defun gnus-summary-mark-article-as-unread (mark)
8562   "Mark the current article quickly as unread with MARK."
8563   (let* ((article (gnus-summary-article-number))
8564          (old-mark (gnus-summary-article-mark article)))
8565     ;; Allow the backend to change the mark.
8566     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8567     (if (eq mark old-mark)
8568         t
8569       (if (<= article 0)
8570           (progn
8571             (gnus-error 1 "Can't mark negative article numbers")
8572             nil)
8573         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8574         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8575         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
8576         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
8577         (cond ((= mark gnus-ticked-mark)
8578                (push article gnus-newsgroup-marked))
8579               ((= mark gnus-dormant-mark)
8580                (push article gnus-newsgroup-dormant))
8581               (t
8582                (push article gnus-newsgroup-unreads)))
8583         (gnus-pull article gnus-newsgroup-reads)
8584
8585         ;; See whether the article is to be put in the cache.
8586         (and gnus-use-cache
8587              (vectorp (gnus-summary-article-header article))
8588              (save-excursion
8589                (gnus-cache-possibly-enter-article
8590                 gnus-newsgroup-name article
8591                 (= mark gnus-ticked-mark)
8592                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8593
8594         ;; Fix the mark.
8595         (gnus-summary-update-mark mark 'unread)
8596         t))))
8597
8598 (defun gnus-summary-mark-article (&optional article mark no-expire)
8599   "Mark ARTICLE with MARK.  MARK can be any character.
8600 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
8601 `??' (dormant) and `?E' (expirable).
8602 If MARK is nil, then the default character `?r' is used.
8603 If ARTICLE is nil, then the article on the current line will be
8604 marked.
8605 Iff NO-EXPIRE, auto-expiry will be inhibited."
8606   ;; The mark might be a string.
8607   (when (stringp mark)
8608     (setq mark (aref mark 0)))
8609   ;; If no mark is given, then we check auto-expiring.
8610   (when (null mark)
8611     (setq mark gnus-del-mark))
8612   (when (and (not no-expire)
8613              gnus-newsgroup-auto-expire
8614              (memq mark gnus-auto-expirable-marks))
8615     (setq mark gnus-expirable-mark))
8616   (let ((article (or article (gnus-summary-article-number)))
8617         (old-mark (gnus-summary-article-mark article)))
8618     ;; Allow the backend to change the mark.
8619     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
8620     (if (eq mark old-mark)
8621         t
8622       (unless article
8623         (error "No article on current line"))
8624       (if (not (if (or (= mark gnus-unread-mark)
8625                        (= mark gnus-ticked-mark)
8626                        (= mark gnus-dormant-mark))
8627                    (gnus-mark-article-as-unread article mark)
8628                  (gnus-mark-article-as-read article mark)))
8629           t
8630         ;; See whether the article is to be put in the cache.
8631         (and gnus-use-cache
8632              (not (= mark gnus-canceled-mark))
8633              (vectorp (gnus-summary-article-header article))
8634              (save-excursion
8635                (gnus-cache-possibly-enter-article
8636                 gnus-newsgroup-name article
8637                 (= mark gnus-ticked-mark)
8638                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
8639
8640         (when (gnus-summary-goto-subject article nil t)
8641           (let ((buffer-read-only nil))
8642             (gnus-summary-show-thread)
8643             ;; Fix the mark.
8644             (gnus-summary-update-mark mark 'unread)
8645             t))))))
8646
8647 (defun gnus-summary-update-secondary-mark (article)
8648   "Update the secondary (read, process, cache) mark."
8649   (gnus-summary-update-mark
8650    (cond ((memq article gnus-newsgroup-processable)
8651           gnus-process-mark)
8652          ((memq article gnus-newsgroup-cached)
8653           gnus-cached-mark)
8654          ((memq article gnus-newsgroup-replied)
8655           gnus-replied-mark)
8656          ((memq article gnus-newsgroup-saved)
8657           gnus-saved-mark)
8658          (t gnus-no-mark))
8659    'replied)
8660   (when (gnus-visual-p 'summary-highlight 'highlight)
8661     (gnus-run-hooks 'gnus-summary-update-hook))
8662   t)
8663
8664 (defun gnus-summary-update-mark (mark type)
8665   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
8666         (buffer-read-only nil))
8667     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
8668     (when forward
8669       (when (looking-at "\r")
8670         (incf forward))
8671       (when (<= (+ forward (point)) (point-max))
8672         ;; Go to the right position on the line.
8673         (goto-char (+ forward (point)))
8674         ;; Replace the old mark with the new mark.
8675         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
8676         ;; Optionally update the marks by some user rule.
8677         (when (eq type 'unread)
8678           (gnus-data-set-mark
8679            (gnus-data-find (gnus-summary-article-number)) mark)
8680           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
8681
8682 (defun gnus-mark-article-as-read (article &optional mark)
8683   "Enter ARTICLE in the pertinent lists and remove it from others."
8684   ;; Make the article expirable.
8685   (let ((mark (or mark gnus-del-mark)))
8686     (if (= mark gnus-expirable-mark)
8687         (push article gnus-newsgroup-expirable)
8688       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
8689     ;; Remove from unread and marked lists.
8690     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8691     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
8692     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
8693     (push (cons article mark) gnus-newsgroup-reads)
8694     ;; Possibly remove from cache, if that is used.
8695     (when gnus-use-cache
8696       (gnus-cache-enter-remove-article article))
8697     t))
8698
8699 (defun gnus-mark-article-as-unread (article &optional mark)
8700   "Enter ARTICLE in the pertinent lists and remove it from others."
8701   (let ((mark (or mark gnus-ticked-mark)))
8702     (if (<= article 0)
8703         (progn
8704           (gnus-error 1 "Can't mark negative article numbers")
8705           nil)
8706       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
8707             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
8708             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
8709             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
8710
8711       ;; Unsuppress duplicates?
8712       (when gnus-suppress-duplicates
8713         (gnus-dup-unsuppress-article article))
8714
8715       (cond ((= mark gnus-ticked-mark)
8716              (push article gnus-newsgroup-marked))
8717             ((= mark gnus-dormant-mark)
8718              (push article gnus-newsgroup-dormant))
8719             (t
8720              (push article gnus-newsgroup-unreads)))
8721       (gnus-pull article gnus-newsgroup-reads)
8722       t)))
8723
8724 (defalias 'gnus-summary-mark-as-unread-forward
8725   'gnus-summary-tick-article-forward)
8726 (make-obsolete 'gnus-summary-mark-as-unread-forward
8727                'gnus-summary-tick-article-forward)
8728 (defun gnus-summary-tick-article-forward (n)
8729   "Tick N articles forwards.
8730 If N is negative, tick backwards instead.
8731 The difference between N and the number of articles ticked is returned."
8732   (interactive "p")
8733   (gnus-summary-mark-forward n gnus-ticked-mark))
8734
8735 (defalias 'gnus-summary-mark-as-unread-backward
8736   'gnus-summary-tick-article-backward)
8737 (make-obsolete 'gnus-summary-mark-as-unread-backward
8738                'gnus-summary-tick-article-backward)
8739 (defun gnus-summary-tick-article-backward (n)
8740   "Tick N articles backwards.
8741 The difference between N and the number of articles ticked is returned."
8742   (interactive "p")
8743   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
8744
8745 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8746 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
8747 (defun gnus-summary-tick-article (&optional article clear-mark)
8748   "Mark current article as unread.
8749 Optional 1st argument ARTICLE specifies article number to be marked as unread.
8750 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
8751   (interactive)
8752   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
8753                                        gnus-ticked-mark)))
8754
8755 (defun gnus-summary-mark-as-read-forward (n)
8756   "Mark N articles as read forwards.
8757 If N is negative, mark backwards instead.
8758 The difference between N and the actual number of articles marked is
8759 returned."
8760   (interactive "p")
8761   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
8762
8763 (defun gnus-summary-mark-as-read-backward (n)
8764   "Mark the N articles as read backwards.
8765 The difference between N and the actual number of articles marked is
8766 returned."
8767   (interactive "p")
8768   (gnus-summary-mark-forward
8769    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
8770
8771 (defun gnus-summary-mark-as-read (&optional article mark)
8772   "Mark current article as read.
8773 ARTICLE specifies the article to be marked as read.
8774 MARK specifies a string to be inserted at the beginning of the line."
8775   (gnus-summary-mark-article article mark))
8776
8777 (defun gnus-summary-clear-mark-forward (n)
8778   "Clear marks from N articles forward.
8779 If N is negative, clear backward instead.
8780 The difference between N and the number of marks cleared is returned."
8781   (interactive "p")
8782   (gnus-summary-mark-forward n gnus-unread-mark))
8783
8784 (defun gnus-summary-clear-mark-backward (n)
8785   "Clear marks from N articles backward.
8786 The difference between N and the number of marks cleared is returned."
8787   (interactive "p")
8788   (gnus-summary-mark-forward (- n) gnus-unread-mark))
8789
8790 (defun gnus-summary-mark-unread-as-read ()
8791   "Intended to be used by `gnus-summary-mark-article-hook'."
8792   (when (memq gnus-current-article gnus-newsgroup-unreads)
8793     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
8794
8795 (defun gnus-summary-mark-read-and-unread-as-read ()
8796   "Intended to be used by `gnus-summary-mark-article-hook'."
8797   (let ((mark (gnus-summary-article-mark)))
8798     (when (or (gnus-unread-mark-p mark)
8799               (gnus-read-mark-p mark))
8800       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
8801
8802 (defun gnus-summary-mark-unread-as-ticked ()
8803    "Intended to be used by `gnus-summary-mark-article-hook'."
8804   (when (memq gnus-current-article gnus-newsgroup-unreads)
8805     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
8806
8807 (defun gnus-summary-mark-region-as-read (point mark all)
8808   "Mark all unread articles between point and mark as read.
8809 If given a prefix, mark all articles between point and mark as read,
8810 even ticked and dormant ones."
8811   (interactive "r\nP")
8812   (save-excursion
8813     (let (article)
8814       (goto-char point)
8815       (beginning-of-line)
8816       (while (and
8817               (< (point) mark)
8818               (progn
8819                 (when (or all
8820                           (memq (setq article (gnus-summary-article-number))
8821                                 gnus-newsgroup-unreads))
8822                   (gnus-summary-mark-article article gnus-del-mark))
8823                 t)
8824               (gnus-summary-find-next))))))
8825
8826 (defun gnus-summary-mark-below (score mark)
8827   "Mark articles with score less than SCORE with MARK."
8828   (interactive "P\ncMark: ")
8829   (setq score (if score
8830                   (prefix-numeric-value score)
8831                 (or gnus-summary-default-score 0)))
8832   (save-excursion
8833     (set-buffer gnus-summary-buffer)
8834     (goto-char (point-min))
8835     (while
8836         (progn
8837           (and (< (gnus-summary-article-score) score)
8838                (gnus-summary-mark-article nil mark))
8839           (gnus-summary-find-next)))))
8840
8841 (defun gnus-summary-kill-below (&optional score)
8842   "Mark articles with score below SCORE as read."
8843   (interactive "P")
8844   (gnus-summary-mark-below score gnus-killed-mark))
8845
8846 (defun gnus-summary-clear-above (&optional score)
8847   "Clear all marks from articles with score above SCORE."
8848   (interactive "P")
8849   (gnus-summary-mark-above score gnus-unread-mark))
8850
8851 (defun gnus-summary-tick-above (&optional score)
8852   "Tick all articles with score above SCORE."
8853   (interactive "P")
8854   (gnus-summary-mark-above score gnus-ticked-mark))
8855
8856 (defun gnus-summary-mark-above (score mark)
8857   "Mark articles with score over SCORE with MARK."
8858   (interactive "P\ncMark: ")
8859   (setq score (if score
8860                   (prefix-numeric-value score)
8861                 (or gnus-summary-default-score 0)))
8862   (save-excursion
8863     (set-buffer gnus-summary-buffer)
8864     (goto-char (point-min))
8865     (while (and (progn
8866                   (when (> (gnus-summary-article-score) score)
8867                     (gnus-summary-mark-article nil mark))
8868                   t)
8869                 (gnus-summary-find-next)))))
8870
8871 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8872 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
8873 (defun gnus-summary-limit-include-expunged (&optional no-error)
8874   "Display all the hidden articles that were expunged for low scores."
8875   (interactive)
8876   (let ((buffer-read-only nil))
8877     (let ((scored gnus-newsgroup-scored)
8878           headers h)
8879       (while scored
8880         (unless (gnus-summary-article-header (caar scored))
8881           (and (setq h (gnus-number-to-header (caar scored)))
8882                (< (cdar scored) gnus-summary-expunge-below)
8883                (push h headers)))
8884         (setq scored (cdr scored)))
8885       (if (not headers)
8886           (when (not no-error)
8887             (error "No expunged articles hidden"))
8888         (goto-char (point-min))
8889         (push gnus-newsgroup-limit gnus-newsgroup-limits)
8890         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
8891         (mapcar (lambda (x) (push (mail-header-number x) 
8892                                   gnus-newsgroup-limit))
8893                 headers)
8894         (gnus-summary-prepare-unthreaded (nreverse headers))
8895         (goto-char (point-min))
8896         (gnus-summary-position-point)
8897         t))))
8898
8899 (defun gnus-summary-catchup (&optional all quietly to-here not-mark)
8900   "Mark all unread articles in this newsgroup as read.
8901 If prefix argument ALL is non-nil, ticked and dormant articles will
8902 also be marked as read.
8903 If QUIETLY is non-nil, no questions will be asked.
8904 If TO-HERE is non-nil, it should be a point in the buffer.  All
8905 articles before this point will be marked as read.
8906 Note that this function will only catch up the unread article
8907 in the current summary buffer limitation.
8908 The number of articles marked as read is returned."
8909   (interactive "P")
8910   (prog1
8911       (save-excursion
8912         (when (or quietly
8913                   (not gnus-interactive-catchup) ;Without confirmation?
8914                   gnus-expert-user
8915                   (gnus-y-or-n-p
8916                    (if all
8917                        "Mark absolutely all articles as read? "
8918                      "Mark all unread articles as read? ")))
8919           (if (and not-mark
8920                    (not gnus-newsgroup-adaptive)
8921                    (not gnus-newsgroup-auto-expire)
8922                    (not gnus-suppress-duplicates)
8923                    (or (not gnus-use-cache)
8924                        (eq gnus-use-cache 'passive)))
8925               (progn
8926                 (when all
8927                   (setq gnus-newsgroup-marked nil
8928                         gnus-newsgroup-dormant nil))
8929                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
8930             ;; We actually mark all articles as canceled, which we
8931             ;; have to do when using auto-expiry or adaptive scoring.
8932             (gnus-summary-show-all-threads)
8933             (when (gnus-summary-first-subject (not all) t)
8934               (while (and
8935                       (if to-here (< (point) to-here) t)
8936                       (gnus-summary-mark-article-as-read gnus-catchup-mark)
8937                       (gnus-summary-find-next (not all) nil nil t))))
8938             (gnus-set-mode-line 'summary))
8939           t))
8940     (gnus-summary-position-point)))
8941
8942 (defun gnus-summary-catchup-to-here (&optional all)
8943   "Mark all unticked articles before the current one as read.
8944 If ALL is non-nil, also mark ticked and dormant articles as read."
8945   (interactive "P")
8946   (save-excursion
8947     (gnus-save-hidden-threads
8948       (let ((beg (point)))
8949         ;; We check that there are unread articles.
8950         (when (or all (gnus-summary-find-prev))
8951           (gnus-summary-catchup all t beg)))))
8952   (gnus-summary-position-point))
8953
8954 (defun gnus-summary-catchup-all (&optional quietly)
8955   "Mark all articles in this newsgroup as read."
8956   (interactive "P")
8957   (gnus-summary-catchup t quietly))
8958
8959 (defun gnus-summary-catchup-and-exit (&optional all quietly)
8960   "Mark all unread articles in this group as read, then exit.
8961 If prefix argument ALL is non-nil, all articles are marked as read."
8962   (interactive "P")
8963   (when (gnus-summary-catchup all quietly nil 'fast)
8964     ;; Select next newsgroup or exit.
8965     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
8966              (eq gnus-auto-select-next 'quietly))
8967         (gnus-summary-next-group nil)
8968       (gnus-summary-exit))))
8969
8970 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
8971   "Mark all articles in this newsgroup as read, and then exit."
8972   (interactive "P")
8973   (gnus-summary-catchup-and-exit t quietly))
8974
8975 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
8976   "Mark all articles in this group as read and select the next group.
8977 If given a prefix, mark all articles, unread as well as ticked, as
8978 read."
8979   (interactive "P")
8980   (save-excursion
8981     (gnus-summary-catchup all))
8982   (gnus-summary-next-group))
8983
8984 ;;;
8985 ;;; with article
8986 ;;;
8987
8988 (defmacro gnus-with-article (article &rest forms)
8989   "Select ARTICLE and perform FORMS in the original article buffer.
8990 Then replace the article with the result."
8991   `(progn
8992      ;; We don't want the article to be marked as read.
8993      (let (gnus-mark-article-hook)
8994        (gnus-summary-select-article t t nil ,article))
8995      (set-buffer gnus-original-article-buffer)
8996      ,@forms
8997      (if (not (gnus-check-backend-function
8998                'request-replace-article (car gnus-article-current)))
8999          (gnus-message 5 "Read-only group; not replacing")
9000        (unless (gnus-request-replace-article
9001                 ,article (car gnus-article-current)
9002                 (current-buffer) t)
9003          (error "Couldn't replace article")))
9004      ;; The cache and backlog have to be flushed somewhat.
9005      (when gnus-keep-backlog
9006        (gnus-backlog-remove-article
9007         (car gnus-article-current) (cdr gnus-article-current)))
9008      (when gnus-use-cache
9009        (gnus-cache-update-article
9010         (car gnus-article-current) (cdr gnus-article-current)))))
9011
9012 (put 'gnus-with-article 'lisp-indent-function 1)
9013 (put 'gnus-with-article 'edebug-form-spec '(form body))
9014
9015 ;; Thread-based commands.
9016
9017 (defun gnus-summary-articles-in-thread (&optional article)
9018   "Return a list of all articles in the current thread.
9019 If ARTICLE is non-nil, return all articles in the thread that starts
9020 with that article."
9021   (let* ((article (or article (gnus-summary-article-number)))
9022          (data (gnus-data-find-list article))
9023          (top-level (gnus-data-level (car data)))
9024          (top-subject
9025           (cond ((null gnus-thread-operation-ignore-subject)
9026                  (gnus-simplify-subject-re
9027                   (mail-header-subject (gnus-data-header (car data)))))
9028                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9029                  (gnus-simplify-subject-fuzzy
9030                   (mail-header-subject (gnus-data-header (car data)))))
9031                 (t nil)))
9032          (end-point (save-excursion
9033                       (if (gnus-summary-go-to-next-thread)
9034                           (point) (point-max))))
9035          articles)
9036     (while (and data
9037                 (< (gnus-data-pos (car data)) end-point))
9038       (when (or (not top-subject)
9039                 (string= top-subject
9040                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9041                              (gnus-simplify-subject-fuzzy
9042                               (mail-header-subject
9043                                (gnus-data-header (car data))))
9044                            (gnus-simplify-subject-re
9045                             (mail-header-subject
9046                              (gnus-data-header (car data)))))))
9047         (push (gnus-data-number (car data)) articles))
9048       (unless (and (setq data (cdr data))
9049                    (> (gnus-data-level (car data)) top-level))
9050         (setq data nil)))
9051     ;; Return the list of articles.
9052     (nreverse articles)))
9053
9054 (defun gnus-summary-rethread-current ()
9055   "Rethread the thread the current article is part of."
9056   (interactive)
9057   (let* ((gnus-show-threads t)
9058          (article (gnus-summary-article-number))
9059          (id (mail-header-id (gnus-summary-article-header)))
9060          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9061     (unless id
9062       (error "No article on the current line"))
9063     (gnus-rebuild-thread id)
9064     (gnus-summary-goto-subject article)))
9065
9066 (defun gnus-summary-reparent-thread ()
9067   "Make the current article child of the marked (or previous) article.
9068
9069 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9070 is non-nil or the Subject: of both articles are the same."
9071   (interactive)
9072   (unless (not (gnus-group-read-only-p))
9073     (error "The current newsgroup does not support article editing"))
9074   (unless (<= (length gnus-newsgroup-processable) 1)
9075     (error "No more than one article may be marked"))
9076   (save-window-excursion
9077     (let ((gnus-article-buffer " *reparent*")
9078           (current-article (gnus-summary-article-number))
9079           ;; First grab the marked article, otherwise one line up.
9080           (parent-article (if (not (null gnus-newsgroup-processable))
9081                               (car gnus-newsgroup-processable)
9082                             (save-excursion
9083                               (if (eq (forward-line -1) 0)
9084                                   (gnus-summary-article-number)
9085                                 (error "Beginning of summary buffer"))))))
9086       (unless (not (eq current-article parent-article))
9087         (error "An article may not be self-referential"))
9088       (let ((message-id (mail-header-id
9089                          (gnus-summary-article-header parent-article))))
9090         (unless (and message-id (not (equal message-id "")))
9091           (error "No message-id in desired parent"))
9092         (gnus-with-article current-article
9093           (save-restriction
9094             (goto-char (point-min))
9095             (message-narrow-to-head)
9096             (if (re-search-forward "^References: " nil t)
9097                 (progn
9098                   (re-search-forward "^[^ \t]" nil t)
9099                   (forward-line -1)
9100                   (end-of-line)
9101                   (insert " " message-id))
9102               (insert "References: " message-id "\n"))))
9103         (set-buffer gnus-summary-buffer)
9104         (gnus-summary-unmark-all-processable)
9105         (gnus-summary-update-article current-article)
9106         (gnus-summary-rethread-current)
9107         (gnus-message 3 "Article %d is now the child of article %d"
9108                       current-article parent-article)))))
9109
9110 (defun gnus-summary-toggle-threads (&optional arg)
9111   "Toggle showing conversation threads.
9112 If ARG is positive number, turn showing conversation threads on."
9113   (interactive "P")
9114   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9115     (setq gnus-show-threads
9116           (if (null arg) (not gnus-show-threads)
9117             (> (prefix-numeric-value arg) 0)))
9118     (gnus-summary-prepare)
9119     (gnus-summary-goto-subject current)
9120     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9121     (gnus-summary-position-point)))
9122
9123 (defun gnus-summary-show-all-threads ()
9124   "Show all threads."
9125   (interactive)
9126   (save-excursion
9127     (let ((buffer-read-only nil))
9128       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9129   (gnus-summary-position-point))
9130
9131 (defun gnus-summary-show-thread ()
9132   "Show thread subtrees.
9133 Returns nil if no thread was there to be shown."
9134   (interactive)
9135   (let ((buffer-read-only nil)
9136         (orig (point))
9137         ;; first goto end then to beg, to have point at beg after let
9138         (end (progn (end-of-line) (point)))
9139         (beg (progn (beginning-of-line) (point))))
9140     (prog1
9141         ;; Any hidden lines here?
9142         (search-forward "\r" end t)
9143       (subst-char-in-region beg end ?\^M ?\n t)
9144       (goto-char orig)
9145       (gnus-summary-position-point))))
9146
9147 (defun gnus-summary-hide-all-threads ()
9148   "Hide all thread subtrees."
9149   (interactive)
9150   (save-excursion
9151     (goto-char (point-min))
9152     (gnus-summary-hide-thread)
9153     (while (zerop (gnus-summary-next-thread 1 t))
9154       (gnus-summary-hide-thread)))
9155   (gnus-summary-position-point))
9156
9157 (defun gnus-summary-hide-thread ()
9158   "Hide thread subtrees.
9159 Returns nil if no threads were there to be hidden."
9160   (interactive)
9161   (let ((buffer-read-only nil)
9162         (start (point))
9163         (article (gnus-summary-article-number)))
9164     (goto-char start)
9165     ;; Go forward until either the buffer ends or the subthread
9166     ;; ends.
9167     (when (and (not (eobp))
9168                (or (zerop (gnus-summary-next-thread 1 t))
9169                    (goto-char (point-max))))
9170       (prog1
9171           (if (and (> (point) start)
9172                    (search-backward "\n" start t))
9173               (progn
9174                 (subst-char-in-region start (point) ?\n ?\^M)
9175                 (gnus-summary-goto-subject article))
9176             (goto-char start)
9177             nil)))))
9178
9179 (defun gnus-summary-go-to-next-thread (&optional previous)
9180   "Go to the same level (or less) next thread.
9181 If PREVIOUS is non-nil, go to previous thread instead.
9182 Return the article number moved to, or nil if moving was impossible."
9183   (let ((level (gnus-summary-thread-level))
9184         (way (if previous -1 1))
9185         (beg (point)))
9186     (forward-line way)
9187     (while (and (not (eobp))
9188                 (< level (gnus-summary-thread-level)))
9189       (forward-line way))
9190     (if (eobp)
9191         (progn
9192           (goto-char beg)
9193           nil)
9194       (setq beg (point))
9195       (prog1
9196           (gnus-summary-article-number)
9197         (goto-char beg)))))
9198
9199 (defun gnus-summary-next-thread (n &optional silent)
9200   "Go to the same level next N'th thread.
9201 If N is negative, search backward instead.
9202 Returns the difference between N and the number of skips actually
9203 done.
9204
9205 If SILENT, don't output messages."
9206   (interactive "p")
9207   (let ((backward (< n 0))
9208         (n (abs n)))
9209     (while (and (> n 0)
9210                 (gnus-summary-go-to-next-thread backward))
9211       (decf n))
9212     (unless silent
9213       (gnus-summary-position-point))
9214     (when (and (not silent) (/= 0 n))
9215       (gnus-message 7 "No more threads"))
9216     n))
9217
9218 (defun gnus-summary-prev-thread (n)
9219   "Go to the same level previous N'th thread.
9220 Returns the difference between N and the number of skips actually
9221 done."
9222   (interactive "p")
9223   (gnus-summary-next-thread (- n)))
9224
9225 (defun gnus-summary-go-down-thread ()
9226   "Go down one level in the current thread."
9227   (let ((children (gnus-summary-article-children)))
9228     (when children
9229       (gnus-summary-goto-subject (car children)))))
9230
9231 (defun gnus-summary-go-up-thread ()
9232   "Go up one level in the current thread."
9233   (let ((parent (gnus-summary-article-parent)))
9234     (when parent
9235       (gnus-summary-goto-subject parent))))
9236
9237 (defun gnus-summary-down-thread (n)
9238   "Go down thread N steps.
9239 If N is negative, go up instead.
9240 Returns the difference between N and how many steps down that were
9241 taken."
9242   (interactive "p")
9243   (let ((up (< n 0))
9244         (n (abs n)))
9245     (while (and (> n 0)
9246                 (if up (gnus-summary-go-up-thread)
9247                   (gnus-summary-go-down-thread)))
9248       (setq n (1- n)))
9249     (gnus-summary-position-point)
9250     (when (/= 0 n)
9251       (gnus-message 7 "Can't go further"))
9252     n))
9253
9254 (defun gnus-summary-up-thread (n)
9255   "Go up thread N steps.
9256 If N is negative, go up instead.
9257 Returns the difference between N and how many steps down that were
9258 taken."
9259   (interactive "p")
9260   (gnus-summary-down-thread (- n)))
9261
9262 (defun gnus-summary-top-thread ()
9263   "Go to the top of the thread."
9264   (interactive)
9265   (while (gnus-summary-go-up-thread))
9266   (gnus-summary-article-number))
9267
9268 (defun gnus-summary-kill-thread (&optional unmark)
9269   "Mark articles under current thread as read.
9270 If the prefix argument is positive, remove any kinds of marks.
9271 If the prefix argument is negative, tick articles instead."
9272   (interactive "P")
9273   (when unmark
9274     (setq unmark (prefix-numeric-value unmark)))
9275   (let ((articles (gnus-summary-articles-in-thread)))
9276     (save-excursion
9277       ;; Expand the thread.
9278       (gnus-summary-show-thread)
9279       ;; Mark all the articles.
9280       (while articles
9281         (gnus-summary-goto-subject (car articles))
9282         (cond ((null unmark)
9283                (gnus-summary-mark-article-as-read gnus-killed-mark))
9284               ((> unmark 0)
9285                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9286               (t
9287                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9288         (setq articles (cdr articles))))
9289     ;; Hide killed subtrees.
9290     (and (null unmark)
9291          gnus-thread-hide-killed
9292          (gnus-summary-hide-thread))
9293     ;; If marked as read, go to next unread subject.
9294     (when (null unmark)
9295       ;; Go to next unread subject.
9296       (gnus-summary-next-subject 1 t)))
9297   (gnus-set-mode-line 'summary))
9298
9299 ;; Summary sorting commands
9300
9301 (defun gnus-summary-sort-by-number (&optional reverse)
9302   "Sort the summary buffer by article number.
9303 Argument REVERSE means reverse order."
9304   (interactive "P")
9305   (gnus-summary-sort 'number reverse))
9306
9307 (defun gnus-summary-sort-by-author (&optional reverse)
9308   "Sort the summary buffer by author name alphabetically.
9309 If `case-fold-search' is non-nil, case of letters is ignored.
9310 Argument REVERSE means reverse order."
9311   (interactive "P")
9312   (gnus-summary-sort 'author reverse))
9313
9314 (defun gnus-summary-sort-by-subject (&optional reverse)
9315   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9316 If `case-fold-search' is non-nil, case of letters is ignored.
9317 Argument REVERSE means reverse order."
9318   (interactive "P")
9319   (gnus-summary-sort 'subject reverse))
9320
9321 (defun gnus-summary-sort-by-date (&optional reverse)
9322   "Sort the summary buffer by date.
9323 Argument REVERSE means reverse order."
9324   (interactive "P")
9325   (gnus-summary-sort 'date reverse))
9326
9327 (defun gnus-summary-sort-by-score (&optional reverse)
9328   "Sort the summary buffer by score.
9329 Argument REVERSE means reverse order."
9330   (interactive "P")
9331   (gnus-summary-sort 'score reverse))
9332
9333 (defun gnus-summary-sort-by-lines (&optional reverse)
9334   "Sort the summary buffer by the number of lines.
9335 Argument REVERSE means reverse order."
9336   (interactive "P")
9337   (gnus-summary-sort 'lines reverse))
9338
9339 (defun gnus-summary-sort-by-chars (&optional reverse)
9340   "Sort the summary buffer by article length.
9341 Argument REVERSE means reverse order."
9342   (interactive "P")
9343   (gnus-summary-sort 'chars reverse))
9344
9345 (defun gnus-summary-sort (predicate reverse)
9346   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9347   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9348          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9349          (gnus-thread-sort-functions
9350           (if (not reverse)
9351               thread
9352             `(lambda (t1 t2)
9353                (,thread t2 t1))))
9354          (gnus-sort-gathered-threads-function
9355           gnus-thread-sort-functions)
9356          (gnus-article-sort-functions
9357           (if (not reverse)
9358               article
9359             `(lambda (t1 t2)
9360                (,article t2 t1))))
9361          (buffer-read-only)
9362          (gnus-summary-prepare-hook nil))
9363     ;; We do the sorting by regenerating the threads.
9364     (gnus-summary-prepare)
9365     ;; Hide subthreads if needed.
9366     (when (and gnus-show-threads gnus-thread-hide-subtree)
9367       (gnus-summary-hide-all-threads))))
9368
9369 ;; Summary saving commands.
9370
9371 (defun gnus-summary-save-article (&optional n not-saved)
9372   "Save the current article using the default saver function.
9373 If N is a positive number, save the N next articles.
9374 If N is a negative number, save the N previous articles.
9375 If N is nil and any articles have been marked with the process mark,
9376 save those articles instead.
9377 The variable `gnus-default-article-saver' specifies the saver function."
9378   (interactive "P")
9379   (let* ((articles (gnus-summary-work-articles n))
9380          (save-buffer (save-excursion
9381                         (nnheader-set-temp-buffer " *Gnus Save*")))
9382          (num (length articles))
9383          header file)
9384     (dolist (article articles)
9385       (setq header (gnus-summary-article-header article))
9386       (if (not (vectorp header))
9387           ;; This is a pseudo-article.
9388           (if (assq 'name header)
9389               (gnus-copy-file (cdr (assq 'name header)))
9390             (gnus-message 1 "Article %d is unsaveable" article))
9391         ;; This is a real article.
9392         (save-window-excursion
9393           (gnus-summary-select-article t nil nil article))
9394         (save-excursion
9395           (set-buffer save-buffer)
9396           (erase-buffer)
9397           (insert-buffer-substring gnus-original-article-buffer))
9398         (setq file (gnus-article-save save-buffer file num))
9399         (gnus-summary-remove-process-mark article)
9400         (unless not-saved
9401           (gnus-summary-set-saved-mark article))))
9402     (gnus-kill-buffer save-buffer)
9403     (gnus-summary-position-point)
9404     (gnus-set-mode-line 'summary)
9405     n))
9406
9407 (defun gnus-summary-pipe-output (&optional arg)
9408   "Pipe the current article to a subprocess.
9409 If N is a positive number, pipe the N next articles.
9410 If N is a negative number, pipe the N previous articles.
9411 If N is nil and any articles have been marked with the process mark,
9412 pipe those articles instead."
9413   (interactive "P")
9414   (require 'gnus-art)
9415   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9416     (gnus-summary-save-article arg t))
9417   (gnus-configure-windows 'pipe))
9418
9419 (defun gnus-summary-save-article-mail (&optional arg)
9420   "Append the current article to an mail file.
9421 If N is a positive number, save the N next articles.
9422 If N is a negative number, save the N previous articles.
9423 If N is nil and any articles have been marked with the process mark,
9424 save those articles instead."
9425   (interactive "P")
9426   (require 'gnus-art)
9427   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9428     (gnus-summary-save-article arg)))
9429
9430 (defun gnus-summary-save-article-rmail (&optional arg)
9431   "Append the current article to an rmail file.
9432 If N is a positive number, save the N next articles.
9433 If N is a negative number, save the N previous articles.
9434 If N is nil and any articles have been marked with the process mark,
9435 save those articles instead."
9436   (interactive "P")
9437   (require 'gnus-art)
9438   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9439     (gnus-summary-save-article arg)))
9440
9441 (defun gnus-summary-save-article-file (&optional arg)
9442   "Append the current article to a file.
9443 If N is a positive number, save the N next articles.
9444 If N is a negative number, save the N previous articles.
9445 If N is nil and any articles have been marked with the process mark,
9446 save those articles instead."
9447   (interactive "P")
9448   (require 'gnus-art)
9449   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9450     (gnus-summary-save-article arg)))
9451
9452 (defun gnus-summary-write-article-file (&optional arg)
9453   "Write the current article to a file, deleting the previous file.
9454 If N is a positive number, save the N next articles.
9455 If N is a negative number, save the N previous articles.
9456 If N is nil and any articles have been marked with the process mark,
9457 save those articles instead."
9458   (interactive "P")
9459   (require 'gnus-art)
9460   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9461     (gnus-summary-save-article arg)))
9462
9463 (defun gnus-summary-save-article-body-file (&optional arg)
9464   "Append the current article body to a file.
9465 If N is a positive number, save the N next articles.
9466 If N is a negative number, save the N previous articles.
9467 If N is nil and any articles have been marked with the process mark,
9468 save those articles instead."
9469   (interactive "P")
9470   (require 'gnus-art)
9471   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9472     (gnus-summary-save-article arg)))
9473
9474 (defun gnus-summary-pipe-message (program)
9475   "Pipe the current article through PROGRAM."
9476   (interactive "sProgram: ")
9477   (gnus-summary-select-article)
9478   (let ((mail-header-separator ""))
9479     (gnus-eval-in-buffer-window gnus-article-buffer
9480       (save-restriction
9481         (widen)
9482         (let ((start (window-start))
9483               buffer-read-only)
9484           (message-pipe-buffer-body program)
9485           (set-window-start (get-buffer-window (current-buffer)) start))))))
9486
9487 (defun gnus-get-split-value (methods)
9488   "Return a value based on the split METHODS."
9489   (let (split-name method result match)
9490     (when methods
9491       (save-excursion
9492         (set-buffer gnus-original-article-buffer)
9493         (save-restriction
9494           (nnheader-narrow-to-headers)
9495           (while (and methods (not split-name))
9496             (goto-char (point-min))
9497             (setq method (pop methods))
9498             (setq match (car method))
9499             (when (cond
9500                    ((stringp match)
9501                     ;; Regular expression.
9502                     (ignore-errors
9503                       (re-search-forward match nil t)))
9504                    ((gnus-functionp match)
9505                     ;; Function.
9506                     (save-restriction
9507                       (widen)
9508                       (setq result (funcall match gnus-newsgroup-name))))
9509                    ((consp match)
9510                     ;; Form.
9511                     (save-restriction
9512                       (widen)
9513                       (setq result (eval match)))))
9514               (setq split-name (cdr method))
9515               (cond ((stringp result)
9516                      (push (expand-file-name
9517                             result gnus-article-save-directory)
9518                            split-name))
9519                     ((consp result)
9520                      (setq split-name (append result split-name)))))))))
9521     (nreverse split-name)))
9522
9523 (defun gnus-valid-move-group-p (group)
9524   (and (boundp group)
9525        (symbol-name group)
9526        (symbol-value group)
9527        (gnus-get-function (gnus-find-method-for-group
9528                            (symbol-name group)) 'request-accept-article t)))
9529
9530 (defun gnus-read-move-group-name (prompt default articles prefix)
9531   "Read a group name."
9532   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
9533          (minibuffer-confirm-incomplete nil) ; XEmacs
9534          (prom
9535           (format "%s %s to:"
9536                   prompt
9537                   (if (> (length articles) 1)
9538                       (format "these %d articles" (length articles))
9539                     "this article")))
9540          (to-newsgroup
9541           (cond
9542            ((null split-name)
9543             (gnus-completing-read default prom
9544                                   gnus-active-hashtb
9545                                   'gnus-valid-move-group-p
9546                                   nil prefix
9547                                   'gnus-group-history))
9548            ((= 1 (length split-name))
9549             (gnus-completing-read (car split-name) prom
9550                                   gnus-active-hashtb
9551                                   'gnus-valid-move-group-p
9552                                   nil nil
9553                                   'gnus-group-history))
9554            (t
9555             (gnus-completing-read nil prom
9556                                   (mapcar (lambda (el) (list el))
9557                                           (nreverse split-name))
9558                                   nil nil nil
9559                                   'gnus-group-history))))
9560          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
9561     (when to-newsgroup
9562       (if (or (string= to-newsgroup "")
9563               (string= to-newsgroup prefix))
9564           (setq to-newsgroup default))
9565       (unless to-newsgroup
9566         (error "No group name entered"))
9567       (or (gnus-active to-newsgroup)
9568           (gnus-activate-group to-newsgroup nil nil to-method)
9569           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
9570                                      to-newsgroup))
9571               (or (and (gnus-request-create-group to-newsgroup to-method)
9572                        (gnus-activate-group
9573                         to-newsgroup nil nil to-method)
9574                        (gnus-subscribe-group to-newsgroup))
9575                   (error "Couldn't create group %s" to-newsgroup)))
9576           (error "No such group: %s" to-newsgroup)))
9577     to-newsgroup))
9578
9579 (defun gnus-summary-save-parts (type dir n &optional reverse)
9580   "Save parts matching TYPE to DIR.
9581 If REVERSE, save parts that do not match TYPE."
9582   (interactive
9583    (list (read-string "Save parts of type: "
9584                       (or (car gnus-summary-save-parts-type-history)
9585                           gnus-summary-save-parts-default-mime)
9586                       'gnus-summary-save-parts-type-history)
9587          (setq gnus-summary-save-parts-last-directory
9588                (read-file-name "Save to directory: "
9589                                gnus-summary-save-parts-last-directory
9590                                nil t))
9591          current-prefix-arg))
9592   (gnus-summary-iterate n
9593     (let ((gnus-display-mime-function nil)
9594           (gnus-inhibit-treatment t))
9595       (gnus-summary-select-article))
9596     (save-excursion
9597       (set-buffer gnus-article-buffer)
9598       (let ((handles (or gnus-article-mime-handles
9599                          (mm-dissect-buffer) (mm-uu-dissect))))
9600         (when handles
9601           (gnus-summary-save-parts-1 type dir handles reverse)
9602           (unless gnus-article-mime-handles ;; Don't destroy this case.
9603             (mm-destroy-parts handles)))))))
9604
9605 (defun gnus-summary-save-parts-1 (type dir handle reverse)
9606   (if (stringp (car handle))
9607       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
9608               (cdr handle))
9609     (when (if reverse
9610               (not (string-match type (mm-handle-media-type handle)))
9611             (string-match type (mm-handle-media-type handle)))
9612       (let ((file (expand-file-name
9613                    (file-name-nondirectory
9614                     (or
9615                      (mail-content-type-get
9616                       (mm-handle-disposition handle) 'filename)
9617                      (concat gnus-newsgroup-name
9618                              "." (number-to-string
9619                                   (cdr gnus-article-current)))))
9620                    dir)))
9621         (unless (file-exists-p file)
9622           (mm-save-part-to-file handle file))))))
9623
9624 ;; Summary extract commands
9625
9626 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
9627   (let ((buffer-read-only nil)
9628         (article (gnus-summary-article-number))
9629         after-article b e)
9630     (unless (gnus-summary-goto-subject article)
9631       (error "No such article: %d" article))
9632     (gnus-summary-position-point)
9633     ;; If all commands are to be bunched up on one line, we collect
9634     ;; them here.
9635     (unless gnus-view-pseudos-separately
9636       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
9637             files action)
9638         (while ps
9639           (setq action (cdr (assq 'action (car ps))))
9640           (setq files (list (cdr (assq 'name (car ps)))))
9641           (while (and ps (cdr ps)
9642                       (string= (or action "1")
9643                                (or (cdr (assq 'action (cadr ps))) "2")))
9644             (push (cdr (assq 'name (cadr ps))) files)
9645             (setcdr ps (cddr ps)))
9646           (when files
9647             (when (not (string-match "%s" action))
9648               (push " " files))
9649             (push " " files)
9650             (when (assq 'execute (car ps))
9651               (setcdr (assq 'execute (car ps))
9652                       (funcall (if (string-match "%s" action)
9653                                    'format 'concat)
9654                                action
9655                                (mapconcat
9656                                 (lambda (f)
9657                                   (if (equal f " ")
9658                                       f
9659                                     (mm-quote-arg f)))
9660                                 files " ")))))
9661           (setq ps (cdr ps)))))
9662     (if (and gnus-view-pseudos (not not-view))
9663         (while pslist
9664           (when (assq 'execute (car pslist))
9665             (gnus-execute-command (cdr (assq 'execute (car pslist)))
9666                                   (eq gnus-view-pseudos 'not-confirm)))
9667           (setq pslist (cdr pslist)))
9668       (save-excursion
9669         (while pslist
9670           (setq after-article (or (cdr (assq 'article (car pslist)))
9671                                   (gnus-summary-article-number)))
9672           (gnus-summary-goto-subject after-article)
9673           (forward-line 1)
9674           (setq b (point))
9675           (insert "    " (file-name-nondirectory
9676                           (cdr (assq 'name (car pslist))))
9677                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
9678           (setq e (point))
9679           (forward-line -1)             ; back to `b'
9680           (gnus-add-text-properties
9681            b (1- e) (list 'gnus-number gnus-reffed-article-number
9682                           gnus-mouse-face-prop gnus-mouse-face))
9683           (gnus-data-enter
9684            after-article gnus-reffed-article-number
9685            gnus-unread-mark b (car pslist) 0 (- e b))
9686           (push gnus-reffed-article-number gnus-newsgroup-unreads)
9687           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
9688           (setq pslist (cdr pslist)))))))
9689
9690 (defun gnus-pseudos< (p1 p2)
9691   (let ((c1 (cdr (assq 'action p1)))
9692         (c2 (cdr (assq 'action p2))))
9693     (and c1 c2 (string< c1 c2))))
9694
9695 (defun gnus-request-pseudo-article (props)
9696   (cond ((assq 'execute props)
9697          (gnus-execute-command (cdr (assq 'execute props)))))
9698   (let ((gnus-current-article (gnus-summary-article-number)))
9699     (gnus-run-hooks 'gnus-mark-article-hook)))
9700
9701 (defun gnus-execute-command (command &optional automatic)
9702   (save-excursion
9703     (gnus-article-setup-buffer)
9704     (set-buffer gnus-article-buffer)
9705     (setq buffer-read-only nil)
9706     (let ((command (if automatic command
9707                      (read-string "Command: " (cons command 0)))))
9708       (erase-buffer)
9709       (insert "$ " command "\n\n")
9710       (if gnus-view-pseudo-asynchronously
9711           (start-process "gnus-execute" (current-buffer) shell-file-name
9712                          shell-command-switch command)
9713         (call-process shell-file-name nil t nil
9714                       shell-command-switch command)))))
9715
9716 ;; Summary kill commands.
9717
9718 (defun gnus-summary-edit-global-kill (article)
9719   "Edit the \"global\" kill file."
9720   (interactive (list (gnus-summary-article-number)))
9721   (gnus-group-edit-global-kill article))
9722
9723 (defun gnus-summary-edit-local-kill ()
9724   "Edit a local kill file applied to the current newsgroup."
9725   (interactive)
9726   (setq gnus-current-headers (gnus-summary-article-header))
9727   (gnus-group-edit-local-kill
9728    (gnus-summary-article-number) gnus-newsgroup-name))
9729
9730 ;;; Header reading.
9731
9732 (defun gnus-read-header (id &optional header)
9733   "Read the headers of article ID and enter them into the Gnus system."
9734   (let ((group gnus-newsgroup-name)
9735         (gnus-override-method
9736          (or
9737           gnus-override-method
9738           (and (gnus-news-group-p gnus-newsgroup-name)
9739                (car (gnus-refer-article-methods)))))
9740         where)
9741     ;; First we check to see whether the header in question is already
9742     ;; fetched.
9743     (if (stringp id)
9744         ;; This is a Message-ID.
9745         (setq header (or header (gnus-id-to-header id)))
9746       ;; This is an article number.
9747       (setq header (or header (gnus-summary-article-header id))))
9748     (if (and header
9749              (not (gnus-summary-article-sparse-p (mail-header-number header))))
9750         ;; We have found the header.
9751         header
9752       ;; If this is a sparse article, we have to nix out its
9753       ;; previous entry in the thread hashtb.
9754       (when (and header
9755                  (gnus-summary-article-sparse-p (mail-header-number header)))
9756         (let* ((parent (gnus-parent-id (mail-header-references header)))
9757                (thread (and parent (gnus-id-to-thread parent))))
9758           (when thread
9759             (delq (assq header thread) thread))))
9760       ;; We have to really fetch the header to this article.
9761       (save-excursion
9762         (set-buffer nntp-server-buffer)
9763         (when (setq where (gnus-request-head id group))
9764           (nnheader-fold-continuation-lines)
9765           (goto-char (point-max))
9766           (insert ".\n")
9767           (goto-char (point-min))
9768           (insert "211 ")
9769           (princ (cond
9770                   ((numberp id) id)
9771                   ((cdr where) (cdr where))
9772                   (header (mail-header-number header))
9773                   (t gnus-reffed-article-number))
9774                  (current-buffer))
9775           (insert " Article retrieved.\n"))
9776         (if (or (not where)
9777                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
9778             ()                          ; Malformed head.
9779           (unless (gnus-summary-article-sparse-p (mail-header-number header))
9780             (when (and (stringp id)
9781                        (not (string= (gnus-group-real-name group)
9782                                      (car where))))
9783               ;; If we fetched by Message-ID and the article came
9784               ;; from a different group, we fudge some bogus article
9785               ;; numbers for this article.
9786               (mail-header-set-number header gnus-reffed-article-number))
9787             (save-excursion
9788               (set-buffer gnus-summary-buffer)
9789               (decf gnus-reffed-article-number)
9790               (gnus-remove-header (mail-header-number header))
9791               (push header gnus-newsgroup-headers)
9792               (setq gnus-current-headers header)
9793               (push (mail-header-number header) gnus-newsgroup-limit)))
9794           header)))))
9795
9796 (defun gnus-remove-header (number)
9797   "Remove header NUMBER from `gnus-newsgroup-headers'."
9798   (if (and gnus-newsgroup-headers
9799            (= number (mail-header-number (car gnus-newsgroup-headers))))
9800       (pop gnus-newsgroup-headers)
9801     (let ((headers gnus-newsgroup-headers))
9802       (while (and (cdr headers)
9803                   (not (= number (mail-header-number (cadr headers)))))
9804         (pop headers))
9805       (when (cdr headers)
9806         (setcdr headers (cddr headers))))))
9807
9808 ;;;
9809 ;;; summary highlights
9810 ;;;
9811
9812 (defun gnus-highlight-selected-summary ()
9813   "Highlight selected article in summary buffer."
9814   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
9815   (when gnus-summary-selected-face
9816     (save-excursion
9817       (let* ((beg (progn (beginning-of-line) (point)))
9818              (end (progn (end-of-line) (point)))
9819              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
9820              (from (if (get-text-property beg gnus-mouse-face-prop)
9821                        beg
9822                      (or (next-single-property-change
9823                           beg gnus-mouse-face-prop nil end)
9824                          beg)))
9825              (to
9826               (if (= from end)
9827                   (- from 2)
9828                 (or (next-single-property-change
9829                      from gnus-mouse-face-prop nil end)
9830                     end))))
9831         ;; If no mouse-face prop on line we will have to = from = end,
9832         ;; so we highlight the entire line instead.
9833         (when (= (+ to 2) from)
9834           (setq from beg)
9835           (setq to end))
9836         (if gnus-newsgroup-selected-overlay
9837             ;; Move old overlay.
9838             (gnus-move-overlay
9839              gnus-newsgroup-selected-overlay from to (current-buffer))
9840           ;; Create new overlay.
9841           (gnus-overlay-put
9842            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
9843            'face gnus-summary-selected-face))))))
9844
9845 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
9846 (defun gnus-summary-highlight-line ()
9847   "Highlight current line according to `gnus-summary-highlight'."
9848   (let* ((list gnus-summary-highlight)
9849          (p (point))
9850          (end (progn (end-of-line) (point)))
9851          ;; now find out where the line starts and leave point there.
9852          (beg (progn (beginning-of-line) (point)))
9853          (article (gnus-summary-article-number))
9854          (score (or (cdr (assq (or article gnus-current-article)
9855                                gnus-newsgroup-scored))
9856                     gnus-summary-default-score 0))
9857          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
9858          (inhibit-read-only t))
9859     ;; Eval the cars of the lists until we find a match.
9860     (let ((default gnus-summary-default-score))
9861       (while (and list
9862                   (not (eval (caar list))))
9863         (setq list (cdr list))))
9864     (let ((face (cdar list)))
9865       (unless (eq face (get-text-property beg 'face))
9866         (gnus-put-text-property-excluding-characters-with-faces
9867          beg end 'face
9868          (setq face (if (boundp face) (symbol-value face) face)))
9869         (when gnus-summary-highlight-line-function
9870           (funcall gnus-summary-highlight-line-function article face))))
9871     (goto-char p)))
9872
9873 (defun gnus-update-read-articles (group unread &optional compute)
9874   "Update the list of read articles in GROUP."
9875   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
9876          (entry (gnus-gethash group gnus-newsrc-hashtb))
9877          (info (nth 2 entry))
9878          (prev 1)
9879          (unread (sort (copy-sequence unread) '<))
9880          read)
9881     (if (or (not info) (not active))
9882         ;; There is no info on this group if it was, in fact,
9883         ;; killed.  Gnus stores no information on killed groups, so
9884         ;; there's nothing to be done.
9885         ;; One could store the information somewhere temporarily,
9886         ;; perhaps...  Hmmm...
9887         ()
9888       ;; Remove any negative articles numbers.
9889       (while (and unread (< (car unread) 0))
9890         (setq unread (cdr unread)))
9891       ;; Remove any expired article numbers
9892       (while (and unread (< (car unread) (car active)))
9893         (setq unread (cdr unread)))
9894       ;; Compute the ranges of read articles by looking at the list of
9895       ;; unread articles.
9896       (while unread
9897         (when (/= (car unread) prev)
9898           (push (if (= prev (1- (car unread))) prev
9899                   (cons prev (1- (car unread))))
9900                 read))
9901         (setq prev (1+ (car unread)))
9902         (setq unread (cdr unread)))
9903       (when (<= prev (cdr active))
9904         (push (cons prev (cdr active)) read))
9905       (setq read (if (> (length read) 1) (nreverse read) read))
9906       (if compute
9907           read
9908         (save-excursion
9909           (let (setmarkundo)
9910             ;; Propagate the read marks to the backend.
9911             (when (gnus-check-backend-function 'request-set-mark group)
9912               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
9913                     (add (gnus-remove-from-range read (gnus-info-read info))))
9914                 (when (or add del)
9915                   (unless (gnus-check-group group)
9916                     (error "Can't open server for %s" group))
9917                   (gnus-request-set-mark
9918                    group (delq nil (list (if add (list add 'add '(read)))
9919                                          (if del (list del 'del '(read))))))
9920                   (setq setmarkundo
9921                         `(gnus-request-set-mark
9922                           ,group
9923                           ',(delq nil (list
9924                                        (if del (list del 'add '(read)))
9925                                        (if add (list add 'del '(read))))))))))
9926             (set-buffer gnus-group-buffer)
9927             (gnus-undo-register
9928               `(progn
9929                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
9930                  (gnus-info-set-read ',info ',(gnus-info-read info))
9931                  (gnus-get-unread-articles-in-group ',info
9932                                                     (gnus-active ,group))
9933                  (gnus-group-update-group ,group t)
9934                  ,setmarkundo))))
9935         ;; Enter this list into the group info.
9936         (gnus-info-set-read info read)
9937         ;; Set the number of unread articles in gnus-newsrc-hashtb.
9938         (gnus-get-unread-articles-in-group info (gnus-active group))
9939         t))))
9940
9941 (defun gnus-offer-save-summaries ()
9942   "Offer to save all active summary buffers."
9943   (save-excursion
9944     (let ((buflist (buffer-list))
9945           buffers bufname)
9946       ;; Go through all buffers and find all summaries.
9947       (while buflist
9948         (and (setq bufname (buffer-name (car buflist)))
9949              (string-match "Summary" bufname)
9950              (save-excursion
9951                (set-buffer bufname)
9952                ;; We check that this is, indeed, a summary buffer.
9953                (and (eq major-mode 'gnus-summary-mode)
9954                     ;; Also make sure this isn't bogus.
9955                     gnus-newsgroup-prepared
9956                     ;; Also make sure that this isn't a dead summary buffer.
9957                     (not gnus-dead-summary-mode)))
9958              (push bufname buffers))
9959         (setq buflist (cdr buflist)))
9960       ;; Go through all these summary buffers and offer to save them.
9961       (when buffers
9962         (map-y-or-n-p
9963          "Update summary buffer %s? "
9964          (lambda (buf)
9965            (switch-to-buffer buf)
9966            (gnus-summary-exit))
9967          buffers)))))
9968
9969 (defun gnus-summary-setup-default-charset ()
9970   "Setup newsgroup default charset."
9971   (if (equal gnus-newsgroup-name "nndraft:drafts")
9972       (setq gnus-newsgroup-charset nil)
9973     (let* ((ignored-charsets
9974             (or gnus-newsgroup-ephemeral-ignored-charsets
9975                 (append
9976                  (and gnus-newsgroup-name
9977                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
9978                  gnus-newsgroup-ignored-charsets))))
9979       (setq gnus-newsgroup-charset
9980             (or gnus-newsgroup-ephemeral-charset
9981                 (and gnus-newsgroup-name
9982                      (gnus-parameter-charset gnus-newsgroup-name))
9983                 gnus-default-charset))
9984       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
9985            ignored-charsets))))
9986
9987 ;;;
9988 ;;; Mime Commands
9989 ;;;
9990
9991 (defun gnus-summary-display-buttonized (&optional show-all-parts)
9992   "Display the current article buffer fully MIME-buttonized.
9993 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
9994 treated as multipart/mixed."
9995   (interactive "P")
9996   (require 'gnus-art)
9997   (let ((gnus-unbuttonized-mime-types nil)
9998         (gnus-mime-display-multipart-as-mixed show-all-parts))
9999     (gnus-summary-show-article)))
10000
10001 (defun gnus-summary-repair-multipart (article)
10002   "Add a Content-Type header to a multipart article without one."
10003   (interactive (list (gnus-summary-article-number)))
10004   (gnus-with-article article
10005     (message-narrow-to-head)
10006     (message-remove-header "Mime-Version")
10007     (goto-char (point-max))
10008     (insert "Mime-Version: 1.0\n")
10009     (widen)
10010     (when (search-forward "\n--" nil t)
10011       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10012         (message-narrow-to-head)
10013         (message-remove-header "Content-Type")
10014         (goto-char (point-max))
10015         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10016                         separator))
10017         (widen))))
10018   (let (gnus-mark-article-hook)
10019     (gnus-summary-select-article t t nil article)))
10020
10021 (defun gnus-summary-toggle-display-buttonized ()
10022   "Toggle the buttonizing of the article buffer."
10023   (interactive)
10024   (require 'gnus-art)
10025   (if (setq gnus-inhibit-mime-unbuttonizing
10026             (not gnus-inhibit-mime-unbuttonizing))
10027       (let ((gnus-unbuttonized-mime-types nil))
10028         (gnus-summary-show-article))
10029     (gnus-summary-show-article)))
10030
10031 ;;;
10032 ;;; Generic summary marking commands
10033 ;;;
10034
10035 (defvar gnus-summary-marking-alist
10036   '((read gnus-del-mark "d")
10037     (unread gnus-unread-mark "u")
10038     (ticked gnus-ticked-mark "!")
10039     (dormant gnus-dormant-mark "?")
10040     (expirable gnus-expirable-mark "e"))
10041   "An alist of names/marks/keystrokes.")
10042
10043 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10044 (defvar gnus-summary-mark-map)
10045
10046 (defun gnus-summary-make-all-marking-commands ()
10047   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10048   (dolist (elem gnus-summary-marking-alist)
10049     (apply 'gnus-summary-make-marking-command elem)))
10050
10051 (defun gnus-summary-make-marking-command (name mark keystroke)
10052   (let ((map (make-sparse-keymap)))
10053     (define-key gnus-summary-generic-mark-map keystroke map)
10054     (dolist (lway `((next "next" next nil "n")
10055                     (next-unread "next unread" next t "N")
10056                     (prev "previous" prev nil "p")
10057                     (prev-unread "previous unread" prev t "P")
10058                     (nomove "" nil nil ,keystroke)))
10059       (let ((func (gnus-summary-make-marking-command-1
10060                    mark (car lway) lway name)))
10061         (setq func (eval func))
10062         (define-key map (nth 4 lway) func)))))
10063
10064 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10065   `(defun ,(intern
10066             (format "gnus-summary-put-mark-as-%s%s"
10067                     name (if (eq way 'nomove)
10068                              ""
10069                            (concat "-" (symbol-name way)))))
10070      (n)
10071      ,(format
10072        "Mark the current article as %s%s.
10073 If N, the prefix, then repeat N times.
10074 If N is negative, move in reverse order.
10075 The difference between N and the actual number of articles marked is
10076 returned."
10077        name (cadr lway))
10078      (interactive "p")
10079      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10080
10081 (defun gnus-summary-generic-mark (n mark move unread)
10082   "Mark N articles with MARK."
10083   (unless (eq major-mode 'gnus-summary-mode)
10084     (error "This command can only be used in the summary buffer"))
10085   (gnus-summary-show-thread)
10086   (let ((nummove
10087          (cond
10088           ((eq move 'next) 1)
10089           ((eq move 'prev) -1)
10090           (t 0))))
10091     (if (zerop nummove)
10092         (setq n 1)
10093       (when (< n 0)
10094         (setq n (abs n)
10095               nummove (* -1 nummove))))
10096     (while (and (> n 0)
10097                 (gnus-summary-mark-article nil mark)
10098                 (zerop (gnus-summary-next-subject nummove unread t)))
10099       (setq n (1- n)))
10100     (when (/= 0 n)
10101       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10102     (gnus-summary-recenter)
10103     (gnus-summary-position-point)
10104     (gnus-set-mode-line 'summary)
10105     n))
10106
10107 (defun gnus-summary-insert-articles (articles)
10108   (when (setq articles
10109               (gnus-set-difference articles
10110                                    (mapcar (lambda (h) (mail-header-number h))
10111                                            gnus-newsgroup-headers)))
10112     (setq gnus-newsgroup-headers 
10113           (merge 'list
10114                  gnus-newsgroup-headers
10115                  (gnus-fetch-headers articles)
10116                  'gnus-article-sort-by-number))
10117     ;; Suppress duplicates?
10118     (when gnus-suppress-duplicates
10119       (gnus-dup-suppress-articles))
10120     
10121     ;; We might want to build some more threads first.
10122     (when (and gnus-fetch-old-headers
10123                (eq gnus-headers-retrieved-by 'nov))
10124       (if (eq gnus-fetch-old-headers 'invisible)
10125         (gnus-build-all-threads)
10126         (gnus-build-old-threads)))
10127     ;; Let the Gnus agent mark articles as read.
10128     (when gnus-agent
10129       (gnus-agent-get-undownloaded-list))
10130     ;; Remove list identifiers from subject
10131     (when gnus-list-identifiers
10132       (gnus-summary-remove-list-identifiers))
10133     ;; First and last article in this newsgroup.
10134     (when gnus-newsgroup-headers
10135       (setq gnus-newsgroup-begin
10136             (mail-header-number (car gnus-newsgroup-headers))
10137             gnus-newsgroup-end
10138             (mail-header-number
10139              (gnus-last-element gnus-newsgroup-headers))))
10140     (when gnus-use-scoring
10141       (gnus-possibly-score-headers))))
10142
10143 (defun gnus-summary-insert-old-articles (&optional all)
10144   "Insert all old articles in this group.
10145 If ALL is non-nil, already read articles become readable.
10146 If ALL is a number, fetch this number of articles."
10147   (interactive "P")
10148   (prog1
10149       (let ((old (mapcar 'car gnus-newsgroup-data))
10150             (i (car gnus-newsgroup-active))
10151             older len)
10152         (while (<= i (cdr gnus-newsgroup-active))
10153           (or (memq i old) (push i older))
10154           (incf i))
10155         (setq len (length older))
10156         (cond 
10157          ((null older) nil)
10158          ((numberp all) 
10159           (if (< all len)
10160               (setq older (subseq older 0 all))))
10161          (all nil)
10162          (t
10163           (if (and (numberp gnus-large-newsgroup)
10164                    (> len gnus-large-newsgroup))
10165               (let ((input
10166                      (read-string
10167                       (format
10168                        "How many articles from %s (default %d): "
10169                        (gnus-limit-string 
10170                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10171                        len))))
10172                 (unless (string-match "^[ \t]*$" input) 
10173                   (setq all (string-to-number input))
10174                   (if (< all len)
10175                       (setq older (subseq older 0 all))))))))
10176         (if (not older)
10177             (message "No old news.")
10178           (gnus-summary-insert-articles older)
10179           (gnus-summary-limit (gnus-union older old))))
10180     (gnus-summary-position-point)))
10181
10182 (defun gnus-summary-insert-new-articles ()
10183   "Insert all new articles in this group."
10184   (interactive)
10185   (prog1
10186       (let ((old (mapcar 'car gnus-newsgroup-data))
10187             (old-active gnus-newsgroup-active)
10188             (nnmail-fetched-sources (list t))
10189             i new)
10190         (setq gnus-newsgroup-active 
10191               (gnus-activate-group gnus-newsgroup-name 'scan))
10192         (setq i (1+ (cdr old-active)))
10193         (while (<= i (cdr gnus-newsgroup-active))
10194           (push i new)
10195           (incf i))
10196         (if (not new)
10197             (message "No gnus is bad news.")
10198           (gnus-summary-insert-articles new)
10199           (setq gnus-newsgroup-unreads
10200                 (append gnus-newsgroup-unreads new))
10201           (gnus-summary-limit (gnus-union old new))))
10202     (gnus-summary-position-point)))
10203
10204 (gnus-summary-make-all-marking-commands)
10205
10206 (gnus-ems-redefine)
10207
10208 (provide 'gnus-sum)
10209
10210 (run-hooks 'gnus-sum-load-hook)
10211
10212 ;;; gnus-sum.el ends here