Revision: miles@gnu.org--gnu-2004/gnus--devo--0--patch-200
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is t, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const :tag "on" t)
79                  (const some)
80                  (const invisible)
81                  number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-refer-thread-limit 200
85   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
86 If t, fetch all the available old headers."
87   :group 'gnus-thread
88   :type '(choice number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-summary-make-false-root 'adopt
92   "*nil means that Gnus won't gather loose threads.
93 If the root of a thread has expired or been read in a previous
94 session, the information necessary to build a complete thread has been
95 lost.  Instead of having many small sub-threads from this original thread
96 scattered all over the summary buffer, Gnus can gather them.
97
98 If non-nil, Gnus will try to gather all loose sub-threads from an
99 original thread into one large thread.
100
101 If this variable is non-nil, it should be one of `none', `adopt',
102 `dummy' or `empty'.
103
104 If this variable is `none', Gnus will not make a false root, but just
105 present the sub-threads after another.
106 If this variable is `dummy', Gnus will create a dummy root that will
107 have all the sub-threads as children.
108 If this variable is `adopt', Gnus will make one of the \"children\"
109 the parent and mark all the step-children as such.
110 If this variable is `empty', the \"children\" are printed with empty
111 subject fields.  (Or rather, they will be printed with a string
112 given by the `gnus-summary-same-subject' variable.)"
113   :group 'gnus-thread
114   :type '(choice (const :tag "off" nil)
115                  (const none)
116                  (const dummy)
117                  (const adopt)
118                  (const empty)))
119
120 (defcustom gnus-summary-make-false-root-always nil
121   "Always make a false dummy root."
122   :version "21.4"
123   :group 'gnus-thread
124   :type 'boolean)
125
126 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
127   "*A regexp to match subjects to be excluded from loose thread gathering.
128 As loose thread gathering is done on subjects only, that means that
129 there can be many false gatherings performed.  By rooting out certain
130 common subjects, gathering might become saner."
131   :group 'gnus-thread
132   :type 'regexp)
133
134 (defcustom gnus-summary-gather-subject-limit nil
135   "*Maximum length of subject comparisons when gathering loose threads.
136 Use nil to compare full subjects.  Setting this variable to a low
137 number will help gather threads that have been corrupted by
138 newsreaders chopping off subject lines, but it might also mean that
139 unrelated articles that have subject that happen to begin with the
140 same few characters will be incorrectly gathered.
141
142 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
143 comparing subjects."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  (const fuzzy)
147                  (sexp :menu-tag "on" t)))
148
149 (defcustom gnus-simplify-subject-functions nil
150   "List of functions taking a string argument that simplify subjects.
151 The functions are applied recursively.
152
153 Useful functions to put in this list include:
154 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
155 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
156   :group 'gnus-thread
157   :type '(repeat function))
158
159 (defcustom gnus-simplify-ignored-prefixes nil
160   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
161   :group 'gnus-thread
162   :type '(choice (const :tag "off" nil)
163                  regexp))
164
165 (defcustom gnus-build-sparse-threads nil
166   "*If non-nil, fill in the gaps in threads.
167 If `some', only fill in the gaps that are needed to tie loose threads
168 together.  If `more', fill in all leaf nodes that Gnus can find.  If
169 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  (const some)
173                  (const more)
174                  (sexp :menu-tag "all" t)))
175
176 (defcustom gnus-summary-thread-gathering-function
177   'gnus-gather-threads-by-subject
178   "*Function used for gathering loose threads.
179 There are two pre-defined functions: `gnus-gather-threads-by-subject',
180 which only takes Subjects into consideration; and
181 `gnus-gather-threads-by-references', which compared the References
182 headers of the articles to find matches."
183   :group 'gnus-thread
184   :type '(radio (function-item gnus-gather-threads-by-subject)
185                 (function-item gnus-gather-threads-by-references)
186                 (function :tag "other")))
187
188 (defcustom gnus-summary-same-subject ""
189   "*String indicating that the current article has the same subject as the previous.
190 This variable will only be used if the value of
191 `gnus-summary-make-false-root' is `empty'."
192   :group 'gnus-summary-format
193   :type 'string)
194
195 (defcustom gnus-summary-goto-unread t
196   "*If t, many commands will go to the next unread article.
197 This applies to marking commands as well as other commands that
198 \"naturally\" select the next article, like, for instance, `SPC' at
199 the end of an article.
200
201 If nil, the marking commands do NOT go to the next unread article
202 \(they go to the next article instead).  If `never', commands that
203 usually go to the next unread article, will go to the next article,
204 whether it is read or not."
205   :group 'gnus-summary-marks
206   :link '(custom-manual "(gnus)Setting Marks")
207   :type '(choice (const :tag "off" nil)
208                  (const never)
209                  (sexp :menu-tag "on" t)))
210
211 (defcustom gnus-summary-default-score 0
212   "*Default article score level.
213 All scores generated by the score files will be added to this score.
214 If this variable is nil, scoring will be disabled."
215   :group 'gnus-score-default
216   :type '(choice (const :tag "disable")
217                  integer))
218
219 (defcustom gnus-summary-default-high-score 0
220   "*Default threshold for a high scored article.
221 An article will be highlighted as high scored if its score is greater
222 than this score."
223   :version "21.4"
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-default-low-score 0
228   "*Default threshold for a low scored article.
229 An article will be highlighted as low scored if its score is smaller
230 than this score."
231   :version "21.4"
232   :group 'gnus-score-default
233   :type 'integer)
234
235 (defcustom gnus-summary-zcore-fuzz 0
236   "*Fuzziness factor for the zcore in the summary buffer.
237 Articles with scores closer than this to `gnus-summary-default-score'
238 will not be marked."
239   :group 'gnus-summary-format
240   :type 'integer)
241
242 (defcustom gnus-simplify-subject-fuzzy-regexp nil
243   "*Strings to be removed when doing fuzzy matches.
244 This can either be a regular expression or list of regular expressions
245 that will be removed from subject strings if fuzzy subject
246 simplification is selected."
247   :group 'gnus-thread
248   :type '(repeat regexp))
249
250 (defcustom gnus-show-threads t
251   "*If non-nil, display threads in summary mode."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-subtree nil
256   "*If non-nil, hide all threads initially.
257 This can be a predicate specifier which says which threads to hide.
258 If threads are hidden, you have to run the command
259 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
260 to expose hidden threads."
261   :group 'gnus-thread
262   :type '(radio (sexp :format "Non-nil\n"
263                       :match (lambda (widget value)
264                                (not (or (consp value) (functionp value))))
265                       :value t)
266                 (const nil)
267                 (sexp :tag "Predicate specifier")))
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :version "21.4"
328   :group 'gnus-group-select
329   :type '(choice (const best)
330                  (const unread)
331                  (const first)
332                  (const unseen)
333                  (const unseen-or-unread)))
334
335 (defcustom gnus-auto-select-next t
336   "*If non-nil, offer to go to the next group from the end of the previous.
337 If the value is t and the next newsgroup is empty, Gnus will exit
338 summary mode and go back to group mode.  If the value is neither nil
339 nor t, Gnus will select the following unread newsgroup.  In
340 particular, if the value is the symbol `quietly', the next unread
341 newsgroup will be selected without any confirmation, and if it is
342 `almost-quietly', the next group will be selected without any
343 confirmation if you are located on the last article in the group.
344 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
345 will go to the next group without confirmation."
346   :group 'gnus-summary-maneuvering
347   :type '(choice (const :tag "off" nil)
348                  (const quietly)
349                  (const almost-quietly)
350                  (const slightly-quietly)
351                  (sexp :menu-tag "on" t)))
352
353 (defcustom gnus-auto-select-same nil
354   "*If non-nil, select the next article with the same subject.
355 If there are no more articles with the same subject, go to
356 the first unread article."
357   :group 'gnus-summary-maneuvering
358   :type 'boolean)
359
360 (defcustom gnus-auto-goto-ignores 'unfetched
361   "*Says how to handle unfetched articles when maneuvering.
362
363 This variable can either be the symbols nil (maneuver to any
364 article), `undownloaded' (maneuvering while unplugged ignores articles
365 that have not been fetched), `always-undownloaded' (maneuvering always
366 ignores articles that have not been fetched), `unfetched' (maneuvering
367 ignores articles whose headers have not been fetched).
368
369 NOTE: The list of unfetched articles will always be nil when plugged
370 and, when unplugged, a subset of the undownloaded article list."
371   :version "21.4"
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "None" nil)
374                  (const :tag "Undownloaded when unplugged" undownloaded)
375                  (const :tag "Undownloaded" always-undownloaded)
376                  (const :tag "Unfetched" unfetched)))
377
378 (defcustom gnus-summary-check-current nil
379   "*If non-nil, consider the current article when moving.
380 The \"unread\" movement commands will stay on the same line if the
381 current article is unread."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-center-summary 2
386   "*If non-nil, always center the current summary buffer.
387 In particular, if `vertical' do only vertical recentering.  If non-nil
388 and non-`vertical', do both horizontal and vertical recentering."
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "none" nil)
391                  (const vertical)
392                  (integer :tag "height")
393                  (sexp :menu-tag "both" t)))
394
395 (defvar gnus-auto-center-group t
396   "*If non-nil, always center the group buffer.")
397
398 (defcustom gnus-show-all-headers nil
399   "*If non-nil, don't hide any headers."
400   :group 'gnus-article-hiding
401   :group 'gnus-article-headers
402   :type 'boolean)
403
404 (defcustom gnus-summary-ignore-duplicates nil
405   "*If non-nil, ignore articles with identical Message-ID headers."
406   :group 'gnus-summary
407   :type 'boolean)
408
409 (defcustom gnus-single-article-buffer t
410   "*If non-nil, display all articles in the same buffer.
411 If nil, each group will get its own article buffer."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-break-pages t
416   "*If non-nil, do page breaking on articles.
417 The page delimiter is specified by the `gnus-page-delimiter'
418 variable."
419   :group 'gnus-article-various
420   :type 'boolean)
421
422 (defcustom gnus-move-split-methods nil
423   "*Variable used to suggest where articles are to be moved to.
424 It uses the same syntax as the `gnus-split-methods' variable.
425 However, whereas `gnus-split-methods' specifies file names as targets,
426 this variable specifies group names."
427   :group 'gnus-summary-mail
428   :type '(repeat (choice (list :value (fun) function)
429                          (cons :value ("" "") regexp (repeat string))
430                          (sexp :value nil))))
431
432 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
433   "Function used to compute default prefix for article move/copy/etc prompts.
434 The function should take one argument, a group name, and return a
435 string with the suggested prefix."
436   :group 'gnus-summary-mail
437   :type 'function)
438
439 ;; FIXME: Although the custom type is `character' for the following variables,
440 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
441
442 (defcustom gnus-unread-mark ?           ;Whitespace
443   "*Mark used for unread articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-ticked-mark ?!
448   "*Mark used for ticked articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-dormant-mark ??
453   "*Mark used for dormant articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-del-mark ?r
458   "*Mark used for del'd articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-read-mark ?R
463   "*Mark used for read articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-expirable-mark ?E
468   "*Mark used for expirable articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-killed-mark ?K
473   "*Mark used for killed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-spam-mark ?$
478   "*Mark used for spam articles."
479   :version "21.4"
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :version "21.4"
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-recent-mark ?N
515   "*Mark used for articles that are recent."
516   :version "21.4"
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :version "21.4"
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-no-mark ?               ;Whitespace
537   "*Mark used for articles that have no other secondary mark."
538   :version "21.4"
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-ancient-mark ?O
543   "*Mark used for ancient articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-sparse-mark ?Q
548   "*Mark used for sparsely reffed articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-canceled-mark ?G
553   "*Mark used for canceled articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-duplicate-mark ?M
558   "*Mark used for duplicate articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-undownloaded-mark ?-
563   "*Mark used for articles that weren't downloaded."
564   :version "21.4"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?     ;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defun gnus-widget-reversible-match (widget value)
699   "Ignoring WIDGET, convert VALUE to internal form.
700 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
701   ;; (debug value)
702   (or (symbolp value)
703       (and (listp value)
704            (eq (length value) 2)
705            (eq (nth 0 value) 'not)
706            (symbolp (nth 1 value)))))
707
708 (defun gnus-widget-reversible-to-internal (widget value)
709   "Ignoring WIDGET, convert VALUE to internal form.
710 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
711 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
712   ;; (debug value)
713   (if (atom value)
714       (list value nil)
715     (list (nth 1 value) t)))
716
717 (defun gnus-widget-reversible-to-external (widget value)
718   "Ignoring WIDGET, convert VALUE to external form.
719 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
720 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
721   ;; (debug value)
722   (if (nth 1 value)
723       (list 'not (nth 0 value))
724     (nth 0 value)))
725
726 (define-widget 'gnus-widget-reversible 'group
727   "A `group' that convert values."
728   :match 'gnus-widget-reversible-match
729   :value-to-internal 'gnus-widget-reversible-to-internal
730   :value-to-external 'gnus-widget-reversible-to-external)
731
732 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
733   "*List of functions used for sorting articles in the summary buffer.
734
735 Each function takes two articles and returns non-nil if the first
736 article should be sorted before the other.  If you use more than one
737 function, the primary sort function should be the last.  You should
738 probably always include `gnus-article-sort-by-number' in the list of
739 sorting functions -- preferably first.  Also note that sorting by date
740 is often much slower than sorting by number, and the sorting order is
741 very similar.  (Sorting by date means sorting by the time the message
742 was sent, sorting by number means sorting by arrival time.)
743
744 Each item can also be a list `(not F)' where F is a function;
745 this reverses the sort order.
746
747 Ready-made functions include `gnus-article-sort-by-number',
748 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
749 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
750 and `gnus-article-sort-by-score'.
751
752 When threading is turned on, the variable `gnus-thread-sort-functions'
753 controls how articles are sorted."
754   :group 'gnus-summary-sort
755   :type '(repeat (gnus-widget-reversible
756                   (choice (function-item gnus-article-sort-by-number)
757                           (function-item gnus-article-sort-by-author)
758                           (function-item gnus-article-sort-by-subject)
759                           (function-item gnus-article-sort-by-date)
760                           (function-item gnus-article-sort-by-score)
761                           (function-item gnus-article-sort-by-random)
762                           (function :tag "other"))
763                   (boolean :tag "Reverse order"))))
764
765
766 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
767   "*List of functions used for sorting threads in the summary buffer.
768 By default, threads are sorted by article number.
769
770 Each function takes two threads and returns non-nil if the first
771 thread should be sorted before the other.  If you use more than one
772 function, the primary sort function should be the last.  You should
773 probably always include `gnus-thread-sort-by-number' in the list of
774 sorting functions -- preferably first.  Also note that sorting by date
775 is often much slower than sorting by number, and the sorting order is
776 very similar.  (Sorting by date means sorting by the time the message
777 was sent, sorting by number means sorting by arrival time.)
778
779 Each list item can also be a list `(not F)' where F is a
780 function; this specifies reversed sort order.
781
782 Ready-made functions include `gnus-thread-sort-by-number',
783 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
784 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
785 `gnus-thread-sort-by-most-recent-number',
786 `gnus-thread-sort-by-most-recent-date',
787 `gnus-thread-sort-by-random', and
788 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
789
790 When threading is turned off, the variable
791 `gnus-article-sort-functions' controls how articles are sorted."
792   :group 'gnus-summary-sort
793   :type '(repeat 
794           (gnus-widget-reversible
795            (choice (function-item gnus-thread-sort-by-number)
796                    (function-item gnus-thread-sort-by-author)
797                    (function-item gnus-thread-sort-by-subject)
798                    (function-item gnus-thread-sort-by-date)
799                    (function-item gnus-thread-sort-by-score)
800                    (function-item gnus-thread-sort-by-most-recent-number)
801                    (function-item gnus-thread-sort-by-most-recent-date)
802                    (function-item gnus-thread-sort-by-random)
803                    (function-item gnus-thread-sort-by-total-score)
804                    (function :tag "other"))
805            (boolean :tag "Reverse order"))))
806
807 (defcustom gnus-thread-score-function '+
808   "*Function used for calculating the total score of a thread.
809
810 The function is called with the scores of the article and each
811 subthread and should then return the score of the thread.
812
813 Some functions you can use are `+', `max', or `min'."
814   :group 'gnus-summary-sort
815   :type 'function)
816
817 (defcustom gnus-summary-expunge-below nil
818   "All articles that have a score less than this variable will be expunged.
819 This variable is local to the summary buffers."
820   :group 'gnus-score-default
821   :type '(choice (const :tag "off" nil)
822                  integer))
823
824 (defcustom gnus-thread-expunge-below nil
825   "All threads that have a total score less than this variable will be expunged.
826 See `gnus-thread-score-function' for en explanation of what a
827 \"thread score\" is.
828
829 This variable is local to the summary buffers."
830   :group 'gnus-threading
831   :group 'gnus-score-default
832   :type '(choice (const :tag "off" nil)
833                  integer))
834
835 (defcustom gnus-summary-mode-hook nil
836   "*A hook for Gnus summary mode.
837 This hook is run before any variables are set in the summary buffer."
838   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
839   :group 'gnus-summary-various
840   :type 'hook)
841
842 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
843 (when (featurep 'xemacs)
844   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
846   (add-hook 'gnus-summary-mode-hook
847             'gnus-xmas-switch-horizontal-scrollbar-off))
848
849 (defcustom gnus-summary-menu-hook nil
850   "*Hook run after the creation of the summary mode menu."
851   :group 'gnus-summary-visual
852   :type 'hook)
853
854 (defcustom gnus-summary-exit-hook nil
855   "*A hook called on exit from the summary buffer.
856 It will be called with point in the group buffer."
857   :group 'gnus-summary-exit
858   :type 'hook)
859
860 (defcustom gnus-summary-prepare-hook nil
861   "*A hook called after the summary buffer has been generated.
862 If you want to modify the summary buffer, you can use this hook."
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 (defcustom gnus-summary-prepared-hook nil
867   "*A hook called as the last thing after the summary buffer has been generated."
868   :group 'gnus-summary-various
869   :type 'hook)
870
871 (defcustom gnus-summary-generate-hook nil
872   "*A hook run just before generating the summary buffer.
873 This hook is commonly used to customize threading variables and the
874 like."
875   :group 'gnus-summary-various
876   :type 'hook)
877
878 (defcustom gnus-select-group-hook nil
879   "*A hook called when a newsgroup is selected.
880
881 If you'd like to simplify subjects like the
882 `gnus-summary-next-same-subject' command does, you can use the
883 following hook:
884
885  (add-hook gnus-select-group-hook
886            (lambda ()
887              (mapcar (lambda (header)
888                        (mail-header-set-subject
889                         header
890                         (gnus-simplify-subject
891                          (mail-header-subject header) 're-only)))
892                      gnus-newsgroup-headers)))"
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-select-article-hook nil
897   "*A hook called when an article is selected."
898   :group 'gnus-summary-choose
899   :options '(gnus-agent-fetch-selected-article)
900   :type 'hook)
901
902 (defcustom gnus-visual-mark-article-hook
903   (list 'gnus-highlight-selected-summary)
904   "*Hook run after selecting an article in the summary buffer.
905 It is meant to be used for highlighting the article in some way.  It
906 is not run if `gnus-visual' is nil."
907   :group 'gnus-summary-visual
908   :type 'hook)
909
910 (defcustom gnus-parse-headers-hook nil
911   "*A hook called before parsing the headers."
912   :group 'gnus-various
913   :type 'hook)
914
915 (defcustom gnus-exit-group-hook nil
916   "*A hook called when exiting summary mode.
917 This hook is not called from the non-updating exit commands like `Q'."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-summary-update-hook
922   (list 'gnus-summary-highlight-line)
923   "*A hook called when a summary line is changed.
924 The hook will not be called if `gnus-visual' is nil.
925
926 The default function `gnus-summary-highlight-line' will
927 highlight the line according to the `gnus-summary-highlight'
928 variable."
929   :group 'gnus-summary-visual
930   :type 'hook)
931
932 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
933   "*A hook called when an article is selected for the first time.
934 The hook is intended to mark an article as read (or unread)
935 automatically when it is selected."
936   :group 'gnus-summary-choose
937   :type 'hook)
938
939 (defcustom gnus-group-no-more-groups-hook nil
940   "*A hook run when returning to group mode having no more (unread) groups."
941   :group 'gnus-group-select
942   :type 'hook)
943
944 (defcustom gnus-ps-print-hook nil
945   "*A hook run before ps-printing something from Gnus."
946   :group 'gnus-summary
947   :type 'hook)
948
949 (defcustom gnus-summary-article-move-hook nil
950   "*A hook called after an article is moved, copied, respooled, or crossposted."
951   :version "21.4"
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-delete-hook nil
956   "*A hook called after an article is deleted."
957   :version "21.4"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-expire-hook nil
962   "*A hook called after an article is expired."
963   :version "21.4"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-display-arrow
968   (and (fboundp 'display-graphic-p)
969        (display-graphic-p))
970   "*If non-nil, display an arrow highlighting the current article."
971   :version "21.4"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
976   "Face used for highlighting the current article in the summary buffer."
977   :group 'gnus-summary-visual
978   :type 'face)
979
980 (defvar gnus-tmp-downloaded nil)
981
982 (defcustom gnus-summary-highlight
983   '(((eq mark gnus-canceled-mark)
984      . gnus-summary-cancelled-face)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded-face)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded-face)
989     (uncached
990      . gnus-summary-normal-undownloaded-face)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked-face)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked-face)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked-face)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient-face)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient-face)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient-face)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread-face)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread-face)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread-face)
1014     ((> score default-high)
1015      . gnus-summary-high-read-face)
1016     ((< score default-low)
1017      . gnus-summary-low-read-face)
1018     (t
1019      . gnus-summary-normal-read-face))
1020   "*Controls the highlighting of summary buffer lines.
1021
1022 A list of (FORM . FACE) pairs.  When deciding how a a particular
1023 summary line should be displayed, each form is evaluated.  The content
1024 of the face field after the first true form is used.  You can change
1025 how those summary lines are displayed, by editing the face field.
1026
1027 You can use the following variables in the FORM field.
1028
1029 score:        The article's score
1030 default:      The default article score.
1031 default-high: The default score for high scored articles.
1032 default-low:  The default score for low scored articles.
1033 below:        The score below which articles are automatically marked as read.
1034 mark:         The article's mark.
1035 uncached:     Non-nil if the article is uncached."
1036   :group 'gnus-summary-visual
1037   :type '(repeat (cons (sexp :tag "Form" nil)
1038                        face)))
1039
1040 (defcustom gnus-alter-header-function nil
1041   "Function called to allow alteration of article header structures.
1042 The function is called with one parameter, the article header vector,
1043 which it may alter in any way."
1044   :type '(choice (const :tag "None" nil)
1045                  function)
1046   :group 'gnus-summary)
1047
1048 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1049   "Variable that says which function should be used to decode a string with encoded words.")
1050
1051 (defcustom gnus-extra-headers '(To Newsgroups)
1052   "*Extra headers to parse."
1053   :version "21.1"
1054   :group 'gnus-summary
1055   :type '(repeat symbol))
1056
1057 (defcustom gnus-ignored-from-addresses
1058   (and user-mail-address (regexp-quote user-mail-address))
1059   "*Regexp of From headers that may be suppressed in favor of To headers."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type 'regexp)
1063
1064 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1065   "List of charsets that should be ignored.
1066 When these charsets are used in the \"charset\" parameter, the
1067 default charset will be used instead."
1068   :version "21.1"
1069   :type '(repeat symbol)
1070   :group 'gnus-charset)
1071
1072 (gnus-define-group-parameter
1073  ignored-charsets
1074  :type list
1075  :function-document
1076  "Return the ignored charsets of GROUP."
1077  :variable gnus-group-ignored-charsets-alist
1078  :variable-default
1079  '(("alt\\.chinese\\.text" iso-8859-1))
1080  :variable-document
1081  "Alist of regexps (to match group names) and charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084  :variable-group gnus-charset
1085  :variable-type '(repeat (cons (regexp :tag "Group")
1086                                (repeat symbol)))
1087  :parameter-type '(choice :tag "Ignored charsets"
1088                           :value nil
1089                           (repeat (symbol)))
1090  :parameter-document       "\
1091 List of charsets that should be ignored.
1092
1093 When these charsets are used in the \"charset\" parameter, the
1094 default charset will be used instead.")
1095
1096 (defcustom gnus-group-highlight-words-alist nil
1097   "Alist of group regexps and highlight regexps.
1098 This variable uses the same syntax as `gnus-emphasis-alist'."
1099   :version "21.1"
1100   :type '(repeat (cons (regexp :tag "Group")
1101                        (repeat (list (regexp :tag "Highlight regexp")
1102                                      (number :tag "Group for entire word" 0)
1103                                      (number :tag "Group for displayed part" 0)
1104                                      (symbol :tag "Face"
1105                                              gnus-emphasis-highlight-words)))))
1106   :group 'gnus-summary-visual)
1107
1108 (defcustom gnus-summary-show-article-charset-alist
1109   nil
1110   "Alist of number and charset.
1111 The article will be shown with the charset corresponding to the
1112 numbered argument.
1113 For example: ((1 . cn-gb-2312) (2 . big5))."
1114   :version "21.1"
1115   :type '(repeat (cons (number :tag "Argument" 1)
1116                        (symbol :tag "Charset")))
1117   :group 'gnus-charset)
1118
1119 (defcustom gnus-preserve-marks t
1120   "Whether marks are preserved when moving, copying and respooling messages."
1121   :version "21.1"
1122   :type 'boolean
1123   :group 'gnus-summary-marks)
1124
1125 (defcustom gnus-alter-articles-to-read-function nil
1126   "Function to be called to alter the list of articles to be selected."
1127   :type '(choice (const nil) function)
1128   :group 'gnus-summary)
1129
1130 (defcustom gnus-orphan-score nil
1131   "*All orphans get this score added.  Set in the score file."
1132   :group 'gnus-score-default
1133   :type '(choice (const nil)
1134                  integer))
1135
1136 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1137   "*A regexp to match MIME parts when saving multiple parts of a
1138 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1139 This regexp will be used by default when prompting the user for which
1140 type of files to save."
1141   :group 'gnus-summary
1142   :type 'regexp)
1143
1144 (defcustom gnus-read-all-available-headers nil
1145   "Whether Gnus should parse all headers made available to it.
1146 This is mostly relevant for slow back ends where the user may
1147 wish to widen the summary buffer to include all headers
1148 that were fetched.  Say, for nnultimate groups."
1149   :version "21.4"
1150   :group 'gnus-summary
1151   :type '(choice boolean regexp))
1152
1153 (defcustom gnus-summary-muttprint-program "muttprint"
1154   "Command (and optional arguments) used to run Muttprint."
1155   :version "21.4"
1156   :group 'gnus-summary
1157   :type 'string)
1158
1159 (defcustom gnus-article-loose-mime t
1160   "If non-nil, don't require MIME-Version header.
1161 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1162 supply the MIME-Version header or deliberately strip it from the mail.
1163 If non-nil (the default), Gnus will treat some articles as MIME
1164 even if the MIME-Version header is missing."
1165   :version "21.4"
1166   :type 'boolean
1167   :group 'gnus-article-mime)
1168
1169 (defcustom gnus-article-emulate-mime t
1170   "If non-nil, use MIME emulation for uuencode and the like.
1171 This means that Gnus will search message bodies for text that look
1172 like uuencoded bits, yEncoded bits, and so on, and present that using
1173 the normal Gnus MIME machinery."
1174   :version "21.4"
1175   :type 'boolean
1176   :group 'gnus-article-mime)
1177
1178 ;;; Internal variables
1179
1180 (defvar gnus-summary-display-cache nil)
1181 (defvar gnus-article-mime-handles nil)
1182 (defvar gnus-article-decoded-p nil)
1183 (defvar gnus-article-charset nil)
1184 (defvar gnus-article-ignored-charsets nil)
1185 (defvar gnus-scores-exclude-files nil)
1186 (defvar gnus-page-broken nil)
1187
1188 (defvar gnus-original-article nil)
1189 (defvar gnus-article-internal-prepare-hook nil)
1190 (defvar gnus-newsgroup-process-stack nil)
1191
1192 (defvar gnus-thread-indent-array nil)
1193 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1194 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1195   "Function called to sort the articles within a thread after it has been gathered together.")
1196
1197 (defvar gnus-summary-save-parts-type-history nil)
1198 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1199
1200 ;; Avoid highlighting in kill files.
1201 (defvar gnus-summary-inhibit-highlight nil)
1202 (defvar gnus-newsgroup-selected-overlay nil)
1203 (defvar gnus-inhibit-limiting nil)
1204 (defvar gnus-newsgroup-adaptive-score-file nil)
1205 (defvar gnus-current-score-file nil)
1206 (defvar gnus-current-move-group nil)
1207 (defvar gnus-current-copy-group nil)
1208 (defvar gnus-current-crosspost-group nil)
1209 (defvar gnus-newsgroup-display nil)
1210
1211 (defvar gnus-newsgroup-dependencies nil)
1212 (defvar gnus-newsgroup-adaptive nil)
1213 (defvar gnus-summary-display-article-function nil)
1214 (defvar gnus-summary-highlight-line-function nil
1215   "Function called after highlighting a summary line.")
1216
1217 (defvar gnus-summary-line-format-alist
1218   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1219     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1220     (?s gnus-tmp-subject-or-nil ?s)
1221     (?n gnus-tmp-name ?s)
1222     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1223         ?s)
1224     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1225             gnus-tmp-from) ?s)
1226     (?F gnus-tmp-from ?s)
1227     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1228     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1229     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1230     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1231     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1232     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1233     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1234     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1235     (?L gnus-tmp-lines ?s)
1236     (?O gnus-tmp-downloaded ?c)
1237     (?I gnus-tmp-indentation ?s)
1238     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1239     (?R gnus-tmp-replied ?c)
1240     (?\[ gnus-tmp-opening-bracket ?c)
1241     (?\] gnus-tmp-closing-bracket ?c)
1242     (?\> (make-string gnus-tmp-level ? ) ?s)
1243     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1244     (?i gnus-tmp-score ?d)
1245     (?z gnus-tmp-score-char ?c)
1246     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1247     (?U gnus-tmp-unread ?c)
1248     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1249         ?s)
1250     (?t (gnus-summary-number-of-articles-in-thread
1251          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1252         ?d)
1253     (?e (gnus-summary-number-of-articles-in-thread
1254          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1255         ?c)
1256     (?u gnus-tmp-user-defined ?s)
1257     (?P (gnus-pick-line-number) ?d)
1258     (?B gnus-tmp-thread-tree-header-string ?s)
1259     (user-date (gnus-user-date
1260                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1261   "An alist of format specifications that can appear in summary lines.
1262 These are paired with what variables they correspond with, along with
1263 the type of the variable (string, integer, character, etc).")
1264
1265 (defvar gnus-summary-dummy-line-format-alist
1266   `((?S gnus-tmp-subject ?s)
1267     (?N gnus-tmp-number ?d)
1268     (?u gnus-tmp-user-defined ?s)))
1269
1270 (defvar gnus-summary-mode-line-format-alist
1271   `((?G gnus-tmp-group-name ?s)
1272     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1273     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1274     (?A gnus-tmp-article-number ?d)
1275     (?Z gnus-tmp-unread-and-unselected ?s)
1276     (?V gnus-version ?s)
1277     (?U gnus-tmp-unread-and-unticked ?d)
1278     (?S gnus-tmp-subject ?s)
1279     (?e gnus-tmp-unselected ?d)
1280     (?u gnus-tmp-user-defined ?s)
1281     (?d (length gnus-newsgroup-dormant) ?d)
1282     (?t (length gnus-newsgroup-marked) ?d)
1283     (?h (length gnus-newsgroup-spam-marked) ?d)
1284     (?r (length gnus-newsgroup-reads) ?d)
1285     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1286     (?E gnus-newsgroup-expunged-tally ?d)
1287     (?s (gnus-current-score-file-nondirectory) ?s)))
1288
1289 (defvar gnus-last-search-regexp nil
1290   "Default regexp for article search command.")
1291
1292 (defvar gnus-last-shell-command nil
1293   "Default shell command on article.")
1294
1295 (defvar gnus-newsgroup-agentized nil
1296   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1297 (defvar gnus-newsgroup-begin nil)
1298 (defvar gnus-newsgroup-end nil)
1299 (defvar gnus-newsgroup-last-rmail nil)
1300 (defvar gnus-newsgroup-last-mail nil)
1301 (defvar gnus-newsgroup-last-folder nil)
1302 (defvar gnus-newsgroup-last-file nil)
1303 (defvar gnus-newsgroup-auto-expire nil)
1304 (defvar gnus-newsgroup-active nil)
1305
1306 (defvar gnus-newsgroup-data nil)
1307 (defvar gnus-newsgroup-data-reverse nil)
1308 (defvar gnus-newsgroup-limit nil)
1309 (defvar gnus-newsgroup-limits nil)
1310 (defvar gnus-summary-use-undownloaded-faces nil)
1311
1312 (defvar gnus-newsgroup-unreads nil
1313   "Sorted list of unread articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-unselected nil
1316   "Sorted list of unselected unread articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-reads nil
1319   "Alist of read articles and article marks in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-expunged-tally nil)
1322
1323 (defvar gnus-newsgroup-marked nil
1324   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1325
1326 (defvar gnus-newsgroup-spam-marked nil
1327   "List of ranges of articles that have been marked as spam.")
1328
1329 (defvar gnus-newsgroup-killed nil
1330   "List of ranges of articles that have been through the scoring process.")
1331
1332 (defvar gnus-newsgroup-cached nil
1333   "Sorted list of articles that come from the article cache.")
1334
1335 (defvar gnus-newsgroup-saved nil
1336   "List of articles that have been saved.")
1337
1338 (defvar gnus-newsgroup-kill-headers nil)
1339
1340 (defvar gnus-newsgroup-replied nil
1341   "List of articles that have been replied to in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-forwarded nil
1344   "List of articles that have been forwarded in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-recent nil
1347   "List of articles that have are recent in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-expirable nil
1350   "Sorted list of articles in the current newsgroup that can be expired.")
1351
1352 (defvar gnus-newsgroup-processable nil
1353   "List of articles in the current newsgroup that can be processed.")
1354
1355 (defvar gnus-newsgroup-downloadable nil
1356   "Sorted list of articles in the current newsgroup that can be processed.")
1357
1358 (defvar gnus-newsgroup-unfetched nil
1359   "Sorted list of articles in the current newsgroup whose headers have
1360 not been fetched into the agent.
1361
1362 This list will always be a subset of gnus-newsgroup-undownloaded.")
1363
1364 (defvar gnus-newsgroup-undownloaded nil
1365   "List of articles in the current newsgroup that haven't been downloaded.")
1366
1367 (defvar gnus-newsgroup-unsendable nil
1368   "List of articles in the current newsgroup that won't be sent.")
1369
1370 (defvar gnus-newsgroup-bookmarks nil
1371   "List of articles in the current newsgroup that have bookmarks.")
1372
1373 (defvar gnus-newsgroup-dormant nil
1374   "Sorted list of dormant articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-unseen nil
1377   "List of unseen articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-seen nil
1380   "Range of seen articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-articles nil
1383   "List of articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-scored nil
1386   "List of scored articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-headers nil
1389   "List of article headers in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-threads nil)
1392
1393 (defvar gnus-newsgroup-prepared nil
1394   "Whether the current group has been prepared properly.")
1395
1396 (defvar gnus-newsgroup-ancient nil
1397   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-sparse nil)
1400
1401 (defvar gnus-current-article nil)
1402 (defvar gnus-article-current nil)
1403 (defvar gnus-current-headers nil)
1404 (defvar gnus-have-all-headers nil)
1405 (defvar gnus-last-article nil)
1406 (defvar gnus-newsgroup-history nil)
1407 (defvar gnus-newsgroup-charset nil)
1408 (defvar gnus-newsgroup-ephemeral-charset nil)
1409 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1410
1411 (defvar gnus-article-before-search nil)
1412
1413 (defvar gnus-summary-local-variables
1414   '(gnus-newsgroup-name
1415     gnus-newsgroup-begin gnus-newsgroup-end
1416     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1417     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1418     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1419     gnus-newsgroup-unselected gnus-newsgroup-marked
1420     gnus-newsgroup-spam-marked
1421     gnus-newsgroup-reads gnus-newsgroup-saved
1422     gnus-newsgroup-replied gnus-newsgroup-forwarded
1423     gnus-newsgroup-recent
1424     gnus-newsgroup-expirable
1425     gnus-newsgroup-processable gnus-newsgroup-killed
1426     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1427     gnus-newsgroup-unfetched
1428     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1429     gnus-newsgroup-seen gnus-newsgroup-articles
1430     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1431     gnus-newsgroup-headers gnus-newsgroup-threads
1432     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1433     gnus-current-article gnus-current-headers gnus-have-all-headers
1434     gnus-last-article gnus-article-internal-prepare-hook
1435     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1436     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1437     gnus-thread-expunge-below
1438     gnus-score-alist gnus-current-score-file
1439     (gnus-summary-expunge-below . global)
1440     (gnus-summary-mark-below . global)
1441     (gnus-orphan-score . global)
1442     gnus-newsgroup-active gnus-scores-exclude-files
1443     gnus-newsgroup-history gnus-newsgroup-ancient
1444     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1445     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1446     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1447     (gnus-newsgroup-expunged-tally . 0)
1448     gnus-cache-removable-articles gnus-newsgroup-cached
1449     gnus-newsgroup-data gnus-newsgroup-data-reverse
1450     gnus-newsgroup-limit gnus-newsgroup-limits
1451     gnus-newsgroup-charset gnus-newsgroup-display
1452     gnus-summary-use-undownloaded-faces)
1453   "Variables that are buffer-local to the summary buffers.")
1454
1455 (defvar gnus-newsgroup-variables nil
1456   "A list of variables that have separate values in different newsgroups.
1457 A list of newsgroup (summary buffer) local variables, or cons of
1458 variables and their default expressions to be evalled (when the default
1459 values are not nil), that should be made global while the summary buffer
1460 is active.
1461
1462 Note: The default expressions will be evaluated (using function `eval')
1463 before assignment to the local variable rather than just assigned to it.
1464 If the default expression is the symbol `global', that symbol will not
1465 be evaluated but the global value of the local variable will be used
1466 instead.
1467
1468 These variables can be used to set variables in the group parameters
1469 while still allowing them to affect operations done in other buffers.
1470 For example:
1471
1472 \(setq gnus-newsgroup-variables
1473      '(message-use-followup-to
1474        (gnus-visible-headers .
1475          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1476 ")
1477
1478 ;; Byte-compiler warning.
1479 (eval-when-compile
1480   ;; Bind features so that require will believe that gnus-sum has
1481   ;; already been loaded (avoids infinite recursion)
1482   (let ((features (cons 'gnus-sum features)))
1483     ;; Several of the declarations in gnus-sum are needed to load the
1484     ;; following files. Right now, these definitions have been
1485     ;; compiled but not defined (evaluated).  We could either do a
1486     ;; eval-and-compile about all of the declarations or evaluate the
1487     ;; source file.
1488     (if (boundp 'gnus-newsgroup-variables)
1489         nil
1490       (load "gnus-sum.el" t t t))
1491     (require 'gnus)
1492     (require 'gnus-art)))
1493
1494 ;; MIME stuff.
1495
1496 (defvar gnus-decode-encoded-word-methods
1497   '(mail-decode-encoded-word-string)
1498   "List of methods used to decode encoded words.
1499
1500 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1501 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1502 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1503 whose names match REGEXP.
1504
1505 For example:
1506 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1507  mail-decode-encoded-word-string
1508  (\"chinese\" . rfc1843-decode-string))")
1509
1510 (defvar gnus-decode-encoded-word-methods-cache nil)
1511
1512 (defun gnus-multi-decode-encoded-word-string (string)
1513   "Apply the functions from `gnus-encoded-word-methods' that match."
1514   (unless (and gnus-decode-encoded-word-methods-cache
1515                (eq gnus-newsgroup-name
1516                    (car gnus-decode-encoded-word-methods-cache)))
1517     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1518     (mapcar (lambda (x)
1519               (if (symbolp x)
1520                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1521                 (if (and gnus-newsgroup-name
1522                          (string-match (car x) gnus-newsgroup-name))
1523                     (nconc gnus-decode-encoded-word-methods-cache
1524                            (list (cdr x))))))
1525             gnus-decode-encoded-word-methods))
1526   (let ((xlist gnus-decode-encoded-word-methods-cache))
1527     (pop xlist)
1528     (while xlist
1529       (setq string (funcall (pop xlist) string))))
1530   string)
1531
1532 ;; Subject simplification.
1533
1534 (defun gnus-simplify-whitespace (str)
1535   "Remove excessive whitespace from STR."
1536   ;; Multiple spaces.
1537   (while (string-match "[ \t][ \t]+" str)
1538     (setq str (concat (substring str 0 (match-beginning 0))
1539                         " "
1540                         (substring str (match-end 0)))))
1541   ;; Leading spaces.
1542   (when (string-match "^[ \t]+" str)
1543     (setq str (substring str (match-end 0))))
1544   ;; Trailing spaces.
1545   (when (string-match "[ \t]+$" str)
1546     (setq str (substring str 0 (match-beginning 0))))
1547   str)
1548
1549 (defun gnus-simplify-all-whitespace (str)
1550   "Remove all whitespace from STR."
1551   (while (string-match "[ \t\n]+" str)
1552     (setq str (replace-match "" nil nil str)))
1553   str)
1554
1555 (defsubst gnus-simplify-subject-re (subject)
1556   "Remove \"Re:\" from subject lines."
1557   (if (string-match message-subject-re-regexp subject)
1558       (substring subject (match-end 0))
1559     subject))
1560
1561 (defun gnus-simplify-subject (subject &optional re-only)
1562   "Remove `Re:' and words in parentheses.
1563 If RE-ONLY is non-nil, strip leading `Re:'s only."
1564   (let ((case-fold-search t))           ;Ignore case.
1565     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1566     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1567       (setq subject (substring subject (match-end 0))))
1568     ;; Remove uninteresting prefixes.
1569     (when (and (not re-only)
1570                gnus-simplify-ignored-prefixes
1571                (string-match gnus-simplify-ignored-prefixes subject))
1572       (setq subject (substring subject (match-end 0))))
1573     ;; Remove words in parentheses from end.
1574     (unless re-only
1575       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1576         (setq subject (substring subject 0 (match-beginning 0)))))
1577     ;; Return subject string.
1578     subject))
1579
1580 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1581 ;; all whitespace.
1582 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1583   (goto-char (point-min))
1584   (while (re-search-forward regexp nil t)
1585     (replace-match (or newtext ""))))
1586
1587 (defun gnus-simplify-buffer-fuzzy ()
1588   "Simplify string in the buffer fuzzily.
1589 The string in the accessible portion of the current buffer is simplified.
1590 It is assumed to be a single-line subject.
1591 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1592 matter is removed.  Additional things can be deleted by setting
1593 `gnus-simplify-subject-fuzzy-regexp'."
1594   (let ((case-fold-search t)
1595         (modified-tick))
1596     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1597
1598     (while (not (eq modified-tick (buffer-modified-tick)))
1599       (setq modified-tick (buffer-modified-tick))
1600       (cond
1601        ((listp gnus-simplify-subject-fuzzy-regexp)
1602         (mapcar 'gnus-simplify-buffer-fuzzy-step
1603                 gnus-simplify-subject-fuzzy-regexp))
1604        (gnus-simplify-subject-fuzzy-regexp
1605         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1606       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1607       (gnus-simplify-buffer-fuzzy-step
1608        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1609       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1610
1611     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1612     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1613     (gnus-simplify-buffer-fuzzy-step " $")
1614     (gnus-simplify-buffer-fuzzy-step "^ +")))
1615
1616 (defun gnus-simplify-subject-fuzzy (subject)
1617   "Simplify a subject string fuzzily.
1618 See `gnus-simplify-buffer-fuzzy' for details."
1619   (save-excursion
1620     (gnus-set-work-buffer)
1621     (let ((case-fold-search t))
1622       ;; Remove uninteresting prefixes.
1623       (when (and gnus-simplify-ignored-prefixes
1624                  (string-match gnus-simplify-ignored-prefixes subject))
1625         (setq subject (substring subject (match-end 0))))
1626       (insert subject)
1627       (inline (gnus-simplify-buffer-fuzzy))
1628       (buffer-string))))
1629
1630 (defsubst gnus-simplify-subject-fully (subject)
1631   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1632   (cond
1633    (gnus-simplify-subject-functions
1634     (gnus-map-function gnus-simplify-subject-functions subject))
1635    ((null gnus-summary-gather-subject-limit)
1636     (gnus-simplify-subject-re subject))
1637    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1638     (gnus-simplify-subject-fuzzy subject))
1639    ((numberp gnus-summary-gather-subject-limit)
1640     (gnus-limit-string (gnus-simplify-subject-re subject)
1641                        gnus-summary-gather-subject-limit))
1642    (t
1643     subject)))
1644
1645 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1646   "Check whether two subjects are equal.
1647 If optional argument SIMPLE-FIRST is t, first argument is already
1648 simplified."
1649   (cond
1650    ((null simple-first)
1651     (equal (gnus-simplify-subject-fully s1)
1652            (gnus-simplify-subject-fully s2)))
1653    (t
1654     (equal s1
1655            (gnus-simplify-subject-fully s2)))))
1656
1657 (defun gnus-summary-bubble-group ()
1658   "Increase the score of the current group.
1659 This is a handy function to add to `gnus-summary-exit-hook' to
1660 increase the score of each group you read."
1661   (gnus-group-add-score gnus-newsgroup-name))
1662
1663 \f
1664 ;;;
1665 ;;; Gnus summary mode
1666 ;;;
1667
1668 (put 'gnus-summary-mode 'mode-class 'special)
1669
1670 (defvar gnus-article-commands-menu)
1671
1672 ;; Non-orthogonal keys
1673
1674 (gnus-define-keys gnus-summary-mode-map
1675   " " gnus-summary-next-page
1676   "\177" gnus-summary-prev-page
1677   [delete] gnus-summary-prev-page
1678   [backspace] gnus-summary-prev-page
1679   "\r" gnus-summary-scroll-up
1680   "\M-\r" gnus-summary-scroll-down
1681   "n" gnus-summary-next-unread-article
1682   "p" gnus-summary-prev-unread-article
1683   "N" gnus-summary-next-article
1684   "P" gnus-summary-prev-article
1685   "\M-\C-n" gnus-summary-next-same-subject
1686   "\M-\C-p" gnus-summary-prev-same-subject
1687   "\M-n" gnus-summary-next-unread-subject
1688   "\M-p" gnus-summary-prev-unread-subject
1689   "." gnus-summary-first-unread-article
1690   "," gnus-summary-best-unread-article
1691   "\M-s" gnus-summary-search-article-forward
1692   "\M-r" gnus-summary-search-article-backward
1693   "<" gnus-summary-beginning-of-article
1694   ">" gnus-summary-end-of-article
1695   "j" gnus-summary-goto-article
1696   "^" gnus-summary-refer-parent-article
1697   "\M-^" gnus-summary-refer-article
1698   "u" gnus-summary-tick-article-forward
1699   "!" gnus-summary-tick-article-forward
1700   "U" gnus-summary-tick-article-backward
1701   "d" gnus-summary-mark-as-read-forward
1702   "D" gnus-summary-mark-as-read-backward
1703   "E" gnus-summary-mark-as-expirable
1704   "\M-u" gnus-summary-clear-mark-forward
1705   "\M-U" gnus-summary-clear-mark-backward
1706   "k" gnus-summary-kill-same-subject-and-select
1707   "\C-k" gnus-summary-kill-same-subject
1708   "\M-\C-k" gnus-summary-kill-thread
1709   "\M-\C-l" gnus-summary-lower-thread
1710   "e" gnus-summary-edit-article
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "\M-\C-t" gnus-summary-toggle-threads
1714   "\M-\C-s" gnus-summary-show-thread
1715   "\M-\C-h" gnus-summary-hide-thread
1716   "\M-\C-f" gnus-summary-next-thread
1717   "\M-\C-b" gnus-summary-prev-thread
1718   [(meta down)] gnus-summary-next-thread
1719   [(meta up)] gnus-summary-prev-thread
1720   "\M-\C-u" gnus-summary-up-thread
1721   "\M-\C-d" gnus-summary-down-thread
1722   "&" gnus-summary-execute-command
1723   "c" gnus-summary-catchup-and-exit
1724   "\C-w" gnus-summary-mark-region-as-read
1725   "\C-t" gnus-summary-toggle-truncation
1726   "?" gnus-summary-mark-as-dormant
1727   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1728   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1729   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1730   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1731   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1732   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1733   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1734   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1735   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1736   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1737   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1738   "=" gnus-summary-expand-window
1739   "\C-x\C-s" gnus-summary-reselect-current-group
1740   "\M-g" gnus-summary-rescan-group
1741   "w" gnus-summary-stop-page-breaking
1742   "\C-c\C-r" gnus-summary-caesar-message
1743   "f" gnus-summary-followup
1744   "F" gnus-summary-followup-with-original
1745   "C" gnus-summary-cancel-article
1746   "r" gnus-summary-reply
1747   "R" gnus-summary-reply-with-original
1748   "\C-c\C-f" gnus-summary-mail-forward
1749   "o" gnus-summary-save-article
1750   "\C-o" gnus-summary-save-article-mail
1751   "|" gnus-summary-pipe-output
1752   "\M-k" gnus-summary-edit-local-kill
1753   "\M-K" gnus-summary-edit-global-kill
1754   ;; "V" gnus-version
1755   "\C-c\C-d" gnus-summary-describe-group
1756   "q" gnus-summary-exit
1757   "Q" gnus-summary-exit-no-update
1758   "\C-c\C-i" gnus-info-find-node
1759   gnus-mouse-2 gnus-mouse-pick-article
1760   [follow-link] mouse-face
1761   "m" gnus-summary-mail-other-window
1762   "a" gnus-summary-post-news
1763   "i" gnus-summary-news-other-window
1764   "x" gnus-summary-limit-to-unread
1765   "s" gnus-summary-isearch-article
1766   "t" gnus-summary-toggle-header
1767   "g" gnus-summary-show-article
1768   "l" gnus-summary-goto-last-article
1769   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1770   "\C-d" gnus-summary-enter-digest-group
1771   "\M-\C-d" gnus-summary-read-document
1772   "\M-\C-e" gnus-summary-edit-parameters
1773   "\M-\C-a" gnus-summary-customize-parameters
1774   "\C-c\C-b" gnus-bug
1775   "*" gnus-cache-enter-article
1776   "\M-*" gnus-cache-remove-article
1777   "\M-&" gnus-summary-universal-argument
1778   "\C-l" gnus-recenter
1779   "I" gnus-summary-increase-score
1780   "L" gnus-summary-lower-score
1781   "\M-i" gnus-symbolic-argument
1782   "h" gnus-summary-select-article-buffer
1783
1784   "b" gnus-article-view-part
1785   "\M-t" gnus-summary-toggle-display-buttonized
1786
1787   "V" gnus-summary-score-map
1788   "X" gnus-uu-extract-map
1789   "S" gnus-summary-send-map)
1790
1791 ;; Sort of orthogonal keymap
1792 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1793   "t" gnus-summary-tick-article-forward
1794   "!" gnus-summary-tick-article-forward
1795   "d" gnus-summary-mark-as-read-forward
1796   "r" gnus-summary-mark-as-read-forward
1797   "c" gnus-summary-clear-mark-forward
1798   " " gnus-summary-clear-mark-forward
1799   "e" gnus-summary-mark-as-expirable
1800   "x" gnus-summary-mark-as-expirable
1801   "?" gnus-summary-mark-as-dormant
1802   "b" gnus-summary-set-bookmark
1803   "B" gnus-summary-remove-bookmark
1804   "#" gnus-summary-mark-as-processable
1805   "\M-#" gnus-summary-unmark-as-processable
1806   "S" gnus-summary-limit-include-expunged
1807   "C" gnus-summary-catchup
1808   "H" gnus-summary-catchup-to-here
1809   "h" gnus-summary-catchup-from-here
1810   "\C-c" gnus-summary-catchup-all
1811   "k" gnus-summary-kill-same-subject-and-select
1812   "K" gnus-summary-kill-same-subject
1813   "P" gnus-uu-mark-map)
1814
1815 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1816   "c" gnus-summary-clear-above
1817   "u" gnus-summary-tick-above
1818   "m" gnus-summary-mark-above
1819   "k" gnus-summary-kill-below)
1820
1821 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1822   "/" gnus-summary-limit-to-subject
1823   "n" gnus-summary-limit-to-articles
1824   "w" gnus-summary-pop-limit
1825   "s" gnus-summary-limit-to-subject
1826   "a" gnus-summary-limit-to-author
1827   "u" gnus-summary-limit-to-unread
1828   "m" gnus-summary-limit-to-marks
1829   "M" gnus-summary-limit-exclude-marks
1830   "v" gnus-summary-limit-to-score
1831   "*" gnus-summary-limit-include-cached
1832   "D" gnus-summary-limit-include-dormant
1833   "T" gnus-summary-limit-include-thread
1834   "d" gnus-summary-limit-exclude-dormant
1835   "t" gnus-summary-limit-to-age
1836   "." gnus-summary-limit-to-unseen
1837   "x" gnus-summary-limit-to-extra
1838   "p" gnus-summary-limit-to-display-predicate
1839   "E" gnus-summary-limit-include-expunged
1840   "c" gnus-summary-limit-exclude-childless-dormant
1841   "C" gnus-summary-limit-mark-excluded-as-read
1842   "o" gnus-summary-insert-old-articles
1843   "N" gnus-summary-insert-new-articles
1844   "r" gnus-summary-limit-to-replied
1845   "R" gnus-summary-limit-to-recipient)
1846
1847 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1848   "n" gnus-summary-next-unread-article
1849   "p" gnus-summary-prev-unread-article
1850   "N" gnus-summary-next-article
1851   "P" gnus-summary-prev-article
1852   "\C-n" gnus-summary-next-same-subject
1853   "\C-p" gnus-summary-prev-same-subject
1854   "\M-n" gnus-summary-next-unread-subject
1855   "\M-p" gnus-summary-prev-unread-subject
1856   "f" gnus-summary-first-unread-article
1857   "b" gnus-summary-best-unread-article
1858   "j" gnus-summary-goto-article
1859   "g" gnus-summary-goto-subject
1860   "l" gnus-summary-goto-last-article
1861   "o" gnus-summary-pop-article)
1862
1863 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1864   "k" gnus-summary-kill-thread
1865   "l" gnus-summary-lower-thread
1866   "i" gnus-summary-raise-thread
1867   "T" gnus-summary-toggle-threads
1868   "t" gnus-summary-rethread-current
1869   "^" gnus-summary-reparent-thread
1870   "s" gnus-summary-show-thread
1871   "S" gnus-summary-show-all-threads
1872   "h" gnus-summary-hide-thread
1873   "H" gnus-summary-hide-all-threads
1874   "n" gnus-summary-next-thread
1875   "p" gnus-summary-prev-thread
1876   "u" gnus-summary-up-thread
1877   "o" gnus-summary-top-thread
1878   "d" gnus-summary-down-thread
1879   "#" gnus-uu-mark-thread
1880   "\M-#" gnus-uu-unmark-thread)
1881
1882 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1883   "g" gnus-summary-prepare
1884   "c" gnus-summary-insert-cached-articles
1885   "d" gnus-summary-insert-dormant-articles)
1886
1887 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1888   "c" gnus-summary-catchup-and-exit
1889   "C" gnus-summary-catchup-all-and-exit
1890   "E" gnus-summary-exit-no-update
1891   "Q" gnus-summary-exit
1892   "Z" gnus-summary-exit
1893   "n" gnus-summary-catchup-and-goto-next-group
1894   "R" gnus-summary-reselect-current-group
1895   "G" gnus-summary-rescan-group
1896   "N" gnus-summary-next-group
1897   "s" gnus-summary-save-newsrc
1898   "P" gnus-summary-prev-group)
1899
1900 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1901   " " gnus-summary-next-page
1902   "n" gnus-summary-next-page
1903   "\177" gnus-summary-prev-page
1904   [delete] gnus-summary-prev-page
1905   "p" gnus-summary-prev-page
1906   "\r" gnus-summary-scroll-up
1907   "\M-\r" gnus-summary-scroll-down
1908   "<" gnus-summary-beginning-of-article
1909   ">" gnus-summary-end-of-article
1910   "b" gnus-summary-beginning-of-article
1911   "e" gnus-summary-end-of-article
1912   "^" gnus-summary-refer-parent-article
1913   "r" gnus-summary-refer-parent-article
1914   "D" gnus-summary-enter-digest-group
1915   "R" gnus-summary-refer-references
1916   "T" gnus-summary-refer-thread
1917   "g" gnus-summary-show-article
1918   "s" gnus-summary-isearch-article
1919   "P" gnus-summary-print-article
1920   "M" gnus-mailing-list-insinuate
1921   "t" gnus-article-babel)
1922
1923 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1924   "b" gnus-article-add-buttons
1925   "B" gnus-article-add-buttons-to-head
1926   "o" gnus-article-treat-overstrike
1927   "e" gnus-article-emphasize
1928   "w" gnus-article-fill-cited-article
1929   "Q" gnus-article-fill-long-lines
1930   "C" gnus-article-capitalize-sentences
1931   "c" gnus-article-remove-cr
1932   "q" gnus-article-de-quoted-unreadable
1933   "6" gnus-article-de-base64-unreadable
1934   "Z" gnus-article-decode-HZ
1935   "A" gnus-article-treat-ansi-sequences
1936   "h" gnus-article-wash-html
1937   "u" gnus-article-unsplit-urls
1938   "s" gnus-summary-force-verify-and-decrypt
1939   "f" gnus-article-display-x-face
1940   "l" gnus-summary-stop-page-breaking
1941   "r" gnus-summary-caesar-message
1942   "m" gnus-summary-morse-message
1943   "t" gnus-summary-toggle-header
1944   "g" gnus-treat-smiley
1945   "v" gnus-summary-verbose-headers
1946   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1947   "p" gnus-article-verify-x-pgp-sig
1948   "d" gnus-article-treat-dumbquotes)
1949
1950 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1951   ;; mnemonic: deuglif*Y*
1952   "u" gnus-article-outlook-unwrap-lines
1953   "a" gnus-article-outlook-repair-attribution
1954   "c" gnus-article-outlook-rearrange-citation
1955   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1956
1957 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1958   "a" gnus-article-hide
1959   "h" gnus-article-hide-headers
1960   "b" gnus-article-hide-boring-headers
1961   "s" gnus-article-hide-signature
1962   "c" gnus-article-hide-citation
1963   "C" gnus-article-hide-citation-in-followups
1964   "l" gnus-article-hide-list-identifiers
1965   "B" gnus-article-strip-banner
1966   "P" gnus-article-hide-pem
1967   "\C-c" gnus-article-hide-citation-maybe)
1968
1969 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1970   "a" gnus-article-highlight
1971   "h" gnus-article-highlight-headers
1972   "c" gnus-article-highlight-citation
1973   "s" gnus-article-highlight-signature)
1974
1975 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1976   "f" gnus-article-treat-fold-headers
1977   "u" gnus-article-treat-unfold-headers
1978   "n" gnus-article-treat-fold-newsgroups)
1979
1980 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1981   "x" gnus-article-display-x-face
1982   "d" gnus-article-display-face
1983   "s" gnus-treat-smiley
1984   "D" gnus-article-remove-images
1985   "f" gnus-treat-from-picon
1986   "m" gnus-treat-mail-picon
1987   "n" gnus-treat-newsgroups-picon)
1988
1989 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1990   "w" gnus-article-decode-mime-words
1991   "c" gnus-article-decode-charset
1992   "v" gnus-mime-view-all-parts
1993   "b" gnus-article-view-part)
1994
1995 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1996   "z" gnus-article-date-ut
1997   "u" gnus-article-date-ut
1998   "l" gnus-article-date-local
1999   "p" gnus-article-date-english
2000   "e" gnus-article-date-lapsed
2001   "o" gnus-article-date-original
2002   "i" gnus-article-date-iso8601
2003   "s" gnus-article-date-user)
2004
2005 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2006   "t" gnus-article-remove-trailing-blank-lines
2007   "l" gnus-article-strip-leading-blank-lines
2008   "m" gnus-article-strip-multiple-blank-lines
2009   "a" gnus-article-strip-blank-lines
2010   "A" gnus-article-strip-all-blank-lines
2011   "s" gnus-article-strip-leading-space
2012   "e" gnus-article-strip-trailing-space
2013   "w" gnus-article-remove-leading-whitespace)
2014
2015 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2016   "v" gnus-version
2017   "f" gnus-summary-fetch-faq
2018   "d" gnus-summary-describe-group
2019   "h" gnus-summary-describe-briefly
2020   "i" gnus-info-find-node
2021   "c" gnus-group-fetch-charter
2022   "C" gnus-group-fetch-control)
2023
2024 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2025   "e" gnus-summary-expire-articles
2026   "\M-\C-e" gnus-summary-expire-articles-now
2027   "\177" gnus-summary-delete-article
2028   [delete] gnus-summary-delete-article
2029   [backspace] gnus-summary-delete-article
2030   "m" gnus-summary-move-article
2031   "r" gnus-summary-respool-article
2032   "w" gnus-summary-edit-article
2033   "c" gnus-summary-copy-article
2034   "B" gnus-summary-crosspost-article
2035   "q" gnus-summary-respool-query
2036   "t" gnus-summary-respool-trace
2037   "i" gnus-summary-import-article
2038   "I" gnus-summary-create-article
2039   "p" gnus-summary-article-posted-p)
2040
2041 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2042   "o" gnus-summary-save-article
2043   "m" gnus-summary-save-article-mail
2044   "F" gnus-summary-write-article-file
2045   "r" gnus-summary-save-article-rmail
2046   "f" gnus-summary-save-article-file
2047   "b" gnus-summary-save-article-body-file
2048   "h" gnus-summary-save-article-folder
2049   "v" gnus-summary-save-article-vm
2050   "p" gnus-summary-pipe-output
2051   "P" gnus-summary-muttprint
2052   "s" gnus-soup-add-article)
2053
2054 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2055   "b" gnus-summary-display-buttonized
2056   "m" gnus-summary-repair-multipart
2057   "v" gnus-article-view-part
2058   "o" gnus-article-save-part
2059   "c" gnus-article-copy-part
2060   "C" gnus-article-view-part-as-charset
2061   "e" gnus-article-view-part-externally
2062   "E" gnus-article-encrypt-body
2063   "i" gnus-article-inline-part
2064   "|" gnus-article-pipe-part)
2065
2066 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2067   "p" gnus-summary-mark-as-processable
2068   "u" gnus-summary-unmark-as-processable
2069   "U" gnus-summary-unmark-all-processable
2070   "v" gnus-uu-mark-over
2071   "s" gnus-uu-mark-series
2072   "r" gnus-uu-mark-region
2073   "g" gnus-uu-unmark-region
2074   "R" gnus-uu-mark-by-regexp
2075   "G" gnus-uu-unmark-by-regexp
2076   "t" gnus-uu-mark-thread
2077   "T" gnus-uu-unmark-thread
2078   "a" gnus-uu-mark-all
2079   "b" gnus-uu-mark-buffer
2080   "S" gnus-uu-mark-sparse
2081   "k" gnus-summary-kill-process-mark
2082   "y" gnus-summary-yank-process-mark
2083   "w" gnus-summary-save-process-mark
2084   "i" gnus-uu-invert-processable)
2085
2086 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2087   ;;"x" gnus-uu-extract-any
2088   "m" gnus-summary-save-parts
2089   "u" gnus-uu-decode-uu
2090   "U" gnus-uu-decode-uu-and-save
2091   "s" gnus-uu-decode-unshar
2092   "S" gnus-uu-decode-unshar-and-save
2093   "o" gnus-uu-decode-save
2094   "O" gnus-uu-decode-save
2095   "b" gnus-uu-decode-binhex
2096   "B" gnus-uu-decode-binhex
2097   "p" gnus-uu-decode-postscript
2098   "P" gnus-uu-decode-postscript-and-save)
2099
2100 (gnus-define-keys
2101     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2102   "u" gnus-uu-decode-uu-view
2103   "U" gnus-uu-decode-uu-and-save-view
2104   "s" gnus-uu-decode-unshar-view
2105   "S" gnus-uu-decode-unshar-and-save-view
2106   "o" gnus-uu-decode-save-view
2107   "O" gnus-uu-decode-save-view
2108   "b" gnus-uu-decode-binhex-view
2109   "B" gnus-uu-decode-binhex-view
2110   "p" gnus-uu-decode-postscript-view
2111   "P" gnus-uu-decode-postscript-and-save-view)
2112
2113 (defvar gnus-article-post-menu nil)
2114
2115 (defconst gnus-summary-menu-maxlen 20)
2116
2117 (defun gnus-summary-menu-split (menu)
2118   ;; If we have lots of elements, divide them into groups of 20
2119   ;; and make a pane (or submenu) for each one.
2120   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2121       (let ((menu menu) sublists next
2122             (i 1))
2123         (while menu
2124           ;; Pull off the next gnus-summary-menu-maxlen elements
2125           ;; and make them the next element of sublist.
2126           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2127           (if next
2128               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2129                       nil))
2130           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2131                                              (aref (car (last menu)) 0)) menu)
2132                                sublists))
2133           (setq i (1+ i))
2134           (setq menu next))
2135         (nreverse sublists))
2136     ;; Few elements--put them all in one pane.
2137     menu))
2138
2139 (defun gnus-summary-make-menu-bar ()
2140   (gnus-turn-off-edit-menu 'summary)
2141
2142   (unless (boundp 'gnus-summary-misc-menu)
2143
2144     (easy-menu-define
2145       gnus-summary-kill-menu gnus-summary-mode-map ""
2146       (cons
2147        "Score"
2148        (nconc
2149         (list
2150          ["Customize" gnus-score-customize t])
2151         (gnus-make-score-map 'increase)
2152         (gnus-make-score-map 'lower)
2153         '(("Mark"
2154            ["Kill below" gnus-summary-kill-below t]
2155            ["Mark above" gnus-summary-mark-above t]
2156            ["Tick above" gnus-summary-tick-above t]
2157            ["Clear above" gnus-summary-clear-above t])
2158           ["Current score" gnus-summary-current-score t]
2159           ["Set score" gnus-summary-set-score t]
2160           ["Switch current score file..." gnus-score-change-score-file t]
2161           ["Set mark below..." gnus-score-set-mark-below t]
2162           ["Set expunge below..." gnus-score-set-expunge-below t]
2163           ["Edit current score file" gnus-score-edit-current-scores t]
2164           ["Edit score file" gnus-score-edit-file t]
2165           ["Trace score" gnus-score-find-trace t]
2166           ["Find words" gnus-score-find-favourite-words t]
2167           ["Rescore buffer" gnus-summary-rescore t]
2168           ["Increase score..." gnus-summary-increase-score t]
2169           ["Lower score..." gnus-summary-lower-score t]))))
2170
2171     ;; Define both the Article menu in the summary buffer and the
2172     ;; equivalent Commands menu in the article buffer here for
2173     ;; consistency.
2174     (let ((innards
2175            `(("Hide"
2176               ["All" gnus-article-hide t]
2177               ["Headers" gnus-article-hide-headers t]
2178               ["Signature" gnus-article-hide-signature t]
2179               ["Citation" gnus-article-hide-citation t]
2180               ["List identifiers" gnus-article-hide-list-identifiers t]
2181               ["Banner" gnus-article-strip-banner t]
2182               ["Boring headers" gnus-article-hide-boring-headers t])
2183              ("Highlight"
2184               ["All" gnus-article-highlight t]
2185               ["Headers" gnus-article-highlight-headers t]
2186               ["Signature" gnus-article-highlight-signature t]
2187               ["Citation" gnus-article-highlight-citation t])
2188              ("MIME"
2189               ["Words" gnus-article-decode-mime-words t]
2190               ["Charset" gnus-article-decode-charset t]
2191               ["QP" gnus-article-de-quoted-unreadable t]
2192               ["Base64" gnus-article-de-base64-unreadable t]
2193               ["View MIME buttons" gnus-summary-display-buttonized t]
2194               ["View all" gnus-mime-view-all-parts t]
2195               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2196               ["Encrypt body" gnus-article-encrypt-body
2197                :active (not (gnus-group-read-only-p))
2198                ,@(if (featurep 'xemacs) nil
2199                    '(:help "Encrypt the message body on disk"))]
2200               ["Extract all parts..." gnus-summary-save-parts t]
2201               ("Multipart"
2202                ["Repair multipart" gnus-summary-repair-multipart t]
2203                ["Pipe part..." gnus-article-pipe-part t]
2204                ["Inline part" gnus-article-inline-part t]
2205                ["Encrypt body" gnus-article-encrypt-body
2206                 :active (not (gnus-group-read-only-p))
2207                ,@(if (featurep 'xemacs) nil
2208                    '(:help "Encrypt the message body on disk"))]
2209                ["View part externally" gnus-article-view-part-externally t]
2210                ["View part with charset..." gnus-article-view-part-as-charset t]
2211                ["Copy part" gnus-article-copy-part t]
2212                ["Save part..." gnus-article-save-part t]
2213                ["View part" gnus-article-view-part t]))
2214              ("Date"
2215               ["Local" gnus-article-date-local t]
2216               ["ISO8601" gnus-article-date-iso8601 t]
2217               ["UT" gnus-article-date-ut t]
2218               ["Original" gnus-article-date-original t]
2219               ["Lapsed" gnus-article-date-lapsed t]
2220               ["User-defined" gnus-article-date-user t])
2221              ("Display"
2222               ["Remove images" gnus-article-remove-images t]
2223               ["Toggle smiley" gnus-treat-smiley t]
2224               ["Show X-Face" gnus-article-display-x-face t]
2225               ["Show picons in From" gnus-treat-from-picon t]
2226               ["Show picons in mail headers" gnus-treat-mail-picon t]
2227               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2228               ("View as different encoding"
2229                ,@(gnus-summary-menu-split
2230                   (mapcar
2231                    (lambda (cs)
2232                      ;; Since easymenu under Emacs doesn't allow
2233                      ;; lambda forms for menu commands, we should
2234                      ;; provide intern'ed function symbols.
2235                      (let ((command (intern (format "\
2236 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2237                        (fset command
2238                              `(lambda ()
2239                                 (interactive)
2240                                 (let ((gnus-summary-show-article-charset-alist
2241                                        '((1 . ,cs))))
2242                                   (gnus-summary-show-article 1))))
2243                        `[,(symbol-name cs) ,command t]))
2244                    (sort (if (fboundp 'coding-system-list)
2245                              (coding-system-list)
2246                            (mapcar 'car mm-mime-mule-charset-alist))
2247                          'string<)))))
2248              ("Washing"
2249               ("Remove Blanks"
2250                ["Leading" gnus-article-strip-leading-blank-lines t]
2251                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2252                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2253                ["All of the above" gnus-article-strip-blank-lines t]
2254                ["All" gnus-article-strip-all-blank-lines t]
2255                ["Leading space" gnus-article-strip-leading-space t]
2256                ["Trailing space" gnus-article-strip-trailing-space t]
2257                ["Leading space in headers"
2258                 gnus-article-remove-leading-whitespace t])
2259               ["Overstrike" gnus-article-treat-overstrike t]
2260               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2261               ["Emphasis" gnus-article-emphasize t]
2262               ["Word wrap" gnus-article-fill-cited-article t]
2263               ["Fill long lines" gnus-article-fill-long-lines t]
2264               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2265               ["Remove CR" gnus-article-remove-cr t]
2266               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2267               ["Base64" gnus-article-de-base64-unreadable t]
2268               ["Rot 13" gnus-summary-caesar-message
2269                ,@(if (featurep 'xemacs) '(t)
2270                    '(:help "\"Caesar rotate\" article by 13"))]
2271               ["Morse decode" gnus-summary-morse-message t]
2272               ["Unix pipe..." gnus-summary-pipe-message t]
2273               ["Add buttons" gnus-article-add-buttons t]
2274               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2275               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2276               ["Verbose header" gnus-summary-verbose-headers t]
2277               ["Toggle header" gnus-summary-toggle-header t]
2278               ["Unfold headers" gnus-article-treat-unfold-headers t]
2279               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2280               ["Html" gnus-article-wash-html t]
2281               ["Unsplit URLs" gnus-article-unsplit-urls t]
2282               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2283               ["Decode HZ" gnus-article-decode-HZ t]
2284               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2285               ("(Outlook) Deuglify"
2286                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2287                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2288                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2289                ["Full (Outlook) deuglify"
2290                 gnus-article-outlook-deuglify-article t])
2291               )
2292              ("Output"
2293               ["Save in default format..." gnus-summary-save-article
2294                ,@(if (featurep 'xemacs) '(t)
2295                    '(:help "Save article using default method"))]
2296               ["Save in file..." gnus-summary-save-article-file
2297                ,@(if (featurep 'xemacs) '(t)
2298                    '(:help "Save article in file"))]
2299               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2300               ["Save in MH folder..." gnus-summary-save-article-folder t]
2301               ["Save in VM folder..." gnus-summary-save-article-vm t]
2302               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2303               ["Save body in file..." gnus-summary-save-article-body-file t]
2304               ["Pipe through a filter..." gnus-summary-pipe-output t]
2305               ["Add to SOUP packet" gnus-soup-add-article t]
2306               ["Print with Muttprint..." gnus-summary-muttprint t]
2307               ["Print" gnus-summary-print-article
2308                ,@(if (featurep 'xemacs) '(t)
2309                    '(:help "Generate and print a PostScript image"))])
2310              ("Copy, move,... (Backend)"
2311               ,@(if (featurep 'xemacs) nil
2312                   '(:help "Copying, moving, expiring articles..."))
2313               ["Respool article..." gnus-summary-respool-article t]
2314               ["Move article..." gnus-summary-move-article
2315                (gnus-check-backend-function
2316                 'request-move-article gnus-newsgroup-name)]
2317               ["Copy article..." gnus-summary-copy-article t]
2318               ["Crosspost article..." gnus-summary-crosspost-article
2319                (gnus-check-backend-function
2320                 'request-replace-article gnus-newsgroup-name)]
2321               ["Import file..." gnus-summary-import-article
2322                (gnus-check-backend-function
2323                 'request-accept-article gnus-newsgroup-name)]
2324               ["Create article..." gnus-summary-create-article
2325                (gnus-check-backend-function
2326                 'request-accept-article gnus-newsgroup-name)]
2327               ["Check if posted" gnus-summary-article-posted-p t]
2328               ["Edit article" gnus-summary-edit-article
2329                (not (gnus-group-read-only-p))]
2330               ["Delete article" gnus-summary-delete-article
2331                (gnus-check-backend-function
2332                 'request-expire-articles gnus-newsgroup-name)]
2333               ["Query respool" gnus-summary-respool-query t]
2334               ["Trace respool" gnus-summary-respool-trace t]
2335               ["Delete expirable articles" gnus-summary-expire-articles-now
2336                (gnus-check-backend-function
2337                 'request-expire-articles gnus-newsgroup-name)])
2338              ("Extract"
2339               ["Uudecode" gnus-uu-decode-uu
2340                ,@(if (featurep 'xemacs) '(t)
2341                    '(:help "Decode uuencoded article(s)"))]
2342               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2343               ["Unshar" gnus-uu-decode-unshar t]
2344               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2345               ["Save" gnus-uu-decode-save t]
2346               ["Binhex" gnus-uu-decode-binhex t]
2347               ["Postscript" gnus-uu-decode-postscript t]
2348               ["All MIME parts" gnus-summary-save-parts t])
2349              ("Cache"
2350               ["Enter article" gnus-cache-enter-article t]
2351               ["Remove article" gnus-cache-remove-article t])
2352              ["Translate" gnus-article-babel t]
2353              ["Select article buffer" gnus-summary-select-article-buffer t]
2354              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2355              ["Isearch article..." gnus-summary-isearch-article t]
2356              ["Beginning of the article" gnus-summary-beginning-of-article t]
2357              ["End of the article" gnus-summary-end-of-article t]
2358              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2359              ["Fetch referenced articles" gnus-summary-refer-references t]
2360              ["Fetch current thread" gnus-summary-refer-thread t]
2361              ["Fetch article with id..." gnus-summary-refer-article t]
2362              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2363              ["Redisplay" gnus-summary-show-article t]
2364              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2365       (easy-menu-define
2366         gnus-summary-article-menu gnus-summary-mode-map ""
2367         (cons "Article" innards))
2368
2369       (if (not (keymapp gnus-summary-article-menu))
2370           (easy-menu-define
2371             gnus-article-commands-menu gnus-article-mode-map ""
2372             (cons "Commands" innards))
2373         ;; in Emacs, don't share menu.
2374         (setq gnus-article-commands-menu
2375               (copy-keymap gnus-summary-article-menu))
2376         (define-key gnus-article-mode-map [menu-bar commands]
2377           (cons "Commands" gnus-article-commands-menu))))
2378
2379     (easy-menu-define
2380       gnus-summary-thread-menu gnus-summary-mode-map ""
2381       '("Threads"
2382         ["Find all messages in thread" gnus-summary-refer-thread t]
2383         ["Toggle threading" gnus-summary-toggle-threads t]
2384         ["Hide threads" gnus-summary-hide-all-threads t]
2385         ["Show threads" gnus-summary-show-all-threads t]
2386         ["Hide thread" gnus-summary-hide-thread t]
2387         ["Show thread" gnus-summary-show-thread t]
2388         ["Go to next thread" gnus-summary-next-thread t]
2389         ["Go to previous thread" gnus-summary-prev-thread t]
2390         ["Go down thread" gnus-summary-down-thread t]
2391         ["Go up thread" gnus-summary-up-thread t]
2392         ["Top of thread" gnus-summary-top-thread t]
2393         ["Mark thread as read" gnus-summary-kill-thread t]
2394         ["Lower thread score" gnus-summary-lower-thread t]
2395         ["Raise thread score" gnus-summary-raise-thread t]
2396         ["Rethread current" gnus-summary-rethread-current t]))
2397
2398     (easy-menu-define
2399       gnus-summary-post-menu gnus-summary-mode-map ""
2400       `("Post"
2401         ["Send a message (mail or news)" gnus-summary-post-news
2402          ,@(if (featurep 'xemacs) '(t)
2403              '(:help "Compose a new message (mail or news)"))]
2404         ["Followup" gnus-summary-followup
2405          ,@(if (featurep 'xemacs) '(t)
2406              '(:help "Post followup to this article"))]
2407         ["Followup and yank" gnus-summary-followup-with-original
2408          ,@(if (featurep 'xemacs) '(t)
2409              '(:help "Post followup to this article, quoting its contents"))]
2410         ["Supersede article" gnus-summary-supersede-article t]
2411         ["Cancel article" gnus-summary-cancel-article
2412          ,@(if (featurep 'xemacs) '(t)
2413              '(:help "Cancel an article you posted"))]
2414         ["Reply" gnus-summary-reply t]
2415         ["Reply and yank" gnus-summary-reply-with-original t]
2416         ["Wide reply" gnus-summary-wide-reply t]
2417         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2418          ,@(if (featurep 'xemacs) '(t)
2419              '(:help "Mail a reply, quoting this article"))]
2420         ["Very wide reply" gnus-summary-very-wide-reply t]
2421         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2422          ,@(if (featurep 'xemacs) '(t)
2423              '(:help "Mail a very wide reply, quoting this article"))]
2424         ["Mail forward" gnus-summary-mail-forward t]
2425         ["Post forward" gnus-summary-post-forward t]
2426         ["Digest and mail" gnus-uu-digest-mail-forward t]
2427         ["Digest and post" gnus-uu-digest-post-forward t]
2428         ["Resend message" gnus-summary-resend-message t]
2429         ["Resend message edit" gnus-summary-resend-message-edit t]
2430         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2431         ["Send a mail" gnus-summary-mail-other-window t]
2432         ["Create a local message" gnus-summary-news-other-window t]
2433         ["Uuencode and post" gnus-uu-post-news
2434          ,@(if (featurep 'xemacs) '(t)
2435              '(:help "Post a uuencoded article"))]
2436         ["Followup via news" gnus-summary-followup-to-mail t]
2437         ["Followup via news and yank"
2438          gnus-summary-followup-to-mail-with-original t]
2439         ;;("Draft"
2440         ;;["Send" gnus-summary-send-draft t]
2441         ;;["Send bounced" gnus-resend-bounced-mail t])
2442         ))
2443
2444     (cond
2445      ((not (keymapp gnus-summary-post-menu))
2446       (setq gnus-article-post-menu gnus-summary-post-menu))
2447      ((not gnus-article-post-menu)
2448       ;; Don't share post menu.
2449       (setq gnus-article-post-menu
2450             (copy-keymap gnus-summary-post-menu))))
2451     (define-key gnus-article-mode-map [menu-bar post]
2452       (cons "Post" gnus-article-post-menu))
2453
2454     (easy-menu-define
2455       gnus-summary-misc-menu gnus-summary-mode-map ""
2456       `("Gnus"
2457         ("Mark Read"
2458          ["Mark as read" gnus-summary-mark-as-read-forward t]
2459          ["Mark same subject and select"
2460           gnus-summary-kill-same-subject-and-select t]
2461          ["Mark same subject" gnus-summary-kill-same-subject t]
2462          ["Catchup" gnus-summary-catchup
2463           ,@(if (featurep 'xemacs) '(t)
2464               '(:help "Mark unread articles in this group as read"))]
2465          ["Catchup all" gnus-summary-catchup-all t]
2466          ["Catchup to here" gnus-summary-catchup-to-here t]
2467          ["Catchup from here" gnus-summary-catchup-from-here t]
2468          ["Catchup region" gnus-summary-mark-region-as-read
2469           (gnus-mark-active-p)]
2470          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2471         ("Mark Various"
2472          ["Tick" gnus-summary-tick-article-forward t]
2473          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2474          ["Remove marks" gnus-summary-clear-mark-forward t]
2475          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2476          ["Set bookmark" gnus-summary-set-bookmark t]
2477          ["Remove bookmark" gnus-summary-remove-bookmark t])
2478         ("Limit to"
2479          ["Marks..." gnus-summary-limit-to-marks t]
2480          ["Subject..." gnus-summary-limit-to-subject t]
2481          ["Author..." gnus-summary-limit-to-author t]
2482          ["Recipient..." gnus-summary-limit-to-recipient t]
2483          ["Age..." gnus-summary-limit-to-age t]
2484          ["Extra..." gnus-summary-limit-to-extra t]
2485          ["Score..." gnus-summary-limit-to-score t]
2486          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2487          ["Unread" gnus-summary-limit-to-unread t]
2488          ["Unseen" gnus-summary-limit-to-unseen t]
2489          ["Replied" gnus-summary-limit-to-replied t]
2490          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2491          ["Next articles" gnus-summary-limit-to-articles t]
2492          ["Pop limit" gnus-summary-pop-limit t]
2493          ["Show dormant" gnus-summary-limit-include-dormant t]
2494          ["Hide childless dormant"
2495           gnus-summary-limit-exclude-childless-dormant t]
2496          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2497          ["Hide marked" gnus-summary-limit-exclude-marks t]
2498          ["Show expunged" gnus-summary-limit-include-expunged t])
2499         ("Process Mark"
2500          ["Set mark" gnus-summary-mark-as-processable t]
2501          ["Remove mark" gnus-summary-unmark-as-processable t]
2502          ["Remove all marks" gnus-summary-unmark-all-processable t]
2503          ["Invert marks" gnus-uu-invert-processable t]
2504          ["Mark above" gnus-uu-mark-over t]
2505          ["Mark series" gnus-uu-mark-series t]
2506          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2507          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2508          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2509          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2510          ["Mark all" gnus-uu-mark-all t]
2511          ["Mark buffer" gnus-uu-mark-buffer t]
2512          ["Mark sparse" gnus-uu-mark-sparse t]
2513          ["Mark thread" gnus-uu-mark-thread t]
2514          ["Unmark thread" gnus-uu-unmark-thread t]
2515          ("Process Mark Sets"
2516           ["Kill" gnus-summary-kill-process-mark t]
2517           ["Yank" gnus-summary-yank-process-mark
2518            gnus-newsgroup-process-stack]
2519           ["Save" gnus-summary-save-process-mark t]
2520           ["Run command on marked..." gnus-summary-universal-argument t]))
2521         ("Scroll article"
2522          ["Page forward" gnus-summary-next-page
2523           ,@(if (featurep 'xemacs) '(t)
2524               '(:help "Show next page of article"))]
2525          ["Page backward" gnus-summary-prev-page
2526           ,@(if (featurep 'xemacs) '(t)
2527               '(:help "Show previous page of article"))]
2528          ["Line forward" gnus-summary-scroll-up t])
2529         ("Move"
2530          ["Next unread article" gnus-summary-next-unread-article t]
2531          ["Previous unread article" gnus-summary-prev-unread-article t]
2532          ["Next article" gnus-summary-next-article t]
2533          ["Previous article" gnus-summary-prev-article t]
2534          ["Next unread subject" gnus-summary-next-unread-subject t]
2535          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2536          ["Next article same subject" gnus-summary-next-same-subject t]
2537          ["Previous article same subject" gnus-summary-prev-same-subject t]
2538          ["First unread article" gnus-summary-first-unread-article t]
2539          ["Best unread article" gnus-summary-best-unread-article t]
2540          ["Go to subject number..." gnus-summary-goto-subject t]
2541          ["Go to article number..." gnus-summary-goto-article t]
2542          ["Go to the last article" gnus-summary-goto-last-article t]
2543          ["Pop article off history" gnus-summary-pop-article t])
2544         ("Sort"
2545          ["Sort by number" gnus-summary-sort-by-number t]
2546          ["Sort by author" gnus-summary-sort-by-author t]
2547          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2548          ["Sort by subject" gnus-summary-sort-by-subject t]
2549          ["Sort by date" gnus-summary-sort-by-date t]
2550          ["Sort by score" gnus-summary-sort-by-score t]
2551          ["Sort by lines" gnus-summary-sort-by-lines t]
2552          ["Sort by characters" gnus-summary-sort-by-chars t]
2553          ["Randomize" gnus-summary-sort-by-random t]
2554          ["Original sort" gnus-summary-sort-by-original t])
2555         ("Help"
2556          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2557          ["Describe group" gnus-summary-describe-group t]
2558          ["Fetch charter" gnus-group-fetch-charter
2559           ,@(if (featurep 'xemacs) nil
2560               '(:help "Display the charter of the current group"))]
2561          ["Fetch control message" gnus-group-fetch-control
2562           ,@(if (featurep 'xemacs) nil
2563               '(:help "Display the archived control message for the current group"))]
2564          ["Read manual" gnus-info-find-node t])
2565         ("Modes"
2566          ["Pick and read" gnus-pick-mode t]
2567          ["Binary" gnus-binary-mode t])
2568         ("Regeneration"
2569          ["Regenerate" gnus-summary-prepare t]
2570          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2571          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2572          ["Toggle threading" gnus-summary-toggle-threads t])
2573         ["See old articles" gnus-summary-insert-old-articles t]
2574         ["See new articles" gnus-summary-insert-new-articles t]
2575         ["Filter articles..." gnus-summary-execute-command t]
2576         ["Run command on articles..." gnus-summary-universal-argument t]
2577         ["Search articles forward..." gnus-summary-search-article-forward t]
2578         ["Search articles backward..." gnus-summary-search-article-backward t]
2579         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2580         ["Expand window" gnus-summary-expand-window t]
2581         ["Expire expirable articles" gnus-summary-expire-articles
2582          (gnus-check-backend-function
2583           'request-expire-articles gnus-newsgroup-name)]
2584         ["Edit local kill file" gnus-summary-edit-local-kill t]
2585         ["Edit main kill file" gnus-summary-edit-global-kill t]
2586         ["Edit group parameters" gnus-summary-edit-parameters t]
2587         ["Customize group parameters" gnus-summary-customize-parameters t]
2588         ["Send a bug report" gnus-bug t]
2589         ("Exit"
2590          ["Catchup and exit" gnus-summary-catchup-and-exit
2591           ,@(if (featurep 'xemacs) '(t)
2592               '(:help "Mark unread articles in this group as read, then exit"))]
2593          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2594          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2595          ["Exit group" gnus-summary-exit
2596           ,@(if (featurep 'xemacs) '(t)
2597               '(:help "Exit current group, return to group selection mode"))]
2598          ["Exit group without updating" gnus-summary-exit-no-update t]
2599          ["Exit and goto next group" gnus-summary-next-group t]
2600          ["Exit and goto prev group" gnus-summary-prev-group t]
2601          ["Reselect group" gnus-summary-reselect-current-group t]
2602          ["Rescan group" gnus-summary-rescan-group t]
2603          ["Update dribble" gnus-summary-save-newsrc t])))
2604
2605     (gnus-run-hooks 'gnus-summary-menu-hook)))
2606
2607 (defvar gnus-summary-tool-bar-map nil)
2608
2609 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2610 (defun gnus-summary-make-tool-bar ()
2611   (if (and (fboundp 'tool-bar-add-item-from-menu)
2612            (default-value 'tool-bar-mode)
2613            (not gnus-summary-tool-bar-map))
2614       (setq gnus-summary-tool-bar-map
2615             (let ((tool-bar-map (make-sparse-keymap))
2616                   (load-path (mm-image-load-path)))
2617               (tool-bar-add-item-from-menu
2618                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-post-news "post" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-summary-followup "followup" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-reply "reply" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2633               (tool-bar-add-item-from-menu
2634                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2635               (tool-bar-add-item-from-menu
2636                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2637               (tool-bar-add-item-from-menu
2638                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2639               (tool-bar-add-item-from-menu
2640                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2641               (tool-bar-add-item-from-menu
2642                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2643               (tool-bar-add-item-from-menu
2644                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2645               (tool-bar-add-item-from-menu
2646                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2647               (tool-bar-add-item-from-menu
2648                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2649               tool-bar-map)))
2650   (if gnus-summary-tool-bar-map
2651       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2652
2653 (defun gnus-score-set-default (var value)
2654   "A version of set that updates the GNU Emacs menu-bar."
2655   (set var value)
2656   ;; It is the message that forces the active status to be updated.
2657   (message ""))
2658
2659 (defun gnus-make-score-map (type)
2660   "Make a summary score map of type TYPE."
2661   (if t
2662       nil
2663     (let ((headers '(("author" "from" string)
2664                      ("subject" "subject" string)
2665                      ("article body" "body" string)
2666                      ("article head" "head" string)
2667                      ("xref" "xref" string)
2668                      ("extra header" "extra" string)
2669                      ("lines" "lines" number)
2670                      ("followups to author" "followup" string)))
2671           (types '((number ("less than" <)
2672                            ("greater than" >)
2673                            ("equal" =))
2674                    (string ("substring" s)
2675                            ("exact string" e)
2676                            ("fuzzy string" f)
2677                            ("regexp" r))))
2678           (perms '(("temporary" (current-time-string))
2679                    ("permanent" nil)
2680                    ("immediate" now)))
2681           header)
2682       (list
2683        (apply
2684         'nconc
2685         (list
2686          (if (eq type 'lower)
2687              "Lower score"
2688            "Increase score"))
2689         (let (outh)
2690           (while headers
2691             (setq header (car headers))
2692             (setq outh
2693                   (cons
2694                    (apply
2695                     'nconc
2696                     (list (car header))
2697                     (let ((ts (cdr (assoc (nth 2 header) types)))
2698                           outt)
2699                       (while ts
2700                         (setq outt
2701                               (cons
2702                                (apply
2703                                 'nconc
2704                                 (list (caar ts))
2705                                 (let ((ps perms)
2706                                       outp)
2707                                   (while ps
2708                                     (setq outp
2709                                           (cons
2710                                            (vector
2711                                             (caar ps)
2712                                             (list
2713                                              'gnus-summary-score-entry
2714                                              (nth 1 header)
2715                                              (if (or (string= (nth 1 header)
2716                                                               "head")
2717                                                      (string= (nth 1 header)
2718                                                               "body"))
2719                                                  ""
2720                                                (list 'gnus-summary-header
2721                                                      (nth 1 header)))
2722                                              (list 'quote (nth 1 (car ts)))
2723                                              (list 'gnus-score-delta-default
2724                                                    nil)
2725                                              (nth 1 (car ps))
2726                                              t)
2727                                             t)
2728                                            outp))
2729                                     (setq ps (cdr ps)))
2730                                   (list (nreverse outp))))
2731                                outt))
2732                         (setq ts (cdr ts)))
2733                       (list (nreverse outt))))
2734                    outh))
2735             (setq headers (cdr headers)))
2736           (list (nreverse outh))))))))
2737
2738 \f
2739
2740 (defun gnus-summary-mode (&optional group)
2741   "Major mode for reading articles.
2742
2743 All normal editing commands are switched off.
2744 \\<gnus-summary-mode-map>
2745 Each line in this buffer represents one article.  To read an
2746 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2747 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2748 respectively.
2749
2750 You can also post articles and send mail from this buffer.  To
2751 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2752 of an article, type `\\[gnus-summary-reply]'.
2753
2754 There are approx. one gazillion commands you can execute in this
2755 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2756
2757 The following commands are available:
2758
2759 \\{gnus-summary-mode-map}"
2760   (interactive)
2761   (kill-all-local-variables)
2762   (when (gnus-visual-p 'summary-menu 'menu)
2763     (gnus-summary-make-menu-bar)
2764     (gnus-summary-make-tool-bar))
2765   (gnus-summary-make-local-variables)
2766   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2767     (gnus-summary-make-local-variables))
2768   (gnus-make-thread-indent-array)
2769   (gnus-simplify-mode-line)
2770   (setq major-mode 'gnus-summary-mode)
2771   (setq mode-name "Summary")
2772   (make-local-variable 'minor-mode-alist)
2773   (use-local-map gnus-summary-mode-map)
2774   (buffer-disable-undo)
2775   (setq buffer-read-only t              ;Disable modification
2776         show-trailing-whitespace nil)
2777   (setq truncate-lines t)
2778   (setq selective-display t)
2779   (setq selective-display-ellipses t)   ;Display `...'
2780   (gnus-summary-set-display-table)
2781   (gnus-set-default-directory)
2782   (setq gnus-newsgroup-name group)
2783   (make-local-variable 'gnus-summary-line-format)
2784   (make-local-variable 'gnus-summary-line-format-spec)
2785   (make-local-variable 'gnus-summary-dummy-line-format)
2786   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2787   (make-local-variable 'gnus-summary-mark-positions)
2788   (gnus-make-local-hook 'pre-command-hook)
2789   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2790   (gnus-run-hooks 'gnus-summary-mode-hook)
2791   (turn-on-gnus-mailing-list-mode)
2792   (mm-enable-multibyte)
2793   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2794   (gnus-update-summary-mark-positions))
2795
2796 (defun gnus-summary-make-local-variables ()
2797   "Make all the local summary buffer variables."
2798   (let (global)
2799     (dolist (local gnus-summary-local-variables)
2800       (if (consp local)
2801           (progn
2802             (if (eq (cdr local) 'global)
2803                 ;; Copy the global value of the variable.
2804                 (setq global (symbol-value (car local)))
2805               ;; Use the value from the list.
2806               (setq global (eval (cdr local))))
2807             (set (make-local-variable (car local)) global))
2808         ;; Simple nil-valued local variable.
2809         (set (make-local-variable local) nil)))))
2810
2811 (defun gnus-summary-clear-local-variables ()
2812   (let ((locals gnus-summary-local-variables))
2813     (while locals
2814       (if (consp (car locals))
2815           (and (symbolp (caar locals))
2816                (set (caar locals) nil))
2817         (and (symbolp (car locals))
2818              (set (car locals) nil)))
2819       (setq locals (cdr locals)))))
2820
2821 ;; Summary data functions.
2822
2823 (defmacro gnus-data-number (data)
2824   `(car ,data))
2825
2826 (defmacro gnus-data-set-number (data number)
2827   `(setcar ,data ,number))
2828
2829 (defmacro gnus-data-mark (data)
2830   `(nth 1 ,data))
2831
2832 (defmacro gnus-data-set-mark (data mark)
2833   `(setcar (nthcdr 1 ,data) ,mark))
2834
2835 (defmacro gnus-data-pos (data)
2836   `(nth 2 ,data))
2837
2838 (defmacro gnus-data-set-pos (data pos)
2839   `(setcar (nthcdr 2 ,data) ,pos))
2840
2841 (defmacro gnus-data-header (data)
2842   `(nth 3 ,data))
2843
2844 (defmacro gnus-data-set-header (data header)
2845   `(setf (nth 3 ,data) ,header))
2846
2847 (defmacro gnus-data-level (data)
2848   `(nth 4 ,data))
2849
2850 (defmacro gnus-data-unread-p (data)
2851   `(= (nth 1 ,data) gnus-unread-mark))
2852
2853 (defmacro gnus-data-read-p (data)
2854   `(/= (nth 1 ,data) gnus-unread-mark))
2855
2856 (defmacro gnus-data-pseudo-p (data)
2857   `(consp (nth 3 ,data)))
2858
2859 (defmacro gnus-data-find (number)
2860   `(assq ,number gnus-newsgroup-data))
2861
2862 (defmacro gnus-data-find-list (number &optional data)
2863   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2864      (memq (assq ,number bdata)
2865            bdata)))
2866
2867 (defmacro gnus-data-make (number mark pos header level)
2868   `(list ,number ,mark ,pos ,header ,level))
2869
2870 (defun gnus-data-enter (after-article number mark pos header level offset)
2871   (let ((data (gnus-data-find-list after-article)))
2872     (unless data
2873       (error "No such article: %d" after-article))
2874     (setcdr data (cons (gnus-data-make number mark pos header level)
2875                        (cdr data)))
2876     (setq gnus-newsgroup-data-reverse nil)
2877     (gnus-data-update-list (cddr data) offset)))
2878
2879 (defun gnus-data-enter-list (after-article list &optional offset)
2880   (when list
2881     (let ((data (and after-article (gnus-data-find-list after-article)))
2882           (ilist list))
2883       (if (not (or data
2884                    after-article))
2885           (let ((odata gnus-newsgroup-data))
2886             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2887             (when offset
2888               (gnus-data-update-list odata offset)))
2889         ;; Find the last element in the list to be spliced into the main
2890         ;; list.
2891         (setq list (last list))
2892         (if (not data)
2893             (progn
2894               (setcdr list gnus-newsgroup-data)
2895               (setq gnus-newsgroup-data ilist)
2896               (when offset
2897                 (gnus-data-update-list (cdr list) offset)))
2898           (setcdr list (cdr data))
2899           (setcdr data ilist)
2900           (when offset
2901             (gnus-data-update-list (cdr list) offset))))
2902       (setq gnus-newsgroup-data-reverse nil))))
2903
2904 (defun gnus-data-remove (article &optional offset)
2905   (let ((data gnus-newsgroup-data))
2906     (if (= (gnus-data-number (car data)) article)
2907         (progn
2908           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2909                 gnus-newsgroup-data-reverse nil)
2910           (when offset
2911             (gnus-data-update-list gnus-newsgroup-data offset)))
2912       (while (cdr data)
2913         (when (= (gnus-data-number (cadr data)) article)
2914           (setcdr data (cddr data))
2915           (when offset
2916             (gnus-data-update-list (cdr data) offset))
2917           (setq data nil
2918                 gnus-newsgroup-data-reverse nil))
2919         (setq data (cdr data))))))
2920
2921 (defmacro gnus-data-list (backward)
2922   `(if ,backward
2923        (or gnus-newsgroup-data-reverse
2924            (setq gnus-newsgroup-data-reverse
2925                  (reverse gnus-newsgroup-data)))
2926      gnus-newsgroup-data))
2927
2928 (defun gnus-data-update-list (data offset)
2929   "Add OFFSET to the POS of all data entries in DATA."
2930   (setq gnus-newsgroup-data-reverse nil)
2931   (while data
2932     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2933     (setq data (cdr data))))
2934
2935 (defun gnus-summary-article-pseudo-p (article)
2936   "Say whether this article is a pseudo article or not."
2937   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2938
2939 (defmacro gnus-summary-article-sparse-p (article)
2940   "Say whether this article is a sparse article or not."
2941   `(memq ,article gnus-newsgroup-sparse))
2942
2943 (defmacro gnus-summary-article-ancient-p (article)
2944   "Say whether this article is a sparse article or not."
2945   `(memq ,article gnus-newsgroup-ancient))
2946
2947 (defun gnus-article-parent-p (number)
2948   "Say whether this article is a parent or not."
2949   (let ((data (gnus-data-find-list number)))
2950     (and (cdr data)              ; There has to be an article after...
2951          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2952             (gnus-data-level (nth 1 data))))))
2953
2954 (defun gnus-article-children (number)
2955   "Return a list of all children to NUMBER."
2956   (let* ((data (gnus-data-find-list number))
2957          (level (gnus-data-level (car data)))
2958          children)
2959     (setq data (cdr data))
2960     (while (and data
2961                 (= (gnus-data-level (car data)) (1+ level)))
2962       (push (gnus-data-number (car data)) children)
2963       (setq data (cdr data)))
2964     children))
2965
2966 (defmacro gnus-summary-skip-intangible ()
2967   "If the current article is intangible, then jump to a different article."
2968   '(let ((to (get-text-property (point) 'gnus-intangible)))
2969      (and to (gnus-summary-goto-subject to))))
2970
2971 (defmacro gnus-summary-article-intangible-p ()
2972   "Say whether this article is intangible or not."
2973   '(get-text-property (point) 'gnus-intangible))
2974
2975 (defun gnus-article-read-p (article)
2976   "Say whether ARTICLE is read or not."
2977   (not (or (memq article gnus-newsgroup-marked)
2978            (memq article gnus-newsgroup-spam-marked)
2979            (memq article gnus-newsgroup-unreads)
2980            (memq article gnus-newsgroup-unselected)
2981            (memq article gnus-newsgroup-dormant))))
2982
2983 ;; Some summary mode macros.
2984
2985 (defmacro gnus-summary-article-number ()
2986   "The article number of the article on the current line.
2987 If there isn't an article number here, then we return the current
2988 article number."
2989   '(progn
2990      (gnus-summary-skip-intangible)
2991      (or (get-text-property (point) 'gnus-number)
2992          (gnus-summary-last-subject))))
2993
2994 (defmacro gnus-summary-article-header (&optional number)
2995   "Return the header of article NUMBER."
2996   `(gnus-data-header (gnus-data-find
2997                       ,(or number '(gnus-summary-article-number)))))
2998
2999 (defmacro gnus-summary-thread-level (&optional number)
3000   "Return the level of thread that starts with article NUMBER."
3001   `(if (and (eq gnus-summary-make-false-root 'dummy)
3002             (get-text-property (point) 'gnus-intangible))
3003        0
3004      (gnus-data-level (gnus-data-find
3005                        ,(or number '(gnus-summary-article-number))))))
3006
3007 (defmacro gnus-summary-article-mark (&optional number)
3008   "Return the mark of article NUMBER."
3009   `(gnus-data-mark (gnus-data-find
3010                     ,(or number '(gnus-summary-article-number)))))
3011
3012 (defmacro gnus-summary-article-pos (&optional number)
3013   "Return the position of the line of article NUMBER."
3014   `(gnus-data-pos (gnus-data-find
3015                    ,(or number '(gnus-summary-article-number)))))
3016
3017 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3018 (defmacro gnus-summary-article-subject (&optional number)
3019   "Return current subject string or nil if nothing."
3020   `(let ((headers
3021           ,(if number
3022                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3023              '(gnus-data-header (assq (gnus-summary-article-number)
3024                                       gnus-newsgroup-data)))))
3025      (and headers
3026           (vectorp headers)
3027           (mail-header-subject headers))))
3028
3029 (defmacro gnus-summary-article-score (&optional number)
3030   "Return current article score."
3031   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3032                   gnus-newsgroup-scored))
3033        gnus-summary-default-score 0))
3034
3035 (defun gnus-summary-article-children (&optional number)
3036   "Return a list of article numbers that are children of article NUMBER."
3037   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3038          (level (gnus-data-level (car data)))
3039          l children)
3040     (while (and (setq data (cdr data))
3041                 (> (setq l (gnus-data-level (car data))) level))
3042       (and (= (1+ level) l)
3043            (push (gnus-data-number (car data))
3044                  children)))
3045     (nreverse children)))
3046
3047 (defun gnus-summary-article-parent (&optional number)
3048   "Return the article number of the parent of article NUMBER."
3049   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3050                                     (gnus-data-list t)))
3051          (level (gnus-data-level (car data))))
3052     (if (zerop level)
3053         ()                              ; This is a root.
3054       ;; We search until we find an article with a level less than
3055       ;; this one.  That function has to be the parent.
3056       (while (and (setq data (cdr data))
3057                   (not (< (gnus-data-level (car data)) level))))
3058       (and data (gnus-data-number (car data))))))
3059
3060 (defun gnus-unread-mark-p (mark)
3061   "Say whether MARK is the unread mark."
3062   (= mark gnus-unread-mark))
3063
3064 (defun gnus-read-mark-p (mark)
3065   "Say whether MARK is one of the marks that mark as read.
3066 This is all marks except unread, ticked, dormant, and expirable."
3067   (not (or (= mark gnus-unread-mark)
3068            (= mark gnus-ticked-mark)
3069            (= mark gnus-spam-mark)
3070            (= mark gnus-dormant-mark)
3071            (= mark gnus-expirable-mark))))
3072
3073 (defmacro gnus-article-mark (number)
3074   "Return the MARK of article NUMBER.
3075 This macro should only be used when computing the mark the \"first\"
3076 time; i.e., when generating the summary lines.  After that,
3077 `gnus-summary-article-mark' should be used to examine the
3078 marks of articles."
3079   `(cond
3080     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3081     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3082     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3083     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3084     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3085     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3086     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3087     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3088            gnus-ancient-mark))))
3089
3090 ;; Saving hidden threads.
3091
3092 (defmacro gnus-save-hidden-threads (&rest forms)
3093   "Save hidden threads, eval FORMS, and restore the hidden threads."
3094   (let ((config (make-symbol "config")))
3095     `(let ((,config (gnus-hidden-threads-configuration)))
3096        (unwind-protect
3097            (save-excursion
3098              ,@forms)
3099          (gnus-restore-hidden-threads-configuration ,config)))))
3100 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3101 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3102
3103 (defun gnus-data-compute-positions ()
3104   "Compute the positions of all articles."
3105   (setq gnus-newsgroup-data-reverse nil)
3106   (let ((data gnus-newsgroup-data))
3107     (save-excursion
3108       (gnus-save-hidden-threads
3109         (gnus-summary-show-all-threads)
3110         (goto-char (point-min))
3111         (while data
3112           (while (get-text-property (point) 'gnus-intangible)
3113             (forward-line 1))
3114           (gnus-data-set-pos (car data) (+ (point) 3))
3115           (setq data (cdr data))
3116           (forward-line 1))))))
3117
3118 (defun gnus-hidden-threads-configuration ()
3119   "Return the current hidden threads configuration."
3120   (save-excursion
3121     (let (config)
3122       (goto-char (point-min))
3123       (while (search-forward "\r" nil t)
3124         (push (1- (point)) config))
3125       config)))
3126
3127 (defun gnus-restore-hidden-threads-configuration (config)
3128   "Restore hidden threads configuration from CONFIG."
3129   (save-excursion
3130     (let (point buffer-read-only)
3131       (while (setq point (pop config))
3132         (when (and (< point (point-max))
3133                    (goto-char point)
3134                    (eq (char-after) ?\n))
3135           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3136
3137 ;; Various summary mode internalish functions.
3138
3139 (defun gnus-mouse-pick-article (e)
3140   (interactive "e")
3141   (mouse-set-point e)
3142   (gnus-summary-next-page nil t))
3143
3144 (defun gnus-summary-set-display-table ()
3145   "Change the display table.
3146 Odd characters have a tendency to mess
3147 up nicely formatted displays - we make all possible glyphs
3148 display only a single character."
3149
3150   ;; We start from the standard display table, if any.
3151   (let ((table (or (copy-sequence standard-display-table)
3152                    (make-display-table)))
3153         (i 32))
3154     ;; Nix out all the control chars...
3155     (while (>= (setq i (1- i)) 0)
3156       (aset table i [??]))
3157    ;; ... but not newline and cr, of course.  (cr is necessary for the
3158     ;; selective display).
3159     (aset table ?\n nil)
3160     (aset table ?\r nil)
3161     ;; We keep TAB as well.
3162     (aset table ?\t nil)
3163     ;; We nix out any glyphs over 126 that are not set already.
3164     (let ((i 256))
3165       (while (>= (setq i (1- i)) 127)
3166         ;; Only modify if the entry is nil.
3167         (unless (aref table i)
3168           (aset table i [??]))))
3169     (setq buffer-display-table table)))
3170
3171 (defun gnus-summary-set-article-display-arrow (pos)
3172   "Update the overlay arrow to point to line at position POS."
3173   (when (and gnus-summary-display-arrow
3174              (boundp 'overlay-arrow-position)
3175              (boundp 'overlay-arrow-string))
3176     (save-excursion
3177       (goto-char pos)
3178       (beginning-of-line)
3179       (unless overlay-arrow-position
3180         (setq overlay-arrow-position (make-marker)))
3181       (setq overlay-arrow-string "=>"
3182             overlay-arrow-position (set-marker overlay-arrow-position
3183                                                (point)
3184                                                (current-buffer))))))
3185
3186 (defun gnus-summary-setup-buffer (group)
3187   "Initialize summary buffer."
3188   (let ((buffer (gnus-summary-buffer-name group))
3189         (dead-name (concat "*Dead Summary "
3190                            (gnus-group-decoded-name group) "*")))
3191     ;; If a dead summary buffer exists, we kill it.
3192     (when (gnus-buffer-live-p dead-name)
3193       (gnus-kill-buffer dead-name))
3194     (if (get-buffer buffer)
3195         (progn
3196           (set-buffer buffer)
3197           (setq gnus-summary-buffer (current-buffer))
3198           (not gnus-newsgroup-prepared))
3199       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3200       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3201       (gnus-summary-mode group)
3202       (when gnus-carpal
3203         (gnus-carpal-setup-buffer 'summary))
3204       (unless gnus-single-article-buffer
3205         (make-local-variable 'gnus-article-buffer)
3206         (make-local-variable 'gnus-article-current)
3207         (make-local-variable 'gnus-original-article-buffer))
3208       (setq gnus-newsgroup-name group)
3209       ;; Set any local variables in the group parameters.
3210       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3211       t)))
3212
3213 (defun gnus-set-global-variables ()
3214   "Set the global equivalents of the buffer-local variables.
3215 They are set to the latest values they had.  These reflect the summary
3216 buffer that was in action when the last article was fetched."
3217   (when (eq major-mode 'gnus-summary-mode)
3218     (setq gnus-summary-buffer (current-buffer))
3219     (let ((name gnus-newsgroup-name)
3220           (marked gnus-newsgroup-marked)
3221           (spam gnus-newsgroup-spam-marked)
3222           (unread gnus-newsgroup-unreads)
3223           (headers gnus-current-headers)
3224           (data gnus-newsgroup-data)
3225           (summary gnus-summary-buffer)
3226           (article-buffer gnus-article-buffer)
3227           (original gnus-original-article-buffer)
3228           (gac gnus-article-current)
3229           (reffed gnus-reffed-article-number)
3230           (score-file gnus-current-score-file)
3231           (default-charset gnus-newsgroup-charset)
3232           vlist)
3233       (let ((locals gnus-newsgroup-variables))
3234         (while locals
3235           (if (consp (car locals))
3236               (push (eval (caar locals)) vlist)
3237             (push (eval (car locals)) vlist))
3238           (setq locals (cdr locals)))
3239         (setq vlist (nreverse vlist)))
3240       (with-current-buffer gnus-group-buffer
3241         (setq gnus-newsgroup-name name
3242               gnus-newsgroup-marked marked
3243               gnus-newsgroup-spam-marked spam
3244               gnus-newsgroup-unreads unread
3245               gnus-current-headers headers
3246               gnus-newsgroup-data data
3247               gnus-article-current gac
3248               gnus-summary-buffer summary
3249               gnus-article-buffer article-buffer
3250               gnus-original-article-buffer original
3251               gnus-reffed-article-number reffed
3252               gnus-current-score-file score-file
3253               gnus-newsgroup-charset default-charset)
3254         (let ((locals gnus-newsgroup-variables))
3255           (while locals
3256             (if (consp (car locals))
3257                 (set (caar locals) (pop vlist))
3258               (set (car locals) (pop vlist)))
3259             (setq locals (cdr locals))))
3260         ;; The article buffer also has local variables.
3261         (when (gnus-buffer-live-p gnus-article-buffer)
3262           (set-buffer gnus-article-buffer)
3263           (setq gnus-summary-buffer summary))))))
3264
3265 (defun gnus-summary-article-unread-p (article)
3266   "Say whether ARTICLE is unread or not."
3267   (memq article gnus-newsgroup-unreads))
3268
3269 (defun gnus-summary-first-article-p (&optional article)
3270   "Return whether ARTICLE is the first article in the buffer."
3271   (if (not (setq article (or article (gnus-summary-article-number))))
3272       nil
3273     (eq article (caar gnus-newsgroup-data))))
3274
3275 (defun gnus-summary-last-article-p (&optional article)
3276   "Return whether ARTICLE is the last article in the buffer."
3277   (if (not (setq article (or article (gnus-summary-article-number))))
3278       ;; All non-existent numbers are the last article.  :-)
3279       t
3280     (not (cdr (gnus-data-find-list article)))))
3281
3282 (defun gnus-make-thread-indent-array ()
3283   (let ((n 200))
3284     (unless (and gnus-thread-indent-array
3285                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3286       (setq gnus-thread-indent-array (make-vector 201 "")
3287             gnus-thread-indent-array-level gnus-thread-indent-level)
3288       (while (>= n 0)
3289         (aset gnus-thread-indent-array n
3290               (make-string (* n gnus-thread-indent-level) ? ))
3291         (setq n (1- n))))))
3292
3293 (defun gnus-update-summary-mark-positions ()
3294   "Compute where the summary marks are to go."
3295   (save-excursion
3296     (when (gnus-buffer-exists-p gnus-summary-buffer)
3297       (set-buffer gnus-summary-buffer))
3298     (let ((spec gnus-summary-line-format-spec)
3299           pos)
3300       (save-excursion
3301         (gnus-set-work-buffer)
3302         (let ((gnus-tmp-unread ?Z)
3303               (gnus-replied-mark ?Z)
3304               (gnus-score-below-mark ?Z)
3305               (gnus-score-over-mark ?Z)
3306               (gnus-undownloaded-mark ?Z)
3307               (gnus-summary-line-format-spec spec)
3308               (gnus-newsgroup-downloadable '(0))
3309               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3310               case-fold-search ignores)
3311           ;; Here, all marks are bound to Z.
3312           (gnus-summary-insert-line header
3313                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3314           (goto-char (point-min))
3315           ;; Memorize the positions of the same characters as dummy marks.
3316           (while (re-search-forward "[A-D]" nil t)
3317             (push (point) ignores))
3318           (erase-buffer)
3319           ;; We use A-D as dummy marks in order to know column positions
3320           ;; where marks should be inserted.
3321           (setq gnus-tmp-unread ?A
3322                 gnus-replied-mark ?B
3323                 gnus-score-below-mark ?C
3324                 gnus-score-over-mark ?C
3325                 gnus-undownloaded-mark ?D)
3326           (gnus-summary-insert-line header
3327                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3328           ;; Ignore characters which aren't dummy marks.
3329           (dolist (p ignores)
3330             (delete-region (goto-char (1- p)) p)
3331             (insert ?Z))
3332           (goto-char (point-min))
3333           (setq pos (list (cons 'unread
3334                                 (and (search-forward "A" nil t)
3335                                      (- (point) (point-min) 1)))))
3336           (goto-char (point-min))
3337           (push (cons 'replied (and (search-forward "B" nil t)
3338                                     (- (point) (point-min) 1)))
3339                 pos)
3340           (goto-char (point-min))
3341           (push (cons 'score (and (search-forward "C" nil t)
3342                                   (- (point) (point-min) 1)))
3343                 pos)
3344           (goto-char (point-min))
3345           (push (cons 'download (and (search-forward "D" nil t)
3346                                      (- (point) (point-min) 1)))
3347                 pos)))
3348       (setq gnus-summary-mark-positions pos))))
3349
3350 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3351   "Insert a dummy root in the summary buffer."
3352   (beginning-of-line)
3353   (gnus-add-text-properties
3354    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3355    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3356
3357 (defun gnus-summary-extract-address-component (from)
3358   (or (car (funcall gnus-extract-address-components from))
3359       from))
3360
3361 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3362   (let ((mail-parse-charset gnus-newsgroup-charset)
3363         ; Is it really necessary to do this next part for each summary line?
3364         ; Luckily, doesn't seem to slow things down much.
3365         (mail-parse-ignored-charsets
3366          (with-current-buffer gnus-summary-buffer
3367            gnus-newsgroup-ignored-charsets)))
3368     (or
3369      (and gnus-ignored-from-addresses
3370           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3371           (let ((extra-headers (mail-header-extra header))
3372                 to
3373                 newsgroups)
3374             (cond
3375              ((setq to (cdr (assq 'To extra-headers)))
3376               (concat "-> "
3377                       (inline
3378                         (gnus-summary-extract-address-component
3379                          (funcall gnus-decode-encoded-word-function to)))))
3380              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3381               (concat "=> " newsgroups)))))
3382      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3383
3384 (defun gnus-summary-insert-line (gnus-tmp-header
3385                                  gnus-tmp-level gnus-tmp-current
3386                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3387                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3388                                  &optional gnus-tmp-dummy gnus-tmp-score
3389                                  gnus-tmp-process)
3390   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3391          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3392          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3393          (gnus-tmp-score-char
3394           (if (or (null gnus-summary-default-score)
3395                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3396                       gnus-summary-zcore-fuzz))
3397               ?                         ;Whitespace
3398             (if (< gnus-tmp-score gnus-summary-default-score)
3399                 gnus-score-below-mark gnus-score-over-mark)))
3400          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3401          (gnus-tmp-replied
3402           (cond (gnus-tmp-process gnus-process-mark)
3403                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3404                  gnus-cached-mark)
3405                 (gnus-tmp-replied gnus-replied-mark)
3406                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3407                  gnus-forwarded-mark)
3408                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3409                  gnus-saved-mark)
3410                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3411                  gnus-recent-mark)
3412                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3413                  gnus-unseen-mark)
3414                 (t gnus-no-mark)))
3415          (gnus-tmp-downloaded
3416           (cond (undownloaded
3417                  gnus-undownloaded-mark)
3418                 (gnus-newsgroup-agentized
3419                  gnus-downloaded-mark)
3420                 (t
3421                  gnus-no-mark)))
3422          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3423          (gnus-tmp-name
3424           (cond
3425            ((string-match "<[^>]+> *$" gnus-tmp-from)
3426             (let ((beg (match-beginning 0)))
3427               (or (and (string-match "^\".+\"" gnus-tmp-from)
3428                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3429                   (substring gnus-tmp-from 0 beg))))
3430            ((string-match "(.+)" gnus-tmp-from)
3431             (substring gnus-tmp-from
3432                        (1+ (match-beginning 0)) (1- (match-end 0))))
3433            (t gnus-tmp-from)))
3434          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3435          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3436          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3437          (buffer-read-only nil))
3438     (when (string= gnus-tmp-name "")
3439       (setq gnus-tmp-name gnus-tmp-from))
3440     (unless (numberp gnus-tmp-lines)
3441       (setq gnus-tmp-lines -1))
3442     (if (= gnus-tmp-lines -1)
3443         (setq gnus-tmp-lines "?")
3444       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3445       (gnus-put-text-property
3446      (point)
3447      (progn (eval gnus-summary-line-format-spec) (point))
3448        'gnus-number gnus-tmp-number)
3449     (when (gnus-visual-p 'summary-highlight 'highlight)
3450       (forward-line -1)
3451       (gnus-run-hooks 'gnus-summary-update-hook)
3452       (forward-line 1))))
3453
3454 (defun gnus-summary-update-line (&optional dont-update)
3455   "Update summary line after change."
3456   (when (and gnus-summary-default-score
3457              (not gnus-summary-inhibit-highlight))
3458     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3459            (article (gnus-summary-article-number))
3460            (score (gnus-summary-article-score article)))
3461       (unless dont-update
3462         (if (and gnus-summary-mark-below
3463                  (< (gnus-summary-article-score)
3464                     gnus-summary-mark-below))
3465             ;; This article has a low score, so we mark it as read.
3466             (when (memq article gnus-newsgroup-unreads)
3467               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3468           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3469             ;; This article was previously marked as read on account
3470             ;; of a low score, but now it has risen, so we mark it as
3471             ;; unread.
3472             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3473         (gnus-summary-update-mark
3474          (if (or (null gnus-summary-default-score)
3475                  (<= (abs (- score gnus-summary-default-score))
3476                      gnus-summary-zcore-fuzz))
3477              ?                          ;Whitespace
3478            (if (< score gnus-summary-default-score)
3479                gnus-score-below-mark gnus-score-over-mark))
3480          'score))
3481       ;; Do visual highlighting.
3482       (when (gnus-visual-p 'summary-highlight 'highlight)
3483         (gnus-run-hooks 'gnus-summary-update-hook)))))
3484
3485 (defvar gnus-tmp-new-adopts nil)
3486
3487 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3488   "Return the number of articles in THREAD.
3489 This may be 0 in some cases -- if none of the articles in
3490 the thread are to be displayed."
3491   (let* ((number
3492          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3493           (cond
3494            ((not (listp thread))
3495             1)
3496            ((and (consp thread) (cdr thread))
3497             (apply
3498              '+ 1 (mapcar
3499                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3500            ((null thread)
3501             1)
3502            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3503             1)
3504            (t 0))))
3505     (when (and level (zerop level) gnus-tmp-new-adopts)
3506       (incf number
3507             (apply '+ (mapcar
3508                        'gnus-summary-number-of-articles-in-thread
3509                        gnus-tmp-new-adopts))))
3510     (if char
3511         (if (> number 1) gnus-not-empty-thread-mark
3512           gnus-empty-thread-mark)
3513       number)))
3514
3515 (defsubst gnus-summary-line-message-size (head)
3516   "Return pretty-printed version of message size.
3517 This function is intended to be used in
3518 `gnus-summary-line-format-alist'."
3519   (let ((c (or (mail-header-chars head) -1)))
3520     (cond ((< c 0) "n/a")               ; chars not available
3521           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3522           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3523           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3524           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3525
3526
3527 (defun gnus-summary-set-local-parameters (group)
3528   "Go through the local params of GROUP and set all variable specs in that list."
3529   (let ((vars '(quit-config)))          ; Ignore quit-config.
3530     (dolist (elem (gnus-group-find-parameter group))
3531       (and (consp elem)                 ; Has to be a cons.
3532            (consp (cdr elem))           ; The cdr has to be a list.
3533            (symbolp (car elem))         ; Has to be a symbol in there.
3534            (not (memq (car elem) vars))
3535            (ignore-errors               ; So we set it.
3536              (push (car elem) vars)
3537              (make-local-variable (car elem))
3538              (set (car elem) (eval (nth 1 elem))))))))
3539
3540 (defun gnus-summary-read-group (group &optional show-all no-article
3541                                       kill-buffer no-display backward
3542                                       select-articles)
3543   "Start reading news in newsgroup GROUP.
3544 If SHOW-ALL is non-nil, already read articles are also listed.
3545 If NO-ARTICLE is non-nil, no article is selected initially.
3546 If NO-DISPLAY, don't generate a summary buffer."
3547   (let (result)
3548     (while (and group
3549                 (null (setq result
3550                             (let ((gnus-auto-select-next nil))
3551                               (or (gnus-summary-read-group-1
3552                                    group show-all no-article
3553                                    kill-buffer no-display
3554                                    select-articles)
3555                                   (setq show-all nil
3556                                         select-articles nil)))))
3557                 (eq gnus-auto-select-next 'quietly))
3558       (set-buffer gnus-group-buffer)
3559       ;; The entry function called above goes to the next
3560       ;; group automatically, so we go two groups back
3561       ;; if we are searching for the previous group.
3562       (when backward
3563         (gnus-group-prev-unread-group 2))
3564       (if (not (equal group (gnus-group-group-name)))
3565           (setq group (gnus-group-group-name))
3566         (setq group nil)))
3567     result))
3568
3569 (defun gnus-summary-read-group-1 (group show-all no-article
3570                                         kill-buffer no-display
3571                                         &optional select-articles)
3572   ;; Killed foreign groups can't be entered.
3573   ;;  (when (and (not (gnus-group-native-p group))
3574   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3575   ;;    (error "Dead non-native groups can't be entered"))
3576   (gnus-message 5 "Retrieving newsgroup: %s..."
3577                 (gnus-group-decoded-name group))
3578   (let* ((new-group (gnus-summary-setup-buffer group))
3579          (quit-config (gnus-group-quit-config group))
3580          (did-select (and new-group (gnus-select-newsgroup
3581                                      group show-all select-articles))))
3582     (cond
3583      ;; This summary buffer exists already, so we just select it.
3584      ((not new-group)
3585       (gnus-set-global-variables)
3586       (when kill-buffer
3587         (gnus-kill-or-deaden-summary kill-buffer))
3588       (gnus-configure-windows 'summary 'force)
3589       (gnus-set-mode-line 'summary)
3590       (gnus-summary-position-point)
3591       (message "")
3592       t)
3593      ;; We couldn't select this group.
3594      ((null did-select)
3595       (when (and (eq major-mode 'gnus-summary-mode)
3596                  (not (equal (current-buffer) kill-buffer)))
3597         (kill-buffer (current-buffer))
3598         (if (not quit-config)
3599             (progn
3600               ;; Update the info -- marks might need to be removed,
3601               ;; for instance.
3602               (gnus-summary-update-info)
3603               (set-buffer gnus-group-buffer)
3604               (gnus-group-jump-to-group group)
3605               (gnus-group-next-unread-group 1))
3606           (gnus-handle-ephemeral-exit quit-config)))
3607       (let ((grpinfo (gnus-get-info group)))
3608         (if (null (gnus-info-read grpinfo))
3609             (gnus-message 3 "Group %s contains no messages"
3610                           (gnus-group-decoded-name group))
3611           (gnus-message 3 "Can't select group")))
3612       nil)
3613      ;; The user did a `C-g' while prompting for number of articles,
3614      ;; so we exit this group.
3615      ((eq did-select 'quit)
3616       (and (eq major-mode 'gnus-summary-mode)
3617            (not (equal (current-buffer) kill-buffer))
3618            (kill-buffer (current-buffer)))
3619       (when kill-buffer
3620         (gnus-kill-or-deaden-summary kill-buffer))
3621       (if (not quit-config)
3622           (progn
3623             (set-buffer gnus-group-buffer)
3624             (gnus-group-jump-to-group group)
3625             (gnus-group-next-unread-group 1)
3626             (gnus-configure-windows 'group 'force))
3627         (gnus-handle-ephemeral-exit quit-config))
3628       ;; Finally signal the quit.
3629       (signal 'quit nil))
3630      ;; The group was successfully selected.
3631      (t
3632       (gnus-set-global-variables)
3633       ;; Save the active value in effect when the group was entered.
3634       (setq gnus-newsgroup-active
3635             (gnus-copy-sequence
3636              (gnus-active gnus-newsgroup-name)))
3637       ;; You can change the summary buffer in some way with this hook.
3638       (gnus-run-hooks 'gnus-select-group-hook)
3639       (when (memq 'summary (gnus-update-format-specifications
3640                             nil 'summary 'summary-mode 'summary-dummy))
3641         ;; The format specification for the summary line was updated,
3642         ;; so we need to update the mark positions as well.
3643         (gnus-update-summary-mark-positions))
3644       ;; Do score processing.
3645       (when gnus-use-scoring
3646         (gnus-possibly-score-headers))
3647       ;; Check whether to fill in the gaps in the threads.
3648       (when gnus-build-sparse-threads
3649         (gnus-build-sparse-threads))
3650       ;; Find the initial limit.
3651       (if show-all
3652           (let ((gnus-newsgroup-dormant nil))
3653             (gnus-summary-initial-limit show-all))
3654         (gnus-summary-initial-limit show-all))
3655       ;; Generate the summary buffer.
3656       (unless no-display
3657         (gnus-summary-prepare))
3658       (when gnus-use-trees
3659         (gnus-tree-open group)
3660         (setq gnus-summary-highlight-line-function
3661               'gnus-tree-highlight-article))
3662       ;; If the summary buffer is empty, but there are some low-scored
3663       ;; articles or some excluded dormants, we include these in the
3664       ;; buffer.
3665       (when (and (zerop (buffer-size))
3666                  (not no-display))
3667         (cond (gnus-newsgroup-dormant
3668                (gnus-summary-limit-include-dormant))
3669               ((and gnus-newsgroup-scored show-all)
3670                (gnus-summary-limit-include-expunged t))))
3671       ;; Function `gnus-apply-kill-file' must be called in this hook.
3672       (gnus-run-hooks 'gnus-apply-kill-hook)
3673       (if (and (zerop (buffer-size))
3674                (not no-display))
3675           (progn
3676             ;; This newsgroup is empty.
3677             (gnus-summary-catchup-and-exit nil t)
3678             (gnus-message 6 "No unread news")
3679             (when kill-buffer
3680               (gnus-kill-or-deaden-summary kill-buffer))
3681             ;; Return nil from this function.
3682             nil)
3683         ;; Hide conversation thread subtrees.  We cannot do this in
3684         ;; gnus-summary-prepare-hook since kill processing may not
3685         ;; work with hidden articles.
3686         (gnus-summary-maybe-hide-threads)
3687         (when kill-buffer
3688           (gnus-kill-or-deaden-summary kill-buffer))
3689         (gnus-summary-auto-select-subject)
3690         ;; Show first unread article if requested.
3691         (if (and (not no-article)
3692                  (not no-display)
3693                  gnus-newsgroup-unreads
3694                  gnus-auto-select-first)
3695             (progn
3696               (gnus-configure-windows 'summary)
3697               (let ((art (gnus-summary-article-number)))
3698                 (unless (and (not gnus-plugged)
3699                              (or (memq art gnus-newsgroup-undownloaded)
3700                                  (memq art gnus-newsgroup-downloadable)))
3701                   (gnus-summary-goto-article art))))
3702           ;; Don't select any articles.
3703           (gnus-summary-position-point)
3704           (gnus-configure-windows 'summary 'force)
3705           (gnus-set-mode-line 'summary))
3706         (when (and gnus-auto-center-group
3707                    (get-buffer-window gnus-group-buffer t))
3708           ;; Gotta use windows, because recenter does weird stuff if
3709           ;; the current buffer ain't the displayed window.
3710           (let ((owin (selected-window)))
3711             (select-window (get-buffer-window gnus-group-buffer t))
3712             (when (gnus-group-goto-group group)
3713               (recenter))
3714             (select-window owin)))
3715         ;; Mark this buffer as "prepared".
3716         (setq gnus-newsgroup-prepared t)
3717         (gnus-run-hooks 'gnus-summary-prepared-hook)
3718         (unless (gnus-ephemeral-group-p group)
3719           (gnus-group-update-group group))
3720         t)))))
3721
3722 (defun gnus-summary-auto-select-subject ()
3723   "Select the subject line on initial group entry."
3724   (goto-char (point-min))
3725   (cond
3726    ((eq gnus-auto-select-subject 'best)
3727     (gnus-summary-best-unread-subject))
3728    ((eq gnus-auto-select-subject 'unread)
3729     (gnus-summary-first-unread-subject))
3730    ((eq gnus-auto-select-subject 'unseen)
3731     (gnus-summary-first-unseen-subject))
3732    ((eq gnus-auto-select-subject 'unseen-or-unread)
3733     (gnus-summary-first-unseen-or-unread-subject))
3734    ((eq gnus-auto-select-subject 'first)
3735     ;; Do nothing.
3736     )
3737    ((functionp gnus-auto-select-subject)
3738     (funcall gnus-auto-select-subject))))
3739
3740 (defun gnus-summary-prepare ()
3741   "Generate the summary buffer."
3742   (interactive)
3743   (let ((buffer-read-only nil))
3744     (erase-buffer)
3745     (setq gnus-newsgroup-data nil
3746           gnus-newsgroup-data-reverse nil)
3747     (gnus-run-hooks 'gnus-summary-generate-hook)
3748     ;; Generate the buffer, either with threads or without.
3749     (when gnus-newsgroup-headers
3750       (gnus-summary-prepare-threads
3751        (if gnus-show-threads
3752            (gnus-sort-gathered-threads
3753             (funcall gnus-summary-thread-gathering-function
3754                      (gnus-sort-threads
3755                       (gnus-cut-threads (gnus-make-threads)))))
3756          ;; Unthreaded display.
3757          (gnus-sort-articles gnus-newsgroup-headers))))
3758     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3759     ;; Call hooks for modifying summary buffer.
3760     (goto-char (point-min))
3761     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3762
3763 (defsubst gnus-general-simplify-subject (subject)
3764   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3765   (setq subject
3766         (cond
3767          ;; Truncate the subject.
3768          (gnus-simplify-subject-functions
3769           (gnus-map-function gnus-simplify-subject-functions subject))
3770          ((numberp gnus-summary-gather-subject-limit)
3771           (setq subject (gnus-simplify-subject-re subject))
3772           (if (> (length subject) gnus-summary-gather-subject-limit)
3773               (substring subject 0 gnus-summary-gather-subject-limit)
3774             subject))
3775          ;; Fuzzily simplify it.
3776          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3777           (gnus-simplify-subject-fuzzy subject))
3778          ;; Just remove the leading "Re:".
3779          (t
3780           (gnus-simplify-subject-re subject))))
3781
3782   (if (and gnus-summary-gather-exclude-subject
3783            (string-match gnus-summary-gather-exclude-subject subject))
3784       nil                         ; This article shouldn't be gathered
3785     subject))
3786
3787 (defun gnus-summary-simplify-subject-query ()
3788   "Query where the respool algorithm would put this article."
3789   (interactive)
3790   (gnus-summary-select-article)
3791   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3792
3793 (defun gnus-gather-threads-by-subject (threads)
3794   "Gather threads by looking at Subject headers."
3795   (if (not gnus-summary-make-false-root)
3796       threads
3797     (let ((hashtb (gnus-make-hashtable 1024))
3798           (prev threads)
3799           (result threads)
3800           subject hthread whole-subject)
3801       (while threads
3802         (setq subject (gnus-general-simplify-subject
3803                        (setq whole-subject (mail-header-subject
3804                                             (caar threads)))))
3805         (when subject
3806           (if (setq hthread (gnus-gethash subject hashtb))
3807               (progn
3808                 ;; We enter a dummy root into the thread, if we
3809                 ;; haven't done that already.
3810                 (unless (stringp (caar hthread))
3811                   (setcar hthread (list whole-subject (car hthread))))
3812                 ;; We add this new gathered thread to this gathered
3813                 ;; thread.
3814                 (setcdr (car hthread)
3815                         (nconc (cdar hthread) (list (car threads))))
3816                 ;; Remove it from the list of threads.
3817                 (setcdr prev (cdr threads))
3818                 (setq threads prev))
3819             ;; Enter this thread into the hash table.
3820             (gnus-sethash subject
3821                           (if gnus-summary-make-false-root-always
3822                               (progn
3823                                 ;; If you want a dummy root above all
3824                                 ;; threads...
3825                                 (setcar threads (list whole-subject
3826                                                       (car threads)))
3827                                 threads)
3828                             threads)
3829                           hashtb)))
3830         (setq prev threads)
3831         (setq threads (cdr threads)))
3832       result)))
3833
3834 (defun gnus-gather-threads-by-references (threads)
3835   "Gather threads by looking at References headers."
3836   (let ((idhashtb (gnus-make-hashtable 1024))
3837         (thhashtb (gnus-make-hashtable 1024))
3838         (prev threads)
3839         (result threads)
3840         ids references id gthread gid entered ref)
3841     (while threads
3842       (when (setq references (mail-header-references (caar threads)))
3843         (setq id (mail-header-id (caar threads))
3844               ids (inline (gnus-split-references references))
3845               entered nil)
3846         (while (setq ref (pop ids))
3847           (setq ids (delete ref ids))
3848           (if (not (setq gid (gnus-gethash ref idhashtb)))
3849               (progn
3850                 (gnus-sethash ref id idhashtb)
3851                 (gnus-sethash id threads thhashtb))
3852             (setq gthread (gnus-gethash gid thhashtb))
3853             (unless entered
3854               ;; We enter a dummy root into the thread, if we
3855               ;; haven't done that already.
3856               (unless (stringp (caar gthread))
3857                 (setcar gthread (list (mail-header-subject (caar gthread))
3858                                       (car gthread))))
3859               ;; We add this new gathered thread to this gathered
3860               ;; thread.
3861               (setcdr (car gthread)
3862                       (nconc (cdar gthread) (list (car threads)))))
3863             ;; Add it into the thread hash table.
3864             (gnus-sethash id gthread thhashtb)
3865             (setq entered t)
3866             ;; Remove it from the list of threads.
3867             (setcdr prev (cdr threads))
3868             (setq threads prev))))
3869       (setq prev threads)
3870       (setq threads (cdr threads)))
3871     result))
3872
3873 (defun gnus-sort-gathered-threads (threads)
3874   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3875   (let ((result threads))
3876     (while threads
3877       (when (stringp (caar threads))
3878         (setcdr (car threads)
3879                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3880       (setq threads (cdr threads)))
3881     result))
3882
3883 (defun gnus-thread-loop-p (root thread)
3884   "Say whether ROOT is in THREAD."
3885   (let ((stack (list thread))
3886         (infloop 0)
3887         th)
3888     (while (setq thread (pop stack))
3889       (setq th (cdr thread))
3890       (while (and th
3891                   (not (eq (caar th) root)))
3892         (pop th))
3893       (if th
3894           ;; We have found a loop.
3895           (let (ref-dep)
3896             (setcdr thread (delq (car th) (cdr thread)))
3897             (if (boundp (setq ref-dep (intern "none"
3898                                               gnus-newsgroup-dependencies)))
3899                 (setcdr (symbol-value ref-dep)
3900                         (nconc (cdr (symbol-value ref-dep))
3901                                (list (car th))))
3902               (set ref-dep (list nil (car th))))
3903             (setq infloop 1
3904                   stack nil))
3905         ;; Push all the subthreads onto the stack.
3906         (push (cdr thread) stack)))
3907     infloop))
3908
3909 (defun gnus-make-threads ()
3910   "Go through the dependency hashtb and find the roots.  Return all threads."
3911   (let (threads)
3912     (while (catch 'infloop
3913              (mapatoms
3914               (lambda (refs)
3915                 ;; Deal with self-referencing References loops.
3916                 (when (and (car (symbol-value refs))
3917                            (not (zerop
3918                                  (apply
3919                                   '+
3920                                   (mapcar
3921                                    (lambda (thread)
3922                                      (gnus-thread-loop-p
3923                                       (car (symbol-value refs)) thread))
3924                                    (cdr (symbol-value refs)))))))
3925                   (setq threads nil)
3926                   (throw 'infloop t))
3927                 (unless (car (symbol-value refs))
3928                   ;; These threads do not refer back to any other
3929                   ;; articles, so they're roots.
3930                   (setq threads (append (cdr (symbol-value refs)) threads))))
3931               gnus-newsgroup-dependencies)))
3932     threads))
3933
3934 ;; Build the thread tree.
3935 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3936   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3937
3938 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3939 if it was already present.
3940
3941 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3942 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3943 Message-IDs will be renamed to a unique Message-ID before being
3944 entered.
3945
3946 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3947   (let* ((id (mail-header-id header))
3948          (id-dep (and id (intern id dependencies)))
3949          parent-id ref ref-dep ref-header replaced)
3950     ;; Enter this `header' in the `dependencies' table.
3951     (cond
3952      ((not id-dep)
3953       (setq header nil))
3954      ;; The first two cases do the normal part: enter a new `header'
3955      ;; in the `dependencies' table.
3956      ((not (boundp id-dep))
3957       (set id-dep (list header)))
3958      ((null (car (symbol-value id-dep)))
3959       (setcar (symbol-value id-dep) header))
3960
3961      ;; From here the `header' was already present in the
3962      ;; `dependencies' table.
3963      (force-new
3964       ;; Overrides an existing entry;
3965       ;; just set the header part of the entry.
3966       (setcar (symbol-value id-dep) header)
3967       (setq replaced t))
3968
3969      ;; Renames the existing `header' to a unique Message-ID.
3970      ((not gnus-summary-ignore-duplicates)
3971       ;; An article with this Message-ID has already been seen.
3972       ;; We rename the Message-ID.
3973       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3974            (list header))
3975       (mail-header-set-id header id))
3976
3977      ;; The last case ignores an existing entry, except it adds any
3978      ;; additional Xrefs (in case the two articles came from different
3979      ;; servers.
3980      ;; Also sets `header' to `nil' meaning that the `dependencies'
3981      ;; table was *not* modified.
3982      (t
3983       (mail-header-set-xref
3984        (car (symbol-value id-dep))
3985        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3986                    "")
3987                (or (mail-header-xref header) "")))
3988       (setq header nil)))
3989
3990     (when (and header (not replaced))
3991       ;; First check that we are not creating a References loop.
3992       (setq parent-id (gnus-parent-id (mail-header-references header)))
3993       (setq ref parent-id)
3994       (while (and ref
3995                   (setq ref-dep (intern-soft ref dependencies))
3996                   (boundp ref-dep)
3997                   (setq ref-header (car (symbol-value ref-dep))))
3998         (if (string= id ref)
3999             ;; Yuk!  This is a reference loop.  Make the article be a
4000             ;; root article.
4001             (progn
4002               (mail-header-set-references (car (symbol-value id-dep)) "none")
4003               (setq ref nil)
4004               (setq parent-id nil))
4005           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4006       (setq ref-dep (intern (or parent-id "none") dependencies))
4007       (if (boundp ref-dep)
4008           (setcdr (symbol-value ref-dep)
4009                   (nconc (cdr (symbol-value ref-dep))
4010                          (list (symbol-value id-dep))))
4011         (set ref-dep (list nil (symbol-value id-dep)))))
4012     header))
4013
4014 (defun gnus-extract-message-id-from-in-reply-to (string)
4015   (if (string-match "<[^>]+>" string)
4016       (substring string (match-beginning 0) (match-end 0))
4017     nil))
4018
4019 (defun gnus-build-sparse-threads ()
4020   (let ((headers gnus-newsgroup-headers)
4021         (mail-parse-charset gnus-newsgroup-charset)
4022         (gnus-summary-ignore-duplicates t)
4023         header references generation relations
4024         subject child end new-child date)
4025     ;; First we create an alist of generations/relations, where
4026     ;; generations is how much we trust the relation, and the relation
4027     ;; is parent/child.
4028     (gnus-message 7 "Making sparse threads...")
4029     (save-excursion
4030       (nnheader-set-temp-buffer " *gnus sparse threads*")
4031       (while (setq header (pop headers))
4032         (when (and (setq references (mail-header-references header))
4033                    (not (string= references "")))
4034           (insert references)
4035           (setq child (mail-header-id header)
4036                 subject (mail-header-subject header)
4037                 date (mail-header-date header)
4038                 generation 0)
4039           (while (search-backward ">" nil t)
4040             (setq end (1+ (point)))
4041             (when (search-backward "<" nil t)
4042               (setq new-child (buffer-substring (point) end))
4043               (push (list (incf generation)
4044                           child (setq child new-child)
4045                           subject date)
4046                     relations)))
4047           (when child
4048             (push (list (1+ generation) child nil subject) relations))
4049           (erase-buffer)))
4050       (kill-buffer (current-buffer)))
4051     ;; Sort over trustworthiness.
4052     (mapcar
4053      (lambda (relation)
4054        (when (gnus-dependencies-add-header
4055               (make-full-mail-header
4056                gnus-reffed-article-number
4057                (nth 3 relation) "" (or (nth 4 relation) "")
4058                (nth 1 relation)
4059                (or (nth 2 relation) "") 0 0 "")
4060               gnus-newsgroup-dependencies nil)
4061          (push gnus-reffed-article-number gnus-newsgroup-limit)
4062          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4063          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4064                gnus-newsgroup-reads)
4065          (decf gnus-reffed-article-number)))
4066      (sort relations 'car-less-than-car))
4067     (gnus-message 7 "Making sparse threads...done")))
4068
4069 (defun gnus-build-old-threads ()
4070   ;; Look at all the articles that refer back to old articles, and
4071   ;; fetch the headers for the articles that aren't there.  This will
4072   ;; build complete threads - if the roots haven't been expired by the
4073   ;; server, that is.
4074   (let ((mail-parse-charset gnus-newsgroup-charset)
4075         id heads)
4076     (mapatoms
4077      (lambda (refs)
4078        (when (not (car (symbol-value refs)))
4079          (setq heads (cdr (symbol-value refs)))
4080          (while heads
4081            (if (memq (mail-header-number (caar heads))
4082                      gnus-newsgroup-dormant)
4083                (setq heads (cdr heads))
4084              (setq id (symbol-name refs))
4085              (while (and (setq id (gnus-build-get-header id))
4086                          (not (car (gnus-id-to-thread id)))))
4087              (setq heads nil)))))
4088      gnus-newsgroup-dependencies)))
4089
4090 (defsubst gnus-remove-odd-characters (string)
4091   "Translate STRING into something that doesn't contain weird characters."
4092   (mm-subst-char-in-string
4093    ?\r ?\-
4094    (mm-subst-char-in-string ?\n ?\- string t) t))
4095
4096 ;; This function has to be called with point after the article number
4097 ;; on the beginning of the line.
4098 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4099   (let ((eol (point-at-eol))
4100         (buffer (current-buffer))
4101         header references in-reply-to)
4102
4103     ;; overview: [num subject from date id refs chars lines misc]
4104     (unwind-protect
4105         (let (x)
4106           (narrow-to-region (point) eol)
4107           (unless (eobp)
4108             (forward-char))
4109
4110           (setq header
4111                 (make-full-mail-header
4112                  number                 ; number
4113                  (condition-case ()     ; subject
4114                      (gnus-remove-odd-characters
4115                       (funcall gnus-decode-encoded-word-function
4116                                (setq x (nnheader-nov-field))))
4117                    (error x))
4118                  (condition-case ()     ; from
4119                      (gnus-remove-odd-characters
4120                       (funcall gnus-decode-encoded-word-function
4121                                (setq x (nnheader-nov-field))))
4122                    (error x))
4123                  (nnheader-nov-field)   ; date
4124                  (nnheader-nov-read-message-id number)  ; id
4125                  (setq references (nnheader-nov-field)) ; refs
4126                  (nnheader-nov-read-integer) ; chars
4127                  (nnheader-nov-read-integer) ; lines
4128                  (unless (eobp)
4129                    (if (looking-at "Xref: ")
4130                        (goto-char (match-end 0)))
4131                    (nnheader-nov-field)) ; Xref
4132                  (nnheader-nov-parse-extra)))) ; extra
4133
4134       (widen))
4135
4136     (when (and (string= references "")
4137                (setq in-reply-to (mail-header-extra header))
4138                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4139       (mail-header-set-references
4140        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4141
4142     (when gnus-alter-header-function
4143       (funcall gnus-alter-header-function header))
4144     (gnus-dependencies-add-header header dependencies force-new)))
4145
4146 (defun gnus-build-get-header (id)
4147   "Look through the buffer of NOV lines and find the header to ID.
4148 Enter this line into the dependencies hash table, and return
4149 the id of the parent article (if any)."
4150   (let ((deps gnus-newsgroup-dependencies)
4151         found header)
4152     (prog1
4153         (save-excursion
4154           (set-buffer nntp-server-buffer)
4155           (let ((case-fold-search nil))
4156             (goto-char (point-min))
4157             (while (and (not found)
4158                         (search-forward id nil t))
4159               (beginning-of-line)
4160               (setq found (looking-at
4161                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4162                                    (regexp-quote id))))
4163               (or found (beginning-of-line 2)))
4164             (when found
4165               (beginning-of-line)
4166               (and
4167                (setq header (gnus-nov-parse-line
4168                              (read (current-buffer)) deps))
4169                (gnus-parent-id (mail-header-references header))))))
4170       (when header
4171         (let ((number (mail-header-number header)))
4172           (push number gnus-newsgroup-limit)
4173           (push header gnus-newsgroup-headers)
4174           (if (memq number gnus-newsgroup-unselected)
4175               (progn
4176                 (setq gnus-newsgroup-unreads
4177                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4178                                                number))
4179                 (setq gnus-newsgroup-unselected
4180                       (delq number gnus-newsgroup-unselected)))
4181             (push number gnus-newsgroup-ancient)))))))
4182
4183 (defun gnus-build-all-threads ()
4184   "Read all the headers."
4185   (let ((gnus-summary-ignore-duplicates t)
4186         (mail-parse-charset gnus-newsgroup-charset)
4187         (dependencies gnus-newsgroup-dependencies)
4188         header article)
4189     (save-excursion
4190       (set-buffer nntp-server-buffer)
4191       (let ((case-fold-search nil))
4192         (goto-char (point-min))
4193         (while (not (eobp))
4194           (ignore-errors
4195             (setq article (read (current-buffer))
4196                   header (gnus-nov-parse-line article dependencies)))
4197           (when header
4198             (with-current-buffer gnus-summary-buffer
4199               (push header gnus-newsgroup-headers)
4200               (if (memq (setq article (mail-header-number header))
4201                         gnus-newsgroup-unselected)
4202                   (progn
4203                     (setq gnus-newsgroup-unreads
4204                           (gnus-add-to-sorted-list
4205                            gnus-newsgroup-unreads article))
4206                     (setq gnus-newsgroup-unselected
4207                           (delq article gnus-newsgroup-unselected)))
4208                 (push article gnus-newsgroup-ancient)))
4209             (forward-line 1)))))))
4210
4211 (defun gnus-summary-update-article-line (article header)
4212   "Update the line for ARTICLE using HEADER."
4213   (let* ((id (mail-header-id header))
4214          (thread (gnus-id-to-thread id)))
4215     (unless thread
4216       (error "Article in no thread"))
4217     ;; Update the thread.
4218     (setcar thread header)
4219     (gnus-summary-goto-subject article)
4220     (let* ((datal (gnus-data-find-list article))
4221            (data (car datal))
4222            (buffer-read-only nil)
4223            (level (gnus-summary-thread-level)))
4224       (gnus-delete-line)
4225       (let ((inserted (- (point)
4226                          (progn
4227                            (gnus-summary-insert-line
4228                             header level nil
4229                             (memq article gnus-newsgroup-undownloaded)
4230                             (gnus-article-mark article)
4231                             (memq article gnus-newsgroup-replied)
4232                             (memq article gnus-newsgroup-expirable)
4233                             ;; Only insert the Subject string when it's different
4234                             ;; from the previous Subject string.
4235                             (if (and
4236                                  gnus-show-threads
4237                                  (gnus-subject-equal
4238                                   (condition-case ()
4239                                       (mail-header-subject
4240                                        (gnus-data-header
4241                                         (cadr
4242                                          (gnus-data-find-list
4243                                           article
4244                                           (gnus-data-list t)))))
4245                                     ;; Error on the side of excessive subjects.
4246                                     (error ""))
4247                                   (mail-header-subject header)))
4248                                 ""
4249                               (mail-header-subject header))
4250                             nil (cdr (assq article gnus-newsgroup-scored))
4251                             (memq article gnus-newsgroup-processable))
4252                            (point)))))
4253         (when (cdr datal)
4254           (gnus-data-update-list
4255            (cdr datal)
4256            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4257
4258 (defun gnus-summary-update-article (article &optional iheader)
4259   "Update ARTICLE in the summary buffer."
4260   (set-buffer gnus-summary-buffer)
4261   (let* ((header (gnus-summary-article-header article))
4262          (id (mail-header-id header))
4263          (data (gnus-data-find article))
4264          (thread (gnus-id-to-thread id))
4265          (references (mail-header-references header))
4266          (parent
4267           (gnus-id-to-thread
4268            (or (gnus-parent-id
4269                 (when (and references
4270                            (not (equal "" references)))
4271                   references))
4272                "none")))
4273          (buffer-read-only nil)
4274          (old (car thread)))
4275     (when thread
4276       (unless iheader
4277         (setcar thread nil)
4278         (when parent
4279           (delq thread parent)))
4280       (if (gnus-summary-insert-subject id header)
4281           ;; Set the (possibly) new article number in the data structure.
4282           (gnus-data-set-number data (gnus-id-to-article id))
4283         (setcar thread old)
4284         nil))))
4285
4286 (defun gnus-rebuild-thread (id &optional line)
4287   "Rebuild the thread containing ID.
4288 If LINE, insert the rebuilt thread starting on line LINE."
4289   (let ((buffer-read-only nil)
4290         old-pos current thread data)
4291     (if (not gnus-show-threads)
4292         (setq thread (list (car (gnus-id-to-thread id))))
4293       ;; Get the thread this article is part of.
4294       (setq thread (gnus-remove-thread id)))
4295     (setq old-pos (point-at-bol))
4296     (setq current (save-excursion
4297                     (and (re-search-backward "[\r\n]" nil t)
4298                          (gnus-summary-article-number))))
4299     ;; If this is a gathered thread, we have to go some re-gathering.
4300     (when (stringp (car thread))
4301       (let ((subject (car thread))
4302             roots thr)
4303         (setq thread (cdr thread))
4304         (while thread
4305           (unless (memq (setq thr (gnus-id-to-thread
4306                                    (gnus-root-id
4307                                     (mail-header-id (caar thread)))))
4308                         roots)
4309             (push thr roots))
4310           (setq thread (cdr thread)))
4311         ;; We now have all (unique) roots.
4312         (if (= (length roots) 1)
4313             ;; All the loose roots are now one solid root.
4314             (setq thread (car roots))
4315           (setq thread (cons subject (gnus-sort-threads roots))))))
4316     (let (threads)
4317       ;; We then insert this thread into the summary buffer.
4318       (when line
4319         (goto-char (point-min))
4320         (forward-line (1- line)))
4321       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4322         (if gnus-show-threads
4323             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4324           (gnus-summary-prepare-unthreaded thread))
4325         (setq data (nreverse gnus-newsgroup-data))
4326         (setq threads gnus-newsgroup-threads))
4327       ;; We splice the new data into the data structure.
4328       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4329       ;;!!! then we want to insert at the beginning of the buffer.
4330       ;;!!! That happens to be true with Gnus now, but that may
4331       ;;!!! change in the future.  Perhaps.
4332       (gnus-data-enter-list
4333        (if line nil current) data (- (point) old-pos))
4334       (setq gnus-newsgroup-threads
4335             (nconc threads gnus-newsgroup-threads))
4336       (gnus-data-compute-positions))))
4337
4338 (defun gnus-number-to-header (number)
4339   "Return the header for article NUMBER."
4340   (let ((headers gnus-newsgroup-headers))
4341     (while (and headers
4342                 (not (= number (mail-header-number (car headers)))))
4343       (pop headers))
4344     (when headers
4345       (car headers))))
4346
4347 (defun gnus-parent-headers (in-headers &optional generation)
4348   "Return the headers of the GENERATIONeth parent of HEADERS."
4349   (unless generation
4350     (setq generation 1))
4351   (let ((parent t)
4352         (headers in-headers)
4353         references)
4354     (while (and parent
4355                 (not (zerop generation))
4356                 (setq references (mail-header-references headers)))
4357       (setq headers (if (and references
4358                              (setq parent (gnus-parent-id references)))
4359                         (car (gnus-id-to-thread parent))
4360                       nil))
4361       (decf generation))
4362     (and (not (eq headers in-headers))
4363          headers)))
4364
4365 (defun gnus-id-to-thread (id)
4366   "Return the (sub-)thread where ID appears."
4367   (gnus-gethash id gnus-newsgroup-dependencies))
4368
4369 (defun gnus-id-to-article (id)
4370   "Return the article number of ID."
4371   (let ((thread (gnus-id-to-thread id)))
4372     (when (and thread
4373                (car thread))
4374       (mail-header-number (car thread)))))
4375
4376 (defun gnus-id-to-header (id)
4377   "Return the article headers of ID."
4378   (car (gnus-id-to-thread id)))
4379
4380 (defun gnus-article-displayed-root-p (article)
4381   "Say whether ARTICLE is a root(ish) article."
4382   (let ((level (gnus-summary-thread-level article))
4383         (refs (mail-header-references  (gnus-summary-article-header article)))
4384         particle)
4385     (cond
4386      ((null level) nil)
4387      ((zerop level) t)
4388      ((null refs) t)
4389      ((null (gnus-parent-id refs)) t)
4390      ((and (= 1 level)
4391            (null (setq particle (gnus-id-to-article
4392                                  (gnus-parent-id refs))))
4393            (null (gnus-summary-thread-level particle)))))))
4394
4395 (defun gnus-root-id (id)
4396   "Return the id of the root of the thread where ID appears."
4397   (let (last-id prev)
4398     (while (and id (setq prev (car (gnus-id-to-thread id))))
4399       (setq last-id id
4400             id (gnus-parent-id (mail-header-references prev))))
4401     last-id))
4402
4403 (defun gnus-articles-in-thread (thread)
4404   "Return the list of articles in THREAD."
4405   (cons (mail-header-number (car thread))
4406         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4407
4408 (defun gnus-remove-thread (id &optional dont-remove)
4409   "Remove the thread that has ID in it."
4410   (let (headers thread last-id)
4411     ;; First go up in this thread until we find the root.
4412     (setq last-id (gnus-root-id id)
4413           headers (message-flatten-list (gnus-id-to-thread last-id)))
4414     ;; We have now found the real root of this thread.  It might have
4415     ;; been gathered into some loose thread, so we have to search
4416     ;; through the threads to find the thread we wanted.
4417     (let ((threads gnus-newsgroup-threads)
4418           sub)
4419       (while threads
4420         (setq sub (car threads))
4421         (if (stringp (car sub))
4422             ;; This is a gathered thread, so we look at the roots
4423             ;; below it to find whether this article is in this
4424             ;; gathered root.
4425             (progn
4426               (setq sub (cdr sub))
4427               (while sub
4428                 (when (member (caar sub) headers)
4429                   (setq thread (car threads)
4430                         threads nil
4431                         sub nil))
4432                 (setq sub (cdr sub))))
4433           ;; It's an ordinary thread, so we check it.
4434           (when (eq (car sub) (car headers))
4435             (setq thread sub
4436                   threads nil)))
4437         (setq threads (cdr threads)))
4438       ;; If this article is in no thread, then it's a root.
4439       (if thread
4440           (unless dont-remove
4441             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4442         (setq thread (gnus-id-to-thread last-id)))
4443       (when thread
4444         (prog1
4445             thread                      ; We return this thread.
4446           (unless dont-remove
4447             (if (stringp (car thread))
4448                 (progn
4449                   ;; If we use dummy roots, then we have to remove the
4450                   ;; dummy root as well.
4451                   (when (eq gnus-summary-make-false-root 'dummy)
4452                     ;; We go to the dummy root by going to
4453                     ;; the first sub-"thread", and then one line up.
4454                     (gnus-summary-goto-article
4455                      (mail-header-number (caadr thread)))
4456                     (forward-line -1)
4457                     (gnus-delete-line)
4458                     (gnus-data-compute-positions))
4459                   (setq thread (cdr thread))
4460                   (while thread
4461                     (gnus-remove-thread-1 (car thread))
4462                     (setq thread (cdr thread))))
4463               (gnus-remove-thread-1 thread))))))))
4464
4465 (defun gnus-remove-thread-1 (thread)
4466   "Remove the thread THREAD recursively."
4467   (let ((number (mail-header-number (pop thread)))
4468         d)
4469     (setq thread (reverse thread))
4470     (while thread
4471       (gnus-remove-thread-1 (pop thread)))
4472     (when (setq d (gnus-data-find number))
4473       (goto-char (gnus-data-pos d))
4474       (gnus-summary-show-thread)
4475       (gnus-data-remove
4476        number
4477        (- (point-at-bol)
4478           (prog1
4479               (1+ (point-at-eol))
4480             (gnus-delete-line)))))))
4481
4482 (defun gnus-sort-threads-1 (threads func)
4483   (sort (mapcar (lambda (thread)
4484                   (cons (car thread)
4485                         (and (cdr thread)
4486                              (gnus-sort-threads-1 (cdr thread) func))))
4487                 threads) func))
4488
4489 (defun gnus-sort-threads (threads)
4490   "Sort THREADS."
4491   (if (not gnus-thread-sort-functions)
4492       threads
4493     (gnus-message 8 "Sorting threads...")
4494     (let ((max-lisp-eval-depth 5000))
4495       (prog1 (gnus-sort-threads-1
4496          threads
4497          (gnus-make-sort-function gnus-thread-sort-functions))
4498         (gnus-message 8 "Sorting threads...done")))))
4499
4500 (defun gnus-sort-articles (articles)
4501   "Sort ARTICLES."
4502   (when gnus-article-sort-functions
4503     (gnus-message 7 "Sorting articles...")
4504     (prog1
4505         (setq gnus-newsgroup-headers
4506               (sort articles (gnus-make-sort-function
4507                               gnus-article-sort-functions)))
4508       (gnus-message 7 "Sorting articles...done"))))
4509
4510 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4511 (defmacro gnus-thread-header (thread)
4512   "Return header of first article in THREAD.
4513 Note that THREAD must never, ever be anything else than a variable -
4514 using some other form will lead to serious barfage."
4515   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4516   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4517   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4518         (vector thread) 2))
4519
4520 (defsubst gnus-article-sort-by-number (h1 h2)
4521   "Sort articles by article number."
4522   (< (mail-header-number h1)
4523      (mail-header-number h2)))
4524
4525 (defun gnus-thread-sort-by-number (h1 h2)
4526   "Sort threads by root article number."
4527   (gnus-article-sort-by-number
4528    (gnus-thread-header h1) (gnus-thread-header h2)))
4529
4530 (defsubst gnus-article-sort-by-random (h1 h2)
4531   "Sort articles by article number."
4532   (zerop (random 2)))
4533
4534 (defun gnus-thread-sort-by-random (h1 h2)
4535   "Sort threads by root article number."
4536   (gnus-article-sort-by-random
4537    (gnus-thread-header h1) (gnus-thread-header h2)))
4538
4539 (defsubst gnus-article-sort-by-lines (h1 h2)
4540   "Sort articles by article Lines header."
4541   (< (mail-header-lines h1)
4542      (mail-header-lines h2)))
4543
4544 (defun gnus-thread-sort-by-lines (h1 h2)
4545   "Sort threads by root article Lines header."
4546   (gnus-article-sort-by-lines
4547    (gnus-thread-header h1) (gnus-thread-header h2)))
4548
4549 (defsubst gnus-article-sort-by-chars (h1 h2)
4550   "Sort articles by octet length."
4551   (< (mail-header-chars h1)
4552      (mail-header-chars h2)))
4553
4554 (defun gnus-thread-sort-by-chars (h1 h2)
4555   "Sort threads by root article octet length."
4556   (gnus-article-sort-by-chars
4557    (gnus-thread-header h1) (gnus-thread-header h2)))
4558
4559 (defsubst gnus-article-sort-by-author (h1 h2)
4560   "Sort articles by root author."
4561   (string-lessp
4562    (let ((extract (funcall
4563                    gnus-extract-address-components
4564                    (mail-header-from h1))))
4565      (or (car extract) (cadr extract) ""))
4566    (let ((extract (funcall
4567                    gnus-extract-address-components
4568                    (mail-header-from h2))))
4569      (or (car extract) (cadr extract) ""))))
4570
4571 (defun gnus-thread-sort-by-author (h1 h2)
4572   "Sort threads by root author."
4573   (gnus-article-sort-by-author
4574    (gnus-thread-header h1)  (gnus-thread-header h2)))
4575
4576 (defsubst gnus-article-sort-by-recipient (h1 h2)
4577   "Sort articles by recipient."
4578   (string-lessp
4579    (let ((extract (funcall
4580                    gnus-extract-address-components
4581                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4582      (or (car extract) (cadr extract)))
4583    (let ((extract (funcall
4584                    gnus-extract-address-components
4585                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4586      (or (car extract) (cadr extract)))))
4587
4588 (defsubst gnus-article-sort-by-subject (h1 h2)
4589   "Sort articles by root subject."
4590   (string-lessp
4591    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4592    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4593
4594 (defun gnus-thread-sort-by-subject (h1 h2)
4595   "Sort threads by root subject."
4596   (gnus-article-sort-by-subject
4597    (gnus-thread-header h1) (gnus-thread-header h2)))
4598
4599 (defsubst gnus-article-sort-by-date (h1 h2)
4600   "Sort articles by root article date."
4601   (time-less-p
4602    (gnus-date-get-time (mail-header-date h1))
4603    (gnus-date-get-time (mail-header-date h2))))
4604
4605 (defun gnus-thread-sort-by-date (h1 h2)
4606   "Sort threads by root article date."
4607   (gnus-article-sort-by-date
4608    (gnus-thread-header h1) (gnus-thread-header h2)))
4609
4610 (defsubst gnus-article-sort-by-score (h1 h2)
4611   "Sort articles by root article score.
4612 Unscored articles will be counted as having a score of zero."
4613   (> (or (cdr (assq (mail-header-number h1)
4614                     gnus-newsgroup-scored))
4615          gnus-summary-default-score 0)
4616      (or (cdr (assq (mail-header-number h2)
4617                     gnus-newsgroup-scored))
4618          gnus-summary-default-score 0)))
4619
4620 (defun gnus-thread-sort-by-score (h1 h2)
4621   "Sort threads by root article score."
4622   (gnus-article-sort-by-score
4623    (gnus-thread-header h1) (gnus-thread-header h2)))
4624
4625 (defun gnus-thread-sort-by-total-score (h1 h2)
4626   "Sort threads by the sum of all scores in the thread.
4627 Unscored articles will be counted as having a score of zero."
4628   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4629
4630 (defun gnus-thread-total-score (thread)
4631   ;; This function find the total score of THREAD.
4632   (cond
4633    ((null thread)
4634     0)
4635    ((consp thread)
4636     (if (stringp (car thread))
4637         (apply gnus-thread-score-function 0
4638                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4639       (gnus-thread-total-score-1 thread)))
4640    (t
4641     (gnus-thread-total-score-1 (list thread)))))
4642
4643 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4644   "Sort threads such that the thread with the most recently arrived article comes first."
4645   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4646
4647 (defun gnus-thread-highest-number (thread)
4648   "Return the highest article number in THREAD."
4649   (apply 'max (mapcar (lambda (header)
4650                         (mail-header-number header))
4651                       (message-flatten-list thread))))
4652
4653 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4654   "Sort threads such that the thread with the most recently dated article comes first."
4655   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4656
4657 (defun gnus-thread-latest-date (thread)
4658   "Return the highest article date in THREAD."
4659   (let ((previous-time 0))
4660     (apply 'max
4661            (mapcar
4662             (lambda (header)
4663               (setq previous-time
4664                     (condition-case ()
4665                         (time-to-seconds (mail-header-parse-date
4666                                           (mail-header-date header)))
4667                       (error previous-time))))
4668             (sort
4669              (message-flatten-list thread)
4670              (lambda (h1 h2)
4671                (< (mail-header-number h1)
4672                   (mail-header-number h2))))))))
4673
4674 (defun gnus-thread-total-score-1 (root)
4675   ;; This function find the total score of the thread below ROOT.
4676   (setq root (car root))
4677   (apply gnus-thread-score-function
4678          (or (append
4679               (mapcar 'gnus-thread-total-score
4680                       (cdr (gnus-id-to-thread (mail-header-id root))))
4681               (when (> (mail-header-number root) 0)
4682                 (list (or (cdr (assq (mail-header-number root)
4683                                      gnus-newsgroup-scored))
4684                           gnus-summary-default-score 0))))
4685              (list gnus-summary-default-score)
4686              '(0))))
4687
4688 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4689 (defvar gnus-tmp-prev-subject nil)
4690 (defvar gnus-tmp-false-parent nil)
4691 (defvar gnus-tmp-root-expunged nil)
4692 (defvar gnus-tmp-dummy-line nil)
4693
4694 (eval-when-compile (defvar gnus-tmp-header))
4695 (defun gnus-extra-header (type &optional header)
4696   "Return the extra header of TYPE."
4697   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4698       ""))
4699
4700 (defvar gnus-tmp-thread-tree-header-string "")
4701
4702 (defcustom gnus-sum-thread-tree-root "> "
4703   "With %B spec, used for the root of a thread.
4704 If nil, use subject instead."
4705   :version "21.4"
4706   :type '(radio (const :format "%v  " nil) string)
4707   :group 'gnus-thread)
4708 (defcustom gnus-sum-thread-tree-false-root "> "
4709   "With %B spec, used for a false root of a thread.
4710 If nil, use subject instead."
4711   :version "21.4"
4712   :type '(radio (const :format "%v  " nil) string)
4713   :group 'gnus-thread)
4714 (defcustom gnus-sum-thread-tree-single-indent ""
4715   "With %B spec, used for a thread with just one message.
4716 If nil, use subject instead."
4717   :version "21.4"
4718   :type '(radio (const :format "%v  " nil) string)
4719   :group 'gnus-thread)
4720 (defcustom gnus-sum-thread-tree-vertical "| "
4721   "With %B spec, used for drawing a vertical line."
4722   :version "21.4"
4723   :type 'string
4724   :group 'gnus-thread)
4725 (defcustom gnus-sum-thread-tree-indent "  "
4726   "With %B spec, used for indenting."
4727   :version "21.4"
4728   :type 'string
4729   :group 'gnus-thread)
4730 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4731   "With %B spec, used for a leaf with brothers."
4732   :version "21.4"
4733   :type 'string
4734   :group 'gnus-thread)
4735 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4736   "With %B spec, used for a leaf without brothers."
4737   :version "21.4"
4738   :type 'string
4739   :group 'gnus-thread)
4740
4741 (defun gnus-summary-prepare-threads (threads)
4742   "Prepare summary buffer from THREADS and indentation LEVEL.
4743 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4744 or a straight list of headers."
4745   (gnus-message 7 "Generating summary...")
4746
4747   (setq gnus-newsgroup-threads threads)
4748   (beginning-of-line)
4749
4750   (let ((gnus-tmp-level 0)
4751         (default-score (or gnus-summary-default-score 0))
4752         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4753         (building-line-count gnus-summary-display-while-building)
4754         (building-count (integerp gnus-summary-display-while-building))
4755         thread number subject stack state gnus-tmp-gathered beg-match
4756         new-roots gnus-tmp-new-adopts thread-end simp-subject
4757         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4758         gnus-tmp-replied gnus-tmp-subject-or-nil
4759         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4760         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4761         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4762         tree-stack)
4763
4764     (setq gnus-tmp-prev-subject nil
4765           gnus-tmp-thread-tree-header-string "")
4766
4767     (if (vectorp (car threads))
4768         ;; If this is a straight (sic) list of headers, then a
4769         ;; threaded summary display isn't required, so we just create
4770         ;; an unthreaded one.
4771         (gnus-summary-prepare-unthreaded threads)
4772
4773       ;; Do the threaded display.
4774
4775       (if gnus-summary-display-while-building
4776           (switch-to-buffer (buffer-name)))
4777       (while (or threads stack gnus-tmp-new-adopts new-roots)
4778
4779         (if (and (= gnus-tmp-level 0)
4780                  (or (not stack)
4781                      (= (caar stack) 0))
4782                  (not gnus-tmp-false-parent)
4783                  (or gnus-tmp-new-adopts new-roots))
4784             (if gnus-tmp-new-adopts
4785                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4786                       thread (list (car gnus-tmp-new-adopts))
4787                       gnus-tmp-header (caar thread)
4788                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4789               (when new-roots
4790                 (setq thread (list (car new-roots))
4791                       gnus-tmp-header (caar thread)
4792                       new-roots (cdr new-roots))))
4793
4794           (if threads
4795               ;; If there are some threads, we do them before the
4796               ;; threads on the stack.
4797               (setq thread threads
4798                     gnus-tmp-header (caar thread))
4799             ;; There were no current threads, so we pop something off
4800             ;; the stack.
4801             (setq state (car stack)
4802                   gnus-tmp-level (car state)
4803                   tree-stack (cadr state)
4804                   thread (caddr state)
4805                   stack (cdr stack)
4806                   gnus-tmp-header (caar thread))))
4807
4808         (setq gnus-tmp-false-parent nil)
4809         (setq gnus-tmp-root-expunged nil)
4810         (setq thread-end nil)
4811
4812         (if (stringp gnus-tmp-header)
4813             ;; The header is a dummy root.
4814             (cond
4815              ((eq gnus-summary-make-false-root 'adopt)
4816               ;; We let the first article adopt the rest.
4817               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4818                                                (cddar thread)))
4819               (setq gnus-tmp-gathered
4820                     (nconc (mapcar
4821                             (lambda (h) (mail-header-number (car h)))
4822                             (cddar thread))
4823                            gnus-tmp-gathered))
4824               (setq thread (cons (list (caar thread)
4825                                        (cadar thread))
4826                                  (cdr thread)))
4827               (setq gnus-tmp-level -1
4828                     gnus-tmp-false-parent t))
4829              ((eq gnus-summary-make-false-root 'empty)
4830               ;; We print adopted articles with empty subject fields.
4831               (setq gnus-tmp-gathered
4832                     (nconc (mapcar
4833                             (lambda (h) (mail-header-number (car h)))
4834                             (cddar thread))
4835                            gnus-tmp-gathered))
4836               (setq gnus-tmp-level -1))
4837              ((eq gnus-summary-make-false-root 'dummy)
4838               ;; We remember that we probably want to output a dummy
4839               ;; root.
4840               (setq gnus-tmp-dummy-line gnus-tmp-header)
4841               (setq gnus-tmp-prev-subject gnus-tmp-header))
4842              (t
4843               ;; We do not make a root for the gathered
4844               ;; sub-threads at all.
4845               (setq gnus-tmp-level -1)))
4846
4847           (setq number (mail-header-number gnus-tmp-header)
4848                 subject (mail-header-subject gnus-tmp-header)
4849                 simp-subject (gnus-simplify-subject-fully subject))
4850
4851           (cond
4852            ;; If the thread has changed subject, we might want to make
4853            ;; this subthread into a root.
4854            ((and (null gnus-thread-ignore-subject)
4855                  (not (zerop gnus-tmp-level))
4856                  gnus-tmp-prev-subject
4857                  (not (string= gnus-tmp-prev-subject simp-subject)))
4858             (setq new-roots (nconc new-roots (list (car thread)))
4859                   thread-end t
4860                   gnus-tmp-header nil))
4861            ;; If the article lies outside the current limit,
4862            ;; then we do not display it.
4863            ((not (memq number gnus-newsgroup-limit))
4864             (setq gnus-tmp-gathered
4865                   (nconc (mapcar
4866                           (lambda (h) (mail-header-number (car h)))
4867                           (cdar thread))
4868                          gnus-tmp-gathered))
4869             (setq gnus-tmp-new-adopts (if (cdar thread)
4870                                           (append gnus-tmp-new-adopts
4871                                                   (cdar thread))
4872                                         gnus-tmp-new-adopts)
4873                   thread-end t
4874                   gnus-tmp-header nil)
4875             (when (zerop gnus-tmp-level)
4876               (setq gnus-tmp-root-expunged t)))
4877            ;; Perhaps this article is to be marked as read?
4878            ((and gnus-summary-mark-below
4879                  (< (or (cdr (assq number gnus-newsgroup-scored))
4880                         default-score)
4881                     gnus-summary-mark-below)
4882                  ;; Don't touch sparse articles.
4883                  (not (gnus-summary-article-sparse-p number))
4884                  (not (gnus-summary-article-ancient-p number)))
4885             (setq gnus-newsgroup-unreads
4886                   (delq number gnus-newsgroup-unreads))
4887             (if gnus-newsgroup-auto-expire
4888                 (setq gnus-newsgroup-expirable
4889                       (gnus-add-to-sorted-list
4890                        gnus-newsgroup-expirable number))
4891               (push (cons number gnus-low-score-mark)
4892                     gnus-newsgroup-reads))))
4893
4894           (when gnus-tmp-header
4895             ;; We may have an old dummy line to output before this
4896             ;; article.
4897             (when (and gnus-tmp-dummy-line
4898                        (gnus-subject-equal
4899                         gnus-tmp-dummy-line
4900                         (mail-header-subject gnus-tmp-header)))
4901               (gnus-summary-insert-dummy-line
4902                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4903               (setq gnus-tmp-dummy-line nil))
4904
4905             ;; Compute the mark.
4906             (setq gnus-tmp-unread (gnus-article-mark number))
4907
4908             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4909                                   gnus-tmp-header gnus-tmp-level)
4910                   gnus-newsgroup-data)
4911
4912             ;; Actually insert the line.
4913             (setq
4914              gnus-tmp-subject-or-nil
4915              (cond
4916               ((and gnus-thread-ignore-subject
4917                     gnus-tmp-prev-subject
4918                     (not (string= gnus-tmp-prev-subject simp-subject)))
4919                subject)
4920               ((zerop gnus-tmp-level)
4921                (if (and (eq gnus-summary-make-false-root 'empty)
4922                         (memq number gnus-tmp-gathered)
4923                         gnus-tmp-prev-subject
4924                         (string= gnus-tmp-prev-subject simp-subject))
4925                    gnus-summary-same-subject
4926                  subject))
4927               (t gnus-summary-same-subject)))
4928             (if (and (eq gnus-summary-make-false-root 'adopt)
4929                      (= gnus-tmp-level 1)
4930                      (memq number gnus-tmp-gathered))
4931                 (setq gnus-tmp-opening-bracket ?\<
4932                       gnus-tmp-closing-bracket ?\>)
4933               (setq gnus-tmp-opening-bracket ?\[
4934                     gnus-tmp-closing-bracket ?\]))
4935             (setq
4936              gnus-tmp-indentation
4937              (aref gnus-thread-indent-array gnus-tmp-level)
4938              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4939              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4940                                 gnus-summary-default-score 0)
4941              gnus-tmp-score-char
4942              (if (or (null gnus-summary-default-score)
4943                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4944                          gnus-summary-zcore-fuzz))
4945                  ?                      ;Whitespace
4946                (if (< gnus-tmp-score gnus-summary-default-score)
4947                    gnus-score-below-mark gnus-score-over-mark))
4948              gnus-tmp-replied
4949              (cond ((memq number gnus-newsgroup-processable)
4950                     gnus-process-mark)
4951                    ((memq number gnus-newsgroup-cached)
4952                     gnus-cached-mark)
4953                    ((memq number gnus-newsgroup-replied)
4954                     gnus-replied-mark)
4955                    ((memq number gnus-newsgroup-forwarded)
4956                     gnus-forwarded-mark)
4957                    ((memq number gnus-newsgroup-saved)
4958                     gnus-saved-mark)
4959                    ((memq number gnus-newsgroup-recent)
4960                     gnus-recent-mark)
4961                    ((memq number gnus-newsgroup-unseen)
4962                     gnus-unseen-mark)
4963                    (t gnus-no-mark))
4964              gnus-tmp-downloaded
4965              (cond ((memq number gnus-newsgroup-undownloaded)
4966                     gnus-undownloaded-mark)
4967                    (gnus-newsgroup-agentized
4968                     gnus-downloaded-mark)
4969                    (t
4970                     gnus-no-mark))
4971              gnus-tmp-from (mail-header-from gnus-tmp-header)
4972              gnus-tmp-name
4973              (cond
4974               ((string-match "<[^>]+> *$" gnus-tmp-from)
4975                (setq beg-match (match-beginning 0))
4976                (or (and (string-match "^\".+\"" gnus-tmp-from)
4977                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4978                    (substring gnus-tmp-from 0 beg-match)))
4979               ((string-match "(.+)" gnus-tmp-from)
4980                (substring gnus-tmp-from
4981                           (1+ (match-beginning 0)) (1- (match-end 0))))
4982               (t gnus-tmp-from))
4983
4984              ;; Do the %B string
4985              gnus-tmp-thread-tree-header-string
4986              (cond
4987               ((not gnus-show-threads) "")
4988               ((zerop gnus-tmp-level)
4989                (cond ((cdar thread)
4990                       (or gnus-sum-thread-tree-root subject))
4991                      (gnus-tmp-new-adopts
4992                       (or gnus-sum-thread-tree-false-root subject))
4993                      (t
4994                       (or gnus-sum-thread-tree-single-indent subject))))
4995               (t
4996                (concat (apply 'concat
4997                               (mapcar (lambda (item)
4998                                         (if (= item 1)
4999                                             gnus-sum-thread-tree-vertical
5000                                           gnus-sum-thread-tree-indent))
5001                                       (cdr (reverse tree-stack))))
5002                        (if (nth 1 thread)
5003                            gnus-sum-thread-tree-leaf-with-other
5004                          gnus-sum-thread-tree-single-leaf)))))
5005             (when (string= gnus-tmp-name "")
5006               (setq gnus-tmp-name gnus-tmp-from))
5007             (unless (numberp gnus-tmp-lines)
5008               (setq gnus-tmp-lines -1))
5009             (if (= gnus-tmp-lines -1)
5010                 (setq gnus-tmp-lines "?")
5011               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5012               (gnus-put-text-property
5013              (point)
5014              (progn (eval gnus-summary-line-format-spec) (point))
5015                'gnus-number number)
5016             (when gnus-visual-p
5017               (forward-line -1)
5018               (gnus-run-hooks 'gnus-summary-update-hook)
5019               (forward-line 1))
5020
5021             (setq gnus-tmp-prev-subject simp-subject)))
5022
5023         (when (nth 1 thread)
5024           (push (list (max 0 gnus-tmp-level)
5025                       (copy-sequence tree-stack)
5026                       (nthcdr 1 thread))
5027                 stack))
5028         (push (if (nth 1 thread) 1 0) tree-stack)
5029         (incf gnus-tmp-level)
5030         (setq threads (if thread-end nil (cdar thread)))
5031         (if gnus-summary-display-while-building
5032             (if building-count
5033                 (progn
5034                   ;; use a set frequency
5035                   (setq building-line-count (1- building-line-count))
5036                   (when (= building-line-count 0)
5037                     (sit-for 0)
5038                     (setq building-line-count
5039                           gnus-summary-display-while-building)))
5040               ;; always
5041               (sit-for 0)))
5042         (unless threads
5043           (setq gnus-tmp-level 0)))))
5044   (gnus-message 7 "Generating summary...done"))
5045
5046 (defun gnus-summary-prepare-unthreaded (headers)
5047   "Generate an unthreaded summary buffer based on HEADERS."
5048   (let (header number mark)
5049
5050     (beginning-of-line)
5051
5052     (while headers
5053       ;; We may have to root out some bad articles...
5054       (when (memq (setq number (mail-header-number
5055                                 (setq header (pop headers))))
5056                   gnus-newsgroup-limit)
5057         ;; Mark article as read when it has a low score.
5058         (when (and gnus-summary-mark-below
5059                    (< (or (cdr (assq number gnus-newsgroup-scored))
5060                           gnus-summary-default-score 0)
5061                       gnus-summary-mark-below)
5062                    (not (gnus-summary-article-ancient-p number)))
5063           (setq gnus-newsgroup-unreads
5064                 (delq number gnus-newsgroup-unreads))
5065           (if gnus-newsgroup-auto-expire
5066               (push number gnus-newsgroup-expirable)
5067             (push (cons number gnus-low-score-mark)
5068                   gnus-newsgroup-reads)))
5069
5070         (setq mark (gnus-article-mark number))
5071         (push (gnus-data-make number mark (1+ (point)) header 0)
5072               gnus-newsgroup-data)
5073         (gnus-summary-insert-line
5074          header 0 number
5075          (memq number gnus-newsgroup-undownloaded)
5076          mark (memq number gnus-newsgroup-replied)
5077          (memq number gnus-newsgroup-expirable)
5078          (mail-header-subject header) nil
5079          (cdr (assq number gnus-newsgroup-scored))
5080          (memq number gnus-newsgroup-processable))))))
5081
5082 (defun gnus-summary-remove-list-identifiers ()
5083   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5084   (let ((regexp (if (consp gnus-list-identifiers)
5085                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5086                   gnus-list-identifiers))
5087         changed subject)
5088     (when regexp
5089       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5090       (dolist (header gnus-newsgroup-headers)
5091         (setq subject (mail-header-subject header)
5092               changed nil)
5093         (while (string-match regexp subject)
5094           (setq subject
5095                 (concat (substring subject 0 (match-beginning 1))
5096                         (substring subject (match-end 0)))
5097                 changed t))
5098         (when changed
5099           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5100             (setq subject
5101                   (concat (substring subject 0 (match-beginning 1))
5102                           (substring subject (match-end 1)))))
5103           (mail-header-set-subject header subject))))))
5104
5105 (defun gnus-fetch-headers (articles)
5106   "Fetch headers of ARTICLES."
5107   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5108     (gnus-message 5 "Fetching headers for %s..." name)
5109     (prog1
5110         (if (eq 'nov
5111                 (setq gnus-headers-retrieved-by
5112                       (gnus-retrieve-headers
5113                        articles gnus-newsgroup-name
5114                        ;; We might want to fetch old headers, but
5115                        ;; not if there is only 1 article.
5116                        (and (or (and
5117                                  (not (eq gnus-fetch-old-headers 'some))
5118                                  (not (numberp gnus-fetch-old-headers)))
5119                                 (> (length articles) 1))
5120                             gnus-fetch-old-headers))))
5121             (gnus-get-newsgroup-headers-xover
5122              articles nil nil gnus-newsgroup-name t)
5123           (gnus-get-newsgroup-headers))
5124       (gnus-message 5 "Fetching headers for %s...done" name))))
5125
5126 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5127   "Select newsgroup GROUP.
5128 If READ-ALL is non-nil, all articles in the group are selected.
5129 If SELECT-ARTICLES, only select those articles from GROUP."
5130   (let* ((entry (gnus-group-entry group))
5131          ;;!!! Dirty hack; should be removed.
5132          (gnus-summary-ignore-duplicates
5133           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5134               t
5135             gnus-summary-ignore-duplicates))
5136          (info (nth 2 entry))
5137          articles fetched-articles cached)
5138
5139     (unless (gnus-check-server
5140              (set (make-local-variable 'gnus-current-select-method)
5141                   (gnus-find-method-for-group group)))
5142       (error "Couldn't open server"))
5143
5144     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5145         (gnus-activate-group group)     ; Or we can activate it...
5146         (progn                          ; Or we bug out.
5147           (when (equal major-mode 'gnus-summary-mode)
5148             (gnus-kill-buffer (current-buffer)))
5149           (error "Couldn't activate group %s: %s"
5150                  group (gnus-status-message group))))
5151
5152     (unless (gnus-request-group group t)
5153       (when (equal major-mode 'gnus-summary-mode)
5154         (gnus-kill-buffer (current-buffer)))
5155       (error "Couldn't request group %s: %s"
5156              group (gnus-status-message group)))
5157
5158     (when gnus-agent
5159       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5160
5161       (setq gnus-summary-use-undownloaded-faces
5162             (gnus-agent-find-parameter
5163              group
5164              'agent-enable-undownloaded-faces)))
5165
5166     (setq gnus-newsgroup-name group
5167           gnus-newsgroup-unselected nil
5168           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5169
5170     (let ((display (gnus-group-find-parameter group 'display)))
5171       (setq gnus-newsgroup-display
5172             (cond
5173              ((not (zerop (or (car-safe read-all) 0)))
5174               ;; The user entered the group with C-u SPC/RET, let's show
5175               ;; all articles.
5176               'gnus-not-ignore)
5177              ((eq display 'all)
5178               'gnus-not-ignore)
5179              ((arrayp display)
5180               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5181              ((numberp display)
5182               ;; The following is probably the "correct" solution, but
5183               ;; it makes Gnus fetch all headers and then limit the
5184               ;; articles (which is slow), so instead we hack the
5185               ;; select-articles parameter instead. -- Simon Josefsson
5186               ;; <jas@kth.se>
5187               ;;
5188               ;; (gnus-byte-compile
5189               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5190               ;;                         display)))))
5191               (setq select-articles
5192                     (gnus-uncompress-range
5193                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5194                              (if (> tmp 0)
5195                                  tmp
5196                                1))
5197                            (cdr (gnus-active group)))))
5198               nil)
5199              (t
5200               nil))))
5201
5202     (gnus-summary-setup-default-charset)
5203
5204     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5205     (when (gnus-virtual-group-p group)
5206       (setq cached gnus-newsgroup-cached))
5207
5208     (setq gnus-newsgroup-unreads
5209           (gnus-sorted-ndifference
5210            (gnus-sorted-ndifference gnus-newsgroup-unreads
5211                                     gnus-newsgroup-marked)
5212            gnus-newsgroup-dormant))
5213
5214     (setq gnus-newsgroup-processable nil)
5215
5216     (gnus-update-read-articles group gnus-newsgroup-unreads)
5217
5218     ;; Adjust and set lists of article marks.
5219     (when info
5220       (gnus-adjust-marked-articles info))
5221     (if (setq articles select-articles)
5222         (setq gnus-newsgroup-unselected
5223               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5224       (setq articles (gnus-articles-to-read group read-all)))
5225
5226     (cond
5227      ((null articles)
5228       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5229       'quit)
5230      ((eq articles 0) nil)
5231      (t
5232       ;; Init the dependencies hash table.
5233       (setq gnus-newsgroup-dependencies
5234             (gnus-make-hashtable (length articles)))
5235       (gnus-set-global-variables)
5236       ;; Retrieve the headers and read them in.
5237
5238       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5239
5240       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5241       (when cached
5242         (setq gnus-newsgroup-cached cached))
5243
5244       ;; Suppress duplicates?
5245       (when gnus-suppress-duplicates
5246         (gnus-dup-suppress-articles))
5247
5248       ;; Set the initial limit.
5249       (setq gnus-newsgroup-limit (copy-sequence articles))
5250       ;; Remove canceled articles from the list of unread articles.
5251       (setq fetched-articles
5252             (mapcar (lambda (headers) (mail-header-number headers))
5253                     gnus-newsgroup-headers))
5254       (setq gnus-newsgroup-articles fetched-articles)
5255       (setq gnus-newsgroup-unreads
5256             (gnus-sorted-nintersection
5257              gnus-newsgroup-unreads fetched-articles))
5258       (gnus-compute-unseen-list)
5259
5260       ;; Removed marked articles that do not exist.
5261       (gnus-update-missing-marks
5262        (gnus-sorted-difference articles fetched-articles))
5263       ;; We might want to build some more threads first.
5264       (when (and gnus-fetch-old-headers
5265                  (eq gnus-headers-retrieved-by 'nov))
5266         (if (eq gnus-fetch-old-headers 'invisible)
5267             (gnus-build-all-threads)
5268           (gnus-build-old-threads)))
5269       ;; Let the Gnus agent mark articles as read.
5270       (when gnus-agent
5271         (gnus-agent-get-undownloaded-list))
5272       ;; Remove list identifiers from subject
5273       (when gnus-list-identifiers
5274         (gnus-summary-remove-list-identifiers))
5275       ;; Check whether auto-expire is to be done in this group.
5276       (setq gnus-newsgroup-auto-expire
5277             (gnus-group-auto-expirable-p group))
5278       ;; Set up the article buffer now, if necessary.
5279       (unless gnus-single-article-buffer
5280         (gnus-article-setup-buffer))
5281       ;; First and last article in this newsgroup.
5282       (when gnus-newsgroup-headers
5283         (setq gnus-newsgroup-begin
5284               (mail-header-number (car gnus-newsgroup-headers))
5285               gnus-newsgroup-end
5286               (mail-header-number
5287                (gnus-last-element gnus-newsgroup-headers))))
5288       ;; GROUP is successfully selected.
5289       (or gnus-newsgroup-headers t)))))
5290
5291 (defun gnus-compute-unseen-list ()
5292   ;; The `seen' marks are treated specially.
5293   (if (not gnus-newsgroup-seen)
5294       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5295     (setq gnus-newsgroup-unseen
5296           (gnus-inverse-list-range-intersection
5297            gnus-newsgroup-articles gnus-newsgroup-seen))))
5298
5299 (defun gnus-summary-display-make-predicate (display)
5300   (require 'gnus-agent)
5301   (when (= (length display) 1)
5302     (setq display (car display)))
5303   (unless gnus-summary-display-cache
5304     (dolist (elem (append '((unread . unread)
5305                             (read . read)
5306                             (unseen . unseen))
5307                           gnus-article-mark-lists))
5308       (push (cons (cdr elem)
5309                   (gnus-byte-compile
5310                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5311             gnus-summary-display-cache)))
5312   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5313         (gnus-category-predicate-cache gnus-summary-display-cache))
5314     (gnus-get-predicate display)))
5315
5316 ;; Uses the dynamically bound `number' variable.
5317 (eval-when-compile
5318   (defvar number))
5319 (defun gnus-article-marked-p (type &optional article)
5320   (let ((article (or article number)))
5321     (cond
5322      ((eq type 'tick)
5323       (memq article gnus-newsgroup-marked))
5324      ((eq type 'spam)
5325       (memq article gnus-newsgroup-spam-marked))
5326      ((eq type 'unsend)
5327       (memq article gnus-newsgroup-unsendable))
5328      ((eq type 'undownload)
5329       (memq article gnus-newsgroup-undownloaded))
5330      ((eq type 'download)
5331       (memq article gnus-newsgroup-downloadable))
5332      ((eq type 'unread)
5333       (memq article gnus-newsgroup-unreads))
5334      ((eq type 'read)
5335       (memq article gnus-newsgroup-reads))
5336      ((eq type 'dormant)
5337       (memq article gnus-newsgroup-dormant) )
5338      ((eq type 'expire)
5339       (memq article gnus-newsgroup-expirable))
5340      ((eq type 'reply)
5341       (memq article gnus-newsgroup-replied))
5342      ((eq type 'killed)
5343       (memq article gnus-newsgroup-killed))
5344      ((eq type 'bookmark)
5345       (assq article gnus-newsgroup-bookmarks))
5346      ((eq type 'score)
5347       (assq article gnus-newsgroup-scored))
5348      ((eq type 'save)
5349       (memq article gnus-newsgroup-saved))
5350      ((eq type 'cache)
5351       (memq article gnus-newsgroup-cached))
5352      ((eq type 'forward)
5353       (memq article gnus-newsgroup-forwarded))
5354      ((eq type 'seen)
5355       (not (memq article gnus-newsgroup-unseen)))
5356      ((eq type 'recent)
5357       (memq article gnus-newsgroup-recent))
5358      (t t))))
5359
5360 (defun gnus-articles-to-read (group &optional read-all)
5361   "Find out what articles the user wants to read."
5362   (let* ((articles
5363           ;; Select all articles if `read-all' is non-nil, or if there
5364           ;; are no unread articles.
5365           (if (or read-all
5366                   (and (zerop (length gnus-newsgroup-marked))
5367                        (zerop (length gnus-newsgroup-unreads)))
5368                   ;; Fetch all if the predicate is non-nil.
5369                   gnus-newsgroup-display)
5370               ;; We want to select the headers for all the articles in
5371               ;; the group, so we select either all the active
5372               ;; articles in the group, or (if that's nil), the
5373               ;; articles in the cache.
5374               (or
5375                (gnus-uncompress-range (gnus-active group))
5376                (gnus-cache-articles-in-group group))
5377             ;; Select only the "normal" subset of articles.
5378             (gnus-sorted-nunion
5379              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5380              gnus-newsgroup-unreads)))
5381          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5382          (scored (length scored-list))
5383          (number (length articles))
5384          (marked (+ (length gnus-newsgroup-marked)
5385                     (length gnus-newsgroup-dormant)))
5386          (select
5387           (cond
5388            ((numberp read-all)
5389             read-all)
5390            ((numberp gnus-newsgroup-display)
5391             gnus-newsgroup-display)
5392            (t
5393             (condition-case ()
5394                 (cond
5395                  ((and (or (<= scored marked) (= scored number))
5396                        (numberp gnus-large-newsgroup)
5397                        (> number gnus-large-newsgroup))
5398                   (let* ((cursor-in-echo-area nil)
5399                          (initial (gnus-parameter-large-newsgroup-initial
5400                                    gnus-newsgroup-name))
5401                          (input
5402                           (read-string
5403                            (format
5404                             "How many articles from %s (%s %d): "
5405                             (gnus-limit-string
5406                              (gnus-group-decoded-name gnus-newsgroup-name)
5407                              35)
5408                             (if initial "max" "default")
5409                             number)
5410                            (if initial
5411                                (cons (number-to-string initial)
5412                                      0)))))
5413                     (if (string-match "^[ \t]*$" input) number input)))
5414                  ((and (> scored marked) (< scored number)
5415                        (> (- scored number) 20))
5416                   (let ((input
5417                          (read-string
5418                           (format "%s %s (%d scored, %d total): "
5419                                   "How many articles from"
5420                                   (gnus-group-decoded-name group)
5421                                   scored number))))
5422                     (if (string-match "^[ \t]*$" input)
5423                         number input)))
5424                  (t number))
5425               (quit
5426                (message "Quit getting the articles to read")
5427                nil))))))
5428     (setq select (if (stringp select) (string-to-number select) select))
5429     (if (or (null select) (zerop select))
5430         select
5431       (if (and (not (zerop scored)) (<= (abs select) scored))
5432           (progn
5433             (setq articles (sort scored-list '<))
5434             (setq number (length articles)))
5435         (setq articles (copy-sequence articles)))
5436
5437       (when (< (abs select) number)
5438         (if (< select 0)
5439             ;; Select the N oldest articles.
5440             (setcdr (nthcdr (1- (abs select)) articles) nil)
5441           ;; Select the N most recent articles.
5442           (setq articles (nthcdr (- number select) articles))))
5443       (setq gnus-newsgroup-unselected
5444             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5445       (when gnus-alter-articles-to-read-function
5446         (setq articles
5447               (sort
5448                (funcall gnus-alter-articles-to-read-function
5449                         gnus-newsgroup-name articles)
5450                '<)))
5451       articles)))
5452
5453 (defun gnus-killed-articles (killed articles)
5454   (let (out)
5455     (while articles
5456       (when (inline (gnus-member-of-range (car articles) killed))
5457         (push (car articles) out))
5458       (setq articles (cdr articles)))
5459     out))
5460
5461 (defun gnus-uncompress-marks (marks)
5462   "Uncompress the mark ranges in MARKS."
5463   (let ((uncompressed '(score bookmark))
5464         out)
5465     (while marks
5466       (if (memq (caar marks) uncompressed)
5467           (push (car marks) out)
5468         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5469       (setq marks (cdr marks)))
5470     out))
5471
5472 (defun gnus-article-mark-to-type (mark)
5473   "Return the type of MARK."
5474   (or (cadr (assq mark gnus-article-special-mark-lists))
5475       'list))
5476
5477 (defun gnus-article-unpropagatable-p (mark)
5478   "Return whether MARK should be propagated to back end."
5479   (memq mark gnus-article-unpropagated-mark-lists))
5480
5481 (defun gnus-adjust-marked-articles (info)
5482   "Set all article lists and remove all marks that are no longer valid."
5483   (let* ((marked-lists (gnus-info-marks info))
5484          (active (gnus-active (gnus-info-group info)))
5485          (min (car active))
5486          (max (cdr active))
5487          (types gnus-article-mark-lists)
5488          marks var articles article mark mark-type
5489          bgn end)
5490
5491     (dolist (marks marked-lists)
5492       (setq mark (car marks)
5493             mark-type (gnus-article-mark-to-type mark)
5494             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5495
5496       ;; We set the variable according to the type of the marks list,
5497       ;; and then adjust the marks to a subset of the active articles.
5498       (cond
5499        ;; Adjust "simple" lists - compressed yet unsorted
5500        ((eq mark-type 'list)
5501         ;; Simultaneously uncompress and clip to active range
5502         ;; See gnus-uncompress-range for a description of possible marks
5503         (let (l lh)
5504           (if (not (cadr marks))
5505               (set var nil)
5506             (setq articles (if (numberp (cddr marks))
5507                                (list (cdr marks))
5508                              (cdr marks))
5509                   lh (cons nil nil)
5510                   l lh)
5511
5512             (while (setq article (pop articles))
5513               (cond ((consp article)
5514                      (setq bgn (max (car article) min)
5515                            end (min (cdr article) max))
5516                      (while (<= bgn end)
5517                        (setq l (setcdr l (cons bgn nil))
5518                              bgn (1+ bgn))))
5519                     ((and (<= min article)
5520                           (>= max article))
5521                      (setq l (setcdr l (cons article nil))))))
5522             (set var (cdr lh)))))
5523        ;; Adjust assocs.
5524        ((eq mark-type 'tuple)
5525         (set var (setq articles (cdr marks)))
5526         (when (not (listp (cdr (symbol-value var))))
5527           (set var (list (symbol-value var))))
5528         (when (not (listp (cdr articles)))
5529           (setq articles (list articles)))
5530         (while articles
5531           (when (or (not (consp (setq article (pop articles))))
5532                     (< (car article) min)
5533                     (> (car article) max))
5534             (set var (delq article (symbol-value var))))))
5535        ;; Adjust ranges (sloppily).
5536        ((eq mark-type 'range)
5537         (cond
5538          ((eq mark 'seen)
5539           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5540           ;; It should be (seen (NUM1 . NUM2)).
5541           (when (numberp (cddr marks))
5542             (setcdr marks (list (cdr marks))))
5543           (setq articles (cdr marks))
5544           (while (and articles
5545                       (or (and (consp (car articles))
5546                                (> min (cdar articles)))
5547                           (and (numberp (car articles))
5548                                (> min (car articles)))))
5549             (pop articles))
5550           (set var articles))))))))
5551
5552 (defun gnus-update-missing-marks (missing)
5553   "Go through the list of MISSING articles and remove them from the mark lists."
5554   (when missing
5555     (let (var m)
5556       ;; Go through all types.
5557       (dolist (elem gnus-article-mark-lists)
5558         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5559           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5560           (when (symbol-value var)
5561             ;; This list has articles.  So we delete all missing
5562             ;; articles from it.
5563             (setq m missing)
5564             (while m
5565               (set var (delq (pop m) (symbol-value var))))))))))
5566
5567 (defun gnus-update-marks ()
5568   "Enter the various lists of marked articles into the newsgroup info list."
5569   (let ((types gnus-article-mark-lists)
5570         (info (gnus-get-info gnus-newsgroup-name))
5571         type list newmarked symbol delta-marks)
5572     (when info
5573       ;; Add all marks lists to the list of marks lists.
5574       (while (setq type (pop types))
5575         (setq list (symbol-value
5576                     (setq symbol
5577                           (intern (format "gnus-newsgroup-%s" (car type))))))
5578
5579         (when list
5580           ;; Get rid of the entries of the articles that have the
5581           ;; default score.
5582           (when (and (eq (cdr type) 'score)
5583                      gnus-save-score
5584                      list)
5585             (let* ((arts list)
5586                    (prev (cons nil list))
5587                    (all prev))
5588               (while arts
5589                 (if (or (not (consp (car arts)))
5590                         (= (cdar arts) gnus-summary-default-score))
5591                     (setcdr prev (cdr arts))
5592                   (setq prev arts))
5593                 (setq arts (cdr arts)))
5594               (setq list (cdr all)))))
5595
5596         (when (eq (cdr type) 'seen)
5597           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5598
5599         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5600           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5601
5602         (when (and (gnus-check-backend-function
5603                     'request-set-mark gnus-newsgroup-name)
5604                    (not (gnus-article-unpropagatable-p (cdr type))))
5605           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5606                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5607                  (add (gnus-remove-from-range
5608                        (gnus-copy-sequence list) old)))
5609             (when add
5610               (push (list add 'add (list (cdr type))) delta-marks))
5611             (when del
5612               (push (list del 'del (list (cdr type))) delta-marks))))
5613
5614         (when list
5615           (push (cons (cdr type) list) newmarked)))
5616
5617       (when delta-marks
5618         (unless (gnus-check-group gnus-newsgroup-name)
5619           (error "Can't open server for %s" gnus-newsgroup-name))
5620         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5621
5622       ;; Enter these new marks into the info of the group.
5623       (if (nthcdr 3 info)
5624           (setcar (nthcdr 3 info) newmarked)
5625         ;; Add the marks lists to the end of the info.
5626         (when newmarked
5627           (setcdr (nthcdr 2 info) (list newmarked))))
5628
5629       ;; Cut off the end of the info if there's nothing else there.
5630       (let ((i 5))
5631         (while (and (> i 2)
5632                     (not (nth i info)))
5633           (when (nthcdr (decf i) info)
5634             (setcdr (nthcdr i info) nil)))))))
5635
5636 (defun gnus-set-mode-line (where)
5637   "Set the mode line of the article or summary buffers.
5638 If WHERE is `summary', the summary mode line format will be used."
5639   ;; Is this mode line one we keep updated?
5640   (when (and (memq where gnus-updated-mode-lines)
5641              (symbol-value
5642               (intern (format "gnus-%s-mode-line-format-spec" where))))
5643     (let (mode-string)
5644       (save-excursion
5645         ;; We evaluate this in the summary buffer since these
5646         ;; variables are buffer-local to that buffer.
5647         (set-buffer gnus-summary-buffer)
5648        ;; We bind all these variables that are used in the `eval' form
5649         ;; below.
5650         (let* ((mformat (symbol-value
5651                          (intern
5652                           (format "gnus-%s-mode-line-format-spec" where))))
5653                (gnus-tmp-group-name (gnus-group-decoded-name
5654                                      gnus-newsgroup-name))
5655                (gnus-tmp-article-number (or gnus-current-article 0))
5656                (gnus-tmp-unread gnus-newsgroup-unreads)
5657                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5658                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5659                (gnus-tmp-unread-and-unselected
5660                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5661                             (zerop gnus-tmp-unselected))
5662                        "")
5663                       ((zerop gnus-tmp-unselected)
5664                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5665                       (t (format "{%d(+%d) more}"
5666                                  gnus-tmp-unread-and-unticked
5667                                  gnus-tmp-unselected))))
5668                (gnus-tmp-subject
5669                 (if (and gnus-current-headers
5670                          (vectorp gnus-current-headers))
5671                     (gnus-mode-string-quote
5672                      (mail-header-subject gnus-current-headers))
5673                   ""))
5674                bufname-length max-len
5675                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5676           (setq mode-string (eval mformat))
5677           (setq bufname-length (if (string-match "%b" mode-string)
5678                                    (- (length
5679                                        (buffer-name
5680                                         (if (eq where 'summary)
5681                                             nil
5682                                           (get-buffer gnus-article-buffer))))
5683                                       2)
5684                                  0))
5685           (setq max-len (max 4 (if gnus-mode-non-string-length
5686                                    (- (window-width)
5687                                       gnus-mode-non-string-length
5688                                       bufname-length)
5689                                  (length mode-string))))
5690           ;; We might have to chop a bit of the string off...
5691           (when (> (length mode-string) max-len)
5692             (setq mode-string
5693                   (concat (truncate-string-to-width mode-string (- max-len 3))
5694                           "...")))
5695           ;; Pad the mode string a bit.
5696           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5697       ;; Update the mode line.
5698       (setq mode-line-buffer-identification
5699             (gnus-mode-line-buffer-identification (list mode-string)))
5700       (set-buffer-modified-p t))))
5701
5702 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5703   "Go through the HEADERS list and add all Xrefs to a hash table.
5704 The resulting hash table is returned, or nil if no Xrefs were found."
5705   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5706          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5707          (xref-hashtb (gnus-make-hashtable))
5708          start group entry number xrefs header)
5709     (while headers
5710       (setq header (pop headers))
5711       (when (and (setq xrefs (mail-header-xref header))
5712                  (not (memq (setq number (mail-header-number header))
5713                             unreads)))
5714         (setq start 0)
5715         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5716           (setq start (match-end 0))
5717           (setq group (if prefix
5718                           (concat prefix (substring xrefs (match-beginning 1)
5719                                                     (match-end 1)))
5720                         (substring xrefs (match-beginning 1) (match-end 1))))
5721           (setq number
5722                 (string-to-int (substring xrefs (match-beginning 2)
5723                                           (match-end 2))))
5724           (if (setq entry (gnus-gethash group xref-hashtb))
5725               (setcdr entry (cons number (cdr entry)))
5726             (gnus-sethash group (cons number nil) xref-hashtb)))))
5727     (and start xref-hashtb)))
5728
5729 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5730   "Look through all the headers and mark the Xrefs as read."
5731   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5732         name info xref-hashtb idlist method nth4)
5733     (save-excursion
5734       (set-buffer gnus-group-buffer)
5735       (when (setq xref-hashtb
5736                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5737         (mapatoms
5738          (lambda (group)
5739            (unless (string= from-newsgroup (setq name (symbol-name group)))
5740              (setq idlist (symbol-value group))
5741              ;; Dead groups are not updated.
5742              (and (prog1
5743                       (setq info (gnus-get-info name))
5744                     (when (stringp (setq nth4 (gnus-info-method info)))
5745                       (setq nth4 (gnus-server-to-method nth4))))
5746                   ;; Only do the xrefs if the group has the same
5747                   ;; select method as the group we have just read.
5748                   (or (gnus-methods-equal-p
5749                        nth4 (gnus-find-method-for-group from-newsgroup))
5750                       virtual
5751                       (equal nth4 (setq method (gnus-find-method-for-group
5752                                                 from-newsgroup)))
5753                       (and (equal (car nth4) (car method))
5754                            (equal (nth 1 nth4) (nth 1 method))))
5755                   gnus-use-cross-reference
5756                   (or (not (eq gnus-use-cross-reference t))
5757                       virtual
5758                       ;; Only do cross-references on subscribed
5759                       ;; groups, if that is what is wanted.
5760                       (<= (gnus-info-level info) gnus-level-subscribed))
5761                   (gnus-group-make-articles-read name idlist))))
5762          xref-hashtb)))))
5763
5764 (defun gnus-compute-read-articles (group articles)
5765   (let* ((entry (gnus-group-entry group))
5766          (info (nth 2 entry))
5767          (active (gnus-active group))
5768          ninfo)
5769     (when entry
5770       ;; First peel off all invalid article numbers.
5771       (when active
5772         (let ((ids articles)
5773               id first)
5774           (while (setq id (pop ids))
5775             (when (and first (> id (cdr active)))
5776               ;; We'll end up in this situation in one particular
5777               ;; obscure situation.  If you re-scan a group and get
5778               ;; a new article that is cross-posted to a different
5779               ;; group that has not been re-scanned, you might get
5780               ;; crossposted article that has a higher number than
5781               ;; Gnus believes possible.  So we re-activate this
5782               ;; group as well.  This might mean doing the
5783               ;; crossposting thingy will *increase* the number
5784               ;; of articles in some groups.  Tsk, tsk.
5785               (setq active (or (gnus-activate-group group) active)))
5786             (when (or (> id (cdr active))
5787                       (< id (car active)))
5788               (setq articles (delq id articles))))))
5789       ;; If the read list is nil, we init it.
5790       (if (and active
5791                (null (gnus-info-read info))
5792                (> (car active) 1))
5793           (setq ninfo (cons 1 (1- (car active))))
5794         (setq ninfo (gnus-info-read info)))
5795       ;; Then we add the read articles to the range.
5796       (gnus-add-to-range
5797        ninfo (setq articles (sort articles '<))))))
5798
5799 (defun gnus-group-make-articles-read (group articles)
5800   "Update the info of GROUP to say that ARTICLES are read."
5801   (let* ((num 0)
5802          (entry (gnus-group-entry group))
5803          (info (nth 2 entry))
5804          (active (gnus-active group))
5805          range)
5806     (when entry
5807       (setq range (gnus-compute-read-articles group articles))
5808       (with-current-buffer gnus-group-buffer
5809         (gnus-undo-register
5810           `(progn
5811              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5812              (gnus-info-set-read ',info ',(gnus-info-read info))
5813              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5814              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5815              (gnus-group-update-group ,group t))))
5816       ;; Add the read articles to the range.
5817       (gnus-info-set-read info range)
5818       (gnus-request-set-mark group (list (list range 'add '(read))))
5819       ;; Then we have to re-compute how many unread
5820       ;; articles there are in this group.
5821       (when active
5822         (cond
5823          ((not range)
5824           (setq num (- (1+ (cdr active)) (car active))))
5825          ((not (listp (cdr range)))
5826           (setq num (- (cdr active) (- (1+ (cdr range))
5827                                        (car range)))))
5828          (t
5829           (while range
5830             (if (numberp (car range))
5831                 (setq num (1+ num))
5832               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5833             (setq range (cdr range)))
5834           (setq num (- (cdr active) num))))
5835         ;; Update the number of unread articles.
5836         (setcar entry num)
5837         ;; Update the group buffer.
5838         (unless (gnus-ephemeral-group-p group)
5839           (gnus-group-update-group group t))))))
5840
5841 (defvar gnus-newsgroup-none-id 0)
5842
5843 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5844   (let ((cur nntp-server-buffer)
5845         (dependencies
5846          (or dependencies
5847              (with-current-buffer gnus-summary-buffer
5848                gnus-newsgroup-dependencies)))
5849         headers id end ref number
5850         (mail-parse-charset gnus-newsgroup-charset)
5851         (mail-parse-ignored-charsets
5852          (save-excursion (condition-case nil
5853                              (set-buffer gnus-summary-buffer)
5854                            (error))
5855                          gnus-newsgroup-ignored-charsets)))
5856     (save-excursion
5857       (set-buffer nntp-server-buffer)
5858       ;; Translate all TAB characters into SPACE characters.
5859       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5860       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5861       (ietf-drums-unfold-fws)
5862       (gnus-run-hooks 'gnus-parse-headers-hook)
5863       (let ((case-fold-search t)
5864             in-reply-to header p lines chars)
5865         (goto-char (point-min))
5866         ;; Search to the beginning of the next header.  Error messages
5867         ;; do not begin with 2 or 3.
5868         (while (re-search-forward "^[23][0-9]+ " nil t)
5869           (setq id nil
5870                 ref nil)
5871           ;; This implementation of this function, with nine
5872           ;; search-forwards instead of the one re-search-forward and
5873           ;; a case (which basically was the old function) is actually
5874           ;; about twice as fast, even though it looks messier.  You
5875           ;; can't have everything, I guess.  Speed and elegance
5876           ;; doesn't always go hand in hand.
5877           (setq
5878            header
5879            (vector
5880             ;; Number.
5881             (prog1
5882                 (setq number (read cur))
5883               (end-of-line)
5884               (setq p (point))
5885               (narrow-to-region (point)
5886                                 (or (and (search-forward "\n.\n" nil t)
5887                                          (- (point) 2))
5888                                     (point))))
5889             ;; Subject.
5890             (progn
5891               (goto-char p)
5892               (if (search-forward "\nsubject:" nil t)
5893                   (funcall gnus-decode-encoded-word-function
5894                            (nnheader-header-value))
5895                 "(none)"))
5896             ;; From.
5897             (progn
5898               (goto-char p)
5899               (if (search-forward "\nfrom:" nil t)
5900                   (funcall gnus-decode-encoded-word-function
5901                            (nnheader-header-value))
5902                 "(nobody)"))
5903             ;; Date.
5904             (progn
5905               (goto-char p)
5906               (if (search-forward "\ndate:" nil t)
5907                   (nnheader-header-value) ""))
5908             ;; Message-ID.
5909             (progn
5910               (goto-char p)
5911               (setq id (if (re-search-forward
5912                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5913                            ;; We do it this way to make sure the Message-ID
5914                            ;; is (somewhat) syntactically valid.
5915                            (buffer-substring (match-beginning 1)
5916                                              (match-end 1))
5917                          ;; If there was no message-id, we just fake one
5918                          ;; to make subsequent routines simpler.
5919                          (nnheader-generate-fake-message-id number))))
5920             ;; References.
5921             (progn
5922               (goto-char p)
5923               (if (search-forward "\nreferences:" nil t)
5924                   (progn
5925                     (setq end (point))
5926                     (prog1
5927                         (nnheader-header-value)
5928                       (setq ref
5929                             (buffer-substring
5930                              (progn
5931                                (end-of-line)
5932                                (search-backward ">" end t)
5933                                (1+ (point)))
5934                              (progn
5935                                (search-backward "<" end t)
5936                                (point))))))
5937                 ;; Get the references from the in-reply-to header if there
5938                 ;; were no references and the in-reply-to header looks
5939                 ;; promising.
5940                 (if (and (search-forward "\nin-reply-to:" nil t)
5941                          (setq in-reply-to (nnheader-header-value))
5942                          (string-match "<[^>]+>" in-reply-to))
5943                     (let (ref2)
5944                       (setq ref (substring in-reply-to (match-beginning 0)
5945                                            (match-end 0)))
5946                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5947                         (setq ref2 (substring in-reply-to (match-beginning 0)
5948                                               (match-end 0)))
5949                         (when (> (length ref2) (length ref))
5950                           (setq ref ref2)))
5951                       ref)
5952                   (setq ref nil))))
5953             ;; Chars.
5954             (progn
5955               (goto-char p)
5956               (if (search-forward "\nchars: " nil t)
5957                   (if (numberp (setq chars (ignore-errors (read cur))))
5958                       chars -1)
5959                 -1))
5960             ;; Lines.
5961             (progn
5962               (goto-char p)
5963               (if (search-forward "\nlines: " nil t)
5964                   (if (numberp (setq lines (ignore-errors (read cur))))
5965                       lines -1)
5966                 -1))
5967             ;; Xref.
5968             (progn
5969               (goto-char p)
5970               (and (search-forward "\nxref:" nil t)
5971                    (nnheader-header-value)))
5972             ;; Extra.
5973             (when gnus-extra-headers
5974               (let ((extra gnus-extra-headers)
5975                     out)
5976                 (while extra
5977                   (goto-char p)
5978                   (when (search-forward
5979                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5980                     (push (cons (car extra) (nnheader-header-value))
5981                           out))
5982                   (pop extra))
5983                 out))))
5984           (when (equal id ref)
5985             (setq ref nil))
5986
5987           (when gnus-alter-header-function
5988             (funcall gnus-alter-header-function header)
5989             (setq id (mail-header-id header)
5990                   ref (gnus-parent-id (mail-header-references header))))
5991
5992           (when (setq header
5993                       (gnus-dependencies-add-header
5994                        header dependencies force-new))
5995             (push header headers))
5996           (goto-char (point-max))
5997           (widen))
5998         (nreverse headers)))))
5999
6000 ;; Goes through the xover lines and returns a list of vectors
6001 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6002                                                   force-new dependencies
6003                                                   group also-fetch-heads)
6004   "Parse the news overview data in the server buffer.
6005 Return a list of headers that match SEQUENCE (see
6006 `nntp-retrieve-headers')."
6007   ;; Get the Xref when the users reads the articles since most/some
6008   ;; NNTP servers do not include Xrefs when using XOVER.
6009   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6010   (let ((mail-parse-charset gnus-newsgroup-charset)
6011         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6012         (cur nntp-server-buffer)
6013         (dependencies (or dependencies gnus-newsgroup-dependencies))
6014         (allp (cond
6015                ((eq gnus-read-all-available-headers t)
6016                 t)
6017                ((stringp gnus-read-all-available-headers)
6018                 (string-match gnus-read-all-available-headers group))
6019                (t
6020                 nil)))
6021         number headers header)
6022     (save-excursion
6023       (set-buffer nntp-server-buffer)
6024       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6025       ;; Allow the user to mangle the headers before parsing them.
6026       (gnus-run-hooks 'gnus-parse-headers-hook)
6027       (goto-char (point-min))
6028       (gnus-parse-without-error
6029         (while (and (or sequence allp)
6030                     (not (eobp)))
6031           (setq number (read cur))
6032           (when (not allp)
6033             (while (and sequence
6034                         (< (car sequence) number))
6035               (setq sequence (cdr sequence))))
6036           (when (and (or allp
6037                          (and sequence
6038                               (eq number (car sequence))))
6039                      (progn
6040                        (setq sequence (cdr sequence))
6041                        (setq header (inline
6042                                       (gnus-nov-parse-line
6043                                        number dependencies force-new)))))
6044             (push header headers))
6045           (forward-line 1)))
6046       ;; A common bug in inn is that if you have posted an article and
6047       ;; then retrieves the active file, it will answer correctly --
6048       ;; the new article is included.  However, a NOV entry for the
6049       ;; article may not have been generated yet, so this may fail.
6050       ;; We work around this problem by retrieving the last few
6051       ;; headers using HEAD.
6052       (if (or (not also-fetch-heads)
6053               (not sequence))
6054           ;; We (probably) got all the headers.
6055           (nreverse headers)
6056         (let ((gnus-nov-is-evil t))
6057           (nconc
6058            (nreverse headers)
6059            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6060              (gnus-get-newsgroup-headers))))))))
6061
6062 (defun gnus-article-get-xrefs ()
6063   "Fill in the Xref value in `gnus-current-headers', if necessary.
6064 This is meant to be called in `gnus-article-internal-prepare-hook'."
6065   (let ((headers (with-current-buffer gnus-summary-buffer
6066                    gnus-current-headers)))
6067     (or (not gnus-use-cross-reference)
6068         (not headers)
6069         (and (mail-header-xref headers)
6070              (not (string= (mail-header-xref headers) "")))
6071         (let ((case-fold-search t)
6072               xref)
6073           (save-restriction
6074             (nnheader-narrow-to-headers)
6075             (goto-char (point-min))
6076             (when (or (and (not (eobp))
6077                            (eq (downcase (char-after)) ?x)
6078                            (looking-at "Xref:"))
6079                       (search-forward "\nXref:" nil t))
6080               (goto-char (1+ (match-end 0)))
6081               (setq xref (buffer-substring (point) (point-at-eol)))
6082               (mail-header-set-xref headers xref)))))))
6083
6084 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6085   "Find article ID and insert the summary line for that article.
6086 OLD-HEADER can either be a header or a line number to insert
6087 the subject line on."
6088   (let* ((line (and (numberp old-header) old-header))
6089          (old-header (and (vectorp old-header) old-header))
6090          (header (cond ((and old-header use-old-header)
6091                         old-header)
6092                        ((and (numberp id)
6093                              (gnus-number-to-header id))
6094                         (gnus-number-to-header id))
6095                        (t
6096                         (gnus-read-header id))))
6097          (number (and (numberp id) id))
6098          d)
6099     (when header
6100       ;; Rebuild the thread that this article is part of and go to the
6101       ;; article we have fetched.
6102       (when (and (not gnus-show-threads)
6103                  old-header)
6104         (when (and number
6105                    (setq d (gnus-data-find (mail-header-number old-header))))
6106           (goto-char (gnus-data-pos d))
6107           (gnus-data-remove
6108            number
6109            (- (point-at-bol)
6110               (prog1
6111                   (1+ (point-at-eol))
6112                 (gnus-delete-line))))))
6113       ;; Remove list identifiers from subject.
6114       (when gnus-list-identifiers
6115         (let ((gnus-newsgroup-headers (list header)))
6116           (gnus-summary-remove-list-identifiers)))
6117       (when old-header
6118         (mail-header-set-number header (mail-header-number old-header)))
6119       (setq gnus-newsgroup-sparse
6120             (delq (setq number (mail-header-number header))
6121                   gnus-newsgroup-sparse))
6122       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6123       (push number gnus-newsgroup-limit)
6124       (gnus-rebuild-thread (mail-header-id header) line)
6125       (gnus-summary-goto-subject number nil t))
6126     (when (and (numberp number)
6127                (> number 0))
6128       ;; We have to update the boundaries even if we can't fetch the
6129       ;; article if ID is a number -- so that the next `P' or `N'
6130       ;; command will fetch the previous (or next) article even
6131       ;; if the one we tried to fetch this time has been canceled.
6132       (when (> number gnus-newsgroup-end)
6133         (setq gnus-newsgroup-end number))
6134       (when (< number gnus-newsgroup-begin)
6135         (setq gnus-newsgroup-begin number))
6136       (setq gnus-newsgroup-unselected
6137             (delq number gnus-newsgroup-unselected)))
6138     ;; Report back a success?
6139     (and header (mail-header-number header))))
6140
6141 ;;; Process/prefix in the summary buffer
6142
6143 (defun gnus-summary-work-articles (n)
6144   "Return a list of articles to be worked upon.
6145 The prefix argument, the list of process marked articles, and the
6146 current article will be taken into consideration."
6147   (save-excursion
6148     (set-buffer gnus-summary-buffer)
6149     (cond
6150      (n
6151       ;; A numerical prefix has been given.
6152       (setq n (prefix-numeric-value n))
6153       (let ((backward (< n 0))
6154             (n (abs (prefix-numeric-value n)))
6155             articles article)
6156         (save-excursion
6157           (while
6158               (and (> n 0)
6159                    (push (setq article (gnus-summary-article-number))
6160                          articles)
6161                    (if backward
6162                        (gnus-summary-find-prev nil article)
6163                      (gnus-summary-find-next nil article)))
6164             (decf n)))
6165         (nreverse articles)))
6166      ((and (gnus-region-active-p) (mark))
6167       (message "region active")
6168       ;; Work on the region between point and mark.
6169       (let ((max (max (point) (mark)))
6170             articles article)
6171         (save-excursion
6172           (goto-char (min (min (point) (mark))))
6173           (while
6174               (and
6175                (push (setq article (gnus-summary-article-number)) articles)
6176                (gnus-summary-find-next nil article)
6177                (< (point) max)))
6178           (nreverse articles))))
6179      (gnus-newsgroup-processable
6180       ;; There are process-marked articles present.
6181       ;; Save current state.
6182       (gnus-summary-save-process-mark)
6183       ;; Return the list.
6184       (reverse gnus-newsgroup-processable))
6185      (t
6186       ;; Just return the current article.
6187       (list (gnus-summary-article-number))))))
6188
6189 (defmacro gnus-summary-iterate (arg &rest forms)
6190   "Iterate over the process/prefixed articles and do FORMS.
6191 ARG is the interactive prefix given to the command.  FORMS will be
6192 executed with point over the summary line of the articles."
6193   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6194     `(let ((,articles (gnus-summary-work-articles ,arg)))
6195        (while ,articles
6196          (gnus-summary-goto-subject (car ,articles))
6197          ,@forms
6198          (pop ,articles)))))
6199
6200 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6201 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6202
6203 (defun gnus-summary-save-process-mark ()
6204   "Push the current set of process marked articles on the stack."
6205   (interactive)
6206   (push (copy-sequence gnus-newsgroup-processable)
6207         gnus-newsgroup-process-stack))
6208
6209 (defun gnus-summary-kill-process-mark ()
6210   "Push the current set of process marked articles on the stack and unmark."
6211   (interactive)
6212   (gnus-summary-save-process-mark)
6213   (gnus-summary-unmark-all-processable))
6214
6215 (defun gnus-summary-yank-process-mark ()
6216   "Pop the last process mark state off the stack and restore it."
6217   (interactive)
6218   (unless gnus-newsgroup-process-stack
6219     (error "Empty mark stack"))
6220   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6221
6222 (defun gnus-summary-process-mark-set (set)
6223   "Make SET into the current process marked articles."
6224   (gnus-summary-unmark-all-processable)
6225   (mapc 'gnus-summary-set-process-mark set))
6226
6227 ;;; Searching and stuff
6228
6229 (defun gnus-summary-search-group (&optional backward use-level)
6230   "Search for next unread newsgroup.
6231 If optional argument BACKWARD is non-nil, search backward instead."
6232   (save-excursion
6233     (set-buffer gnus-group-buffer)
6234     (when (gnus-group-search-forward
6235            backward nil (if use-level (gnus-group-group-level) nil))
6236       (gnus-group-group-name))))
6237
6238 (defun gnus-summary-best-group (&optional exclude-group)
6239   "Find the name of the best unread group.
6240 If EXCLUDE-GROUP, do not go to this group."
6241   (with-current-buffer gnus-group-buffer
6242     (save-excursion
6243       (gnus-group-best-unread-group exclude-group))))
6244
6245 (defun gnus-summary-find-next (&optional unread article backward)
6246   (if backward
6247       (gnus-summary-find-prev unread article)
6248     (let* ((dummy (gnus-summary-article-intangible-p))
6249            (article (or article (gnus-summary-article-number)))
6250            (data (gnus-data-find-list article))
6251            result)
6252       (when (and (not dummy)
6253                  (or (not gnus-summary-check-current)
6254                      (not unread)
6255                      (not (gnus-data-unread-p (car data)))))
6256         (setq data (cdr data)))
6257       (when (setq result
6258                   (if unread
6259                       (progn
6260                         (while data
6261                           (unless (memq (gnus-data-number (car data))
6262                                         (cond
6263                                          ((eq gnus-auto-goto-ignores
6264                                               'always-undownloaded)
6265                                           gnus-newsgroup-undownloaded)
6266                                          (gnus-plugged
6267                                           nil)
6268                                          ((eq gnus-auto-goto-ignores
6269                                               'unfetched)
6270                                           gnus-newsgroup-unfetched)
6271                                          ((eq gnus-auto-goto-ignores
6272                                               'undownloaded)
6273                                           gnus-newsgroup-undownloaded)))
6274                             (when (gnus-data-unread-p (car data))
6275                               (setq result (car data)
6276                                     data nil)))
6277                           (setq data (cdr data)))
6278                         result)
6279                     (car data)))
6280         (goto-char (gnus-data-pos result))
6281         (gnus-data-number result)))))
6282
6283 (defun gnus-summary-find-prev (&optional unread article)
6284   (let* ((eobp (eobp))
6285          (article (or article (gnus-summary-article-number)))
6286          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6287          result)
6288     (when (and (not eobp)
6289                (or (not gnus-summary-check-current)
6290                    (not unread)
6291                    (not (gnus-data-unread-p (car data)))))
6292       (setq data (cdr data)))
6293     (when (setq result
6294                 (if unread
6295                     (progn
6296                       (while data
6297                         (unless (memq (gnus-data-number (car data))
6298                                       (cond
6299                                        ((eq gnus-auto-goto-ignores
6300                                             'always-undownloaded)
6301                                         gnus-newsgroup-undownloaded)
6302                                        (gnus-plugged
6303                                         nil)
6304                                        ((eq gnus-auto-goto-ignores
6305                                             'unfetched)
6306                                         gnus-newsgroup-unfetched)
6307                                        ((eq gnus-auto-goto-ignores
6308                                             'undownloaded)
6309                                         gnus-newsgroup-undownloaded)))
6310                           (when (gnus-data-unread-p (car data))
6311                             (setq result (car data)
6312                                   data nil)))
6313                         (setq data (cdr data)))
6314                       result)
6315                   (car data)))
6316       (goto-char (gnus-data-pos result))
6317       (gnus-data-number result))))
6318
6319 (defun gnus-summary-find-subject (subject &optional unread backward article)
6320   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6321          (article (or article (gnus-summary-article-number)))
6322          (articles (gnus-data-list backward))
6323          (arts (gnus-data-find-list article articles))
6324          result)
6325     (when (or (not gnus-summary-check-current)
6326               (not unread)
6327               (not (gnus-data-unread-p (car arts))))
6328       (setq arts (cdr arts)))
6329     (while arts
6330       (and (or (not unread)
6331                (gnus-data-unread-p (car arts)))
6332            (vectorp (gnus-data-header (car arts)))
6333            (gnus-subject-equal
6334             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6335            (setq result (car arts)
6336                  arts nil))
6337       (setq arts (cdr arts)))
6338     (and result
6339          (goto-char (gnus-data-pos result))
6340          (gnus-data-number result))))
6341
6342 (defun gnus-summary-search-forward (&optional unread subject backward)
6343   "Search forward for an article.
6344 If UNREAD, look for unread articles.  If SUBJECT, look for
6345 articles with that subject.  If BACKWARD, search backward instead."
6346   (cond (subject (gnus-summary-find-subject subject unread backward))
6347         (backward (gnus-summary-find-prev unread))
6348         (t (gnus-summary-find-next unread))))
6349
6350 (defun gnus-recenter (&optional n)
6351   "Center point in window and redisplay frame.
6352 Also do horizontal recentering."
6353   (interactive "P")
6354   (when (and gnus-auto-center-summary
6355              (not (eq gnus-auto-center-summary 'vertical)))
6356     (gnus-horizontal-recenter))
6357   (recenter n))
6358
6359 (defun gnus-summary-recenter ()
6360   "Center point in the summary window.
6361 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6362 displayed, no centering will be performed."
6363   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6364   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6365   (interactive)
6366   ;; The user has to want it.
6367   (when gnus-auto-center-summary
6368     (let* ((top (cond ((< (window-height) 4) 0)
6369                       ((< (window-height) 7) 1)
6370                       (t (if (numberp gnus-auto-center-summary)
6371                              gnus-auto-center-summary
6372                            (/ (1- (window-height)) 2)))))
6373            (height (1- (window-height)))
6374            (bottom (save-excursion (goto-char (point-max))
6375                                    (forward-line (- height))
6376                                    (point)))
6377            (window (get-buffer-window (current-buffer))))
6378       (when (get-buffer-window gnus-article-buffer)
6379         ;; Only do recentering when the article buffer is displayed,
6380         ;; Set the window start to either `bottom', which is the biggest
6381         ;; possible valid number, or the second line from the top,
6382         ;; whichever is the least.
6383         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6384           (if (> bottom top-pos)
6385               ;; Keep the second line from the top visible
6386               (set-window-start window top-pos t)
6387             ;; Try to keep the bottom line visible; if it's partially
6388             ;; obscured, either scroll one more line to make it fully
6389             ;; visible, or revert to using TOP-POS.
6390             (save-excursion
6391               (goto-char (point-max))
6392               (forward-line -1)
6393               (let ((last-line-start (point)))
6394                 (goto-char bottom)
6395                 (set-window-start window (point) t)
6396                 (when (not (pos-visible-in-window-p last-line-start window))
6397                   (forward-line 1)
6398                   (set-window-start window (min (point) top-pos) t)))))))
6399       ;; Do horizontal recentering while we're at it.
6400       (when (and (get-buffer-window (current-buffer) t)
6401                  (not (eq gnus-auto-center-summary 'vertical)))
6402         (let ((selected (selected-window)))
6403           (select-window (get-buffer-window (current-buffer) t))
6404           (gnus-summary-position-point)
6405           (gnus-horizontal-recenter)
6406           (select-window selected))))))
6407
6408 (defun gnus-summary-jump-to-group (newsgroup)
6409   "Move point to NEWSGROUP in group mode buffer."
6410   ;; Keep update point of group mode buffer if visible.
6411   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6412       (save-window-excursion
6413         ;; Take care of tree window mode.
6414         (when (get-buffer-window gnus-group-buffer)
6415           (pop-to-buffer gnus-group-buffer))
6416         (gnus-group-jump-to-group newsgroup))
6417     (save-excursion
6418       ;; Take care of tree window mode.
6419       (if (get-buffer-window gnus-group-buffer)
6420           (pop-to-buffer gnus-group-buffer)
6421         (set-buffer gnus-group-buffer))
6422       (gnus-group-jump-to-group newsgroup))))
6423
6424 ;; This function returns a list of article numbers based on the
6425 ;; difference between the ranges of read articles in this group and
6426 ;; the range of active articles.
6427 (defun gnus-list-of-unread-articles (group)
6428   (let* ((read (gnus-info-read (gnus-get-info group)))
6429          (active (or (gnus-active group) (gnus-activate-group group)))
6430          (last (cdr active))
6431          first nlast unread)
6432     ;; If none are read, then all are unread.
6433     (if (not read)
6434         (setq first (car active))
6435       ;; If the range of read articles is a single range, then the
6436       ;; first unread article is the article after the last read
6437       ;; article.  Sounds logical, doesn't it?
6438       (if (and (not (listp (cdr read)))
6439                (or (< (car read) (car active))
6440                    (progn (setq read (list read))
6441                           nil)))
6442           (setq first (max (car active) (1+ (cdr read))))
6443         ;; `read' is a list of ranges.
6444         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6445                                   (caar read)))
6446                   1)
6447           (setq first (car active)))
6448         (while read
6449           (when first
6450             (while (< first nlast)
6451               (setq unread (cons first unread)
6452                     first (1+ first))))
6453           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6454           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6455           (setq read (cdr read)))))
6456     ;; And add the last unread articles.
6457     (while (<= first last)
6458       (setq unread (cons first unread)
6459             first (1+ first)))
6460     ;; Return the list of unread articles.
6461     (delq 0 (nreverse unread))))
6462
6463 (defun gnus-list-of-read-articles (group)
6464   "Return a list of unread, unticked and non-dormant articles."
6465   (let* ((info (gnus-get-info group))
6466          (marked (gnus-info-marks info))
6467          (active (gnus-active group)))
6468     (and info active
6469          (gnus-list-range-difference
6470           (gnus-list-range-difference
6471            (gnus-sorted-complement
6472             (gnus-uncompress-range active)
6473             (gnus-list-of-unread-articles group))
6474            (cdr (assq 'dormant marked)))
6475           (cdr (assq 'tick marked))))))
6476
6477 ;; This function returns a sequence of article numbers based on the
6478 ;; difference between the ranges of read articles in this group and
6479 ;; the range of active articles.
6480 (defun gnus-sequence-of-unread-articles (group)
6481   (let* ((read (gnus-info-read (gnus-get-info group)))
6482          (active (or (gnus-active group) (gnus-activate-group group)))
6483          (last (cdr active))
6484          first nlast unread)
6485     ;; If none are read, then all are unread.
6486     (if (not read)
6487         (setq first (car active))
6488       ;; If the range of read articles is a single range, then the
6489       ;; first unread article is the article after the last read
6490       ;; article.  Sounds logical, doesn't it?
6491       (if (and (not (listp (cdr read)))
6492                (or (< (car read) (car active))
6493                    (progn (setq read (list read))
6494                           nil)))
6495           (setq first (max (car active) (1+ (cdr read))))
6496         ;; `read' is a list of ranges.
6497         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6498                                   (caar read)))
6499                   1)
6500           (setq first (car active)))
6501         (while read
6502           (when first
6503             (push (cons first nlast) unread))
6504           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6505           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6506           (setq read (cdr read)))))
6507     ;; And add the last unread articles.
6508     (cond ((< first last)
6509            (push (cons first last) unread))
6510           ((= first last)
6511            (push first unread)))
6512     ;; Return the sequence of unread articles.
6513     (delq 0 (nreverse unread))))
6514
6515 ;; Various summary commands
6516
6517 (defun gnus-summary-select-article-buffer ()
6518   "Reconfigure windows to show article buffer."
6519   (interactive)
6520   (if (not (gnus-buffer-live-p gnus-article-buffer))
6521       (error "There is no article buffer for this summary buffer")
6522     (gnus-configure-windows 'article)
6523     (select-window (get-buffer-window gnus-article-buffer))))
6524
6525 (defun gnus-summary-universal-argument (arg)
6526   "Perform any operation on all articles that are process/prefixed."
6527   (interactive "P")
6528   (let ((articles (gnus-summary-work-articles arg))
6529         func article)
6530     (if (eq
6531          (setq
6532           func
6533           (key-binding
6534            (read-key-sequence
6535             (substitute-command-keys
6536              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6537          'undefined)
6538         (gnus-error 1 "Undefined key")
6539       (save-excursion
6540         (while articles
6541           (gnus-summary-goto-subject (setq article (pop articles)))
6542           (let (gnus-newsgroup-processable)
6543             (command-execute func))
6544           (gnus-summary-remove-process-mark article)))))
6545   (gnus-summary-position-point))
6546
6547 (defun gnus-summary-toggle-truncation (&optional arg)
6548   "Toggle truncation of summary lines.
6549 With ARG, turn line truncation on if ARG is positive."
6550   (interactive "P")
6551   (setq truncate-lines
6552         (if (null arg) (not truncate-lines)
6553           (> (prefix-numeric-value arg) 0)))
6554   (redraw-display))
6555
6556 (defun gnus-summary-find-for-reselect ()
6557   "Return the number of an article to stay on across a reselect.
6558 The current article is considered, then following articles, then previous
6559 articles.  An article is sought which is not cancelled and isn't a temporary
6560 insertion from another group.  If there's no such then return a dummy 0."
6561   (let (found)
6562     (dolist (rev '(nil t))
6563       (unless found      ; don't demand the reverse list if we don't need it
6564         (let ((data (gnus-data-find-list
6565                      (gnus-summary-article-number) (gnus-data-list rev))))
6566           (while (and data (not found))
6567             (if (and (< 0 (gnus-data-number (car data)))
6568                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6569                 (setq found (gnus-data-number (car data))))
6570             (setq data (cdr data))))))
6571     (or found 0)))
6572
6573 (defun gnus-summary-reselect-current-group (&optional all rescan)
6574   "Exit and then reselect the current newsgroup.
6575 The prefix argument ALL means to select all articles."
6576   (interactive "P")
6577   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6578     (error "Ephemeral groups can't be reselected"))
6579   (let ((current-subject (gnus-summary-find-for-reselect))
6580         (group gnus-newsgroup-name))
6581     (setq gnus-newsgroup-begin nil)
6582     (gnus-summary-exit nil 'leave-hidden)
6583     ;; We have to adjust the point of group mode buffer because
6584     ;; point was moved to the next unread newsgroup by exiting.
6585     (gnus-summary-jump-to-group group)
6586     (when rescan
6587       (save-excursion
6588         (gnus-group-get-new-news-this-group 1)))
6589     (gnus-group-read-group all t)
6590     (gnus-summary-goto-subject current-subject nil t)))
6591
6592 (defun gnus-summary-rescan-group (&optional all)
6593   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6594   (interactive "P")
6595   (gnus-summary-reselect-current-group all t))
6596
6597 (defun gnus-summary-update-info (&optional non-destructive)
6598   (save-excursion
6599     (let ((group gnus-newsgroup-name))
6600       (when group
6601         (when gnus-newsgroup-kill-headers
6602           (setq gnus-newsgroup-killed
6603                 (gnus-compress-sequence
6604                  (gnus-sorted-union
6605                   (gnus-list-range-intersection
6606                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6607                   gnus-newsgroup-unreads)
6608                  t)))
6609         (unless (listp (cdr gnus-newsgroup-killed))
6610           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6611         (let ((headers gnus-newsgroup-headers))
6612           ;; Set the new ranges of read articles.
6613           (with-current-buffer gnus-group-buffer
6614             (gnus-undo-force-boundary))
6615           (gnus-update-read-articles
6616            group (gnus-sorted-union
6617                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6618           ;; Set the current article marks.
6619           (let ((gnus-newsgroup-scored
6620                  (if (and (not gnus-save-score)
6621                           (not non-destructive))
6622                      nil
6623                    gnus-newsgroup-scored)))
6624             (save-excursion
6625               (gnus-update-marks)))
6626           ;; Do the cross-ref thing.
6627           (when gnus-use-cross-reference
6628             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6629           ;; Do not switch windows but change the buffer to work.
6630           (set-buffer gnus-group-buffer)
6631           (unless (gnus-ephemeral-group-p group)
6632             (gnus-group-update-group group)))))))
6633
6634 (defun gnus-summary-save-newsrc (&optional force)
6635   "Save the current number of read/marked articles in the dribble buffer.
6636 The dribble buffer will then be saved.
6637 If FORCE (the prefix), also save the .newsrc file(s)."
6638   (interactive "P")
6639   (gnus-summary-update-info t)
6640   (if force
6641       (gnus-save-newsrc-file)
6642     (gnus-dribble-save)))
6643
6644 (defun gnus-summary-exit (&optional temporary leave-hidden)
6645   "Exit reading current newsgroup, and then return to group selection mode.
6646 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6647   (interactive)
6648   (gnus-set-global-variables)
6649   (when (gnus-buffer-live-p gnus-article-buffer)
6650     (save-excursion
6651       (set-buffer gnus-article-buffer)
6652       (mm-destroy-parts gnus-article-mime-handles)
6653       ;; Set it to nil for safety reason.
6654       (setq gnus-article-mime-handle-alist nil)
6655       (setq gnus-article-mime-handles nil)))
6656   (gnus-kill-save-kill-buffer)
6657   (gnus-async-halt-prefetch)
6658   (let* ((group gnus-newsgroup-name)
6659          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6660          (gnus-group-is-exiting-p t)
6661          (mode major-mode)
6662          (group-point nil)
6663          (buf (current-buffer)))
6664     (unless quit-config
6665       ;; Do adaptive scoring, and possibly save score files.
6666       (when gnus-newsgroup-adaptive
6667         (gnus-score-adaptive))
6668       (when gnus-use-scoring
6669         (gnus-score-save)))
6670     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6671     ;; If we have several article buffers, we kill them at exit.
6672     (unless gnus-single-article-buffer
6673       (gnus-kill-buffer gnus-original-article-buffer)
6674       (setq gnus-article-current nil))
6675     (when gnus-use-cache
6676       (gnus-cache-possibly-remove-articles)
6677       (gnus-cache-save-buffers))
6678     (gnus-async-prefetch-remove-group group)
6679     (when gnus-suppress-duplicates
6680       (gnus-dup-enter-articles))
6681     (when gnus-use-trees
6682       (gnus-tree-close group))
6683     (when gnus-use-cache
6684       (gnus-cache-write-active))
6685     ;; Remove entries for this group.
6686     (nnmail-purge-split-history (gnus-group-real-name group))
6687     ;; Make all changes in this group permanent.
6688     (unless quit-config
6689       (gnus-run-hooks 'gnus-exit-group-hook)
6690       (gnus-summary-update-info))
6691     (gnus-close-group group)
6692     ;; Make sure where we were, and go to next newsgroup.
6693     (set-buffer gnus-group-buffer)
6694     (unless quit-config
6695       (gnus-group-jump-to-group group))
6696     (gnus-run-hooks 'gnus-summary-exit-hook)
6697     (unless (or quit-config
6698                 ;; If this group has disappeared from the summary
6699                 ;; buffer, don't skip forwards.
6700                 (not (string= group (gnus-group-group-name))))
6701       (gnus-group-next-unread-group 1))
6702     (setq group-point (point))
6703     (if temporary
6704         nil                             ;Nothing to do.
6705       ;; If we have several article buffers, we kill them at exit.
6706       (unless gnus-single-article-buffer
6707         (gnus-kill-buffer gnus-article-buffer)
6708         (gnus-kill-buffer gnus-original-article-buffer)
6709         (setq gnus-article-current nil))
6710       (set-buffer buf)
6711       (if (not gnus-kill-summary-on-exit)
6712           (progn
6713             (gnus-deaden-summary)
6714             (setq mode nil))
6715         ;; We set all buffer-local variables to nil.  It is unclear why
6716         ;; this is needed, but if we don't, buffer-local variables are
6717         ;; not garbage-collected, it seems.  This would the lead to en
6718         ;; ever-growing Emacs.
6719         (gnus-summary-clear-local-variables)
6720         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6721           (gnus-summary-clear-local-variables))
6722         (when (get-buffer gnus-article-buffer)
6723           (bury-buffer gnus-article-buffer))
6724         ;; Return to group mode buffer.
6725         (when (eq mode 'gnus-summary-mode)
6726           (gnus-kill-buffer buf)))
6727       (setq gnus-current-select-method gnus-select-method)
6728       (set-buffer gnus-group-buffer)
6729       (if quit-config
6730           (gnus-handle-ephemeral-exit quit-config)
6731         (goto-char group-point)
6732         (unless leave-hidden
6733           (gnus-configure-windows 'group 'force)))
6734       ;; Clear the current group name.
6735       (unless quit-config
6736         (setq gnus-newsgroup-name nil)))))
6737
6738 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6739 (defun gnus-summary-exit-no-update (&optional no-questions)
6740   "Quit reading current newsgroup without updating read article info."
6741   (interactive)
6742   (let* ((group gnus-newsgroup-name)
6743          (gnus-group-is-exiting-p t)
6744          (gnus-group-is-exiting-without-update-p t)
6745          (quit-config (gnus-group-quit-config group)))
6746     (when (or no-questions
6747               gnus-expert-user
6748               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6749       (gnus-async-halt-prefetch)
6750       (run-hooks 'gnus-summary-prepare-exit-hook)
6751       (when (gnus-buffer-live-p gnus-article-buffer)
6752         (save-excursion
6753           (set-buffer gnus-article-buffer)
6754           (mm-destroy-parts gnus-article-mime-handles)
6755           ;; Set it to nil for safety reason.
6756           (setq gnus-article-mime-handle-alist nil)
6757           (setq gnus-article-mime-handles nil)))
6758       ;; If we have several article buffers, we kill them at exit.
6759       (unless gnus-single-article-buffer
6760         (gnus-kill-buffer gnus-article-buffer)
6761         (gnus-kill-buffer gnus-original-article-buffer)
6762         (setq gnus-article-current nil))
6763       (if (not gnus-kill-summary-on-exit)
6764           (gnus-deaden-summary)
6765         (gnus-close-group group)
6766         (gnus-summary-clear-local-variables)
6767         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6768           (gnus-summary-clear-local-variables))
6769         (gnus-kill-buffer gnus-summary-buffer))
6770       (unless gnus-single-article-buffer
6771         (setq gnus-article-current nil))
6772       (when gnus-use-trees
6773         (gnus-tree-close group))
6774       (gnus-async-prefetch-remove-group group)
6775       (when (get-buffer gnus-article-buffer)
6776         (bury-buffer gnus-article-buffer))
6777       ;; Return to the group buffer.
6778       (gnus-configure-windows 'group 'force)
6779       ;; Clear the current group name.
6780       (setq gnus-newsgroup-name nil)
6781       (unless (gnus-ephemeral-group-p group)
6782         (gnus-group-update-group group))
6783       (when (equal (gnus-group-group-name) group)
6784         (gnus-group-next-unread-group 1))
6785       (when quit-config
6786         (gnus-handle-ephemeral-exit quit-config)))))
6787
6788 (defun gnus-handle-ephemeral-exit (quit-config)
6789   "Handle movement when leaving an ephemeral group.
6790 The state which existed when entering the ephemeral is reset."
6791   (if (not (buffer-name (car quit-config)))
6792       (gnus-configure-windows 'group 'force)
6793     (set-buffer (car quit-config))
6794     (cond ((eq major-mode 'gnus-summary-mode)
6795            (gnus-set-global-variables))
6796           ((eq major-mode 'gnus-article-mode)
6797            (save-excursion
6798              ;; The `gnus-summary-buffer' variable may point
6799              ;; to the old summary buffer when using a single
6800              ;; article buffer.
6801              (unless (gnus-buffer-live-p gnus-summary-buffer)
6802                (set-buffer gnus-group-buffer))
6803              (set-buffer gnus-summary-buffer)
6804              (gnus-set-global-variables))))
6805     (if (or (eq (cdr quit-config) 'article)
6806             (eq (cdr quit-config) 'pick))
6807         (progn
6808           ;; The current article may be from the ephemeral group
6809           ;; thus it is best that we reload this article
6810           ;;
6811           ;; If we're exiting from a large digest, this can be
6812           ;; extremely slow.  So, it's better not to reload it. -- jh.
6813           ;;(gnus-summary-show-article)
6814           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6815               (gnus-configure-windows 'pick 'force)
6816             (gnus-configure-windows (cdr quit-config) 'force)))
6817       (gnus-configure-windows (cdr quit-config) 'force))
6818     (when (eq major-mode 'gnus-summary-mode)
6819       (gnus-summary-next-subject 1 nil t)
6820       (gnus-summary-recenter)
6821       (gnus-summary-position-point))))
6822
6823 ;;; Dead summaries.
6824
6825 (defvar gnus-dead-summary-mode-map nil)
6826
6827 (unless gnus-dead-summary-mode-map
6828   (setq gnus-dead-summary-mode-map (make-keymap))
6829   (suppress-keymap gnus-dead-summary-mode-map)
6830   (substitute-key-definition
6831    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6832   (dolist (key '("\C-d" "\r" "\177" [delete]))
6833     (define-key gnus-dead-summary-mode-map
6834       key 'gnus-summary-wake-up-the-dead))
6835   (dolist (key '("q" "Q"))
6836     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6837
6838 (defvar gnus-dead-summary-mode nil
6839   "Minor mode for Gnus summary buffers.")
6840
6841 (defun gnus-dead-summary-mode (&optional arg)
6842   "Minor mode for Gnus summary buffers."
6843   (interactive "P")
6844   (when (eq major-mode 'gnus-summary-mode)
6845     (make-local-variable 'gnus-dead-summary-mode)
6846     (setq gnus-dead-summary-mode
6847           (if (null arg) (not gnus-dead-summary-mode)
6848             (> (prefix-numeric-value arg) 0)))
6849     (when gnus-dead-summary-mode
6850       (add-minor-mode
6851        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6852
6853 (defun gnus-deaden-summary ()
6854   "Make the current summary buffer into a dead summary buffer."
6855   ;; Kill any previous dead summary buffer.
6856   (when (and gnus-dead-summary
6857              (buffer-name gnus-dead-summary))
6858     (with-current-buffer gnus-dead-summary
6859       (when gnus-dead-summary-mode
6860         (kill-buffer (current-buffer)))))
6861   ;; Make this the current dead summary.
6862   (setq gnus-dead-summary (current-buffer))
6863   (gnus-dead-summary-mode 1)
6864   (let ((name (buffer-name)))
6865     (when (string-match "Summary" name)
6866       (rename-buffer
6867        (concat (substring name 0 (match-beginning 0)) "Dead "
6868                (substring name (match-beginning 0)))
6869        t)
6870       (bury-buffer))))
6871
6872 (defun gnus-kill-or-deaden-summary (buffer)
6873   "Kill or deaden the summary BUFFER."
6874   (save-excursion
6875     (when (and (buffer-name buffer)
6876                (not gnus-single-article-buffer))
6877       (with-current-buffer buffer
6878         (gnus-kill-buffer gnus-article-buffer)
6879         (gnus-kill-buffer gnus-original-article-buffer)))
6880     (cond
6881      ;; Kill the buffer.
6882      (gnus-kill-summary-on-exit
6883       (when (and gnus-use-trees
6884                  (gnus-buffer-exists-p buffer))
6885         (save-excursion
6886           (set-buffer buffer)
6887           (gnus-tree-close gnus-newsgroup-name)))
6888       (gnus-kill-buffer buffer))
6889      ;; Deaden the buffer.
6890      ((gnus-buffer-exists-p buffer)
6891       (save-excursion
6892         (set-buffer buffer)
6893         (gnus-deaden-summary))))))
6894
6895 (defun gnus-summary-wake-up-the-dead (&rest args)
6896   "Wake up the dead summary buffer."
6897   (interactive)
6898   (gnus-dead-summary-mode -1)
6899   (let ((name (buffer-name)))
6900     (when (string-match "Dead " name)
6901       (rename-buffer
6902        (concat (substring name 0 (match-beginning 0))
6903                (substring name (match-end 0)))
6904        t)))
6905   (gnus-message 3 "This dead summary is now alive again"))
6906
6907 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6908 (defun gnus-summary-fetch-faq (&optional faq-dir)
6909   "Fetch the FAQ for the current group.
6910 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6911 in."
6912   (interactive
6913    (list
6914     (when current-prefix-arg
6915       (completing-read
6916        "FAQ dir: " (and (listp gnus-group-faq-directory)
6917                         (mapcar 'list
6918                                 gnus-group-faq-directory))))))
6919   (let (gnus-faq-buffer)
6920     (when (setq gnus-faq-buffer
6921                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6922       (gnus-configure-windows 'summary-faq))))
6923
6924 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6925 (defun gnus-summary-describe-group (&optional force)
6926   "Describe the current newsgroup."
6927   (interactive "P")
6928   (gnus-group-describe-group force gnus-newsgroup-name))
6929
6930 (defun gnus-summary-describe-briefly ()
6931   "Describe summary mode commands briefly."
6932   (interactive)
6933   (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")))
6934
6935 ;; Walking around group mode buffer from summary mode.
6936
6937 (defun gnus-summary-next-group (&optional no-article target-group backward)
6938   "Exit current newsgroup and then select next unread newsgroup.
6939 If prefix argument NO-ARTICLE is non-nil, no article is selected
6940 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6941 previous group instead."
6942   (interactive "P")
6943   ;; Stop pre-fetching.
6944   (gnus-async-halt-prefetch)
6945   (let ((current-group gnus-newsgroup-name)
6946         (current-buffer (current-buffer))
6947         entered)
6948     ;; First we semi-exit this group to update Xrefs and all variables.
6949     ;; We can't do a real exit, because the window conf must remain
6950     ;; the same in case the user is prompted for info, and we don't
6951     ;; want the window conf to change before that...
6952     (gnus-summary-exit t)
6953     (while (not entered)
6954       ;; Then we find what group we are supposed to enter.
6955       (set-buffer gnus-group-buffer)
6956       (gnus-group-jump-to-group current-group)
6957       (setq target-group
6958             (or target-group
6959                 (if (eq gnus-keep-same-level 'best)
6960                     (gnus-summary-best-group gnus-newsgroup-name)
6961                   (gnus-summary-search-group backward gnus-keep-same-level))))
6962       (if (not target-group)
6963           ;; There are no further groups, so we return to the group
6964           ;; buffer.
6965           (progn
6966             (gnus-message 5 "Returning to the group buffer")
6967             (setq entered t)
6968             (when (gnus-buffer-live-p current-buffer)
6969               (set-buffer current-buffer)
6970               (gnus-summary-exit))
6971             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6972         ;; We try to enter the target group.
6973         (gnus-group-jump-to-group target-group)
6974         (let ((unreads (gnus-group-group-unread)))
6975           (if (and (or (eq t unreads)
6976                        (and unreads (not (zerop unreads))))
6977                    (gnus-summary-read-group
6978                     target-group nil no-article
6979                     (and (buffer-name current-buffer) current-buffer)
6980                     nil backward))
6981               (setq entered t)
6982             (setq current-group target-group
6983                   target-group nil)))))))
6984
6985 (defun gnus-summary-prev-group (&optional no-article)
6986   "Exit current newsgroup and then select previous unread newsgroup.
6987 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6988   (interactive "P")
6989   (gnus-summary-next-group no-article nil t))
6990
6991 ;; Walking around summary lines.
6992
6993 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6994   "Go to the first subject satisfying any non-nil constraint.
6995 If UNREAD is non-nil, the article should be unread.
6996 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6997 If UNSEEN is non-nil, the article should be unseen.
6998 Returns the article selected or nil if there are no matching articles."
6999   (interactive "P")
7000   (cond
7001    ;; Empty summary.
7002    ((null gnus-newsgroup-data)
7003     (gnus-message 3 "No articles in the group")
7004     nil)
7005    ;; Pick the first article.
7006    ((not (or unread undownloaded unseen))
7007     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7008     (gnus-data-number (car gnus-newsgroup-data)))
7009    ;; Find the first unread article.
7010    (t
7011     (let ((data gnus-newsgroup-data))
7012       (while (and data
7013                   (let ((num (gnus-data-number (car data))))
7014                     (or (memq num gnus-newsgroup-unfetched)
7015                         (not (or (and unread
7016                                       (memq num gnus-newsgroup-unreads))
7017                                  (and undownloaded
7018                                       (memq num gnus-newsgroup-undownloaded))
7019                                  (and unseen
7020                                       (memq num gnus-newsgroup-unseen)))))))
7021         (setq data (cdr data)))
7022       (prog1
7023           (if data
7024               (progn
7025                 (goto-char (gnus-data-pos (car data)))
7026                 (gnus-data-number (car data)))
7027             (gnus-message 3 "No more%s articles"
7028                           (let* ((r (when unread " unread"))
7029                                  (d (when undownloaded " undownloaded"))
7030                                  (s (when unseen " unseen"))
7031                                  (l (delq nil (list r d s))))
7032                             (cond ((= 3 (length l))
7033                                    (concat r "," d ", or" s))
7034                                   ((= 2 (length l))
7035                                    (concat (car l) ", or" (cadr l)))
7036                                   ((= 1 (length l))
7037                                    (car l))
7038                                   (t
7039                                    ""))))
7040             nil
7041             )
7042         (gnus-summary-position-point))))))
7043
7044 (defun gnus-summary-next-subject (n &optional unread dont-display)
7045   "Go to next N'th summary line.
7046 If N is negative, go to the previous N'th subject line.
7047 If UNREAD is non-nil, only unread articles are selected.
7048 The difference between N and the actual number of steps taken is
7049 returned."
7050   (interactive "p")
7051   (let ((backward (< n 0))
7052         (n (abs n)))
7053     (while (and (> n 0)
7054                 (if backward
7055                     (gnus-summary-find-prev unread)
7056                   (gnus-summary-find-next unread)))
7057       (unless (zerop (setq n (1- n)))
7058         (gnus-summary-show-thread)))
7059     (when (/= 0 n)
7060       (gnus-message 7 "No more%s articles"
7061                     (if unread " unread" "")))
7062     (unless dont-display
7063       (gnus-summary-recenter)
7064       (gnus-summary-position-point))
7065     n))
7066
7067 (defun gnus-summary-next-unread-subject (n)
7068   "Go to next N'th unread summary line."
7069   (interactive "p")
7070   (gnus-summary-next-subject n t))
7071
7072 (defun gnus-summary-prev-subject (n &optional unread)
7073   "Go to previous N'th summary line.
7074 If optional argument UNREAD is non-nil, only unread article is selected."
7075   (interactive "p")
7076   (gnus-summary-next-subject (- n) unread))
7077
7078 (defun gnus-summary-prev-unread-subject (n)
7079   "Go to previous N'th unread summary line."
7080   (interactive "p")
7081   (gnus-summary-next-subject (- n) t))
7082
7083 (defun gnus-summary-goto-subjects (articles)
7084   "Insert the subject header for ARTICLES in the current buffer."
7085   (save-excursion
7086     (dolist (article articles)
7087       (gnus-summary-goto-subject article t)))
7088   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7089   (gnus-summary-position-point))
7090
7091 (defun gnus-summary-goto-subject (article &optional force silent)
7092   "Go the subject line of ARTICLE.
7093 If FORCE, also allow jumping to articles not currently shown."
7094   (interactive "nArticle number: ")
7095   (unless (numberp article)
7096     (error "Article %s is not a number" article))
7097   (let ((b (point))
7098         (data (gnus-data-find article)))
7099     ;; We read in the article if we have to.
7100     (and (not data)
7101          force
7102          (gnus-summary-insert-subject
7103           article
7104           (if (or (numberp force) (vectorp force)) force)
7105           t)
7106          (setq data (gnus-data-find article)))
7107     (goto-char b)
7108     (if (not data)
7109         (progn
7110           (unless silent
7111             (gnus-message 3 "Can't find article %d" article))
7112           nil)
7113       (let ((pt (gnus-data-pos data)))
7114         (goto-char pt)
7115         (gnus-summary-set-article-display-arrow pt))
7116       (gnus-summary-position-point)
7117       article)))
7118
7119 ;; Walking around summary lines with displaying articles.
7120
7121 (defun gnus-summary-expand-window (&optional arg)
7122   "Make the summary buffer take up the entire Emacs frame.
7123 Given a prefix, will force an `article' buffer configuration."
7124   (interactive "P")
7125   (if arg
7126       (gnus-configure-windows 'article 'force)
7127     (gnus-configure-windows 'summary 'force)))
7128
7129 (defun gnus-summary-display-article (article &optional all-header)
7130   "Display ARTICLE in article buffer."
7131   (when (gnus-buffer-live-p gnus-article-buffer)
7132     (with-current-buffer gnus-article-buffer
7133       (mm-enable-multibyte)))
7134   (gnus-set-global-variables)
7135   (when (gnus-buffer-live-p gnus-article-buffer)
7136     (with-current-buffer gnus-article-buffer
7137       (setq gnus-article-charset gnus-newsgroup-charset)
7138       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7139       (mm-enable-multibyte)))
7140   (if (null article)
7141       nil
7142     (prog1
7143         (if gnus-summary-display-article-function
7144             (funcall gnus-summary-display-article-function article all-header)
7145           (gnus-article-prepare article all-header))
7146       (gnus-run-hooks 'gnus-select-article-hook)
7147       (when (and gnus-current-article
7148                  (not (zerop gnus-current-article)))
7149         (gnus-summary-goto-subject gnus-current-article))
7150       (gnus-summary-recenter)
7151       (when (and gnus-use-trees gnus-show-threads)
7152         (gnus-possibly-generate-tree article)
7153         (gnus-highlight-selected-tree article))
7154       ;; Successfully display article.
7155       (gnus-article-set-window-start
7156        (cdr (assq article gnus-newsgroup-bookmarks))))))
7157
7158 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7159   "Select the current article.
7160 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7161 non-nil, the article will be re-fetched even if it already present in
7162 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7163 be displayed."
7164   ;; Make sure we are in the summary buffer to work around bbdb bug.
7165   (unless (eq major-mode 'gnus-summary-mode)
7166     (set-buffer gnus-summary-buffer))
7167   (let ((article (or article (gnus-summary-article-number)))
7168         (all-headers (not (not all-headers))) ;Must be t or nil.
7169         gnus-summary-display-article-function)
7170     (and (not pseudo)
7171          (gnus-summary-article-pseudo-p article)
7172          (error "This is a pseudo-article"))
7173     (save-excursion
7174       (set-buffer gnus-summary-buffer)
7175       (if (or (and gnus-single-article-buffer
7176                    (or (null gnus-current-article)
7177                        (null gnus-article-current)
7178                        (null (get-buffer gnus-article-buffer))
7179                        (not (eq article (cdr gnus-article-current)))
7180                        (not (equal (car gnus-article-current)
7181                                    gnus-newsgroup-name))))
7182               (and (not gnus-single-article-buffer)
7183                    (or (null gnus-current-article)
7184                        (not (eq gnus-current-article article))))
7185               force)
7186           ;; The requested article is different from the current article.
7187           (progn
7188             (gnus-summary-display-article article all-headers)
7189             (when (gnus-buffer-live-p gnus-article-buffer)
7190               (with-current-buffer gnus-article-buffer
7191                 (if (not gnus-article-decoded-p) ;; a local variable
7192                     (mm-disable-multibyte))))
7193             (gnus-article-set-window-start
7194              (cdr (assq article gnus-newsgroup-bookmarks)))
7195             article)
7196         'old))))
7197
7198 (defun gnus-summary-force-verify-and-decrypt ()
7199   "Display buttons for signed/encrypted parts and verify/decrypt them."
7200   (interactive)
7201   (let ((mm-verify-option 'known)
7202         (mm-decrypt-option 'known)
7203         (gnus-article-emulate-mime t)
7204         (gnus-buttonized-mime-types (append (list "multipart/signed"
7205                                                   "multipart/encrypted")
7206                                             gnus-buttonized-mime-types)))
7207     (gnus-summary-select-article nil 'force)))
7208
7209 (defun gnus-summary-set-current-mark (&optional current-mark)
7210   "Obsolete function."
7211   nil)
7212
7213 (defun gnus-summary-next-article (&optional unread subject backward push)
7214   "Select the next article.
7215 If UNREAD, only unread articles are selected.
7216 If SUBJECT, only articles with SUBJECT are selected.
7217 If BACKWARD, the previous article is selected instead of the next."
7218   (interactive "P")
7219   (cond
7220    ;; Is there such an article?
7221    ((and (gnus-summary-search-forward unread subject backward)
7222          (or (gnus-summary-display-article (gnus-summary-article-number))
7223              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7224     (gnus-summary-position-point))
7225    ;; If not, we try the first unread, if that is wanted.
7226    ((and subject
7227          gnus-auto-select-same
7228          (gnus-summary-first-unread-article))
7229     (gnus-summary-position-point)
7230     (gnus-message 6 "Wrapped"))
7231    ;; Try to get next/previous article not displayed in this group.
7232    ((and gnus-auto-extend-newsgroup
7233          (not unread) (not subject))
7234     (gnus-summary-goto-article
7235      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7236      nil (count-lines (point-min) (point))))
7237    ;; Go to next/previous group.
7238    (t
7239     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7240       (gnus-summary-jump-to-group gnus-newsgroup-name))
7241     (let ((cmd last-command-char)
7242           (point
7243            (with-current-buffer gnus-group-buffer
7244              (point)))
7245           (group
7246            (if (eq gnus-keep-same-level 'best)
7247                (gnus-summary-best-group gnus-newsgroup-name)
7248              (gnus-summary-search-group backward gnus-keep-same-level))))
7249       ;; For some reason, the group window gets selected.  We change
7250       ;; it back.
7251       (select-window (get-buffer-window (current-buffer)))
7252       ;; Select next unread newsgroup automagically.
7253       (cond
7254        ((or (not gnus-auto-select-next)
7255             (not cmd))
7256         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7257        ((or (eq gnus-auto-select-next 'quietly)
7258             (and (eq gnus-auto-select-next 'slightly-quietly)
7259                  push)
7260             (and (eq gnus-auto-select-next 'almost-quietly)
7261                  (gnus-summary-last-article-p)))
7262         ;; Select quietly.
7263         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7264             (gnus-summary-exit)
7265           (gnus-message 7 "No more%s articles (%s)..."
7266                         (if unread " unread" "")
7267                         (if group (concat "selecting " group)
7268                           "exiting"))
7269           (gnus-summary-next-group nil group backward)))
7270        (t
7271         (when (gnus-key-press-event-p last-input-event)
7272           (gnus-summary-walk-group-buffer
7273            gnus-newsgroup-name cmd unread backward point))))))))
7274
7275 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7276   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7277                       (?\C-p (gnus-group-prev-unread-group 1))))
7278         (cursor-in-echo-area t)
7279         keve key group ended prompt)
7280     (save-excursion
7281       (set-buffer gnus-group-buffer)
7282       (goto-char start)
7283       (setq group
7284             (if (eq gnus-keep-same-level 'best)
7285                 (gnus-summary-best-group gnus-newsgroup-name)
7286               (gnus-summary-search-group backward gnus-keep-same-level))))
7287     (while (not ended)
7288       (setq prompt
7289             (format
7290              "No more%s articles%s " (if unread " unread" "")
7291              (if (and group
7292                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7293                  (format " (Type %s for %s [%s])"
7294                          (single-key-description cmd)
7295                          (gnus-group-decoded-name group)
7296                          (gnus-group-unread group))
7297                (format " (Type %s to exit %s)"
7298                        (single-key-description cmd)
7299                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7300       ;; Confirm auto selection.
7301       (setq key (car (setq keve (gnus-read-event-char prompt)))
7302             ended t)
7303       (cond
7304        ((assq key keystrokes)
7305         (let ((obuf (current-buffer)))
7306           (switch-to-buffer gnus-group-buffer)
7307           (when group
7308             (gnus-group-jump-to-group group))
7309           (eval (cadr (assq key keystrokes)))
7310           (setq group (gnus-group-group-name))
7311           (switch-to-buffer obuf))
7312         (setq ended nil))
7313        ((equal key cmd)
7314         (if (or (not group)
7315                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7316             (gnus-summary-exit)
7317           (gnus-summary-next-group nil group backward)))
7318        (t
7319         (push (cdr keve) unread-command-events))))))
7320
7321 (defun gnus-summary-next-unread-article ()
7322   "Select unread article after current one."
7323   (interactive)
7324   (gnus-summary-next-article
7325    (or (not (eq gnus-summary-goto-unread 'never))
7326        (gnus-summary-last-article-p (gnus-summary-article-number)))
7327    (and gnus-auto-select-same
7328         (gnus-summary-article-subject))))
7329
7330 (defun gnus-summary-prev-article (&optional unread subject)
7331   "Select the article after the current one.
7332 If UNREAD is non-nil, only unread articles are selected."
7333   (interactive "P")
7334   (gnus-summary-next-article unread subject t))
7335
7336 (defun gnus-summary-prev-unread-article ()
7337   "Select unread article before current one."
7338   (interactive)
7339   (gnus-summary-prev-article
7340    (or (not (eq gnus-summary-goto-unread 'never))
7341        (gnus-summary-first-article-p (gnus-summary-article-number)))
7342    (and gnus-auto-select-same
7343         (gnus-summary-article-subject))))
7344
7345 (defun gnus-summary-next-page (&optional lines circular stop)
7346   "Show next page of the selected article.
7347 If at the end of the current article, select the next article.
7348 LINES says how many lines should be scrolled up.
7349
7350 If CIRCULAR is non-nil, go to the start of the article instead of
7351 selecting the next article when reaching the end of the current
7352 article.
7353
7354 If STOP is non-nil, just stop when reaching the end of the message.
7355
7356 Also see the variable `gnus-article-skip-boring'."
7357   (interactive "P")
7358   (setq gnus-summary-buffer (current-buffer))
7359   (gnus-set-global-variables)
7360   (let ((article (gnus-summary-article-number))
7361         (article-window (get-buffer-window gnus-article-buffer t))
7362         endp)
7363     ;; If the buffer is empty, we have no article.
7364     (unless article
7365       (error "No article to select"))
7366     (gnus-configure-windows 'article)
7367     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7368         (if (and (eq gnus-summary-goto-unread 'never)
7369                  (not (gnus-summary-last-article-p article)))
7370             (gnus-summary-next-article)
7371           (gnus-summary-next-unread-article))
7372       (if (or (null gnus-current-article)
7373               (null gnus-article-current)
7374               (/= article (cdr gnus-article-current))
7375               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7376           ;; Selected subject is different from current article's.
7377           (gnus-summary-display-article article)
7378         (when article-window
7379           (gnus-eval-in-buffer-window gnus-article-buffer
7380             (setq endp (or (gnus-article-next-page lines)
7381                            (gnus-article-only-boring-p))))
7382           (when endp
7383             (cond (stop
7384                    (gnus-message 3 "End of message"))
7385                   (circular
7386                    (gnus-summary-beginning-of-article))
7387                   (lines
7388                    (gnus-message 3 "End of message"))
7389                   ((null lines)
7390                    (if (and (eq gnus-summary-goto-unread 'never)
7391                             (not (gnus-summary-last-article-p article)))
7392                        (gnus-summary-next-article)
7393                      (gnus-summary-next-unread-article))))))))
7394     (gnus-summary-recenter)
7395     (gnus-summary-position-point)))
7396
7397 (defun gnus-summary-prev-page (&optional lines move)
7398   "Show previous page of selected article.
7399 Argument LINES specifies lines to be scrolled down.
7400 If MOVE, move to the previous unread article if point is at
7401 the beginning of the buffer."
7402   (interactive "P")
7403   (let ((article (gnus-summary-article-number))
7404         (article-window (get-buffer-window gnus-article-buffer t))
7405         endp)
7406     (gnus-configure-windows 'article)
7407     (if (or (null gnus-current-article)
7408             (null gnus-article-current)
7409             (/= article (cdr gnus-article-current))
7410             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7411         ;; Selected subject is different from current article's.
7412         (gnus-summary-display-article article)
7413       (gnus-summary-recenter)
7414       (when article-window
7415         (gnus-eval-in-buffer-window gnus-article-buffer
7416           (setq endp (gnus-article-prev-page lines)))
7417         (when (and move endp)
7418           (cond (lines
7419                  (gnus-message 3 "Beginning of message"))
7420                 ((null lines)
7421                  (if (and (eq gnus-summary-goto-unread 'never)
7422                           (not (gnus-summary-first-article-p article)))
7423                      (gnus-summary-prev-article)
7424                    (gnus-summary-prev-unread-article))))))))
7425   (gnus-summary-position-point))
7426
7427 (defun gnus-summary-prev-page-or-article (&optional lines)
7428   "Show previous page of selected article.
7429 Argument LINES specifies lines to be scrolled down.
7430 If at the beginning of the article, go to the next article."
7431   (interactive "P")
7432   (gnus-summary-prev-page lines t))
7433
7434 (defun gnus-summary-scroll-up (lines)
7435   "Scroll up (or down) one line current article.
7436 Argument LINES specifies lines to be scrolled up (or down if negative)."
7437   (interactive "p")
7438   (gnus-configure-windows 'article)
7439   (gnus-summary-show-thread)
7440   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7441     (gnus-eval-in-buffer-window gnus-article-buffer
7442       (cond ((> lines 0)
7443              (when (gnus-article-next-page lines)
7444                (gnus-message 3 "End of message")))
7445             ((< lines 0)
7446              (gnus-article-prev-page (- lines))))))
7447   (gnus-summary-recenter)
7448   (gnus-summary-position-point))
7449
7450 (defun gnus-summary-scroll-down (lines)
7451   "Scroll down (or up) one line current article.
7452 Argument LINES specifies lines to be scrolled down (or up if negative)."
7453   (interactive "p")
7454   (gnus-summary-scroll-up (- lines)))
7455
7456 (defun gnus-summary-next-same-subject ()
7457   "Select next article which has the same subject as current one."
7458   (interactive)
7459   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7460
7461 (defun gnus-summary-prev-same-subject ()
7462   "Select previous article which has the same subject as current one."
7463   (interactive)
7464   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7465
7466 (defun gnus-summary-next-unread-same-subject ()
7467   "Select next unread article which has the same subject as current one."
7468   (interactive)
7469   (gnus-summary-next-article t (gnus-summary-article-subject)))
7470
7471 (defun gnus-summary-prev-unread-same-subject ()
7472   "Select previous unread article which has the same subject as current one."
7473   (interactive)
7474   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7475
7476 (defun gnus-summary-first-unread-article ()
7477   "Select the first unread article.
7478 Return nil if there are no unread articles."
7479   (interactive)
7480   (prog1
7481       (when (gnus-summary-first-subject t)
7482         (gnus-summary-show-thread)
7483         (gnus-summary-first-subject t)
7484         (gnus-summary-display-article (gnus-summary-article-number)))
7485     (gnus-summary-position-point)))
7486
7487 (defun gnus-summary-first-unread-subject ()
7488   "Place the point on the subject line of the first unread article.
7489 Return nil if there are no unread articles."
7490   (interactive)
7491   (prog1
7492       (when (gnus-summary-first-subject t)
7493         (gnus-summary-show-thread)
7494         (gnus-summary-first-subject t))
7495     (gnus-summary-position-point)))
7496
7497 (defun gnus-summary-first-unseen-subject ()
7498   "Place the point on the subject line of the first unseen article.
7499 Return nil if there are no unseen articles."
7500   (interactive)
7501   (prog1
7502       (when (gnus-summary-first-subject nil nil t)
7503         (gnus-summary-show-thread)
7504         (gnus-summary-first-subject nil nil t))
7505     (gnus-summary-position-point)))
7506
7507 (defun gnus-summary-first-unseen-or-unread-subject ()
7508   "Place the point on the subject line of the first unseen article or,
7509 if all article have been seen, on the subject line of the first unread
7510 article."
7511   (interactive)
7512   (prog1
7513       (unless (when (gnus-summary-first-subject nil nil t)
7514                 (gnus-summary-show-thread)
7515                 (gnus-summary-first-subject nil nil t))
7516         (when (gnus-summary-first-subject t)
7517           (gnus-summary-show-thread)
7518           (gnus-summary-first-subject t)))
7519     (gnus-summary-position-point)))
7520
7521 (defun gnus-summary-first-article ()
7522   "Select the first article.
7523 Return nil if there are no articles."
7524   (interactive)
7525   (prog1
7526       (when (gnus-summary-first-subject)
7527         (gnus-summary-show-thread)
7528         (gnus-summary-first-subject)
7529         (gnus-summary-display-article (gnus-summary-article-number)))
7530     (gnus-summary-position-point)))
7531
7532 (defun gnus-summary-best-unread-article (&optional arg)
7533   "Select the unread article with the highest score.
7534 If given a prefix argument, select the next unread article that has a
7535 score higher than the default score."
7536   (interactive "P")
7537   (let ((article (if arg
7538                      (gnus-summary-better-unread-subject)
7539                    (gnus-summary-best-unread-subject))))
7540     (if article
7541         (gnus-summary-goto-article article)
7542       (error "No unread articles"))))
7543
7544 (defun gnus-summary-best-unread-subject ()
7545   "Select the unread subject with the highest score."
7546   (interactive)
7547   (let ((best -1000000)
7548         (data gnus-newsgroup-data)
7549         article score)
7550     (while data
7551       (and (gnus-data-unread-p (car data))
7552            (> (setq score
7553                     (gnus-summary-article-score (gnus-data-number (car data))))
7554               best)
7555            (setq best score
7556                  article (gnus-data-number (car data))))
7557       (setq data (cdr data)))
7558     (when article
7559       (gnus-summary-goto-subject article))
7560     (gnus-summary-position-point)
7561     article))
7562
7563 (defun gnus-summary-better-unread-subject ()
7564   "Select the first unread subject that has a score over the default score."
7565   (interactive)
7566   (let ((data gnus-newsgroup-data)
7567         article score)
7568     (while (and (setq article (gnus-data-number (car data)))
7569                 (or (gnus-data-read-p (car data))
7570                     (not (> (gnus-summary-article-score article)
7571                             gnus-summary-default-score))))
7572       (setq data (cdr data)))
7573     (when article
7574       (gnus-summary-goto-subject article))
7575     (gnus-summary-position-point)
7576     article))
7577
7578 (defun gnus-summary-last-subject ()
7579   "Go to the last displayed subject line in the group."
7580   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7581     (when article
7582       (gnus-summary-goto-subject article))))
7583
7584 (defun gnus-summary-goto-article (article &optional all-headers force)
7585   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7586 If ALL-HEADERS is non-nil, no header lines are hidden.
7587 If FORCE, go to the article even if it isn't displayed.  If FORCE
7588 is a number, it is the line the article is to be displayed on."
7589   (interactive
7590    (list
7591     (completing-read
7592      "Article number or Message-ID: "
7593      (mapcar (lambda (number) (list (int-to-string number)))
7594              gnus-newsgroup-limit))
7595     current-prefix-arg
7596     t))
7597   (prog1
7598       (if (and (stringp article)
7599                (string-match "@\\|%40" article))
7600           (gnus-summary-refer-article article)
7601         (when (stringp article)
7602           (setq article (string-to-number article)))
7603         (if (gnus-summary-goto-subject article force)
7604             (gnus-summary-display-article article all-headers)
7605           (gnus-message 4 "Couldn't go to article %s" article) nil))
7606     (gnus-summary-position-point)))
7607
7608 (defun gnus-summary-goto-last-article ()
7609   "Go to the previously read article."
7610   (interactive)
7611   (prog1
7612       (when gnus-last-article
7613         (gnus-summary-goto-article gnus-last-article nil t))
7614     (gnus-summary-position-point)))
7615
7616 (defun gnus-summary-pop-article (number)
7617   "Pop one article off the history and go to the previous.
7618 NUMBER articles will be popped off."
7619   (interactive "p")
7620   (let (to)
7621     (setq gnus-newsgroup-history
7622           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7623     (if to
7624         (gnus-summary-goto-article (car to) nil t)
7625       (error "Article history empty")))
7626   (gnus-summary-position-point))
7627
7628 ;; Summary commands and functions for limiting the summary buffer.
7629
7630 (defun gnus-summary-limit-to-articles (n)
7631   "Limit the summary buffer to the next N articles.
7632 If not given a prefix, use the process marked articles instead."
7633   (interactive "P")
7634   (prog1
7635       (let ((articles (gnus-summary-work-articles n)))
7636         (setq gnus-newsgroup-processable nil)
7637         (gnus-summary-limit articles))
7638     (gnus-summary-position-point)))
7639
7640 (defun gnus-summary-pop-limit (&optional total)
7641   "Restore the previous limit.
7642 If given a prefix, remove all limits."
7643   (interactive "P")
7644   (when total
7645     (setq gnus-newsgroup-limits
7646           (list (mapcar (lambda (h) (mail-header-number h))
7647                         gnus-newsgroup-headers))))
7648   (unless gnus-newsgroup-limits
7649     (error "No limit to pop"))
7650   (prog1
7651       (gnus-summary-limit nil 'pop)
7652     (gnus-summary-position-point)))
7653
7654 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7655   "Limit the summary buffer to articles that have subjects that match a regexp.
7656 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7657   (interactive
7658    (list (read-string (if current-prefix-arg
7659                           "Exclude subject (regexp): "
7660                         "Limit to subject (regexp): "))
7661          nil current-prefix-arg))
7662   (unless header
7663     (setq header "subject"))
7664   (when (not (equal "" subject))
7665     (prog1
7666         (let ((articles (gnus-summary-find-matching
7667                          (or header "subject") subject 'all nil nil
7668                          not-matching)))
7669           (unless articles
7670             (error "Found no matches for \"%s\"" subject))
7671           (gnus-summary-limit articles))
7672       (gnus-summary-position-point))))
7673
7674 (defun gnus-summary-limit-to-author (from &optional not-matching)
7675   "Limit the summary buffer to articles that have authors that match a regexp.
7676 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7677   (interactive
7678    (list (read-string (if current-prefix-arg
7679                           "Exclude author (regexp): "
7680                         "Limit to author (regexp): "))
7681          current-prefix-arg))
7682   (gnus-summary-limit-to-subject from "from" not-matching))
7683
7684 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7685   "Limit the summary buffer to articles with the given RECIPIENT.
7686
7687 If NOT-MATCHING, exclude RECIPIENT.
7688
7689 To and Cc headers are checked.  You need to include them in
7690 `nnmail-extra-headers'."
7691   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7692   (interactive
7693    (list (read-string (format "%s recipient (regexp): "
7694                               (if current-prefix-arg "Exclude" "Limit to")))
7695          current-prefix-arg))
7696   (when (not (equal "" recipient))
7697     (prog1 (let* ((to
7698                    (if (memq 'To nnmail-extra-headers)
7699                        (gnus-summary-find-matching
7700                         (cons 'extra 'To) recipient 'all nil nil
7701                         not-matching)
7702                      (gnus-message
7703                       1 "`To' isn't present in `nnmail-extra-headers'")
7704                      (sit-for 1)
7705                      nil))
7706                   (cc
7707                    (if (memq 'Cc nnmail-extra-headers)
7708                        (gnus-summary-find-matching
7709                         (cons 'extra 'Cc) recipient 'all nil nil
7710                         not-matching)
7711                      (gnus-message
7712                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7713                      (sit-for 1)
7714                      nil))
7715                   (articles
7716                    (if not-matching
7717                        ;; We need the numbers that are in both lists:
7718                        (mapcar (lambda (a)
7719                                  (and (memq a to) a))
7720                                cc)
7721                      (nconc to cc))))
7722              (unless articles
7723                (error "Found no matches for \"%s\"" recipient))
7724              (gnus-summary-limit articles))
7725       (gnus-summary-position-point))))
7726
7727 (defun gnus-summary-limit-to-age (age &optional younger-p)
7728   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7729 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7730 articles that are younger than AGE days."
7731   (interactive
7732    (let ((younger current-prefix-arg)
7733          (days-got nil)
7734          days)
7735      (while (not days-got)
7736        (setq days (if younger
7737                       (read-string "Limit to articles younger than (in days, older when negative): ")
7738                     (read-string
7739                      "Limit to articles older than (in days, younger when negative): ")))
7740        (when (> (length days) 0)
7741          (setq days (read days)))
7742        (if (numberp days)
7743            (progn
7744              (setq days-got t)
7745              (when (< days 0)
7746                (setq younger (not younger))
7747                (setq days (* days -1))))
7748          (message "Please enter a number.")
7749          (sleep-for 1)))
7750      (list days younger)))
7751   (prog1
7752       (let ((data gnus-newsgroup-data)
7753             (cutoff (days-to-time age))
7754             articles d date is-younger)
7755         (while (setq d (pop data))
7756           (when (and (vectorp (gnus-data-header d))
7757                      (setq date (mail-header-date (gnus-data-header d))))
7758             (setq is-younger (time-less-p
7759                               (time-since (condition-case ()
7760                                               (date-to-time date)
7761                                             (error '(0 0))))
7762                               cutoff))
7763             (when (if younger-p
7764                       is-younger
7765                     (not is-younger))
7766               (push (gnus-data-number d) articles))))
7767         (gnus-summary-limit (nreverse articles)))
7768     (gnus-summary-position-point)))
7769
7770 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7771   "Limit the summary buffer to articles that match an 'extra' header."
7772   (interactive
7773    (let ((header
7774           (intern
7775            (gnus-completing-read-with-default
7776             (symbol-name (car gnus-extra-headers))
7777             (if current-prefix-arg
7778                 "Exclude extra header:"
7779               "Limit extra header:")
7780             (mapcar (lambda (x)
7781                       (cons (symbol-name x) x))
7782                     gnus-extra-headers)
7783             nil
7784             t))))
7785      (list header
7786            (read-string (format "%s header %s (regexp): "
7787                                 (if current-prefix-arg "Exclude" "Limit to")
7788                                 header))
7789            current-prefix-arg)))
7790   (when (not (equal "" regexp))
7791     (prog1
7792         (let ((articles (gnus-summary-find-matching
7793                          (cons 'extra header) regexp 'all nil nil
7794                          not-matching)))
7795           (unless articles
7796             (error "Found no matches for \"%s\"" regexp))
7797           (gnus-summary-limit articles))
7798       (gnus-summary-position-point))))
7799
7800 (defun gnus-summary-limit-to-display-predicate ()
7801   "Limit the summary buffer to the predicated in the `display' group parameter."
7802   (interactive)
7803   (unless gnus-newsgroup-display
7804     (error "There is no `display' group parameter"))
7805   (let (articles)
7806     (dolist (number gnus-newsgroup-articles)
7807       (when (funcall gnus-newsgroup-display)
7808         (push number articles)))
7809     (gnus-summary-limit articles))
7810   (gnus-summary-position-point))
7811
7812 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7813 (make-obsolete
7814  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7815
7816 (defun gnus-summary-limit-to-unread (&optional all)
7817   "Limit the summary buffer to articles that are not marked as read.
7818 If ALL is non-nil, limit strictly to unread articles."
7819   (interactive "P")
7820   (if all
7821       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7822     (gnus-summary-limit-to-marks
7823      ;; Concat all the marks that say that an article is read and have
7824      ;; those removed.
7825      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7826            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7827            gnus-low-score-mark gnus-expirable-mark
7828            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7829            gnus-duplicate-mark gnus-souped-mark)
7830      'reverse)))
7831
7832 (defun gnus-summary-limit-to-replied (&optional unreplied)
7833   "Limit the summary buffer to replied articles.
7834 If UNREPLIED (the prefix), limit to unreplied articles."
7835   (interactive "P")
7836   (if unreplied
7837       (gnus-summary-limit
7838        (gnus-set-difference gnus-newsgroup-articles
7839         gnus-newsgroup-replied))
7840     (gnus-summary-limit gnus-newsgroup-replied))
7841   (gnus-summary-position-point))
7842
7843 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7844 (make-obsolete 'gnus-summary-delete-marked-with
7845                'gnus-summary-limit-exclude-marks)
7846
7847 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7848   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7849 If REVERSE, limit the summary buffer to articles that are marked
7850 with MARKS.  MARKS can either be a string of marks or a list of marks.
7851 Returns how many articles were removed."
7852   (interactive "sMarks: ")
7853   (gnus-summary-limit-to-marks marks t))
7854
7855 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7856   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7857 If REVERSE (the prefix), limit the summary buffer to articles that are
7858 not marked with MARKS.  MARKS can either be a string of marks or a
7859 list of marks.
7860 Returns how many articles were removed."
7861   (interactive "sMarks: \nP")
7862   (prog1
7863       (let ((data gnus-newsgroup-data)
7864             (marks (if (listp marks) marks
7865                      (append marks nil))) ; Transform to list.
7866             articles)
7867         (while data
7868           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7869                   (memq (gnus-data-mark (car data)) marks))
7870             (push (gnus-data-number (car data)) articles))
7871           (setq data (cdr data)))
7872         (gnus-summary-limit articles))
7873     (gnus-summary-position-point)))
7874
7875 (defun gnus-summary-limit-to-score (score)
7876   "Limit to articles with score at or above SCORE."
7877   (interactive "NLimit to articles with score of at least: ")
7878   (let ((data gnus-newsgroup-data)
7879         articles)
7880     (while data
7881       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7882                 score)
7883         (push (gnus-data-number (car data)) articles))
7884       (setq data (cdr data)))
7885     (prog1
7886         (gnus-summary-limit articles)
7887       (gnus-summary-position-point))))
7888
7889 (defun gnus-summary-limit-to-unseen ()
7890   "Limit to unseen articles."
7891   (interactive)
7892   (prog1
7893       (gnus-summary-limit gnus-newsgroup-unseen)
7894     (gnus-summary-position-point)))
7895
7896 (defun gnus-summary-limit-include-thread (id)
7897   "Display all the hidden articles that is in the thread with ID in it.
7898 When called interactively, ID is the Message-ID of the current
7899 article."
7900   (interactive (list (mail-header-id (gnus-summary-article-header))))
7901   (let ((articles (gnus-articles-in-thread
7902                    (gnus-id-to-thread (gnus-root-id id)))))
7903     (prog1
7904         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7905       (gnus-summary-limit-include-matching-articles
7906        "subject"
7907        (regexp-quote (gnus-simplify-subject-re
7908                       (mail-header-subject (gnus-id-to-header id)))))
7909       (gnus-summary-position-point))))
7910
7911 (defun gnus-summary-limit-include-matching-articles (header regexp)
7912   "Display all the hidden articles that have HEADERs that match REGEXP."
7913   (interactive (list (read-string "Match on header: ")
7914                      (read-string "Regexp: ")))
7915   (let ((articles (gnus-find-matching-articles header regexp)))
7916     (prog1
7917         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7918       (gnus-summary-position-point))))
7919
7920 (defun gnus-summary-insert-dormant-articles ()
7921   "Insert all the dormant articles for this group into the current buffer."
7922   (interactive)
7923   (let ((gnus-verbose (max 6 gnus-verbose)))
7924     (if (not gnus-newsgroup-dormant)
7925         (gnus-message 3 "No cached articles for this group")
7926       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7927
7928 (defun gnus-summary-limit-include-dormant ()
7929   "Display all the hidden articles that are marked as dormant.
7930 Note that this command only works on a subset of the articles currently
7931 fetched for this group."
7932   (interactive)
7933   (unless gnus-newsgroup-dormant
7934     (error "There are no dormant articles in this group"))
7935   (prog1
7936       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7937     (gnus-summary-position-point)))
7938
7939 (defun gnus-summary-limit-exclude-dormant ()
7940   "Hide all dormant articles."
7941   (interactive)
7942   (prog1
7943       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7944     (gnus-summary-position-point)))
7945
7946 (defun gnus-summary-limit-exclude-childless-dormant ()
7947   "Hide all dormant articles that have no children."
7948   (interactive)
7949   (let ((data (gnus-data-list t))
7950         articles d children)
7951     ;; Find all articles that are either not dormant or have
7952     ;; children.
7953     (while (setq d (pop data))
7954       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7955                 (and (setq children
7956                            (gnus-article-children (gnus-data-number d)))
7957                      (let (found)
7958                        (while children
7959                          (when (memq (car children) articles)
7960                            (setq children nil
7961                                  found t))
7962                          (pop children))
7963                        found)))
7964         (push (gnus-data-number d) articles)))
7965     ;; Do the limiting.
7966     (prog1
7967         (gnus-summary-limit articles)
7968       (gnus-summary-position-point))))
7969
7970 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7971   "Mark all unread excluded articles as read.
7972 If ALL, mark even excluded ticked and dormants as read."
7973   (interactive "P")
7974   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7975   (let ((articles (gnus-sorted-ndifference
7976                    (sort
7977                     (mapcar (lambda (h) (mail-header-number h))
7978                             gnus-newsgroup-headers)
7979                     '<)
7980                    gnus-newsgroup-limit))
7981         article)
7982     (setq gnus-newsgroup-unreads
7983           (gnus-sorted-intersection gnus-newsgroup-unreads
7984                                     gnus-newsgroup-limit))
7985     (if all
7986         (setq gnus-newsgroup-dormant nil
7987               gnus-newsgroup-marked nil
7988               gnus-newsgroup-reads
7989               (nconc
7990                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7991                gnus-newsgroup-reads))
7992       (while (setq article (pop articles))
7993         (unless (or (memq article gnus-newsgroup-dormant)
7994                     (memq article gnus-newsgroup-marked))
7995           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7996
7997 (defun gnus-summary-limit (articles &optional pop)
7998   (if pop
7999       ;; We pop the previous limit off the stack and use that.
8000       (setq articles (car gnus-newsgroup-limits)
8001             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8002     ;; We use the new limit, so we push the old limit on the stack.
8003     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8004   ;; Set the limit.
8005   (setq gnus-newsgroup-limit articles)
8006   (let ((total (length gnus-newsgroup-data))
8007         (data (gnus-data-find-list (gnus-summary-article-number)))
8008         (gnus-summary-mark-below nil)   ; Inhibit this.
8009         found)
8010     ;; This will do all the work of generating the new summary buffer
8011     ;; according to the new limit.
8012     (gnus-summary-prepare)
8013     ;; Hide any threads, possibly.
8014     (gnus-summary-maybe-hide-threads)
8015     ;; Try to return to the article you were at, or one in the
8016     ;; neighborhood.
8017     (when data
8018       ;; We try to find some article after the current one.
8019       (while data
8020         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8021           (setq data nil
8022                 found t))
8023         (setq data (cdr data))))
8024     (unless found
8025       ;; If there is no data, that means that we were after the last
8026       ;; article.  The same goes when we can't find any articles
8027       ;; after the current one.
8028       (goto-char (point-max))
8029       (gnus-summary-find-prev))
8030     (gnus-set-mode-line 'summary)
8031     ;; We return how many articles were removed from the summary
8032     ;; buffer as a result of the new limit.
8033     (- total (length gnus-newsgroup-data))))
8034
8035 (defsubst gnus-invisible-cut-children (threads)
8036   (let ((num 0))
8037     (while threads
8038       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8039         (incf num))
8040       (pop threads))
8041     (< num 2)))
8042
8043 (defsubst gnus-cut-thread (thread)
8044   "Go forwards in the thread until we find an article that we want to display."
8045   (when (or (eq gnus-fetch-old-headers 'some)
8046             (eq gnus-fetch-old-headers 'invisible)
8047             (numberp gnus-fetch-old-headers)
8048             (eq gnus-build-sparse-threads 'some)
8049             (eq gnus-build-sparse-threads 'more))
8050     ;; Deal with old-fetched headers and sparse threads.
8051     (while (and
8052             thread
8053             (or
8054              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8055              (gnus-summary-article-ancient-p
8056               (mail-header-number (car thread))))
8057             (if (or (<= (length (cdr thread)) 1)
8058                     (eq gnus-fetch-old-headers 'invisible))
8059                 (setq gnus-newsgroup-limit
8060                       (delq (mail-header-number (car thread))
8061                             gnus-newsgroup-limit)
8062                       thread (cadr thread))
8063               (when (gnus-invisible-cut-children (cdr thread))
8064                 (let ((th (cdr thread)))
8065                   (while th
8066                     (if (memq (mail-header-number (caar th))
8067                               gnus-newsgroup-limit)
8068                         (setq thread (car th)
8069                               th nil)
8070                       (setq th (cdr th))))))))))
8071   thread)
8072
8073 (defun gnus-cut-threads (threads)
8074   "Cut off all uninteresting articles from the beginning of THREADS."
8075   (when (or (eq gnus-fetch-old-headers 'some)
8076             (eq gnus-fetch-old-headers 'invisible)
8077             (numberp gnus-fetch-old-headers)
8078             (eq gnus-build-sparse-threads 'some)
8079             (eq gnus-build-sparse-threads 'more))
8080     (let ((th threads))
8081       (while th
8082         (setcar th (gnus-cut-thread (car th)))
8083         (setq th (cdr th)))))
8084   ;; Remove nixed out threads.
8085   (delq nil threads))
8086
8087 (defun gnus-summary-initial-limit (&optional show-if-empty)
8088   "Figure out what the initial limit is supposed to be on group entry.
8089 This entails weeding out unwanted dormants, low-scored articles,
8090 fetch-old-headers verbiage, and so on."
8091   ;; Most groups have nothing to remove.
8092   (if (or gnus-inhibit-limiting
8093           (and (null gnus-newsgroup-dormant)
8094                (eq gnus-newsgroup-display 'gnus-not-ignore)
8095                (not (eq gnus-fetch-old-headers 'some))
8096                (not (numberp gnus-fetch-old-headers))
8097                (not (eq gnus-fetch-old-headers 'invisible))
8098                (null gnus-summary-expunge-below)
8099                (not (eq gnus-build-sparse-threads 'some))
8100                (not (eq gnus-build-sparse-threads 'more))
8101                (null gnus-thread-expunge-below)
8102                (not gnus-use-nocem)))
8103       ()                                ; Do nothing.
8104     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8105     (setq gnus-newsgroup-limit nil)
8106     (mapatoms
8107      (lambda (node)
8108        (unless (car (symbol-value node))
8109          ;; These threads have no parents -- they are roots.
8110          (let ((nodes (cdr (symbol-value node)))
8111                thread)
8112            (while nodes
8113              (if (and gnus-thread-expunge-below
8114                       (< (gnus-thread-total-score (car nodes))
8115                          gnus-thread-expunge-below))
8116                  (gnus-expunge-thread (pop nodes))
8117                (setq thread (pop nodes))
8118                (gnus-summary-limit-children thread))))))
8119      gnus-newsgroup-dependencies)
8120     ;; If this limitation resulted in an empty group, we might
8121     ;; pop the previous limit and use it instead.
8122     (when (and (not gnus-newsgroup-limit)
8123                show-if-empty)
8124       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8125     gnus-newsgroup-limit))
8126
8127 (defun gnus-summary-limit-children (thread)
8128   "Return 1 if this subthread is visible and 0 if it is not."
8129   ;; First we get the number of visible children to this thread.  This
8130   ;; is done by recursing down the thread using this function, so this
8131   ;; will really go down to a leaf article first, before slowly
8132   ;; working its way up towards the root.
8133   (when thread
8134     (let* ((max-lisp-eval-depth 5000)
8135            (children
8136            (if (cdr thread)
8137                (apply '+ (mapcar 'gnus-summary-limit-children
8138                                  (cdr thread)))
8139              0))
8140           (number (mail-header-number (car thread)))
8141           score)
8142       (if (and
8143            (not (memq number gnus-newsgroup-marked))
8144            (or
8145             ;; If this article is dormant and has absolutely no visible
8146             ;; children, then this article isn't visible.
8147             (and (memq number gnus-newsgroup-dormant)
8148                  (zerop children))
8149             ;; If this is "fetch-old-headered" and there is no
8150             ;; visible children, then we don't want this article.
8151             (and (or (eq gnus-fetch-old-headers 'some)
8152                      (numberp gnus-fetch-old-headers))
8153                  (gnus-summary-article-ancient-p number)
8154                  (zerop children))
8155             ;; If this is "fetch-old-headered" and `invisible', then
8156             ;; we don't want this article.
8157             (and (eq gnus-fetch-old-headers 'invisible)
8158                  (gnus-summary-article-ancient-p number))
8159             ;; If this is a sparsely inserted article with no children,
8160             ;; we don't want it.
8161             (and (eq gnus-build-sparse-threads 'some)
8162                  (gnus-summary-article-sparse-p number)
8163                  (zerop children))
8164             ;; If we use expunging, and this article is really
8165             ;; low-scored, then we don't want this article.
8166             (when (and gnus-summary-expunge-below
8167                        (< (setq score
8168                                 (or (cdr (assq number gnus-newsgroup-scored))
8169                                     gnus-summary-default-score))
8170                           gnus-summary-expunge-below))
8171               ;; We increase the expunge-tally here, but that has
8172               ;; nothing to do with the limits, really.
8173               (incf gnus-newsgroup-expunged-tally)
8174               ;; We also mark as read here, if that's wanted.
8175               (when (and gnus-summary-mark-below
8176                          (< score gnus-summary-mark-below))
8177                 (setq gnus-newsgroup-unreads
8178                       (delq number gnus-newsgroup-unreads))
8179                 (if gnus-newsgroup-auto-expire
8180                     (push number gnus-newsgroup-expirable)
8181                   (push (cons number gnus-low-score-mark)
8182                         gnus-newsgroup-reads)))
8183               t)
8184             ;; Do the `display' group parameter.
8185             (and gnus-newsgroup-display
8186                  (not (funcall gnus-newsgroup-display)))
8187             ;; Check NoCeM things.
8188             (when (and gnus-use-nocem
8189                        (gnus-nocem-unwanted-article-p
8190                         (mail-header-id (car thread))))
8191               (setq gnus-newsgroup-unreads
8192                     (delq number gnus-newsgroup-unreads))
8193               t)))
8194           ;; Nope, invisible article.
8195           0
8196         ;; Ok, this article is to be visible, so we add it to the limit
8197         ;; and return 1.
8198         (push number gnus-newsgroup-limit)
8199         1))))
8200
8201 (defun gnus-expunge-thread (thread)
8202   "Mark all articles in THREAD as read."
8203   (let* ((number (mail-header-number (car thread))))
8204     (incf gnus-newsgroup-expunged-tally)
8205     ;; We also mark as read here, if that's wanted.
8206     (setq gnus-newsgroup-unreads
8207           (delq number gnus-newsgroup-unreads))
8208     (if gnus-newsgroup-auto-expire
8209         (push number gnus-newsgroup-expirable)
8210       (push (cons number gnus-low-score-mark)
8211             gnus-newsgroup-reads)))
8212   ;; Go recursively through all subthreads.
8213   (mapcar 'gnus-expunge-thread (cdr thread)))
8214
8215 ;; Summary article oriented commands
8216
8217 (defun gnus-summary-refer-parent-article (n)
8218   "Refer parent article N times.
8219 If N is negative, go to ancestor -N instead.
8220 The difference between N and the number of articles fetched is returned."
8221   (interactive "p")
8222   (let ((skip 1)
8223         error header ref)
8224     (when (not (natnump n))
8225       (setq skip (abs n)
8226             n 1))
8227     (while (and (> n 0)
8228                 (not error))
8229       (setq header (gnus-summary-article-header))
8230       (if (and (eq (mail-header-number header)
8231                    (cdr gnus-article-current))
8232                (equal gnus-newsgroup-name
8233                       (car gnus-article-current)))
8234           ;; If we try to find the parent of the currently
8235           ;; displayed article, then we take a look at the actual
8236           ;; References header, since this is slightly more
8237           ;; reliable than the References field we got from the
8238           ;; server.
8239           (save-excursion
8240             (set-buffer gnus-original-article-buffer)
8241             (nnheader-narrow-to-headers)
8242             (unless (setq ref (message-fetch-field "references"))
8243               (when (setq ref (message-fetch-field "in-reply-to"))
8244                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8245             (widen))
8246         (setq ref
8247               ;; It's not the current article, so we take a bet on
8248               ;; the value we got from the server.
8249               (mail-header-references header)))
8250       (if (and ref
8251                (not (equal ref "")))
8252           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8253             (gnus-message 1 "Couldn't find parent"))
8254         (gnus-message 1 "No references in article %d"
8255                       (gnus-summary-article-number))
8256         (setq error t))
8257       (decf n))
8258     (gnus-summary-position-point)
8259     n))
8260
8261 (defun gnus-summary-refer-references ()
8262   "Fetch all articles mentioned in the References header.
8263 Return the number of articles fetched."
8264   (interactive)
8265   (let ((ref (mail-header-references (gnus-summary-article-header)))
8266         (current (gnus-summary-article-number))
8267         (n 0))
8268     (if (or (not ref)
8269             (equal ref ""))
8270         (error "No References in the current article")
8271       ;; For each Message-ID in the References header...
8272       (while (string-match "<[^>]*>" ref)
8273         (incf n)
8274         ;; ... fetch that article.
8275         (gnus-summary-refer-article
8276          (prog1 (match-string 0 ref)
8277            (setq ref (substring ref (match-end 0))))))
8278       (gnus-summary-goto-subject current)
8279       (gnus-summary-position-point)
8280       n)))
8281
8282 (defun gnus-summary-refer-thread (&optional limit)
8283   "Fetch all articles in the current thread.
8284 If LIMIT (the numerical prefix), fetch that many old headers instead
8285 of what's specified by the `gnus-refer-thread-limit' variable."
8286   (interactive "P")
8287   (let ((id (mail-header-id (gnus-summary-article-header)))
8288         (limit (if limit (prefix-numeric-value limit)
8289                  gnus-refer-thread-limit)))
8290     (unless (eq gnus-fetch-old-headers 'invisible)
8291       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8292       ;; Retrieve the headers and read them in.
8293       (if (eq (if (numberp limit)
8294                   (gnus-retrieve-headers
8295                    (list (min
8296                           (+ (mail-header-number
8297                               (gnus-summary-article-header))
8298                              limit)
8299                           gnus-newsgroup-end))
8300                    gnus-newsgroup-name (* limit 2))
8301                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8302                 ;; headers.
8303                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8304                                        gnus-newsgroup-name limit))
8305               'nov)
8306           (gnus-build-all-threads)
8307         (error "Can't fetch thread from back ends that don't support NOV"))
8308       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8309     (gnus-summary-limit-include-thread id)))
8310
8311 (defun gnus-summary-refer-article (message-id)
8312   "Fetch an article specified by MESSAGE-ID."
8313   (interactive "sMessage-ID: ")
8314   (when (and (stringp message-id)
8315              (not (zerop (length message-id))))
8316     (setq message-id (gnus-replace-in-string message-id " " ""))
8317     ;; Construct the correct Message-ID if necessary.
8318     ;; Suggested by tale@pawl.rpi.edu.
8319     (unless (string-match "^<" message-id)
8320       (setq message-id (concat "<" message-id)))
8321     (unless (string-match ">$" message-id)
8322       (setq message-id (concat message-id ">")))
8323     ;; People often post MIDs from URLs, so unhex it:
8324     (unless (string-match "@" message-id)
8325       (setq message-id (gnus-url-unhex-string message-id)))
8326     (let* ((header (gnus-id-to-header message-id))
8327            (sparse (and header
8328                         (gnus-summary-article-sparse-p
8329                          (mail-header-number header))
8330                         (memq (mail-header-number header)
8331                               gnus-newsgroup-limit)))
8332            number)
8333       (cond
8334        ;; If the article is present in the buffer we just go to it.
8335        ((and header
8336              (or (not (gnus-summary-article-sparse-p
8337                        (mail-header-number header)))
8338                  sparse))
8339         (prog1
8340             (gnus-summary-goto-article
8341              (mail-header-number header) nil t)
8342           (when sparse
8343             (gnus-summary-update-article (mail-header-number header)))))
8344        (t
8345         ;; We fetch the article.
8346         (catch 'found
8347           (dolist (gnus-override-method (gnus-refer-article-methods))
8348             (when (and (gnus-check-server gnus-override-method)
8349                        ;; Fetch the header,
8350                        (setq number (gnus-summary-insert-subject message-id)))
8351               ;; and display the article.
8352               (gnus-summary-select-article nil nil nil number)
8353               (throw 'found t)))
8354           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8355
8356 (defun gnus-refer-article-methods ()
8357   "Return a list of referable methods."
8358   (cond
8359    ;; No method, so we default to current and native.
8360    ((null gnus-refer-article-method)
8361     (list gnus-current-select-method gnus-select-method))
8362    ;; Current.
8363    ((eq 'current gnus-refer-article-method)
8364     (list gnus-current-select-method))
8365    ;; List of select methods.
8366    ((not (and (symbolp (car gnus-refer-article-method))
8367               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8368     (let (out)
8369       (dolist (method gnus-refer-article-method)
8370         (push (if (eq 'current method)
8371                   gnus-current-select-method
8372                 method)
8373               out))
8374       (nreverse out)))
8375    ;; One single select method.
8376    (t
8377     (list gnus-refer-article-method))))
8378
8379 (defun gnus-summary-edit-parameters ()
8380   "Edit the group parameters of the current group."
8381   (interactive)
8382   (gnus-group-edit-group gnus-newsgroup-name 'params))
8383
8384 (defun gnus-summary-customize-parameters ()
8385   "Customize the group parameters of the current group."
8386   (interactive)
8387   (gnus-group-customize gnus-newsgroup-name))
8388
8389 (defun gnus-summary-enter-digest-group (&optional force)
8390   "Enter an nndoc group based on the current article.
8391 If FORCE, force a digest interpretation.  If not, try
8392 to guess what the document format is."
8393   (interactive "P")
8394   (let ((conf gnus-current-window-configuration))
8395     (save-window-excursion
8396       (save-excursion
8397         (let (gnus-article-prepare-hook
8398               gnus-display-mime-function
8399               gnus-break-pages)
8400           (gnus-summary-select-article))))
8401     (setq gnus-current-window-configuration conf)
8402     (let* ((name (format "%s-%d"
8403                          (gnus-group-prefixed-name
8404                           gnus-newsgroup-name (list 'nndoc ""))
8405                          (with-current-buffer gnus-summary-buffer
8406                            gnus-current-article)))
8407            (ogroup gnus-newsgroup-name)
8408            (params (append (gnus-info-params (gnus-get-info ogroup))
8409                            (list (cons 'to-group ogroup))
8410                            (list (cons 'parent-group ogroup))
8411                            (list (cons 'save-article-group ogroup))))
8412            (case-fold-search t)
8413            (buf (current-buffer))
8414            dig to-address)
8415       (save-excursion
8416         (set-buffer gnus-original-article-buffer)
8417         ;; Have the digest group inherit the main mail address of
8418         ;; the parent article.
8419         (when (setq to-address (or (gnus-fetch-field "reply-to")
8420                                    (gnus-fetch-field "from")))
8421           (setq params (append
8422                         (list (cons 'to-address
8423                                     (funcall gnus-decode-encoded-word-function
8424                                              to-address))))))
8425         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8426         (insert-buffer-substring gnus-original-article-buffer)
8427         ;; Remove lines that may lead nndoc to misinterpret the
8428         ;; document type.
8429         (narrow-to-region
8430          (goto-char (point-min))
8431          (or (search-forward "\n\n" nil t) (point)))
8432         (goto-char (point-min))
8433         (delete-matching-lines "^Path:\\|^From ")
8434         (widen))
8435       (unwind-protect
8436           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8437                     (gnus-newsgroup-ephemeral-ignored-charsets
8438                      gnus-newsgroup-ignored-charsets))
8439                 (gnus-group-read-ephemeral-group
8440                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8441                               (nndoc-article-type
8442                                ,(if force 'mbox 'guess)))
8443                  t nil nil nil
8444                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8445                                                         "ADAPT")))))
8446               ;; Make all postings to this group go to the parent group.
8447               (nconc (gnus-info-params (gnus-get-info name))
8448                      params)
8449             ;; Couldn't select this doc group.
8450             (switch-to-buffer buf)
8451             (gnus-set-global-variables)
8452             (gnus-configure-windows 'summary)
8453             (gnus-message 3 "Article couldn't be entered?"))
8454         (kill-buffer dig)))))
8455
8456 (defun gnus-summary-read-document (n)
8457   "Open a new group based on the current article(s).
8458 This will allow you to read digests and other similar
8459 documents as newsgroups.
8460 Obeys the standard process/prefix convention."
8461   (interactive "P")
8462   (let* ((ogroup gnus-newsgroup-name)
8463          (params (append (gnus-info-params (gnus-get-info ogroup))
8464                          (list (cons 'to-group ogroup))))
8465          group egroup groups vgroup)
8466     (dolist (article (gnus-summary-work-articles n))
8467       (setq group (format "%s-%d" gnus-newsgroup-name article))
8468       (gnus-summary-remove-process-mark article)
8469       (when (gnus-summary-display-article article)
8470         (save-excursion
8471           (with-temp-buffer
8472             (insert-buffer-substring gnus-original-article-buffer)
8473             ;; Remove some headers that may lead nndoc to make
8474             ;; the wrong guess.
8475             (message-narrow-to-head)
8476             (goto-char (point-min))
8477             (delete-matching-lines "^Path:\\|^From ")
8478             (widen)
8479             (if (setq egroup
8480                       (gnus-group-read-ephemeral-group
8481                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8482                                      (nndoc-article-type guess))
8483                        t nil t))
8484                 (progn
8485             ;; Make all postings to this group go to the parent group.
8486                   (nconc (gnus-info-params (gnus-get-info egroup))
8487                          params)
8488                   (push egroup groups))
8489               ;; Couldn't select this doc group.
8490               (gnus-error 3 "Article couldn't be entered"))))))
8491     ;; Now we have selected all the documents.
8492     (cond
8493      ((not groups)
8494       (error "None of the articles could be interpreted as documents"))
8495      ((gnus-group-read-ephemeral-group
8496        (setq vgroup (format
8497                      "nnvirtual:%s-%s" gnus-newsgroup-name
8498                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8499        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8500        t
8501        (cons (current-buffer) 'summary)))
8502      (t
8503       (error "Couldn't select virtual nndoc group")))))
8504
8505 (defun gnus-summary-isearch-article (&optional regexp-p)
8506   "Do incremental search forward on the current article.
8507 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8508   (interactive "P")
8509   (gnus-summary-select-article)
8510   (gnus-configure-windows 'article)
8511   (gnus-eval-in-buffer-window gnus-article-buffer
8512     (save-restriction
8513       (widen)
8514       (isearch-forward regexp-p))))
8515
8516 (defun gnus-summary-search-article-forward (regexp &optional backward)
8517   "Search for an article containing REGEXP forward.
8518 If BACKWARD, search backward instead."
8519   (interactive
8520    (list (read-string
8521           (format "Search article %s (regexp%s): "
8522                   (if current-prefix-arg "backward" "forward")
8523                   (if gnus-last-search-regexp
8524                       (concat ", default " gnus-last-search-regexp)
8525                     "")))
8526          current-prefix-arg))
8527   (if (string-equal regexp "")
8528       (setq regexp (or gnus-last-search-regexp ""))
8529     (setq gnus-last-search-regexp regexp)
8530     (setq gnus-article-before-search gnus-current-article))
8531   ;; Intentionally set gnus-last-article.
8532   (setq gnus-last-article gnus-article-before-search)
8533   (let ((gnus-last-article gnus-last-article))
8534     (if (gnus-summary-search-article regexp backward)
8535         (gnus-summary-show-thread)
8536       (signal 'search-failed (list regexp)))))
8537
8538 (defun gnus-summary-search-article-backward (regexp)
8539   "Search for an article containing REGEXP backward."
8540   (interactive
8541    (list (read-string
8542           (format "Search article backward (regexp%s): "
8543                   (if gnus-last-search-regexp
8544                       (concat ", default " gnus-last-search-regexp)
8545                     "")))))
8546   (gnus-summary-search-article-forward regexp 'backward))
8547
8548 (defun gnus-summary-search-article (regexp &optional backward)
8549   "Search for an article containing REGEXP.
8550 Optional argument BACKWARD means do search for backward.
8551 `gnus-select-article-hook' is not called during the search."
8552   ;; We have to require this here to make sure that the following
8553   ;; dynamic binding isn't shadowed by autoloading.
8554   (require 'gnus-async)
8555   (require 'gnus-art)
8556   (let ((gnus-select-article-hook nil)  ;Disable hook.
8557         (gnus-article-prepare-hook nil)
8558         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8559         (gnus-use-article-prefetch nil)
8560         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8561         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8562         (gnus-visual nil)
8563         (gnus-keep-backlog nil)
8564         (gnus-break-pages nil)
8565         (gnus-summary-display-arrow nil)
8566         (gnus-updated-mode-lines nil)
8567         (gnus-auto-center-summary nil)
8568         (sum (current-buffer))
8569         (gnus-display-mime-function nil)
8570         (found nil)
8571         point)
8572     (gnus-save-hidden-threads
8573       (gnus-summary-select-article)
8574       (set-buffer gnus-article-buffer)
8575       (goto-char (window-point (get-buffer-window (current-buffer))))
8576       (when backward
8577         (forward-line -1))
8578       (while (not found)
8579         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8580         (if (if backward
8581                 (re-search-backward regexp nil t)
8582               (re-search-forward regexp nil t))
8583             ;; We found the regexp.
8584             (progn
8585               (setq found 'found)
8586               (beginning-of-line)
8587               (set-window-start
8588                (get-buffer-window (current-buffer))
8589                (point))
8590               (forward-line 1)
8591               (set-window-point
8592                (get-buffer-window (current-buffer))
8593                (point))
8594               (set-buffer sum)
8595               (setq point (point)))
8596           ;; We didn't find it, so we go to the next article.
8597           (set-buffer sum)
8598           (setq found 'not)
8599           (while (eq found 'not)
8600             (if (not (if backward (gnus-summary-find-prev)
8601                        (gnus-summary-find-next)))
8602                 ;; No more articles.
8603                 (setq found t)
8604               ;; Select the next article and adjust point.
8605               (unless (gnus-summary-article-sparse-p
8606                        (gnus-summary-article-number))
8607                 (setq found nil)
8608                 (gnus-summary-select-article)
8609                 (set-buffer gnus-article-buffer)
8610                 (widen)
8611                 (goto-char (if backward (point-max) (point-min))))))))
8612       (gnus-message 7 ""))
8613     ;; Return whether we found the regexp.
8614     (when (eq found 'found)
8615       (goto-char point)
8616       (gnus-summary-show-thread)
8617       (gnus-summary-goto-subject gnus-current-article)
8618       (gnus-summary-position-point)
8619       t)))
8620
8621 (defun gnus-find-matching-articles (header regexp)
8622   "Return a list of all articles that match REGEXP on HEADER.
8623 This search includes all articles in the current group that Gnus has
8624 fetched headers for, whether they are displayed or not."
8625   (let ((articles nil)
8626         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8627         (case-fold-search t))
8628     (dolist (header gnus-newsgroup-headers)
8629       (when (string-match regexp (funcall func header))
8630         (push (mail-header-number header) articles)))
8631     (nreverse articles)))
8632
8633 (defun gnus-summary-find-matching (header regexp &optional backward unread
8634                                           not-case-fold not-matching)
8635   "Return a list of all articles that match REGEXP on HEADER.
8636 The search stars on the current article and goes forwards unless
8637 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8638 If UNREAD is non-nil, only unread articles will
8639 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8640 in the comparisons. If NOT-MATCHING, return a list of all articles that
8641 not match REGEXP on HEADER."
8642   (let ((case-fold-search (not not-case-fold))
8643         articles d func)
8644     (if (consp header)
8645         (if (eq (car header) 'extra)
8646             (setq func
8647                   `(lambda (h)
8648                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8649                          "")))
8650           (error "%s is an invalid header" header))
8651       (unless (fboundp (intern (concat "mail-header-" header)))
8652         (error "%s is not a valid header" header))
8653       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8654     (dolist (d (if (eq backward 'all)
8655                    gnus-newsgroup-data
8656                  (gnus-data-find-list
8657                   (gnus-summary-article-number)
8658                   (gnus-data-list backward))))
8659       (when (and (or (not unread)       ; We want all articles...
8660                      (gnus-data-unread-p d)) ; Or just unreads.
8661                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8662                  (if not-matching
8663                      (not (string-match
8664                            regexp
8665                            (funcall func (gnus-data-header d))))
8666                    (string-match regexp
8667                                  (funcall func (gnus-data-header d)))))
8668         (push (gnus-data-number d) articles))) ; Success!
8669     (nreverse articles)))
8670
8671 (defun gnus-summary-execute-command (header regexp command &optional backward)
8672   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8673 If HEADER is an empty string (or nil), the match is done on the entire
8674 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8675   (interactive
8676    (list (let ((completion-ignore-case t))
8677            (completing-read
8678             "Header name: "
8679             (mapcar (lambda (header) (list (format "%s" header)))
8680                     (append
8681                      '("Number" "Subject" "From" "Lines" "Date"
8682                        "Message-ID" "Xref" "References" "Body")
8683                      gnus-extra-headers))
8684             nil 'require-match))
8685          (read-string "Regexp: ")
8686          (read-key-sequence "Command: ")
8687          current-prefix-arg))
8688   (when (equal header "Body")
8689     (setq header ""))
8690   ;; Hidden thread subtrees must be searched as well.
8691   (gnus-summary-show-all-threads)
8692   ;; We don't want to change current point nor window configuration.
8693   (save-excursion
8694     (save-window-excursion
8695       (let (gnus-visual
8696             gnus-treat-strip-trailing-blank-lines
8697             gnus-treat-strip-leading-blank-lines
8698             gnus-treat-strip-multiple-blank-lines
8699             gnus-treat-hide-boring-headers
8700             gnus-treat-fold-newsgroups
8701             gnus-article-prepare-hook)
8702         (gnus-message 6 "Executing %s..." (key-description command))
8703         ;; We'd like to execute COMMAND interactively so as to give arguments.
8704         (gnus-execute header regexp
8705                       `(call-interactively ',(key-binding command))
8706                       backward)
8707         (gnus-message 6 "Executing %s...done" (key-description command))))))
8708
8709 (defun gnus-summary-beginning-of-article ()
8710   "Scroll the article back to the beginning."
8711   (interactive)
8712   (gnus-summary-select-article)
8713   (gnus-configure-windows 'article)
8714   (gnus-eval-in-buffer-window gnus-article-buffer
8715     (widen)
8716     (goto-char (point-min))
8717     (when gnus-break-pages
8718       (gnus-narrow-to-page))))
8719
8720 (defun gnus-summary-end-of-article ()
8721   "Scroll to the end of the article."
8722   (interactive)
8723   (gnus-summary-select-article)
8724   (gnus-configure-windows 'article)
8725   (gnus-eval-in-buffer-window gnus-article-buffer
8726     (widen)
8727     (goto-char (point-max))
8728     (recenter -3)
8729     (when gnus-break-pages
8730       (when (re-search-backward page-delimiter nil t)
8731         (narrow-to-region (match-end 0) (point-max)))
8732       (gnus-narrow-to-page))))
8733
8734 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8735   "Truncate to LEN and quote all \"(\"'s in STRING."
8736   (gnus-replace-in-string (if (and len (> (length string) len))
8737                               (substring string 0 len)
8738                             string)
8739                           "[()]" "\\\\\\&"))
8740
8741 (defun gnus-summary-print-article (&optional filename n)
8742   "Generate and print a PostScript image of the process-marked (mail) articles.
8743
8744 If used interactively, print the current article if none are
8745 process-marked.  With prefix arg, prompt the user for the name of the
8746 file to save in.
8747
8748 When used from Lisp, accept two optional args FILENAME and N.  N means
8749 to print the next N articles.  If N is negative, print the N previous
8750 articles.  If N is nil and articles have been marked with the process
8751 mark, print these instead.
8752
8753 If the optional first argument FILENAME is nil, send the image to the
8754 printer.  If FILENAME is a string, save the PostScript image in a file with
8755 that name.  If FILENAME is a number, prompt the user for the name of the file
8756 to save in."
8757   (interactive (list (ps-print-preprint current-prefix-arg)))
8758   (dolist (article (gnus-summary-work-articles n))
8759     (gnus-summary-select-article nil nil 'pseudo article)
8760     (gnus-eval-in-buffer-window gnus-article-buffer
8761       (gnus-print-buffer))
8762     (gnus-summary-remove-process-mark article))
8763   (ps-despool filename))
8764
8765 (defun gnus-print-buffer ()
8766   (let ((buffer (generate-new-buffer " *print*")))
8767     (unwind-protect
8768         (progn
8769           (copy-to-buffer buffer (point-min) (point-max))
8770           (set-buffer buffer)
8771           (gnus-remove-text-with-property 'gnus-decoration)
8772           (when (gnus-visual-p 'article-highlight 'highlight)
8773             ;; Copy-to-buffer doesn't copy overlay.  So redo
8774             ;; highlight.
8775             (let ((gnus-article-buffer buffer))
8776               (gnus-article-highlight-citation t)
8777               (gnus-article-highlight-signature)
8778               (gnus-article-emphasize)
8779               (gnus-article-delete-invisible-text)))
8780           (let ((ps-left-header
8781                  (list
8782                   (concat "("
8783                           (gnus-summary-print-truncate-and-quote
8784                            (mail-header-subject gnus-current-headers)
8785                            66) ")")
8786                   (concat "("
8787                           (gnus-summary-print-truncate-and-quote
8788                            (mail-header-from gnus-current-headers)
8789                            45) ")")))
8790                 (ps-right-header
8791                  (list
8792                   "/pagenumberstring load"
8793                   (concat "("
8794                           (mail-header-date gnus-current-headers) ")"))))
8795             (gnus-run-hooks 'gnus-ps-print-hook)
8796             (save-excursion
8797               (if window-system
8798                   (ps-spool-buffer-with-faces)
8799                 (ps-spool-buffer)))))
8800       (kill-buffer buffer))))
8801
8802 (defun gnus-summary-show-article (&optional arg)
8803   "Force redisplaying of the current article.
8804 If ARG (the prefix) is a number, show the article with the charset
8805 defined in `gnus-summary-show-article-charset-alist', or the charset
8806 input.
8807 If ARG (the prefix) is non-nil and not a number, show the raw article
8808 without any article massaging functions being run.  Normally, the key
8809 strokes are `C-u g'."
8810   (interactive "P")
8811   (cond
8812    ((numberp arg)
8813     (gnus-summary-show-article t)
8814     (let ((gnus-newsgroup-charset
8815            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8816                (mm-read-coding-system
8817                 "View as charset: " ;; actually it is coding system.
8818                 (with-current-buffer gnus-article-buffer
8819                   (mm-detect-coding-region (point) (point-max))))))
8820           (gnus-newsgroup-ignored-charsets 'gnus-all))
8821       (gnus-summary-select-article nil 'force)
8822       (let ((deps gnus-newsgroup-dependencies)
8823             head header lines)
8824         (save-excursion
8825           (set-buffer gnus-original-article-buffer)
8826           (save-restriction
8827             (message-narrow-to-head)
8828             (setq head (buffer-string))
8829             (goto-char (point-min))
8830             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8831               (goto-char (point-max))
8832               (widen)
8833               (setq lines (1- (count-lines (point) (point-max))))))
8834           (with-temp-buffer
8835             (insert (format "211 %d Article retrieved.\n"
8836                             (cdr gnus-article-current)))
8837             (insert head)
8838             (if lines (insert (format "Lines: %d\n" lines)))
8839             (insert ".\n")
8840             (let ((nntp-server-buffer (current-buffer)))
8841               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8842         (gnus-data-set-header
8843          (gnus-data-find (cdr gnus-article-current))
8844          header)
8845         (gnus-summary-update-article-line
8846          (cdr gnus-article-current) header)
8847         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8848           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8849    ((not arg)
8850     ;; Select the article the normal way.
8851     (gnus-summary-select-article nil 'force))
8852    (t
8853     ;; We have to require this here to make sure that the following
8854     ;; dynamic binding isn't shadowed by autoloading.
8855     (require 'gnus-async)
8856     (require 'gnus-art)
8857     ;; Bind the article treatment functions to nil.
8858     (let ((gnus-have-all-headers t)
8859           gnus-article-prepare-hook
8860           gnus-article-decode-hook
8861           gnus-display-mime-function
8862           gnus-break-pages)
8863       ;; Destroy any MIME parts.
8864       (when (gnus-buffer-live-p gnus-article-buffer)
8865         (save-excursion
8866           (set-buffer gnus-article-buffer)
8867           (mm-destroy-parts gnus-article-mime-handles)
8868           ;; Set it to nil for safety reason.
8869           (setq gnus-article-mime-handle-alist nil)
8870           (setq gnus-article-mime-handles nil)))
8871       (gnus-summary-select-article nil 'force))))
8872   (gnus-summary-goto-subject gnus-current-article)
8873   (gnus-summary-position-point))
8874
8875 (defun gnus-summary-show-raw-article ()
8876   "Show the raw article without any article massaging functions being run."
8877   (interactive)
8878   (gnus-summary-show-article t))
8879
8880 (defun gnus-summary-verbose-headers (&optional arg)
8881   "Toggle permanent full header display.
8882 If ARG is a positive number, turn header display on.
8883 If ARG is a negative number, turn header display off."
8884   (interactive "P")
8885   (setq gnus-show-all-headers
8886         (cond ((or (not (numberp arg))
8887                    (zerop arg))
8888                (not gnus-show-all-headers))
8889               ((natnump arg)
8890                t)))
8891   (gnus-summary-show-article))
8892
8893 (defun gnus-summary-toggle-header (&optional arg)
8894   "Show the headers if they are hidden, or hide them if they are shown.
8895 If ARG is a positive number, show the entire header.
8896 If ARG is a negative number, hide the unwanted header lines."
8897   (interactive "P")
8898   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8899                      (get-buffer-window gnus-article-buffer t))))
8900     (with-current-buffer gnus-article-buffer
8901       (widen)
8902       (article-narrow-to-head)
8903       (let* ((buffer-read-only nil)
8904              (inhibit-point-motion-hooks t)
8905              (hidden (if (numberp arg)
8906                          (>= arg 0)
8907                        (or (not (looking-at "[^ \t\n]+:"))
8908                            (gnus-article-hidden-text-p 'headers))))
8909              s e)
8910         (delete-region (point-min) (point-max))
8911         (with-current-buffer gnus-original-article-buffer
8912           (goto-char (setq s (point-min)))
8913           (setq e (if (search-forward "\n\n" nil t)
8914                       (1- (point))
8915                     (point-max))))
8916         (insert-buffer-substring gnus-original-article-buffer s e)
8917         (run-hooks 'gnus-article-decode-hook)
8918         (if hidden
8919             (let ((gnus-treat-hide-headers nil)
8920                   (gnus-treat-hide-boring-headers nil))
8921               (gnus-delete-wash-type 'headers)
8922               (gnus-treat-article 'head))
8923           (gnus-treat-article 'head))
8924         (widen)
8925         (if window
8926             (set-window-start window (goto-char (point-min))))
8927         (if gnus-break-pages
8928             (gnus-narrow-to-page)
8929           (when (gnus-visual-p 'page-marker)
8930             (let ((buffer-read-only nil))
8931               (gnus-remove-text-with-property 'gnus-prev)
8932               (gnus-remove-text-with-property 'gnus-next))))
8933         (gnus-set-mode-line 'article)))))
8934
8935 (defun gnus-summary-show-all-headers ()
8936   "Make all header lines visible."
8937   (interactive)
8938   (gnus-summary-toggle-header 1))
8939
8940 (defun gnus-summary-caesar-message (&optional arg)
8941   "Caesar rotate the current article by 13.
8942 The numerical prefix specifies how many places to rotate each letter
8943 forward."
8944   (interactive "P")
8945   (gnus-summary-select-article)
8946   (let ((mail-header-separator ""))
8947     (gnus-eval-in-buffer-window gnus-article-buffer
8948       (save-restriction
8949         (widen)
8950         (let ((start (window-start))
8951               buffer-read-only)
8952           (message-caesar-buffer-body arg)
8953           (set-window-start (get-buffer-window (current-buffer)) start))))))
8954
8955 (autoload 'unmorse-region "morse"
8956   "Convert morse coded text in region to ordinary ASCII text."
8957   t)
8958
8959 (defun gnus-summary-morse-message (&optional arg)
8960   "Morse decode the current article."
8961   (interactive "P")
8962   (gnus-summary-select-article)
8963   (let ((mail-header-separator ""))
8964     (gnus-eval-in-buffer-window gnus-article-buffer
8965       (save-excursion
8966         (save-restriction
8967           (widen)
8968           (let ((pos (window-start))
8969                 buffer-read-only)
8970             (goto-char (point-min))
8971             (when (message-goto-body)
8972               (gnus-narrow-to-body))
8973             (goto-char (point-min))
8974             (while (search-forward "·" (point-max) t)
8975               (replace-match "."))
8976             (unmorse-region (point-min) (point-max))
8977             (widen)
8978             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8979
8980 (defun gnus-summary-stop-page-breaking ()
8981   "Stop page breaking in the current article."
8982   (interactive)
8983   (gnus-summary-select-article)
8984   (gnus-eval-in-buffer-window gnus-article-buffer
8985     (widen)
8986     (when (gnus-visual-p 'page-marker)
8987       (let ((buffer-read-only nil))
8988         (gnus-remove-text-with-property 'gnus-prev)
8989         (gnus-remove-text-with-property 'gnus-next))
8990       (setq gnus-page-broken nil))))
8991
8992 (defun gnus-summary-move-article (&optional n to-newsgroup
8993                                             select-method action)
8994   "Move the current article to a different newsgroup.
8995 If N is a positive number, move the N next articles.
8996 If N is a negative number, move the N previous articles.
8997 If N is nil and any articles have been marked with the process mark,
8998 move those articles instead.
8999 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9000 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9001 re-spool using this method.
9002
9003 When called interactively with TO-NEWSGROUP being nil, the value of
9004 the variable `gnus-move-split-methods' is used for finding a default
9005 for the target newsgroup.
9006
9007 For this function to work, both the current newsgroup and the
9008 newsgroup that you want to move to have to support the `request-move'
9009 and `request-accept' functions.
9010
9011 ACTION can be either `move' (the default), `crosspost' or `copy'."
9012   (interactive "P")
9013   (unless action
9014     (setq action 'move))
9015   ;; Check whether the source group supports the required functions.
9016   (cond ((and (eq action 'move)
9017               (not (gnus-check-backend-function
9018                     'request-move-article gnus-newsgroup-name)))
9019          (error "The current group does not support article moving"))
9020         ((and (eq action 'crosspost)
9021               (not (gnus-check-backend-function
9022                     'request-replace-article gnus-newsgroup-name)))
9023          (error "The current group does not support article editing")))
9024   (let ((articles (gnus-summary-work-articles n))
9025         (prefix (if (gnus-check-backend-function
9026                      'request-move-article gnus-newsgroup-name)
9027                     (funcall gnus-move-group-prefix-function
9028                              gnus-newsgroup-name)
9029                   ""))
9030         (names '((move "Move" "Moving")
9031                  (copy "Copy" "Copying")
9032                  (crosspost "Crosspost" "Crossposting")))
9033         (copy-buf (save-excursion
9034                     (nnheader-set-temp-buffer " *copy article*")))
9035         art-group to-method new-xref article to-groups)
9036     (unless (assq action names)
9037       (error "Unknown action %s" action))
9038     ;; Read the newsgroup name.
9039     (when (and (not to-newsgroup)
9040                (not select-method))
9041       (if (and gnus-move-split-methods
9042                (not
9043                 (and (memq gnus-current-article articles)
9044                      (gnus-buffer-live-p gnus-original-article-buffer))))
9045           ;; When `gnus-move-split-methods' is non-nil, we have to
9046           ;; select an article to give `gnus-read-move-group-name' an
9047           ;; opportunity to suggest an appropriate default.  However,
9048           ;; we needn't render or mark the article.
9049           (let ((gnus-display-mime-function nil)
9050                 (gnus-article-prepare-hook nil)
9051                 (gnus-mark-article-hook nil))
9052             (gnus-summary-select-article nil nil nil (car articles))))
9053       (setq to-newsgroup
9054             (gnus-read-move-group-name
9055              (cadr (assq action names))
9056              (symbol-value (intern (format "gnus-current-%s-group" action)))
9057              articles prefix))
9058       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9059     (setq to-method (or select-method
9060                         (gnus-server-to-method
9061                          (gnus-group-method to-newsgroup))))
9062     ;; Check the method we are to move this article to...
9063     (unless (gnus-check-backend-function
9064              'request-accept-article (car to-method))
9065       (error "%s does not support article copying" (car to-method)))
9066     (unless (gnus-check-server to-method)
9067       (error "Can't open server %s" (car to-method)))
9068     (gnus-message 6 "%s to %s: %s..."
9069                   (caddr (assq action names))
9070                   (or (car select-method) to-newsgroup) articles)
9071     (while articles
9072       (setq article (pop articles))
9073       (setq
9074        art-group
9075        (cond
9076         ;; Move the article.
9077         ((eq action 'move)
9078          ;; Remove this article from future suppression.
9079          (gnus-dup-unsuppress-article article)
9080          (gnus-request-move-article
9081           article                       ; Article to move
9082           gnus-newsgroup-name           ; From newsgroup
9083           (nth 1 (gnus-find-method-for-group
9084                   gnus-newsgroup-name)) ; Server
9085           (list 'gnus-request-accept-article
9086                 to-newsgroup (list 'quote select-method)
9087                 (not articles) t)       ; Accept form
9088           (not articles)))              ; Only save nov last time
9089         ;; Copy the article.
9090         ((eq action 'copy)
9091          (save-excursion
9092            (set-buffer copy-buf)
9093            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9094              (save-restriction
9095                (nnheader-narrow-to-headers)
9096                (dolist (hdr gnus-copy-article-ignored-headers)
9097                  (message-remove-header hdr t)))
9098              (gnus-request-accept-article
9099               to-newsgroup select-method (not articles) t))))
9100         ;; Crosspost the article.
9101         ((eq action 'crosspost)
9102          (let ((xref (message-tokenize-header
9103                       (mail-header-xref (gnus-summary-article-header article))
9104                       " ")))
9105            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9106                                   ":" (number-to-string article)))
9107            (unless xref
9108              (setq xref (list (system-name))))
9109            (setq new-xref
9110                  (concat
9111                   (mapconcat 'identity
9112                              (delete "Xref:" (delete new-xref xref))
9113                              " ")
9114                   " " new-xref))
9115            (save-excursion
9116              (set-buffer copy-buf)
9117              ;; First put the article in the destination group.
9118              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9119              (when (consp (setq art-group
9120                                 (gnus-request-accept-article
9121                                  to-newsgroup select-method (not articles))))
9122                (setq new-xref (concat new-xref " " (car art-group)
9123                                       ":"
9124                                       (number-to-string (cdr art-group))))
9125                ;; Now we have the new Xrefs header, so we insert
9126                ;; it and replace the new article.
9127                (nnheader-replace-header "Xref" new-xref)
9128                (gnus-request-replace-article
9129                 (cdr art-group) to-newsgroup (current-buffer))
9130                art-group))))))
9131       (cond
9132        ((not art-group)
9133         (gnus-message 1 "Couldn't %s article %s: %s"
9134                       (cadr (assq action names)) article
9135                       (nnheader-get-report (car to-method))))
9136        ((eq art-group 'junk)
9137         (when (eq action 'move)
9138           (gnus-summary-mark-article article gnus-canceled-mark)
9139           (gnus-message 4 "Deleted article %s" article)
9140           ;; run the delete hook
9141           (run-hook-with-args 'gnus-summary-article-delete-hook
9142                               action
9143                               (gnus-data-header
9144                                (assoc article (gnus-data-list nil)))
9145                               gnus-newsgroup-name nil
9146                               select-method)))
9147        (t
9148         (let* ((pto-group (gnus-group-prefixed-name
9149                            (car art-group) to-method))
9150                (info (gnus-get-info pto-group))
9151                (to-group (gnus-info-group info))
9152                to-marks)
9153           ;; Update the group that has been moved to.
9154           (when (and info
9155                      (memq action '(move copy)))
9156             (unless (member to-group to-groups)
9157               (push to-group to-groups))
9158
9159             (unless (memq article gnus-newsgroup-unreads)
9160               (push 'read to-marks)
9161               (gnus-info-set-read
9162                info (gnus-add-to-range (gnus-info-read info)
9163                                        (list (cdr art-group)))))
9164
9165             ;; See whether the article is to be put in the cache.
9166             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9167                              gnus-article-mark-lists
9168                            (delete '(expirable . expire)
9169                                    (copy-sequence gnus-article-mark-lists))))
9170                   (to-article (cdr art-group)))
9171
9172               ;; Enter the article into the cache in the new group,
9173               ;; if that is required.
9174               (when gnus-use-cache
9175                 (gnus-cache-possibly-enter-article
9176                  to-group to-article
9177                  (memq article gnus-newsgroup-marked)
9178                  (memq article gnus-newsgroup-dormant)
9179                  (memq article gnus-newsgroup-unreads)))
9180
9181               (when gnus-preserve-marks
9182                 ;; Copy any marks over to the new group.
9183                 (when (and (equal to-group gnus-newsgroup-name)
9184                            (not (memq article gnus-newsgroup-unreads)))
9185                   ;; Mark this article as read in this group.
9186                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9187                   (setcdr (gnus-active to-group) to-article)
9188                   (setcdr gnus-newsgroup-active to-article))
9189
9190                 (while marks
9191                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9192                     (when (memq article (symbol-value
9193                                          (intern (format "gnus-newsgroup-%s"
9194                                                          (caar marks)))))
9195                       (push (cdar marks) to-marks)
9196                       ;; If the other group is the same as this group,
9197                       ;; then we have to add the mark to the list.
9198                       (when (equal to-group gnus-newsgroup-name)
9199                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9200                              (cons to-article
9201                                    (symbol-value
9202                                     (intern (format "gnus-newsgroup-%s"
9203                                                     (caar marks)))))))
9204                       ;; Copy the marks to other group.
9205                       (gnus-add-marked-articles
9206                        to-group (cdar marks) (list to-article) info)))
9207                   (setq marks (cdr marks)))
9208
9209                 (gnus-request-set-mark
9210                  to-group (list (list (list to-article) 'add to-marks))))
9211
9212               (gnus-dribble-enter
9213                (concat "(gnus-group-set-info '"
9214                        (gnus-prin1-to-string (gnus-get-info to-group))
9215                        ")"))))
9216
9217           ;; Update the Xref header in this article to point to
9218           ;; the new crossposted article we have just created.
9219           (when (eq action 'crosspost)
9220             (save-excursion
9221               (set-buffer copy-buf)
9222               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9223               (nnheader-replace-header "Xref" new-xref)
9224               (gnus-request-replace-article
9225                article gnus-newsgroup-name (current-buffer))))
9226
9227           ;; run the move/copy/crosspost/respool hook
9228           (run-hook-with-args 'gnus-summary-article-move-hook
9229                               action
9230                               (gnus-data-header
9231                                (assoc article (gnus-data-list nil)))
9232                               gnus-newsgroup-name
9233                               to-newsgroup
9234                               select-method))
9235
9236         ;;;!!!Why is this necessary?
9237         (set-buffer gnus-summary-buffer)
9238
9239         (gnus-summary-goto-subject article)
9240         (when (eq action 'move)
9241           (gnus-summary-mark-article article gnus-canceled-mark))))
9242       (gnus-summary-remove-process-mark article))
9243     ;; Re-activate all groups that have been moved to.
9244     (save-excursion
9245       (set-buffer gnus-group-buffer)
9246       (let ((gnus-group-marked to-groups))
9247         (gnus-group-get-new-news-this-group nil t)))
9248
9249     (gnus-kill-buffer copy-buf)
9250     (gnus-summary-position-point)
9251     (gnus-set-mode-line 'summary)))
9252
9253 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9254   "Copy the current article to some other group.
9255 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9256 When called interactively, if TO-NEWSGROUP is nil, use the value of
9257 the variable `gnus-move-split-methods' for finding a default target
9258 newsgroup.
9259 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9260 re-spool using this method."
9261   (interactive "P")
9262   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9263
9264 (defun gnus-summary-crosspost-article (&optional n)
9265   "Crosspost the current article to some other group."
9266   (interactive "P")
9267   (gnus-summary-move-article n nil nil 'crosspost))
9268
9269 (defcustom gnus-summary-respool-default-method nil
9270   "Default method type for respooling an article.
9271 If nil, use to the current newsgroup method."
9272   :type 'symbol
9273   :group 'gnus-summary-mail)
9274
9275 (defcustom gnus-summary-display-while-building nil
9276   "If non-nil, show and update the summary buffer as it's being built.
9277 If the value is t, update the buffer after every line is inserted.  If
9278 the value is an integer (N), update the display every N lines."
9279   :version "21.4"
9280   :group 'gnus-thread
9281   :type '(choice (const :tag "off" nil)
9282                  number
9283                  (const :tag "frequently" t)))
9284
9285 (defun gnus-summary-respool-article (&optional n method)
9286   "Respool the current article.
9287 The article will be squeezed through the mail spooling process again,
9288 which means that it will be put in some mail newsgroup or other
9289 depending on `nnmail-split-methods'.
9290 If N is a positive number, respool the N next articles.
9291 If N is a negative number, respool the N previous articles.
9292 If N is nil and any articles have been marked with the process mark,
9293 respool those articles instead.
9294
9295 Respooling can be done both from mail groups and \"real\" newsgroups.
9296 In the former case, the articles in question will be moved from the
9297 current group into whatever groups they are destined to.  In the
9298 latter case, they will be copied into the relevant groups."
9299   (interactive
9300    (list current-prefix-arg
9301          (let* ((methods (gnus-methods-using 'respool))
9302                 (methname
9303                  (symbol-name (or gnus-summary-respool-default-method
9304                                   (car (gnus-find-method-for-group
9305                                         gnus-newsgroup-name)))))
9306                 (method
9307                  (gnus-completing-read-with-default
9308                   methname "What backend do you want to use when respooling?"
9309                   methods nil t nil 'gnus-mail-method-history))
9310                 ms)
9311            (cond
9312             ((zerop (length (setq ms (gnus-servers-using-backend
9313                                       (intern method)))))
9314              (list (intern method) ""))
9315             ((= 1 (length ms))
9316              (car ms))
9317             (t
9318              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9319                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9320                            ms-alist))))))))
9321   (unless method
9322     (error "No method given for respooling"))
9323   (if (assoc (symbol-name
9324               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9325              (gnus-methods-using 'respool))
9326       (gnus-summary-move-article n nil method)
9327     (gnus-summary-copy-article n nil method)))
9328
9329 (defun gnus-summary-import-article (file &optional edit)
9330   "Import an arbitrary file into a mail newsgroup."
9331   (interactive "fImport file: \nP")
9332   (let ((group gnus-newsgroup-name)
9333         (now (current-time))
9334         atts lines group-art)
9335     (unless (gnus-check-backend-function 'request-accept-article group)
9336       (error "%s does not support article importing" group))
9337     (or (file-readable-p file)
9338         (not (file-regular-p file))
9339         (error "Can't read %s" file))
9340     (save-excursion
9341       (set-buffer (gnus-get-buffer-create " *import file*"))
9342       (erase-buffer)
9343       (nnheader-insert-file-contents file)
9344       (goto-char (point-min))
9345       (if (nnheader-article-p)
9346           (save-restriction
9347             (goto-char (point-min))
9348             (search-forward "\n\n" nil t)
9349             (narrow-to-region (point-min) (1- (point)))
9350             (goto-char (point-min))
9351             (unless (re-search-forward "^date:" nil t)
9352               (goto-char (point-max))
9353               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9354        ;; This doesn't look like an article, so we fudge some headers.
9355         (setq atts (file-attributes file)
9356               lines (count-lines (point-min) (point-max)))
9357         (insert "From: " (read-string "From: ") "\n"
9358                 "Subject: " (read-string "Subject: ") "\n"
9359                 "Date: " (message-make-date (nth 5 atts)) "\n"
9360                 "Message-ID: " (message-make-message-id) "\n"
9361                 "Lines: " (int-to-string lines) "\n"
9362                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9363       (setq group-art (gnus-request-accept-article group nil t))
9364       (kill-buffer (current-buffer)))
9365     (setq gnus-newsgroup-active (gnus-activate-group group))
9366     (forward-line 1)
9367     (gnus-summary-goto-article (cdr group-art) nil t)
9368     (when edit
9369       (gnus-summary-edit-article))))
9370
9371 (defun gnus-summary-create-article ()
9372   "Create an article in a mail newsgroup."
9373   (interactive)
9374   (let ((group gnus-newsgroup-name)
9375         (now (current-time))
9376         group-art)
9377     (unless (gnus-check-backend-function 'request-accept-article group)
9378       (error "%s does not support article importing" group))
9379     (save-excursion
9380       (set-buffer (gnus-get-buffer-create " *import file*"))
9381       (erase-buffer)
9382       (goto-char (point-min))
9383       ;; This doesn't look like an article, so we fudge some headers.
9384       (insert "From: " (read-string "From: ") "\n"
9385               "Subject: " (read-string "Subject: ") "\n"
9386               "Date: " (message-make-date now) "\n"
9387               "Message-ID: " (message-make-message-id) "\n")
9388       (setq group-art (gnus-request-accept-article group nil t))
9389       (kill-buffer (current-buffer)))
9390     (setq gnus-newsgroup-active (gnus-activate-group group))
9391     (forward-line 1)
9392     (gnus-summary-goto-article (cdr group-art) nil t)
9393     (gnus-summary-edit-article)))
9394
9395 (defun gnus-summary-article-posted-p ()
9396   "Say whether the current (mail) article is available from news as well.
9397 This will be the case if the article has both been mailed and posted."
9398   (interactive)
9399   (let ((id (mail-header-references (gnus-summary-article-header)))
9400         (gnus-override-method (car (gnus-refer-article-methods))))
9401     (if (gnus-request-head id "")
9402         (gnus-message 2 "The current message was found on %s"
9403                       gnus-override-method)
9404       (gnus-message 2 "The current message couldn't be found on %s"
9405                     gnus-override-method)
9406       nil)))
9407
9408 (defun gnus-summary-expire-articles (&optional now)
9409   "Expire all articles that are marked as expirable in the current group."
9410   (interactive)
9411   (when (and (not gnus-group-is-exiting-without-update-p)
9412              (gnus-check-backend-function
9413               'request-expire-articles gnus-newsgroup-name))
9414     ;; This backend supports expiry.
9415     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9416            (expirable (if total
9417                           (progn
9418                             ;; We need to update the info for
9419                             ;; this group for `gnus-list-of-read-articles'
9420                             ;; to give us the right answer.
9421                             (gnus-run-hooks 'gnus-exit-group-hook)
9422                             (gnus-summary-update-info)
9423                             (gnus-list-of-read-articles gnus-newsgroup-name))
9424                         (setq gnus-newsgroup-expirable
9425                               (sort gnus-newsgroup-expirable '<))))
9426            (expiry-wait (if now 'immediate
9427                           (gnus-group-find-parameter
9428                            gnus-newsgroup-name 'expiry-wait)))
9429            (nnmail-expiry-target
9430             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9431                 nnmail-expiry-target))
9432            es)
9433       (when expirable
9434         ;; There are expirable articles in this group, so we run them
9435         ;; through the expiry process.
9436         (gnus-message 6 "Expiring articles...")
9437         (unless (gnus-check-group gnus-newsgroup-name)
9438           (error "Can't open server for %s" gnus-newsgroup-name))
9439         ;; The list of articles that weren't expired is returned.
9440         (save-excursion
9441           (if expiry-wait
9442               (let ((nnmail-expiry-wait-function nil)
9443                     (nnmail-expiry-wait expiry-wait))
9444                 (setq es (gnus-request-expire-articles
9445                           expirable gnus-newsgroup-name)))
9446             (setq es (gnus-request-expire-articles
9447                       expirable gnus-newsgroup-name)))
9448           (unless total
9449             (setq gnus-newsgroup-expirable es))
9450           ;; We go through the old list of expirable, and mark all
9451           ;; really expired articles as nonexistent.
9452           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9453             (let ((gnus-use-cache nil))
9454               (dolist (article expirable)
9455                 (when (and (not (memq article es))
9456                            (gnus-data-find article))
9457                   (gnus-summary-mark-article article gnus-canceled-mark)
9458                   (run-hook-with-args 'gnus-summary-article-expire-hook
9459                                       'delete
9460                                       (gnus-data-header
9461                                        (assoc article (gnus-data-list nil)))
9462                                       gnus-newsgroup-name
9463                                       nil
9464                                       nil))))))
9465         (gnus-message 6 "Expiring articles...done")))))
9466
9467 (defun gnus-summary-expire-articles-now ()
9468   "Expunge all expirable articles in the current group.
9469 This means that *all* articles that are marked as expirable will be
9470 deleted forever, right now."
9471   (interactive)
9472   (or gnus-expert-user
9473       (gnus-yes-or-no-p
9474        "Are you really, really, really sure you want to delete all these messages? ")
9475       (error "Phew!"))
9476   (gnus-summary-expire-articles t))
9477
9478 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9479 (defun gnus-summary-delete-article (&optional n)
9480   "Delete the N next (mail) articles.
9481 This command actually deletes articles.  This is not a marking
9482 command.  The article will disappear forever from your life, never to
9483 return.
9484
9485 If N is negative, delete backwards.
9486 If N is nil and articles have been marked with the process mark,
9487 delete these instead.
9488
9489 If `gnus-novice-user' is non-nil you will be asked for
9490 confirmation before the articles are deleted."
9491   (interactive "P")
9492   (unless (gnus-check-backend-function 'request-expire-articles
9493                                        gnus-newsgroup-name)
9494     (error "The current newsgroup does not support article deletion"))
9495   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9496     (error "Couldn't open server"))
9497   ;; Compute the list of articles to delete.
9498   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9499         (nnmail-expiry-target 'delete)
9500         not-deleted)
9501     (if (and gnus-novice-user
9502              (not (gnus-yes-or-no-p
9503                    (format "Do you really want to delete %s forever? "
9504                            (if (> (length articles) 1)
9505                                (format "these %s articles" (length articles))
9506                              "this article")))))
9507         ()
9508       ;; Delete the articles.
9509       (setq not-deleted (gnus-request-expire-articles
9510                          articles gnus-newsgroup-name 'force))
9511       (while articles
9512         (gnus-summary-remove-process-mark (car articles))
9513         ;; The backend might not have been able to delete the article
9514         ;; after all.
9515         (unless (memq (car articles) not-deleted)
9516           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9517         (let* ((article (car articles))
9518                (ghead  (gnus-data-header
9519                                     (assoc article (gnus-data-list nil)))))
9520           (run-hook-with-args 'gnus-summary-article-delete-hook
9521                               'delete ghead gnus-newsgroup-name nil
9522                               nil))
9523         (setq articles (cdr articles)))
9524       (when not-deleted
9525         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9526     (gnus-summary-position-point)
9527     (gnus-set-mode-line 'summary)
9528     not-deleted))
9529
9530 (defun gnus-summary-edit-article (&optional arg)
9531   "Edit the current article.
9532 This will have permanent effect only in mail groups.
9533 If ARG is nil, edit the decoded articles.
9534 If ARG is 1, edit the raw articles.
9535 If ARG is 2, edit the raw articles even in read-only groups.
9536 If ARG is 3, edit the articles with the current handles.
9537 Otherwise, allow editing of articles even in read-only
9538 groups."
9539   (interactive "P")
9540   (let (force raw current-handles)
9541     (cond
9542      ((null arg))
9543      ((eq arg 1)
9544       (setq raw t))
9545      ((eq arg 2)
9546       (setq raw t
9547             force t))
9548      ((eq arg 3)
9549       (setq current-handles
9550             (and (gnus-buffer-live-p gnus-article-buffer)
9551                  (with-current-buffer gnus-article-buffer
9552                    (prog1
9553                        gnus-article-mime-handles
9554                      (setq gnus-article-mime-handles nil))))))
9555      (t
9556       (setq force t)))
9557     (when (and raw (not force)
9558                (member gnus-newsgroup-name '("nndraft:delayed"
9559                                              "nndraft:drafts"
9560                                              "nndraft:queue")))
9561       (error "Can't edit the raw article in group %s"
9562              gnus-newsgroup-name))
9563     (save-excursion
9564       (set-buffer gnus-summary-buffer)
9565       (let ((mail-parse-charset gnus-newsgroup-charset)
9566             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9567         (gnus-set-global-variables)
9568         (when (and (not force)
9569                    (gnus-group-read-only-p))
9570           (error "The current newsgroup does not support article editing"))
9571         (gnus-summary-show-article t)
9572         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9573           (with-current-buffer gnus-article-buffer
9574             (mm-enable-multibyte)))
9575         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9576             (setq raw t))
9577         (gnus-article-edit-article
9578          (if raw 'ignore
9579            `(lambda ()
9580               (let ((mbl mml-buffer-list))
9581                 (setq mml-buffer-list nil)
9582                 (mime-to-mml ,'current-handles)
9583                 (let ((mbl1 mml-buffer-list))
9584                   (setq mml-buffer-list mbl)
9585                   (set (make-local-variable 'mml-buffer-list) mbl1))
9586                 (gnus-make-local-hook 'kill-buffer-hook)
9587                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9588          `(lambda (no-highlight)
9589             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9590                   (message-options message-options)
9591                   (message-options-set-recipient)
9592                   (mail-parse-ignored-charsets
9593                    ',gnus-newsgroup-ignored-charsets))
9594               ,(if (not raw) '(progn
9595                                 (mml-to-mime)
9596                                 (mml-destroy-buffers)
9597                                 (remove-hook 'kill-buffer-hook
9598                                              'mml-destroy-buffers t)
9599                                 (kill-local-variable 'mml-buffer-list)))
9600               (gnus-summary-edit-article-done
9601                ,(or (mail-header-references gnus-current-headers) "")
9602                ,(gnus-group-read-only-p)
9603                ,gnus-summary-buffer no-highlight))))))))
9604
9605 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9606
9607 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9608                                                  no-highlight)
9609   "Make edits to the current article permanent."
9610   (interactive)
9611   (save-excursion
9612    ;; The buffer restriction contains the entire article if it exists.
9613     (when (article-goto-body)
9614       (let ((lines (count-lines (point) (point-max)))
9615             (length (- (point-max) (point)))
9616             (case-fold-search t)
9617             (body (copy-marker (point))))
9618         (goto-char (point-min))
9619         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9620           (delete-region (match-beginning 1) (match-end 1))
9621           (insert (number-to-string length)))
9622         (goto-char (point-min))
9623         (when (re-search-forward
9624                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9625           (delete-region (match-beginning 1) (match-end 1))
9626           (insert (number-to-string length)))
9627         (goto-char (point-min))
9628         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9629           (delete-region (match-beginning 1) (match-end 1))
9630           (insert (number-to-string lines))))))
9631   ;; Replace the article.
9632   (let ((buf (current-buffer)))
9633     (with-temp-buffer
9634       (insert-buffer-substring buf)
9635
9636       (if (and (not read-only)
9637                (not (gnus-request-replace-article
9638                      (cdr gnus-article-current) (car gnus-article-current)
9639                      (current-buffer) t)))
9640           (error "Couldn't replace article")
9641         ;; Update the summary buffer.
9642         (if (and references
9643                  (equal (message-tokenize-header references " ")
9644                         (message-tokenize-header
9645                          (or (message-fetch-field "references") "") " ")))
9646             ;; We only have to update this line.
9647             (save-excursion
9648               (save-restriction
9649                 (message-narrow-to-head)
9650                 (let ((head (buffer-string))
9651                       header)
9652                   (with-temp-buffer
9653                     (insert (format "211 %d Article retrieved.\n"
9654                                     (cdr gnus-article-current)))
9655                     (insert head)
9656                     (insert ".\n")
9657                     (let ((nntp-server-buffer (current-buffer)))
9658                       (setq header (car (gnus-get-newsgroup-headers
9659                                          nil t))))
9660                     (save-excursion
9661                       (set-buffer gnus-summary-buffer)
9662                       (gnus-data-set-header
9663                        (gnus-data-find (cdr gnus-article-current))
9664                        header)
9665                       (gnus-summary-update-article-line
9666                        (cdr gnus-article-current) header)
9667                       (if (gnus-summary-goto-subject
9668                            (cdr gnus-article-current) nil t)
9669                           (gnus-summary-update-secondary-mark
9670                            (cdr gnus-article-current))))))))
9671           ;; Update threads.
9672           (set-buffer (or buffer gnus-summary-buffer))
9673           (gnus-summary-update-article (cdr gnus-article-current))
9674           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9675               (gnus-summary-update-secondary-mark
9676                (cdr gnus-article-current))))
9677         ;; Prettify the article buffer again.
9678         (unless no-highlight
9679           (save-excursion
9680             (set-buffer gnus-article-buffer)
9681             ;;;!!! Fix this -- article should be rehighlighted.
9682             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9683             (set-buffer gnus-original-article-buffer)
9684             (gnus-request-article
9685              (cdr gnus-article-current)
9686              (car gnus-article-current) (current-buffer))))
9687         ;; Prettify the summary buffer line.
9688         (when (gnus-visual-p 'summary-highlight 'highlight)
9689           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9690
9691 (defun gnus-summary-edit-wash (key)
9692   "Perform editing command KEY in the article buffer."
9693   (interactive
9694    (list
9695     (progn
9696       (message "%s" (concat (this-command-keys) "- "))
9697       (read-char))))
9698   (message "")
9699   (gnus-summary-edit-article)
9700   (execute-kbd-macro (concat (this-command-keys) key))
9701   (gnus-article-edit-done))
9702
9703 ;;; Respooling
9704
9705 (defun gnus-summary-respool-query (&optional silent trace)
9706   "Query where the respool algorithm would put this article."
9707   (interactive)
9708   (let (gnus-mark-article-hook)
9709     (gnus-summary-select-article)
9710     (save-excursion
9711       (set-buffer gnus-original-article-buffer)
9712       (let ((groups (nnmail-article-group 'identity trace)))
9713         (unless silent
9714           (if groups
9715               (message "This message would go to %s"
9716                        (mapconcat 'car groups ", "))
9717             (message "This message would go to no groups"))
9718           groups)))))
9719
9720 (defun gnus-summary-respool-trace ()
9721   "Trace where the respool algorithm would put this article.
9722 Display a buffer showing all fancy splitting patterns which matched."
9723   (interactive)
9724   (gnus-summary-respool-query nil t))
9725
9726 ;; Summary marking commands.
9727
9728 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9729   "Mark articles which has the same subject as read, and then select the next.
9730 If UNMARK is positive, remove any kind of mark.
9731 If UNMARK is negative, tick articles."
9732   (interactive "P")
9733   (when unmark
9734     (setq unmark (prefix-numeric-value unmark)))
9735   (let ((count
9736          (gnus-summary-mark-same-subject
9737           (gnus-summary-article-subject) unmark)))
9738     ;; Select next unread article.  If auto-select-same mode, should
9739     ;; select the first unread article.
9740     (gnus-summary-next-article t (and gnus-auto-select-same
9741                                       (gnus-summary-article-subject)))
9742     (gnus-message 7 "%d article%s marked as %s"
9743                   count (if (= count 1) " is" "s are")
9744                   (if unmark "unread" "read"))))
9745
9746 (defun gnus-summary-kill-same-subject (&optional unmark)
9747   "Mark articles which has the same subject as read.
9748 If UNMARK is positive, remove any kind of mark.
9749 If UNMARK is negative, tick articles."
9750   (interactive "P")
9751   (when unmark
9752     (setq unmark (prefix-numeric-value unmark)))
9753   (let ((count
9754          (gnus-summary-mark-same-subject
9755           (gnus-summary-article-subject) unmark)))
9756     ;; If marked as read, go to next unread subject.
9757     (when (null unmark)
9758       ;; Go to next unread subject.
9759       (gnus-summary-next-subject 1 t))
9760     (gnus-message 7 "%d articles are marked as %s"
9761                   count (if unmark "unread" "read"))))
9762
9763 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9764   "Mark articles with same SUBJECT as read, and return marked number.
9765 If optional argument UNMARK is positive, remove any kinds of marks.
9766 If optional argument UNMARK is negative, mark articles as unread instead."
9767   (let ((count 1))
9768     (save-excursion
9769       (cond
9770        ((null unmark)                   ; Mark as read.
9771         (while (and
9772                 (progn
9773                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9774                   (gnus-summary-show-thread) t)
9775                 (gnus-summary-find-subject subject))
9776           (setq count (1+ count))))
9777        ((> unmark 0)                    ; Tick.
9778         (while (and
9779                 (progn
9780                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9781                   (gnus-summary-show-thread) t)
9782                 (gnus-summary-find-subject subject))
9783           (setq count (1+ count))))
9784        (t                               ; Mark as unread.
9785         (while (and
9786                 (progn
9787                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9788                   (gnus-summary-show-thread) t)
9789                 (gnus-summary-find-subject subject))
9790           (setq count (1+ count)))))
9791       (gnus-set-mode-line 'summary)
9792       ;; Return the number of marked articles.
9793       count)))
9794
9795 (defun gnus-summary-mark-as-processable (n &optional unmark)
9796   "Set the process mark on the next N articles.
9797 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9798 the process mark instead.  The difference between N and the actual
9799 number of articles marked is returned."
9800   (interactive "P")
9801   (if (and (null n) (gnus-region-active-p))
9802       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9803     (setq n (prefix-numeric-value n))
9804     (let ((backward (< n 0))
9805           (n (abs n)))
9806       (while (and
9807               (> n 0)
9808               (if unmark
9809                   (gnus-summary-remove-process-mark
9810                    (gnus-summary-article-number))
9811                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9812               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9813         (setq n (1- n)))
9814       (when (/= 0 n)
9815         (gnus-message 7 "No more articles"))
9816       (gnus-summary-recenter)
9817       (gnus-summary-position-point)
9818       n)))
9819
9820 (defun gnus-summary-unmark-as-processable (n)
9821   "Remove the process mark from the next N articles.
9822 If N is negative, unmark backward instead.  The difference between N and
9823 the actual number of articles unmarked is returned."
9824   (interactive "P")
9825   (gnus-summary-mark-as-processable n t))
9826
9827 (defun gnus-summary-unmark-all-processable ()
9828   "Remove the process mark from all articles."
9829   (interactive)
9830   (save-excursion
9831     (while gnus-newsgroup-processable
9832       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9833   (gnus-summary-position-point))
9834
9835 (defun gnus-summary-add-mark (article type)
9836   "Mark ARTICLE with a mark of TYPE."
9837   (let ((vtype (car (assq type gnus-article-mark-lists)))
9838         var)
9839     (if (not vtype)
9840         (error "No such mark type: %s" type)
9841       (setq var (intern (format "gnus-newsgroup-%s" type)))
9842       (set var (cons article (symbol-value var)))
9843       (if (memq type '(processable cached replied forwarded recent saved))
9844           (gnus-summary-update-secondary-mark article)
9845         ;;; !!! This is bogus.  We should find out what primary
9846         ;;; !!! mark we want to set.
9847         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9848
9849 (defun gnus-summary-mark-as-expirable (n)
9850   "Mark N articles forward as expirable.
9851 If N is negative, mark backward instead.  The difference between N and
9852 the actual number of articles marked is returned."
9853   (interactive "p")
9854   (gnus-summary-mark-forward n gnus-expirable-mark))
9855
9856 (defun gnus-summary-mark-as-spam (n)
9857   "Mark N articles forward as spam.
9858 If N is negative, mark backward instead.  The difference between N and
9859 the actual number of articles marked is returned."
9860   (interactive "p")
9861   (gnus-summary-mark-forward n gnus-spam-mark))
9862
9863 (defun gnus-summary-mark-article-as-replied (article)
9864   "Mark ARTICLE as replied to and update the summary line.
9865 ARTICLE can also be a list of articles."
9866   (interactive (list (gnus-summary-article-number)))
9867   (let ((articles (if (listp article) article (list article))))
9868     (dolist (article articles)
9869       (unless (numberp article)
9870         (error "%s is not a number" article))
9871       (push article gnus-newsgroup-replied)
9872       (let ((buffer-read-only nil))
9873         (when (gnus-summary-goto-subject article nil t)
9874           (gnus-summary-update-secondary-mark article))))))
9875
9876 (defun gnus-summary-mark-article-as-forwarded (article)
9877   "Mark ARTICLE as forwarded and update the summary line.
9878 ARTICLE can also be a list of articles."
9879   (let ((articles (if (listp article) article (list article))))
9880     (dolist (article articles)
9881       (push article gnus-newsgroup-forwarded)
9882       (let ((buffer-read-only nil))
9883         (when (gnus-summary-goto-subject article nil t)
9884           (gnus-summary-update-secondary-mark article))))))
9885
9886 (defun gnus-summary-set-bookmark (article)
9887   "Set a bookmark in current article."
9888   (interactive (list (gnus-summary-article-number)))
9889   (when (or (not (get-buffer gnus-article-buffer))
9890             (not gnus-current-article)
9891             (not gnus-article-current)
9892             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9893     (error "No current article selected"))
9894   ;; Remove old bookmark, if one exists.
9895   (gnus-pull article gnus-newsgroup-bookmarks)
9896   ;; Set the new bookmark, which is on the form
9897   ;; (article-number . line-number-in-body).
9898   (push
9899    (cons article
9900          (with-current-buffer gnus-article-buffer
9901            (count-lines
9902             (min (point)
9903                  (save-excursion
9904                    (article-goto-body)
9905                    (point)))
9906             (point))))
9907    gnus-newsgroup-bookmarks)
9908   (gnus-message 6 "A bookmark has been added to the current article."))
9909
9910 (defun gnus-summary-remove-bookmark (article)
9911   "Remove the bookmark from the current article."
9912   (interactive (list (gnus-summary-article-number)))
9913   ;; Remove old bookmark, if one exists.
9914   (if (not (assq article gnus-newsgroup-bookmarks))
9915       (gnus-message 6 "No bookmark in current article.")
9916     (gnus-pull article gnus-newsgroup-bookmarks)
9917     (gnus-message 6 "Removed bookmark.")))
9918
9919 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9920 (defun gnus-summary-mark-as-dormant (n)
9921   "Mark N articles forward as dormant.
9922 If N is negative, mark backward instead.  The difference between N and
9923 the actual number of articles marked is returned."
9924   (interactive "p")
9925   (gnus-summary-mark-forward n gnus-dormant-mark))
9926
9927 (defun gnus-summary-set-process-mark (article)
9928   "Set the process mark on ARTICLE and update the summary line."
9929   (setq gnus-newsgroup-processable
9930         (cons article
9931               (delq article gnus-newsgroup-processable)))
9932   (when (gnus-summary-goto-subject article)
9933     (gnus-summary-show-thread)
9934     (gnus-summary-goto-subject article)
9935     (gnus-summary-update-secondary-mark article)))
9936
9937 (defun gnus-summary-remove-process-mark (article)
9938   "Remove the process mark from ARTICLE and update the summary line."
9939   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9940   (when (gnus-summary-goto-subject article)
9941     (gnus-summary-show-thread)
9942     (gnus-summary-goto-subject article)
9943     (gnus-summary-update-secondary-mark article)))
9944
9945 (defun gnus-summary-set-saved-mark (article)
9946   "Set the process mark on ARTICLE and update the summary line."
9947   (push article gnus-newsgroup-saved)
9948   (when (gnus-summary-goto-subject article)
9949     (gnus-summary-update-secondary-mark article)))
9950
9951 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9952   "Mark N articles as read forwards.
9953 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9954 The difference between N and the actual number of articles marked is
9955 returned.
9956 If NO-EXPIRE, auto-expiry will be inhibited."
9957   (interactive "p")
9958   (gnus-summary-show-thread)
9959   (let ((backward (< n 0))
9960         (gnus-summary-goto-unread
9961          (and gnus-summary-goto-unread
9962               (not (eq gnus-summary-goto-unread 'never))
9963               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9964                                     gnus-ticked-mark gnus-dormant-mark)))))
9965         (n (abs n))
9966         (mark (or mark gnus-del-mark)))
9967     (while (and (> n 0)
9968                 (gnus-summary-mark-article nil mark no-expire)
9969                 (zerop (gnus-summary-next-subject
9970                         (if backward -1 1)
9971                         (and gnus-summary-goto-unread
9972                              (not (eq gnus-summary-goto-unread 'never)))
9973                         t)))
9974       (setq n (1- n)))
9975     (when (/= 0 n)
9976       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9977     (gnus-summary-recenter)
9978     (gnus-summary-position-point)
9979     (gnus-set-mode-line 'summary)
9980     n))
9981
9982 (defun gnus-summary-mark-article-as-read (mark)
9983   "Mark the current article quickly as read with MARK."
9984   (let ((article (gnus-summary-article-number)))
9985     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9986     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9987     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9988     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9989     (push (cons article mark) gnus-newsgroup-reads)
9990     ;; Possibly remove from cache, if that is used.
9991     (when gnus-use-cache
9992       (gnus-cache-enter-remove-article article))
9993     ;; Allow the backend to change the mark.
9994     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9995     ;; Check for auto-expiry.
9996     (when (and gnus-newsgroup-auto-expire
9997                (memq mark gnus-auto-expirable-marks))
9998       (setq mark gnus-expirable-mark)
9999       ;; Let the backend know about the mark change.
10000       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10001       (push article gnus-newsgroup-expirable))
10002     ;; Set the mark in the buffer.
10003     (gnus-summary-update-mark mark 'unread)
10004     t))
10005
10006 (defun gnus-summary-mark-article-as-unread (mark)
10007   "Mark the current article quickly as unread with MARK."
10008   (let* ((article (gnus-summary-article-number))
10009          (old-mark (gnus-summary-article-mark article)))
10010     ;; Allow the backend to change the mark.
10011     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10012     (if (eq mark old-mark)
10013         t
10014       (if (<= article 0)
10015           (progn
10016             (gnus-error 1 "Can't mark negative article numbers")
10017             nil)
10018         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10019         (setq gnus-newsgroup-spam-marked
10020               (delq article gnus-newsgroup-spam-marked))
10021         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10022         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10023         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10024         (cond ((= mark gnus-ticked-mark)
10025                (setq gnus-newsgroup-marked
10026                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10027                                               article)))
10028               ((= mark gnus-spam-mark)
10029                (setq gnus-newsgroup-spam-marked
10030                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10031                                               article)))
10032               ((= mark gnus-dormant-mark)
10033                (setq gnus-newsgroup-dormant
10034                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10035                                               article)))
10036               (t
10037                (setq gnus-newsgroup-unreads
10038                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10039                                               article))))
10040         (gnus-pull article gnus-newsgroup-reads)
10041
10042         ;; See whether the article is to be put in the cache.
10043         (and gnus-use-cache
10044              (vectorp (gnus-summary-article-header article))
10045              (save-excursion
10046                (gnus-cache-possibly-enter-article
10047                 gnus-newsgroup-name article
10048                 (= mark gnus-ticked-mark)
10049                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10050
10051         ;; Fix the mark.
10052         (gnus-summary-update-mark mark 'unread)
10053         t))))
10054
10055 (defun gnus-summary-mark-article (&optional article mark no-expire)
10056   "Mark ARTICLE with MARK.  MARK can be any character.
10057 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10058 `??' (dormant) and `?E' (expirable).
10059 If MARK is nil, then the default character `?r' is used.
10060 If ARTICLE is nil, then the article on the current line will be
10061 marked.
10062 If NO-EXPIRE, auto-expiry will be inhibited."
10063   ;; The mark might be a string.
10064   (when (stringp mark)
10065     (setq mark (aref mark 0)))
10066   ;; If no mark is given, then we check auto-expiring.
10067   (when (null mark)
10068     (setq mark gnus-del-mark))
10069   (when (and (not no-expire)
10070              gnus-newsgroup-auto-expire
10071              (memq mark gnus-auto-expirable-marks))
10072     (setq mark gnus-expirable-mark))
10073   (let ((article (or article (gnus-summary-article-number)))
10074         (old-mark (gnus-summary-article-mark article)))
10075     ;; Allow the backend to change the mark.
10076     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10077     (if (eq mark old-mark)
10078         t
10079       (unless article
10080         (error "No article on current line"))
10081       (if (not (if (or (= mark gnus-unread-mark)
10082                        (= mark gnus-ticked-mark)
10083                        (= mark gnus-spam-mark)
10084                        (= mark gnus-dormant-mark))
10085                    (gnus-mark-article-as-unread article mark)
10086                  (gnus-mark-article-as-read article mark)))
10087           t
10088         ;; See whether the article is to be put in the cache.
10089         (and gnus-use-cache
10090              (not (= mark gnus-canceled-mark))
10091              (vectorp (gnus-summary-article-header article))
10092              (save-excursion
10093                (gnus-cache-possibly-enter-article
10094                 gnus-newsgroup-name article
10095                 (= mark gnus-ticked-mark)
10096                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10097
10098         (when (gnus-summary-goto-subject article nil t)
10099           (let ((buffer-read-only nil))
10100             (gnus-summary-show-thread)
10101             ;; Fix the mark.
10102             (gnus-summary-update-mark mark 'unread)
10103             t))))))
10104
10105 (defun gnus-summary-update-secondary-mark (article)
10106   "Update the secondary (read, process, cache) mark."
10107   (gnus-summary-update-mark
10108    (cond ((memq article gnus-newsgroup-processable)
10109           gnus-process-mark)
10110          ((memq article gnus-newsgroup-cached)
10111           gnus-cached-mark)
10112          ((memq article gnus-newsgroup-replied)
10113           gnus-replied-mark)
10114          ((memq article gnus-newsgroup-forwarded)
10115           gnus-forwarded-mark)
10116          ((memq article gnus-newsgroup-saved)
10117           gnus-saved-mark)
10118          ((memq article gnus-newsgroup-recent)
10119           gnus-recent-mark)
10120          ((memq article gnus-newsgroup-unseen)
10121           gnus-unseen-mark)
10122          (t gnus-no-mark))
10123    'replied)
10124   (when (gnus-visual-p 'summary-highlight 'highlight)
10125     (gnus-run-hooks 'gnus-summary-update-hook))
10126   t)
10127
10128 (defun gnus-summary-update-download-mark (article)
10129   "Update the download mark."
10130   (gnus-summary-update-mark
10131    (cond ((memq article gnus-newsgroup-undownloaded)
10132           gnus-undownloaded-mark)
10133          (gnus-newsgroup-agentized
10134           gnus-downloaded-mark)
10135          (t
10136           gnus-no-mark))
10137    'download)
10138   (gnus-summary-update-line t)
10139   t)
10140
10141 (defun gnus-summary-update-mark (mark type)
10142   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10143         (buffer-read-only nil))
10144     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10145     (when forward
10146       (when (looking-at "\r")
10147         (incf forward))
10148       (when (<= (+ forward (point)) (point-max))
10149         ;; Go to the right position on the line.
10150         (goto-char (+ forward (point)))
10151         ;; Replace the old mark with the new mark.
10152         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10153         ;; Optionally update the marks by some user rule.
10154         (when (eq type 'unread)
10155           (gnus-data-set-mark
10156            (gnus-data-find (gnus-summary-article-number)) mark)
10157           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10158
10159 (defun gnus-mark-article-as-read (article &optional mark)
10160   "Enter ARTICLE in the pertinent lists and remove it from others."
10161   ;; Make the article expirable.
10162   (let ((mark (or mark gnus-del-mark)))
10163     (setq gnus-newsgroup-expirable
10164           (if (= mark gnus-expirable-mark)
10165               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10166             (delq article gnus-newsgroup-expirable)))
10167     ;; Remove from unread and marked lists.
10168     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10169     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10170     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10171     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10172     (push (cons article mark) gnus-newsgroup-reads)
10173     ;; Possibly remove from cache, if that is used.
10174     (when gnus-use-cache
10175       (gnus-cache-enter-remove-article article))
10176     t))
10177
10178 (defun gnus-mark-article-as-unread (article &optional mark)
10179   "Enter ARTICLE in the pertinent lists and remove it from others."
10180   (let ((mark (or mark gnus-ticked-mark)))
10181     (if (<= article 0)
10182         (progn
10183           (gnus-error 1 "Can't mark negative article numbers")
10184           nil)
10185       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10186             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10187             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10188             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10189             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10190
10191       ;; Unsuppress duplicates?
10192       (when gnus-suppress-duplicates
10193         (gnus-dup-unsuppress-article article))
10194
10195       (cond ((= mark gnus-ticked-mark)
10196              (setq gnus-newsgroup-marked
10197                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10198             ((= mark gnus-spam-mark)
10199              (setq gnus-newsgroup-spam-marked
10200                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10201                                             article)))
10202             ((= mark gnus-dormant-mark)
10203              (setq gnus-newsgroup-dormant
10204                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10205             (t
10206              (setq gnus-newsgroup-unreads
10207                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10208       (gnus-pull article gnus-newsgroup-reads)
10209       t)))
10210
10211 (defalias 'gnus-summary-mark-as-unread-forward
10212   'gnus-summary-tick-article-forward)
10213 (make-obsolete 'gnus-summary-mark-as-unread-forward
10214                'gnus-summary-tick-article-forward)
10215 (defun gnus-summary-tick-article-forward (n)
10216   "Tick N articles forwards.
10217 If N is negative, tick backwards instead.
10218 The difference between N and the number of articles ticked is returned."
10219   (interactive "p")
10220   (gnus-summary-mark-forward n gnus-ticked-mark))
10221
10222 (defalias 'gnus-summary-mark-as-unread-backward
10223   'gnus-summary-tick-article-backward)
10224 (make-obsolete 'gnus-summary-mark-as-unread-backward
10225                'gnus-summary-tick-article-backward)
10226 (defun gnus-summary-tick-article-backward (n)
10227   "Tick N articles backwards.
10228 The difference between N and the number of articles ticked is returned."
10229   (interactive "p")
10230   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10231
10232 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10233 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10234 (defun gnus-summary-tick-article (&optional article clear-mark)
10235   "Mark current article as unread.
10236 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10237 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10238   (interactive)
10239   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10240                                        gnus-ticked-mark)))
10241
10242 (defun gnus-summary-mark-as-read-forward (n)
10243   "Mark N articles as read forwards.
10244 If N is negative, mark backwards instead.
10245 The difference between N and the actual number of articles marked is
10246 returned."
10247   (interactive "p")
10248   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10249
10250 (defun gnus-summary-mark-as-read-backward (n)
10251   "Mark the N articles as read backwards.
10252 The difference between N and the actual number of articles marked is
10253 returned."
10254   (interactive "p")
10255   (gnus-summary-mark-forward
10256    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10257
10258 (defun gnus-summary-mark-as-read (&optional article mark)
10259   "Mark current article as read.
10260 ARTICLE specifies the article to be marked as read.
10261 MARK specifies a string to be inserted at the beginning of the line."
10262   (gnus-summary-mark-article article mark))
10263
10264 (defun gnus-summary-clear-mark-forward (n)
10265   "Clear marks from N articles forward.
10266 If N is negative, clear backward instead.
10267 The difference between N and the number of marks cleared is returned."
10268   (interactive "p")
10269   (gnus-summary-mark-forward n gnus-unread-mark))
10270
10271 (defun gnus-summary-clear-mark-backward (n)
10272   "Clear marks from N articles backward.
10273 The difference between N and the number of marks cleared is returned."
10274   (interactive "p")
10275   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10276
10277 (defun gnus-summary-mark-unread-as-read ()
10278   "Intended to be used by `gnus-summary-mark-article-hook'."
10279   (when (memq gnus-current-article gnus-newsgroup-unreads)
10280     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10281
10282 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10283   "Intended to be used by `gnus-summary-mark-article-hook'."
10284   (let ((mark (gnus-summary-article-mark)))
10285     (when (or (gnus-unread-mark-p mark)
10286               (gnus-read-mark-p mark))
10287       (gnus-summary-mark-article gnus-current-article
10288                                  (or new-mark gnus-read-mark)))))
10289
10290 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10291   "Intended to be used by `gnus-summary-mark-article-hook'."
10292   (let ((mark (gnus-summary-article-mark)))
10293     (when (or (gnus-unread-mark-p mark)
10294               (gnus-read-mark-p mark))
10295       (gnus-summary-mark-article (gnus-summary-article-number)
10296                                  (or new-mark gnus-read-mark)))))
10297
10298 (defun gnus-summary-mark-unread-as-ticked ()
10299   "Intended to be used by `gnus-summary-mark-article-hook'."
10300   (when (memq gnus-current-article gnus-newsgroup-unreads)
10301     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10302
10303 (defun gnus-summary-mark-region-as-read (point mark all)
10304   "Mark all unread articles between point and mark as read.
10305 If given a prefix, mark all articles between point and mark as read,
10306 even ticked and dormant ones."
10307   (interactive "r\nP")
10308   (save-excursion
10309     (let (article)
10310       (goto-char point)
10311       (beginning-of-line)
10312       (while (and
10313               (< (point) mark)
10314               (progn
10315                 (when (or all
10316                           (memq (setq article (gnus-summary-article-number))
10317                                 gnus-newsgroup-unreads))
10318                   (gnus-summary-mark-article article gnus-del-mark))
10319                 t)
10320               (gnus-summary-find-next))))))
10321
10322 (defun gnus-summary-mark-below (score mark)
10323   "Mark articles with score less than SCORE with MARK."
10324   (interactive "P\ncMark: ")
10325   (setq score (if score
10326                   (prefix-numeric-value score)
10327                 (or gnus-summary-default-score 0)))
10328   (save-excursion
10329     (set-buffer gnus-summary-buffer)
10330     (goto-char (point-min))
10331     (while
10332         (progn
10333           (and (< (gnus-summary-article-score) score)
10334                (gnus-summary-mark-article nil mark))
10335           (gnus-summary-find-next)))))
10336
10337 (defun gnus-summary-kill-below (&optional score)
10338   "Mark articles with score below SCORE as read."
10339   (interactive "P")
10340   (gnus-summary-mark-below score gnus-killed-mark))
10341
10342 (defun gnus-summary-clear-above (&optional score)
10343   "Clear all marks from articles with score above SCORE."
10344   (interactive "P")
10345   (gnus-summary-mark-above score gnus-unread-mark))
10346
10347 (defun gnus-summary-tick-above (&optional score)
10348   "Tick all articles with score above SCORE."
10349   (interactive "P")
10350   (gnus-summary-mark-above score gnus-ticked-mark))
10351
10352 (defun gnus-summary-mark-above (score mark)
10353   "Mark articles with score over SCORE with MARK."
10354   (interactive "P\ncMark: ")
10355   (setq score (if score
10356                   (prefix-numeric-value score)
10357                 (or gnus-summary-default-score 0)))
10358   (save-excursion
10359     (set-buffer gnus-summary-buffer)
10360     (goto-char (point-min))
10361     (while (and (progn
10362                   (when (> (gnus-summary-article-score) score)
10363                     (gnus-summary-mark-article nil mark))
10364                   t)
10365                 (gnus-summary-find-next)))))
10366
10367 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10368 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10369 (defun gnus-summary-limit-include-expunged (&optional no-error)
10370   "Display all the hidden articles that were expunged for low scores."
10371   (interactive)
10372   (let ((buffer-read-only nil))
10373     (let ((scored gnus-newsgroup-scored)
10374           headers h)
10375       (while scored
10376         (unless (gnus-summary-article-header (caar scored))
10377           (and (setq h (gnus-number-to-header (caar scored)))
10378                (< (cdar scored) gnus-summary-expunge-below)
10379                (push h headers)))
10380         (setq scored (cdr scored)))
10381       (if (not headers)
10382           (when (not no-error)
10383             (error "No expunged articles hidden"))
10384         (goto-char (point-min))
10385         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10386         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10387         (mapcar (lambda (x) (push (mail-header-number x)
10388                                   gnus-newsgroup-limit))
10389                 headers)
10390         (gnus-summary-prepare-unthreaded (nreverse headers))
10391         (goto-char (point-min))
10392         (gnus-summary-position-point)
10393         t))))
10394
10395 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10396   "Mark all unread articles in this newsgroup as read.
10397 If prefix argument ALL is non-nil, ticked and dormant articles will
10398 also be marked as read.
10399 If QUIETLY is non-nil, no questions will be asked.
10400
10401 If TO-HERE is non-nil, it should be a point in the buffer.  All
10402 articles before (after, if REVERSE is set) this point will be marked
10403 as read.
10404
10405 Note that this function will only catch up the unread article
10406 in the current summary buffer limitation.
10407
10408 The number of articles marked as read is returned."
10409   (interactive "P")
10410   (prog1
10411       (save-excursion
10412         (when (or quietly
10413                   (not gnus-interactive-catchup) ;Without confirmation?
10414                   gnus-expert-user
10415                   (gnus-y-or-n-p
10416                    (if all
10417                        "Mark absolutely all articles as read? "
10418                      "Mark all unread articles as read? ")))
10419           (if (and not-mark
10420                    (not gnus-newsgroup-adaptive)
10421                    (not gnus-newsgroup-auto-expire)
10422                    (not gnus-suppress-duplicates)
10423                    (or (not gnus-use-cache)
10424                        (eq gnus-use-cache 'passive)))
10425               (progn
10426                 (when all
10427                   (setq gnus-newsgroup-marked nil
10428                         gnus-newsgroup-spam-marked nil
10429                         gnus-newsgroup-dormant nil))
10430                 (setq gnus-newsgroup-unreads
10431                       (gnus-sorted-nunion
10432                        (gnus-intersection gnus-newsgroup-unreads
10433                                           gnus-newsgroup-downloadable)
10434                        gnus-newsgroup-unfetched)))
10435             ;; We actually mark all articles as canceled, which we
10436             ;; have to do when using auto-expiry or adaptive scoring.
10437             (gnus-summary-show-all-threads)
10438             (if (and to-here reverse)
10439                 (progn
10440                   (goto-char to-here)
10441                   (gnus-summary-mark-current-read-and-unread-as-read
10442                    gnus-catchup-mark)
10443                   (while (gnus-summary-find-next (not all))
10444                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10445               (when (gnus-summary-first-subject (not all))
10446                 (while (and
10447                         (if to-here (< (point) to-here) t)
10448                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10449                         (gnus-summary-find-next (not all))))))
10450             (gnus-set-mode-line 'summary))
10451           t))
10452     (gnus-summary-position-point)))
10453
10454 (defun gnus-summary-catchup-to-here (&optional all)
10455   "Mark all unticked articles before the current one as read.
10456 If ALL is non-nil, also mark ticked and dormant articles as read."
10457   (interactive "P")
10458   (save-excursion
10459     (gnus-save-hidden-threads
10460       (let ((beg (point)))
10461         ;; We check that there are unread articles.
10462         (when (or all (gnus-summary-find-prev))
10463           (gnus-summary-catchup all t beg)))))
10464   (gnus-summary-position-point))
10465
10466 (defun gnus-summary-catchup-from-here (&optional all)
10467   "Mark all unticked articles after (and including) the current one as read.
10468 If ALL is non-nil, also mark ticked and dormant articles as read."
10469   (interactive "P")
10470   (save-excursion
10471     (gnus-save-hidden-threads
10472       (let ((beg (point)))
10473         ;; We check that there are unread articles.
10474         (when (or all (gnus-summary-find-next))
10475           (gnus-summary-catchup all t beg nil t)))))
10476   (gnus-summary-position-point))
10477
10478 (defun gnus-summary-catchup-all (&optional quietly)
10479   "Mark all articles in this newsgroup as read.
10480 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10481 instead, which marks only unread articles as read."
10482   (interactive "P")
10483   (gnus-summary-catchup t quietly))
10484
10485 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10486   "Mark all unread articles in this group as read, then exit.
10487 If prefix argument ALL is non-nil, all articles are marked as read.
10488 If QUIETLY is non-nil, no questions will be asked."
10489   (interactive "P")
10490   (when (gnus-summary-catchup all quietly nil 'fast)
10491     ;; Select next newsgroup or exit.
10492     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10493              (eq gnus-auto-select-next 'quietly))
10494         (gnus-summary-next-group nil)
10495       (gnus-summary-exit))))
10496
10497 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10498   "Mark all articles in this newsgroup as read, and then exit.
10499 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10500 instead, which marks only unread articles as read."
10501   (interactive "P")
10502   (gnus-summary-catchup-and-exit t quietly))
10503
10504 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10505   "Mark all articles in this group as read and select the next group.
10506 If given a prefix, mark all articles, unread as well as ticked, as
10507 read."
10508   (interactive "P")
10509   (save-excursion
10510     (gnus-summary-catchup all))
10511   (gnus-summary-next-group))
10512
10513 ;;;
10514 ;;; with article
10515 ;;;
10516
10517 (defmacro gnus-with-article (article &rest forms)
10518   "Select ARTICLE and perform FORMS in the original article buffer.
10519 Then replace the article with the result."
10520   `(progn
10521      ;; We don't want the article to be marked as read.
10522      (let (gnus-mark-article-hook)
10523        (gnus-summary-select-article t t nil ,article))
10524      (set-buffer gnus-original-article-buffer)
10525      ,@forms
10526      (if (not (gnus-check-backend-function
10527                'request-replace-article (car gnus-article-current)))
10528          (gnus-message 5 "Read-only group; not replacing")
10529        (unless (gnus-request-replace-article
10530                 ,article (car gnus-article-current)
10531                 (current-buffer) t)
10532          (error "Couldn't replace article")))
10533      ;; The cache and backlog have to be flushed somewhat.
10534      (when gnus-keep-backlog
10535        (gnus-backlog-remove-article
10536         (car gnus-article-current) (cdr gnus-article-current)))
10537      (when gnus-use-cache
10538        (gnus-cache-update-article
10539         (car gnus-article-current) (cdr gnus-article-current)))))
10540
10541 (put 'gnus-with-article 'lisp-indent-function 1)
10542 (put 'gnus-with-article 'edebug-form-spec '(form body))
10543
10544 ;; Thread-based commands.
10545
10546 (defun gnus-summary-articles-in-thread (&optional article)
10547   "Return a list of all articles in the current thread.
10548 If ARTICLE is non-nil, return all articles in the thread that starts
10549 with that article."
10550   (let* ((article (or article (gnus-summary-article-number)))
10551          (data (gnus-data-find-list article))
10552          (top-level (gnus-data-level (car data)))
10553          (top-subject
10554           (cond ((null gnus-thread-operation-ignore-subject)
10555                  (gnus-simplify-subject-re
10556                   (mail-header-subject (gnus-data-header (car data)))))
10557                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10558                  (gnus-simplify-subject-fuzzy
10559                   (mail-header-subject (gnus-data-header (car data)))))
10560                 (t nil)))
10561          (end-point (save-excursion
10562                       (if (gnus-summary-go-to-next-thread)
10563                           (point) (point-max))))
10564          articles)
10565     (while (and data
10566                 (< (gnus-data-pos (car data)) end-point))
10567       (when (or (not top-subject)
10568                 (string= top-subject
10569                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10570                              (gnus-simplify-subject-fuzzy
10571                               (mail-header-subject
10572                                (gnus-data-header (car data))))
10573                            (gnus-simplify-subject-re
10574                             (mail-header-subject
10575                              (gnus-data-header (car data)))))))
10576         (push (gnus-data-number (car data)) articles))
10577       (unless (and (setq data (cdr data))
10578                    (> (gnus-data-level (car data)) top-level))
10579         (setq data nil)))
10580     ;; Return the list of articles.
10581     (nreverse articles)))
10582
10583 (defun gnus-summary-rethread-current ()
10584   "Rethread the thread the current article is part of."
10585   (interactive)
10586   (let* ((gnus-show-threads t)
10587          (article (gnus-summary-article-number))
10588          (id (mail-header-id (gnus-summary-article-header)))
10589          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10590     (unless id
10591       (error "No article on the current line"))
10592     (gnus-rebuild-thread id)
10593     (gnus-summary-goto-subject article)))
10594
10595 (defun gnus-summary-reparent-thread ()
10596   "Make the current article child of the marked (or previous) article.
10597
10598 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10599 is non-nil or the Subject: of both articles are the same."
10600   (interactive)
10601   (unless (not (gnus-group-read-only-p))
10602     (error "The current newsgroup does not support article editing"))
10603   (unless (<= (length gnus-newsgroup-processable) 1)
10604     (error "No more than one article may be marked"))
10605   (save-window-excursion
10606     (let ((gnus-article-buffer " *reparent*")
10607           (current-article (gnus-summary-article-number))
10608           ;; First grab the marked article, otherwise one line up.
10609           (parent-article (if (not (null gnus-newsgroup-processable))
10610                               (car gnus-newsgroup-processable)
10611                             (save-excursion
10612                               (if (eq (forward-line -1) 0)
10613                                   (gnus-summary-article-number)
10614                                 (error "Beginning of summary buffer"))))))
10615       (unless (not (eq current-article parent-article))
10616         (error "An article may not be self-referential"))
10617       (let ((message-id (mail-header-id
10618                          (gnus-summary-article-header parent-article))))
10619         (unless (and message-id (not (equal message-id "")))
10620           (error "No message-id in desired parent"))
10621         (gnus-with-article current-article
10622           (save-restriction
10623             (goto-char (point-min))
10624             (message-narrow-to-head)
10625             (if (re-search-forward "^References: " nil t)
10626                 (progn
10627                   (re-search-forward "^[^ \t]" nil t)
10628                   (forward-line -1)
10629                   (end-of-line)
10630                   (insert " " message-id))
10631               (insert "References: " message-id "\n"))))
10632         (set-buffer gnus-summary-buffer)
10633         (gnus-summary-unmark-all-processable)
10634         (gnus-summary-update-article current-article)
10635         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10636             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10637         (gnus-summary-rethread-current)
10638         (gnus-message 3 "Article %d is now the child of article %d"
10639                       current-article parent-article)))))
10640
10641 (defun gnus-summary-toggle-threads (&optional arg)
10642   "Toggle showing conversation threads.
10643 If ARG is positive number, turn showing conversation threads on."
10644   (interactive "P")
10645   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10646     (setq gnus-show-threads
10647           (if (null arg) (not gnus-show-threads)
10648             (> (prefix-numeric-value arg) 0)))
10649     (gnus-summary-prepare)
10650     (gnus-summary-goto-subject current)
10651     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10652     (gnus-summary-position-point)))
10653
10654 (defun gnus-summary-show-all-threads ()
10655   "Show all threads."
10656   (interactive)
10657   (save-excursion
10658     (let ((buffer-read-only nil))
10659       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10660   (gnus-summary-position-point))
10661
10662 (defun gnus-summary-show-thread ()
10663   "Show thread subtrees.
10664 Returns nil if no thread was there to be shown."
10665   (interactive)
10666   (let ((buffer-read-only nil)
10667         (orig (point))
10668         (end (point-at-eol))
10669         ;; Leave point at bol
10670         (beg (progn (beginning-of-line) (point))))
10671     (prog1
10672         ;; Any hidden lines here?
10673         (search-forward "\r" end t)
10674       (subst-char-in-region beg end ?\^M ?\n t)
10675       (goto-char orig)
10676       (gnus-summary-position-point))))
10677
10678 (defun gnus-summary-maybe-hide-threads ()
10679   "If requested, hide the threads that should be hidden."
10680   (when (and gnus-show-threads
10681              gnus-thread-hide-subtree)
10682     (gnus-summary-hide-all-threads
10683      (if (or (consp gnus-thread-hide-subtree)
10684              (functionp gnus-thread-hide-subtree))
10685          (gnus-make-predicate gnus-thread-hide-subtree)
10686        nil))))
10687
10688 ;;; Hiding predicates.
10689
10690 (defun gnus-article-unread-p (header)
10691   (memq (mail-header-number header) gnus-newsgroup-unreads))
10692
10693 (defun gnus-article-unseen-p (header)
10694   (memq (mail-header-number header) gnus-newsgroup-unseen))
10695
10696 (defun gnus-map-articles (predicate articles)
10697   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10698   (apply 'gnus-or (mapcar predicate
10699                           (mapcar 'gnus-summary-article-header articles))))
10700
10701 (defun gnus-summary-hide-all-threads (&optional predicate)
10702   "Hide all thread subtrees.
10703 If PREDICATE is supplied, threads that satisfy this predicate
10704 will not be hidden."
10705   (interactive)
10706   (save-excursion
10707     (goto-char (point-min))
10708     (let ((end nil))
10709       (while (not end)
10710         (when (or (not predicate)
10711                   (gnus-map-articles
10712                    predicate (gnus-summary-article-children)))
10713             (gnus-summary-hide-thread))
10714         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10715   (gnus-summary-position-point))
10716
10717 (defun gnus-summary-hide-thread ()
10718   "Hide thread subtrees.
10719 If PREDICATE is supplied, threads that satisfy this predicate
10720 will not be hidden.
10721 Returns nil if no threads were there to be hidden."
10722   (interactive)
10723   (let ((buffer-read-only nil)
10724         (start (point))
10725         (article (gnus-summary-article-number)))
10726     (goto-char start)
10727     ;; Go forward until either the buffer ends or the subthread
10728     ;; ends.
10729     (when (and (not (eobp))
10730                (or (zerop (gnus-summary-next-thread 1 t))
10731                    (goto-char (point-max))))
10732       (prog1
10733           (if (and (> (point) start)
10734                    (search-backward "\n" start t))
10735               (progn
10736                 (subst-char-in-region start (point) ?\n ?\^M)
10737                 (gnus-summary-goto-subject article))
10738             (goto-char start)
10739             nil)))))
10740
10741 (defun gnus-summary-go-to-next-thread (&optional previous)
10742   "Go to the same level (or less) next thread.
10743 If PREVIOUS is non-nil, go to previous thread instead.
10744 Return the article number moved to, or nil if moving was impossible."
10745   (let ((level (gnus-summary-thread-level))
10746         (way (if previous -1 1))
10747         (beg (point)))
10748     (forward-line way)
10749     (while (and (not (eobp))
10750                 (< level (gnus-summary-thread-level)))
10751       (forward-line way))
10752     (if (eobp)
10753         (progn
10754           (goto-char beg)
10755           nil)
10756       (setq beg (point))
10757       (prog1
10758           (gnus-summary-article-number)
10759         (goto-char beg)))))
10760
10761 (defun gnus-summary-next-thread (n &optional silent)
10762   "Go to the same level next N'th thread.
10763 If N is negative, search backward instead.
10764 Returns the difference between N and the number of skips actually
10765 done.
10766
10767 If SILENT, don't output messages."
10768   (interactive "p")
10769   (let ((backward (< n 0))
10770         (n (abs n)))
10771     (while (and (> n 0)
10772                 (gnus-summary-go-to-next-thread backward))
10773       (decf n))
10774     (unless silent
10775       (gnus-summary-position-point))
10776     (when (and (not silent) (/= 0 n))
10777       (gnus-message 7 "No more threads"))
10778     n))
10779
10780 (defun gnus-summary-prev-thread (n)
10781   "Go to the same level previous N'th thread.
10782 Returns the difference between N and the number of skips actually
10783 done."
10784   (interactive "p")
10785   (gnus-summary-next-thread (- n)))
10786
10787 (defun gnus-summary-go-down-thread ()
10788   "Go down one level in the current thread."
10789   (let ((children (gnus-summary-article-children)))
10790     (when children
10791       (gnus-summary-goto-subject (car children)))))
10792
10793 (defun gnus-summary-go-up-thread ()
10794   "Go up one level in the current thread."
10795   (let ((parent (gnus-summary-article-parent)))
10796     (when parent
10797       (gnus-summary-goto-subject parent))))
10798
10799 (defun gnus-summary-down-thread (n)
10800   "Go down thread N steps.
10801 If N is negative, go up instead.
10802 Returns the difference between N and how many steps down that were
10803 taken."
10804   (interactive "p")
10805   (let ((up (< n 0))
10806         (n (abs n)))
10807     (while (and (> n 0)
10808                 (if up (gnus-summary-go-up-thread)
10809                   (gnus-summary-go-down-thread)))
10810       (setq n (1- n)))
10811     (gnus-summary-position-point)
10812     (when (/= 0 n)
10813       (gnus-message 7 "Can't go further"))
10814     n))
10815
10816 (defun gnus-summary-up-thread (n)
10817   "Go up thread N steps.
10818 If N is negative, go down instead.
10819 Returns the difference between N and how many steps down that were
10820 taken."
10821   (interactive "p")
10822   (gnus-summary-down-thread (- n)))
10823
10824 (defun gnus-summary-top-thread ()
10825   "Go to the top of the thread."
10826   (interactive)
10827   (while (gnus-summary-go-up-thread))
10828   (gnus-summary-article-number))
10829
10830 (defun gnus-summary-kill-thread (&optional unmark)
10831   "Mark articles under current thread as read.
10832 If the prefix argument is positive, remove any kinds of marks.
10833 If the prefix argument is negative, tick articles instead."
10834   (interactive "P")
10835   (when unmark
10836     (setq unmark (prefix-numeric-value unmark)))
10837   (let ((articles (gnus-summary-articles-in-thread)))
10838     (save-excursion
10839       ;; Expand the thread.
10840       (gnus-summary-show-thread)
10841       ;; Mark all the articles.
10842       (while articles
10843         (gnus-summary-goto-subject (car articles))
10844         (cond ((null unmark)
10845                (gnus-summary-mark-article-as-read gnus-killed-mark))
10846               ((> unmark 0)
10847                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10848               (t
10849                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10850         (setq articles (cdr articles))))
10851     ;; Hide killed subtrees.
10852     (and (null unmark)
10853          gnus-thread-hide-killed
10854          (gnus-summary-hide-thread))
10855     ;; If marked as read, go to next unread subject.
10856     (when (null unmark)
10857       ;; Go to next unread subject.
10858       (gnus-summary-next-subject 1 t)))
10859   (gnus-set-mode-line 'summary))
10860
10861 ;; Summary sorting commands
10862
10863 (defun gnus-summary-sort-by-number (&optional reverse)
10864   "Sort the summary buffer by article number.
10865 Argument REVERSE means reverse order."
10866   (interactive "P")
10867   (gnus-summary-sort 'number reverse))
10868
10869 (defun gnus-summary-sort-by-random (&optional reverse)
10870   "Randomize the order in the summary buffer.
10871 Argument REVERSE means to randomize in reverse order."
10872   (interactive "P")
10873   (gnus-summary-sort 'random reverse))
10874
10875 (defun gnus-summary-sort-by-author (&optional reverse)
10876   "Sort the summary buffer by author name alphabetically.
10877 If `case-fold-search' is non-nil, case of letters is ignored.
10878 Argument REVERSE means reverse order."
10879   (interactive "P")
10880   (gnus-summary-sort 'author reverse))
10881
10882 (defun gnus-summary-sort-by-recipient (&optional reverse)
10883   "Sort the summary buffer by recipient name alphabetically.
10884 If `case-fold-search' is non-nil, case of letters is ignored.
10885 Argument REVERSE means reverse order."
10886   (interactive "P")
10887   (gnus-summary-sort 'recipient reverse))
10888
10889 (defun gnus-summary-sort-by-subject (&optional reverse)
10890   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10891 If `case-fold-search' is non-nil, case of letters is ignored.
10892 Argument REVERSE means reverse order."
10893   (interactive "P")
10894   (gnus-summary-sort 'subject reverse))
10895
10896 (defun gnus-summary-sort-by-date (&optional reverse)
10897   "Sort the summary buffer by date.
10898 Argument REVERSE means reverse order."
10899   (interactive "P")
10900   (gnus-summary-sort 'date reverse))
10901
10902 (defun gnus-summary-sort-by-score (&optional reverse)
10903   "Sort the summary buffer by score.
10904 Argument REVERSE means reverse order."
10905   (interactive "P")
10906   (gnus-summary-sort 'score reverse))
10907
10908 (defun gnus-summary-sort-by-lines (&optional reverse)
10909   "Sort the summary buffer by the number of lines.
10910 Argument REVERSE means reverse order."
10911   (interactive "P")
10912   (gnus-summary-sort 'lines reverse))
10913
10914 (defun gnus-summary-sort-by-chars (&optional reverse)
10915   "Sort the summary buffer by article length.
10916 Argument REVERSE means reverse order."
10917   (interactive "P")
10918   (gnus-summary-sort 'chars reverse))
10919
10920 (defun gnus-summary-sort-by-original (&optional reverse)
10921   "Sort the summary buffer using the default sorting method.
10922 Argument REVERSE means reverse order."
10923   (interactive "P")
10924   (let* ((buffer-read-only)
10925          (gnus-summary-prepare-hook nil))
10926     ;; We do the sorting by regenerating the threads.
10927     (gnus-summary-prepare)
10928     ;; Hide subthreads if needed.
10929     (gnus-summary-maybe-hide-threads)))
10930
10931 (defun gnus-summary-sort (predicate reverse)
10932   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10933   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10934          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10935          (gnus-thread-sort-functions
10936           (if (not reverse)
10937               thread
10938             `(lambda (t1 t2)
10939                (,thread t2 t1))))
10940          (gnus-sort-gathered-threads-function
10941           gnus-thread-sort-functions)
10942          (gnus-article-sort-functions
10943           (if (not reverse)
10944               article
10945             `(lambda (t1 t2)
10946                (,article t2 t1))))
10947          (buffer-read-only)
10948          (gnus-summary-prepare-hook nil))
10949     ;; We do the sorting by regenerating the threads.
10950     (gnus-summary-prepare)
10951     ;; Hide subthreads if needed.
10952     (gnus-summary-maybe-hide-threads)))
10953
10954 ;; Summary saving commands.
10955
10956 (defun gnus-summary-save-article (&optional n not-saved)
10957   "Save the current article using the default saver function.
10958 If N is a positive number, save the N next articles.
10959 If N is a negative number, save the N previous articles.
10960 If N is nil and any articles have been marked with the process mark,
10961 save those articles instead.
10962 The variable `gnus-default-article-saver' specifies the saver function."
10963   (interactive "P")
10964   (let* ((articles (gnus-summary-work-articles n))
10965          (save-buffer (save-excursion
10966                         (nnheader-set-temp-buffer " *Gnus Save*")))
10967          (num (length articles))
10968          header file)
10969     (dolist (article articles)
10970       (setq header (gnus-summary-article-header article))
10971       (if (not (vectorp header))
10972           ;; This is a pseudo-article.
10973           (if (assq 'name header)
10974               (gnus-copy-file (cdr (assq 'name header)))
10975             (gnus-message 1 "Article %d is unsaveable" article))
10976         ;; This is a real article.
10977         (save-window-excursion
10978           (let ((gnus-display-mime-function nil)
10979                 (gnus-article-prepare-hook nil))
10980             (gnus-summary-select-article t nil nil article)))
10981         (save-excursion
10982           (set-buffer save-buffer)
10983           (erase-buffer)
10984           (insert-buffer-substring gnus-original-article-buffer))
10985         (setq file (gnus-article-save save-buffer file num))
10986         (gnus-summary-remove-process-mark article)
10987         (unless not-saved
10988           (gnus-summary-set-saved-mark article))))
10989     (gnus-kill-buffer save-buffer)
10990     (gnus-summary-position-point)
10991     (gnus-set-mode-line 'summary)
10992     n))
10993
10994 (defun gnus-summary-pipe-output (&optional arg headers)
10995   "Pipe the current article to a subprocess.
10996 If N is a positive number, pipe the N next articles.
10997 If N is a negative number, pipe the N previous articles.
10998 If N is nil and any articles have been marked with the process mark,
10999 pipe those articles instead.
11000 If HEADERS (the symbolic prefix), include the headers, too."
11001   (interactive (gnus-interactive "P\ny"))
11002   (require 'gnus-art)
11003   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11004         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11005     (gnus-summary-save-article arg t))
11006   (let ((buffer (get-buffer "*Shell Command Output*")))
11007     (when (and buffer
11008                (not (zerop (buffer-size buffer))))
11009       (gnus-configure-windows 'pipe))))
11010
11011 (defun gnus-summary-save-article-mail (&optional arg)
11012   "Append the current article to an mail file.
11013 If N is a positive number, save the N next articles.
11014 If N is a negative number, save the N previous articles.
11015 If N is nil and any articles have been marked with the process mark,
11016 save those articles instead."
11017   (interactive "P")
11018   (require 'gnus-art)
11019   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11020     (gnus-summary-save-article arg)))
11021
11022 (defun gnus-summary-save-article-rmail (&optional arg)
11023   "Append the current article to an rmail file.
11024 If N is a positive number, save the N next articles.
11025 If N is a negative number, save the N previous articles.
11026 If N is nil and any articles have been marked with the process mark,
11027 save those articles instead."
11028   (interactive "P")
11029   (require 'gnus-art)
11030   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11031     (gnus-summary-save-article arg)))
11032
11033 (defun gnus-summary-save-article-file (&optional arg)
11034   "Append the current article to a file.
11035 If N is a positive number, save the N next articles.
11036 If N is a negative number, save the N previous articles.
11037 If N is nil and any articles have been marked with the process mark,
11038 save those articles instead."
11039   (interactive "P")
11040   (require 'gnus-art)
11041   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11042     (gnus-summary-save-article arg)))
11043
11044 (defun gnus-summary-write-article-file (&optional arg)
11045   "Write the current article to a file, deleting the previous file.
11046 If N is a positive number, save the N next articles.
11047 If N is a negative number, save the N previous articles.
11048 If N is nil and any articles have been marked with the process mark,
11049 save those articles instead."
11050   (interactive "P")
11051   (require 'gnus-art)
11052   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11053     (gnus-summary-save-article arg)))
11054
11055 (defun gnus-summary-save-article-body-file (&optional arg)
11056   "Append the current article body to a file.
11057 If N is a positive number, save the N next articles.
11058 If N is a negative number, save the N previous articles.
11059 If N is nil and any articles have been marked with the process mark,
11060 save those articles instead."
11061   (interactive "P")
11062   (require 'gnus-art)
11063   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11064     (gnus-summary-save-article arg)))
11065
11066 (defun gnus-summary-muttprint (&optional arg)
11067   "Print the current article using Muttprint.
11068 If N is a positive number, save the N next articles.
11069 If N is a negative number, save the N previous articles.
11070 If N is nil and any articles have been marked with the process mark,
11071 save those articles instead."
11072   (interactive "P")
11073   (require 'gnus-art)
11074   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11075     (gnus-summary-save-article arg t)))
11076
11077 (defun gnus-summary-pipe-message (program)
11078   "Pipe the current article through PROGRAM."
11079   (interactive "sProgram: ")
11080   (gnus-summary-select-article)
11081   (let ((mail-header-separator ""))
11082     (gnus-eval-in-buffer-window gnus-article-buffer
11083       (save-restriction
11084         (widen)
11085         (let ((start (window-start))
11086               buffer-read-only)
11087           (message-pipe-buffer-body program)
11088           (set-window-start (get-buffer-window (current-buffer)) start))))))
11089
11090 (defun gnus-get-split-value (methods)
11091   "Return a value based on the split METHODS."
11092   (let (split-name method result match)
11093     (when methods
11094       (save-excursion
11095         (set-buffer gnus-original-article-buffer)
11096         (save-restriction
11097           (nnheader-narrow-to-headers)
11098           (while (and methods (not split-name))
11099             (goto-char (point-min))
11100             (setq method (pop methods))
11101             (setq match (car method))
11102             (when (cond
11103                    ((stringp match)
11104                     ;; Regular expression.
11105                     (ignore-errors
11106                       (re-search-forward match nil t)))
11107                    ((functionp match)
11108                     ;; Function.
11109                     (save-restriction
11110                       (widen)
11111                       (setq result (funcall match gnus-newsgroup-name))))
11112                    ((consp match)
11113                     ;; Form.
11114                     (save-restriction
11115                       (widen)
11116                       (setq result (eval match)))))
11117               (setq split-name (cdr method))
11118               (cond ((stringp result)
11119                      (push (expand-file-name
11120                             result gnus-article-save-directory)
11121                            split-name))
11122                     ((consp result)
11123                      (setq split-name (append result split-name)))))))))
11124     (nreverse split-name)))
11125
11126 (defun gnus-valid-move-group-p (group)
11127   (and (boundp group)
11128        (symbol-name group)
11129        (symbol-value group)
11130        (gnus-get-function (gnus-find-method-for-group
11131                            (symbol-name group)) 'request-accept-article t)))
11132
11133 (defun gnus-read-move-group-name (prompt default articles prefix)
11134   "Read a group name."
11135   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11136          (minibuffer-confirm-incomplete nil) ; XEmacs
11137          (prom
11138           (format "%s %s to:"
11139                   prompt
11140                   (if (> (length articles) 1)
11141                       (format "these %d articles" (length articles))
11142                     "this article")))
11143          (to-newsgroup
11144           (cond
11145            ((null split-name)
11146             (gnus-completing-read-with-default
11147              default prom
11148              gnus-active-hashtb
11149              'gnus-valid-move-group-p
11150              nil prefix
11151              'gnus-group-history))
11152            ((= 1 (length split-name))
11153             (gnus-completing-read-with-default
11154              (car split-name) prom
11155              gnus-active-hashtb
11156              'gnus-valid-move-group-p
11157              nil nil
11158              'gnus-group-history))
11159            (t
11160             (gnus-completing-read-with-default
11161              nil prom
11162              (mapcar 'list (nreverse split-name))
11163              nil nil nil
11164              'gnus-group-history))))
11165          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11166     (when to-newsgroup
11167       (if (or (string= to-newsgroup "")
11168               (string= to-newsgroup prefix))
11169           (setq to-newsgroup default))
11170       (unless to-newsgroup
11171         (error "No group name entered"))
11172       (or (gnus-active to-newsgroup)
11173           (gnus-activate-group to-newsgroup nil nil to-method)
11174           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11175                                      to-newsgroup))
11176               (or (and (gnus-request-create-group to-newsgroup to-method)
11177                        (gnus-activate-group
11178                         to-newsgroup nil nil to-method)
11179                        (gnus-subscribe-group to-newsgroup))
11180                   (error "Couldn't create group %s" to-newsgroup)))
11181           (error "No such group: %s" to-newsgroup)))
11182     to-newsgroup))
11183
11184 (defun gnus-summary-save-parts (type dir n &optional reverse)
11185   "Save parts matching TYPE to DIR.
11186 If REVERSE, save parts that do not match TYPE."
11187   (interactive
11188    (list (read-string "Save parts of type: "
11189                       (or (car gnus-summary-save-parts-type-history)
11190                           gnus-summary-save-parts-default-mime)
11191                       'gnus-summary-save-parts-type-history)
11192          (setq gnus-summary-save-parts-last-directory
11193                (read-file-name "Save to directory: "
11194                                gnus-summary-save-parts-last-directory
11195                                nil t))
11196          current-prefix-arg))
11197   (gnus-summary-iterate n
11198     (let ((gnus-display-mime-function nil)
11199           (gnus-inhibit-treatment t))
11200       (gnus-summary-select-article))
11201     (save-excursion
11202       (set-buffer gnus-article-buffer)
11203       (let ((handles (or gnus-article-mime-handles
11204                          (mm-dissect-buffer nil gnus-article-loose-mime)
11205                          (and gnus-article-emulate-mime
11206                               (mm-uu-dissect)))))
11207         (when handles
11208           (gnus-summary-save-parts-1 type dir handles reverse)
11209           (unless gnus-article-mime-handles ;; Don't destroy this case.
11210             (mm-destroy-parts handles)))))))
11211
11212 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11213   (if (stringp (car handle))
11214       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11215               (cdr handle))
11216     (when (if reverse
11217               (not (string-match type (mm-handle-media-type handle)))
11218             (string-match type (mm-handle-media-type handle)))
11219       (let ((file (expand-file-name
11220                    (gnus-map-function
11221                     mm-file-name-rewrite-functions
11222                     (file-name-nondirectory
11223                      (or
11224                       (mail-content-type-get
11225                        (mm-handle-disposition handle) 'filename)
11226                       (mail-content-type-get
11227                        (mm-handle-type handle) 'name)
11228                       (concat gnus-newsgroup-name
11229                               "." (number-to-string
11230                                    (cdr gnus-article-current))))))
11231                    dir)))
11232         (unless (file-exists-p file)
11233           (mm-save-part-to-file handle file))))))
11234
11235 ;; Summary extract commands
11236
11237 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11238   (let ((buffer-read-only nil)
11239         (article (gnus-summary-article-number))
11240         after-article b e)
11241     (unless (gnus-summary-goto-subject article)
11242       (error "No such article: %d" article))
11243     (gnus-summary-position-point)
11244     ;; If all commands are to be bunched up on one line, we collect
11245     ;; them here.
11246     (unless gnus-view-pseudos-separately
11247       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11248             files action)
11249         (while ps
11250           (setq action (cdr (assq 'action (car ps))))
11251           (setq files (list (cdr (assq 'name (car ps)))))
11252           (while (and ps (cdr ps)
11253                       (string= (or action "1")
11254                                (or (cdr (assq 'action (cadr ps))) "2")))
11255             (push (cdr (assq 'name (cadr ps))) files)
11256             (setcdr ps (cddr ps)))
11257           (when files
11258             (when (not (string-match "%s" action))
11259               (push " " files))
11260             (push " " files)
11261             (when (assq 'execute (car ps))
11262               (setcdr (assq 'execute (car ps))
11263                       (funcall (if (string-match "%s" action)
11264                                    'format 'concat)
11265                                action
11266                                (mapconcat
11267                                 (lambda (f)
11268                                   (if (equal f " ")
11269                                       f
11270                                     (shell-quote-argument f)))
11271                                 files " ")))))
11272           (setq ps (cdr ps)))))
11273     (if (and gnus-view-pseudos (not not-view))
11274         (while pslist
11275           (when (assq 'execute (car pslist))
11276             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11277                                   (eq gnus-view-pseudos 'not-confirm)))
11278           (setq pslist (cdr pslist)))
11279       (save-excursion
11280         (while pslist
11281           (setq after-article (or (cdr (assq 'article (car pslist)))
11282                                   (gnus-summary-article-number)))
11283           (gnus-summary-goto-subject after-article)
11284           (forward-line 1)
11285           (setq b (point))
11286           (insert "    " (file-name-nondirectory
11287                           (cdr (assq 'name (car pslist))))
11288                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11289           (setq e (point))
11290           (forward-line -1)             ; back to `b'
11291           (gnus-add-text-properties
11292            b (1- e) (list 'gnus-number gnus-reffed-article-number
11293                           gnus-mouse-face-prop gnus-mouse-face))
11294           (gnus-data-enter
11295            after-article gnus-reffed-article-number
11296            gnus-unread-mark b (car pslist) 0 (- e b))
11297           (setq gnus-newsgroup-unreads
11298                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11299                                          gnus-reffed-article-number))
11300           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11301           (setq pslist (cdr pslist)))))))
11302
11303 (defun gnus-pseudos< (p1 p2)
11304   (let ((c1 (cdr (assq 'action p1)))
11305         (c2 (cdr (assq 'action p2))))
11306     (and c1 c2 (string< c1 c2))))
11307
11308 (defun gnus-request-pseudo-article (props)
11309   (cond ((assq 'execute props)
11310          (gnus-execute-command (cdr (assq 'execute props)))))
11311   (let ((gnus-current-article (gnus-summary-article-number)))
11312     (gnus-run-hooks 'gnus-mark-article-hook)))
11313
11314 (defun gnus-execute-command (command &optional automatic)
11315   (save-excursion
11316     (gnus-article-setup-buffer)
11317     (set-buffer gnus-article-buffer)
11318     (setq buffer-read-only nil)
11319     (let ((command (if automatic command
11320                      (read-string "Command: " (cons command 0)))))
11321       (erase-buffer)
11322       (insert "$ " command "\n\n")
11323       (if gnus-view-pseudo-asynchronously
11324           (start-process "gnus-execute" (current-buffer) shell-file-name
11325                          shell-command-switch command)
11326         (call-process shell-file-name nil t nil
11327                       shell-command-switch command)))))
11328
11329 ;; Summary kill commands.
11330
11331 (defun gnus-summary-edit-global-kill (article)
11332   "Edit the \"global\" kill file."
11333   (interactive (list (gnus-summary-article-number)))
11334   (gnus-group-edit-global-kill article))
11335
11336 (defun gnus-summary-edit-local-kill ()
11337   "Edit a local kill file applied to the current newsgroup."
11338   (interactive)
11339   (setq gnus-current-headers (gnus-summary-article-header))
11340   (gnus-group-edit-local-kill
11341    (gnus-summary-article-number) gnus-newsgroup-name))
11342
11343 ;;; Header reading.
11344
11345 (defun gnus-read-header (id &optional header)
11346   "Read the headers of article ID and enter them into the Gnus system."
11347   (let ((group gnus-newsgroup-name)
11348         (gnus-override-method
11349          (or
11350           gnus-override-method
11351           (and (gnus-news-group-p gnus-newsgroup-name)
11352                (car (gnus-refer-article-methods)))))
11353         where)
11354     ;; First we check to see whether the header in question is already
11355     ;; fetched.
11356     (if (stringp id)
11357         ;; This is a Message-ID.
11358         (setq header (or header (gnus-id-to-header id)))
11359       ;; This is an article number.
11360       (setq header (or header (gnus-summary-article-header id))))
11361     (if (and header
11362              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11363         ;; We have found the header.
11364         header
11365       ;; We have to really fetch the header to this article.
11366       (save-excursion
11367         (set-buffer nntp-server-buffer)
11368         (when (setq where (gnus-request-head id group))
11369           (nnheader-fold-continuation-lines)
11370           (goto-char (point-max))
11371           (insert ".\n")
11372           (goto-char (point-min))
11373           (insert "211 ")
11374           (princ (cond
11375                   ((numberp id) id)
11376                   ((cdr where) (cdr where))
11377                   (header (mail-header-number header))
11378                   (t gnus-reffed-article-number))
11379                  (current-buffer))
11380           (insert " Article retrieved.\n"))
11381         (if (or (not where)
11382                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11383             ()                          ; Malformed head.
11384           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11385             (when (and (stringp id)
11386                        (not (string= (gnus-group-real-name group)
11387                                      (car where))))
11388               ;; If we fetched by Message-ID and the article came
11389               ;; from a different group, we fudge some bogus article
11390               ;; numbers for this article.
11391               (mail-header-set-number header gnus-reffed-article-number))
11392             (save-excursion
11393               (set-buffer gnus-summary-buffer)
11394               (decf gnus-reffed-article-number)
11395               (gnus-remove-header (mail-header-number header))
11396               (push header gnus-newsgroup-headers)
11397               (setq gnus-current-headers header)
11398               (push (mail-header-number header) gnus-newsgroup-limit)))
11399           header)))))
11400
11401 (defun gnus-remove-header (number)
11402   "Remove header NUMBER from `gnus-newsgroup-headers'."
11403   (if (and gnus-newsgroup-headers
11404            (= number (mail-header-number (car gnus-newsgroup-headers))))
11405       (pop gnus-newsgroup-headers)
11406     (let ((headers gnus-newsgroup-headers))
11407       (while (and (cdr headers)
11408                   (not (= number (mail-header-number (cadr headers)))))
11409         (pop headers))
11410       (when (cdr headers)
11411         (setcdr headers (cddr headers))))))
11412
11413 ;;;
11414 ;;; summary highlights
11415 ;;;
11416
11417 (defun gnus-highlight-selected-summary ()
11418   "Highlight selected article in summary buffer."
11419   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11420   (when gnus-summary-selected-face
11421     (save-excursion
11422       (let* ((beg (point-at-bol))
11423              (end (point-at-eol))
11424              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11425              (from (if (get-text-property beg gnus-mouse-face-prop)
11426                        beg
11427                      (or (next-single-property-change
11428                           beg gnus-mouse-face-prop nil end)
11429                          beg)))
11430              (to
11431               (if (= from end)
11432                   (- from 2)
11433                 (or (next-single-property-change
11434                      from gnus-mouse-face-prop nil end)
11435                     end))))
11436         ;; If no mouse-face prop on line we will have to = from = end,
11437         ;; so we highlight the entire line instead.
11438         (when (= (+ to 2) from)
11439           (setq from beg)
11440           (setq to end))
11441         (if gnus-newsgroup-selected-overlay
11442             ;; Move old overlay.
11443             (gnus-move-overlay
11444              gnus-newsgroup-selected-overlay from to (current-buffer))
11445           ;; Create new overlay.
11446           (gnus-overlay-put
11447            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11448            'face gnus-summary-selected-face))))))
11449
11450 (defvar gnus-summary-highlight-line-cached nil)
11451 (defvar gnus-summary-highlight-line-trigger nil)
11452
11453 (defun gnus-summary-highlight-line-0 ()
11454   (if (and (eq gnus-summary-highlight-line-trigger
11455                gnus-summary-highlight)
11456            gnus-summary-highlight-line-cached)
11457       gnus-summary-highlight-line-cached
11458     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11459           gnus-summary-highlight-line-cached
11460           (let* ((cond (list 'cond))
11461                  (c cond)
11462                  (list gnus-summary-highlight))
11463             (while list
11464               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11465                               nil))
11466               (setq c (cdr c)
11467                     list (cdr list)))
11468             (gnus-byte-compile (list 'lambda nil cond))))))
11469
11470 (defun gnus-summary-highlight-line ()
11471   "Highlight current line according to `gnus-summary-highlight'."
11472   (let* ((beg (point-at-bol))
11473          (article (or (gnus-summary-article-number) gnus-current-article))
11474          (score (or (cdr (assq article
11475                                gnus-newsgroup-scored))
11476                     gnus-summary-default-score 0))
11477          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11478          (inhibit-read-only t)
11479          (default gnus-summary-default-score)
11480          (default-high gnus-summary-default-high-score)
11481          (default-low gnus-summary-default-low-score)
11482          (uncached (and gnus-summary-use-undownloaded-faces
11483                         (memq article gnus-newsgroup-undownloaded)
11484                         (not (memq article gnus-newsgroup-cached)))))
11485     (let ((face (funcall (gnus-summary-highlight-line-0))))
11486       (unless (eq face (get-text-property beg 'face))
11487         (gnus-put-text-property-excluding-characters-with-faces
11488          beg (point-at-eol) 'face
11489          (setq face (if (boundp face) (symbol-value face) face)))
11490         (when gnus-summary-highlight-line-function
11491           (funcall gnus-summary-highlight-line-function article face))))))
11492
11493 (defun gnus-update-read-articles (group unread &optional compute)
11494   "Update the list of read articles in GROUP.
11495 UNREAD is a sorted list."
11496   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11497         (info (gnus-get-info group))
11498         (prev 1)
11499         read)
11500     (if (or (not info) (not active))
11501         ;; There is no info on this group if it was, in fact,
11502         ;; killed.  Gnus stores no information on killed groups, so
11503         ;; there's nothing to be done.
11504         ;; One could store the information somewhere temporarily,
11505         ;; perhaps...  Hmmm...
11506         ()
11507       ;; Remove any negative articles numbers.
11508       (while (and unread (< (car unread) 0))
11509         (setq unread (cdr unread)))
11510       ;; Remove any expired article numbers
11511       (while (and unread (< (car unread) (car active)))
11512         (setq unread (cdr unread)))
11513       ;; Compute the ranges of read articles by looking at the list of
11514       ;; unread articles.
11515       (while unread
11516         (when (/= (car unread) prev)
11517           (push (if (= prev (1- (car unread))) prev
11518                   (cons prev (1- (car unread))))
11519                 read))
11520         (setq prev (1+ (car unread)))
11521         (setq unread (cdr unread)))
11522       (when (<= prev (cdr active))
11523         (push (cons prev (cdr active)) read))
11524       (setq read (if (> (length read) 1) (nreverse read) read))
11525       (if compute
11526           read
11527         (save-excursion
11528           (let (setmarkundo)
11529             ;; Propagate the read marks to the backend.
11530             (when (gnus-check-backend-function 'request-set-mark group)
11531               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11532                     (add (gnus-remove-from-range read (gnus-info-read info))))
11533                 (when (or add del)
11534                   (unless (gnus-check-group group)
11535                     (error "Can't open server for %s" group))
11536                   (gnus-request-set-mark
11537                    group (delq nil (list (if add (list add 'add '(read)))
11538                                          (if del (list del 'del '(read))))))
11539                   (setq setmarkundo
11540                         `(gnus-request-set-mark
11541                           ,group
11542                           ',(delq nil (list
11543                                        (if del (list del 'add '(read)))
11544                                        (if add (list add 'del '(read))))))))))
11545             (set-buffer gnus-group-buffer)
11546             (gnus-undo-register
11547               `(progn
11548                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11549                  (gnus-info-set-read ',info ',(gnus-info-read info))
11550                  (gnus-get-unread-articles-in-group ',info
11551                                                     (gnus-active ,group))
11552                  (gnus-group-update-group ,group t)
11553                  ,setmarkundo))))
11554         ;; Enter this list into the group info.
11555         (gnus-info-set-read info read)
11556         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11557         (gnus-get-unread-articles-in-group info (gnus-active group))
11558         t))))
11559
11560 (defun gnus-offer-save-summaries ()
11561   "Offer to save all active summary buffers."
11562   (let (buffers)
11563     ;; Go through all buffers and find all summaries.
11564     (dolist (buffer (buffer-list))
11565       (when (and (setq buffer (buffer-name buffer))
11566                  (string-match "Summary" buffer)
11567                  (with-current-buffer buffer
11568                    ;; We check that this is, indeed, a summary buffer.
11569                    (and (eq major-mode 'gnus-summary-mode)
11570                         ;; Also make sure this isn't bogus.
11571                         gnus-newsgroup-prepared
11572                         ;; Also make sure that this isn't a
11573                         ;; dead summary buffer.
11574                         (not gnus-dead-summary-mode))))
11575         (push buffer buffers)))
11576     ;; Go through all these summary buffers and offer to save them.
11577     (when buffers
11578       (save-excursion
11579         (map-y-or-n-p
11580          "Update summary buffer %s? "
11581          (lambda (buf)
11582            (switch-to-buffer buf)
11583            (gnus-summary-exit))
11584          buffers)))))
11585
11586 (defun gnus-summary-setup-default-charset ()
11587   "Setup newsgroup default charset."
11588   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11589       (setq gnus-newsgroup-charset nil)
11590     (let* ((ignored-charsets
11591             (or gnus-newsgroup-ephemeral-ignored-charsets
11592                 (append
11593                  (and gnus-newsgroup-name
11594                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11595                  gnus-newsgroup-ignored-charsets))))
11596       (setq gnus-newsgroup-charset
11597             (or gnus-newsgroup-ephemeral-charset
11598                 (and gnus-newsgroup-name
11599                      (gnus-parameter-charset gnus-newsgroup-name))
11600                 gnus-default-charset))
11601       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11602            ignored-charsets))))
11603
11604 ;;;
11605 ;;; Mime Commands
11606 ;;;
11607
11608 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11609   "Display the current article buffer fully MIME-buttonized.
11610 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11611 treated as multipart/mixed."
11612   (interactive "P")
11613   (require 'gnus-art)
11614   (let ((gnus-unbuttonized-mime-types nil)
11615         (gnus-mime-display-multipart-as-mixed show-all-parts))
11616     (gnus-summary-show-article)))
11617
11618 (defun gnus-summary-repair-multipart (article)
11619   "Add a Content-Type header to a multipart article without one."
11620   (interactive (list (gnus-summary-article-number)))
11621   (gnus-with-article article
11622     (message-narrow-to-head)
11623     (message-remove-header "Mime-Version")
11624     (goto-char (point-max))
11625     (insert "Mime-Version: 1.0\n")
11626     (widen)
11627     (when (search-forward "\n--" nil t)
11628       (let ((separator (buffer-substring (point) (point-at-eol))))
11629         (message-narrow-to-head)
11630         (message-remove-header "Content-Type")
11631         (goto-char (point-max))
11632         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11633                         separator))
11634         (widen))))
11635   (let (gnus-mark-article-hook)
11636     (gnus-summary-select-article t t nil article)))
11637
11638 (defun gnus-summary-toggle-display-buttonized ()
11639   "Toggle the buttonizing of the article buffer."
11640   (interactive)
11641   (require 'gnus-art)
11642   (if (setq gnus-inhibit-mime-unbuttonizing
11643             (not gnus-inhibit-mime-unbuttonizing))
11644       (let ((gnus-unbuttonized-mime-types nil))
11645         (gnus-summary-show-article))
11646     (gnus-summary-show-article)))
11647
11648 ;;;
11649 ;;; Generic summary marking commands
11650 ;;;
11651
11652 (defvar gnus-summary-marking-alist
11653   '((read gnus-del-mark "d")
11654     (unread gnus-unread-mark "u")
11655     (ticked gnus-ticked-mark "!")
11656     (dormant gnus-dormant-mark "?")
11657     (expirable gnus-expirable-mark "e"))
11658   "An alist of names/marks/keystrokes.")
11659
11660 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11661 (defvar gnus-summary-mark-map)
11662
11663 (defun gnus-summary-make-all-marking-commands ()
11664   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11665   (dolist (elem gnus-summary-marking-alist)
11666     (apply 'gnus-summary-make-marking-command elem)))
11667
11668 (defun gnus-summary-make-marking-command (name mark keystroke)
11669   (let ((map (make-sparse-keymap)))
11670     (define-key gnus-summary-generic-mark-map keystroke map)
11671     (dolist (lway `((next "next" next nil "n")
11672                     (next-unread "next unread" next t "N")
11673                     (prev "previous" prev nil "p")
11674                     (prev-unread "previous unread" prev t "P")
11675                     (nomove "" nil nil ,keystroke)))
11676       (let ((func (gnus-summary-make-marking-command-1
11677                    mark (car lway) lway name)))
11678         (setq func (eval func))
11679         (define-key map (nth 4 lway) func)))))
11680
11681 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11682   `(defun ,(intern
11683             (format "gnus-summary-put-mark-as-%s%s"
11684                     name (if (eq way 'nomove)
11685                              ""
11686                            (concat "-" (symbol-name way)))))
11687      (n)
11688      ,(format
11689        "Mark the current article as %s%s.
11690 If N, the prefix, then repeat N times.
11691 If N is negative, move in reverse order.
11692 The difference between N and the actual number of articles marked is
11693 returned."
11694        name (cadr lway))
11695      (interactive "p")
11696      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11697
11698 (defun gnus-summary-generic-mark (n mark move unread)
11699   "Mark N articles with MARK."
11700   (unless (eq major-mode 'gnus-summary-mode)
11701     (error "This command can only be used in the summary buffer"))
11702   (gnus-summary-show-thread)
11703   (let ((nummove
11704          (cond
11705           ((eq move 'next) 1)
11706           ((eq move 'prev) -1)
11707           (t 0))))
11708     (if (zerop nummove)
11709         (setq n 1)
11710       (when (< n 0)
11711         (setq n (abs n)
11712               nummove (* -1 nummove))))
11713     (while (and (> n 0)
11714                 (gnus-summary-mark-article nil mark)
11715                 (zerop (gnus-summary-next-subject nummove unread t)))
11716       (setq n (1- n)))
11717     (when (/= 0 n)
11718       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11719     (gnus-summary-recenter)
11720     (gnus-summary-position-point)
11721     (gnus-set-mode-line 'summary)
11722     n))
11723
11724 (defun gnus-summary-insert-articles (articles)
11725   (when (setq articles
11726               (gnus-sorted-difference articles
11727                                       (mapcar (lambda (h)
11728                                                 (mail-header-number h))
11729                                               gnus-newsgroup-headers)))
11730     (setq gnus-newsgroup-headers
11731           (gnus-merge 'list
11732                       gnus-newsgroup-headers
11733                       (gnus-fetch-headers articles)
11734                       'gnus-article-sort-by-number))
11735     ;; Suppress duplicates?
11736     (when gnus-suppress-duplicates
11737       (gnus-dup-suppress-articles))
11738
11739     ;; We might want to build some more threads first.
11740     (when (and gnus-fetch-old-headers
11741                (eq gnus-headers-retrieved-by 'nov))
11742       (if (eq gnus-fetch-old-headers 'invisible)
11743           (gnus-build-all-threads)
11744         (gnus-build-old-threads)))
11745     ;; Let the Gnus agent mark articles as read.
11746     (when gnus-agent
11747       (gnus-agent-get-undownloaded-list))
11748     ;; Remove list identifiers from subject
11749     (when gnus-list-identifiers
11750       (gnus-summary-remove-list-identifiers))
11751     ;; First and last article in this newsgroup.
11752     (when gnus-newsgroup-headers
11753       (setq gnus-newsgroup-begin
11754             (mail-header-number (car gnus-newsgroup-headers))
11755             gnus-newsgroup-end
11756             (mail-header-number
11757              (gnus-last-element gnus-newsgroup-headers))))
11758     (when gnus-use-scoring
11759       (gnus-possibly-score-headers))))
11760
11761 (defun gnus-summary-insert-old-articles (&optional all)
11762   "Insert all old articles in this group.
11763 If ALL is non-nil, already read articles become readable.
11764 If ALL is a number, fetch this number of articles."
11765   (interactive "P")
11766   (prog1
11767       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11768             older len)
11769         (setq older
11770               ;; Some nntp servers lie about their active range.  When
11771               ;; this happens, the active range can be in the millions.
11772               ;; Use a compressed range to avoid creating a huge list.
11773               (gnus-range-difference (list gnus-newsgroup-active) old))
11774         (setq len (gnus-range-length older))
11775         (cond
11776          ((null older) nil)
11777          ((numberp all)
11778           (if (< all len)
11779               (let ((older-range (nreverse older)))
11780                 (setq older nil)
11781
11782                 (while (> all 0)
11783                   (let* ((r (pop older-range))
11784                          (min (if (numberp r) r (car r)))
11785                          (max (if (numberp r) r (cdr r))))
11786                     (while (and (<= min max)
11787                                 (> all 0))
11788                       (push max older)
11789                       (setq all (1- all)
11790                             max (1- max))))))
11791             (setq older (gnus-uncompress-range older))))
11792          (all
11793           (setq older (gnus-uncompress-range older)))
11794          (t
11795           (when (and (numberp gnus-large-newsgroup)
11796                    (> len gnus-large-newsgroup))
11797               (let* ((cursor-in-echo-area nil)
11798                      (initial (gnus-parameter-large-newsgroup-initial
11799                                gnus-newsgroup-name))
11800                      (input
11801                       (read-string
11802                        (format
11803                         "How many articles from %s (%s %d): "
11804                         (gnus-limit-string
11805                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11806                         (if initial "max" "default")
11807                         len)
11808                        (if initial
11809                            (cons (number-to-string initial)
11810                                  0)))))
11811                 (unless (string-match "^[ \t]*$" input)
11812                   (setq all (string-to-number input))
11813                   (if (< all len)
11814                       (let ((older-range (nreverse older)))
11815                         (setq older nil)
11816
11817                         (while (> all 0)
11818                           (let* ((r (pop older-range))
11819                                  (min (if (numberp r) r (car r)))
11820                                  (max (if (numberp r) r (cdr r))))
11821                             (while (and (<= min max)
11822                                         (> all 0))
11823                               (push max older)
11824                               (setq all (1- all)
11825                                     max (1- max))))))))))
11826           (setq older (gnus-uncompress-range older))))
11827         (if (not older)
11828             (message "No old news.")
11829           (gnus-summary-insert-articles older)
11830           (gnus-summary-limit (gnus-sorted-nunion old older))))
11831     (gnus-summary-position-point)))
11832
11833 (defun gnus-summary-insert-new-articles ()
11834   "Insert all new articles in this group."
11835   (interactive)
11836   (prog1
11837       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11838             (old-active gnus-newsgroup-active)
11839             (nnmail-fetched-sources (list t))
11840             i new)
11841         (setq gnus-newsgroup-active
11842               (gnus-activate-group gnus-newsgroup-name 'scan))
11843         (setq i (cdr gnus-newsgroup-active))
11844         (while (> i (cdr old-active))
11845           (push i new)
11846           (decf i))
11847         (if (not new)
11848             (message "No gnus is bad news")
11849           (gnus-summary-insert-articles new)
11850           (setq gnus-newsgroup-unreads
11851                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11852           (gnus-summary-limit (gnus-sorted-nunion old new))))
11853     (gnus-summary-position-point)))
11854
11855 (gnus-summary-make-all-marking-commands)
11856
11857 (gnus-ems-redefine)
11858
11859 (provide 'gnus-sum)
11860
11861 (run-hooks 'gnus-sum-load-hook)
11862
11863 ;; Local Variables:
11864 ;; coding: iso-8859-1
11865 ;; End:
11866
11867 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11868 ;;; gnus-sum.el ends here