(gnus-article-sort-by-recipient, gnus-summary-sort-by-recipient):
[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   "m" gnus-summary-mail-other-window
1761   "a" gnus-summary-post-news
1762   "i" gnus-summary-news-other-window
1763   "x" gnus-summary-limit-to-unread
1764   "s" gnus-summary-isearch-article
1765   "t" gnus-summary-toggle-header
1766   "g" gnus-summary-show-article
1767   "l" gnus-summary-goto-last-article
1768   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1769   "\C-d" gnus-summary-enter-digest-group
1770   "\M-\C-d" gnus-summary-read-document
1771   "\M-\C-e" gnus-summary-edit-parameters
1772   "\M-\C-a" gnus-summary-customize-parameters
1773   "\C-c\C-b" gnus-bug
1774   "*" gnus-cache-enter-article
1775   "\M-*" gnus-cache-remove-article
1776   "\M-&" gnus-summary-universal-argument
1777   "\C-l" gnus-recenter
1778   "I" gnus-summary-increase-score
1779   "L" gnus-summary-lower-score
1780   "\M-i" gnus-symbolic-argument
1781   "h" gnus-summary-select-article-buffer
1782
1783   "b" gnus-article-view-part
1784   "\M-t" gnus-summary-toggle-display-buttonized
1785
1786   "V" gnus-summary-score-map
1787   "X" gnus-uu-extract-map
1788   "S" gnus-summary-send-map)
1789
1790 ;; Sort of orthogonal keymap
1791 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1792   "t" gnus-summary-tick-article-forward
1793   "!" gnus-summary-tick-article-forward
1794   "d" gnus-summary-mark-as-read-forward
1795   "r" gnus-summary-mark-as-read-forward
1796   "c" gnus-summary-clear-mark-forward
1797   " " gnus-summary-clear-mark-forward
1798   "e" gnus-summary-mark-as-expirable
1799   "x" gnus-summary-mark-as-expirable
1800   "?" gnus-summary-mark-as-dormant
1801   "b" gnus-summary-set-bookmark
1802   "B" gnus-summary-remove-bookmark
1803   "#" gnus-summary-mark-as-processable
1804   "\M-#" gnus-summary-unmark-as-processable
1805   "S" gnus-summary-limit-include-expunged
1806   "C" gnus-summary-catchup
1807   "H" gnus-summary-catchup-to-here
1808   "h" gnus-summary-catchup-from-here
1809   "\C-c" gnus-summary-catchup-all
1810   "k" gnus-summary-kill-same-subject-and-select
1811   "K" gnus-summary-kill-same-subject
1812   "P" gnus-uu-mark-map)
1813
1814 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1815   "c" gnus-summary-clear-above
1816   "u" gnus-summary-tick-above
1817   "m" gnus-summary-mark-above
1818   "k" gnus-summary-kill-below)
1819
1820 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1821   "/" gnus-summary-limit-to-subject
1822   "n" gnus-summary-limit-to-articles
1823   "w" gnus-summary-pop-limit
1824   "s" gnus-summary-limit-to-subject
1825   "a" gnus-summary-limit-to-author
1826   "u" gnus-summary-limit-to-unread
1827   "m" gnus-summary-limit-to-marks
1828   "M" gnus-summary-limit-exclude-marks
1829   "v" gnus-summary-limit-to-score
1830   "*" gnus-summary-limit-include-cached
1831   "D" gnus-summary-limit-include-dormant
1832   "T" gnus-summary-limit-include-thread
1833   "d" gnus-summary-limit-exclude-dormant
1834   "t" gnus-summary-limit-to-age
1835   "." gnus-summary-limit-to-unseen
1836   "x" gnus-summary-limit-to-extra
1837   "p" gnus-summary-limit-to-display-predicate
1838   "E" gnus-summary-limit-include-expunged
1839   "c" gnus-summary-limit-exclude-childless-dormant
1840   "C" gnus-summary-limit-mark-excluded-as-read
1841   "o" gnus-summary-insert-old-articles
1842   "N" gnus-summary-insert-new-articles
1843   "r" gnus-summary-limit-to-replied
1844   "R" gnus-summary-limit-to-recipient)
1845
1846 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1847   "n" gnus-summary-next-unread-article
1848   "p" gnus-summary-prev-unread-article
1849   "N" gnus-summary-next-article
1850   "P" gnus-summary-prev-article
1851   "\C-n" gnus-summary-next-same-subject
1852   "\C-p" gnus-summary-prev-same-subject
1853   "\M-n" gnus-summary-next-unread-subject
1854   "\M-p" gnus-summary-prev-unread-subject
1855   "f" gnus-summary-first-unread-article
1856   "b" gnus-summary-best-unread-article
1857   "j" gnus-summary-goto-article
1858   "g" gnus-summary-goto-subject
1859   "l" gnus-summary-goto-last-article
1860   "o" gnus-summary-pop-article)
1861
1862 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1863   "k" gnus-summary-kill-thread
1864   "l" gnus-summary-lower-thread
1865   "i" gnus-summary-raise-thread
1866   "T" gnus-summary-toggle-threads
1867   "t" gnus-summary-rethread-current
1868   "^" gnus-summary-reparent-thread
1869   "s" gnus-summary-show-thread
1870   "S" gnus-summary-show-all-threads
1871   "h" gnus-summary-hide-thread
1872   "H" gnus-summary-hide-all-threads
1873   "n" gnus-summary-next-thread
1874   "p" gnus-summary-prev-thread
1875   "u" gnus-summary-up-thread
1876   "o" gnus-summary-top-thread
1877   "d" gnus-summary-down-thread
1878   "#" gnus-uu-mark-thread
1879   "\M-#" gnus-uu-unmark-thread)
1880
1881 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1882   "g" gnus-summary-prepare
1883   "c" gnus-summary-insert-cached-articles
1884   "d" gnus-summary-insert-dormant-articles)
1885
1886 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1887   "c" gnus-summary-catchup-and-exit
1888   "C" gnus-summary-catchup-all-and-exit
1889   "E" gnus-summary-exit-no-update
1890   "Q" gnus-summary-exit
1891   "Z" gnus-summary-exit
1892   "n" gnus-summary-catchup-and-goto-next-group
1893   "R" gnus-summary-reselect-current-group
1894   "G" gnus-summary-rescan-group
1895   "N" gnus-summary-next-group
1896   "s" gnus-summary-save-newsrc
1897   "P" gnus-summary-prev-group)
1898
1899 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1900   " " gnus-summary-next-page
1901   "n" gnus-summary-next-page
1902   "\177" gnus-summary-prev-page
1903   [delete] gnus-summary-prev-page
1904   "p" gnus-summary-prev-page
1905   "\r" gnus-summary-scroll-up
1906   "\M-\r" gnus-summary-scroll-down
1907   "<" gnus-summary-beginning-of-article
1908   ">" gnus-summary-end-of-article
1909   "b" gnus-summary-beginning-of-article
1910   "e" gnus-summary-end-of-article
1911   "^" gnus-summary-refer-parent-article
1912   "r" gnus-summary-refer-parent-article
1913   "D" gnus-summary-enter-digest-group
1914   "R" gnus-summary-refer-references
1915   "T" gnus-summary-refer-thread
1916   "g" gnus-summary-show-article
1917   "s" gnus-summary-isearch-article
1918   "P" gnus-summary-print-article
1919   "M" gnus-mailing-list-insinuate
1920   "t" gnus-article-babel)
1921
1922 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1923   "b" gnus-article-add-buttons
1924   "B" gnus-article-add-buttons-to-head
1925   "o" gnus-article-treat-overstrike
1926   "e" gnus-article-emphasize
1927   "w" gnus-article-fill-cited-article
1928   "Q" gnus-article-fill-long-lines
1929   "C" gnus-article-capitalize-sentences
1930   "c" gnus-article-remove-cr
1931   "q" gnus-article-de-quoted-unreadable
1932   "6" gnus-article-de-base64-unreadable
1933   "Z" gnus-article-decode-HZ
1934   "A" gnus-article-treat-ansi-sequences
1935   "h" gnus-article-wash-html
1936   "u" gnus-article-unsplit-urls
1937   "s" gnus-summary-force-verify-and-decrypt
1938   "f" gnus-article-display-x-face
1939   "l" gnus-summary-stop-page-breaking
1940   "r" gnus-summary-caesar-message
1941   "m" gnus-summary-morse-message
1942   "t" gnus-summary-toggle-header
1943   "g" gnus-treat-smiley
1944   "v" gnus-summary-verbose-headers
1945   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1946   "p" gnus-article-verify-x-pgp-sig
1947   "d" gnus-article-treat-dumbquotes)
1948
1949 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1950   ;; mnemonic: deuglif*Y*
1951   "u" gnus-article-outlook-unwrap-lines
1952   "a" gnus-article-outlook-repair-attribution
1953   "c" gnus-article-outlook-rearrange-citation
1954   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1955
1956 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1957   "a" gnus-article-hide
1958   "h" gnus-article-hide-headers
1959   "b" gnus-article-hide-boring-headers
1960   "s" gnus-article-hide-signature
1961   "c" gnus-article-hide-citation
1962   "C" gnus-article-hide-citation-in-followups
1963   "l" gnus-article-hide-list-identifiers
1964   "B" gnus-article-strip-banner
1965   "P" gnus-article-hide-pem
1966   "\C-c" gnus-article-hide-citation-maybe)
1967
1968 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1969   "a" gnus-article-highlight
1970   "h" gnus-article-highlight-headers
1971   "c" gnus-article-highlight-citation
1972   "s" gnus-article-highlight-signature)
1973
1974 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1975   "f" gnus-article-treat-fold-headers
1976   "u" gnus-article-treat-unfold-headers
1977   "n" gnus-article-treat-fold-newsgroups)
1978
1979 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1980   "x" gnus-article-display-x-face
1981   "d" gnus-article-display-face
1982   "s" gnus-treat-smiley
1983   "D" gnus-article-remove-images
1984   "f" gnus-treat-from-picon
1985   "m" gnus-treat-mail-picon
1986   "n" gnus-treat-newsgroups-picon)
1987
1988 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1989   "w" gnus-article-decode-mime-words
1990   "c" gnus-article-decode-charset
1991   "v" gnus-mime-view-all-parts
1992   "b" gnus-article-view-part)
1993
1994 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1995   "z" gnus-article-date-ut
1996   "u" gnus-article-date-ut
1997   "l" gnus-article-date-local
1998   "p" gnus-article-date-english
1999   "e" gnus-article-date-lapsed
2000   "o" gnus-article-date-original
2001   "i" gnus-article-date-iso8601
2002   "s" gnus-article-date-user)
2003
2004 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2005   "t" gnus-article-remove-trailing-blank-lines
2006   "l" gnus-article-strip-leading-blank-lines
2007   "m" gnus-article-strip-multiple-blank-lines
2008   "a" gnus-article-strip-blank-lines
2009   "A" gnus-article-strip-all-blank-lines
2010   "s" gnus-article-strip-leading-space
2011   "e" gnus-article-strip-trailing-space
2012   "w" gnus-article-remove-leading-whitespace)
2013
2014 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2015   "v" gnus-version
2016   "f" gnus-summary-fetch-faq
2017   "d" gnus-summary-describe-group
2018   "h" gnus-summary-describe-briefly
2019   "i" gnus-info-find-node
2020   "c" gnus-group-fetch-charter
2021   "C" gnus-group-fetch-control)
2022
2023 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2024   "e" gnus-summary-expire-articles
2025   "\M-\C-e" gnus-summary-expire-articles-now
2026   "\177" gnus-summary-delete-article
2027   [delete] gnus-summary-delete-article
2028   [backspace] gnus-summary-delete-article
2029   "m" gnus-summary-move-article
2030   "r" gnus-summary-respool-article
2031   "w" gnus-summary-edit-article
2032   "c" gnus-summary-copy-article
2033   "B" gnus-summary-crosspost-article
2034   "q" gnus-summary-respool-query
2035   "t" gnus-summary-respool-trace
2036   "i" gnus-summary-import-article
2037   "I" gnus-summary-create-article
2038   "p" gnus-summary-article-posted-p)
2039
2040 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2041   "o" gnus-summary-save-article
2042   "m" gnus-summary-save-article-mail
2043   "F" gnus-summary-write-article-file
2044   "r" gnus-summary-save-article-rmail
2045   "f" gnus-summary-save-article-file
2046   "b" gnus-summary-save-article-body-file
2047   "h" gnus-summary-save-article-folder
2048   "v" gnus-summary-save-article-vm
2049   "p" gnus-summary-pipe-output
2050   "P" gnus-summary-muttprint
2051   "s" gnus-soup-add-article)
2052
2053 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2054   "b" gnus-summary-display-buttonized
2055   "m" gnus-summary-repair-multipart
2056   "v" gnus-article-view-part
2057   "o" gnus-article-save-part
2058   "c" gnus-article-copy-part
2059   "C" gnus-article-view-part-as-charset
2060   "e" gnus-article-view-part-externally
2061   "E" gnus-article-encrypt-body
2062   "i" gnus-article-inline-part
2063   "|" gnus-article-pipe-part)
2064
2065 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2066   "p" gnus-summary-mark-as-processable
2067   "u" gnus-summary-unmark-as-processable
2068   "U" gnus-summary-unmark-all-processable
2069   "v" gnus-uu-mark-over
2070   "s" gnus-uu-mark-series
2071   "r" gnus-uu-mark-region
2072   "g" gnus-uu-unmark-region
2073   "R" gnus-uu-mark-by-regexp
2074   "G" gnus-uu-unmark-by-regexp
2075   "t" gnus-uu-mark-thread
2076   "T" gnus-uu-unmark-thread
2077   "a" gnus-uu-mark-all
2078   "b" gnus-uu-mark-buffer
2079   "S" gnus-uu-mark-sparse
2080   "k" gnus-summary-kill-process-mark
2081   "y" gnus-summary-yank-process-mark
2082   "w" gnus-summary-save-process-mark
2083   "i" gnus-uu-invert-processable)
2084
2085 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2086   ;;"x" gnus-uu-extract-any
2087   "m" gnus-summary-save-parts
2088   "u" gnus-uu-decode-uu
2089   "U" gnus-uu-decode-uu-and-save
2090   "s" gnus-uu-decode-unshar
2091   "S" gnus-uu-decode-unshar-and-save
2092   "o" gnus-uu-decode-save
2093   "O" gnus-uu-decode-save
2094   "b" gnus-uu-decode-binhex
2095   "B" gnus-uu-decode-binhex
2096   "p" gnus-uu-decode-postscript
2097   "P" gnus-uu-decode-postscript-and-save)
2098
2099 (gnus-define-keys
2100     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2101   "u" gnus-uu-decode-uu-view
2102   "U" gnus-uu-decode-uu-and-save-view
2103   "s" gnus-uu-decode-unshar-view
2104   "S" gnus-uu-decode-unshar-and-save-view
2105   "o" gnus-uu-decode-save-view
2106   "O" gnus-uu-decode-save-view
2107   "b" gnus-uu-decode-binhex-view
2108   "B" gnus-uu-decode-binhex-view
2109   "p" gnus-uu-decode-postscript-view
2110   "P" gnus-uu-decode-postscript-and-save-view)
2111
2112 (defvar gnus-article-post-menu nil)
2113
2114 (defconst gnus-summary-menu-maxlen 20)
2115
2116 (defun gnus-summary-menu-split (menu)
2117   ;; If we have lots of elements, divide them into groups of 20
2118   ;; and make a pane (or submenu) for each one.
2119   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2120       (let ((menu menu) sublists next
2121             (i 1))
2122         (while menu
2123           ;; Pull off the next gnus-summary-menu-maxlen elements
2124           ;; and make them the next element of sublist.
2125           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2126           (if next
2127               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2128                       nil))
2129           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2130                                              (aref (car (last menu)) 0)) menu)
2131                                sublists))
2132           (setq i (1+ i))
2133           (setq menu next))
2134         (nreverse sublists))
2135     ;; Few elements--put them all in one pane.
2136     menu))
2137
2138 (defun gnus-summary-make-menu-bar ()
2139   (gnus-turn-off-edit-menu 'summary)
2140
2141   (unless (boundp 'gnus-summary-misc-menu)
2142
2143     (easy-menu-define
2144       gnus-summary-kill-menu gnus-summary-mode-map ""
2145       (cons
2146        "Score"
2147        (nconc
2148         (list
2149          ["Customize" gnus-score-customize t])
2150         (gnus-make-score-map 'increase)
2151         (gnus-make-score-map 'lower)
2152         '(("Mark"
2153            ["Kill below" gnus-summary-kill-below t]
2154            ["Mark above" gnus-summary-mark-above t]
2155            ["Tick above" gnus-summary-tick-above t]
2156            ["Clear above" gnus-summary-clear-above t])
2157           ["Current score" gnus-summary-current-score t]
2158           ["Set score" gnus-summary-set-score t]
2159           ["Switch current score file..." gnus-score-change-score-file t]
2160           ["Set mark below..." gnus-score-set-mark-below t]
2161           ["Set expunge below..." gnus-score-set-expunge-below t]
2162           ["Edit current score file" gnus-score-edit-current-scores t]
2163           ["Edit score file" gnus-score-edit-file t]
2164           ["Trace score" gnus-score-find-trace t]
2165           ["Find words" gnus-score-find-favourite-words t]
2166           ["Rescore buffer" gnus-summary-rescore t]
2167           ["Increase score..." gnus-summary-increase-score t]
2168           ["Lower score..." gnus-summary-lower-score t]))))
2169
2170     ;; Define both the Article menu in the summary buffer and the
2171     ;; equivalent Commands menu in the article buffer here for
2172     ;; consistency.
2173     (let ((innards
2174            `(("Hide"
2175               ["All" gnus-article-hide t]
2176               ["Headers" gnus-article-hide-headers t]
2177               ["Signature" gnus-article-hide-signature t]
2178               ["Citation" gnus-article-hide-citation t]
2179               ["List identifiers" gnus-article-hide-list-identifiers t]
2180               ["Banner" gnus-article-strip-banner t]
2181               ["Boring headers" gnus-article-hide-boring-headers t])
2182              ("Highlight"
2183               ["All" gnus-article-highlight t]
2184               ["Headers" gnus-article-highlight-headers t]
2185               ["Signature" gnus-article-highlight-signature t]
2186               ["Citation" gnus-article-highlight-citation t])
2187              ("MIME"
2188               ["Words" gnus-article-decode-mime-words t]
2189               ["Charset" gnus-article-decode-charset t]
2190               ["QP" gnus-article-de-quoted-unreadable t]
2191               ["Base64" gnus-article-de-base64-unreadable t]
2192               ["View MIME buttons" gnus-summary-display-buttonized t]
2193               ["View all" gnus-mime-view-all-parts t]
2194               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2195               ["Encrypt body" gnus-article-encrypt-body
2196                :active (not (gnus-group-read-only-p))
2197                ,@(if (featurep 'xemacs) nil
2198                    '(:help "Encrypt the message body on disk"))]
2199               ["Extract all parts..." gnus-summary-save-parts t]
2200               ("Multipart"
2201                ["Repair multipart" gnus-summary-repair-multipart t]
2202                ["Pipe part..." gnus-article-pipe-part t]
2203                ["Inline part" gnus-article-inline-part t]
2204                ["Encrypt body" gnus-article-encrypt-body
2205                 :active (not (gnus-group-read-only-p))
2206                ,@(if (featurep 'xemacs) nil
2207                    '(:help "Encrypt the message body on disk"))]
2208                ["View part externally" gnus-article-view-part-externally t]
2209                ["View part with charset..." gnus-article-view-part-as-charset t]
2210                ["Copy part" gnus-article-copy-part t]
2211                ["Save part..." gnus-article-save-part t]
2212                ["View part" gnus-article-view-part t]))
2213              ("Date"
2214               ["Local" gnus-article-date-local t]
2215               ["ISO8601" gnus-article-date-iso8601 t]
2216               ["UT" gnus-article-date-ut t]
2217               ["Original" gnus-article-date-original t]
2218               ["Lapsed" gnus-article-date-lapsed t]
2219               ["User-defined" gnus-article-date-user t])
2220              ("Display"
2221               ["Remove images" gnus-article-remove-images t]
2222               ["Toggle smiley" gnus-treat-smiley t]
2223               ["Show X-Face" gnus-article-display-x-face t]
2224               ["Show picons in From" gnus-treat-from-picon t]
2225               ["Show picons in mail headers" gnus-treat-mail-picon t]
2226               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2227               ("View as different encoding"
2228                ,@(gnus-summary-menu-split
2229                   (mapcar
2230                    (lambda (cs)
2231                      ;; Since easymenu under Emacs doesn't allow
2232                      ;; lambda forms for menu commands, we should
2233                      ;; provide intern'ed function symbols.
2234                      (let ((command (intern (format "\
2235 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2236                        (fset command
2237                              `(lambda ()
2238                                 (interactive)
2239                                 (let ((gnus-summary-show-article-charset-alist
2240                                        '((1 . ,cs))))
2241                                   (gnus-summary-show-article 1))))
2242                        `[,(symbol-name cs) ,command t]))
2243                    (sort (if (fboundp 'coding-system-list)
2244                              (coding-system-list)
2245                            (mapcar 'car mm-mime-mule-charset-alist))
2246                          'string<)))))
2247              ("Washing"
2248               ("Remove Blanks"
2249                ["Leading" gnus-article-strip-leading-blank-lines t]
2250                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2251                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2252                ["All of the above" gnus-article-strip-blank-lines t]
2253                ["All" gnus-article-strip-all-blank-lines t]
2254                ["Leading space" gnus-article-strip-leading-space t]
2255                ["Trailing space" gnus-article-strip-trailing-space t]
2256                ["Leading space in headers"
2257                 gnus-article-remove-leading-whitespace t])
2258               ["Overstrike" gnus-article-treat-overstrike t]
2259               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2260               ["Emphasis" gnus-article-emphasize t]
2261               ["Word wrap" gnus-article-fill-cited-article t]
2262               ["Fill long lines" gnus-article-fill-long-lines t]
2263               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2264               ["Remove CR" gnus-article-remove-cr t]
2265               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2266               ["Base64" gnus-article-de-base64-unreadable t]
2267               ["Rot 13" gnus-summary-caesar-message
2268                ,@(if (featurep 'xemacs) '(t)
2269                    '(:help "\"Caesar rotate\" article by 13"))]
2270               ["Morse decode" gnus-summary-morse-message t]
2271               ["Unix pipe..." gnus-summary-pipe-message t]
2272               ["Add buttons" gnus-article-add-buttons t]
2273               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2274               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2275               ["Verbose header" gnus-summary-verbose-headers t]
2276               ["Toggle header" gnus-summary-toggle-header t]
2277               ["Unfold headers" gnus-article-treat-unfold-headers t]
2278               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2279               ["Html" gnus-article-wash-html t]
2280               ["Unsplit URLs" gnus-article-unsplit-urls t]
2281               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2282               ["Decode HZ" gnus-article-decode-HZ t]
2283               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2284               ("(Outlook) Deuglify"
2285                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2286                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2287                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2288                ["Full (Outlook) deuglify"
2289                 gnus-article-outlook-deuglify-article t])
2290               )
2291              ("Output"
2292               ["Save in default format..." gnus-summary-save-article
2293                ,@(if (featurep 'xemacs) '(t)
2294                    '(:help "Save article using default method"))]
2295               ["Save in file..." gnus-summary-save-article-file
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article in file"))]
2298               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2299               ["Save in MH folder..." gnus-summary-save-article-folder t]
2300               ["Save in VM folder..." gnus-summary-save-article-vm t]
2301               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2302               ["Save body in file..." gnus-summary-save-article-body-file t]
2303               ["Pipe through a filter..." gnus-summary-pipe-output t]
2304               ["Add to SOUP packet" gnus-soup-add-article t]
2305               ["Print with Muttprint..." gnus-summary-muttprint t]
2306               ["Print" gnus-summary-print-article
2307                ,@(if (featurep 'xemacs) '(t)
2308                    '(:help "Generate and print a PostScript image"))])
2309              ("Copy, move,... (Backend)"
2310               ,@(if (featurep 'xemacs) nil
2311                   '(:help "Copying, moving, expiring articles..."))
2312               ["Respool article..." gnus-summary-respool-article t]
2313               ["Move article..." gnus-summary-move-article
2314                (gnus-check-backend-function
2315                 'request-move-article gnus-newsgroup-name)]
2316               ["Copy article..." gnus-summary-copy-article t]
2317               ["Crosspost article..." gnus-summary-crosspost-article
2318                (gnus-check-backend-function
2319                 'request-replace-article gnus-newsgroup-name)]
2320               ["Import file..." gnus-summary-import-article
2321                (gnus-check-backend-function
2322                 'request-accept-article gnus-newsgroup-name)]
2323               ["Create article..." gnus-summary-create-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Check if posted" gnus-summary-article-posted-p t]
2327               ["Edit article" gnus-summary-edit-article
2328                (not (gnus-group-read-only-p))]
2329               ["Delete article" gnus-summary-delete-article
2330                (gnus-check-backend-function
2331                 'request-expire-articles gnus-newsgroup-name)]
2332               ["Query respool" gnus-summary-respool-query t]
2333               ["Trace respool" gnus-summary-respool-trace t]
2334               ["Delete expirable articles" gnus-summary-expire-articles-now
2335                (gnus-check-backend-function
2336                 'request-expire-articles gnus-newsgroup-name)])
2337              ("Extract"
2338               ["Uudecode" gnus-uu-decode-uu
2339                ,@(if (featurep 'xemacs) '(t)
2340                    '(:help "Decode uuencoded article(s)"))]
2341               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2342               ["Unshar" gnus-uu-decode-unshar t]
2343               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2344               ["Save" gnus-uu-decode-save t]
2345               ["Binhex" gnus-uu-decode-binhex t]
2346               ["Postscript" gnus-uu-decode-postscript t]
2347               ["All MIME parts" gnus-summary-save-parts t])
2348              ("Cache"
2349               ["Enter article" gnus-cache-enter-article t]
2350               ["Remove article" gnus-cache-remove-article t])
2351              ["Translate" gnus-article-babel t]
2352              ["Select article buffer" gnus-summary-select-article-buffer t]
2353              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2354              ["Isearch article..." gnus-summary-isearch-article t]
2355              ["Beginning of the article" gnus-summary-beginning-of-article t]
2356              ["End of the article" gnus-summary-end-of-article t]
2357              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2358              ["Fetch referenced articles" gnus-summary-refer-references t]
2359              ["Fetch current thread" gnus-summary-refer-thread t]
2360              ["Fetch article with id..." gnus-summary-refer-article t]
2361              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2362              ["Redisplay" gnus-summary-show-article t]
2363              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2364       (easy-menu-define
2365         gnus-summary-article-menu gnus-summary-mode-map ""
2366         (cons "Article" innards))
2367
2368       (if (not (keymapp gnus-summary-article-menu))
2369           (easy-menu-define
2370             gnus-article-commands-menu gnus-article-mode-map ""
2371             (cons "Commands" innards))
2372         ;; in Emacs, don't share menu.
2373         (setq gnus-article-commands-menu
2374               (copy-keymap gnus-summary-article-menu))
2375         (define-key gnus-article-mode-map [menu-bar commands]
2376           (cons "Commands" gnus-article-commands-menu))))
2377
2378     (easy-menu-define
2379       gnus-summary-thread-menu gnus-summary-mode-map ""
2380       '("Threads"
2381         ["Find all messages in thread" gnus-summary-refer-thread t]
2382         ["Toggle threading" gnus-summary-toggle-threads t]
2383         ["Hide threads" gnus-summary-hide-all-threads t]
2384         ["Show threads" gnus-summary-show-all-threads t]
2385         ["Hide thread" gnus-summary-hide-thread t]
2386         ["Show thread" gnus-summary-show-thread t]
2387         ["Go to next thread" gnus-summary-next-thread t]
2388         ["Go to previous thread" gnus-summary-prev-thread t]
2389         ["Go down thread" gnus-summary-down-thread t]
2390         ["Go up thread" gnus-summary-up-thread t]
2391         ["Top of thread" gnus-summary-top-thread t]
2392         ["Mark thread as read" gnus-summary-kill-thread t]
2393         ["Lower thread score" gnus-summary-lower-thread t]
2394         ["Raise thread score" gnus-summary-raise-thread t]
2395         ["Rethread current" gnus-summary-rethread-current t]))
2396
2397     (easy-menu-define
2398       gnus-summary-post-menu gnus-summary-mode-map ""
2399       `("Post"
2400         ["Send a message (mail or news)" gnus-summary-post-news
2401          ,@(if (featurep 'xemacs) '(t)
2402              '(:help "Compose a new message (mail or news)"))]
2403         ["Followup" gnus-summary-followup
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Post followup to this article"))]
2406         ["Followup and yank" gnus-summary-followup-with-original
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Post followup to this article, quoting its contents"))]
2409         ["Supersede article" gnus-summary-supersede-article t]
2410         ["Cancel article" gnus-summary-cancel-article
2411          ,@(if (featurep 'xemacs) '(t)
2412              '(:help "Cancel an article you posted"))]
2413         ["Reply" gnus-summary-reply t]
2414         ["Reply and yank" gnus-summary-reply-with-original t]
2415         ["Wide reply" gnus-summary-wide-reply t]
2416         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2417          ,@(if (featurep 'xemacs) '(t)
2418              '(:help "Mail a reply, quoting this article"))]
2419         ["Very wide reply" gnus-summary-very-wide-reply t]
2420         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2421          ,@(if (featurep 'xemacs) '(t)
2422              '(:help "Mail a very wide reply, quoting this article"))]
2423         ["Mail forward" gnus-summary-mail-forward t]
2424         ["Post forward" gnus-summary-post-forward t]
2425         ["Digest and mail" gnus-uu-digest-mail-forward t]
2426         ["Digest and post" gnus-uu-digest-post-forward t]
2427         ["Resend message" gnus-summary-resend-message t]
2428         ["Resend message edit" gnus-summary-resend-message-edit t]
2429         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2430         ["Send a mail" gnus-summary-mail-other-window t]
2431         ["Create a local message" gnus-summary-news-other-window t]
2432         ["Uuencode and post" gnus-uu-post-news
2433          ,@(if (featurep 'xemacs) '(t)
2434              '(:help "Post a uuencoded article"))]
2435         ["Followup via news" gnus-summary-followup-to-mail t]
2436         ["Followup via news and yank"
2437          gnus-summary-followup-to-mail-with-original t]
2438         ;;("Draft"
2439         ;;["Send" gnus-summary-send-draft t]
2440         ;;["Send bounced" gnus-resend-bounced-mail t])
2441         ))
2442
2443     (cond
2444      ((not (keymapp gnus-summary-post-menu))
2445       (setq gnus-article-post-menu gnus-summary-post-menu))
2446      ((not gnus-article-post-menu)
2447       ;; Don't share post menu.
2448       (setq gnus-article-post-menu
2449             (copy-keymap gnus-summary-post-menu))))
2450     (define-key gnus-article-mode-map [menu-bar post]
2451       (cons "Post" gnus-article-post-menu))
2452
2453     (easy-menu-define
2454       gnus-summary-misc-menu gnus-summary-mode-map ""
2455       `("Gnus"
2456         ("Mark Read"
2457          ["Mark as read" gnus-summary-mark-as-read-forward t]
2458          ["Mark same subject and select"
2459           gnus-summary-kill-same-subject-and-select t]
2460          ["Mark same subject" gnus-summary-kill-same-subject t]
2461          ["Catchup" gnus-summary-catchup
2462           ,@(if (featurep 'xemacs) '(t)
2463               '(:help "Mark unread articles in this group as read"))]
2464          ["Catchup all" gnus-summary-catchup-all t]
2465          ["Catchup to here" gnus-summary-catchup-to-here t]
2466          ["Catchup from here" gnus-summary-catchup-from-here t]
2467          ["Catchup region" gnus-summary-mark-region-as-read
2468           (gnus-mark-active-p)]
2469          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2470         ("Mark Various"
2471          ["Tick" gnus-summary-tick-article-forward t]
2472          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2473          ["Remove marks" gnus-summary-clear-mark-forward t]
2474          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2475          ["Set bookmark" gnus-summary-set-bookmark t]
2476          ["Remove bookmark" gnus-summary-remove-bookmark t])
2477         ("Limit to"
2478          ["Marks..." gnus-summary-limit-to-marks t]
2479          ["Subject..." gnus-summary-limit-to-subject t]
2480          ["Author..." gnus-summary-limit-to-author t]
2481          ["Recipient..." gnus-summary-limit-to-recipient t]
2482          ["Age..." gnus-summary-limit-to-age t]
2483          ["Extra..." gnus-summary-limit-to-extra t]
2484          ["Score..." gnus-summary-limit-to-score t]
2485          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2486          ["Unread" gnus-summary-limit-to-unread t]
2487          ["Unseen" gnus-summary-limit-to-unseen t]
2488          ["Replied" gnus-summary-limit-to-replied t]
2489          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2490          ["Next articles" gnus-summary-limit-to-articles t]
2491          ["Pop limit" gnus-summary-pop-limit t]
2492          ["Show dormant" gnus-summary-limit-include-dormant t]
2493          ["Hide childless dormant"
2494           gnus-summary-limit-exclude-childless-dormant t]
2495          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2496          ["Hide marked" gnus-summary-limit-exclude-marks t]
2497          ["Show expunged" gnus-summary-limit-include-expunged t])
2498         ("Process Mark"
2499          ["Set mark" gnus-summary-mark-as-processable t]
2500          ["Remove mark" gnus-summary-unmark-as-processable t]
2501          ["Remove all marks" gnus-summary-unmark-all-processable t]
2502          ["Invert marks" gnus-uu-invert-processable t]
2503          ["Mark above" gnus-uu-mark-over t]
2504          ["Mark series" gnus-uu-mark-series t]
2505          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2506          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2507          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2508          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2509          ["Mark all" gnus-uu-mark-all t]
2510          ["Mark buffer" gnus-uu-mark-buffer t]
2511          ["Mark sparse" gnus-uu-mark-sparse t]
2512          ["Mark thread" gnus-uu-mark-thread t]
2513          ["Unmark thread" gnus-uu-unmark-thread t]
2514          ("Process Mark Sets"
2515           ["Kill" gnus-summary-kill-process-mark t]
2516           ["Yank" gnus-summary-yank-process-mark
2517            gnus-newsgroup-process-stack]
2518           ["Save" gnus-summary-save-process-mark t]
2519           ["Run command on marked..." gnus-summary-universal-argument t]))
2520         ("Scroll article"
2521          ["Page forward" gnus-summary-next-page
2522           ,@(if (featurep 'xemacs) '(t)
2523               '(:help "Show next page of article"))]
2524          ["Page backward" gnus-summary-prev-page
2525           ,@(if (featurep 'xemacs) '(t)
2526               '(:help "Show previous page of article"))]
2527          ["Line forward" gnus-summary-scroll-up t])
2528         ("Move"
2529          ["Next unread article" gnus-summary-next-unread-article t]
2530          ["Previous unread article" gnus-summary-prev-unread-article t]
2531          ["Next article" gnus-summary-next-article t]
2532          ["Previous article" gnus-summary-prev-article t]
2533          ["Next unread subject" gnus-summary-next-unread-subject t]
2534          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2535          ["Next article same subject" gnus-summary-next-same-subject t]
2536          ["Previous article same subject" gnus-summary-prev-same-subject t]
2537          ["First unread article" gnus-summary-first-unread-article t]
2538          ["Best unread article" gnus-summary-best-unread-article t]
2539          ["Go to subject number..." gnus-summary-goto-subject t]
2540          ["Go to article number..." gnus-summary-goto-article t]
2541          ["Go to the last article" gnus-summary-goto-last-article t]
2542          ["Pop article off history" gnus-summary-pop-article t])
2543         ("Sort"
2544          ["Sort by number" gnus-summary-sort-by-number t]
2545          ["Sort by author" gnus-summary-sort-by-author t]
2546          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2547          ["Sort by subject" gnus-summary-sort-by-subject t]
2548          ["Sort by date" gnus-summary-sort-by-date t]
2549          ["Sort by score" gnus-summary-sort-by-score t]
2550          ["Sort by lines" gnus-summary-sort-by-lines t]
2551          ["Sort by characters" gnus-summary-sort-by-chars t]
2552          ["Randomize" gnus-summary-sort-by-random t]
2553          ["Original sort" gnus-summary-sort-by-original t])
2554         ("Help"
2555          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2556          ["Describe group" gnus-summary-describe-group t]
2557          ["Fetch charter" gnus-group-fetch-charter
2558           ,@(if (featurep 'xemacs) nil
2559               '(:help "Display the charter of the current group"))]
2560          ["Fetch control message" gnus-group-fetch-control
2561           ,@(if (featurep 'xemacs) nil
2562               '(:help "Display the archived control message for the current group"))]
2563          ["Read manual" gnus-info-find-node t])
2564         ("Modes"
2565          ["Pick and read" gnus-pick-mode t]
2566          ["Binary" gnus-binary-mode t])
2567         ("Regeneration"
2568          ["Regenerate" gnus-summary-prepare t]
2569          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2570          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2571          ["Toggle threading" gnus-summary-toggle-threads t])
2572         ["See old articles" gnus-summary-insert-old-articles t]
2573         ["See new articles" gnus-summary-insert-new-articles t]
2574         ["Filter articles..." gnus-summary-execute-command t]
2575         ["Run command on articles..." gnus-summary-universal-argument t]
2576         ["Search articles forward..." gnus-summary-search-article-forward t]
2577         ["Search articles backward..." gnus-summary-search-article-backward t]
2578         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2579         ["Expand window" gnus-summary-expand-window t]
2580         ["Expire expirable articles" gnus-summary-expire-articles
2581          (gnus-check-backend-function
2582           'request-expire-articles gnus-newsgroup-name)]
2583         ["Edit local kill file" gnus-summary-edit-local-kill t]
2584         ["Edit main kill file" gnus-summary-edit-global-kill t]
2585         ["Edit group parameters" gnus-summary-edit-parameters t]
2586         ["Customize group parameters" gnus-summary-customize-parameters t]
2587         ["Send a bug report" gnus-bug t]
2588         ("Exit"
2589          ["Catchup and exit" gnus-summary-catchup-and-exit
2590           ,@(if (featurep 'xemacs) '(t)
2591               '(:help "Mark unread articles in this group as read, then exit"))]
2592          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2593          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2594          ["Exit group" gnus-summary-exit
2595           ,@(if (featurep 'xemacs) '(t)
2596               '(:help "Exit current group, return to group selection mode"))]
2597          ["Exit group without updating" gnus-summary-exit-no-update t]
2598          ["Exit and goto next group" gnus-summary-next-group t]
2599          ["Exit and goto prev group" gnus-summary-prev-group t]
2600          ["Reselect group" gnus-summary-reselect-current-group t]
2601          ["Rescan group" gnus-summary-rescan-group t]
2602          ["Update dribble" gnus-summary-save-newsrc t])))
2603
2604     (gnus-run-hooks 'gnus-summary-menu-hook)))
2605
2606 (defvar gnus-summary-tool-bar-map nil)
2607
2608 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2609 (defun gnus-summary-make-tool-bar ()
2610   (if (and (fboundp 'tool-bar-add-item-from-menu)
2611            (default-value 'tool-bar-mode)
2612            (not gnus-summary-tool-bar-map))
2613       (setq gnus-summary-tool-bar-map
2614             (let ((tool-bar-map (make-sparse-keymap))
2615                   (load-path (mm-image-load-path)))
2616               (tool-bar-add-item-from-menu
2617                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2618               (tool-bar-add-item-from-menu
2619                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2620               (tool-bar-add-item-from-menu
2621                'gnus-summary-post-news "post" gnus-summary-mode-map)
2622               (tool-bar-add-item-from-menu
2623                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2624               (tool-bar-add-item-from-menu
2625                'gnus-summary-followup "followup" gnus-summary-mode-map)
2626               (tool-bar-add-item-from-menu
2627                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2628               (tool-bar-add-item-from-menu
2629                'gnus-summary-reply "reply" gnus-summary-mode-map)
2630               (tool-bar-add-item-from-menu
2631                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2632               (tool-bar-add-item-from-menu
2633                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2634               (tool-bar-add-item-from-menu
2635                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2636               (tool-bar-add-item-from-menu
2637                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2638               (tool-bar-add-item-from-menu
2639                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2640               (tool-bar-add-item-from-menu
2641                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2642               (tool-bar-add-item-from-menu
2643                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2644               (tool-bar-add-item-from-menu
2645                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2646               (tool-bar-add-item-from-menu
2647                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2648               tool-bar-map)))
2649   (if gnus-summary-tool-bar-map
2650       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2651
2652 (defun gnus-score-set-default (var value)
2653   "A version of set that updates the GNU Emacs menu-bar."
2654   (set var value)
2655   ;; It is the message that forces the active status to be updated.
2656   (message ""))
2657
2658 (defun gnus-make-score-map (type)
2659   "Make a summary score map of type TYPE."
2660   (if t
2661       nil
2662     (let ((headers '(("author" "from" string)
2663                      ("subject" "subject" string)
2664                      ("article body" "body" string)
2665                      ("article head" "head" string)
2666                      ("xref" "xref" string)
2667                      ("extra header" "extra" string)
2668                      ("lines" "lines" number)
2669                      ("followups to author" "followup" string)))
2670           (types '((number ("less than" <)
2671                            ("greater than" >)
2672                            ("equal" =))
2673                    (string ("substring" s)
2674                            ("exact string" e)
2675                            ("fuzzy string" f)
2676                            ("regexp" r))))
2677           (perms '(("temporary" (current-time-string))
2678                    ("permanent" nil)
2679                    ("immediate" now)))
2680           header)
2681       (list
2682        (apply
2683         'nconc
2684         (list
2685          (if (eq type 'lower)
2686              "Lower score"
2687            "Increase score"))
2688         (let (outh)
2689           (while headers
2690             (setq header (car headers))
2691             (setq outh
2692                   (cons
2693                    (apply
2694                     'nconc
2695                     (list (car header))
2696                     (let ((ts (cdr (assoc (nth 2 header) types)))
2697                           outt)
2698                       (while ts
2699                         (setq outt
2700                               (cons
2701                                (apply
2702                                 'nconc
2703                                 (list (caar ts))
2704                                 (let ((ps perms)
2705                                       outp)
2706                                   (while ps
2707                                     (setq outp
2708                                           (cons
2709                                            (vector
2710                                             (caar ps)
2711                                             (list
2712                                              'gnus-summary-score-entry
2713                                              (nth 1 header)
2714                                              (if (or (string= (nth 1 header)
2715                                                               "head")
2716                                                      (string= (nth 1 header)
2717                                                               "body"))
2718                                                  ""
2719                                                (list 'gnus-summary-header
2720                                                      (nth 1 header)))
2721                                              (list 'quote (nth 1 (car ts)))
2722                                              (list 'gnus-score-delta-default
2723                                                    nil)
2724                                              (nth 1 (car ps))
2725                                              t)
2726                                             t)
2727                                            outp))
2728                                     (setq ps (cdr ps)))
2729                                   (list (nreverse outp))))
2730                                outt))
2731                         (setq ts (cdr ts)))
2732                       (list (nreverse outt))))
2733                    outh))
2734             (setq headers (cdr headers)))
2735           (list (nreverse outh))))))))
2736
2737 \f
2738
2739 (defun gnus-summary-mode (&optional group)
2740   "Major mode for reading articles.
2741
2742 All normal editing commands are switched off.
2743 \\<gnus-summary-mode-map>
2744 Each line in this buffer represents one article.  To read an
2745 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2746 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2747 respectively.
2748
2749 You can also post articles and send mail from this buffer.  To
2750 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2751 of an article, type `\\[gnus-summary-reply]'.
2752
2753 There are approx. one gazillion commands you can execute in this
2754 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2755
2756 The following commands are available:
2757
2758 \\{gnus-summary-mode-map}"
2759   (interactive)
2760   (kill-all-local-variables)
2761   (when (gnus-visual-p 'summary-menu 'menu)
2762     (gnus-summary-make-menu-bar)
2763     (gnus-summary-make-tool-bar))
2764   (gnus-summary-make-local-variables)
2765   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2766     (gnus-summary-make-local-variables))
2767   (gnus-make-thread-indent-array)
2768   (gnus-simplify-mode-line)
2769   (setq major-mode 'gnus-summary-mode)
2770   (setq mode-name "Summary")
2771   (make-local-variable 'minor-mode-alist)
2772   (use-local-map gnus-summary-mode-map)
2773   (buffer-disable-undo)
2774   (setq buffer-read-only t              ;Disable modification
2775         show-trailing-whitespace nil)
2776   (setq truncate-lines t)
2777   (setq selective-display t)
2778   (setq selective-display-ellipses t)   ;Display `...'
2779   (gnus-summary-set-display-table)
2780   (gnus-set-default-directory)
2781   (setq gnus-newsgroup-name group)
2782   (make-local-variable 'gnus-summary-line-format)
2783   (make-local-variable 'gnus-summary-line-format-spec)
2784   (make-local-variable 'gnus-summary-dummy-line-format)
2785   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2786   (make-local-variable 'gnus-summary-mark-positions)
2787   (gnus-make-local-hook 'pre-command-hook)
2788   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2789   (gnus-run-hooks 'gnus-summary-mode-hook)
2790   (turn-on-gnus-mailing-list-mode)
2791   (mm-enable-multibyte)
2792   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2793   (gnus-update-summary-mark-positions))
2794
2795 (defun gnus-summary-make-local-variables ()
2796   "Make all the local summary buffer variables."
2797   (let (global)
2798     (dolist (local gnus-summary-local-variables)
2799       (if (consp local)
2800           (progn
2801             (if (eq (cdr local) 'global)
2802                 ;; Copy the global value of the variable.
2803                 (setq global (symbol-value (car local)))
2804               ;; Use the value from the list.
2805               (setq global (eval (cdr local))))
2806             (set (make-local-variable (car local)) global))
2807         ;; Simple nil-valued local variable.
2808         (set (make-local-variable local) nil)))))
2809
2810 (defun gnus-summary-clear-local-variables ()
2811   (let ((locals gnus-summary-local-variables))
2812     (while locals
2813       (if (consp (car locals))
2814           (and (symbolp (caar locals))
2815                (set (caar locals) nil))
2816         (and (symbolp (car locals))
2817              (set (car locals) nil)))
2818       (setq locals (cdr locals)))))
2819
2820 ;; Summary data functions.
2821
2822 (defmacro gnus-data-number (data)
2823   `(car ,data))
2824
2825 (defmacro gnus-data-set-number (data number)
2826   `(setcar ,data ,number))
2827
2828 (defmacro gnus-data-mark (data)
2829   `(nth 1 ,data))
2830
2831 (defmacro gnus-data-set-mark (data mark)
2832   `(setcar (nthcdr 1 ,data) ,mark))
2833
2834 (defmacro gnus-data-pos (data)
2835   `(nth 2 ,data))
2836
2837 (defmacro gnus-data-set-pos (data pos)
2838   `(setcar (nthcdr 2 ,data) ,pos))
2839
2840 (defmacro gnus-data-header (data)
2841   `(nth 3 ,data))
2842
2843 (defmacro gnus-data-set-header (data header)
2844   `(setf (nth 3 ,data) ,header))
2845
2846 (defmacro gnus-data-level (data)
2847   `(nth 4 ,data))
2848
2849 (defmacro gnus-data-unread-p (data)
2850   `(= (nth 1 ,data) gnus-unread-mark))
2851
2852 (defmacro gnus-data-read-p (data)
2853   `(/= (nth 1 ,data) gnus-unread-mark))
2854
2855 (defmacro gnus-data-pseudo-p (data)
2856   `(consp (nth 3 ,data)))
2857
2858 (defmacro gnus-data-find (number)
2859   `(assq ,number gnus-newsgroup-data))
2860
2861 (defmacro gnus-data-find-list (number &optional data)
2862   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2863      (memq (assq ,number bdata)
2864            bdata)))
2865
2866 (defmacro gnus-data-make (number mark pos header level)
2867   `(list ,number ,mark ,pos ,header ,level))
2868
2869 (defun gnus-data-enter (after-article number mark pos header level offset)
2870   (let ((data (gnus-data-find-list after-article)))
2871     (unless data
2872       (error "No such article: %d" after-article))
2873     (setcdr data (cons (gnus-data-make number mark pos header level)
2874                        (cdr data)))
2875     (setq gnus-newsgroup-data-reverse nil)
2876     (gnus-data-update-list (cddr data) offset)))
2877
2878 (defun gnus-data-enter-list (after-article list &optional offset)
2879   (when list
2880     (let ((data (and after-article (gnus-data-find-list after-article)))
2881           (ilist list))
2882       (if (not (or data
2883                    after-article))
2884           (let ((odata gnus-newsgroup-data))
2885             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2886             (when offset
2887               (gnus-data-update-list odata offset)))
2888         ;; Find the last element in the list to be spliced into the main
2889         ;; list.
2890         (setq list (last list))
2891         (if (not data)
2892             (progn
2893               (setcdr list gnus-newsgroup-data)
2894               (setq gnus-newsgroup-data ilist)
2895               (when offset
2896                 (gnus-data-update-list (cdr list) offset)))
2897           (setcdr list (cdr data))
2898           (setcdr data ilist)
2899           (when offset
2900             (gnus-data-update-list (cdr list) offset))))
2901       (setq gnus-newsgroup-data-reverse nil))))
2902
2903 (defun gnus-data-remove (article &optional offset)
2904   (let ((data gnus-newsgroup-data))
2905     (if (= (gnus-data-number (car data)) article)
2906         (progn
2907           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2908                 gnus-newsgroup-data-reverse nil)
2909           (when offset
2910             (gnus-data-update-list gnus-newsgroup-data offset)))
2911       (while (cdr data)
2912         (when (= (gnus-data-number (cadr data)) article)
2913           (setcdr data (cddr data))
2914           (when offset
2915             (gnus-data-update-list (cdr data) offset))
2916           (setq data nil
2917                 gnus-newsgroup-data-reverse nil))
2918         (setq data (cdr data))))))
2919
2920 (defmacro gnus-data-list (backward)
2921   `(if ,backward
2922        (or gnus-newsgroup-data-reverse
2923            (setq gnus-newsgroup-data-reverse
2924                  (reverse gnus-newsgroup-data)))
2925      gnus-newsgroup-data))
2926
2927 (defun gnus-data-update-list (data offset)
2928   "Add OFFSET to the POS of all data entries in DATA."
2929   (setq gnus-newsgroup-data-reverse nil)
2930   (while data
2931     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2932     (setq data (cdr data))))
2933
2934 (defun gnus-summary-article-pseudo-p (article)
2935   "Say whether this article is a pseudo article or not."
2936   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2937
2938 (defmacro gnus-summary-article-sparse-p (article)
2939   "Say whether this article is a sparse article or not."
2940   `(memq ,article gnus-newsgroup-sparse))
2941
2942 (defmacro gnus-summary-article-ancient-p (article)
2943   "Say whether this article is a sparse article or not."
2944   `(memq ,article gnus-newsgroup-ancient))
2945
2946 (defun gnus-article-parent-p (number)
2947   "Say whether this article is a parent or not."
2948   (let ((data (gnus-data-find-list number)))
2949     (and (cdr data)              ; There has to be an article after...
2950          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2951             (gnus-data-level (nth 1 data))))))
2952
2953 (defun gnus-article-children (number)
2954   "Return a list of all children to NUMBER."
2955   (let* ((data (gnus-data-find-list number))
2956          (level (gnus-data-level (car data)))
2957          children)
2958     (setq data (cdr data))
2959     (while (and data
2960                 (= (gnus-data-level (car data)) (1+ level)))
2961       (push (gnus-data-number (car data)) children)
2962       (setq data (cdr data)))
2963     children))
2964
2965 (defmacro gnus-summary-skip-intangible ()
2966   "If the current article is intangible, then jump to a different article."
2967   '(let ((to (get-text-property (point) 'gnus-intangible)))
2968      (and to (gnus-summary-goto-subject to))))
2969
2970 (defmacro gnus-summary-article-intangible-p ()
2971   "Say whether this article is intangible or not."
2972   '(get-text-property (point) 'gnus-intangible))
2973
2974 (defun gnus-article-read-p (article)
2975   "Say whether ARTICLE is read or not."
2976   (not (or (memq article gnus-newsgroup-marked)
2977            (memq article gnus-newsgroup-spam-marked)
2978            (memq article gnus-newsgroup-unreads)
2979            (memq article gnus-newsgroup-unselected)
2980            (memq article gnus-newsgroup-dormant))))
2981
2982 ;; Some summary mode macros.
2983
2984 (defmacro gnus-summary-article-number ()
2985   "The article number of the article on the current line.
2986 If there isn't an article number here, then we return the current
2987 article number."
2988   '(progn
2989      (gnus-summary-skip-intangible)
2990      (or (get-text-property (point) 'gnus-number)
2991          (gnus-summary-last-subject))))
2992
2993 (defmacro gnus-summary-article-header (&optional number)
2994   "Return the header of article NUMBER."
2995   `(gnus-data-header (gnus-data-find
2996                       ,(or number '(gnus-summary-article-number)))))
2997
2998 (defmacro gnus-summary-thread-level (&optional number)
2999   "Return the level of thread that starts with article NUMBER."
3000   `(if (and (eq gnus-summary-make-false-root 'dummy)
3001             (get-text-property (point) 'gnus-intangible))
3002        0
3003      (gnus-data-level (gnus-data-find
3004                        ,(or number '(gnus-summary-article-number))))))
3005
3006 (defmacro gnus-summary-article-mark (&optional number)
3007   "Return the mark of article NUMBER."
3008   `(gnus-data-mark (gnus-data-find
3009                     ,(or number '(gnus-summary-article-number)))))
3010
3011 (defmacro gnus-summary-article-pos (&optional number)
3012   "Return the position of the line of article NUMBER."
3013   `(gnus-data-pos (gnus-data-find
3014                    ,(or number '(gnus-summary-article-number)))))
3015
3016 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3017 (defmacro gnus-summary-article-subject (&optional number)
3018   "Return current subject string or nil if nothing."
3019   `(let ((headers
3020           ,(if number
3021                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3022              '(gnus-data-header (assq (gnus-summary-article-number)
3023                                       gnus-newsgroup-data)))))
3024      (and headers
3025           (vectorp headers)
3026           (mail-header-subject headers))))
3027
3028 (defmacro gnus-summary-article-score (&optional number)
3029   "Return current article score."
3030   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3031                   gnus-newsgroup-scored))
3032        gnus-summary-default-score 0))
3033
3034 (defun gnus-summary-article-children (&optional number)
3035   "Return a list of article numbers that are children of article NUMBER."
3036   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3037          (level (gnus-data-level (car data)))
3038          l children)
3039     (while (and (setq data (cdr data))
3040                 (> (setq l (gnus-data-level (car data))) level))
3041       (and (= (1+ level) l)
3042            (push (gnus-data-number (car data))
3043                  children)))
3044     (nreverse children)))
3045
3046 (defun gnus-summary-article-parent (&optional number)
3047   "Return the article number of the parent of article NUMBER."
3048   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3049                                     (gnus-data-list t)))
3050          (level (gnus-data-level (car data))))
3051     (if (zerop level)
3052         ()                              ; This is a root.
3053       ;; We search until we find an article with a level less than
3054       ;; this one.  That function has to be the parent.
3055       (while (and (setq data (cdr data))
3056                   (not (< (gnus-data-level (car data)) level))))
3057       (and data (gnus-data-number (car data))))))
3058
3059 (defun gnus-unread-mark-p (mark)
3060   "Say whether MARK is the unread mark."
3061   (= mark gnus-unread-mark))
3062
3063 (defun gnus-read-mark-p (mark)
3064   "Say whether MARK is one of the marks that mark as read.
3065 This is all marks except unread, ticked, dormant, and expirable."
3066   (not (or (= mark gnus-unread-mark)
3067            (= mark gnus-ticked-mark)
3068            (= mark gnus-spam-mark)
3069            (= mark gnus-dormant-mark)
3070            (= mark gnus-expirable-mark))))
3071
3072 (defmacro gnus-article-mark (number)
3073   "Return the MARK of article NUMBER.
3074 This macro should only be used when computing the mark the \"first\"
3075 time; i.e., when generating the summary lines.  After that,
3076 `gnus-summary-article-mark' should be used to examine the
3077 marks of articles."
3078   `(cond
3079     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3080     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3081     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3082     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3083     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3084     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3085     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3086     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3087            gnus-ancient-mark))))
3088
3089 ;; Saving hidden threads.
3090
3091 (defmacro gnus-save-hidden-threads (&rest forms)
3092   "Save hidden threads, eval FORMS, and restore the hidden threads."
3093   (let ((config (make-symbol "config")))
3094     `(let ((,config (gnus-hidden-threads-configuration)))
3095        (unwind-protect
3096            (save-excursion
3097              ,@forms)
3098          (gnus-restore-hidden-threads-configuration ,config)))))
3099 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3100 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3101
3102 (defun gnus-data-compute-positions ()
3103   "Compute the positions of all articles."
3104   (setq gnus-newsgroup-data-reverse nil)
3105   (let ((data gnus-newsgroup-data))
3106     (save-excursion
3107       (gnus-save-hidden-threads
3108         (gnus-summary-show-all-threads)
3109         (goto-char (point-min))
3110         (while data
3111           (while (get-text-property (point) 'gnus-intangible)
3112             (forward-line 1))
3113           (gnus-data-set-pos (car data) (+ (point) 3))
3114           (setq data (cdr data))
3115           (forward-line 1))))))
3116
3117 (defun gnus-hidden-threads-configuration ()
3118   "Return the current hidden threads configuration."
3119   (save-excursion
3120     (let (config)
3121       (goto-char (point-min))
3122       (while (search-forward "\r" nil t)
3123         (push (1- (point)) config))
3124       config)))
3125
3126 (defun gnus-restore-hidden-threads-configuration (config)
3127   "Restore hidden threads configuration from CONFIG."
3128   (save-excursion
3129     (let (point buffer-read-only)
3130       (while (setq point (pop config))
3131         (when (and (< point (point-max))
3132                    (goto-char point)
3133                    (eq (char-after) ?\n))
3134           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3135
3136 ;; Various summary mode internalish functions.
3137
3138 (defun gnus-mouse-pick-article (e)
3139   (interactive "e")
3140   (mouse-set-point e)
3141   (gnus-summary-next-page nil t))
3142
3143 (defun gnus-summary-set-display-table ()
3144   "Change the display table.
3145 Odd characters have a tendency to mess
3146 up nicely formatted displays - we make all possible glyphs
3147 display only a single character."
3148
3149   ;; We start from the standard display table, if any.
3150   (let ((table (or (copy-sequence standard-display-table)
3151                    (make-display-table)))
3152         (i 32))
3153     ;; Nix out all the control chars...
3154     (while (>= (setq i (1- i)) 0)
3155       (aset table i [??]))
3156    ;; ... but not newline and cr, of course.  (cr is necessary for the
3157     ;; selective display).
3158     (aset table ?\n nil)
3159     (aset table ?\r nil)
3160     ;; We keep TAB as well.
3161     (aset table ?\t nil)
3162     ;; We nix out any glyphs over 126 that are not set already.
3163     (let ((i 256))
3164       (while (>= (setq i (1- i)) 127)
3165         ;; Only modify if the entry is nil.
3166         (unless (aref table i)
3167           (aset table i [??]))))
3168     (setq buffer-display-table table)))
3169
3170 (defun gnus-summary-set-article-display-arrow (pos)
3171   "Update the overlay arrow to point to line at position POS."
3172   (when (and gnus-summary-display-arrow
3173              (boundp 'overlay-arrow-position)
3174              (boundp 'overlay-arrow-string))
3175     (save-excursion
3176       (goto-char pos)
3177       (beginning-of-line)
3178       (unless overlay-arrow-position
3179         (setq overlay-arrow-position (make-marker)))
3180       (setq overlay-arrow-string "=>"
3181             overlay-arrow-position (set-marker overlay-arrow-position
3182                                                (point)
3183                                                (current-buffer))))))
3184
3185 (defun gnus-summary-setup-buffer (group)
3186   "Initialize summary buffer."
3187   (let ((buffer (gnus-summary-buffer-name group))
3188         (dead-name (concat "*Dead Summary "
3189                            (gnus-group-decoded-name group) "*")))
3190     ;; If a dead summary buffer exists, we kill it.
3191     (when (gnus-buffer-live-p dead-name)
3192       (gnus-kill-buffer dead-name))
3193     (if (get-buffer buffer)
3194         (progn
3195           (set-buffer buffer)
3196           (setq gnus-summary-buffer (current-buffer))
3197           (not gnus-newsgroup-prepared))
3198       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3199       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3200       (gnus-summary-mode group)
3201       (when gnus-carpal
3202         (gnus-carpal-setup-buffer 'summary))
3203       (unless gnus-single-article-buffer
3204         (make-local-variable 'gnus-article-buffer)
3205         (make-local-variable 'gnus-article-current)
3206         (make-local-variable 'gnus-original-article-buffer))
3207       (setq gnus-newsgroup-name group)
3208       ;; Set any local variables in the group parameters.
3209       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3210       t)))
3211
3212 (defun gnus-set-global-variables ()
3213   "Set the global equivalents of the buffer-local variables.
3214 They are set to the latest values they had.  These reflect the summary
3215 buffer that was in action when the last article was fetched."
3216   (when (eq major-mode 'gnus-summary-mode)
3217     (setq gnus-summary-buffer (current-buffer))
3218     (let ((name gnus-newsgroup-name)
3219           (marked gnus-newsgroup-marked)
3220           (spam gnus-newsgroup-spam-marked)
3221           (unread gnus-newsgroup-unreads)
3222           (headers gnus-current-headers)
3223           (data gnus-newsgroup-data)
3224           (summary gnus-summary-buffer)
3225           (article-buffer gnus-article-buffer)
3226           (original gnus-original-article-buffer)
3227           (gac gnus-article-current)
3228           (reffed gnus-reffed-article-number)
3229           (score-file gnus-current-score-file)
3230           (default-charset gnus-newsgroup-charset)
3231           vlist)
3232       (let ((locals gnus-newsgroup-variables))
3233         (while locals
3234           (if (consp (car locals))
3235               (push (eval (caar locals)) vlist)
3236             (push (eval (car locals)) vlist))
3237           (setq locals (cdr locals)))
3238         (setq vlist (nreverse vlist)))
3239       (with-current-buffer gnus-group-buffer
3240         (setq gnus-newsgroup-name name
3241               gnus-newsgroup-marked marked
3242               gnus-newsgroup-spam-marked spam
3243               gnus-newsgroup-unreads unread
3244               gnus-current-headers headers
3245               gnus-newsgroup-data data
3246               gnus-article-current gac
3247               gnus-summary-buffer summary
3248               gnus-article-buffer article-buffer
3249               gnus-original-article-buffer original
3250               gnus-reffed-article-number reffed
3251               gnus-current-score-file score-file
3252               gnus-newsgroup-charset default-charset)
3253         (let ((locals gnus-newsgroup-variables))
3254           (while locals
3255             (if (consp (car locals))
3256                 (set (caar locals) (pop vlist))
3257               (set (car locals) (pop vlist)))
3258             (setq locals (cdr locals))))
3259         ;; The article buffer also has local variables.
3260         (when (gnus-buffer-live-p gnus-article-buffer)
3261           (set-buffer gnus-article-buffer)
3262           (setq gnus-summary-buffer summary))))))
3263
3264 (defun gnus-summary-article-unread-p (article)
3265   "Say whether ARTICLE is unread or not."
3266   (memq article gnus-newsgroup-unreads))
3267
3268 (defun gnus-summary-first-article-p (&optional article)
3269   "Return whether ARTICLE is the first article in the buffer."
3270   (if (not (setq article (or article (gnus-summary-article-number))))
3271       nil
3272     (eq article (caar gnus-newsgroup-data))))
3273
3274 (defun gnus-summary-last-article-p (&optional article)
3275   "Return whether ARTICLE is the last article in the buffer."
3276   (if (not (setq article (or article (gnus-summary-article-number))))
3277       ;; All non-existent numbers are the last article.  :-)
3278       t
3279     (not (cdr (gnus-data-find-list article)))))
3280
3281 (defun gnus-make-thread-indent-array ()
3282   (let ((n 200))
3283     (unless (and gnus-thread-indent-array
3284                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3285       (setq gnus-thread-indent-array (make-vector 201 "")
3286             gnus-thread-indent-array-level gnus-thread-indent-level)
3287       (while (>= n 0)
3288         (aset gnus-thread-indent-array n
3289               (make-string (* n gnus-thread-indent-level) ? ))
3290         (setq n (1- n))))))
3291
3292 (defun gnus-update-summary-mark-positions ()
3293   "Compute where the summary marks are to go."
3294   (save-excursion
3295     (when (gnus-buffer-exists-p gnus-summary-buffer)
3296       (set-buffer gnus-summary-buffer))
3297     (let ((spec gnus-summary-line-format-spec)
3298           pos)
3299       (save-excursion
3300         (gnus-set-work-buffer)
3301         (let ((gnus-tmp-unread ?Z)
3302               (gnus-replied-mark ?Z)
3303               (gnus-score-below-mark ?Z)
3304               (gnus-score-over-mark ?Z)
3305               (gnus-undownloaded-mark ?Z)
3306               (gnus-summary-line-format-spec spec)
3307               (gnus-newsgroup-downloadable '(0))
3308               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3309               case-fold-search ignores)
3310           ;; Here, all marks are bound to Z.
3311           (gnus-summary-insert-line header
3312                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3313           (goto-char (point-min))
3314           ;; Memorize the positions of the same characters as dummy marks.
3315           (while (re-search-forward "[A-D]" nil t)
3316             (push (point) ignores))
3317           (erase-buffer)
3318           ;; We use A-D as dummy marks in order to know column positions
3319           ;; where marks should be inserted.
3320           (setq gnus-tmp-unread ?A
3321                 gnus-replied-mark ?B
3322                 gnus-score-below-mark ?C
3323                 gnus-score-over-mark ?C
3324                 gnus-undownloaded-mark ?D)
3325           (gnus-summary-insert-line header
3326                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3327           ;; Ignore characters which aren't dummy marks.
3328           (dolist (p ignores)
3329             (delete-region (goto-char (1- p)) p)
3330             (insert ?Z))
3331           (goto-char (point-min))
3332           (setq pos (list (cons 'unread
3333                                 (and (search-forward "A" nil t)
3334                                      (- (point) (point-min) 1)))))
3335           (goto-char (point-min))
3336           (push (cons 'replied (and (search-forward "B" nil t)
3337                                     (- (point) (point-min) 1)))
3338                 pos)
3339           (goto-char (point-min))
3340           (push (cons 'score (and (search-forward "C" nil t)
3341                                   (- (point) (point-min) 1)))
3342                 pos)
3343           (goto-char (point-min))
3344           (push (cons 'download (and (search-forward "D" nil t)
3345                                      (- (point) (point-min) 1)))
3346                 pos)))
3347       (setq gnus-summary-mark-positions pos))))
3348
3349 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3350   "Insert a dummy root in the summary buffer."
3351   (beginning-of-line)
3352   (gnus-add-text-properties
3353    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3354    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3355
3356 (defun gnus-summary-extract-address-component (from)
3357   (or (car (funcall gnus-extract-address-components from))
3358       from))
3359
3360 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3361   (let ((mail-parse-charset gnus-newsgroup-charset)
3362         ; Is it really necessary to do this next part for each summary line?
3363         ; Luckily, doesn't seem to slow things down much.
3364         (mail-parse-ignored-charsets
3365          (with-current-buffer gnus-summary-buffer
3366            gnus-newsgroup-ignored-charsets)))
3367     (or
3368      (and gnus-ignored-from-addresses
3369           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3370           (let ((extra-headers (mail-header-extra header))
3371                 to
3372                 newsgroups)
3373             (cond
3374              ((setq to (cdr (assq 'To extra-headers)))
3375               (concat "-> "
3376                       (inline
3377                         (gnus-summary-extract-address-component
3378                          (funcall gnus-decode-encoded-word-function to)))))
3379              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3380               (concat "=> " newsgroups)))))
3381      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3382
3383 (defun gnus-summary-insert-line (gnus-tmp-header
3384                                  gnus-tmp-level gnus-tmp-current
3385                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3386                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3387                                  &optional gnus-tmp-dummy gnus-tmp-score
3388                                  gnus-tmp-process)
3389   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3390          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3391          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3392          (gnus-tmp-score-char
3393           (if (or (null gnus-summary-default-score)
3394                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3395                       gnus-summary-zcore-fuzz))
3396               ?                         ;Whitespace
3397             (if (< gnus-tmp-score gnus-summary-default-score)
3398                 gnus-score-below-mark gnus-score-over-mark)))
3399          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3400          (gnus-tmp-replied
3401           (cond (gnus-tmp-process gnus-process-mark)
3402                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3403                  gnus-cached-mark)
3404                 (gnus-tmp-replied gnus-replied-mark)
3405                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3406                  gnus-forwarded-mark)
3407                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3408                  gnus-saved-mark)
3409                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3410                  gnus-recent-mark)
3411                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3412                  gnus-unseen-mark)
3413                 (t gnus-no-mark)))
3414          (gnus-tmp-downloaded
3415           (cond (undownloaded
3416                  gnus-undownloaded-mark)
3417                 (gnus-newsgroup-agentized
3418                  gnus-downloaded-mark)
3419                 (t
3420                  gnus-no-mark)))
3421          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3422          (gnus-tmp-name
3423           (cond
3424            ((string-match "<[^>]+> *$" gnus-tmp-from)
3425             (let ((beg (match-beginning 0)))
3426               (or (and (string-match "^\".+\"" gnus-tmp-from)
3427                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3428                   (substring gnus-tmp-from 0 beg))))
3429            ((string-match "(.+)" gnus-tmp-from)
3430             (substring gnus-tmp-from
3431                        (1+ (match-beginning 0)) (1- (match-end 0))))
3432            (t gnus-tmp-from)))
3433          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3434          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3435          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3436          (buffer-read-only nil))
3437     (when (string= gnus-tmp-name "")
3438       (setq gnus-tmp-name gnus-tmp-from))
3439     (unless (numberp gnus-tmp-lines)
3440       (setq gnus-tmp-lines -1))
3441     (if (= gnus-tmp-lines -1)
3442         (setq gnus-tmp-lines "?")
3443       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3444       (gnus-put-text-property
3445      (point)
3446      (progn (eval gnus-summary-line-format-spec) (point))
3447        'gnus-number gnus-tmp-number)
3448     (when (gnus-visual-p 'summary-highlight 'highlight)
3449       (forward-line -1)
3450       (gnus-run-hooks 'gnus-summary-update-hook)
3451       (forward-line 1))))
3452
3453 (defun gnus-summary-update-line (&optional dont-update)
3454   "Update summary line after change."
3455   (when (and gnus-summary-default-score
3456              (not gnus-summary-inhibit-highlight))
3457     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3458            (article (gnus-summary-article-number))
3459            (score (gnus-summary-article-score article)))
3460       (unless dont-update
3461         (if (and gnus-summary-mark-below
3462                  (< (gnus-summary-article-score)
3463                     gnus-summary-mark-below))
3464             ;; This article has a low score, so we mark it as read.
3465             (when (memq article gnus-newsgroup-unreads)
3466               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3467           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3468             ;; This article was previously marked as read on account
3469             ;; of a low score, but now it has risen, so we mark it as
3470             ;; unread.
3471             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3472         (gnus-summary-update-mark
3473          (if (or (null gnus-summary-default-score)
3474                  (<= (abs (- score gnus-summary-default-score))
3475                      gnus-summary-zcore-fuzz))
3476              ?                          ;Whitespace
3477            (if (< score gnus-summary-default-score)
3478                gnus-score-below-mark gnus-score-over-mark))
3479          'score))
3480       ;; Do visual highlighting.
3481       (when (gnus-visual-p 'summary-highlight 'highlight)
3482         (gnus-run-hooks 'gnus-summary-update-hook)))))
3483
3484 (defvar gnus-tmp-new-adopts nil)
3485
3486 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3487   "Return the number of articles in THREAD.
3488 This may be 0 in some cases -- if none of the articles in
3489 the thread are to be displayed."
3490   (let* ((number
3491          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3492           (cond
3493            ((not (listp thread))
3494             1)
3495            ((and (consp thread) (cdr thread))
3496             (apply
3497              '+ 1 (mapcar
3498                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3499            ((null thread)
3500             1)
3501            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3502             1)
3503            (t 0))))
3504     (when (and level (zerop level) gnus-tmp-new-adopts)
3505       (incf number
3506             (apply '+ (mapcar
3507                        'gnus-summary-number-of-articles-in-thread
3508                        gnus-tmp-new-adopts))))
3509     (if char
3510         (if (> number 1) gnus-not-empty-thread-mark
3511           gnus-empty-thread-mark)
3512       number)))
3513
3514 (defsubst gnus-summary-line-message-size (head)
3515   "Return pretty-printed version of message size.
3516 This function is intended to be used in
3517 `gnus-summary-line-format-alist'."
3518   (let ((c (or (mail-header-chars head) -1)))
3519     (cond ((< c 0) "n/a")               ; chars not available
3520           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3521           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3522           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3523           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3524
3525
3526 (defun gnus-summary-set-local-parameters (group)
3527   "Go through the local params of GROUP and set all variable specs in that list."
3528   (let ((vars '(quit-config)))          ; Ignore quit-config.
3529     (dolist (elem (gnus-group-find-parameter group))
3530       (and (consp elem)                 ; Has to be a cons.
3531            (consp (cdr elem))           ; The cdr has to be a list.
3532            (symbolp (car elem))         ; Has to be a symbol in there.
3533            (not (memq (car elem) vars))
3534            (ignore-errors               ; So we set it.
3535              (push (car elem) vars)
3536              (make-local-variable (car elem))
3537              (set (car elem) (eval (nth 1 elem))))))))
3538
3539 (defun gnus-summary-read-group (group &optional show-all no-article
3540                                       kill-buffer no-display backward
3541                                       select-articles)
3542   "Start reading news in newsgroup GROUP.
3543 If SHOW-ALL is non-nil, already read articles are also listed.
3544 If NO-ARTICLE is non-nil, no article is selected initially.
3545 If NO-DISPLAY, don't generate a summary buffer."
3546   (let (result)
3547     (while (and group
3548                 (null (setq result
3549                             (let ((gnus-auto-select-next nil))
3550                               (or (gnus-summary-read-group-1
3551                                    group show-all no-article
3552                                    kill-buffer no-display
3553                                    select-articles)
3554                                   (setq show-all nil
3555                                         select-articles nil)))))
3556                 (eq gnus-auto-select-next 'quietly))
3557       (set-buffer gnus-group-buffer)
3558       ;; The entry function called above goes to the next
3559       ;; group automatically, so we go two groups back
3560       ;; if we are searching for the previous group.
3561       (when backward
3562         (gnus-group-prev-unread-group 2))
3563       (if (not (equal group (gnus-group-group-name)))
3564           (setq group (gnus-group-group-name))
3565         (setq group nil)))
3566     result))
3567
3568 (defun gnus-summary-read-group-1 (group show-all no-article
3569                                         kill-buffer no-display
3570                                         &optional select-articles)
3571   ;; Killed foreign groups can't be entered.
3572   ;;  (when (and (not (gnus-group-native-p group))
3573   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3574   ;;    (error "Dead non-native groups can't be entered"))
3575   (gnus-message 5 "Retrieving newsgroup: %s..."
3576                 (gnus-group-decoded-name group))
3577   (let* ((new-group (gnus-summary-setup-buffer group))
3578          (quit-config (gnus-group-quit-config group))
3579          (did-select (and new-group (gnus-select-newsgroup
3580                                      group show-all select-articles))))
3581     (cond
3582      ;; This summary buffer exists already, so we just select it.
3583      ((not new-group)
3584       (gnus-set-global-variables)
3585       (when kill-buffer
3586         (gnus-kill-or-deaden-summary kill-buffer))
3587       (gnus-configure-windows 'summary 'force)
3588       (gnus-set-mode-line 'summary)
3589       (gnus-summary-position-point)
3590       (message "")
3591       t)
3592      ;; We couldn't select this group.
3593      ((null did-select)
3594       (when (and (eq major-mode 'gnus-summary-mode)
3595                  (not (equal (current-buffer) kill-buffer)))
3596         (kill-buffer (current-buffer))
3597         (if (not quit-config)
3598             (progn
3599               ;; Update the info -- marks might need to be removed,
3600               ;; for instance.
3601               (gnus-summary-update-info)
3602               (set-buffer gnus-group-buffer)
3603               (gnus-group-jump-to-group group)
3604               (gnus-group-next-unread-group 1))
3605           (gnus-handle-ephemeral-exit quit-config)))
3606       (let ((grpinfo (gnus-get-info group)))
3607         (if (null (gnus-info-read grpinfo))
3608             (gnus-message 3 "Group %s contains no messages"
3609                           (gnus-group-decoded-name group))
3610           (gnus-message 3 "Can't select group")))
3611       nil)
3612      ;; The user did a `C-g' while prompting for number of articles,
3613      ;; so we exit this group.
3614      ((eq did-select 'quit)
3615       (and (eq major-mode 'gnus-summary-mode)
3616            (not (equal (current-buffer) kill-buffer))
3617            (kill-buffer (current-buffer)))
3618       (when kill-buffer
3619         (gnus-kill-or-deaden-summary kill-buffer))
3620       (if (not quit-config)
3621           (progn
3622             (set-buffer gnus-group-buffer)
3623             (gnus-group-jump-to-group group)
3624             (gnus-group-next-unread-group 1)
3625             (gnus-configure-windows 'group 'force))
3626         (gnus-handle-ephemeral-exit quit-config))
3627       ;; Finally signal the quit.
3628       (signal 'quit nil))
3629      ;; The group was successfully selected.
3630      (t
3631       (gnus-set-global-variables)
3632       ;; Save the active value in effect when the group was entered.
3633       (setq gnus-newsgroup-active
3634             (gnus-copy-sequence
3635              (gnus-active gnus-newsgroup-name)))
3636       ;; You can change the summary buffer in some way with this hook.
3637       (gnus-run-hooks 'gnus-select-group-hook)
3638       (when (memq 'summary (gnus-update-format-specifications
3639                             nil 'summary 'summary-mode 'summary-dummy))
3640         ;; The format specification for the summary line was updated,
3641         ;; so we need to update the mark positions as well.
3642         (gnus-update-summary-mark-positions))
3643       ;; Do score processing.
3644       (when gnus-use-scoring
3645         (gnus-possibly-score-headers))
3646       ;; Check whether to fill in the gaps in the threads.
3647       (when gnus-build-sparse-threads
3648         (gnus-build-sparse-threads))
3649       ;; Find the initial limit.
3650       (if show-all
3651           (let ((gnus-newsgroup-dormant nil))
3652             (gnus-summary-initial-limit show-all))
3653         (gnus-summary-initial-limit show-all))
3654       ;; Generate the summary buffer.
3655       (unless no-display
3656         (gnus-summary-prepare))
3657       (when gnus-use-trees
3658         (gnus-tree-open group)
3659         (setq gnus-summary-highlight-line-function
3660               'gnus-tree-highlight-article))
3661       ;; If the summary buffer is empty, but there are some low-scored
3662       ;; articles or some excluded dormants, we include these in the
3663       ;; buffer.
3664       (when (and (zerop (buffer-size))
3665                  (not no-display))
3666         (cond (gnus-newsgroup-dormant
3667                (gnus-summary-limit-include-dormant))
3668               ((and gnus-newsgroup-scored show-all)
3669                (gnus-summary-limit-include-expunged t))))
3670       ;; Function `gnus-apply-kill-file' must be called in this hook.
3671       (gnus-run-hooks 'gnus-apply-kill-hook)
3672       (if (and (zerop (buffer-size))
3673                (not no-display))
3674           (progn
3675             ;; This newsgroup is empty.
3676             (gnus-summary-catchup-and-exit nil t)
3677             (gnus-message 6 "No unread news")
3678             (when kill-buffer
3679               (gnus-kill-or-deaden-summary kill-buffer))
3680             ;; Return nil from this function.
3681             nil)
3682         ;; Hide conversation thread subtrees.  We cannot do this in
3683         ;; gnus-summary-prepare-hook since kill processing may not
3684         ;; work with hidden articles.
3685         (gnus-summary-maybe-hide-threads)
3686         (when kill-buffer
3687           (gnus-kill-or-deaden-summary kill-buffer))
3688         (gnus-summary-auto-select-subject)
3689         ;; Show first unread article if requested.
3690         (if (and (not no-article)
3691                  (not no-display)
3692                  gnus-newsgroup-unreads
3693                  gnus-auto-select-first)
3694             (progn
3695               (gnus-configure-windows 'summary)
3696               (let ((art (gnus-summary-article-number)))
3697                 (unless (and (not gnus-plugged)
3698                              (or (memq art gnus-newsgroup-undownloaded)
3699                                  (memq art gnus-newsgroup-downloadable)))
3700                   (gnus-summary-goto-article art))))
3701           ;; Don't select any articles.
3702           (gnus-summary-position-point)
3703           (gnus-configure-windows 'summary 'force)
3704           (gnus-set-mode-line 'summary))
3705         (when (and gnus-auto-center-group
3706                    (get-buffer-window gnus-group-buffer t))
3707           ;; Gotta use windows, because recenter does weird stuff if
3708           ;; the current buffer ain't the displayed window.
3709           (let ((owin (selected-window)))
3710             (select-window (get-buffer-window gnus-group-buffer t))
3711             (when (gnus-group-goto-group group)
3712               (recenter))
3713             (select-window owin)))
3714         ;; Mark this buffer as "prepared".
3715         (setq gnus-newsgroup-prepared t)
3716         (gnus-run-hooks 'gnus-summary-prepared-hook)
3717         (unless (gnus-ephemeral-group-p group)
3718           (gnus-group-update-group group))
3719         t)))))
3720
3721 (defun gnus-summary-auto-select-subject ()
3722   "Select the subject line on initial group entry."
3723   (goto-char (point-min))
3724   (cond
3725    ((eq gnus-auto-select-subject 'best)
3726     (gnus-summary-best-unread-subject))
3727    ((eq gnus-auto-select-subject 'unread)
3728     (gnus-summary-first-unread-subject))
3729    ((eq gnus-auto-select-subject 'unseen)
3730     (gnus-summary-first-unseen-subject))
3731    ((eq gnus-auto-select-subject 'unseen-or-unread)
3732     (gnus-summary-first-unseen-or-unread-subject))
3733    ((eq gnus-auto-select-subject 'first)
3734     ;; Do nothing.
3735     )
3736    ((functionp gnus-auto-select-subject)
3737     (funcall gnus-auto-select-subject))))
3738
3739 (defun gnus-summary-prepare ()
3740   "Generate the summary buffer."
3741   (interactive)
3742   (let ((buffer-read-only nil))
3743     (erase-buffer)
3744     (setq gnus-newsgroup-data nil
3745           gnus-newsgroup-data-reverse nil)
3746     (gnus-run-hooks 'gnus-summary-generate-hook)
3747     ;; Generate the buffer, either with threads or without.
3748     (when gnus-newsgroup-headers
3749       (gnus-summary-prepare-threads
3750        (if gnus-show-threads
3751            (gnus-sort-gathered-threads
3752             (funcall gnus-summary-thread-gathering-function
3753                      (gnus-sort-threads
3754                       (gnus-cut-threads (gnus-make-threads)))))
3755          ;; Unthreaded display.
3756          (gnus-sort-articles gnus-newsgroup-headers))))
3757     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3758     ;; Call hooks for modifying summary buffer.
3759     (goto-char (point-min))
3760     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3761
3762 (defsubst gnus-general-simplify-subject (subject)
3763   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3764   (setq subject
3765         (cond
3766          ;; Truncate the subject.
3767          (gnus-simplify-subject-functions
3768           (gnus-map-function gnus-simplify-subject-functions subject))
3769          ((numberp gnus-summary-gather-subject-limit)
3770           (setq subject (gnus-simplify-subject-re subject))
3771           (if (> (length subject) gnus-summary-gather-subject-limit)
3772               (substring subject 0 gnus-summary-gather-subject-limit)
3773             subject))
3774          ;; Fuzzily simplify it.
3775          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3776           (gnus-simplify-subject-fuzzy subject))
3777          ;; Just remove the leading "Re:".
3778          (t
3779           (gnus-simplify-subject-re subject))))
3780
3781   (if (and gnus-summary-gather-exclude-subject
3782            (string-match gnus-summary-gather-exclude-subject subject))
3783       nil                         ; This article shouldn't be gathered
3784     subject))
3785
3786 (defun gnus-summary-simplify-subject-query ()
3787   "Query where the respool algorithm would put this article."
3788   (interactive)
3789   (gnus-summary-select-article)
3790   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3791
3792 (defun gnus-gather-threads-by-subject (threads)
3793   "Gather threads by looking at Subject headers."
3794   (if (not gnus-summary-make-false-root)
3795       threads
3796     (let ((hashtb (gnus-make-hashtable 1024))
3797           (prev threads)
3798           (result threads)
3799           subject hthread whole-subject)
3800       (while threads
3801         (setq subject (gnus-general-simplify-subject
3802                        (setq whole-subject (mail-header-subject
3803                                             (caar threads)))))
3804         (when subject
3805           (if (setq hthread (gnus-gethash subject hashtb))
3806               (progn
3807                 ;; We enter a dummy root into the thread, if we
3808                 ;; haven't done that already.
3809                 (unless (stringp (caar hthread))
3810                   (setcar hthread (list whole-subject (car hthread))))
3811                 ;; We add this new gathered thread to this gathered
3812                 ;; thread.
3813                 (setcdr (car hthread)
3814                         (nconc (cdar hthread) (list (car threads))))
3815                 ;; Remove it from the list of threads.
3816                 (setcdr prev (cdr threads))
3817                 (setq threads prev))
3818             ;; Enter this thread into the hash table.
3819             (gnus-sethash subject
3820                           (if gnus-summary-make-false-root-always
3821                               (progn
3822                                 ;; If you want a dummy root above all
3823                                 ;; threads...
3824                                 (setcar threads (list whole-subject
3825                                                       (car threads)))
3826                                 threads)
3827                             threads)
3828                           hashtb)))
3829         (setq prev threads)
3830         (setq threads (cdr threads)))
3831       result)))
3832
3833 (defun gnus-gather-threads-by-references (threads)
3834   "Gather threads by looking at References headers."
3835   (let ((idhashtb (gnus-make-hashtable 1024))
3836         (thhashtb (gnus-make-hashtable 1024))
3837         (prev threads)
3838         (result threads)
3839         ids references id gthread gid entered ref)
3840     (while threads
3841       (when (setq references (mail-header-references (caar threads)))
3842         (setq id (mail-header-id (caar threads))
3843               ids (inline (gnus-split-references references))
3844               entered nil)
3845         (while (setq ref (pop ids))
3846           (setq ids (delete ref ids))
3847           (if (not (setq gid (gnus-gethash ref idhashtb)))
3848               (progn
3849                 (gnus-sethash ref id idhashtb)
3850                 (gnus-sethash id threads thhashtb))
3851             (setq gthread (gnus-gethash gid thhashtb))
3852             (unless entered
3853               ;; We enter a dummy root into the thread, if we
3854               ;; haven't done that already.
3855               (unless (stringp (caar gthread))
3856                 (setcar gthread (list (mail-header-subject (caar gthread))
3857                                       (car gthread))))
3858               ;; We add this new gathered thread to this gathered
3859               ;; thread.
3860               (setcdr (car gthread)
3861                       (nconc (cdar gthread) (list (car threads)))))
3862             ;; Add it into the thread hash table.
3863             (gnus-sethash id gthread thhashtb)
3864             (setq entered t)
3865             ;; Remove it from the list of threads.
3866             (setcdr prev (cdr threads))
3867             (setq threads prev))))
3868       (setq prev threads)
3869       (setq threads (cdr threads)))
3870     result))
3871
3872 (defun gnus-sort-gathered-threads (threads)
3873   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3874   (let ((result threads))
3875     (while threads
3876       (when (stringp (caar threads))
3877         (setcdr (car threads)
3878                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3879       (setq threads (cdr threads)))
3880     result))
3881
3882 (defun gnus-thread-loop-p (root thread)
3883   "Say whether ROOT is in THREAD."
3884   (let ((stack (list thread))
3885         (infloop 0)
3886         th)
3887     (while (setq thread (pop stack))
3888       (setq th (cdr thread))
3889       (while (and th
3890                   (not (eq (caar th) root)))
3891         (pop th))
3892       (if th
3893           ;; We have found a loop.
3894           (let (ref-dep)
3895             (setcdr thread (delq (car th) (cdr thread)))
3896             (if (boundp (setq ref-dep (intern "none"
3897                                               gnus-newsgroup-dependencies)))
3898                 (setcdr (symbol-value ref-dep)
3899                         (nconc (cdr (symbol-value ref-dep))
3900                                (list (car th))))
3901               (set ref-dep (list nil (car th))))
3902             (setq infloop 1
3903                   stack nil))
3904         ;; Push all the subthreads onto the stack.
3905         (push (cdr thread) stack)))
3906     infloop))
3907
3908 (defun gnus-make-threads ()
3909   "Go through the dependency hashtb and find the roots.  Return all threads."
3910   (let (threads)
3911     (while (catch 'infloop
3912              (mapatoms
3913               (lambda (refs)
3914                 ;; Deal with self-referencing References loops.
3915                 (when (and (car (symbol-value refs))
3916                            (not (zerop
3917                                  (apply
3918                                   '+
3919                                   (mapcar
3920                                    (lambda (thread)
3921                                      (gnus-thread-loop-p
3922                                       (car (symbol-value refs)) thread))
3923                                    (cdr (symbol-value refs)))))))
3924                   (setq threads nil)
3925                   (throw 'infloop t))
3926                 (unless (car (symbol-value refs))
3927                   ;; These threads do not refer back to any other
3928                   ;; articles, so they're roots.
3929                   (setq threads (append (cdr (symbol-value refs)) threads))))
3930               gnus-newsgroup-dependencies)))
3931     threads))
3932
3933 ;; Build the thread tree.
3934 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3935   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3936
3937 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3938 if it was already present.
3939
3940 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3941 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3942 Message-IDs will be renamed to a unique Message-ID before being
3943 entered.
3944
3945 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3946   (let* ((id (mail-header-id header))
3947          (id-dep (and id (intern id dependencies)))
3948          parent-id ref ref-dep ref-header replaced)
3949     ;; Enter this `header' in the `dependencies' table.
3950     (cond
3951      ((not id-dep)
3952       (setq header nil))
3953      ;; The first two cases do the normal part: enter a new `header'
3954      ;; in the `dependencies' table.
3955      ((not (boundp id-dep))
3956       (set id-dep (list header)))
3957      ((null (car (symbol-value id-dep)))
3958       (setcar (symbol-value id-dep) header))
3959
3960      ;; From here the `header' was already present in the
3961      ;; `dependencies' table.
3962      (force-new
3963       ;; Overrides an existing entry;
3964       ;; just set the header part of the entry.
3965       (setcar (symbol-value id-dep) header)
3966       (setq replaced t))
3967
3968      ;; Renames the existing `header' to a unique Message-ID.
3969      ((not gnus-summary-ignore-duplicates)
3970       ;; An article with this Message-ID has already been seen.
3971       ;; We rename the Message-ID.
3972       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3973            (list header))
3974       (mail-header-set-id header id))
3975
3976      ;; The last case ignores an existing entry, except it adds any
3977      ;; additional Xrefs (in case the two articles came from different
3978      ;; servers.
3979      ;; Also sets `header' to `nil' meaning that the `dependencies'
3980      ;; table was *not* modified.
3981      (t
3982       (mail-header-set-xref
3983        (car (symbol-value id-dep))
3984        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3985                    "")
3986                (or (mail-header-xref header) "")))
3987       (setq header nil)))
3988
3989     (when (and header (not replaced))
3990       ;; First check that we are not creating a References loop.
3991       (setq parent-id (gnus-parent-id (mail-header-references header)))
3992       (setq ref parent-id)
3993       (while (and ref
3994                   (setq ref-dep (intern-soft ref dependencies))
3995                   (boundp ref-dep)
3996                   (setq ref-header (car (symbol-value ref-dep))))
3997         (if (string= id ref)
3998             ;; Yuk!  This is a reference loop.  Make the article be a
3999             ;; root article.
4000             (progn
4001               (mail-header-set-references (car (symbol-value id-dep)) "none")
4002               (setq ref nil)
4003               (setq parent-id nil))
4004           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4005       (setq ref-dep (intern (or parent-id "none") dependencies))
4006       (if (boundp ref-dep)
4007           (setcdr (symbol-value ref-dep)
4008                   (nconc (cdr (symbol-value ref-dep))
4009                          (list (symbol-value id-dep))))
4010         (set ref-dep (list nil (symbol-value id-dep)))))
4011     header))
4012
4013 (defun gnus-extract-message-id-from-in-reply-to (string)
4014   (if (string-match "<[^>]+>" string)
4015       (substring string (match-beginning 0) (match-end 0))
4016     nil))
4017
4018 (defun gnus-build-sparse-threads ()
4019   (let ((headers gnus-newsgroup-headers)
4020         (mail-parse-charset gnus-newsgroup-charset)
4021         (gnus-summary-ignore-duplicates t)
4022         header references generation relations
4023         subject child end new-child date)
4024     ;; First we create an alist of generations/relations, where
4025     ;; generations is how much we trust the relation, and the relation
4026     ;; is parent/child.
4027     (gnus-message 7 "Making sparse threads...")
4028     (save-excursion
4029       (nnheader-set-temp-buffer " *gnus sparse threads*")
4030       (while (setq header (pop headers))
4031         (when (and (setq references (mail-header-references header))
4032                    (not (string= references "")))
4033           (insert references)
4034           (setq child (mail-header-id header)
4035                 subject (mail-header-subject header)
4036                 date (mail-header-date header)
4037                 generation 0)
4038           (while (search-backward ">" nil t)
4039             (setq end (1+ (point)))
4040             (when (search-backward "<" nil t)
4041               (setq new-child (buffer-substring (point) end))
4042               (push (list (incf generation)
4043                           child (setq child new-child)
4044                           subject date)
4045                     relations)))
4046           (when child
4047             (push (list (1+ generation) child nil subject) relations))
4048           (erase-buffer)))
4049       (kill-buffer (current-buffer)))
4050     ;; Sort over trustworthiness.
4051     (mapcar
4052      (lambda (relation)
4053        (when (gnus-dependencies-add-header
4054               (make-full-mail-header
4055                gnus-reffed-article-number
4056                (nth 3 relation) "" (or (nth 4 relation) "")
4057                (nth 1 relation)
4058                (or (nth 2 relation) "") 0 0 "")
4059               gnus-newsgroup-dependencies nil)
4060          (push gnus-reffed-article-number gnus-newsgroup-limit)
4061          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4062          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4063                gnus-newsgroup-reads)
4064          (decf gnus-reffed-article-number)))
4065      (sort relations 'car-less-than-car))
4066     (gnus-message 7 "Making sparse threads...done")))
4067
4068 (defun gnus-build-old-threads ()
4069   ;; Look at all the articles that refer back to old articles, and
4070   ;; fetch the headers for the articles that aren't there.  This will
4071   ;; build complete threads - if the roots haven't been expired by the
4072   ;; server, that is.
4073   (let ((mail-parse-charset gnus-newsgroup-charset)
4074         id heads)
4075     (mapatoms
4076      (lambda (refs)
4077        (when (not (car (symbol-value refs)))
4078          (setq heads (cdr (symbol-value refs)))
4079          (while heads
4080            (if (memq (mail-header-number (caar heads))
4081                      gnus-newsgroup-dormant)
4082                (setq heads (cdr heads))
4083              (setq id (symbol-name refs))
4084              (while (and (setq id (gnus-build-get-header id))
4085                          (not (car (gnus-id-to-thread id)))))
4086              (setq heads nil)))))
4087      gnus-newsgroup-dependencies)))
4088
4089 (defsubst gnus-remove-odd-characters (string)
4090   "Translate STRING into something that doesn't contain weird characters."
4091   (mm-subst-char-in-string
4092    ?\r ?\-
4093    (mm-subst-char-in-string ?\n ?\- string t) t))
4094
4095 ;; This function has to be called with point after the article number
4096 ;; on the beginning of the line.
4097 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4098   (let ((eol (point-at-eol))
4099         (buffer (current-buffer))
4100         header references in-reply-to)
4101
4102     ;; overview: [num subject from date id refs chars lines misc]
4103     (unwind-protect
4104         (let (x)
4105           (narrow-to-region (point) eol)
4106           (unless (eobp)
4107             (forward-char))
4108
4109           (setq header
4110                 (make-full-mail-header
4111                  number                 ; number
4112                  (condition-case ()     ; subject
4113                      (gnus-remove-odd-characters
4114                       (funcall gnus-decode-encoded-word-function
4115                                (setq x (nnheader-nov-field))))
4116                    (error x))
4117                  (condition-case ()     ; from
4118                      (gnus-remove-odd-characters
4119                       (funcall gnus-decode-encoded-word-function
4120                                (setq x (nnheader-nov-field))))
4121                    (error x))
4122                  (nnheader-nov-field)   ; date
4123                  (nnheader-nov-read-message-id number)  ; id
4124                  (setq references (nnheader-nov-field)) ; refs
4125                  (nnheader-nov-read-integer) ; chars
4126                  (nnheader-nov-read-integer) ; lines
4127                  (unless (eobp)
4128                    (if (looking-at "Xref: ")
4129                        (goto-char (match-end 0)))
4130                    (nnheader-nov-field)) ; Xref
4131                  (nnheader-nov-parse-extra)))) ; extra
4132
4133       (widen))
4134
4135     (when (and (string= references "")
4136                (setq in-reply-to (mail-header-extra header))
4137                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4138       (mail-header-set-references
4139        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4140
4141     (when gnus-alter-header-function
4142       (funcall gnus-alter-header-function header))
4143     (gnus-dependencies-add-header header dependencies force-new)))
4144
4145 (defun gnus-build-get-header (id)
4146   "Look through the buffer of NOV lines and find the header to ID.
4147 Enter this line into the dependencies hash table, and return
4148 the id of the parent article (if any)."
4149   (let ((deps gnus-newsgroup-dependencies)
4150         found header)
4151     (prog1
4152         (save-excursion
4153           (set-buffer nntp-server-buffer)
4154           (let ((case-fold-search nil))
4155             (goto-char (point-min))
4156             (while (and (not found)
4157                         (search-forward id nil t))
4158               (beginning-of-line)
4159               (setq found (looking-at
4160                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4161                                    (regexp-quote id))))
4162               (or found (beginning-of-line 2)))
4163             (when found
4164               (beginning-of-line)
4165               (and
4166                (setq header (gnus-nov-parse-line
4167                              (read (current-buffer)) deps))
4168                (gnus-parent-id (mail-header-references header))))))
4169       (when header
4170         (let ((number (mail-header-number header)))
4171           (push number gnus-newsgroup-limit)
4172           (push header gnus-newsgroup-headers)
4173           (if (memq number gnus-newsgroup-unselected)
4174               (progn
4175                 (setq gnus-newsgroup-unreads
4176                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4177                                                number))
4178                 (setq gnus-newsgroup-unselected
4179                       (delq number gnus-newsgroup-unselected)))
4180             (push number gnus-newsgroup-ancient)))))))
4181
4182 (defun gnus-build-all-threads ()
4183   "Read all the headers."
4184   (let ((gnus-summary-ignore-duplicates t)
4185         (mail-parse-charset gnus-newsgroup-charset)
4186         (dependencies gnus-newsgroup-dependencies)
4187         header article)
4188     (save-excursion
4189       (set-buffer nntp-server-buffer)
4190       (let ((case-fold-search nil))
4191         (goto-char (point-min))
4192         (while (not (eobp))
4193           (ignore-errors
4194             (setq article (read (current-buffer))
4195                   header (gnus-nov-parse-line article dependencies)))
4196           (when header
4197             (with-current-buffer gnus-summary-buffer
4198               (push header gnus-newsgroup-headers)
4199               (if (memq (setq article (mail-header-number header))
4200                         gnus-newsgroup-unselected)
4201                   (progn
4202                     (setq gnus-newsgroup-unreads
4203                           (gnus-add-to-sorted-list
4204                            gnus-newsgroup-unreads article))
4205                     (setq gnus-newsgroup-unselected
4206                           (delq article gnus-newsgroup-unselected)))
4207                 (push article gnus-newsgroup-ancient)))
4208             (forward-line 1)))))))
4209
4210 (defun gnus-summary-update-article-line (article header)
4211   "Update the line for ARTICLE using HEADER."
4212   (let* ((id (mail-header-id header))
4213          (thread (gnus-id-to-thread id)))
4214     (unless thread
4215       (error "Article in no thread"))
4216     ;; Update the thread.
4217     (setcar thread header)
4218     (gnus-summary-goto-subject article)
4219     (let* ((datal (gnus-data-find-list article))
4220            (data (car datal))
4221            (buffer-read-only nil)
4222            (level (gnus-summary-thread-level)))
4223       (gnus-delete-line)
4224       (let ((inserted (- (point)
4225                          (progn
4226                            (gnus-summary-insert-line
4227                             header level nil
4228                             (memq article gnus-newsgroup-undownloaded)
4229                             (gnus-article-mark article)
4230                             (memq article gnus-newsgroup-replied)
4231                             (memq article gnus-newsgroup-expirable)
4232                             ;; Only insert the Subject string when it's different
4233                             ;; from the previous Subject string.
4234                             (if (and
4235                                  gnus-show-threads
4236                                  (gnus-subject-equal
4237                                   (condition-case ()
4238                                       (mail-header-subject
4239                                        (gnus-data-header
4240                                         (cadr
4241                                          (gnus-data-find-list
4242                                           article
4243                                           (gnus-data-list t)))))
4244                                     ;; Error on the side of excessive subjects.
4245                                     (error ""))
4246                                   (mail-header-subject header)))
4247                                 ""
4248                               (mail-header-subject header))
4249                             nil (cdr (assq article gnus-newsgroup-scored))
4250                             (memq article gnus-newsgroup-processable))
4251                            (point)))))
4252         (when (cdr datal)
4253           (gnus-data-update-list
4254            (cdr datal)
4255            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4256
4257 (defun gnus-summary-update-article (article &optional iheader)
4258   "Update ARTICLE in the summary buffer."
4259   (set-buffer gnus-summary-buffer)
4260   (let* ((header (gnus-summary-article-header article))
4261          (id (mail-header-id header))
4262          (data (gnus-data-find article))
4263          (thread (gnus-id-to-thread id))
4264          (references (mail-header-references header))
4265          (parent
4266           (gnus-id-to-thread
4267            (or (gnus-parent-id
4268                 (when (and references
4269                            (not (equal "" references)))
4270                   references))
4271                "none")))
4272          (buffer-read-only nil)
4273          (old (car thread)))
4274     (when thread
4275       (unless iheader
4276         (setcar thread nil)
4277         (when parent
4278           (delq thread parent)))
4279       (if (gnus-summary-insert-subject id header)
4280           ;; Set the (possibly) new article number in the data structure.
4281           (gnus-data-set-number data (gnus-id-to-article id))
4282         (setcar thread old)
4283         nil))))
4284
4285 (defun gnus-rebuild-thread (id &optional line)
4286   "Rebuild the thread containing ID.
4287 If LINE, insert the rebuilt thread starting on line LINE."
4288   (let ((buffer-read-only nil)
4289         old-pos current thread data)
4290     (if (not gnus-show-threads)
4291         (setq thread (list (car (gnus-id-to-thread id))))
4292       ;; Get the thread this article is part of.
4293       (setq thread (gnus-remove-thread id)))
4294     (setq old-pos (point-at-bol))
4295     (setq current (save-excursion
4296                     (and (re-search-backward "[\r\n]" nil t)
4297                          (gnus-summary-article-number))))
4298     ;; If this is a gathered thread, we have to go some re-gathering.
4299     (when (stringp (car thread))
4300       (let ((subject (car thread))
4301             roots thr)
4302         (setq thread (cdr thread))
4303         (while thread
4304           (unless (memq (setq thr (gnus-id-to-thread
4305                                    (gnus-root-id
4306                                     (mail-header-id (caar thread)))))
4307                         roots)
4308             (push thr roots))
4309           (setq thread (cdr thread)))
4310         ;; We now have all (unique) roots.
4311         (if (= (length roots) 1)
4312             ;; All the loose roots are now one solid root.
4313             (setq thread (car roots))
4314           (setq thread (cons subject (gnus-sort-threads roots))))))
4315     (let (threads)
4316       ;; We then insert this thread into the summary buffer.
4317       (when line
4318         (goto-char (point-min))
4319         (forward-line (1- line)))
4320       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4321         (if gnus-show-threads
4322             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4323           (gnus-summary-prepare-unthreaded thread))
4324         (setq data (nreverse gnus-newsgroup-data))
4325         (setq threads gnus-newsgroup-threads))
4326       ;; We splice the new data into the data structure.
4327       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4328       ;;!!! then we want to insert at the beginning of the buffer.
4329       ;;!!! That happens to be true with Gnus now, but that may
4330       ;;!!! change in the future.  Perhaps.
4331       (gnus-data-enter-list
4332        (if line nil current) data (- (point) old-pos))
4333       (setq gnus-newsgroup-threads
4334             (nconc threads gnus-newsgroup-threads))
4335       (gnus-data-compute-positions))))
4336
4337 (defun gnus-number-to-header (number)
4338   "Return the header for article NUMBER."
4339   (let ((headers gnus-newsgroup-headers))
4340     (while (and headers
4341                 (not (= number (mail-header-number (car headers)))))
4342       (pop headers))
4343     (when headers
4344       (car headers))))
4345
4346 (defun gnus-parent-headers (in-headers &optional generation)
4347   "Return the headers of the GENERATIONeth parent of HEADERS."
4348   (unless generation
4349     (setq generation 1))
4350   (let ((parent t)
4351         (headers in-headers)
4352         references)
4353     (while (and parent
4354                 (not (zerop generation))
4355                 (setq references (mail-header-references headers)))
4356       (setq headers (if (and references
4357                              (setq parent (gnus-parent-id references)))
4358                         (car (gnus-id-to-thread parent))
4359                       nil))
4360       (decf generation))
4361     (and (not (eq headers in-headers))
4362          headers)))
4363
4364 (defun gnus-id-to-thread (id)
4365   "Return the (sub-)thread where ID appears."
4366   (gnus-gethash id gnus-newsgroup-dependencies))
4367
4368 (defun gnus-id-to-article (id)
4369   "Return the article number of ID."
4370   (let ((thread (gnus-id-to-thread id)))
4371     (when (and thread
4372                (car thread))
4373       (mail-header-number (car thread)))))
4374
4375 (defun gnus-id-to-header (id)
4376   "Return the article headers of ID."
4377   (car (gnus-id-to-thread id)))
4378
4379 (defun gnus-article-displayed-root-p (article)
4380   "Say whether ARTICLE is a root(ish) article."
4381   (let ((level (gnus-summary-thread-level article))
4382         (refs (mail-header-references  (gnus-summary-article-header article)))
4383         particle)
4384     (cond
4385      ((null level) nil)
4386      ((zerop level) t)
4387      ((null refs) t)
4388      ((null (gnus-parent-id refs)) t)
4389      ((and (= 1 level)
4390            (null (setq particle (gnus-id-to-article
4391                                  (gnus-parent-id refs))))
4392            (null (gnus-summary-thread-level particle)))))))
4393
4394 (defun gnus-root-id (id)
4395   "Return the id of the root of the thread where ID appears."
4396   (let (last-id prev)
4397     (while (and id (setq prev (car (gnus-id-to-thread id))))
4398       (setq last-id id
4399             id (gnus-parent-id (mail-header-references prev))))
4400     last-id))
4401
4402 (defun gnus-articles-in-thread (thread)
4403   "Return the list of articles in THREAD."
4404   (cons (mail-header-number (car thread))
4405         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4406
4407 (defun gnus-remove-thread (id &optional dont-remove)
4408   "Remove the thread that has ID in it."
4409   (let (headers thread last-id)
4410     ;; First go up in this thread until we find the root.
4411     (setq last-id (gnus-root-id id)
4412           headers (message-flatten-list (gnus-id-to-thread last-id)))
4413     ;; We have now found the real root of this thread.  It might have
4414     ;; been gathered into some loose thread, so we have to search
4415     ;; through the threads to find the thread we wanted.
4416     (let ((threads gnus-newsgroup-threads)
4417           sub)
4418       (while threads
4419         (setq sub (car threads))
4420         (if (stringp (car sub))
4421             ;; This is a gathered thread, so we look at the roots
4422             ;; below it to find whether this article is in this
4423             ;; gathered root.
4424             (progn
4425               (setq sub (cdr sub))
4426               (while sub
4427                 (when (member (caar sub) headers)
4428                   (setq thread (car threads)
4429                         threads nil
4430                         sub nil))
4431                 (setq sub (cdr sub))))
4432           ;; It's an ordinary thread, so we check it.
4433           (when (eq (car sub) (car headers))
4434             (setq thread sub
4435                   threads nil)))
4436         (setq threads (cdr threads)))
4437       ;; If this article is in no thread, then it's a root.
4438       (if thread
4439           (unless dont-remove
4440             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4441         (setq thread (gnus-id-to-thread last-id)))
4442       (when thread
4443         (prog1
4444             thread                      ; We return this thread.
4445           (unless dont-remove
4446             (if (stringp (car thread))
4447                 (progn
4448                   ;; If we use dummy roots, then we have to remove the
4449                   ;; dummy root as well.
4450                   (when (eq gnus-summary-make-false-root 'dummy)
4451                     ;; We go to the dummy root by going to
4452                     ;; the first sub-"thread", and then one line up.
4453                     (gnus-summary-goto-article
4454                      (mail-header-number (caadr thread)))
4455                     (forward-line -1)
4456                     (gnus-delete-line)
4457                     (gnus-data-compute-positions))
4458                   (setq thread (cdr thread))
4459                   (while thread
4460                     (gnus-remove-thread-1 (car thread))
4461                     (setq thread (cdr thread))))
4462               (gnus-remove-thread-1 thread))))))))
4463
4464 (defun gnus-remove-thread-1 (thread)
4465   "Remove the thread THREAD recursively."
4466   (let ((number (mail-header-number (pop thread)))
4467         d)
4468     (setq thread (reverse thread))
4469     (while thread
4470       (gnus-remove-thread-1 (pop thread)))
4471     (when (setq d (gnus-data-find number))
4472       (goto-char (gnus-data-pos d))
4473       (gnus-summary-show-thread)
4474       (gnus-data-remove
4475        number
4476        (- (point-at-bol)
4477           (prog1
4478               (1+ (point-at-eol))
4479             (gnus-delete-line)))))))
4480
4481 (defun gnus-sort-threads-1 (threads func)
4482   (sort (mapcar (lambda (thread)
4483                   (cons (car thread)
4484                         (and (cdr thread)
4485                              (gnus-sort-threads-1 (cdr thread) func))))
4486                 threads) func))
4487
4488 (defun gnus-sort-threads (threads)
4489   "Sort THREADS."
4490   (if (not gnus-thread-sort-functions)
4491       threads
4492     (gnus-message 8 "Sorting threads...")
4493     (let ((max-lisp-eval-depth 5000))
4494       (prog1 (gnus-sort-threads-1
4495          threads
4496          (gnus-make-sort-function gnus-thread-sort-functions))
4497         (gnus-message 8 "Sorting threads...done")))))
4498
4499 (defun gnus-sort-articles (articles)
4500   "Sort ARTICLES."
4501   (when gnus-article-sort-functions
4502     (gnus-message 7 "Sorting articles...")
4503     (prog1
4504         (setq gnus-newsgroup-headers
4505               (sort articles (gnus-make-sort-function
4506                               gnus-article-sort-functions)))
4507       (gnus-message 7 "Sorting articles...done"))))
4508
4509 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4510 (defmacro gnus-thread-header (thread)
4511   "Return header of first article in THREAD.
4512 Note that THREAD must never, ever be anything else than a variable -
4513 using some other form will lead to serious barfage."
4514   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4515   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4516   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4517         (vector thread) 2))
4518
4519 (defsubst gnus-article-sort-by-number (h1 h2)
4520   "Sort articles by article number."
4521   (< (mail-header-number h1)
4522      (mail-header-number h2)))
4523
4524 (defun gnus-thread-sort-by-number (h1 h2)
4525   "Sort threads by root article number."
4526   (gnus-article-sort-by-number
4527    (gnus-thread-header h1) (gnus-thread-header h2)))
4528
4529 (defsubst gnus-article-sort-by-random (h1 h2)
4530   "Sort articles by article number."
4531   (zerop (random 2)))
4532
4533 (defun gnus-thread-sort-by-random (h1 h2)
4534   "Sort threads by root article number."
4535   (gnus-article-sort-by-random
4536    (gnus-thread-header h1) (gnus-thread-header h2)))
4537
4538 (defsubst gnus-article-sort-by-lines (h1 h2)
4539   "Sort articles by article Lines header."
4540   (< (mail-header-lines h1)
4541      (mail-header-lines h2)))
4542
4543 (defun gnus-thread-sort-by-lines (h1 h2)
4544   "Sort threads by root article Lines header."
4545   (gnus-article-sort-by-lines
4546    (gnus-thread-header h1) (gnus-thread-header h2)))
4547
4548 (defsubst gnus-article-sort-by-chars (h1 h2)
4549   "Sort articles by octet length."
4550   (< (mail-header-chars h1)
4551      (mail-header-chars h2)))
4552
4553 (defun gnus-thread-sort-by-chars (h1 h2)
4554   "Sort threads by root article octet length."
4555   (gnus-article-sort-by-chars
4556    (gnus-thread-header h1) (gnus-thread-header h2)))
4557
4558 (defsubst gnus-article-sort-by-author (h1 h2)
4559   "Sort articles by root author."
4560   (string-lessp
4561    (let ((extract (funcall
4562                    gnus-extract-address-components
4563                    (mail-header-from h1))))
4564      (or (car extract) (cadr extract) ""))
4565    (let ((extract (funcall
4566                    gnus-extract-address-components
4567                    (mail-header-from h2))))
4568      (or (car extract) (cadr extract) ""))))
4569
4570 (defun gnus-thread-sort-by-author (h1 h2)
4571   "Sort threads by root author."
4572   (gnus-article-sort-by-author
4573    (gnus-thread-header h1)  (gnus-thread-header h2)))
4574
4575 (defsubst gnus-article-sort-by-recipient (h1 h2)
4576   "Sort articles by recipient."
4577   (string-lessp
4578    (let ((extract (funcall
4579                    gnus-extract-address-components
4580                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4581      (or (car extract) (cadr extract)))
4582    (let ((extract (funcall
4583                    gnus-extract-address-components
4584                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4585      (or (car extract) (cadr extract)))))
4586
4587 (defsubst gnus-article-sort-by-subject (h1 h2)
4588   "Sort articles by root subject."
4589   (string-lessp
4590    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4591    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4592
4593 (defun gnus-thread-sort-by-subject (h1 h2)
4594   "Sort threads by root subject."
4595   (gnus-article-sort-by-subject
4596    (gnus-thread-header h1) (gnus-thread-header h2)))
4597
4598 (defsubst gnus-article-sort-by-date (h1 h2)
4599   "Sort articles by root article date."
4600   (time-less-p
4601    (gnus-date-get-time (mail-header-date h1))
4602    (gnus-date-get-time (mail-header-date h2))))
4603
4604 (defun gnus-thread-sort-by-date (h1 h2)
4605   "Sort threads by root article date."
4606   (gnus-article-sort-by-date
4607    (gnus-thread-header h1) (gnus-thread-header h2)))
4608
4609 (defsubst gnus-article-sort-by-score (h1 h2)
4610   "Sort articles by root article score.
4611 Unscored articles will be counted as having a score of zero."
4612   (> (or (cdr (assq (mail-header-number h1)
4613                     gnus-newsgroup-scored))
4614          gnus-summary-default-score 0)
4615      (or (cdr (assq (mail-header-number h2)
4616                     gnus-newsgroup-scored))
4617          gnus-summary-default-score 0)))
4618
4619 (defun gnus-thread-sort-by-score (h1 h2)
4620   "Sort threads by root article score."
4621   (gnus-article-sort-by-score
4622    (gnus-thread-header h1) (gnus-thread-header h2)))
4623
4624 (defun gnus-thread-sort-by-total-score (h1 h2)
4625   "Sort threads by the sum of all scores in the thread.
4626 Unscored articles will be counted as having a score of zero."
4627   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4628
4629 (defun gnus-thread-total-score (thread)
4630   ;; This function find the total score of THREAD.
4631   (cond
4632    ((null thread)
4633     0)
4634    ((consp thread)
4635     (if (stringp (car thread))
4636         (apply gnus-thread-score-function 0
4637                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4638       (gnus-thread-total-score-1 thread)))
4639    (t
4640     (gnus-thread-total-score-1 (list thread)))))
4641
4642 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4643   "Sort threads such that the thread with the most recently arrived article comes first."
4644   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4645
4646 (defun gnus-thread-highest-number (thread)
4647   "Return the highest article number in THREAD."
4648   (apply 'max (mapcar (lambda (header)
4649                         (mail-header-number header))
4650                       (message-flatten-list thread))))
4651
4652 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4653   "Sort threads such that the thread with the most recently dated article comes first."
4654   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4655
4656 (defun gnus-thread-latest-date (thread)
4657   "Return the highest article date in THREAD."
4658   (let ((previous-time 0))
4659     (apply 'max
4660            (mapcar
4661             (lambda (header)
4662               (setq previous-time
4663                     (condition-case ()
4664                         (time-to-seconds (mail-header-parse-date
4665                                           (mail-header-date header)))
4666                       (error previous-time))))
4667             (sort
4668              (message-flatten-list thread)
4669              (lambda (h1 h2)
4670                (< (mail-header-number h1)
4671                   (mail-header-number h2))))))))
4672
4673 (defun gnus-thread-total-score-1 (root)
4674   ;; This function find the total score of the thread below ROOT.
4675   (setq root (car root))
4676   (apply gnus-thread-score-function
4677          (or (append
4678               (mapcar 'gnus-thread-total-score
4679                       (cdr (gnus-id-to-thread (mail-header-id root))))
4680               (when (> (mail-header-number root) 0)
4681                 (list (or (cdr (assq (mail-header-number root)
4682                                      gnus-newsgroup-scored))
4683                           gnus-summary-default-score 0))))
4684              (list gnus-summary-default-score)
4685              '(0))))
4686
4687 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4688 (defvar gnus-tmp-prev-subject nil)
4689 (defvar gnus-tmp-false-parent nil)
4690 (defvar gnus-tmp-root-expunged nil)
4691 (defvar gnus-tmp-dummy-line nil)
4692
4693 (eval-when-compile (defvar gnus-tmp-header))
4694 (defun gnus-extra-header (type &optional header)
4695   "Return the extra header of TYPE."
4696   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4697       ""))
4698
4699 (defvar gnus-tmp-thread-tree-header-string "")
4700
4701 (defcustom gnus-sum-thread-tree-root "> "
4702   "With %B spec, used for the root of a thread.
4703 If nil, use subject instead."
4704   :version "21.4"
4705   :type '(radio (const :format "%v  " nil) string)
4706   :group 'gnus-thread)
4707 (defcustom gnus-sum-thread-tree-false-root "> "
4708   "With %B spec, used for a false root of a thread.
4709 If nil, use subject instead."
4710   :version "21.4"
4711   :type '(radio (const :format "%v  " nil) string)
4712   :group 'gnus-thread)
4713 (defcustom gnus-sum-thread-tree-single-indent ""
4714   "With %B spec, used for a thread with just one message.
4715 If nil, use subject instead."
4716   :version "21.4"
4717   :type '(radio (const :format "%v  " nil) string)
4718   :group 'gnus-thread)
4719 (defcustom gnus-sum-thread-tree-vertical "| "
4720   "With %B spec, used for drawing a vertical line."
4721   :version "21.4"
4722   :type 'string
4723   :group 'gnus-thread)
4724 (defcustom gnus-sum-thread-tree-indent "  "
4725   "With %B spec, used for indenting."
4726   :version "21.4"
4727   :type 'string
4728   :group 'gnus-thread)
4729 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4730   "With %B spec, used for a leaf with brothers."
4731   :version "21.4"
4732   :type 'string
4733   :group 'gnus-thread)
4734 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4735   "With %B spec, used for a leaf without brothers."
4736   :version "21.4"
4737   :type 'string
4738   :group 'gnus-thread)
4739
4740 (defun gnus-summary-prepare-threads (threads)
4741   "Prepare summary buffer from THREADS and indentation LEVEL.
4742 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4743 or a straight list of headers."
4744   (gnus-message 7 "Generating summary...")
4745
4746   (setq gnus-newsgroup-threads threads)
4747   (beginning-of-line)
4748
4749   (let ((gnus-tmp-level 0)
4750         (default-score (or gnus-summary-default-score 0))
4751         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4752         (building-line-count gnus-summary-display-while-building)
4753         (building-count (integerp gnus-summary-display-while-building))
4754         thread number subject stack state gnus-tmp-gathered beg-match
4755         new-roots gnus-tmp-new-adopts thread-end simp-subject
4756         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4757         gnus-tmp-replied gnus-tmp-subject-or-nil
4758         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4759         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4760         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4761         tree-stack)
4762
4763     (setq gnus-tmp-prev-subject nil
4764           gnus-tmp-thread-tree-header-string "")
4765
4766     (if (vectorp (car threads))
4767         ;; If this is a straight (sic) list of headers, then a
4768         ;; threaded summary display isn't required, so we just create
4769         ;; an unthreaded one.
4770         (gnus-summary-prepare-unthreaded threads)
4771
4772       ;; Do the threaded display.
4773
4774       (if gnus-summary-display-while-building
4775           (switch-to-buffer (buffer-name)))
4776       (while (or threads stack gnus-tmp-new-adopts new-roots)
4777
4778         (if (and (= gnus-tmp-level 0)
4779                  (or (not stack)
4780                      (= (caar stack) 0))
4781                  (not gnus-tmp-false-parent)
4782                  (or gnus-tmp-new-adopts new-roots))
4783             (if gnus-tmp-new-adopts
4784                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4785                       thread (list (car gnus-tmp-new-adopts))
4786                       gnus-tmp-header (caar thread)
4787                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4788               (when new-roots
4789                 (setq thread (list (car new-roots))
4790                       gnus-tmp-header (caar thread)
4791                       new-roots (cdr new-roots))))
4792
4793           (if threads
4794               ;; If there are some threads, we do them before the
4795               ;; threads on the stack.
4796               (setq thread threads
4797                     gnus-tmp-header (caar thread))
4798             ;; There were no current threads, so we pop something off
4799             ;; the stack.
4800             (setq state (car stack)
4801                   gnus-tmp-level (car state)
4802                   tree-stack (cadr state)
4803                   thread (caddr state)
4804                   stack (cdr stack)
4805                   gnus-tmp-header (caar thread))))
4806
4807         (setq gnus-tmp-false-parent nil)
4808         (setq gnus-tmp-root-expunged nil)
4809         (setq thread-end nil)
4810
4811         (if (stringp gnus-tmp-header)
4812             ;; The header is a dummy root.
4813             (cond
4814              ((eq gnus-summary-make-false-root 'adopt)
4815               ;; We let the first article adopt the rest.
4816               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4817                                                (cddar thread)))
4818               (setq gnus-tmp-gathered
4819                     (nconc (mapcar
4820                             (lambda (h) (mail-header-number (car h)))
4821                             (cddar thread))
4822                            gnus-tmp-gathered))
4823               (setq thread (cons (list (caar thread)
4824                                        (cadar thread))
4825                                  (cdr thread)))
4826               (setq gnus-tmp-level -1
4827                     gnus-tmp-false-parent t))
4828              ((eq gnus-summary-make-false-root 'empty)
4829               ;; We print adopted articles with empty subject fields.
4830               (setq gnus-tmp-gathered
4831                     (nconc (mapcar
4832                             (lambda (h) (mail-header-number (car h)))
4833                             (cddar thread))
4834                            gnus-tmp-gathered))
4835               (setq gnus-tmp-level -1))
4836              ((eq gnus-summary-make-false-root 'dummy)
4837               ;; We remember that we probably want to output a dummy
4838               ;; root.
4839               (setq gnus-tmp-dummy-line gnus-tmp-header)
4840               (setq gnus-tmp-prev-subject gnus-tmp-header))
4841              (t
4842               ;; We do not make a root for the gathered
4843               ;; sub-threads at all.
4844               (setq gnus-tmp-level -1)))
4845
4846           (setq number (mail-header-number gnus-tmp-header)
4847                 subject (mail-header-subject gnus-tmp-header)
4848                 simp-subject (gnus-simplify-subject-fully subject))
4849
4850           (cond
4851            ;; If the thread has changed subject, we might want to make
4852            ;; this subthread into a root.
4853            ((and (null gnus-thread-ignore-subject)
4854                  (not (zerop gnus-tmp-level))
4855                  gnus-tmp-prev-subject
4856                  (not (string= gnus-tmp-prev-subject simp-subject)))
4857             (setq new-roots (nconc new-roots (list (car thread)))
4858                   thread-end t
4859                   gnus-tmp-header nil))
4860            ;; If the article lies outside the current limit,
4861            ;; then we do not display it.
4862            ((not (memq number gnus-newsgroup-limit))
4863             (setq gnus-tmp-gathered
4864                   (nconc (mapcar
4865                           (lambda (h) (mail-header-number (car h)))
4866                           (cdar thread))
4867                          gnus-tmp-gathered))
4868             (setq gnus-tmp-new-adopts (if (cdar thread)
4869                                           (append gnus-tmp-new-adopts
4870                                                   (cdar thread))
4871                                         gnus-tmp-new-adopts)
4872                   thread-end t
4873                   gnus-tmp-header nil)
4874             (when (zerop gnus-tmp-level)
4875               (setq gnus-tmp-root-expunged t)))
4876            ;; Perhaps this article is to be marked as read?
4877            ((and gnus-summary-mark-below
4878                  (< (or (cdr (assq number gnus-newsgroup-scored))
4879                         default-score)
4880                     gnus-summary-mark-below)
4881                  ;; Don't touch sparse articles.
4882                  (not (gnus-summary-article-sparse-p number))
4883                  (not (gnus-summary-article-ancient-p number)))
4884             (setq gnus-newsgroup-unreads
4885                   (delq number gnus-newsgroup-unreads))
4886             (if gnus-newsgroup-auto-expire
4887                 (setq gnus-newsgroup-expirable
4888                       (gnus-add-to-sorted-list
4889                        gnus-newsgroup-expirable number))
4890               (push (cons number gnus-low-score-mark)
4891                     gnus-newsgroup-reads))))
4892
4893           (when gnus-tmp-header
4894             ;; We may have an old dummy line to output before this
4895             ;; article.
4896             (when (and gnus-tmp-dummy-line
4897                        (gnus-subject-equal
4898                         gnus-tmp-dummy-line
4899                         (mail-header-subject gnus-tmp-header)))
4900               (gnus-summary-insert-dummy-line
4901                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4902               (setq gnus-tmp-dummy-line nil))
4903
4904             ;; Compute the mark.
4905             (setq gnus-tmp-unread (gnus-article-mark number))
4906
4907             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4908                                   gnus-tmp-header gnus-tmp-level)
4909                   gnus-newsgroup-data)
4910
4911             ;; Actually insert the line.
4912             (setq
4913              gnus-tmp-subject-or-nil
4914              (cond
4915               ((and gnus-thread-ignore-subject
4916                     gnus-tmp-prev-subject
4917                     (not (string= gnus-tmp-prev-subject simp-subject)))
4918                subject)
4919               ((zerop gnus-tmp-level)
4920                (if (and (eq gnus-summary-make-false-root 'empty)
4921                         (memq number gnus-tmp-gathered)
4922                         gnus-tmp-prev-subject
4923                         (string= gnus-tmp-prev-subject simp-subject))
4924                    gnus-summary-same-subject
4925                  subject))
4926               (t gnus-summary-same-subject)))
4927             (if (and (eq gnus-summary-make-false-root 'adopt)
4928                      (= gnus-tmp-level 1)
4929                      (memq number gnus-tmp-gathered))
4930                 (setq gnus-tmp-opening-bracket ?\<
4931                       gnus-tmp-closing-bracket ?\>)
4932               (setq gnus-tmp-opening-bracket ?\[
4933                     gnus-tmp-closing-bracket ?\]))
4934             (setq
4935              gnus-tmp-indentation
4936              (aref gnus-thread-indent-array gnus-tmp-level)
4937              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4938              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4939                                 gnus-summary-default-score 0)
4940              gnus-tmp-score-char
4941              (if (or (null gnus-summary-default-score)
4942                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4943                          gnus-summary-zcore-fuzz))
4944                  ?                      ;Whitespace
4945                (if (< gnus-tmp-score gnus-summary-default-score)
4946                    gnus-score-below-mark gnus-score-over-mark))
4947              gnus-tmp-replied
4948              (cond ((memq number gnus-newsgroup-processable)
4949                     gnus-process-mark)
4950                    ((memq number gnus-newsgroup-cached)
4951                     gnus-cached-mark)
4952                    ((memq number gnus-newsgroup-replied)
4953                     gnus-replied-mark)
4954                    ((memq number gnus-newsgroup-forwarded)
4955                     gnus-forwarded-mark)
4956                    ((memq number gnus-newsgroup-saved)
4957                     gnus-saved-mark)
4958                    ((memq number gnus-newsgroup-recent)
4959                     gnus-recent-mark)
4960                    ((memq number gnus-newsgroup-unseen)
4961                     gnus-unseen-mark)
4962                    (t gnus-no-mark))
4963              gnus-tmp-downloaded
4964              (cond ((memq number gnus-newsgroup-undownloaded)
4965                     gnus-undownloaded-mark)
4966                    (gnus-newsgroup-agentized
4967                     gnus-downloaded-mark)
4968                    (t
4969                     gnus-no-mark))
4970              gnus-tmp-from (mail-header-from gnus-tmp-header)
4971              gnus-tmp-name
4972              (cond
4973               ((string-match "<[^>]+> *$" gnus-tmp-from)
4974                (setq beg-match (match-beginning 0))
4975                (or (and (string-match "^\".+\"" gnus-tmp-from)
4976                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4977                    (substring gnus-tmp-from 0 beg-match)))
4978               ((string-match "(.+)" gnus-tmp-from)
4979                (substring gnus-tmp-from
4980                           (1+ (match-beginning 0)) (1- (match-end 0))))
4981               (t gnus-tmp-from))
4982
4983              ;; Do the %B string
4984              gnus-tmp-thread-tree-header-string
4985              (cond
4986               ((not gnus-show-threads) "")
4987               ((zerop gnus-tmp-level)
4988                (cond ((cdar thread)
4989                       (or gnus-sum-thread-tree-root subject))
4990                      (gnus-tmp-new-adopts
4991                       (or gnus-sum-thread-tree-false-root subject))
4992                      (t
4993                       (or gnus-sum-thread-tree-single-indent subject))))
4994               (t
4995                (concat (apply 'concat
4996                               (mapcar (lambda (item)
4997                                         (if (= item 1)
4998                                             gnus-sum-thread-tree-vertical
4999                                           gnus-sum-thread-tree-indent))
5000                                       (cdr (reverse tree-stack))))
5001                        (if (nth 1 thread)
5002                            gnus-sum-thread-tree-leaf-with-other
5003                          gnus-sum-thread-tree-single-leaf)))))
5004             (when (string= gnus-tmp-name "")
5005               (setq gnus-tmp-name gnus-tmp-from))
5006             (unless (numberp gnus-tmp-lines)
5007               (setq gnus-tmp-lines -1))
5008             (if (= gnus-tmp-lines -1)
5009                 (setq gnus-tmp-lines "?")
5010               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5011               (gnus-put-text-property
5012              (point)
5013              (progn (eval gnus-summary-line-format-spec) (point))
5014                'gnus-number number)
5015             (when gnus-visual-p
5016               (forward-line -1)
5017               (gnus-run-hooks 'gnus-summary-update-hook)
5018               (forward-line 1))
5019
5020             (setq gnus-tmp-prev-subject simp-subject)))
5021
5022         (when (nth 1 thread)
5023           (push (list (max 0 gnus-tmp-level)
5024                       (copy-sequence tree-stack)
5025                       (nthcdr 1 thread))
5026                 stack))
5027         (push (if (nth 1 thread) 1 0) tree-stack)
5028         (incf gnus-tmp-level)
5029         (setq threads (if thread-end nil (cdar thread)))
5030         (if gnus-summary-display-while-building
5031             (if building-count
5032                 (progn
5033                   ;; use a set frequency
5034                   (setq building-line-count (1- building-line-count))
5035                   (when (= building-line-count 0)
5036                     (sit-for 0)
5037                     (setq building-line-count
5038                           gnus-summary-display-while-building)))
5039               ;; always
5040               (sit-for 0)))
5041         (unless threads
5042           (setq gnus-tmp-level 0)))))
5043   (gnus-message 7 "Generating summary...done"))
5044
5045 (defun gnus-summary-prepare-unthreaded (headers)
5046   "Generate an unthreaded summary buffer based on HEADERS."
5047   (let (header number mark)
5048
5049     (beginning-of-line)
5050
5051     (while headers
5052       ;; We may have to root out some bad articles...
5053       (when (memq (setq number (mail-header-number
5054                                 (setq header (pop headers))))
5055                   gnus-newsgroup-limit)
5056         ;; Mark article as read when it has a low score.
5057         (when (and gnus-summary-mark-below
5058                    (< (or (cdr (assq number gnus-newsgroup-scored))
5059                           gnus-summary-default-score 0)
5060                       gnus-summary-mark-below)
5061                    (not (gnus-summary-article-ancient-p number)))
5062           (setq gnus-newsgroup-unreads
5063                 (delq number gnus-newsgroup-unreads))
5064           (if gnus-newsgroup-auto-expire
5065               (push number gnus-newsgroup-expirable)
5066             (push (cons number gnus-low-score-mark)
5067                   gnus-newsgroup-reads)))
5068
5069         (setq mark (gnus-article-mark number))
5070         (push (gnus-data-make number mark (1+ (point)) header 0)
5071               gnus-newsgroup-data)
5072         (gnus-summary-insert-line
5073          header 0 number
5074          (memq number gnus-newsgroup-undownloaded)
5075          mark (memq number gnus-newsgroup-replied)
5076          (memq number gnus-newsgroup-expirable)
5077          (mail-header-subject header) nil
5078          (cdr (assq number gnus-newsgroup-scored))
5079          (memq number gnus-newsgroup-processable))))))
5080
5081 (defun gnus-summary-remove-list-identifiers ()
5082   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5083   (let ((regexp (if (consp gnus-list-identifiers)
5084                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5085                   gnus-list-identifiers))
5086         changed subject)
5087     (when regexp
5088       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5089       (dolist (header gnus-newsgroup-headers)
5090         (setq subject (mail-header-subject header)
5091               changed nil)
5092         (while (string-match regexp subject)
5093           (setq subject
5094                 (concat (substring subject 0 (match-beginning 1))
5095                         (substring subject (match-end 0)))
5096                 changed t))
5097         (when changed
5098           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5099             (setq subject
5100                   (concat (substring subject 0 (match-beginning 1))
5101                           (substring subject (match-end 1)))))
5102           (mail-header-set-subject header subject))))))
5103
5104 (defun gnus-fetch-headers (articles)
5105   "Fetch headers of ARTICLES."
5106   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5107     (gnus-message 5 "Fetching headers for %s..." name)
5108     (prog1
5109         (if (eq 'nov
5110                 (setq gnus-headers-retrieved-by
5111                       (gnus-retrieve-headers
5112                        articles gnus-newsgroup-name
5113                        ;; We might want to fetch old headers, but
5114                        ;; not if there is only 1 article.
5115                        (and (or (and
5116                                  (not (eq gnus-fetch-old-headers 'some))
5117                                  (not (numberp gnus-fetch-old-headers)))
5118                                 (> (length articles) 1))
5119                             gnus-fetch-old-headers))))
5120             (gnus-get-newsgroup-headers-xover
5121              articles nil nil gnus-newsgroup-name t)
5122           (gnus-get-newsgroup-headers))
5123       (gnus-message 5 "Fetching headers for %s...done" name))))
5124
5125 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5126   "Select newsgroup GROUP.
5127 If READ-ALL is non-nil, all articles in the group are selected.
5128 If SELECT-ARTICLES, only select those articles from GROUP."
5129   (let* ((entry (gnus-group-entry group))
5130          ;;!!! Dirty hack; should be removed.
5131          (gnus-summary-ignore-duplicates
5132           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5133               t
5134             gnus-summary-ignore-duplicates))
5135          (info (nth 2 entry))
5136          articles fetched-articles cached)
5137
5138     (unless (gnus-check-server
5139              (set (make-local-variable 'gnus-current-select-method)
5140                   (gnus-find-method-for-group group)))
5141       (error "Couldn't open server"))
5142
5143     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5144         (gnus-activate-group group)     ; Or we can activate it...
5145         (progn                          ; Or we bug out.
5146           (when (equal major-mode 'gnus-summary-mode)
5147             (gnus-kill-buffer (current-buffer)))
5148           (error "Couldn't activate group %s: %s"
5149                  group (gnus-status-message group))))
5150
5151     (unless (gnus-request-group group t)
5152       (when (equal major-mode 'gnus-summary-mode)
5153         (gnus-kill-buffer (current-buffer)))
5154       (error "Couldn't request group %s: %s"
5155              group (gnus-status-message group)))
5156
5157     (when gnus-agent
5158       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5159       
5160       (setq gnus-summary-use-undownloaded-faces
5161             (gnus-agent-find-parameter
5162              group
5163              'agent-enable-undownloaded-faces)))
5164
5165     (setq gnus-newsgroup-name group
5166           gnus-newsgroup-unselected nil
5167           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5168
5169     (let ((display (gnus-group-find-parameter group 'display)))
5170       (setq gnus-newsgroup-display
5171             (cond
5172              ((not (zerop (or (car-safe read-all) 0)))
5173               ;; The user entered the group with C-u SPC/RET, let's show
5174               ;; all articles.
5175               'gnus-not-ignore)
5176              ((eq display 'all)
5177               'gnus-not-ignore)
5178              ((arrayp display)
5179               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5180              ((numberp display)
5181               ;; The following is probably the "correct" solution, but
5182               ;; it makes Gnus fetch all headers and then limit the
5183               ;; articles (which is slow), so instead we hack the
5184               ;; select-articles parameter instead. -- Simon Josefsson
5185               ;; <jas@kth.se>
5186               ;;
5187               ;; (gnus-byte-compile
5188               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5189               ;;                         display)))))
5190               (setq select-articles
5191                     (gnus-uncompress-range
5192                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5193                              (if (> tmp 0)
5194                                  tmp
5195                                1))
5196                            (cdr (gnus-active group)))))
5197               nil)
5198              (t
5199               nil))))
5200
5201     (gnus-summary-setup-default-charset)
5202
5203     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5204     (when (gnus-virtual-group-p group)
5205       (setq cached gnus-newsgroup-cached))
5206
5207     (setq gnus-newsgroup-unreads
5208           (gnus-sorted-ndifference
5209            (gnus-sorted-ndifference gnus-newsgroup-unreads
5210                                     gnus-newsgroup-marked)
5211            gnus-newsgroup-dormant))
5212
5213     (setq gnus-newsgroup-processable nil)
5214
5215     (gnus-update-read-articles group gnus-newsgroup-unreads)
5216
5217     ;; Adjust and set lists of article marks.
5218     (when info
5219       (gnus-adjust-marked-articles info))
5220     (if (setq articles select-articles)
5221         (setq gnus-newsgroup-unselected
5222               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5223       (setq articles (gnus-articles-to-read group read-all)))
5224
5225     (cond
5226      ((null articles)
5227       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5228       'quit)
5229      ((eq articles 0) nil)
5230      (t
5231       ;; Init the dependencies hash table.
5232       (setq gnus-newsgroup-dependencies
5233             (gnus-make-hashtable (length articles)))
5234       (gnus-set-global-variables)
5235       ;; Retrieve the headers and read them in.
5236
5237       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5238
5239       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5240       (when cached
5241         (setq gnus-newsgroup-cached cached))
5242
5243       ;; Suppress duplicates?
5244       (when gnus-suppress-duplicates
5245         (gnus-dup-suppress-articles))
5246
5247       ;; Set the initial limit.
5248       (setq gnus-newsgroup-limit (copy-sequence articles))
5249       ;; Remove canceled articles from the list of unread articles.
5250       (setq fetched-articles
5251             (mapcar (lambda (headers) (mail-header-number headers))
5252                     gnus-newsgroup-headers))
5253       (setq gnus-newsgroup-articles fetched-articles)
5254       (setq gnus-newsgroup-unreads
5255             (gnus-sorted-nintersection
5256              gnus-newsgroup-unreads fetched-articles))
5257       (gnus-compute-unseen-list)
5258
5259       ;; Removed marked articles that do not exist.
5260       (gnus-update-missing-marks
5261        (gnus-sorted-difference articles fetched-articles))
5262       ;; We might want to build some more threads first.
5263       (when (and gnus-fetch-old-headers
5264                  (eq gnus-headers-retrieved-by 'nov))
5265         (if (eq gnus-fetch-old-headers 'invisible)
5266             (gnus-build-all-threads)
5267           (gnus-build-old-threads)))
5268       ;; Let the Gnus agent mark articles as read.
5269       (when gnus-agent
5270         (gnus-agent-get-undownloaded-list))
5271       ;; Remove list identifiers from subject
5272       (when gnus-list-identifiers
5273         (gnus-summary-remove-list-identifiers))
5274       ;; Check whether auto-expire is to be done in this group.
5275       (setq gnus-newsgroup-auto-expire
5276             (gnus-group-auto-expirable-p group))
5277       ;; Set up the article buffer now, if necessary.
5278       (unless gnus-single-article-buffer
5279         (gnus-article-setup-buffer))
5280       ;; First and last article in this newsgroup.
5281       (when gnus-newsgroup-headers
5282         (setq gnus-newsgroup-begin
5283               (mail-header-number (car gnus-newsgroup-headers))
5284               gnus-newsgroup-end
5285               (mail-header-number
5286                (gnus-last-element gnus-newsgroup-headers))))
5287       ;; GROUP is successfully selected.
5288       (or gnus-newsgroup-headers t)))))
5289
5290 (defun gnus-compute-unseen-list ()
5291   ;; The `seen' marks are treated specially.
5292   (if (not gnus-newsgroup-seen)
5293       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5294     (setq gnus-newsgroup-unseen
5295           (gnus-inverse-list-range-intersection
5296            gnus-newsgroup-articles gnus-newsgroup-seen))))
5297
5298 (defun gnus-summary-display-make-predicate (display)
5299   (require 'gnus-agent)
5300   (when (= (length display) 1)
5301     (setq display (car display)))
5302   (unless gnus-summary-display-cache
5303     (dolist (elem (append '((unread . unread)
5304                             (read . read)
5305                             (unseen . unseen))
5306                           gnus-article-mark-lists))
5307       (push (cons (cdr elem)
5308                   (gnus-byte-compile
5309                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5310             gnus-summary-display-cache)))
5311   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5312         (gnus-category-predicate-cache gnus-summary-display-cache))
5313     (gnus-get-predicate display)))
5314
5315 ;; Uses the dynamically bound `number' variable.
5316 (eval-when-compile
5317   (defvar number))
5318 (defun gnus-article-marked-p (type &optional article)
5319   (let ((article (or article number)))
5320     (cond
5321      ((eq type 'tick)
5322       (memq article gnus-newsgroup-marked))
5323      ((eq type 'spam)
5324       (memq article gnus-newsgroup-spam-marked))
5325      ((eq type 'unsend)
5326       (memq article gnus-newsgroup-unsendable))
5327      ((eq type 'undownload)
5328       (memq article gnus-newsgroup-undownloaded))
5329      ((eq type 'download)
5330       (memq article gnus-newsgroup-downloadable))
5331      ((eq type 'unread)
5332       (memq article gnus-newsgroup-unreads))
5333      ((eq type 'read)
5334       (memq article gnus-newsgroup-reads))
5335      ((eq type 'dormant)
5336       (memq article gnus-newsgroup-dormant) )
5337      ((eq type 'expire)
5338       (memq article gnus-newsgroup-expirable))
5339      ((eq type 'reply)
5340       (memq article gnus-newsgroup-replied))
5341      ((eq type 'killed)
5342       (memq article gnus-newsgroup-killed))
5343      ((eq type 'bookmark)
5344       (assq article gnus-newsgroup-bookmarks))
5345      ((eq type 'score)
5346       (assq article gnus-newsgroup-scored))
5347      ((eq type 'save)
5348       (memq article gnus-newsgroup-saved))
5349      ((eq type 'cache)
5350       (memq article gnus-newsgroup-cached))
5351      ((eq type 'forward)
5352       (memq article gnus-newsgroup-forwarded))
5353      ((eq type 'seen)
5354       (not (memq article gnus-newsgroup-unseen)))
5355      ((eq type 'recent)
5356       (memq article gnus-newsgroup-recent))
5357      (t t))))
5358
5359 (defun gnus-articles-to-read (group &optional read-all)
5360   "Find out what articles the user wants to read."
5361   (let* ((articles
5362           ;; Select all articles if `read-all' is non-nil, or if there
5363           ;; are no unread articles.
5364           (if (or read-all
5365                   (and (zerop (length gnus-newsgroup-marked))
5366                        (zerop (length gnus-newsgroup-unreads)))
5367                   ;; Fetch all if the predicate is non-nil.
5368                   gnus-newsgroup-display)
5369               ;; We want to select the headers for all the articles in
5370               ;; the group, so we select either all the active
5371               ;; articles in the group, or (if that's nil), the
5372               ;; articles in the cache.
5373               (or
5374                (gnus-uncompress-range (gnus-active group))
5375                (gnus-cache-articles-in-group group))
5376             ;; Select only the "normal" subset of articles.
5377             (gnus-sorted-nunion
5378              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5379              gnus-newsgroup-unreads)))
5380          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5381          (scored (length scored-list))
5382          (number (length articles))
5383          (marked (+ (length gnus-newsgroup-marked)
5384                     (length gnus-newsgroup-dormant)))
5385          (select
5386           (cond
5387            ((numberp read-all)
5388             read-all)
5389            ((numberp gnus-newsgroup-display)
5390             gnus-newsgroup-display)
5391            (t
5392             (condition-case ()
5393                 (cond
5394                  ((and (or (<= scored marked) (= scored number))
5395                        (numberp gnus-large-newsgroup)
5396                        (> number gnus-large-newsgroup))
5397                   (let* ((cursor-in-echo-area nil)
5398                          (initial (gnus-parameter-large-newsgroup-initial
5399                                    gnus-newsgroup-name))
5400                          (input
5401                           (read-string
5402                            (format
5403                             "How many articles from %s (%s %d): "
5404                             (gnus-limit-string
5405                              (gnus-group-decoded-name gnus-newsgroup-name)
5406                              35)
5407                             (if initial "max" "default")
5408                             number)
5409                            (if initial
5410                                (cons (number-to-string initial)
5411                                      0)))))
5412                     (if (string-match "^[ \t]*$" input) number input)))
5413                  ((and (> scored marked) (< scored number)
5414                        (> (- scored number) 20))
5415                   (let ((input
5416                          (read-string
5417                           (format "%s %s (%d scored, %d total): "
5418                                   "How many articles from"
5419                                   (gnus-group-decoded-name group)
5420                                   scored number))))
5421                     (if (string-match "^[ \t]*$" input)
5422                         number input)))
5423                  (t number))
5424               (quit
5425                (message "Quit getting the articles to read")
5426                nil))))))
5427     (setq select (if (stringp select) (string-to-number select) select))
5428     (if (or (null select) (zerop select))
5429         select
5430       (if (and (not (zerop scored)) (<= (abs select) scored))
5431           (progn
5432             (setq articles (sort scored-list '<))
5433             (setq number (length articles)))
5434         (setq articles (copy-sequence articles)))
5435
5436       (when (< (abs select) number)
5437         (if (< select 0)
5438             ;; Select the N oldest articles.
5439             (setcdr (nthcdr (1- (abs select)) articles) nil)
5440           ;; Select the N most recent articles.
5441           (setq articles (nthcdr (- number select) articles))))
5442       (setq gnus-newsgroup-unselected
5443             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5444       (when gnus-alter-articles-to-read-function
5445         (setq articles
5446               (sort
5447                (funcall gnus-alter-articles-to-read-function
5448                         gnus-newsgroup-name articles)
5449                '<)))
5450       articles)))
5451
5452 (defun gnus-killed-articles (killed articles)
5453   (let (out)
5454     (while articles
5455       (when (inline (gnus-member-of-range (car articles) killed))
5456         (push (car articles) out))
5457       (setq articles (cdr articles)))
5458     out))
5459
5460 (defun gnus-uncompress-marks (marks)
5461   "Uncompress the mark ranges in MARKS."
5462   (let ((uncompressed '(score bookmark))
5463         out)
5464     (while marks
5465       (if (memq (caar marks) uncompressed)
5466           (push (car marks) out)
5467         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5468       (setq marks (cdr marks)))
5469     out))
5470
5471 (defun gnus-article-mark-to-type (mark)
5472   "Return the type of MARK."
5473   (or (cadr (assq mark gnus-article-special-mark-lists))
5474       'list))
5475
5476 (defun gnus-article-unpropagatable-p (mark)
5477   "Return whether MARK should be propagated to back end."
5478   (memq mark gnus-article-unpropagated-mark-lists))
5479
5480 (defun gnus-adjust-marked-articles (info)
5481   "Set all article lists and remove all marks that are no longer valid."
5482   (let* ((marked-lists (gnus-info-marks info))
5483          (active (gnus-active (gnus-info-group info)))
5484          (min (car active))
5485          (max (cdr active))
5486          (types gnus-article-mark-lists)
5487          marks var articles article mark mark-type
5488          bgn end)
5489
5490     (dolist (marks marked-lists)
5491       (setq mark (car marks)
5492             mark-type (gnus-article-mark-to-type mark)
5493             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5494
5495       ;; We set the variable according to the type of the marks list,
5496       ;; and then adjust the marks to a subset of the active articles.
5497       (cond
5498        ;; Adjust "simple" lists - compressed yet unsorted
5499        ((eq mark-type 'list)
5500         ;; Simultaneously uncompress and clip to active range
5501         ;; See gnus-uncompress-range for a description of possible marks
5502         (let (l lh)
5503           (if (not (cadr marks))
5504               (set var nil)
5505             (setq articles (if (numberp (cddr marks))
5506                                (list (cdr marks))
5507                              (cdr marks))
5508                   lh (cons nil nil)
5509                   l lh)
5510
5511             (while (setq article (pop articles))
5512               (cond ((consp article)
5513                      (setq bgn (max (car article) min)
5514                            end (min (cdr article) max))
5515                      (while (<= bgn end)
5516                        (setq l (setcdr l (cons bgn nil))
5517                              bgn (1+ bgn))))
5518                     ((and (<= min article)
5519                           (>= max article))
5520                      (setq l (setcdr l (cons article nil))))))
5521             (set var (cdr lh)))))
5522        ;; Adjust assocs.
5523        ((eq mark-type 'tuple)
5524         (set var (setq articles (cdr marks)))
5525         (when (not (listp (cdr (symbol-value var))))
5526           (set var (list (symbol-value var))))
5527         (when (not (listp (cdr articles)))
5528           (setq articles (list articles)))
5529         (while articles
5530           (when (or (not (consp (setq article (pop articles))))
5531                     (< (car article) min)
5532                     (> (car article) max))
5533             (set var (delq article (symbol-value var))))))
5534        ;; Adjust ranges (sloppily).
5535        ((eq mark-type 'range)
5536         (cond
5537          ((eq mark 'seen)
5538           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5539           ;; It should be (seen (NUM1 . NUM2)).
5540           (when (numberp (cddr marks))
5541             (setcdr marks (list (cdr marks))))
5542           (setq articles (cdr marks))
5543           (while (and articles
5544                       (or (and (consp (car articles))
5545                                (> min (cdar articles)))
5546                           (and (numberp (car articles))
5547                                (> min (car articles)))))
5548             (pop articles))
5549           (set var articles))))))))
5550
5551 (defun gnus-update-missing-marks (missing)
5552   "Go through the list of MISSING articles and remove them from the mark lists."
5553   (when missing
5554     (let (var m)
5555       ;; Go through all types.
5556       (dolist (elem gnus-article-mark-lists)
5557         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5558           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5559           (when (symbol-value var)
5560             ;; This list has articles.  So we delete all missing
5561             ;; articles from it.
5562             (setq m missing)
5563             (while m
5564               (set var (delq (pop m) (symbol-value var))))))))))
5565
5566 (defun gnus-update-marks ()
5567   "Enter the various lists of marked articles into the newsgroup info list."
5568   (let ((types gnus-article-mark-lists)
5569         (info (gnus-get-info gnus-newsgroup-name))
5570         type list newmarked symbol delta-marks)
5571     (when info
5572       ;; Add all marks lists to the list of marks lists.
5573       (while (setq type (pop types))
5574         (setq list (symbol-value
5575                     (setq symbol
5576                           (intern (format "gnus-newsgroup-%s" (car type))))))
5577
5578         (when list
5579           ;; Get rid of the entries of the articles that have the
5580           ;; default score.
5581           (when (and (eq (cdr type) 'score)
5582                      gnus-save-score
5583                      list)
5584             (let* ((arts list)
5585                    (prev (cons nil list))
5586                    (all prev))
5587               (while arts
5588                 (if (or (not (consp (car arts)))
5589                         (= (cdar arts) gnus-summary-default-score))
5590                     (setcdr prev (cdr arts))
5591                   (setq prev arts))
5592                 (setq arts (cdr arts)))
5593               (setq list (cdr all)))))
5594
5595         (when (eq (cdr type) 'seen)
5596           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5597
5598         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5599           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5600
5601         (when (and (gnus-check-backend-function
5602                     'request-set-mark gnus-newsgroup-name)
5603                    (not (gnus-article-unpropagatable-p (cdr type))))
5604           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5605                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5606                  (add (gnus-remove-from-range
5607                        (gnus-copy-sequence list) old)))
5608             (when add
5609               (push (list add 'add (list (cdr type))) delta-marks))
5610             (when del
5611               (push (list del 'del (list (cdr type))) delta-marks))))
5612
5613         (when list
5614           (push (cons (cdr type) list) newmarked)))
5615
5616       (when delta-marks
5617         (unless (gnus-check-group gnus-newsgroup-name)
5618           (error "Can't open server for %s" gnus-newsgroup-name))
5619         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5620
5621       ;; Enter these new marks into the info of the group.
5622       (if (nthcdr 3 info)
5623           (setcar (nthcdr 3 info) newmarked)
5624         ;; Add the marks lists to the end of the info.
5625         (when newmarked
5626           (setcdr (nthcdr 2 info) (list newmarked))))
5627
5628       ;; Cut off the end of the info if there's nothing else there.
5629       (let ((i 5))
5630         (while (and (> i 2)
5631                     (not (nth i info)))
5632           (when (nthcdr (decf i) info)
5633             (setcdr (nthcdr i info) nil)))))))
5634
5635 (defun gnus-set-mode-line (where)
5636   "Set the mode line of the article or summary buffers.
5637 If WHERE is `summary', the summary mode line format will be used."
5638   ;; Is this mode line one we keep updated?
5639   (when (and (memq where gnus-updated-mode-lines)
5640              (symbol-value
5641               (intern (format "gnus-%s-mode-line-format-spec" where))))
5642     (let (mode-string)
5643       (save-excursion
5644         ;; We evaluate this in the summary buffer since these
5645         ;; variables are buffer-local to that buffer.
5646         (set-buffer gnus-summary-buffer)
5647        ;; We bind all these variables that are used in the `eval' form
5648         ;; below.
5649         (let* ((mformat (symbol-value
5650                          (intern
5651                           (format "gnus-%s-mode-line-format-spec" where))))
5652                (gnus-tmp-group-name (gnus-group-decoded-name
5653                                      gnus-newsgroup-name))
5654                (gnus-tmp-article-number (or gnus-current-article 0))
5655                (gnus-tmp-unread gnus-newsgroup-unreads)
5656                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5657                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5658                (gnus-tmp-unread-and-unselected
5659                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5660                             (zerop gnus-tmp-unselected))
5661                        "")
5662                       ((zerop gnus-tmp-unselected)
5663                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5664                       (t (format "{%d(+%d) more}"
5665                                  gnus-tmp-unread-and-unticked
5666                                  gnus-tmp-unselected))))
5667                (gnus-tmp-subject
5668                 (if (and gnus-current-headers
5669                          (vectorp gnus-current-headers))
5670                     (gnus-mode-string-quote
5671                      (mail-header-subject gnus-current-headers))
5672                   ""))
5673                bufname-length max-len
5674                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5675           (setq mode-string (eval mformat))
5676           (setq bufname-length (if (string-match "%b" mode-string)
5677                                    (- (length
5678                                        (buffer-name
5679                                         (if (eq where 'summary)
5680                                             nil
5681                                           (get-buffer gnus-article-buffer))))
5682                                       2)
5683                                  0))
5684           (setq max-len (max 4 (if gnus-mode-non-string-length
5685                                    (- (window-width)
5686                                       gnus-mode-non-string-length
5687                                       bufname-length)
5688                                  (length mode-string))))
5689           ;; We might have to chop a bit of the string off...
5690           (when (> (length mode-string) max-len)
5691             (setq mode-string
5692                   (concat (truncate-string-to-width mode-string (- max-len 3))
5693                           "...")))
5694           ;; Pad the mode string a bit.
5695           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5696       ;; Update the mode line.
5697       (setq mode-line-buffer-identification
5698             (gnus-mode-line-buffer-identification (list mode-string)))
5699       (set-buffer-modified-p t))))
5700
5701 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5702   "Go through the HEADERS list and add all Xrefs to a hash table.
5703 The resulting hash table is returned, or nil if no Xrefs were found."
5704   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5705          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5706          (xref-hashtb (gnus-make-hashtable))
5707          start group entry number xrefs header)
5708     (while headers
5709       (setq header (pop headers))
5710       (when (and (setq xrefs (mail-header-xref header))
5711                  (not (memq (setq number (mail-header-number header))
5712                             unreads)))
5713         (setq start 0)
5714         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5715           (setq start (match-end 0))
5716           (setq group (if prefix
5717                           (concat prefix (substring xrefs (match-beginning 1)
5718                                                     (match-end 1)))
5719                         (substring xrefs (match-beginning 1) (match-end 1))))
5720           (setq number
5721                 (string-to-int (substring xrefs (match-beginning 2)
5722                                           (match-end 2))))
5723           (if (setq entry (gnus-gethash group xref-hashtb))
5724               (setcdr entry (cons number (cdr entry)))
5725             (gnus-sethash group (cons number nil) xref-hashtb)))))
5726     (and start xref-hashtb)))
5727
5728 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5729   "Look through all the headers and mark the Xrefs as read."
5730   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5731         name info xref-hashtb idlist method nth4)
5732     (save-excursion
5733       (set-buffer gnus-group-buffer)
5734       (when (setq xref-hashtb
5735                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5736         (mapatoms
5737          (lambda (group)
5738            (unless (string= from-newsgroup (setq name (symbol-name group)))
5739              (setq idlist (symbol-value group))
5740              ;; Dead groups are not updated.
5741              (and (prog1
5742                       (setq info (gnus-get-info name))
5743                     (when (stringp (setq nth4 (gnus-info-method info)))
5744                       (setq nth4 (gnus-server-to-method nth4))))
5745                   ;; Only do the xrefs if the group has the same
5746                   ;; select method as the group we have just read.
5747                   (or (gnus-methods-equal-p
5748                        nth4 (gnus-find-method-for-group from-newsgroup))
5749                       virtual
5750                       (equal nth4 (setq method (gnus-find-method-for-group
5751                                                 from-newsgroup)))
5752                       (and (equal (car nth4) (car method))
5753                            (equal (nth 1 nth4) (nth 1 method))))
5754                   gnus-use-cross-reference
5755                   (or (not (eq gnus-use-cross-reference t))
5756                       virtual
5757                       ;; Only do cross-references on subscribed
5758                       ;; groups, if that is what is wanted.
5759                       (<= (gnus-info-level info) gnus-level-subscribed))
5760                   (gnus-group-make-articles-read name idlist))))
5761          xref-hashtb)))))
5762
5763 (defun gnus-compute-read-articles (group articles)
5764   (let* ((entry (gnus-group-entry group))
5765          (info (nth 2 entry))
5766          (active (gnus-active group))
5767          ninfo)
5768     (when entry
5769       ;; First peel off all invalid article numbers.
5770       (when active
5771         (let ((ids articles)
5772               id first)
5773           (while (setq id (pop ids))
5774             (when (and first (> id (cdr active)))
5775               ;; We'll end up in this situation in one particular
5776               ;; obscure situation.  If you re-scan a group and get
5777               ;; a new article that is cross-posted to a different
5778               ;; group that has not been re-scanned, you might get
5779               ;; crossposted article that has a higher number than
5780               ;; Gnus believes possible.  So we re-activate this
5781               ;; group as well.  This might mean doing the
5782               ;; crossposting thingy will *increase* the number
5783               ;; of articles in some groups.  Tsk, tsk.
5784               (setq active (or (gnus-activate-group group) active)))
5785             (when (or (> id (cdr active))
5786                       (< id (car active)))
5787               (setq articles (delq id articles))))))
5788       ;; If the read list is nil, we init it.
5789       (if (and active
5790                (null (gnus-info-read info))
5791                (> (car active) 1))
5792           (setq ninfo (cons 1 (1- (car active))))
5793         (setq ninfo (gnus-info-read info)))
5794       ;; Then we add the read articles to the range.
5795       (gnus-add-to-range
5796        ninfo (setq articles (sort articles '<))))))
5797
5798 (defun gnus-group-make-articles-read (group articles)
5799   "Update the info of GROUP to say that ARTICLES are read."
5800   (let* ((num 0)
5801          (entry (gnus-group-entry group))
5802          (info (nth 2 entry))
5803          (active (gnus-active group))
5804          range)
5805     (when entry
5806       (setq range (gnus-compute-read-articles group articles))
5807       (with-current-buffer gnus-group-buffer
5808         (gnus-undo-register
5809           `(progn
5810              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5811              (gnus-info-set-read ',info ',(gnus-info-read info))
5812              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5813              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5814              (gnus-group-update-group ,group t))))
5815       ;; Add the read articles to the range.
5816       (gnus-info-set-read info range)
5817       (gnus-request-set-mark group (list (list range 'add '(read))))
5818       ;; Then we have to re-compute how many unread
5819       ;; articles there are in this group.
5820       (when active
5821         (cond
5822          ((not range)
5823           (setq num (- (1+ (cdr active)) (car active))))
5824          ((not (listp (cdr range)))
5825           (setq num (- (cdr active) (- (1+ (cdr range))
5826                                        (car range)))))
5827          (t
5828           (while range
5829             (if (numberp (car range))
5830                 (setq num (1+ num))
5831               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5832             (setq range (cdr range)))
5833           (setq num (- (cdr active) num))))
5834         ;; Update the number of unread articles.
5835         (setcar entry num)
5836         ;; Update the group buffer.
5837         (unless (gnus-ephemeral-group-p group)
5838           (gnus-group-update-group group t))))))
5839
5840 (defvar gnus-newsgroup-none-id 0)
5841
5842 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5843   (let ((cur nntp-server-buffer)
5844         (dependencies
5845          (or dependencies
5846              (with-current-buffer gnus-summary-buffer
5847                gnus-newsgroup-dependencies)))
5848         headers id end ref number
5849         (mail-parse-charset gnus-newsgroup-charset)
5850         (mail-parse-ignored-charsets
5851          (save-excursion (condition-case nil
5852                              (set-buffer gnus-summary-buffer)
5853                            (error))
5854                          gnus-newsgroup-ignored-charsets)))
5855     (save-excursion
5856       (set-buffer nntp-server-buffer)
5857       ;; Translate all TAB characters into SPACE characters.
5858       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5859       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5860       (ietf-drums-unfold-fws)
5861       (gnus-run-hooks 'gnus-parse-headers-hook)
5862       (let ((case-fold-search t)
5863             in-reply-to header p lines chars)
5864         (goto-char (point-min))
5865         ;; Search to the beginning of the next header.  Error messages
5866         ;; do not begin with 2 or 3.
5867         (while (re-search-forward "^[23][0-9]+ " nil t)
5868           (setq id nil
5869                 ref nil)
5870           ;; This implementation of this function, with nine
5871           ;; search-forwards instead of the one re-search-forward and
5872           ;; a case (which basically was the old function) is actually
5873           ;; about twice as fast, even though it looks messier.  You
5874           ;; can't have everything, I guess.  Speed and elegance
5875           ;; doesn't always go hand in hand.
5876           (setq
5877            header
5878            (vector
5879             ;; Number.
5880             (prog1
5881                 (setq number (read cur))
5882               (end-of-line)
5883               (setq p (point))
5884               (narrow-to-region (point)
5885                                 (or (and (search-forward "\n.\n" nil t)
5886                                          (- (point) 2))
5887                                     (point))))
5888             ;; Subject.
5889             (progn
5890               (goto-char p)
5891               (if (search-forward "\nsubject:" nil t)
5892                   (funcall gnus-decode-encoded-word-function
5893                            (nnheader-header-value))
5894                 "(none)"))
5895             ;; From.
5896             (progn
5897               (goto-char p)
5898               (if (search-forward "\nfrom:" nil t)
5899                   (funcall gnus-decode-encoded-word-function
5900                            (nnheader-header-value))
5901                 "(nobody)"))
5902             ;; Date.
5903             (progn
5904               (goto-char p)
5905               (if (search-forward "\ndate:" nil t)
5906                   (nnheader-header-value) ""))
5907             ;; Message-ID.
5908             (progn
5909               (goto-char p)
5910               (setq id (if (re-search-forward
5911                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5912                            ;; We do it this way to make sure the Message-ID
5913                            ;; is (somewhat) syntactically valid.
5914                            (buffer-substring (match-beginning 1)
5915                                              (match-end 1))
5916                          ;; If there was no message-id, we just fake one
5917                          ;; to make subsequent routines simpler.
5918                          (nnheader-generate-fake-message-id number))))
5919             ;; References.
5920             (progn
5921               (goto-char p)
5922               (if (search-forward "\nreferences:" nil t)
5923                   (progn
5924                     (setq end (point))
5925                     (prog1
5926                         (nnheader-header-value)
5927                       (setq ref
5928                             (buffer-substring
5929                              (progn
5930                                (end-of-line)
5931                                (search-backward ">" end t)
5932                                (1+ (point)))
5933                              (progn
5934                                (search-backward "<" end t)
5935                                (point))))))
5936                 ;; Get the references from the in-reply-to header if there
5937                 ;; were no references and the in-reply-to header looks
5938                 ;; promising.
5939                 (if (and (search-forward "\nin-reply-to:" nil t)
5940                          (setq in-reply-to (nnheader-header-value))
5941                          (string-match "<[^>]+>" in-reply-to))
5942                     (let (ref2)
5943                       (setq ref (substring in-reply-to (match-beginning 0)
5944                                            (match-end 0)))
5945                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5946                         (setq ref2 (substring in-reply-to (match-beginning 0)
5947                                               (match-end 0)))
5948                         (when (> (length ref2) (length ref))
5949                           (setq ref ref2)))
5950                       ref)
5951                   (setq ref nil))))
5952             ;; Chars.
5953             (progn
5954               (goto-char p)
5955               (if (search-forward "\nchars: " nil t)
5956                   (if (numberp (setq chars (ignore-errors (read cur))))
5957                       chars -1)
5958                 -1))
5959             ;; Lines.
5960             (progn
5961               (goto-char p)
5962               (if (search-forward "\nlines: " nil t)
5963                   (if (numberp (setq lines (ignore-errors (read cur))))
5964                       lines -1)
5965                 -1))
5966             ;; Xref.
5967             (progn
5968               (goto-char p)
5969               (and (search-forward "\nxref:" nil t)
5970                    (nnheader-header-value)))
5971             ;; Extra.
5972             (when gnus-extra-headers
5973               (let ((extra gnus-extra-headers)
5974                     out)
5975                 (while extra
5976                   (goto-char p)
5977                   (when (search-forward
5978                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5979                     (push (cons (car extra) (nnheader-header-value))
5980                           out))
5981                   (pop extra))
5982                 out))))
5983           (when (equal id ref)
5984             (setq ref nil))
5985
5986           (when gnus-alter-header-function
5987             (funcall gnus-alter-header-function header)
5988             (setq id (mail-header-id header)
5989                   ref (gnus-parent-id (mail-header-references header))))
5990
5991           (when (setq header
5992                       (gnus-dependencies-add-header
5993                        header dependencies force-new))
5994             (push header headers))
5995           (goto-char (point-max))
5996           (widen))
5997         (nreverse headers)))))
5998
5999 ;; Goes through the xover lines and returns a list of vectors
6000 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6001                                                   force-new dependencies
6002                                                   group also-fetch-heads)
6003   "Parse the news overview data in the server buffer.
6004 Return a list of headers that match SEQUENCE (see
6005 `nntp-retrieve-headers')."
6006   ;; Get the Xref when the users reads the articles since most/some
6007   ;; NNTP servers do not include Xrefs when using XOVER.
6008   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6009   (let ((mail-parse-charset gnus-newsgroup-charset)
6010         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6011         (cur nntp-server-buffer)
6012         (dependencies (or dependencies gnus-newsgroup-dependencies))
6013         (allp (cond
6014                ((eq gnus-read-all-available-headers t)
6015                 t)
6016                ((stringp gnus-read-all-available-headers)
6017                 (string-match gnus-read-all-available-headers group))
6018                (t
6019                 nil)))
6020         number headers header)
6021     (save-excursion
6022       (set-buffer nntp-server-buffer)
6023       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6024       ;; Allow the user to mangle the headers before parsing them.
6025       (gnus-run-hooks 'gnus-parse-headers-hook)
6026       (goto-char (point-min))
6027       (gnus-parse-without-error
6028         (while (and (or sequence allp)
6029                     (not (eobp)))
6030           (setq number (read cur))
6031           (when (not allp)
6032             (while (and sequence
6033                         (< (car sequence) number))
6034               (setq sequence (cdr sequence))))
6035           (when (and (or allp
6036                          (and sequence
6037                               (eq number (car sequence))))
6038                      (progn
6039                        (setq sequence (cdr sequence))
6040                        (setq header (inline
6041                                       (gnus-nov-parse-line
6042                                        number dependencies force-new)))))
6043             (push header headers))
6044           (forward-line 1)))
6045       ;; A common bug in inn is that if you have posted an article and
6046       ;; then retrieves the active file, it will answer correctly --
6047       ;; the new article is included.  However, a NOV entry for the
6048       ;; article may not have been generated yet, so this may fail.
6049       ;; We work around this problem by retrieving the last few
6050       ;; headers using HEAD.
6051       (if (or (not also-fetch-heads)
6052               (not sequence))
6053           ;; We (probably) got all the headers.
6054           (nreverse headers)
6055         (let ((gnus-nov-is-evil t))
6056           (nconc
6057            (nreverse headers)
6058            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6059              (gnus-get-newsgroup-headers))))))))
6060
6061 (defun gnus-article-get-xrefs ()
6062   "Fill in the Xref value in `gnus-current-headers', if necessary.
6063 This is meant to be called in `gnus-article-internal-prepare-hook'."
6064   (let ((headers (with-current-buffer gnus-summary-buffer
6065                    gnus-current-headers)))
6066     (or (not gnus-use-cross-reference)
6067         (not headers)
6068         (and (mail-header-xref headers)
6069              (not (string= (mail-header-xref headers) "")))
6070         (let ((case-fold-search t)
6071               xref)
6072           (save-restriction
6073             (nnheader-narrow-to-headers)
6074             (goto-char (point-min))
6075             (when (or (and (not (eobp))
6076                            (eq (downcase (char-after)) ?x)
6077                            (looking-at "Xref:"))
6078                       (search-forward "\nXref:" nil t))
6079               (goto-char (1+ (match-end 0)))
6080               (setq xref (buffer-substring (point) (point-at-eol)))
6081               (mail-header-set-xref headers xref)))))))
6082
6083 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6084   "Find article ID and insert the summary line for that article.
6085 OLD-HEADER can either be a header or a line number to insert
6086 the subject line on."
6087   (let* ((line (and (numberp old-header) old-header))
6088          (old-header (and (vectorp old-header) old-header))
6089          (header (cond ((and old-header use-old-header)
6090                         old-header)
6091                        ((and (numberp id)
6092                              (gnus-number-to-header id))
6093                         (gnus-number-to-header id))
6094                        (t
6095                         (gnus-read-header id))))
6096          (number (and (numberp id) id))
6097          d)
6098     (when header
6099       ;; Rebuild the thread that this article is part of and go to the
6100       ;; article we have fetched.
6101       (when (and (not gnus-show-threads)
6102                  old-header)
6103         (when (and number
6104                    (setq d (gnus-data-find (mail-header-number old-header))))
6105           (goto-char (gnus-data-pos d))
6106           (gnus-data-remove
6107            number
6108            (- (point-at-bol)
6109               (prog1
6110                   (1+ (point-at-eol))
6111                 (gnus-delete-line))))))
6112       ;; Remove list identifiers from subject.
6113       (when gnus-list-identifiers
6114         (let ((gnus-newsgroup-headers (list header)))
6115           (gnus-summary-remove-list-identifiers)))
6116       (when old-header
6117         (mail-header-set-number header (mail-header-number old-header)))
6118       (setq gnus-newsgroup-sparse
6119             (delq (setq number (mail-header-number header))
6120                   gnus-newsgroup-sparse))
6121       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6122       (push number gnus-newsgroup-limit)
6123       (gnus-rebuild-thread (mail-header-id header) line)
6124       (gnus-summary-goto-subject number nil t))
6125     (when (and (numberp number)
6126                (> number 0))
6127       ;; We have to update the boundaries even if we can't fetch the
6128       ;; article if ID is a number -- so that the next `P' or `N'
6129       ;; command will fetch the previous (or next) article even
6130       ;; if the one we tried to fetch this time has been canceled.
6131       (when (> number gnus-newsgroup-end)
6132         (setq gnus-newsgroup-end number))
6133       (when (< number gnus-newsgroup-begin)
6134         (setq gnus-newsgroup-begin number))
6135       (setq gnus-newsgroup-unselected
6136             (delq number gnus-newsgroup-unselected)))
6137     ;; Report back a success?
6138     (and header (mail-header-number header))))
6139
6140 ;;; Process/prefix in the summary buffer
6141
6142 (defun gnus-summary-work-articles (n)
6143   "Return a list of articles to be worked upon.
6144 The prefix argument, the list of process marked articles, and the
6145 current article will be taken into consideration."
6146   (save-excursion
6147     (set-buffer gnus-summary-buffer)
6148     (cond
6149      (n
6150       ;; A numerical prefix has been given.
6151       (setq n (prefix-numeric-value n))
6152       (let ((backward (< n 0))
6153             (n (abs (prefix-numeric-value n)))
6154             articles article)
6155         (save-excursion
6156           (while
6157               (and (> n 0)
6158                    (push (setq article (gnus-summary-article-number))
6159                          articles)
6160                    (if backward
6161                        (gnus-summary-find-prev nil article)
6162                      (gnus-summary-find-next nil article)))
6163             (decf n)))
6164         (nreverse articles)))
6165      ((and (gnus-region-active-p) (mark))
6166       (message "region active")
6167       ;; Work on the region between point and mark.
6168       (let ((max (max (point) (mark)))
6169             articles article)
6170         (save-excursion
6171           (goto-char (min (min (point) (mark))))
6172           (while
6173               (and
6174                (push (setq article (gnus-summary-article-number)) articles)
6175                (gnus-summary-find-next nil article)
6176                (< (point) max)))
6177           (nreverse articles))))
6178      (gnus-newsgroup-processable
6179       ;; There are process-marked articles present.
6180       ;; Save current state.
6181       (gnus-summary-save-process-mark)
6182       ;; Return the list.
6183       (reverse gnus-newsgroup-processable))
6184      (t
6185       ;; Just return the current article.
6186       (list (gnus-summary-article-number))))))
6187
6188 (defmacro gnus-summary-iterate (arg &rest forms)
6189   "Iterate over the process/prefixed articles and do FORMS.
6190 ARG is the interactive prefix given to the command.  FORMS will be
6191 executed with point over the summary line of the articles."
6192   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6193     `(let ((,articles (gnus-summary-work-articles ,arg)))
6194        (while ,articles
6195          (gnus-summary-goto-subject (car ,articles))
6196          ,@forms
6197          (pop ,articles)))))
6198
6199 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6200 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6201
6202 (defun gnus-summary-save-process-mark ()
6203   "Push the current set of process marked articles on the stack."
6204   (interactive)
6205   (push (copy-sequence gnus-newsgroup-processable)
6206         gnus-newsgroup-process-stack))
6207
6208 (defun gnus-summary-kill-process-mark ()
6209   "Push the current set of process marked articles on the stack and unmark."
6210   (interactive)
6211   (gnus-summary-save-process-mark)
6212   (gnus-summary-unmark-all-processable))
6213
6214 (defun gnus-summary-yank-process-mark ()
6215   "Pop the last process mark state off the stack and restore it."
6216   (interactive)
6217   (unless gnus-newsgroup-process-stack
6218     (error "Empty mark stack"))
6219   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6220
6221 (defun gnus-summary-process-mark-set (set)
6222   "Make SET into the current process marked articles."
6223   (gnus-summary-unmark-all-processable)
6224   (mapc 'gnus-summary-set-process-mark set))
6225
6226 ;;; Searching and stuff
6227
6228 (defun gnus-summary-search-group (&optional backward use-level)
6229   "Search for next unread newsgroup.
6230 If optional argument BACKWARD is non-nil, search backward instead."
6231   (save-excursion
6232     (set-buffer gnus-group-buffer)
6233     (when (gnus-group-search-forward
6234            backward nil (if use-level (gnus-group-group-level) nil))
6235       (gnus-group-group-name))))
6236
6237 (defun gnus-summary-best-group (&optional exclude-group)
6238   "Find the name of the best unread group.
6239 If EXCLUDE-GROUP, do not go to this group."
6240   (with-current-buffer gnus-group-buffer
6241     (save-excursion
6242       (gnus-group-best-unread-group exclude-group))))
6243
6244 (defun gnus-summary-find-next (&optional unread article backward)
6245   (if backward
6246       (gnus-summary-find-prev unread article)
6247     (let* ((dummy (gnus-summary-article-intangible-p))
6248            (article (or article (gnus-summary-article-number)))
6249            (data (gnus-data-find-list article))
6250            result)
6251       (when (and (not dummy)
6252                  (or (not gnus-summary-check-current)
6253                      (not unread)
6254                      (not (gnus-data-unread-p (car data)))))
6255         (setq data (cdr data)))
6256       (when (setq result
6257                   (if unread
6258                       (progn
6259                         (while data
6260                           (unless (memq (gnus-data-number (car data))
6261                                         (cond
6262                                          ((eq gnus-auto-goto-ignores
6263                                               'always-undownloaded)
6264                                           gnus-newsgroup-undownloaded)
6265                                          (gnus-plugged
6266                                           nil)
6267                                          ((eq gnus-auto-goto-ignores
6268                                               'unfetched)
6269                                           gnus-newsgroup-unfetched)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'undownloaded)
6272                                           gnus-newsgroup-undownloaded)))
6273                             (when (gnus-data-unread-p (car data))
6274                               (setq result (car data)
6275                                     data nil)))
6276                           (setq data (cdr data)))
6277                         result)
6278                     (car data)))
6279         (goto-char (gnus-data-pos result))
6280         (gnus-data-number result)))))
6281
6282 (defun gnus-summary-find-prev (&optional unread article)
6283   (let* ((eobp (eobp))
6284          (article (or article (gnus-summary-article-number)))
6285          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6286          result)
6287     (when (and (not eobp)
6288                (or (not gnus-summary-check-current)
6289                    (not unread)
6290                    (not (gnus-data-unread-p (car data)))))
6291       (setq data (cdr data)))
6292     (when (setq result
6293                 (if unread
6294                     (progn
6295                       (while data
6296                         (unless (memq (gnus-data-number (car data))
6297                                       (cond
6298                                        ((eq gnus-auto-goto-ignores
6299                                             'always-undownloaded)
6300                                         gnus-newsgroup-undownloaded)
6301                                        (gnus-plugged
6302                                         nil)
6303                                        ((eq gnus-auto-goto-ignores
6304                                             'unfetched)
6305                                         gnus-newsgroup-unfetched)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'undownloaded)
6308                                         gnus-newsgroup-undownloaded)))
6309                           (when (gnus-data-unread-p (car data))
6310                             (setq result (car data)
6311                                   data nil)))
6312                         (setq data (cdr data)))
6313                       result)
6314                   (car data)))
6315       (goto-char (gnus-data-pos result))
6316       (gnus-data-number result))))
6317
6318 (defun gnus-summary-find-subject (subject &optional unread backward article)
6319   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6320          (article (or article (gnus-summary-article-number)))
6321          (articles (gnus-data-list backward))
6322          (arts (gnus-data-find-list article articles))
6323          result)
6324     (when (or (not gnus-summary-check-current)
6325               (not unread)
6326               (not (gnus-data-unread-p (car arts))))
6327       (setq arts (cdr arts)))
6328     (while arts
6329       (and (or (not unread)
6330                (gnus-data-unread-p (car arts)))
6331            (vectorp (gnus-data-header (car arts)))
6332            (gnus-subject-equal
6333             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6334            (setq result (car arts)
6335                  arts nil))
6336       (setq arts (cdr arts)))
6337     (and result
6338          (goto-char (gnus-data-pos result))
6339          (gnus-data-number result))))
6340
6341 (defun gnus-summary-search-forward (&optional unread subject backward)
6342   "Search forward for an article.
6343 If UNREAD, look for unread articles.  If SUBJECT, look for
6344 articles with that subject.  If BACKWARD, search backward instead."
6345   (cond (subject (gnus-summary-find-subject subject unread backward))
6346         (backward (gnus-summary-find-prev unread))
6347         (t (gnus-summary-find-next unread))))
6348
6349 (defun gnus-recenter (&optional n)
6350   "Center point in window and redisplay frame.
6351 Also do horizontal recentering."
6352   (interactive "P")
6353   (when (and gnus-auto-center-summary
6354              (not (eq gnus-auto-center-summary 'vertical)))
6355     (gnus-horizontal-recenter))
6356   (recenter n))
6357
6358 (defun gnus-summary-recenter ()
6359   "Center point in the summary window.
6360 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6361 displayed, no centering will be performed."
6362   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6363   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6364   (interactive)
6365   ;; The user has to want it.
6366   (when gnus-auto-center-summary
6367     (let* ((top (cond ((< (window-height) 4) 0)
6368                       ((< (window-height) 7) 1)
6369                       (t (if (numberp gnus-auto-center-summary)
6370                              gnus-auto-center-summary
6371                            (/ (1- (window-height)) 2)))))
6372            (height (1- (window-height)))
6373            (bottom (save-excursion (goto-char (point-max))
6374                                    (forward-line (- height))
6375                                    (point)))
6376            (window (get-buffer-window (current-buffer))))
6377       (when (get-buffer-window gnus-article-buffer)
6378         ;; Only do recentering when the article buffer is displayed,
6379         ;; Set the window start to either `bottom', which is the biggest
6380         ;; possible valid number, or the second line from the top,
6381         ;; whichever is the least.
6382         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6383           (if (> bottom top-pos)
6384               ;; Keep the second line from the top visible
6385               (set-window-start window top-pos t)
6386             ;; Try to keep the bottom line visible; if it's partially
6387             ;; obscured, either scroll one more line to make it fully
6388             ;; visible, or revert to using TOP-POS.
6389             (save-excursion
6390               (goto-char (point-max))
6391               (forward-line -1)
6392               (let ((last-line-start (point)))
6393                 (goto-char bottom)
6394                 (set-window-start window (point) t)
6395                 (when (not (pos-visible-in-window-p last-line-start window))
6396                   (forward-line 1)
6397                   (set-window-start window (min (point) top-pos) t)))))))
6398       ;; Do horizontal recentering while we're at it.
6399       (when (and (get-buffer-window (current-buffer) t)
6400                  (not (eq gnus-auto-center-summary 'vertical)))
6401         (let ((selected (selected-window)))
6402           (select-window (get-buffer-window (current-buffer) t))
6403           (gnus-summary-position-point)
6404           (gnus-horizontal-recenter)
6405           (select-window selected))))))
6406
6407 (defun gnus-summary-jump-to-group (newsgroup)
6408   "Move point to NEWSGROUP in group mode buffer."
6409   ;; Keep update point of group mode buffer if visible.
6410   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6411       (save-window-excursion
6412         ;; Take care of tree window mode.
6413         (when (get-buffer-window gnus-group-buffer)
6414           (pop-to-buffer gnus-group-buffer))
6415         (gnus-group-jump-to-group newsgroup))
6416     (save-excursion
6417       ;; Take care of tree window mode.
6418       (if (get-buffer-window gnus-group-buffer)
6419           (pop-to-buffer gnus-group-buffer)
6420         (set-buffer gnus-group-buffer))
6421       (gnus-group-jump-to-group newsgroup))))
6422
6423 ;; This function returns a list of article numbers based on the
6424 ;; difference between the ranges of read articles in this group and
6425 ;; the range of active articles.
6426 (defun gnus-list-of-unread-articles (group)
6427   (let* ((read (gnus-info-read (gnus-get-info group)))
6428          (active (or (gnus-active group) (gnus-activate-group group)))
6429          (last (cdr active))
6430          first nlast unread)
6431     ;; If none are read, then all are unread.
6432     (if (not read)
6433         (setq first (car active))
6434       ;; If the range of read articles is a single range, then the
6435       ;; first unread article is the article after the last read
6436       ;; article.  Sounds logical, doesn't it?
6437       (if (and (not (listp (cdr read)))
6438                (or (< (car read) (car active))
6439                    (progn (setq read (list read))
6440                           nil)))
6441           (setq first (max (car active) (1+ (cdr read))))
6442         ;; `read' is a list of ranges.
6443         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6444                                   (caar read)))
6445                   1)
6446           (setq first (car active)))
6447         (while read
6448           (when first
6449             (while (< first nlast)
6450               (setq unread (cons first unread)
6451                     first (1+ first))))
6452           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6453           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6454           (setq read (cdr read)))))
6455     ;; And add the last unread articles.
6456     (while (<= first last)
6457       (setq unread (cons first unread)
6458             first (1+ first)))
6459     ;; Return the list of unread articles.
6460     (delq 0 (nreverse unread))))
6461
6462 (defun gnus-list-of-read-articles (group)
6463   "Return a list of unread, unticked and non-dormant articles."
6464   (let* ((info (gnus-get-info group))
6465          (marked (gnus-info-marks info))
6466          (active (gnus-active group)))
6467     (and info active
6468          (gnus-list-range-difference
6469           (gnus-list-range-difference
6470            (gnus-sorted-complement
6471             (gnus-uncompress-range active)
6472             (gnus-list-of-unread-articles group))
6473            (cdr (assq 'dormant marked)))
6474           (cdr (assq 'tick marked))))))
6475
6476 ;; This function returns a sequence of article numbers based on the
6477 ;; difference between the ranges of read articles in this group and
6478 ;; the range of active articles.
6479 (defun gnus-sequence-of-unread-articles (group)
6480   (let* ((read (gnus-info-read (gnus-get-info group)))
6481          (active (or (gnus-active group) (gnus-activate-group group)))
6482          (last (cdr active))
6483          first nlast unread)
6484     ;; If none are read, then all are unread.
6485     (if (not read)
6486         (setq first (car active))
6487       ;; If the range of read articles is a single range, then the
6488       ;; first unread article is the article after the last read
6489       ;; article.  Sounds logical, doesn't it?
6490       (if (and (not (listp (cdr read)))
6491                (or (< (car read) (car active))
6492                    (progn (setq read (list read))
6493                           nil)))
6494           (setq first (max (car active) (1+ (cdr read))))
6495         ;; `read' is a list of ranges.
6496         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6497                                   (caar read)))
6498                   1)
6499           (setq first (car active)))
6500         (while read
6501           (when first
6502             (push (cons first nlast) unread))
6503           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6504           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6505           (setq read (cdr read)))))
6506     ;; And add the last unread articles.
6507     (cond ((< first last)
6508            (push (cons first last) unread))
6509           ((= first last)
6510            (push first unread)))
6511     ;; Return the sequence of unread articles.
6512     (delq 0 (nreverse unread))))
6513
6514 ;; Various summary commands
6515
6516 (defun gnus-summary-select-article-buffer ()
6517   "Reconfigure windows to show article buffer."
6518   (interactive)
6519   (if (not (gnus-buffer-live-p gnus-article-buffer))
6520       (error "There is no article buffer for this summary buffer")
6521     (gnus-configure-windows 'article)
6522     (select-window (get-buffer-window gnus-article-buffer))))
6523
6524 (defun gnus-summary-universal-argument (arg)
6525   "Perform any operation on all articles that are process/prefixed."
6526   (interactive "P")
6527   (let ((articles (gnus-summary-work-articles arg))
6528         func article)
6529     (if (eq
6530          (setq
6531           func
6532           (key-binding
6533            (read-key-sequence
6534             (substitute-command-keys
6535              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6536          'undefined)
6537         (gnus-error 1 "Undefined key")
6538       (save-excursion
6539         (while articles
6540           (gnus-summary-goto-subject (setq article (pop articles)))
6541           (let (gnus-newsgroup-processable)
6542             (command-execute func))
6543           (gnus-summary-remove-process-mark article)))))
6544   (gnus-summary-position-point))
6545
6546 (defun gnus-summary-toggle-truncation (&optional arg)
6547   "Toggle truncation of summary lines.
6548 With ARG, turn line truncation on if ARG is positive."
6549   (interactive "P")
6550   (setq truncate-lines
6551         (if (null arg) (not truncate-lines)
6552           (> (prefix-numeric-value arg) 0)))
6553   (redraw-display))
6554
6555 (defun gnus-summary-find-for-reselect ()
6556   "Return the number of an article to stay on across a reselect.
6557 The current article is considered, then following articles, then previous
6558 articles.  An article is sought which is not cancelled and isn't a temporary
6559 insertion from another group.  If there's no such then return a dummy 0."
6560   (let (found)
6561     (dolist (rev '(nil t))
6562       (unless found      ; don't demand the reverse list if we don't need it
6563         (let ((data (gnus-data-find-list
6564                      (gnus-summary-article-number) (gnus-data-list rev))))
6565           (while (and data (not found))
6566             (if (and (< 0 (gnus-data-number (car data)))
6567                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6568                 (setq found (gnus-data-number (car data))))
6569             (setq data (cdr data))))))
6570     (or found 0)))
6571
6572 (defun gnus-summary-reselect-current-group (&optional all rescan)
6573   "Exit and then reselect the current newsgroup.
6574 The prefix argument ALL means to select all articles."
6575   (interactive "P")
6576   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6577     (error "Ephemeral groups can't be reselected"))
6578   (let ((current-subject (gnus-summary-find-for-reselect))
6579         (group gnus-newsgroup-name))
6580     (setq gnus-newsgroup-begin nil)
6581     (gnus-summary-exit nil 'leave-hidden)
6582     ;; We have to adjust the point of group mode buffer because
6583     ;; point was moved to the next unread newsgroup by exiting.
6584     (gnus-summary-jump-to-group group)
6585     (when rescan
6586       (save-excursion
6587         (gnus-group-get-new-news-this-group 1)))
6588     (gnus-group-read-group all t)
6589     (gnus-summary-goto-subject current-subject nil t)))
6590
6591 (defun gnus-summary-rescan-group (&optional all)
6592   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6593   (interactive "P")
6594   (gnus-summary-reselect-current-group all t))
6595
6596 (defun gnus-summary-update-info (&optional non-destructive)
6597   (save-excursion
6598     (let ((group gnus-newsgroup-name))
6599       (when group
6600         (when gnus-newsgroup-kill-headers
6601           (setq gnus-newsgroup-killed
6602                 (gnus-compress-sequence
6603                  (gnus-sorted-union
6604                   (gnus-list-range-intersection
6605                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6606                   gnus-newsgroup-unreads)
6607                  t)))
6608         (unless (listp (cdr gnus-newsgroup-killed))
6609           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6610         (let ((headers gnus-newsgroup-headers))
6611           ;; Set the new ranges of read articles.
6612           (with-current-buffer gnus-group-buffer
6613             (gnus-undo-force-boundary))
6614           (gnus-update-read-articles
6615            group (gnus-sorted-union
6616                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6617           ;; Set the current article marks.
6618           (let ((gnus-newsgroup-scored
6619                  (if (and (not gnus-save-score)
6620                           (not non-destructive))
6621                      nil
6622                    gnus-newsgroup-scored)))
6623             (save-excursion
6624               (gnus-update-marks)))
6625           ;; Do the cross-ref thing.
6626           (when gnus-use-cross-reference
6627             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6628           ;; Do not switch windows but change the buffer to work.
6629           (set-buffer gnus-group-buffer)
6630           (unless (gnus-ephemeral-group-p group)
6631             (gnus-group-update-group group)))))))
6632
6633 (defun gnus-summary-save-newsrc (&optional force)
6634   "Save the current number of read/marked articles in the dribble buffer.
6635 The dribble buffer will then be saved.
6636 If FORCE (the prefix), also save the .newsrc file(s)."
6637   (interactive "P")
6638   (gnus-summary-update-info t)
6639   (if force
6640       (gnus-save-newsrc-file)
6641     (gnus-dribble-save)))
6642
6643 (defun gnus-summary-exit (&optional temporary leave-hidden)
6644   "Exit reading current newsgroup, and then return to group selection mode.
6645 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6646   (interactive)
6647   (gnus-set-global-variables)
6648   (when (gnus-buffer-live-p gnus-article-buffer)
6649     (save-excursion
6650       (set-buffer gnus-article-buffer)
6651       (mm-destroy-parts gnus-article-mime-handles)
6652       ;; Set it to nil for safety reason.
6653       (setq gnus-article-mime-handle-alist nil)
6654       (setq gnus-article-mime-handles nil)))
6655   (gnus-kill-save-kill-buffer)
6656   (gnus-async-halt-prefetch)
6657   (let* ((group gnus-newsgroup-name)
6658          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6659          (gnus-group-is-exiting-p t)
6660          (mode major-mode)
6661          (group-point nil)
6662          (buf (current-buffer)))
6663     (unless quit-config
6664       ;; Do adaptive scoring, and possibly save score files.
6665       (when gnus-newsgroup-adaptive
6666         (gnus-score-adaptive))
6667       (when gnus-use-scoring
6668         (gnus-score-save)))
6669     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6670     ;; If we have several article buffers, we kill them at exit.
6671     (unless gnus-single-article-buffer
6672       (gnus-kill-buffer gnus-original-article-buffer)
6673       (setq gnus-article-current nil))
6674     (when gnus-use-cache
6675       (gnus-cache-possibly-remove-articles)
6676       (gnus-cache-save-buffers))
6677     (gnus-async-prefetch-remove-group group)
6678     (when gnus-suppress-duplicates
6679       (gnus-dup-enter-articles))
6680     (when gnus-use-trees
6681       (gnus-tree-close group))
6682     (when gnus-use-cache
6683       (gnus-cache-write-active))
6684     ;; Remove entries for this group.
6685     (nnmail-purge-split-history (gnus-group-real-name group))
6686     ;; Make all changes in this group permanent.
6687     (unless quit-config
6688       (gnus-run-hooks 'gnus-exit-group-hook)
6689       (gnus-summary-update-info))
6690     (gnus-close-group group)
6691     ;; Make sure where we were, and go to next newsgroup.
6692     (set-buffer gnus-group-buffer)
6693     (unless quit-config
6694       (gnus-group-jump-to-group group))
6695     (gnus-run-hooks 'gnus-summary-exit-hook)
6696     (unless (or quit-config
6697                 ;; If this group has disappeared from the summary
6698                 ;; buffer, don't skip forwards.
6699                 (not (string= group (gnus-group-group-name))))
6700       (gnus-group-next-unread-group 1))
6701     (setq group-point (point))
6702     (if temporary
6703         nil                             ;Nothing to do.
6704       ;; If we have several article buffers, we kill them at exit.
6705       (unless gnus-single-article-buffer
6706         (gnus-kill-buffer gnus-article-buffer)
6707         (gnus-kill-buffer gnus-original-article-buffer)
6708         (setq gnus-article-current nil))
6709       (set-buffer buf)
6710       (if (not gnus-kill-summary-on-exit)
6711           (progn
6712             (gnus-deaden-summary)
6713             (setq mode nil))
6714         ;; We set all buffer-local variables to nil.  It is unclear why
6715         ;; this is needed, but if we don't, buffer-local variables are
6716         ;; not garbage-collected, it seems.  This would the lead to en
6717         ;; ever-growing Emacs.
6718         (gnus-summary-clear-local-variables)
6719         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6720           (gnus-summary-clear-local-variables))
6721         (when (get-buffer gnus-article-buffer)
6722           (bury-buffer gnus-article-buffer))
6723         ;; We clear the global counterparts of the buffer-local
6724         ;; variables as well, just to be on the safe side.
6725         (set-buffer gnus-group-buffer)
6726         (gnus-summary-clear-local-variables)
6727         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6728           (gnus-summary-clear-local-variables))
6729         ;; Return to group mode buffer.
6730         (when (eq mode 'gnus-summary-mode)
6731           (gnus-kill-buffer buf)))
6732       (setq gnus-current-select-method gnus-select-method)
6733       (if leave-hidden
6734           (set-buffer gnus-group-buffer)
6735         (pop-to-buffer gnus-group-buffer))
6736       (if (not quit-config)
6737           (progn
6738             (goto-char group-point)
6739             (unless leave-hidden
6740               (gnus-configure-windows 'group 'force)))
6741         (gnus-handle-ephemeral-exit quit-config))
6742       ;; Clear the current group name.
6743       (unless quit-config
6744         (setq gnus-newsgroup-name nil)))))
6745
6746 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6747 (defun gnus-summary-exit-no-update (&optional no-questions)
6748   "Quit reading current newsgroup without updating read article info."
6749   (interactive)
6750   (let* ((group gnus-newsgroup-name)
6751          (gnus-group-is-exiting-p t)
6752          (gnus-group-is-exiting-without-update-p t)
6753          (quit-config (gnus-group-quit-config group)))
6754     (when (or no-questions
6755               gnus-expert-user
6756               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6757       (gnus-async-halt-prefetch)
6758       (run-hooks 'gnus-summary-prepare-exit-hook)
6759       (when (gnus-buffer-live-p gnus-article-buffer)
6760         (save-excursion
6761           (set-buffer gnus-article-buffer)
6762           (mm-destroy-parts gnus-article-mime-handles)
6763           ;; Set it to nil for safety reason.
6764           (setq gnus-article-mime-handle-alist nil)
6765           (setq gnus-article-mime-handles nil)))
6766       ;; If we have several article buffers, we kill them at exit.
6767       (unless gnus-single-article-buffer
6768         (gnus-kill-buffer gnus-article-buffer)
6769         (gnus-kill-buffer gnus-original-article-buffer)
6770         (setq gnus-article-current nil))
6771       (if (not gnus-kill-summary-on-exit)
6772           (gnus-deaden-summary)
6773         (gnus-close-group group)
6774         (gnus-summary-clear-local-variables)
6775         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6776           (gnus-summary-clear-local-variables))
6777         (set-buffer gnus-group-buffer)
6778         (gnus-summary-clear-local-variables)
6779         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6780           (gnus-summary-clear-local-variables))
6781         (gnus-kill-buffer gnus-summary-buffer))
6782       (unless gnus-single-article-buffer
6783         (setq gnus-article-current nil))
6784       (when gnus-use-trees
6785         (gnus-tree-close group))
6786       (gnus-async-prefetch-remove-group group)
6787       (when (get-buffer gnus-article-buffer)
6788         (bury-buffer gnus-article-buffer))
6789       ;; Return to the group buffer.
6790       (gnus-configure-windows 'group 'force)
6791       ;; Clear the current group name.
6792       (setq gnus-newsgroup-name nil)
6793       (unless (gnus-ephemeral-group-p group)
6794         (gnus-group-update-group group))
6795       (when (equal (gnus-group-group-name) group)
6796         (gnus-group-next-unread-group 1))
6797       (when quit-config
6798         (gnus-handle-ephemeral-exit quit-config)))))
6799
6800 (defun gnus-handle-ephemeral-exit (quit-config)
6801   "Handle movement when leaving an ephemeral group.
6802 The state which existed when entering the ephemeral is reset."
6803   (if (not (buffer-name (car quit-config)))
6804       (gnus-configure-windows 'group 'force)
6805     (set-buffer (car quit-config))
6806     (cond ((eq major-mode 'gnus-summary-mode)
6807            (gnus-set-global-variables))
6808           ((eq major-mode 'gnus-article-mode)
6809            (save-excursion
6810              ;; The `gnus-summary-buffer' variable may point
6811              ;; to the old summary buffer when using a single
6812              ;; article buffer.
6813              (unless (gnus-buffer-live-p gnus-summary-buffer)
6814                (set-buffer gnus-group-buffer))
6815              (set-buffer gnus-summary-buffer)
6816              (gnus-set-global-variables))))
6817     (if (or (eq (cdr quit-config) 'article)
6818             (eq (cdr quit-config) 'pick))
6819         (progn
6820           ;; The current article may be from the ephemeral group
6821           ;; thus it is best that we reload this article
6822           ;;
6823           ;; If we're exiting from a large digest, this can be
6824           ;; extremely slow.  So, it's better not to reload it. -- jh.
6825           ;;(gnus-summary-show-article)
6826           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6827               (gnus-configure-windows 'pick 'force)
6828             (gnus-configure-windows (cdr quit-config) 'force)))
6829       (gnus-configure-windows (cdr quit-config) 'force))
6830     (when (eq major-mode 'gnus-summary-mode)
6831       (gnus-summary-next-subject 1 nil t)
6832       (gnus-summary-recenter)
6833       (gnus-summary-position-point))))
6834
6835 ;;; Dead summaries.
6836
6837 (defvar gnus-dead-summary-mode-map nil)
6838
6839 (unless gnus-dead-summary-mode-map
6840   (setq gnus-dead-summary-mode-map (make-keymap))
6841   (suppress-keymap gnus-dead-summary-mode-map)
6842   (substitute-key-definition
6843    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6844   (dolist (key '("\C-d" "\r" "\177" [delete]))
6845     (define-key gnus-dead-summary-mode-map
6846       key 'gnus-summary-wake-up-the-dead))
6847   (dolist (key '("q" "Q"))
6848     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6849
6850 (defvar gnus-dead-summary-mode nil
6851   "Minor mode for Gnus summary buffers.")
6852
6853 (defun gnus-dead-summary-mode (&optional arg)
6854   "Minor mode for Gnus summary buffers."
6855   (interactive "P")
6856   (when (eq major-mode 'gnus-summary-mode)
6857     (make-local-variable 'gnus-dead-summary-mode)
6858     (setq gnus-dead-summary-mode
6859           (if (null arg) (not gnus-dead-summary-mode)
6860             (> (prefix-numeric-value arg) 0)))
6861     (when gnus-dead-summary-mode
6862       (add-minor-mode
6863        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6864
6865 (defun gnus-deaden-summary ()
6866   "Make the current summary buffer into a dead summary buffer."
6867   ;; Kill any previous dead summary buffer.
6868   (when (and gnus-dead-summary
6869              (buffer-name gnus-dead-summary))
6870     (with-current-buffer gnus-dead-summary
6871       (when gnus-dead-summary-mode
6872         (kill-buffer (current-buffer)))))
6873   ;; Make this the current dead summary.
6874   (setq gnus-dead-summary (current-buffer))
6875   (gnus-dead-summary-mode 1)
6876   (let ((name (buffer-name)))
6877     (when (string-match "Summary" name)
6878       (rename-buffer
6879        (concat (substring name 0 (match-beginning 0)) "Dead "
6880                (substring name (match-beginning 0)))
6881        t)
6882       (bury-buffer))))
6883
6884 (defun gnus-kill-or-deaden-summary (buffer)
6885   "Kill or deaden the summary BUFFER."
6886   (save-excursion
6887     (when (and (buffer-name buffer)
6888                (not gnus-single-article-buffer))
6889       (with-current-buffer buffer
6890         (gnus-kill-buffer gnus-article-buffer)
6891         (gnus-kill-buffer gnus-original-article-buffer)))
6892     (cond
6893      ;; Kill the buffer.
6894      (gnus-kill-summary-on-exit
6895       (when (and gnus-use-trees
6896                  (gnus-buffer-exists-p buffer))
6897         (save-excursion
6898           (set-buffer buffer)
6899           (gnus-tree-close gnus-newsgroup-name)))
6900       (gnus-kill-buffer buffer))
6901      ;; Deaden the buffer.
6902      ((gnus-buffer-exists-p buffer)
6903       (save-excursion
6904         (set-buffer buffer)
6905         (gnus-deaden-summary))))))
6906
6907 (defun gnus-summary-wake-up-the-dead (&rest args)
6908   "Wake up the dead summary buffer."
6909   (interactive)
6910   (gnus-dead-summary-mode -1)
6911   (let ((name (buffer-name)))
6912     (when (string-match "Dead " name)
6913       (rename-buffer
6914        (concat (substring name 0 (match-beginning 0))
6915                (substring name (match-end 0)))
6916        t)))
6917   (gnus-message 3 "This dead summary is now alive again"))
6918
6919 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6920 (defun gnus-summary-fetch-faq (&optional faq-dir)
6921   "Fetch the FAQ for the current group.
6922 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6923 in."
6924   (interactive
6925    (list
6926     (when current-prefix-arg
6927       (completing-read
6928        "FAQ dir: " (and (listp gnus-group-faq-directory)
6929                         (mapcar 'list
6930                                 gnus-group-faq-directory))))))
6931   (let (gnus-faq-buffer)
6932     (when (setq gnus-faq-buffer
6933                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6934       (gnus-configure-windows 'summary-faq))))
6935
6936 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6937 (defun gnus-summary-describe-group (&optional force)
6938   "Describe the current newsgroup."
6939   (interactive "P")
6940   (gnus-group-describe-group force gnus-newsgroup-name))
6941
6942 (defun gnus-summary-describe-briefly ()
6943   "Describe summary mode commands briefly."
6944   (interactive)
6945   (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")))
6946
6947 ;; Walking around group mode buffer from summary mode.
6948
6949 (defun gnus-summary-next-group (&optional no-article target-group backward)
6950   "Exit current newsgroup and then select next unread newsgroup.
6951 If prefix argument NO-ARTICLE is non-nil, no article is selected
6952 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6953 previous group instead."
6954   (interactive "P")
6955   ;; Stop pre-fetching.
6956   (gnus-async-halt-prefetch)
6957   (let ((current-group gnus-newsgroup-name)
6958         (current-buffer (current-buffer))
6959         entered)
6960     ;; First we semi-exit this group to update Xrefs and all variables.
6961     ;; We can't do a real exit, because the window conf must remain
6962     ;; the same in case the user is prompted for info, and we don't
6963     ;; want the window conf to change before that...
6964     (gnus-summary-exit t)
6965     (while (not entered)
6966       ;; Then we find what group we are supposed to enter.
6967       (set-buffer gnus-group-buffer)
6968       (gnus-group-jump-to-group current-group)
6969       (setq target-group
6970             (or target-group
6971                 (if (eq gnus-keep-same-level 'best)
6972                     (gnus-summary-best-group gnus-newsgroup-name)
6973                   (gnus-summary-search-group backward gnus-keep-same-level))))
6974       (if (not target-group)
6975           ;; There are no further groups, so we return to the group
6976           ;; buffer.
6977           (progn
6978             (gnus-message 5 "Returning to the group buffer")
6979             (setq entered t)
6980             (when (gnus-buffer-live-p current-buffer)
6981               (set-buffer current-buffer)
6982               (gnus-summary-exit))
6983             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6984         ;; We try to enter the target group.
6985         (gnus-group-jump-to-group target-group)
6986         (let ((unreads (gnus-group-group-unread)))
6987           (if (and (or (eq t unreads)
6988                        (and unreads (not (zerop unreads))))
6989                    (gnus-summary-read-group
6990                     target-group nil no-article
6991                     (and (buffer-name current-buffer) current-buffer)
6992                     nil backward))
6993               (setq entered t)
6994             (setq current-group target-group
6995                   target-group nil)))))))
6996
6997 (defun gnus-summary-prev-group (&optional no-article)
6998   "Exit current newsgroup and then select previous unread newsgroup.
6999 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7000   (interactive "P")
7001   (gnus-summary-next-group no-article nil t))
7002
7003 ;; Walking around summary lines.
7004
7005 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7006   "Go to the first subject satisfying any non-nil constraint.
7007 If UNREAD is non-nil, the article should be unread.
7008 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7009 If UNSEEN is non-nil, the article should be unseen.
7010 Returns the article selected or nil if there are no matching articles."
7011   (interactive "P")
7012   (cond
7013    ;; Empty summary.
7014    ((null gnus-newsgroup-data)
7015     (gnus-message 3 "No articles in the group")
7016     nil)
7017    ;; Pick the first article.
7018    ((not (or unread undownloaded unseen))
7019     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7020     (gnus-data-number (car gnus-newsgroup-data)))
7021    ;; Find the first unread article.
7022    (t
7023     (let ((data gnus-newsgroup-data))
7024       (while (and data
7025                   (let ((num (gnus-data-number (car data))))
7026                     (or (memq num gnus-newsgroup-unfetched)
7027                         (not (or (and unread
7028                                       (memq num gnus-newsgroup-unreads))
7029                                  (and undownloaded
7030                                       (memq num gnus-newsgroup-undownloaded))
7031                                  (and unseen
7032                                       (memq num gnus-newsgroup-unseen)))))))
7033         (setq data (cdr data)))
7034       (prog1
7035           (if data
7036               (progn
7037                 (goto-char (gnus-data-pos (car data)))
7038                 (gnus-data-number (car data)))
7039             (gnus-message 3 "No more%s articles"
7040                           (let* ((r (when unread " unread"))
7041                                  (d (when undownloaded " undownloaded"))
7042                                  (s (when unseen " unseen"))
7043                                  (l (delq nil (list r d s))))
7044                             (cond ((= 3 (length l))
7045                                    (concat r "," d ", or" s))
7046                                   ((= 2 (length l))
7047                                    (concat (car l) ", or" (cadr l)))
7048                                   ((= 1 (length l))
7049                                    (car l))
7050                                   (t
7051                                    ""))))
7052             nil
7053             )
7054         (gnus-summary-position-point))))))
7055
7056 (defun gnus-summary-next-subject (n &optional unread dont-display)
7057   "Go to next N'th summary line.
7058 If N is negative, go to the previous N'th subject line.
7059 If UNREAD is non-nil, only unread articles are selected.
7060 The difference between N and the actual number of steps taken is
7061 returned."
7062   (interactive "p")
7063   (let ((backward (< n 0))
7064         (n (abs n)))
7065     (while (and (> n 0)
7066                 (if backward
7067                     (gnus-summary-find-prev unread)
7068                   (gnus-summary-find-next unread)))
7069       (unless (zerop (setq n (1- n)))
7070         (gnus-summary-show-thread)))
7071     (when (/= 0 n)
7072       (gnus-message 7 "No more%s articles"
7073                     (if unread " unread" "")))
7074     (unless dont-display
7075       (gnus-summary-recenter)
7076       (gnus-summary-position-point))
7077     n))
7078
7079 (defun gnus-summary-next-unread-subject (n)
7080   "Go to next N'th unread summary line."
7081   (interactive "p")
7082   (gnus-summary-next-subject n t))
7083
7084 (defun gnus-summary-prev-subject (n &optional unread)
7085   "Go to previous N'th summary line.
7086 If optional argument UNREAD is non-nil, only unread article is selected."
7087   (interactive "p")
7088   (gnus-summary-next-subject (- n) unread))
7089
7090 (defun gnus-summary-prev-unread-subject (n)
7091   "Go to previous N'th unread summary line."
7092   (interactive "p")
7093   (gnus-summary-next-subject (- n) t))
7094
7095 (defun gnus-summary-goto-subjects (articles)
7096   "Insert the subject header for ARTICLES in the current buffer."
7097   (save-excursion
7098     (dolist (article articles)
7099       (gnus-summary-goto-subject article t)))
7100   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7101   (gnus-summary-position-point))
7102  
7103 (defun gnus-summary-goto-subject (article &optional force silent)
7104   "Go the subject line of ARTICLE.
7105 If FORCE, also allow jumping to articles not currently shown."
7106   (interactive "nArticle number: ")
7107   (unless (numberp article)
7108     (error "Article %s is not a number" article))
7109   (let ((b (point))
7110         (data (gnus-data-find article)))
7111     ;; We read in the article if we have to.
7112     (and (not data)
7113          force
7114          (gnus-summary-insert-subject
7115           article
7116           (if (or (numberp force) (vectorp force)) force)
7117           t)
7118          (setq data (gnus-data-find article)))
7119     (goto-char b)
7120     (if (not data)
7121         (progn
7122           (unless silent
7123             (gnus-message 3 "Can't find article %d" article))
7124           nil)
7125       (let ((pt (gnus-data-pos data)))
7126         (goto-char pt)
7127         (gnus-summary-set-article-display-arrow pt))
7128       (gnus-summary-position-point)
7129       article)))
7130
7131 ;; Walking around summary lines with displaying articles.
7132
7133 (defun gnus-summary-expand-window (&optional arg)
7134   "Make the summary buffer take up the entire Emacs frame.
7135 Given a prefix, will force an `article' buffer configuration."
7136   (interactive "P")
7137   (if arg
7138       (gnus-configure-windows 'article 'force)
7139     (gnus-configure-windows 'summary 'force)))
7140
7141 (defun gnus-summary-display-article (article &optional all-header)
7142   "Display ARTICLE in article buffer."
7143   (when (gnus-buffer-live-p gnus-article-buffer)
7144     (with-current-buffer gnus-article-buffer
7145       (mm-enable-multibyte)))
7146   (gnus-set-global-variables)
7147   (when (gnus-buffer-live-p gnus-article-buffer)
7148     (with-current-buffer gnus-article-buffer
7149       (setq gnus-article-charset gnus-newsgroup-charset)
7150       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7151       (mm-enable-multibyte)))
7152   (if (null article)
7153       nil
7154     (prog1
7155         (if gnus-summary-display-article-function
7156             (funcall gnus-summary-display-article-function article all-header)
7157           (gnus-article-prepare article all-header))
7158       (gnus-run-hooks 'gnus-select-article-hook)
7159       (when (and gnus-current-article
7160                  (not (zerop gnus-current-article)))
7161         (gnus-summary-goto-subject gnus-current-article))
7162       (gnus-summary-recenter)
7163       (when (and gnus-use-trees gnus-show-threads)
7164         (gnus-possibly-generate-tree article)
7165         (gnus-highlight-selected-tree article))
7166       ;; Successfully display article.
7167       (gnus-article-set-window-start
7168        (cdr (assq article gnus-newsgroup-bookmarks))))))
7169
7170 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7171   "Select the current article.
7172 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7173 non-nil, the article will be re-fetched even if it already present in
7174 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7175 be displayed."
7176   ;; Make sure we are in the summary buffer to work around bbdb bug.
7177   (unless (eq major-mode 'gnus-summary-mode)
7178     (set-buffer gnus-summary-buffer))
7179   (let ((article (or article (gnus-summary-article-number)))
7180         (all-headers (not (not all-headers))) ;Must be t or nil.
7181         gnus-summary-display-article-function)
7182     (and (not pseudo)
7183          (gnus-summary-article-pseudo-p article)
7184          (error "This is a pseudo-article"))
7185     (save-excursion
7186       (set-buffer gnus-summary-buffer)
7187       (if (or (and gnus-single-article-buffer
7188                    (or (null gnus-current-article)
7189                        (null gnus-article-current)
7190                        (null (get-buffer gnus-article-buffer))
7191                        (not (eq article (cdr gnus-article-current)))
7192                        (not (equal (car gnus-article-current)
7193                                    gnus-newsgroup-name))))
7194               (and (not gnus-single-article-buffer)
7195                    (or (null gnus-current-article)
7196                        (not (eq gnus-current-article article))))
7197               force)
7198           ;; The requested article is different from the current article.
7199           (progn
7200             (gnus-summary-display-article article all-headers)
7201             (when (gnus-buffer-live-p gnus-article-buffer)
7202               (with-current-buffer gnus-article-buffer
7203                 (if (not gnus-article-decoded-p) ;; a local variable
7204                     (mm-disable-multibyte))))
7205             (gnus-article-set-window-start
7206              (cdr (assq article gnus-newsgroup-bookmarks)))
7207             article)
7208         'old))))
7209
7210 (defun gnus-summary-force-verify-and-decrypt ()
7211   "Display buttons for signed/encrypted parts and verify/decrypt them."
7212   (interactive)
7213   (let ((mm-verify-option 'known)
7214         (mm-decrypt-option 'known)
7215         (gnus-article-emulate-mime t)
7216         (gnus-buttonized-mime-types (append (list "multipart/signed"
7217                                                   "multipart/encrypted")
7218                                             gnus-buttonized-mime-types)))
7219     (gnus-summary-select-article nil 'force)))
7220
7221 (defun gnus-summary-set-current-mark (&optional current-mark)
7222   "Obsolete function."
7223   nil)
7224
7225 (defun gnus-summary-next-article (&optional unread subject backward push)
7226   "Select the next article.
7227 If UNREAD, only unread articles are selected.
7228 If SUBJECT, only articles with SUBJECT are selected.
7229 If BACKWARD, the previous article is selected instead of the next."
7230   (interactive "P")
7231   (cond
7232    ;; Is there such an article?
7233    ((and (gnus-summary-search-forward unread subject backward)
7234          (or (gnus-summary-display-article (gnus-summary-article-number))
7235              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7236     (gnus-summary-position-point))
7237    ;; If not, we try the first unread, if that is wanted.
7238    ((and subject
7239          gnus-auto-select-same
7240          (gnus-summary-first-unread-article))
7241     (gnus-summary-position-point)
7242     (gnus-message 6 "Wrapped"))
7243    ;; Try to get next/previous article not displayed in this group.
7244    ((and gnus-auto-extend-newsgroup
7245          (not unread) (not subject))
7246     (gnus-summary-goto-article
7247      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7248      nil (count-lines (point-min) (point))))
7249    ;; Go to next/previous group.
7250    (t
7251     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7252       (gnus-summary-jump-to-group gnus-newsgroup-name))
7253     (let ((cmd last-command-char)
7254           (point
7255            (with-current-buffer gnus-group-buffer
7256              (point)))
7257           (group
7258            (if (eq gnus-keep-same-level 'best)
7259                (gnus-summary-best-group gnus-newsgroup-name)
7260              (gnus-summary-search-group backward gnus-keep-same-level))))
7261       ;; For some reason, the group window gets selected.  We change
7262       ;; it back.
7263       (select-window (get-buffer-window (current-buffer)))
7264       ;; Select next unread newsgroup automagically.
7265       (cond
7266        ((or (not gnus-auto-select-next)
7267             (not cmd))
7268         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7269        ((or (eq gnus-auto-select-next 'quietly)
7270             (and (eq gnus-auto-select-next 'slightly-quietly)
7271                  push)
7272             (and (eq gnus-auto-select-next 'almost-quietly)
7273                  (gnus-summary-last-article-p)))
7274         ;; Select quietly.
7275         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7276             (gnus-summary-exit)
7277           (gnus-message 7 "No more%s articles (%s)..."
7278                         (if unread " unread" "")
7279                         (if group (concat "selecting " group)
7280                           "exiting"))
7281           (gnus-summary-next-group nil group backward)))
7282        (t
7283         (when (gnus-key-press-event-p last-input-event)
7284           (gnus-summary-walk-group-buffer
7285            gnus-newsgroup-name cmd unread backward point))))))))
7286
7287 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7288   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7289                       (?\C-p (gnus-group-prev-unread-group 1))))
7290         (cursor-in-echo-area t)
7291         keve key group ended prompt)
7292     (save-excursion
7293       (set-buffer gnus-group-buffer)
7294       (goto-char start)
7295       (setq group
7296             (if (eq gnus-keep-same-level 'best)
7297                 (gnus-summary-best-group gnus-newsgroup-name)
7298               (gnus-summary-search-group backward gnus-keep-same-level))))
7299     (while (not ended)
7300       (setq prompt
7301             (format
7302              "No more%s articles%s " (if unread " unread" "")
7303              (if (and group
7304                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7305                  (format " (Type %s for %s [%s])"
7306                          (single-key-description cmd) group
7307                          (gnus-group-unread group))
7308                (format " (Type %s to exit %s)"
7309                        (single-key-description cmd)
7310                        gnus-newsgroup-name))))
7311       ;; Confirm auto selection.
7312       (setq key (car (setq keve (gnus-read-event-char prompt)))
7313             ended t)
7314       (cond
7315        ((assq key keystrokes)
7316         (let ((obuf (current-buffer)))
7317           (switch-to-buffer gnus-group-buffer)
7318           (when group
7319             (gnus-group-jump-to-group group))
7320           (eval (cadr (assq key keystrokes)))
7321           (setq group (gnus-group-group-name))
7322           (switch-to-buffer obuf))
7323         (setq ended nil))
7324        ((equal key cmd)
7325         (if (or (not group)
7326                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7327             (gnus-summary-exit)
7328           (gnus-summary-next-group nil group backward)))
7329        (t
7330         (push (cdr keve) unread-command-events))))))
7331
7332 (defun gnus-summary-next-unread-article ()
7333   "Select unread article after current one."
7334   (interactive)
7335   (gnus-summary-next-article
7336    (or (not (eq gnus-summary-goto-unread 'never))
7337        (gnus-summary-last-article-p (gnus-summary-article-number)))
7338    (and gnus-auto-select-same
7339         (gnus-summary-article-subject))))
7340
7341 (defun gnus-summary-prev-article (&optional unread subject)
7342   "Select the article after the current one.
7343 If UNREAD is non-nil, only unread articles are selected."
7344   (interactive "P")
7345   (gnus-summary-next-article unread subject t))
7346
7347 (defun gnus-summary-prev-unread-article ()
7348   "Select unread article before current one."
7349   (interactive)
7350   (gnus-summary-prev-article
7351    (or (not (eq gnus-summary-goto-unread 'never))
7352        (gnus-summary-first-article-p (gnus-summary-article-number)))
7353    (and gnus-auto-select-same
7354         (gnus-summary-article-subject))))
7355
7356 (defun gnus-summary-next-page (&optional lines circular stop)
7357   "Show next page of the selected article.
7358 If at the end of the current article, select the next article.
7359 LINES says how many lines should be scrolled up.
7360
7361 If CIRCULAR is non-nil, go to the start of the article instead of
7362 selecting the next article when reaching the end of the current
7363 article.
7364
7365 If STOP is non-nil, just stop when reaching the end of the message.
7366
7367 Also see the variable `gnus-article-skip-boring'."
7368   (interactive "P")
7369   (setq gnus-summary-buffer (current-buffer))
7370   (gnus-set-global-variables)
7371   (let ((article (gnus-summary-article-number))
7372         (article-window (get-buffer-window gnus-article-buffer t))
7373         endp)
7374     ;; If the buffer is empty, we have no article.
7375     (unless article
7376       (error "No article to select"))
7377     (gnus-configure-windows 'article)
7378     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7379         (if (and (eq gnus-summary-goto-unread 'never)
7380                  (not (gnus-summary-last-article-p article)))
7381             (gnus-summary-next-article)
7382           (gnus-summary-next-unread-article))
7383       (if (or (null gnus-current-article)
7384               (null gnus-article-current)
7385               (/= article (cdr gnus-article-current))
7386               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7387           ;; Selected subject is different from current article's.
7388           (gnus-summary-display-article article)
7389         (when article-window
7390           (gnus-eval-in-buffer-window gnus-article-buffer
7391             (setq endp (or (gnus-article-next-page lines)
7392                            (gnus-article-only-boring-p))))
7393           (when endp
7394             (cond (stop
7395                    (gnus-message 3 "End of message"))
7396                   (circular
7397                    (gnus-summary-beginning-of-article))
7398                   (lines
7399                    (gnus-message 3 "End of message"))
7400                   ((null lines)
7401                    (if (and (eq gnus-summary-goto-unread 'never)
7402                             (not (gnus-summary-last-article-p article)))
7403                        (gnus-summary-next-article)
7404                      (gnus-summary-next-unread-article))))))))
7405     (gnus-summary-recenter)
7406     (gnus-summary-position-point)))
7407
7408 (defun gnus-summary-prev-page (&optional lines move)
7409   "Show previous page of selected article.
7410 Argument LINES specifies lines to be scrolled down.
7411 If MOVE, move to the previous unread article if point is at
7412 the beginning of the buffer."
7413   (interactive "P")
7414   (let ((article (gnus-summary-article-number))
7415         (article-window (get-buffer-window gnus-article-buffer t))
7416         endp)
7417     (gnus-configure-windows 'article)
7418     (if (or (null gnus-current-article)
7419             (null gnus-article-current)
7420             (/= article (cdr gnus-article-current))
7421             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7422         ;; Selected subject is different from current article's.
7423         (gnus-summary-display-article article)
7424       (gnus-summary-recenter)
7425       (when article-window
7426         (gnus-eval-in-buffer-window gnus-article-buffer
7427           (setq endp (gnus-article-prev-page lines)))
7428         (when (and move endp)
7429           (cond (lines
7430                  (gnus-message 3 "Beginning of message"))
7431                 ((null lines)
7432                  (if (and (eq gnus-summary-goto-unread 'never)
7433                           (not (gnus-summary-first-article-p article)))
7434                      (gnus-summary-prev-article)
7435                    (gnus-summary-prev-unread-article))))))))
7436   (gnus-summary-position-point))
7437
7438 (defun gnus-summary-prev-page-or-article (&optional lines)
7439   "Show previous page of selected article.
7440 Argument LINES specifies lines to be scrolled down.
7441 If at the beginning of the article, go to the next article."
7442   (interactive "P")
7443   (gnus-summary-prev-page lines t))
7444
7445 (defun gnus-summary-scroll-up (lines)
7446   "Scroll up (or down) one line current article.
7447 Argument LINES specifies lines to be scrolled up (or down if negative)."
7448   (interactive "p")
7449   (gnus-configure-windows 'article)
7450   (gnus-summary-show-thread)
7451   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7452     (gnus-eval-in-buffer-window gnus-article-buffer
7453       (cond ((> lines 0)
7454              (when (gnus-article-next-page lines)
7455                (gnus-message 3 "End of message")))
7456             ((< lines 0)
7457              (gnus-article-prev-page (- lines))))))
7458   (gnus-summary-recenter)
7459   (gnus-summary-position-point))
7460
7461 (defun gnus-summary-scroll-down (lines)
7462   "Scroll down (or up) one line current article.
7463 Argument LINES specifies lines to be scrolled down (or up if negative)."
7464   (interactive "p")
7465   (gnus-summary-scroll-up (- lines)))
7466
7467 (defun gnus-summary-next-same-subject ()
7468   "Select next article which has the same subject as current one."
7469   (interactive)
7470   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7471
7472 (defun gnus-summary-prev-same-subject ()
7473   "Select previous article which has the same subject as current one."
7474   (interactive)
7475   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7476
7477 (defun gnus-summary-next-unread-same-subject ()
7478   "Select next unread article which has the same subject as current one."
7479   (interactive)
7480   (gnus-summary-next-article t (gnus-summary-article-subject)))
7481
7482 (defun gnus-summary-prev-unread-same-subject ()
7483   "Select previous unread article which has the same subject as current one."
7484   (interactive)
7485   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7486
7487 (defun gnus-summary-first-unread-article ()
7488   "Select 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-display-article (gnus-summary-article-number)))
7496     (gnus-summary-position-point)))
7497
7498 (defun gnus-summary-first-unread-subject ()
7499   "Place the point on the subject line of the first unread article.
7500 Return nil if there are no unread articles."
7501   (interactive)
7502   (prog1
7503       (when (gnus-summary-first-subject t)
7504         (gnus-summary-show-thread)
7505         (gnus-summary-first-subject t))
7506     (gnus-summary-position-point)))
7507
7508 (defun gnus-summary-first-unseen-subject ()
7509   "Place the point on the subject line of the first unseen article.
7510 Return nil if there are no unseen articles."
7511   (interactive)
7512   (prog1
7513       (when (gnus-summary-first-subject nil nil t)
7514         (gnus-summary-show-thread)
7515         (gnus-summary-first-subject nil nil t))
7516     (gnus-summary-position-point)))
7517
7518 (defun gnus-summary-first-unseen-or-unread-subject ()
7519   "Place the point on the subject line of the first unseen article or,
7520 if all article have been seen, on the subject line of the first unread
7521 article."
7522   (interactive)
7523   (prog1
7524       (unless (when (gnus-summary-first-subject nil nil t)
7525                 (gnus-summary-show-thread)
7526                 (gnus-summary-first-subject nil nil t))
7527         (when (gnus-summary-first-subject t)
7528           (gnus-summary-show-thread)
7529           (gnus-summary-first-subject t)))
7530     (gnus-summary-position-point)))
7531
7532 (defun gnus-summary-first-article ()
7533   "Select the first article.
7534 Return nil if there are no articles."
7535   (interactive)
7536   (prog1
7537       (when (gnus-summary-first-subject)
7538         (gnus-summary-show-thread)
7539         (gnus-summary-first-subject)
7540         (gnus-summary-display-article (gnus-summary-article-number)))
7541     (gnus-summary-position-point)))
7542
7543 (defun gnus-summary-best-unread-article (&optional arg)
7544   "Select the unread article with the highest score.
7545 If given a prefix argument, select the next unread article that has a
7546 score higher than the default score."
7547   (interactive "P")
7548   (let ((article (if arg
7549                      (gnus-summary-better-unread-subject)
7550                    (gnus-summary-best-unread-subject))))
7551     (if article
7552         (gnus-summary-goto-article article)
7553       (error "No unread articles"))))
7554
7555 (defun gnus-summary-best-unread-subject ()
7556   "Select the unread subject with the highest score."
7557   (interactive)
7558   (let ((best -1000000)
7559         (data gnus-newsgroup-data)
7560         article score)
7561     (while data
7562       (and (gnus-data-unread-p (car data))
7563            (> (setq score
7564                     (gnus-summary-article-score (gnus-data-number (car data))))
7565               best)
7566            (setq best score
7567                  article (gnus-data-number (car data))))
7568       (setq data (cdr data)))
7569     (when article
7570       (gnus-summary-goto-subject article))
7571     (gnus-summary-position-point)
7572     article))
7573
7574 (defun gnus-summary-better-unread-subject ()
7575   "Select the first unread subject that has a score over the default score."
7576   (interactive)
7577   (let ((data gnus-newsgroup-data)
7578         article score)
7579     (while (and (setq article (gnus-data-number (car data)))
7580                 (or (gnus-data-read-p (car data))
7581                     (not (> (gnus-summary-article-score article)
7582                             gnus-summary-default-score))))
7583       (setq data (cdr data)))
7584     (when article
7585       (gnus-summary-goto-subject article))
7586     (gnus-summary-position-point)
7587     article))
7588
7589 (defun gnus-summary-last-subject ()
7590   "Go to the last displayed subject line in the group."
7591   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7592     (when article
7593       (gnus-summary-goto-subject article))))
7594
7595 (defun gnus-summary-goto-article (article &optional all-headers force)
7596   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7597 If ALL-HEADERS is non-nil, no header lines are hidden.
7598 If FORCE, go to the article even if it isn't displayed.  If FORCE
7599 is a number, it is the line the article is to be displayed on."
7600   (interactive
7601    (list
7602     (completing-read
7603      "Article number or Message-ID: "
7604      (mapcar (lambda (number) (list (int-to-string number)))
7605              gnus-newsgroup-limit))
7606     current-prefix-arg
7607     t))
7608   (prog1
7609       (if (and (stringp article)
7610                (string-match "@\\|%40" article))
7611           (gnus-summary-refer-article article)
7612         (when (stringp article)
7613           (setq article (string-to-number article)))
7614         (if (gnus-summary-goto-subject article force)
7615             (gnus-summary-display-article article all-headers)
7616           (gnus-message 4 "Couldn't go to article %s" article) nil))
7617     (gnus-summary-position-point)))
7618
7619 (defun gnus-summary-goto-last-article ()
7620   "Go to the previously read article."
7621   (interactive)
7622   (prog1
7623       (when gnus-last-article
7624         (gnus-summary-goto-article gnus-last-article nil t))
7625     (gnus-summary-position-point)))
7626
7627 (defun gnus-summary-pop-article (number)
7628   "Pop one article off the history and go to the previous.
7629 NUMBER articles will be popped off."
7630   (interactive "p")
7631   (let (to)
7632     (setq gnus-newsgroup-history
7633           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7634     (if to
7635         (gnus-summary-goto-article (car to) nil t)
7636       (error "Article history empty")))
7637   (gnus-summary-position-point))
7638
7639 ;; Summary commands and functions for limiting the summary buffer.
7640
7641 (defun gnus-summary-limit-to-articles (n)
7642   "Limit the summary buffer to the next N articles.
7643 If not given a prefix, use the process marked articles instead."
7644   (interactive "P")
7645   (prog1
7646       (let ((articles (gnus-summary-work-articles n)))
7647         (setq gnus-newsgroup-processable nil)
7648         (gnus-summary-limit articles))
7649     (gnus-summary-position-point)))
7650
7651 (defun gnus-summary-pop-limit (&optional total)
7652   "Restore the previous limit.
7653 If given a prefix, remove all limits."
7654   (interactive "P")
7655   (when total
7656     (setq gnus-newsgroup-limits
7657           (list (mapcar (lambda (h) (mail-header-number h))
7658                         gnus-newsgroup-headers))))
7659   (unless gnus-newsgroup-limits
7660     (error "No limit to pop"))
7661   (prog1
7662       (gnus-summary-limit nil 'pop)
7663     (gnus-summary-position-point)))
7664
7665 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7666   "Limit the summary buffer to articles that have subjects that match a regexp.
7667 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7668   (interactive
7669    (list (read-string (if current-prefix-arg
7670                           "Exclude subject (regexp): "
7671                         "Limit to subject (regexp): "))
7672          nil current-prefix-arg))
7673   (unless header
7674     (setq header "subject"))
7675   (when (not (equal "" subject))
7676     (prog1
7677         (let ((articles (gnus-summary-find-matching
7678                          (or header "subject") subject 'all nil nil
7679                          not-matching)))
7680           (unless articles
7681             (error "Found no matches for \"%s\"" subject))
7682           (gnus-summary-limit articles))
7683       (gnus-summary-position-point))))
7684
7685 (defun gnus-summary-limit-to-author (from &optional not-matching)
7686   "Limit the summary buffer to articles that have authors that match a regexp.
7687 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7688   (interactive
7689    (list (read-string (if current-prefix-arg
7690                           "Exclude author (regexp): "
7691                         "Limit to author (regexp): "))
7692          current-prefix-arg))
7693   (gnus-summary-limit-to-subject from "from" not-matching))
7694
7695 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7696   "Limit the summary buffer to articles with the given RECIPIENT.
7697
7698 To and Cc headers are checked.  You need to include them in
7699 `nnmail-extra-headers'."
7700   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7701   (interactive
7702    (list (read-string (format "%s recipient (regexp): "
7703                               (if current-prefix-arg "Exclude" "Limit to")))
7704          current-prefix-arg))
7705   (when (not (equal "" recipient))
7706     (prog1 (let* ((articles1
7707                    (if (memq 'To nnmail-extra-headers)
7708                        (gnus-summary-find-matching
7709                         (cons 'extra 'To) recipient 'all nil nil
7710                         not-matching)
7711                      (gnus-message
7712                       1 "`To' isn't present in `nnmail-extra-headers'")
7713                      (sit-for 1)
7714                      nil))
7715                   (articles2
7716                    (if (memq 'Cc nnmail-extra-headers)
7717                        (gnus-summary-find-matching
7718                         (cons 'extra 'Cc) recipient 'all nil nil
7719                         not-matching)
7720                      (gnus-message
7721                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7722                      (sit-for 1)
7723                      nil))
7724                   (articles (nconc articles1 articles2)))
7725              (unless articles
7726                (error "Found no matches for \"%s\"" recipient))
7727              (gnus-summary-limit articles))
7728       (gnus-summary-position-point))))
7729
7730 (defun gnus-summary-limit-to-age (age &optional younger-p)
7731   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7732 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7733 articles that are younger than AGE days."
7734   (interactive
7735    (let ((younger current-prefix-arg)
7736          (days-got nil)
7737          days)
7738      (while (not days-got)
7739        (setq days (if younger
7740                       (read-string "Limit to articles younger than (in days, older when negative): ")
7741                     (read-string
7742                      "Limit to articles older than (in days, younger when negative): ")))
7743        (when (> (length days) 0)
7744          (setq days (read days)))
7745        (if (numberp days)
7746            (progn
7747              (setq days-got t)
7748              (when (< days 0)
7749                (setq younger (not younger))
7750                (setq days (* days -1))))
7751          (message "Please enter a number.")
7752          (sleep-for 1)))
7753      (list days younger)))
7754   (prog1
7755       (let ((data gnus-newsgroup-data)
7756             (cutoff (days-to-time age))
7757             articles d date is-younger)
7758         (while (setq d (pop data))
7759           (when (and (vectorp (gnus-data-header d))
7760                      (setq date (mail-header-date (gnus-data-header d))))
7761             (setq is-younger (time-less-p
7762                               (time-since (condition-case ()
7763                                               (date-to-time date)
7764                                             (error '(0 0))))
7765                               cutoff))
7766             (when (if younger-p
7767                       is-younger
7768                     (not is-younger))
7769               (push (gnus-data-number d) articles))))
7770         (gnus-summary-limit (nreverse articles)))
7771     (gnus-summary-position-point)))
7772
7773 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7774   "Limit the summary buffer to articles that match an 'extra' header."
7775   (interactive
7776    (let ((header
7777           (intern
7778            (gnus-completing-read-with-default
7779             (symbol-name (car gnus-extra-headers))
7780             (if current-prefix-arg
7781                 "Exclude extra header:"
7782               "Limit extra header:")
7783             (mapcar (lambda (x)
7784                       (cons (symbol-name x) x))
7785                     gnus-extra-headers)
7786             nil
7787             t))))
7788      (list header
7789            (read-string (format "%s header %s (regexp): "
7790                                 (if current-prefix-arg "Exclude" "Limit to")
7791                                 header))
7792            current-prefix-arg)))
7793   (when (not (equal "" regexp))
7794     (prog1
7795         (let ((articles (gnus-summary-find-matching
7796                          (cons 'extra header) regexp 'all nil nil
7797                          not-matching)))
7798           (unless articles
7799             (error "Found no matches for \"%s\"" regexp))
7800           (gnus-summary-limit articles))
7801       (gnus-summary-position-point))))
7802
7803 (defun gnus-summary-limit-to-display-predicate ()
7804   "Limit the summary buffer to the predicated in the `display' group parameter."
7805   (interactive)
7806   (unless gnus-newsgroup-display
7807     (error "There is no `display' group parameter"))
7808   (let (articles)
7809     (dolist (number gnus-newsgroup-articles)
7810       (when (funcall gnus-newsgroup-display)
7811         (push number articles)))
7812     (gnus-summary-limit articles))
7813   (gnus-summary-position-point))
7814
7815 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7816 (make-obsolete
7817  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7818
7819 (defun gnus-summary-limit-to-unread (&optional all)
7820   "Limit the summary buffer to articles that are not marked as read.
7821 If ALL is non-nil, limit strictly to unread articles."
7822   (interactive "P")
7823   (if all
7824       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7825     (gnus-summary-limit-to-marks
7826      ;; Concat all the marks that say that an article is read and have
7827      ;; those removed.
7828      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7829            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7830            gnus-low-score-mark gnus-expirable-mark
7831            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7832            gnus-duplicate-mark gnus-souped-mark)
7833      'reverse)))
7834
7835 (defun gnus-summary-limit-to-replied (&optional unreplied)
7836   "Limit the summary buffer to replied articles.
7837 If UNREPLIED (the prefix), limit to unreplied articles."
7838   (interactive "P")
7839   (if unreplied
7840       (gnus-summary-limit
7841        (gnus-set-difference gnus-newsgroup-articles
7842         gnus-newsgroup-replied))
7843     (gnus-summary-limit gnus-newsgroup-replied))
7844   (gnus-summary-position-point))
7845
7846 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7847 (make-obsolete 'gnus-summary-delete-marked-with
7848                'gnus-summary-limit-exclude-marks)
7849
7850 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7851   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7852 If REVERSE, limit the summary buffer to articles that are marked
7853 with MARKS.  MARKS can either be a string of marks or a list of marks.
7854 Returns how many articles were removed."
7855   (interactive "sMarks: ")
7856   (gnus-summary-limit-to-marks marks t))
7857
7858 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7859   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7860 If REVERSE (the prefix), limit the summary buffer to articles that are
7861 not marked with MARKS.  MARKS can either be a string of marks or a
7862 list of marks.
7863 Returns how many articles were removed."
7864   (interactive "sMarks: \nP")
7865   (prog1
7866       (let ((data gnus-newsgroup-data)
7867             (marks (if (listp marks) marks
7868                      (append marks nil))) ; Transform to list.
7869             articles)
7870         (while data
7871           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7872                   (memq (gnus-data-mark (car data)) marks))
7873             (push (gnus-data-number (car data)) articles))
7874           (setq data (cdr data)))
7875         (gnus-summary-limit articles))
7876     (gnus-summary-position-point)))
7877
7878 (defun gnus-summary-limit-to-score (score)
7879   "Limit to articles with score at or above SCORE."
7880   (interactive "NLimit to articles with score of at least: ")
7881   (let ((data gnus-newsgroup-data)
7882         articles)
7883     (while data
7884       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7885                 score)
7886         (push (gnus-data-number (car data)) articles))
7887       (setq data (cdr data)))
7888     (prog1
7889         (gnus-summary-limit articles)
7890       (gnus-summary-position-point))))
7891
7892 (defun gnus-summary-limit-to-unseen ()
7893   "Limit to unseen articles."
7894   (interactive)
7895   (prog1
7896       (gnus-summary-limit gnus-newsgroup-unseen)
7897     (gnus-summary-position-point)))
7898
7899 (defun gnus-summary-limit-include-thread (id)
7900   "Display all the hidden articles that is in the thread with ID in it.
7901 When called interactively, ID is the Message-ID of the current
7902 article."
7903   (interactive (list (mail-header-id (gnus-summary-article-header))))
7904   (let ((articles (gnus-articles-in-thread
7905                    (gnus-id-to-thread (gnus-root-id id)))))
7906     (prog1
7907         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7908       (gnus-summary-limit-include-matching-articles
7909        "subject"
7910        (regexp-quote (gnus-simplify-subject-re
7911                       (mail-header-subject (gnus-id-to-header id)))))
7912       (gnus-summary-position-point))))
7913
7914 (defun gnus-summary-limit-include-matching-articles (header regexp)
7915   "Display all the hidden articles that have HEADERs that match REGEXP."
7916   (interactive (list (read-string "Match on header: ")
7917                      (read-string "Regexp: ")))
7918   (let ((articles (gnus-find-matching-articles header regexp)))
7919     (prog1
7920         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7921       (gnus-summary-position-point))))
7922
7923 (defun gnus-summary-insert-dormant-articles ()
7924   "Insert all the dormant articles for this group into the current buffer."
7925   (interactive)
7926   (let ((gnus-verbose (max 6 gnus-verbose)))
7927     (if (not gnus-newsgroup-dormant)
7928         (gnus-message 3 "No cached articles for this group")
7929       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7930
7931 (defun gnus-summary-limit-include-dormant ()
7932   "Display all the hidden articles that are marked as dormant.
7933 Note that this command only works on a subset of the articles currently
7934 fetched for this group."
7935   (interactive)
7936   (unless gnus-newsgroup-dormant
7937     (error "There are no dormant articles in this group"))
7938   (prog1
7939       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-limit-exclude-dormant ()
7943   "Hide all dormant articles."
7944   (interactive)
7945   (prog1
7946       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7947     (gnus-summary-position-point)))
7948
7949 (defun gnus-summary-limit-exclude-childless-dormant ()
7950   "Hide all dormant articles that have no children."
7951   (interactive)
7952   (let ((data (gnus-data-list t))
7953         articles d children)
7954     ;; Find all articles that are either not dormant or have
7955     ;; children.
7956     (while (setq d (pop data))
7957       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7958                 (and (setq children
7959                            (gnus-article-children (gnus-data-number d)))
7960                      (let (found)
7961                        (while children
7962                          (when (memq (car children) articles)
7963                            (setq children nil
7964                                  found t))
7965                          (pop children))
7966                        found)))
7967         (push (gnus-data-number d) articles)))
7968     ;; Do the limiting.
7969     (prog1
7970         (gnus-summary-limit articles)
7971       (gnus-summary-position-point))))
7972
7973 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7974   "Mark all unread excluded articles as read.
7975 If ALL, mark even excluded ticked and dormants as read."
7976   (interactive "P")
7977   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7978   (let ((articles (gnus-sorted-ndifference
7979                    (sort
7980                     (mapcar (lambda (h) (mail-header-number h))
7981                             gnus-newsgroup-headers)
7982                     '<)
7983                    gnus-newsgroup-limit))
7984         article)
7985     (setq gnus-newsgroup-unreads
7986           (gnus-sorted-intersection gnus-newsgroup-unreads
7987                                     gnus-newsgroup-limit))
7988     (if all
7989         (setq gnus-newsgroup-dormant nil
7990               gnus-newsgroup-marked nil
7991               gnus-newsgroup-reads
7992               (nconc
7993                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7994                gnus-newsgroup-reads))
7995       (while (setq article (pop articles))
7996         (unless (or (memq article gnus-newsgroup-dormant)
7997                     (memq article gnus-newsgroup-marked))
7998           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7999
8000 (defun gnus-summary-limit (articles &optional pop)
8001   (if pop
8002       ;; We pop the previous limit off the stack and use that.
8003       (setq articles (car gnus-newsgroup-limits)
8004             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8005     ;; We use the new limit, so we push the old limit on the stack.
8006     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8007   ;; Set the limit.
8008   (setq gnus-newsgroup-limit articles)
8009   (let ((total (length gnus-newsgroup-data))
8010         (data (gnus-data-find-list (gnus-summary-article-number)))
8011         (gnus-summary-mark-below nil)   ; Inhibit this.
8012         found)
8013     ;; This will do all the work of generating the new summary buffer
8014     ;; according to the new limit.
8015     (gnus-summary-prepare)
8016     ;; Hide any threads, possibly.
8017     (gnus-summary-maybe-hide-threads)
8018     ;; Try to return to the article you were at, or one in the
8019     ;; neighborhood.
8020     (when data
8021       ;; We try to find some article after the current one.
8022       (while data
8023         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8024           (setq data nil
8025                 found t))
8026         (setq data (cdr data))))
8027     (unless found
8028       ;; If there is no data, that means that we were after the last
8029       ;; article.  The same goes when we can't find any articles
8030       ;; after the current one.
8031       (goto-char (point-max))
8032       (gnus-summary-find-prev))
8033     (gnus-set-mode-line 'summary)
8034     ;; We return how many articles were removed from the summary
8035     ;; buffer as a result of the new limit.
8036     (- total (length gnus-newsgroup-data))))
8037
8038 (defsubst gnus-invisible-cut-children (threads)
8039   (let ((num 0))
8040     (while threads
8041       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8042         (incf num))
8043       (pop threads))
8044     (< num 2)))
8045
8046 (defsubst gnus-cut-thread (thread)
8047   "Go forwards in the thread until we find an article that we want to display."
8048   (when (or (eq gnus-fetch-old-headers 'some)
8049             (eq gnus-fetch-old-headers 'invisible)
8050             (numberp gnus-fetch-old-headers)
8051             (eq gnus-build-sparse-threads 'some)
8052             (eq gnus-build-sparse-threads 'more))
8053     ;; Deal with old-fetched headers and sparse threads.
8054     (while (and
8055             thread
8056             (or
8057              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8058              (gnus-summary-article-ancient-p
8059               (mail-header-number (car thread))))
8060             (if (or (<= (length (cdr thread)) 1)
8061                     (eq gnus-fetch-old-headers 'invisible))
8062                 (setq gnus-newsgroup-limit
8063                       (delq (mail-header-number (car thread))
8064                             gnus-newsgroup-limit)
8065                       thread (cadr thread))
8066               (when (gnus-invisible-cut-children (cdr thread))
8067                 (let ((th (cdr thread)))
8068                   (while th
8069                     (if (memq (mail-header-number (caar th))
8070                               gnus-newsgroup-limit)
8071                         (setq thread (car th)
8072                               th nil)
8073                       (setq th (cdr th))))))))))
8074   thread)
8075
8076 (defun gnus-cut-threads (threads)
8077   "Cut off all uninteresting articles from the beginning of THREADS."
8078   (when (or (eq gnus-fetch-old-headers 'some)
8079             (eq gnus-fetch-old-headers 'invisible)
8080             (numberp gnus-fetch-old-headers)
8081             (eq gnus-build-sparse-threads 'some)
8082             (eq gnus-build-sparse-threads 'more))
8083     (let ((th threads))
8084       (while th
8085         (setcar th (gnus-cut-thread (car th)))
8086         (setq th (cdr th)))))
8087   ;; Remove nixed out threads.
8088   (delq nil threads))
8089
8090 (defun gnus-summary-initial-limit (&optional show-if-empty)
8091   "Figure out what the initial limit is supposed to be on group entry.
8092 This entails weeding out unwanted dormants, low-scored articles,
8093 fetch-old-headers verbiage, and so on."
8094   ;; Most groups have nothing to remove.
8095   (if (or gnus-inhibit-limiting
8096           (and (null gnus-newsgroup-dormant)
8097                (eq gnus-newsgroup-display 'gnus-not-ignore)
8098                (not (eq gnus-fetch-old-headers 'some))
8099                (not (numberp gnus-fetch-old-headers))
8100                (not (eq gnus-fetch-old-headers 'invisible))
8101                (null gnus-summary-expunge-below)
8102                (not (eq gnus-build-sparse-threads 'some))
8103                (not (eq gnus-build-sparse-threads 'more))
8104                (null gnus-thread-expunge-below)
8105                (not gnus-use-nocem)))
8106       ()                                ; Do nothing.
8107     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8108     (setq gnus-newsgroup-limit nil)
8109     (mapatoms
8110      (lambda (node)
8111        (unless (car (symbol-value node))
8112          ;; These threads have no parents -- they are roots.
8113          (let ((nodes (cdr (symbol-value node)))
8114                thread)
8115            (while nodes
8116              (if (and gnus-thread-expunge-below
8117                       (< (gnus-thread-total-score (car nodes))
8118                          gnus-thread-expunge-below))
8119                  (gnus-expunge-thread (pop nodes))
8120                (setq thread (pop nodes))
8121                (gnus-summary-limit-children thread))))))
8122      gnus-newsgroup-dependencies)
8123     ;; If this limitation resulted in an empty group, we might
8124     ;; pop the previous limit and use it instead.
8125     (when (and (not gnus-newsgroup-limit)
8126                show-if-empty)
8127       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8128     gnus-newsgroup-limit))
8129
8130 (defun gnus-summary-limit-children (thread)
8131   "Return 1 if this subthread is visible and 0 if it is not."
8132   ;; First we get the number of visible children to this thread.  This
8133   ;; is done by recursing down the thread using this function, so this
8134   ;; will really go down to a leaf article first, before slowly
8135   ;; working its way up towards the root.
8136   (when thread
8137     (let* ((max-lisp-eval-depth 5000)
8138            (children
8139            (if (cdr thread)
8140                (apply '+ (mapcar 'gnus-summary-limit-children
8141                                  (cdr thread)))
8142              0))
8143           (number (mail-header-number (car thread)))
8144           score)
8145       (if (and
8146            (not (memq number gnus-newsgroup-marked))
8147            (or
8148             ;; If this article is dormant and has absolutely no visible
8149             ;; children, then this article isn't visible.
8150             (and (memq number gnus-newsgroup-dormant)
8151                  (zerop children))
8152             ;; If this is "fetch-old-headered" and there is no
8153             ;; visible children, then we don't want this article.
8154             (and (or (eq gnus-fetch-old-headers 'some)
8155                      (numberp gnus-fetch-old-headers))
8156                  (gnus-summary-article-ancient-p number)
8157                  (zerop children))
8158             ;; If this is "fetch-old-headered" and `invisible', then
8159             ;; we don't want this article.
8160             (and (eq gnus-fetch-old-headers 'invisible)
8161                  (gnus-summary-article-ancient-p number))
8162             ;; If this is a sparsely inserted article with no children,
8163             ;; we don't want it.
8164             (and (eq gnus-build-sparse-threads 'some)
8165                  (gnus-summary-article-sparse-p number)
8166                  (zerop children))
8167             ;; If we use expunging, and this article is really
8168             ;; low-scored, then we don't want this article.
8169             (when (and gnus-summary-expunge-below
8170                        (< (setq score
8171                                 (or (cdr (assq number gnus-newsgroup-scored))
8172                                     gnus-summary-default-score))
8173                           gnus-summary-expunge-below))
8174               ;; We increase the expunge-tally here, but that has
8175               ;; nothing to do with the limits, really.
8176               (incf gnus-newsgroup-expunged-tally)
8177               ;; We also mark as read here, if that's wanted.
8178               (when (and gnus-summary-mark-below
8179                          (< score gnus-summary-mark-below))
8180                 (setq gnus-newsgroup-unreads
8181                       (delq number gnus-newsgroup-unreads))
8182                 (if gnus-newsgroup-auto-expire
8183                     (push number gnus-newsgroup-expirable)
8184                   (push (cons number gnus-low-score-mark)
8185                         gnus-newsgroup-reads)))
8186               t)
8187             ;; Do the `display' group parameter.
8188             (and gnus-newsgroup-display
8189                  (not (funcall gnus-newsgroup-display)))
8190             ;; Check NoCeM things.
8191             (when (and gnus-use-nocem
8192                        (gnus-nocem-unwanted-article-p
8193                         (mail-header-id (car thread))))
8194               (setq gnus-newsgroup-unreads
8195                     (delq number gnus-newsgroup-unreads))
8196               t)))
8197           ;; Nope, invisible article.
8198           0
8199         ;; Ok, this article is to be visible, so we add it to the limit
8200         ;; and return 1.
8201         (push number gnus-newsgroup-limit)
8202         1))))
8203
8204 (defun gnus-expunge-thread (thread)
8205   "Mark all articles in THREAD as read."
8206   (let* ((number (mail-header-number (car thread))))
8207     (incf gnus-newsgroup-expunged-tally)
8208     ;; We also mark as read here, if that's wanted.
8209     (setq gnus-newsgroup-unreads
8210           (delq number gnus-newsgroup-unreads))
8211     (if gnus-newsgroup-auto-expire
8212         (push number gnus-newsgroup-expirable)
8213       (push (cons number gnus-low-score-mark)
8214             gnus-newsgroup-reads)))
8215   ;; Go recursively through all subthreads.
8216   (mapcar 'gnus-expunge-thread (cdr thread)))
8217
8218 ;; Summary article oriented commands
8219
8220 (defun gnus-summary-refer-parent-article (n)
8221   "Refer parent article N times.
8222 If N is negative, go to ancestor -N instead.
8223 The difference between N and the number of articles fetched is returned."
8224   (interactive "p")
8225   (let ((skip 1)
8226         error header ref)
8227     (when (not (natnump n))
8228       (setq skip (abs n)
8229             n 1))
8230     (while (and (> n 0)
8231                 (not error))
8232       (setq header (gnus-summary-article-header))
8233       (if (and (eq (mail-header-number header)
8234                    (cdr gnus-article-current))
8235                (equal gnus-newsgroup-name
8236                       (car gnus-article-current)))
8237           ;; If we try to find the parent of the currently
8238           ;; displayed article, then we take a look at the actual
8239           ;; References header, since this is slightly more
8240           ;; reliable than the References field we got from the
8241           ;; server.
8242           (save-excursion
8243             (set-buffer gnus-original-article-buffer)
8244             (nnheader-narrow-to-headers)
8245             (unless (setq ref (message-fetch-field "references"))
8246               (when (setq ref (message-fetch-field "in-reply-to"))
8247                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8248             (widen))
8249         (setq ref
8250               ;; It's not the current article, so we take a bet on
8251               ;; the value we got from the server.
8252               (mail-header-references header)))
8253       (if (and ref
8254                (not (equal ref "")))
8255           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8256             (gnus-message 1 "Couldn't find parent"))
8257         (gnus-message 1 "No references in article %d"
8258                       (gnus-summary-article-number))
8259         (setq error t))
8260       (decf n))
8261     (gnus-summary-position-point)
8262     n))
8263
8264 (defun gnus-summary-refer-references ()
8265   "Fetch all articles mentioned in the References header.
8266 Return the number of articles fetched."
8267   (interactive)
8268   (let ((ref (mail-header-references (gnus-summary-article-header)))
8269         (current (gnus-summary-article-number))
8270         (n 0))
8271     (if (or (not ref)
8272             (equal ref ""))
8273         (error "No References in the current article")
8274       ;; For each Message-ID in the References header...
8275       (while (string-match "<[^>]*>" ref)
8276         (incf n)
8277         ;; ... fetch that article.
8278         (gnus-summary-refer-article
8279          (prog1 (match-string 0 ref)
8280            (setq ref (substring ref (match-end 0))))))
8281       (gnus-summary-goto-subject current)
8282       (gnus-summary-position-point)
8283       n)))
8284
8285 (defun gnus-summary-refer-thread (&optional limit)
8286   "Fetch all articles in the current thread.
8287 If LIMIT (the numerical prefix), fetch that many old headers instead
8288 of what's specified by the `gnus-refer-thread-limit' variable."
8289   (interactive "P")
8290   (let ((id (mail-header-id (gnus-summary-article-header)))
8291         (limit (if limit (prefix-numeric-value limit)
8292                  gnus-refer-thread-limit)))
8293     (unless (eq gnus-fetch-old-headers 'invisible)
8294       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8295       ;; Retrieve the headers and read them in.
8296       (if (eq (if (numberp limit)
8297                   (gnus-retrieve-headers
8298                    (list (min
8299                           (+ (mail-header-number
8300                               (gnus-summary-article-header))
8301                              limit)
8302                           gnus-newsgroup-end))
8303                    gnus-newsgroup-name (* limit 2))
8304                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8305                 ;; headers.
8306                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8307                                        gnus-newsgroup-name limit))
8308               'nov)
8309           (gnus-build-all-threads)
8310         (error "Can't fetch thread from back ends that don't support NOV"))
8311       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8312     (gnus-summary-limit-include-thread id)))
8313
8314 (defun gnus-summary-refer-article (message-id)
8315   "Fetch an article specified by MESSAGE-ID."
8316   (interactive "sMessage-ID: ")
8317   (when (and (stringp message-id)
8318              (not (zerop (length message-id))))
8319     (setq message-id (gnus-replace-in-string message-id " " ""))
8320     ;; Construct the correct Message-ID if necessary.
8321     ;; Suggested by tale@pawl.rpi.edu.
8322     (unless (string-match "^<" message-id)
8323       (setq message-id (concat "<" message-id)))
8324     (unless (string-match ">$" message-id)
8325       (setq message-id (concat message-id ">")))
8326     ;; People often post MIDs from URLs, so unhex it:
8327     (unless (string-match "@" message-id)
8328       (setq message-id (gnus-url-unhex-string message-id)))
8329     (let* ((header (gnus-id-to-header message-id))
8330            (sparse (and header
8331                         (gnus-summary-article-sparse-p
8332                          (mail-header-number header))
8333                         (memq (mail-header-number header)
8334                               gnus-newsgroup-limit)))
8335            number)
8336       (cond
8337        ;; If the article is present in the buffer we just go to it.
8338        ((and header
8339              (or (not (gnus-summary-article-sparse-p
8340                        (mail-header-number header)))
8341                  sparse))
8342         (prog1
8343             (gnus-summary-goto-article
8344              (mail-header-number header) nil t)
8345           (when sparse
8346             (gnus-summary-update-article (mail-header-number header)))))
8347        (t
8348         ;; We fetch the article.
8349         (catch 'found
8350           (dolist (gnus-override-method (gnus-refer-article-methods))
8351             (when (and (gnus-check-server gnus-override-method)
8352                        ;; Fetch the header,
8353                        (setq number (gnus-summary-insert-subject message-id)))
8354               ;; and display the article.
8355               (gnus-summary-select-article nil nil nil number)
8356               (throw 'found t)))
8357           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8358
8359 (defun gnus-refer-article-methods ()
8360   "Return a list of referable methods."
8361   (cond
8362    ;; No method, so we default to current and native.
8363    ((null gnus-refer-article-method)
8364     (list gnus-current-select-method gnus-select-method))
8365    ;; Current.
8366    ((eq 'current gnus-refer-article-method)
8367     (list gnus-current-select-method))
8368    ;; List of select methods.
8369    ((not (and (symbolp (car gnus-refer-article-method))
8370               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8371     (let (out)
8372       (dolist (method gnus-refer-article-method)
8373         (push (if (eq 'current method)
8374                   gnus-current-select-method
8375                 method)
8376               out))
8377       (nreverse out)))
8378    ;; One single select method.
8379    (t
8380     (list gnus-refer-article-method))))
8381
8382 (defun gnus-summary-edit-parameters ()
8383   "Edit the group parameters of the current group."
8384   (interactive)
8385   (gnus-group-edit-group gnus-newsgroup-name 'params))
8386
8387 (defun gnus-summary-customize-parameters ()
8388   "Customize the group parameters of the current group."
8389   (interactive)
8390   (gnus-group-customize gnus-newsgroup-name))
8391
8392 (defun gnus-summary-enter-digest-group (&optional force)
8393   "Enter an nndoc group based on the current article.
8394 If FORCE, force a digest interpretation.  If not, try
8395 to guess what the document format is."
8396   (interactive "P")
8397   (let ((conf gnus-current-window-configuration))
8398     (save-window-excursion
8399       (save-excursion
8400         (let (gnus-article-prepare-hook
8401               gnus-display-mime-function
8402               gnus-break-pages)
8403           (gnus-summary-select-article))))
8404     (setq gnus-current-window-configuration conf)
8405     (let* ((name (format "%s-%d"
8406                          (gnus-group-prefixed-name
8407                           gnus-newsgroup-name (list 'nndoc ""))
8408                          (with-current-buffer gnus-summary-buffer
8409                            gnus-current-article)))
8410            (ogroup gnus-newsgroup-name)
8411            (params (append (gnus-info-params (gnus-get-info ogroup))
8412                            (list (cons 'to-group ogroup))
8413                            (list (cons 'parent-group ogroup))
8414                            (list (cons 'save-article-group ogroup))))
8415            (case-fold-search t)
8416            (buf (current-buffer))
8417            dig to-address)
8418       (save-excursion
8419         (set-buffer gnus-original-article-buffer)
8420         ;; Have the digest group inherit the main mail address of
8421         ;; the parent article.
8422         (when (setq to-address (or (gnus-fetch-field "reply-to")
8423                                    (gnus-fetch-field "from")))
8424           (setq params (append
8425                         (list (cons 'to-address
8426                                     (funcall gnus-decode-encoded-word-function
8427                                              to-address))))))
8428         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8429         (insert-buffer-substring gnus-original-article-buffer)
8430         ;; Remove lines that may lead nndoc to misinterpret the
8431         ;; document type.
8432         (narrow-to-region
8433          (goto-char (point-min))
8434          (or (search-forward "\n\n" nil t) (point)))
8435         (goto-char (point-min))
8436         (delete-matching-lines "^Path:\\|^From ")
8437         (widen))
8438       (unwind-protect
8439           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8440                     (gnus-newsgroup-ephemeral-ignored-charsets
8441                      gnus-newsgroup-ignored-charsets))
8442                 (gnus-group-read-ephemeral-group
8443                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8444                               (nndoc-article-type
8445                                ,(if force 'mbox 'guess)))
8446                  t nil nil nil
8447                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8448                                                         "ADAPT")))))
8449               ;; Make all postings to this group go to the parent group.
8450               (nconc (gnus-info-params (gnus-get-info name))
8451                      params)
8452             ;; Couldn't select this doc group.
8453             (switch-to-buffer buf)
8454             (gnus-set-global-variables)
8455             (gnus-configure-windows 'summary)
8456             (gnus-message 3 "Article couldn't be entered?"))
8457         (kill-buffer dig)))))
8458
8459 (defun gnus-summary-read-document (n)
8460   "Open a new group based on the current article(s).
8461 This will allow you to read digests and other similar
8462 documents as newsgroups.
8463 Obeys the standard process/prefix convention."
8464   (interactive "P")
8465   (let* ((ogroup gnus-newsgroup-name)
8466          (params (append (gnus-info-params (gnus-get-info ogroup))
8467                          (list (cons 'to-group ogroup))))
8468          group egroup groups vgroup)
8469     (dolist (article (gnus-summary-work-articles n))
8470       (setq group (format "%s-%d" gnus-newsgroup-name article))
8471       (gnus-summary-remove-process-mark article)
8472       (when (gnus-summary-display-article article)
8473         (save-excursion
8474           (with-temp-buffer
8475             (insert-buffer-substring gnus-original-article-buffer)
8476             ;; Remove some headers that may lead nndoc to make
8477             ;; the wrong guess.
8478             (message-narrow-to-head)
8479             (goto-char (point-min))
8480             (delete-matching-lines "^Path:\\|^From ")
8481             (widen)
8482             (if (setq egroup
8483                       (gnus-group-read-ephemeral-group
8484                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8485                                      (nndoc-article-type guess))
8486                        t nil t))
8487                 (progn
8488             ;; Make all postings to this group go to the parent group.
8489                   (nconc (gnus-info-params (gnus-get-info egroup))
8490                          params)
8491                   (push egroup groups))
8492               ;; Couldn't select this doc group.
8493               (gnus-error 3 "Article couldn't be entered"))))))
8494     ;; Now we have selected all the documents.
8495     (cond
8496      ((not groups)
8497       (error "None of the articles could be interpreted as documents"))
8498      ((gnus-group-read-ephemeral-group
8499        (setq vgroup (format
8500                      "nnvirtual:%s-%s" gnus-newsgroup-name
8501                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8502        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8503        t
8504        (cons (current-buffer) 'summary)))
8505      (t
8506       (error "Couldn't select virtual nndoc group")))))
8507
8508 (defun gnus-summary-isearch-article (&optional regexp-p)
8509   "Do incremental search forward on the current article.
8510 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8511   (interactive "P")
8512   (gnus-summary-select-article)
8513   (gnus-configure-windows 'article)
8514   (gnus-eval-in-buffer-window gnus-article-buffer
8515     (save-restriction
8516       (widen)
8517       (isearch-forward regexp-p))))
8518
8519 (defun gnus-summary-search-article-forward (regexp &optional backward)
8520   "Search for an article containing REGEXP forward.
8521 If BACKWARD, search backward instead."
8522   (interactive
8523    (list (read-string
8524           (format "Search article %s (regexp%s): "
8525                   (if current-prefix-arg "backward" "forward")
8526                   (if gnus-last-search-regexp
8527                       (concat ", default " gnus-last-search-regexp)
8528                     "")))
8529          current-prefix-arg))
8530   (if (string-equal regexp "")
8531       (setq regexp (or gnus-last-search-regexp ""))
8532     (setq gnus-last-search-regexp regexp)
8533     (setq gnus-article-before-search gnus-current-article))
8534   ;; Intentionally set gnus-last-article.
8535   (setq gnus-last-article gnus-article-before-search)
8536   (let ((gnus-last-article gnus-last-article))
8537     (if (gnus-summary-search-article regexp backward)
8538         (gnus-summary-show-thread)
8539       (signal 'search-failed (list regexp)))))
8540
8541 (defun gnus-summary-search-article-backward (regexp)
8542   "Search for an article containing REGEXP backward."
8543   (interactive
8544    (list (read-string
8545           (format "Search article backward (regexp%s): "
8546                   (if gnus-last-search-regexp
8547                       (concat ", default " gnus-last-search-regexp)
8548                     "")))))
8549   (gnus-summary-search-article-forward regexp 'backward))
8550
8551 (defun gnus-summary-search-article (regexp &optional backward)
8552   "Search for an article containing REGEXP.
8553 Optional argument BACKWARD means do search for backward.
8554 `gnus-select-article-hook' is not called during the search."
8555   ;; We have to require this here to make sure that the following
8556   ;; dynamic binding isn't shadowed by autoloading.
8557   (require 'gnus-async)
8558   (require 'gnus-art)
8559   (let ((gnus-select-article-hook nil)  ;Disable hook.
8560         (gnus-article-prepare-hook nil)
8561         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8562         (gnus-use-article-prefetch nil)
8563         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8564         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8565         (gnus-visual nil)
8566         (gnus-keep-backlog nil)
8567         (gnus-break-pages nil)
8568         (gnus-summary-display-arrow nil)
8569         (gnus-updated-mode-lines nil)
8570         (gnus-auto-center-summary nil)
8571         (sum (current-buffer))
8572         (gnus-display-mime-function nil)
8573         (found nil)
8574         point)
8575     (gnus-save-hidden-threads
8576       (gnus-summary-select-article)
8577       (set-buffer gnus-article-buffer)
8578       (goto-char (window-point (get-buffer-window (current-buffer))))
8579       (when backward
8580         (forward-line -1))
8581       (while (not found)
8582         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8583         (if (if backward
8584                 (re-search-backward regexp nil t)
8585               (re-search-forward regexp nil t))
8586             ;; We found the regexp.
8587             (progn
8588               (setq found 'found)
8589               (beginning-of-line)
8590               (set-window-start
8591                (get-buffer-window (current-buffer))
8592                (point))
8593               (forward-line 1)
8594               (set-window-point
8595                (get-buffer-window (current-buffer))
8596                (point))
8597               (set-buffer sum)
8598               (setq point (point)))
8599           ;; We didn't find it, so we go to the next article.
8600           (set-buffer sum)
8601           (setq found 'not)
8602           (while (eq found 'not)
8603             (if (not (if backward (gnus-summary-find-prev)
8604                        (gnus-summary-find-next)))
8605                 ;; No more articles.
8606                 (setq found t)
8607               ;; Select the next article and adjust point.
8608               (unless (gnus-summary-article-sparse-p
8609                        (gnus-summary-article-number))
8610                 (setq found nil)
8611                 (gnus-summary-select-article)
8612                 (set-buffer gnus-article-buffer)
8613                 (widen)
8614                 (goto-char (if backward (point-max) (point-min))))))))
8615       (gnus-message 7 ""))
8616     ;; Return whether we found the regexp.
8617     (when (eq found 'found)
8618       (goto-char point)
8619       (gnus-summary-show-thread)
8620       (gnus-summary-goto-subject gnus-current-article)
8621       (gnus-summary-position-point)
8622       t)))
8623
8624 (defun gnus-find-matching-articles (header regexp)
8625   "Return a list of all articles that match REGEXP on HEADER.
8626 This search includes all articles in the current group that Gnus has
8627 fetched headers for, whether they are displayed or not."
8628   (let ((articles nil)
8629         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8630         (case-fold-search t))
8631     (dolist (header gnus-newsgroup-headers)
8632       (when (string-match regexp (funcall func header))
8633         (push (mail-header-number header) articles)))
8634     (nreverse articles)))
8635
8636 (defun gnus-summary-find-matching (header regexp &optional backward unread
8637                                           not-case-fold not-matching)
8638   "Return a list of all articles that match REGEXP on HEADER.
8639 The search stars on the current article and goes forwards unless
8640 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8641 If UNREAD is non-nil, only unread articles will
8642 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8643 in the comparisons. If NOT-MATCHING, return a list of all articles that
8644 not match REGEXP on HEADER."
8645   (let ((case-fold-search (not not-case-fold))
8646         articles d func)
8647     (if (consp header)
8648         (if (eq (car header) 'extra)
8649             (setq func
8650                   `(lambda (h)
8651                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8652                          "")))
8653           (error "%s is an invalid header" header))
8654       (unless (fboundp (intern (concat "mail-header-" header)))
8655         (error "%s is not a valid header" header))
8656       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8657     (dolist (d (if (eq backward 'all)
8658                    gnus-newsgroup-data
8659                  (gnus-data-find-list
8660                   (gnus-summary-article-number)
8661                   (gnus-data-list backward))))
8662       (when (and (or (not unread)       ; We want all articles...
8663                      (gnus-data-unread-p d)) ; Or just unreads.
8664                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8665                  (if not-matching
8666                      (not (string-match
8667                            regexp
8668                            (funcall func (gnus-data-header d))))
8669                    (string-match regexp
8670                                  (funcall func (gnus-data-header d)))))
8671         (push (gnus-data-number d) articles))) ; Success!
8672     (nreverse articles)))
8673
8674 (defun gnus-summary-execute-command (header regexp command &optional backward)
8675   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8676 If HEADER is an empty string (or nil), the match is done on the entire
8677 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8678   (interactive
8679    (list (let ((completion-ignore-case t))
8680            (completing-read
8681             "Header name: "
8682             (mapcar (lambda (header) (list (format "%s" header)))
8683                     (append
8684                      '("Number" "Subject" "From" "Lines" "Date"
8685                        "Message-ID" "Xref" "References" "Body")
8686                      gnus-extra-headers))
8687             nil 'require-match))
8688          (read-string "Regexp: ")
8689          (read-key-sequence "Command: ")
8690          current-prefix-arg))
8691   (when (equal header "Body")
8692     (setq header ""))
8693   ;; Hidden thread subtrees must be searched as well.
8694   (gnus-summary-show-all-threads)
8695   ;; We don't want to change current point nor window configuration.
8696   (save-excursion
8697     (save-window-excursion
8698       (let (gnus-visual
8699             gnus-treat-strip-trailing-blank-lines
8700             gnus-treat-strip-leading-blank-lines
8701             gnus-treat-strip-multiple-blank-lines
8702             gnus-treat-hide-boring-headers
8703             gnus-treat-fold-newsgroups
8704             gnus-article-prepare-hook)
8705         (gnus-message 6 "Executing %s..." (key-description command))
8706         ;; We'd like to execute COMMAND interactively so as to give arguments.
8707         (gnus-execute header regexp
8708                       `(call-interactively ',(key-binding command))
8709                       backward)
8710         (gnus-message 6 "Executing %s...done" (key-description command))))))
8711
8712 (defun gnus-summary-beginning-of-article ()
8713   "Scroll the article back to the beginning."
8714   (interactive)
8715   (gnus-summary-select-article)
8716   (gnus-configure-windows 'article)
8717   (gnus-eval-in-buffer-window gnus-article-buffer
8718     (widen)
8719     (goto-char (point-min))
8720     (when gnus-break-pages
8721       (gnus-narrow-to-page))))
8722
8723 (defun gnus-summary-end-of-article ()
8724   "Scroll to the end of the article."
8725   (interactive)
8726   (gnus-summary-select-article)
8727   (gnus-configure-windows 'article)
8728   (gnus-eval-in-buffer-window gnus-article-buffer
8729     (widen)
8730     (goto-char (point-max))
8731     (recenter -3)
8732     (when gnus-break-pages
8733       (when (re-search-backward page-delimiter nil t)
8734         (narrow-to-region (match-end 0) (point-max)))
8735       (gnus-narrow-to-page))))
8736
8737 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8738   "Truncate to LEN and quote all \"(\"'s in STRING."
8739   (gnus-replace-in-string (if (and len (> (length string) len))
8740                               (substring string 0 len)
8741                             string)
8742                           "[()]" "\\\\\\&"))
8743
8744 (defun gnus-summary-print-article (&optional filename n)
8745   "Generate and print a PostScript image of the process-marked (mail) articles.
8746
8747 If used interactively, print the current article if none are
8748 process-marked.  With prefix arg, prompt the user for the name of the
8749 file to save in.
8750
8751 When used from Lisp, accept two optional args FILENAME and N.  N means
8752 to print the next N articles.  If N is negative, print the N previous
8753 articles.  If N is nil and articles have been marked with the process
8754 mark, print these instead.
8755
8756 If the optional first argument FILENAME is nil, send the image to the
8757 printer.  If FILENAME is a string, save the PostScript image in a file with
8758 that name.  If FILENAME is a number, prompt the user for the name of the file
8759 to save in."
8760   (interactive (list (ps-print-preprint current-prefix-arg)))
8761   (dolist (article (gnus-summary-work-articles n))
8762     (gnus-summary-select-article nil nil 'pseudo article)
8763     (gnus-eval-in-buffer-window gnus-article-buffer
8764       (gnus-print-buffer))
8765     (gnus-summary-remove-process-mark article))
8766   (ps-despool filename))
8767
8768 (defun gnus-print-buffer ()
8769   (let ((buffer (generate-new-buffer " *print*")))
8770     (unwind-protect
8771         (progn
8772           (copy-to-buffer buffer (point-min) (point-max))
8773           (set-buffer buffer)
8774           (gnus-remove-text-with-property 'gnus-decoration)
8775           (when (gnus-visual-p 'article-highlight 'highlight)
8776             ;; Copy-to-buffer doesn't copy overlay.  So redo
8777             ;; highlight.
8778             (let ((gnus-article-buffer buffer))
8779               (gnus-article-highlight-citation t)
8780               (gnus-article-highlight-signature)
8781               (gnus-article-emphasize)
8782               (gnus-article-delete-invisible-text)))
8783           (let ((ps-left-header
8784                  (list
8785                   (concat "("
8786                           (gnus-summary-print-truncate-and-quote
8787                            (mail-header-subject gnus-current-headers)
8788                            66) ")")
8789                   (concat "("
8790                           (gnus-summary-print-truncate-and-quote
8791                            (mail-header-from gnus-current-headers)
8792                            45) ")")))
8793                 (ps-right-header
8794                  (list
8795                   "/pagenumberstring load"
8796                   (concat "("
8797                           (mail-header-date gnus-current-headers) ")"))))
8798             (gnus-run-hooks 'gnus-ps-print-hook)
8799             (save-excursion
8800               (if window-system
8801                   (ps-spool-buffer-with-faces)
8802                 (ps-spool-buffer)))))
8803       (kill-buffer buffer))))
8804
8805 (defun gnus-summary-show-article (&optional arg)
8806   "Force redisplaying of the current article.
8807 If ARG (the prefix) is a number, show the article with the charset
8808 defined in `gnus-summary-show-article-charset-alist', or the charset
8809 input.
8810 If ARG (the prefix) is non-nil and not a number, show the raw article
8811 without any article massaging functions being run.  Normally, the key
8812 strokes are `C-u g'."
8813   (interactive "P")
8814   (cond
8815    ((numberp arg)
8816     (gnus-summary-show-article t)
8817     (let ((gnus-newsgroup-charset
8818            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8819                (mm-read-coding-system
8820                 "View as charset: " ;; actually it is coding system.
8821                 (with-current-buffer gnus-article-buffer
8822                   (mm-detect-coding-region (point) (point-max))))))
8823           (gnus-newsgroup-ignored-charsets 'gnus-all))
8824       (gnus-summary-select-article nil 'force)
8825       (let ((deps gnus-newsgroup-dependencies)
8826             head header lines)
8827         (save-excursion
8828           (set-buffer gnus-original-article-buffer)
8829           (save-restriction
8830             (message-narrow-to-head)
8831             (setq head (buffer-string))
8832             (goto-char (point-min))
8833             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8834               (goto-char (point-max))
8835               (widen)
8836               (setq lines (1- (count-lines (point) (point-max))))))
8837           (with-temp-buffer
8838             (insert (format "211 %d Article retrieved.\n"
8839                             (cdr gnus-article-current)))
8840             (insert head)
8841             (if lines (insert (format "Lines: %d\n" lines)))
8842             (insert ".\n")
8843             (let ((nntp-server-buffer (current-buffer)))
8844               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8845         (gnus-data-set-header
8846          (gnus-data-find (cdr gnus-article-current))
8847          header)
8848         (gnus-summary-update-article-line
8849          (cdr gnus-article-current) header)
8850         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8851           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8852    ((not arg)
8853     ;; Select the article the normal way.
8854     (gnus-summary-select-article nil 'force))
8855    (t
8856     ;; We have to require this here to make sure that the following
8857     ;; dynamic binding isn't shadowed by autoloading.
8858     (require 'gnus-async)
8859     (require 'gnus-art)
8860     ;; Bind the article treatment functions to nil.
8861     (let ((gnus-have-all-headers t)
8862           gnus-article-prepare-hook
8863           gnus-article-decode-hook
8864           gnus-display-mime-function
8865           gnus-break-pages)
8866       ;; Destroy any MIME parts.
8867       (when (gnus-buffer-live-p gnus-article-buffer)
8868         (save-excursion
8869           (set-buffer gnus-article-buffer)
8870           (mm-destroy-parts gnus-article-mime-handles)
8871           ;; Set it to nil for safety reason.
8872           (setq gnus-article-mime-handle-alist nil)
8873           (setq gnus-article-mime-handles nil)))
8874       (gnus-summary-select-article nil 'force))))
8875   (gnus-summary-goto-subject gnus-current-article)
8876   (gnus-summary-position-point))
8877
8878 (defun gnus-summary-show-raw-article ()
8879   "Show the raw article without any article massaging functions being run."
8880   (interactive)
8881   (gnus-summary-show-article t))
8882
8883 (defun gnus-summary-verbose-headers (&optional arg)
8884   "Toggle permanent full header display.
8885 If ARG is a positive number, turn header display on.
8886 If ARG is a negative number, turn header display off."
8887   (interactive "P")
8888   (setq gnus-show-all-headers
8889         (cond ((or (not (numberp arg))
8890                    (zerop arg))
8891                (not gnus-show-all-headers))
8892               ((natnump arg)
8893                t)))
8894   (gnus-summary-show-article))
8895
8896 (defun gnus-summary-toggle-header (&optional arg)
8897   "Show the headers if they are hidden, or hide them if they are shown.
8898 If ARG is a positive number, show the entire header.
8899 If ARG is a negative number, hide the unwanted header lines."
8900   (interactive "P")
8901   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8902                      (get-buffer-window gnus-article-buffer t))))
8903     (with-current-buffer gnus-article-buffer
8904       (widen)
8905       (article-narrow-to-head)
8906       (let* ((buffer-read-only nil)
8907              (inhibit-point-motion-hooks t)
8908              (hidden (if (numberp arg)
8909                          (>= arg 0)
8910                        (or (not (looking-at "[^ \t\n]+:"))
8911                            (gnus-article-hidden-text-p 'headers))))
8912              s e)
8913         (delete-region (point-min) (point-max))
8914         (with-current-buffer gnus-original-article-buffer
8915           (goto-char (setq s (point-min)))
8916           (setq e (if (search-forward "\n\n" nil t)
8917                       (1- (point))
8918                     (point-max))))
8919         (insert-buffer-substring gnus-original-article-buffer s e)
8920         (run-hooks 'gnus-article-decode-hook)
8921         (if hidden
8922             (let ((gnus-treat-hide-headers nil)
8923                   (gnus-treat-hide-boring-headers nil))
8924               (gnus-delete-wash-type 'headers)
8925               (gnus-treat-article 'head))
8926           (gnus-treat-article 'head))
8927         (widen)
8928         (if window
8929             (set-window-start window (goto-char (point-min))))
8930         (if gnus-break-pages
8931             (gnus-narrow-to-page)
8932           (when (gnus-visual-p 'page-marker)
8933             (let ((buffer-read-only nil))
8934               (gnus-remove-text-with-property 'gnus-prev)
8935               (gnus-remove-text-with-property 'gnus-next))))
8936         (gnus-set-mode-line 'article)))))
8937
8938 (defun gnus-summary-show-all-headers ()
8939   "Make all header lines visible."
8940   (interactive)
8941   (gnus-summary-toggle-header 1))
8942
8943 (defun gnus-summary-caesar-message (&optional arg)
8944   "Caesar rotate the current article by 13.
8945 The numerical prefix specifies how many places to rotate each letter
8946 forward."
8947   (interactive "P")
8948   (gnus-summary-select-article)
8949   (let ((mail-header-separator ""))
8950     (gnus-eval-in-buffer-window gnus-article-buffer
8951       (save-restriction
8952         (widen)
8953         (let ((start (window-start))
8954               buffer-read-only)
8955           (message-caesar-buffer-body arg)
8956           (set-window-start (get-buffer-window (current-buffer)) start))))))
8957
8958 (autoload 'unmorse-region "morse"
8959   "Convert morse coded text in region to ordinary ASCII text."
8960   t)
8961
8962 (defun gnus-summary-morse-message (&optional arg)
8963   "Morse decode the current article."
8964   (interactive "P")
8965   (gnus-summary-select-article)
8966   (let ((mail-header-separator ""))
8967     (gnus-eval-in-buffer-window gnus-article-buffer
8968       (save-excursion
8969         (save-restriction
8970           (widen)
8971           (let ((pos (window-start))
8972                 buffer-read-only)
8973             (goto-char (point-min))
8974             (when (message-goto-body)
8975               (gnus-narrow-to-body))
8976             (goto-char (point-min))
8977             (while (search-forward "·" (point-max) t)
8978               (replace-match "."))
8979             (unmorse-region (point-min) (point-max))
8980             (widen)
8981             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8982
8983 (defun gnus-summary-stop-page-breaking ()
8984   "Stop page breaking in the current article."
8985   (interactive)
8986   (gnus-summary-select-article)
8987   (gnus-eval-in-buffer-window gnus-article-buffer
8988     (widen)
8989     (when (gnus-visual-p 'page-marker)
8990       (let ((buffer-read-only nil))
8991         (gnus-remove-text-with-property 'gnus-prev)
8992         (gnus-remove-text-with-property 'gnus-next))
8993       (setq gnus-page-broken nil))))
8994
8995 (defun gnus-summary-move-article (&optional n to-newsgroup
8996                                             select-method action)
8997   "Move the current article to a different newsgroup.
8998 If N is a positive number, move the N next articles.
8999 If N is a negative number, move the N previous articles.
9000 If N is nil and any articles have been marked with the process mark,
9001 move those articles instead.
9002 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9003 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9004 re-spool using this method.
9005
9006 When called interactively with TO-NEWSGROUP being nil, the value of
9007 the variable `gnus-move-split-methods' is used for finding a default
9008 for the target newsgroup.
9009
9010 For this function to work, both the current newsgroup and the
9011 newsgroup that you want to move to have to support the `request-move'
9012 and `request-accept' functions.
9013
9014 ACTION can be either `move' (the default), `crosspost' or `copy'."
9015   (interactive "P")
9016   (unless action
9017     (setq action 'move))
9018   ;; Check whether the source group supports the required functions.
9019   (cond ((and (eq action 'move)
9020               (not (gnus-check-backend-function
9021                     'request-move-article gnus-newsgroup-name)))
9022          (error "The current group does not support article moving"))
9023         ((and (eq action 'crosspost)
9024               (not (gnus-check-backend-function
9025                     'request-replace-article gnus-newsgroup-name)))
9026          (error "The current group does not support article editing")))
9027   (let ((articles (gnus-summary-work-articles n))
9028         (prefix (if (gnus-check-backend-function
9029                      'request-move-article gnus-newsgroup-name)
9030                     (funcall gnus-move-group-prefix-function
9031                              gnus-newsgroup-name)
9032                   ""))
9033         (names '((move "Move" "Moving")
9034                  (copy "Copy" "Copying")
9035                  (crosspost "Crosspost" "Crossposting")))
9036         (copy-buf (save-excursion
9037                     (nnheader-set-temp-buffer " *copy article*")))
9038         art-group to-method new-xref article to-groups)
9039     (unless (assq action names)
9040       (error "Unknown action %s" action))
9041     ;; Read the newsgroup name.
9042     (when (and (not to-newsgroup)
9043                (not select-method))
9044       (if (and gnus-move-split-methods
9045                (not
9046                 (and (memq gnus-current-article articles)
9047                      (gnus-buffer-live-p gnus-original-article-buffer))))
9048           ;; When `gnus-move-split-methods' is non-nil, we have to
9049           ;; select an article to give `gnus-read-move-group-name' an
9050           ;; opportunity to suggest an appropriate default.  However,
9051           ;; we needn't render or mark the article.
9052           (let ((gnus-display-mime-function nil)
9053                 (gnus-article-prepare-hook nil)
9054                 (gnus-mark-article-hook nil))
9055             (gnus-summary-select-article nil nil nil (car articles))))
9056       (setq to-newsgroup
9057             (gnus-read-move-group-name
9058              (cadr (assq action names))
9059              (symbol-value (intern (format "gnus-current-%s-group" action)))
9060              articles prefix))
9061       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9062     (setq to-method (or select-method
9063                         (gnus-server-to-method
9064                          (gnus-group-method to-newsgroup))))
9065     ;; Check the method we are to move this article to...
9066     (unless (gnus-check-backend-function
9067              'request-accept-article (car to-method))
9068       (error "%s does not support article copying" (car to-method)))
9069     (unless (gnus-check-server to-method)
9070       (error "Can't open server %s" (car to-method)))
9071     (gnus-message 6 "%s to %s: %s..."
9072                   (caddr (assq action names))
9073                   (or (car select-method) to-newsgroup) articles)
9074     (while articles
9075       (setq article (pop articles))
9076       (setq
9077        art-group
9078        (cond
9079         ;; Move the article.
9080         ((eq action 'move)
9081          ;; Remove this article from future suppression.
9082          (gnus-dup-unsuppress-article article)
9083          (gnus-request-move-article
9084           article                       ; Article to move
9085           gnus-newsgroup-name           ; From newsgroup
9086           (nth 1 (gnus-find-method-for-group
9087                   gnus-newsgroup-name)) ; Server
9088           (list 'gnus-request-accept-article
9089                 to-newsgroup (list 'quote select-method)
9090                 (not articles) t)       ; Accept form
9091           (not articles)))              ; Only save nov last time
9092         ;; Copy the article.
9093         ((eq action 'copy)
9094          (save-excursion
9095            (set-buffer copy-buf)
9096            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9097              (save-restriction
9098                (nnheader-narrow-to-headers)
9099                (dolist (hdr gnus-copy-article-ignored-headers)
9100                  (message-remove-header hdr t)))
9101              (gnus-request-accept-article
9102               to-newsgroup select-method (not articles) t))))
9103         ;; Crosspost the article.
9104         ((eq action 'crosspost)
9105          (let ((xref (message-tokenize-header
9106                       (mail-header-xref (gnus-summary-article-header article))
9107                       " ")))
9108            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9109                                   ":" (number-to-string article)))
9110            (unless xref
9111              (setq xref (list (system-name))))
9112            (setq new-xref
9113                  (concat
9114                   (mapconcat 'identity
9115                              (delete "Xref:" (delete new-xref xref))
9116                              " ")
9117                   " " new-xref))
9118            (save-excursion
9119              (set-buffer copy-buf)
9120              ;; First put the article in the destination group.
9121              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9122              (when (consp (setq art-group
9123                                 (gnus-request-accept-article
9124                                  to-newsgroup select-method (not articles))))
9125                (setq new-xref (concat new-xref " " (car art-group)
9126                                       ":"
9127                                       (number-to-string (cdr art-group))))
9128                ;; Now we have the new Xrefs header, so we insert
9129                ;; it and replace the new article.
9130                (nnheader-replace-header "Xref" new-xref)
9131                (gnus-request-replace-article
9132                 (cdr art-group) to-newsgroup (current-buffer))
9133                art-group))))))
9134       (cond
9135        ((not art-group)
9136         (gnus-message 1 "Couldn't %s article %s: %s"
9137                       (cadr (assq action names)) article
9138                       (nnheader-get-report (car to-method))))
9139        ((eq art-group 'junk)
9140         (when (eq action 'move)
9141           (gnus-summary-mark-article article gnus-canceled-mark)
9142           (gnus-message 4 "Deleted article %s" article)
9143           ;; run the delete hook
9144           (run-hook-with-args 'gnus-summary-article-delete-hook
9145                               action
9146                               (gnus-data-header
9147                                (assoc article (gnus-data-list nil)))
9148                               gnus-newsgroup-name nil
9149                               select-method)))
9150        (t
9151         (let* ((pto-group (gnus-group-prefixed-name
9152                            (car art-group) to-method))
9153                (info (gnus-get-info pto-group))
9154                (to-group (gnus-info-group info))
9155                to-marks)
9156           ;; Update the group that has been moved to.
9157           (when (and info
9158                      (memq action '(move copy)))
9159             (unless (member to-group to-groups)
9160               (push to-group to-groups))
9161
9162             (unless (memq article gnus-newsgroup-unreads)
9163               (push 'read to-marks)
9164               (gnus-info-set-read
9165                info (gnus-add-to-range (gnus-info-read info)
9166                                        (list (cdr art-group)))))
9167
9168             ;; See whether the article is to be put in the cache.
9169             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9170                              gnus-article-mark-lists
9171                            (delete '(expirable . expire)
9172                                    (copy-sequence gnus-article-mark-lists))))
9173                   (to-article (cdr art-group)))
9174
9175               ;; Enter the article into the cache in the new group,
9176               ;; if that is required.
9177               (when gnus-use-cache
9178                 (gnus-cache-possibly-enter-article
9179                  to-group to-article
9180                  (memq article gnus-newsgroup-marked)
9181                  (memq article gnus-newsgroup-dormant)
9182                  (memq article gnus-newsgroup-unreads)))
9183
9184               (when gnus-preserve-marks
9185                 ;; Copy any marks over to the new group.
9186                 (when (and (equal to-group gnus-newsgroup-name)
9187                            (not (memq article gnus-newsgroup-unreads)))
9188                   ;; Mark this article as read in this group.
9189                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9190                   (setcdr (gnus-active to-group) to-article)
9191                   (setcdr gnus-newsgroup-active to-article))
9192
9193                 (while marks
9194                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9195                     (when (memq article (symbol-value
9196                                          (intern (format "gnus-newsgroup-%s"
9197                                                          (caar marks)))))
9198                       (push (cdar marks) to-marks)
9199                       ;; If the other group is the same as this group,
9200                       ;; then we have to add the mark to the list.
9201                       (when (equal to-group gnus-newsgroup-name)
9202                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9203                              (cons to-article
9204                                    (symbol-value
9205                                     (intern (format "gnus-newsgroup-%s"
9206                                                     (caar marks)))))))
9207                       ;; Copy the marks to other group.
9208                       (gnus-add-marked-articles
9209                        to-group (cdar marks) (list to-article) info)))
9210                   (setq marks (cdr marks)))
9211
9212                 (gnus-request-set-mark
9213                  to-group (list (list (list to-article) 'add to-marks))))
9214
9215               (gnus-dribble-enter
9216                (concat "(gnus-group-set-info '"
9217                        (gnus-prin1-to-string (gnus-get-info to-group))
9218                        ")"))))
9219
9220           ;; Update the Xref header in this article to point to
9221           ;; the new crossposted article we have just created.
9222           (when (eq action 'crosspost)
9223             (save-excursion
9224               (set-buffer copy-buf)
9225               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9226               (nnheader-replace-header "Xref" new-xref)
9227               (gnus-request-replace-article
9228                article gnus-newsgroup-name (current-buffer))))
9229
9230           ;; run the move/copy/crosspost/respool hook
9231           (run-hook-with-args 'gnus-summary-article-move-hook
9232                               action
9233                               (gnus-data-header
9234                                (assoc article (gnus-data-list nil)))
9235                               gnus-newsgroup-name
9236                               to-newsgroup
9237                               select-method))
9238
9239         ;;;!!!Why is this necessary?
9240         (set-buffer gnus-summary-buffer)
9241         
9242         (gnus-summary-goto-subject article)
9243         (when (eq action 'move)
9244           (gnus-summary-mark-article article gnus-canceled-mark))))
9245       (gnus-summary-remove-process-mark article))
9246     ;; Re-activate all groups that have been moved to.
9247     (save-excursion
9248       (set-buffer gnus-group-buffer)
9249       (let ((gnus-group-marked to-groups))
9250         (gnus-group-get-new-news-this-group nil t)))
9251
9252     (gnus-kill-buffer copy-buf)
9253     (gnus-summary-position-point)
9254     (gnus-set-mode-line 'summary)))
9255
9256 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9257   "Copy the current article to some other group.
9258 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9259 When called interactively, if TO-NEWSGROUP is nil, use the value of
9260 the variable `gnus-move-split-methods' for finding a default target
9261 newsgroup.
9262 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9263 re-spool using this method."
9264   (interactive "P")
9265   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9266
9267 (defun gnus-summary-crosspost-article (&optional n)
9268   "Crosspost the current article to some other group."
9269   (interactive "P")
9270   (gnus-summary-move-article n nil nil 'crosspost))
9271
9272 (defcustom gnus-summary-respool-default-method nil
9273   "Default method type for respooling an article.
9274 If nil, use to the current newsgroup method."
9275   :type 'symbol
9276   :group 'gnus-summary-mail)
9277
9278 (defcustom gnus-summary-display-while-building nil
9279   "If non-nil, show and update the summary buffer as it's being built.
9280 If the value is t, update the buffer after every line is inserted.  If
9281 the value is an integer (N), update the display every N lines."
9282   :version "21.4"
9283   :group 'gnus-thread
9284   :type '(choice (const :tag "off" nil)
9285                  number
9286                  (const :tag "frequently" t)))
9287
9288 (defun gnus-summary-respool-article (&optional n method)
9289   "Respool the current article.
9290 The article will be squeezed through the mail spooling process again,
9291 which means that it will be put in some mail newsgroup or other
9292 depending on `nnmail-split-methods'.
9293 If N is a positive number, respool the N next articles.
9294 If N is a negative number, respool the N previous articles.
9295 If N is nil and any articles have been marked with the process mark,
9296 respool those articles instead.
9297
9298 Respooling can be done both from mail groups and \"real\" newsgroups.
9299 In the former case, the articles in question will be moved from the
9300 current group into whatever groups they are destined to.  In the
9301 latter case, they will be copied into the relevant groups."
9302   (interactive
9303    (list current-prefix-arg
9304          (let* ((methods (gnus-methods-using 'respool))
9305                 (methname
9306                  (symbol-name (or gnus-summary-respool-default-method
9307                                   (car (gnus-find-method-for-group
9308                                         gnus-newsgroup-name)))))
9309                 (method
9310                  (gnus-completing-read-with-default
9311                   methname "What backend do you want to use when respooling?"
9312                   methods nil t nil 'gnus-mail-method-history))
9313                 ms)
9314            (cond
9315             ((zerop (length (setq ms (gnus-servers-using-backend
9316                                       (intern method)))))
9317              (list (intern method) ""))
9318             ((= 1 (length ms))
9319              (car ms))
9320             (t
9321              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9322                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9323                            ms-alist))))))))
9324   (unless method
9325     (error "No method given for respooling"))
9326   (if (assoc (symbol-name
9327               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9328              (gnus-methods-using 'respool))
9329       (gnus-summary-move-article n nil method)
9330     (gnus-summary-copy-article n nil method)))
9331
9332 (defun gnus-summary-import-article (file &optional edit)
9333   "Import an arbitrary file into a mail newsgroup."
9334   (interactive "fImport file: \nP")
9335   (let ((group gnus-newsgroup-name)
9336         (now (current-time))
9337         atts lines group-art)
9338     (unless (gnus-check-backend-function 'request-accept-article group)
9339       (error "%s does not support article importing" group))
9340     (or (file-readable-p file)
9341         (not (file-regular-p file))
9342         (error "Can't read %s" file))
9343     (save-excursion
9344       (set-buffer (gnus-get-buffer-create " *import file*"))
9345       (erase-buffer)
9346       (nnheader-insert-file-contents file)
9347       (goto-char (point-min))
9348       (if (nnheader-article-p)
9349           (save-restriction
9350             (goto-char (point-min))
9351             (search-forward "\n\n" nil t)
9352             (narrow-to-region (point-min) (1- (point)))
9353             (goto-char (point-min))
9354             (unless (re-search-forward "^date:" nil t)
9355               (goto-char (point-max))
9356               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9357        ;; This doesn't look like an article, so we fudge some headers.
9358         (setq atts (file-attributes file)
9359               lines (count-lines (point-min) (point-max)))
9360         (insert "From: " (read-string "From: ") "\n"
9361                 "Subject: " (read-string "Subject: ") "\n"
9362                 "Date: " (message-make-date (nth 5 atts)) "\n"
9363                 "Message-ID: " (message-make-message-id) "\n"
9364                 "Lines: " (int-to-string lines) "\n"
9365                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9366       (setq group-art (gnus-request-accept-article group nil t))
9367       (kill-buffer (current-buffer)))
9368     (setq gnus-newsgroup-active (gnus-activate-group group))
9369     (forward-line 1)
9370     (gnus-summary-goto-article (cdr group-art) nil t)
9371     (when edit
9372       (gnus-summary-edit-article))))
9373
9374 (defun gnus-summary-create-article ()
9375   "Create an article in a mail newsgroup."
9376   (interactive)
9377   (let ((group gnus-newsgroup-name)
9378         (now (current-time))
9379         group-art)
9380     (unless (gnus-check-backend-function 'request-accept-article group)
9381       (error "%s does not support article importing" group))
9382     (save-excursion
9383       (set-buffer (gnus-get-buffer-create " *import file*"))
9384       (erase-buffer)
9385       (goto-char (point-min))
9386       ;; This doesn't look like an article, so we fudge some headers.
9387       (insert "From: " (read-string "From: ") "\n"
9388               "Subject: " (read-string "Subject: ") "\n"
9389               "Date: " (message-make-date now) "\n"
9390               "Message-ID: " (message-make-message-id) "\n")
9391       (setq group-art (gnus-request-accept-article group nil t))
9392       (kill-buffer (current-buffer)))
9393     (setq gnus-newsgroup-active (gnus-activate-group group))
9394     (forward-line 1)
9395     (gnus-summary-goto-article (cdr group-art) nil t)
9396     (gnus-summary-edit-article)))
9397
9398 (defun gnus-summary-article-posted-p ()
9399   "Say whether the current (mail) article is available from news as well.
9400 This will be the case if the article has both been mailed and posted."
9401   (interactive)
9402   (let ((id (mail-header-references (gnus-summary-article-header)))
9403         (gnus-override-method (car (gnus-refer-article-methods))))
9404     (if (gnus-request-head id "")
9405         (gnus-message 2 "The current message was found on %s"
9406                       gnus-override-method)
9407       (gnus-message 2 "The current message couldn't be found on %s"
9408                     gnus-override-method)
9409       nil)))
9410
9411 (defun gnus-summary-expire-articles (&optional now)
9412   "Expire all articles that are marked as expirable in the current group."
9413   (interactive)
9414   (when (and (not gnus-group-is-exiting-without-update-p)
9415              (gnus-check-backend-function
9416               'request-expire-articles gnus-newsgroup-name))
9417     ;; This backend supports expiry.
9418     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9419            (expirable (if total
9420                           (progn
9421                             ;; We need to update the info for
9422                             ;; this group for `gnus-list-of-read-articles'
9423                             ;; to give us the right answer.
9424                             (gnus-run-hooks 'gnus-exit-group-hook)
9425                             (gnus-summary-update-info)
9426                             (gnus-list-of-read-articles gnus-newsgroup-name))
9427                         (setq gnus-newsgroup-expirable
9428                               (sort gnus-newsgroup-expirable '<))))
9429            (expiry-wait (if now 'immediate
9430                           (gnus-group-find-parameter
9431                            gnus-newsgroup-name 'expiry-wait)))
9432            (nnmail-expiry-target
9433             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9434                 nnmail-expiry-target))
9435            es)
9436       (when expirable
9437         ;; There are expirable articles in this group, so we run them
9438         ;; through the expiry process.
9439         (gnus-message 6 "Expiring articles...")
9440         (unless (gnus-check-group gnus-newsgroup-name)
9441           (error "Can't open server for %s" gnus-newsgroup-name))
9442         ;; The list of articles that weren't expired is returned.
9443         (save-excursion
9444           (if expiry-wait
9445               (let ((nnmail-expiry-wait-function nil)
9446                     (nnmail-expiry-wait expiry-wait))
9447                 (setq es (gnus-request-expire-articles
9448                           expirable gnus-newsgroup-name)))
9449             (setq es (gnus-request-expire-articles
9450                       expirable gnus-newsgroup-name)))
9451           (unless total
9452             (setq gnus-newsgroup-expirable es))
9453           ;; We go through the old list of expirable, and mark all
9454           ;; really expired articles as nonexistent.
9455           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9456             (let ((gnus-use-cache nil))
9457               (dolist (article expirable)
9458                 (when (and (not (memq article es))
9459                            (gnus-data-find article))
9460                   (gnus-summary-mark-article article gnus-canceled-mark)
9461                   (run-hook-with-args 'gnus-summary-article-expire-hook
9462                                       'delete
9463                                       (gnus-data-header
9464                                        (assoc article (gnus-data-list nil)))
9465                                       gnus-newsgroup-name
9466                                       nil
9467                                       nil))))))
9468         (gnus-message 6 "Expiring articles...done")))))
9469
9470 (defun gnus-summary-expire-articles-now ()
9471   "Expunge all expirable articles in the current group.
9472 This means that *all* articles that are marked as expirable will be
9473 deleted forever, right now."
9474   (interactive)
9475   (or gnus-expert-user
9476       (gnus-yes-or-no-p
9477        "Are you really, really, really sure you want to delete all these messages? ")
9478       (error "Phew!"))
9479   (gnus-summary-expire-articles t))
9480
9481 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9482 (defun gnus-summary-delete-article (&optional n)
9483   "Delete the N next (mail) articles.
9484 This command actually deletes articles.  This is not a marking
9485 command.  The article will disappear forever from your life, never to
9486 return.
9487
9488 If N is negative, delete backwards.
9489 If N is nil and articles have been marked with the process mark,
9490 delete these instead.
9491
9492 If `gnus-novice-user' is non-nil you will be asked for
9493 confirmation before the articles are deleted."
9494   (interactive "P")
9495   (unless (gnus-check-backend-function 'request-expire-articles
9496                                        gnus-newsgroup-name)
9497     (error "The current newsgroup does not support article deletion"))
9498   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9499     (error "Couldn't open server"))
9500   ;; Compute the list of articles to delete.
9501   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9502         (nnmail-expiry-target 'delete)
9503         not-deleted)
9504     (if (and gnus-novice-user
9505              (not (gnus-yes-or-no-p
9506                    (format "Do you really want to delete %s forever? "
9507                            (if (> (length articles) 1)
9508                                (format "these %s articles" (length articles))
9509                              "this article")))))
9510         ()
9511       ;; Delete the articles.
9512       (setq not-deleted (gnus-request-expire-articles
9513                          articles gnus-newsgroup-name 'force))
9514       (while articles
9515         (gnus-summary-remove-process-mark (car articles))
9516         ;; The backend might not have been able to delete the article
9517         ;; after all.
9518         (unless (memq (car articles) not-deleted)
9519           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9520         (let* ((article (car articles))
9521                (ghead  (gnus-data-header
9522                                     (assoc article (gnus-data-list nil)))))
9523           (run-hook-with-args 'gnus-summary-article-delete-hook
9524                               'delete ghead gnus-newsgroup-name nil
9525                               nil))
9526         (setq articles (cdr articles)))
9527       (when not-deleted
9528         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9529     (gnus-summary-position-point)
9530     (gnus-set-mode-line 'summary)
9531     not-deleted))
9532
9533 (defun gnus-summary-edit-article (&optional arg)
9534   "Edit the current article.
9535 This will have permanent effect only in mail groups.
9536 If ARG is nil, edit the decoded articles.
9537 If ARG is 1, edit the raw articles.
9538 If ARG is 2, edit the raw articles even in read-only groups.
9539 If ARG is 3, edit the articles with the current handles.
9540 Otherwise, allow editing of articles even in read-only
9541 groups."
9542   (interactive "P")
9543   (let (force raw current-handles)
9544     (cond
9545      ((null arg))
9546      ((eq arg 1)
9547       (setq raw t))
9548      ((eq arg 2)
9549       (setq raw t
9550             force t))
9551      ((eq arg 3)
9552       (setq current-handles
9553             (and (gnus-buffer-live-p gnus-article-buffer)
9554                  (with-current-buffer gnus-article-buffer
9555                    (prog1
9556                        gnus-article-mime-handles
9557                      (setq gnus-article-mime-handles nil))))))
9558      (t
9559       (setq force t)))
9560     (when (and raw (not force)
9561                (member gnus-newsgroup-name '("nndraft:delayed"
9562                                              "nndraft:drafts"
9563                                              "nndraft:queue")))
9564       (error "Can't edit the raw article in group %s"
9565              gnus-newsgroup-name))
9566     (save-excursion
9567       (set-buffer gnus-summary-buffer)
9568       (let ((mail-parse-charset gnus-newsgroup-charset)
9569             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9570         (gnus-set-global-variables)
9571         (when (and (not force)
9572                    (gnus-group-read-only-p))
9573           (error "The current newsgroup does not support article editing"))
9574         (gnus-summary-show-article t)
9575         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9576           (with-current-buffer gnus-article-buffer
9577             (mm-enable-multibyte)))
9578         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9579             (setq raw t))
9580         (gnus-article-edit-article
9581          (if raw 'ignore
9582            `(lambda ()
9583               (let ((mbl mml-buffer-list))
9584                 (setq mml-buffer-list nil)
9585                 (mime-to-mml ,'current-handles)
9586                 (let ((mbl1 mml-buffer-list))
9587                   (setq mml-buffer-list mbl)
9588                   (set (make-local-variable 'mml-buffer-list) mbl1))
9589                 (gnus-make-local-hook 'kill-buffer-hook)
9590                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9591          `(lambda (no-highlight)
9592             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9593                   (message-options message-options)
9594                   (message-options-set-recipient)
9595                   (mail-parse-ignored-charsets
9596                    ',gnus-newsgroup-ignored-charsets))
9597               ,(if (not raw) '(progn
9598                                 (mml-to-mime)
9599                                 (mml-destroy-buffers)
9600                                 (remove-hook 'kill-buffer-hook
9601                                              'mml-destroy-buffers t)
9602                                 (kill-local-variable 'mml-buffer-list)))
9603               (gnus-summary-edit-article-done
9604                ,(or (mail-header-references gnus-current-headers) "")
9605                ,(gnus-group-read-only-p)
9606                ,gnus-summary-buffer no-highlight))))))))
9607
9608 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9609
9610 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9611                                                  no-highlight)
9612   "Make edits to the current article permanent."
9613   (interactive)
9614   (save-excursion
9615    ;; The buffer restriction contains the entire article if it exists.
9616     (when (article-goto-body)
9617       (let ((lines (count-lines (point) (point-max)))
9618             (length (- (point-max) (point)))
9619             (case-fold-search t)
9620             (body (copy-marker (point))))
9621         (goto-char (point-min))
9622         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9623           (delete-region (match-beginning 1) (match-end 1))
9624           (insert (number-to-string length)))
9625         (goto-char (point-min))
9626         (when (re-search-forward
9627                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9628           (delete-region (match-beginning 1) (match-end 1))
9629           (insert (number-to-string length)))
9630         (goto-char (point-min))
9631         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9632           (delete-region (match-beginning 1) (match-end 1))
9633           (insert (number-to-string lines))))))
9634   ;; Replace the article.
9635   (let ((buf (current-buffer)))
9636     (with-temp-buffer
9637       (insert-buffer-substring buf)
9638
9639       (if (and (not read-only)
9640                (not (gnus-request-replace-article
9641                      (cdr gnus-article-current) (car gnus-article-current)
9642                      (current-buffer) t)))
9643           (error "Couldn't replace article")
9644         ;; Update the summary buffer.
9645         (if (and references
9646                  (equal (message-tokenize-header references " ")
9647                         (message-tokenize-header
9648                          (or (message-fetch-field "references") "") " ")))
9649             ;; We only have to update this line.
9650             (save-excursion
9651               (save-restriction
9652                 (message-narrow-to-head)
9653                 (let ((head (buffer-string))
9654                       header)
9655                   (with-temp-buffer
9656                     (insert (format "211 %d Article retrieved.\n"
9657                                     (cdr gnus-article-current)))
9658                     (insert head)
9659                     (insert ".\n")
9660                     (let ((nntp-server-buffer (current-buffer)))
9661                       (setq header (car (gnus-get-newsgroup-headers
9662                                          nil t))))
9663                     (save-excursion
9664                       (set-buffer gnus-summary-buffer)
9665                       (gnus-data-set-header
9666                        (gnus-data-find (cdr gnus-article-current))
9667                        header)
9668                       (gnus-summary-update-article-line
9669                        (cdr gnus-article-current) header)
9670                       (if (gnus-summary-goto-subject
9671                            (cdr gnus-article-current) nil t)
9672                           (gnus-summary-update-secondary-mark
9673                            (cdr gnus-article-current))))))))
9674           ;; Update threads.
9675           (set-buffer (or buffer gnus-summary-buffer))
9676           (gnus-summary-update-article (cdr gnus-article-current))
9677           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9678               (gnus-summary-update-secondary-mark
9679                (cdr gnus-article-current))))
9680         ;; Prettify the article buffer again.
9681         (unless no-highlight
9682           (save-excursion
9683             (set-buffer gnus-article-buffer)
9684             ;;;!!! Fix this -- article should be rehighlighted.
9685             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9686             (set-buffer gnus-original-article-buffer)
9687             (gnus-request-article
9688              (cdr gnus-article-current)
9689              (car gnus-article-current) (current-buffer))))
9690         ;; Prettify the summary buffer line.
9691         (when (gnus-visual-p 'summary-highlight 'highlight)
9692           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9693
9694 (defun gnus-summary-edit-wash (key)
9695   "Perform editing command KEY in the article buffer."
9696   (interactive
9697    (list
9698     (progn
9699       (message "%s" (concat (this-command-keys) "- "))
9700       (read-char))))
9701   (message "")
9702   (gnus-summary-edit-article)
9703   (execute-kbd-macro (concat (this-command-keys) key))
9704   (gnus-article-edit-done))
9705
9706 ;;; Respooling
9707
9708 (defun gnus-summary-respool-query (&optional silent trace)
9709   "Query where the respool algorithm would put this article."
9710   (interactive)
9711   (let (gnus-mark-article-hook)
9712     (gnus-summary-select-article)
9713     (save-excursion
9714       (set-buffer gnus-original-article-buffer)
9715       (let ((groups (nnmail-article-group 'identity trace)))
9716         (unless silent
9717           (if groups
9718               (message "This message would go to %s"
9719                        (mapconcat 'car groups ", "))
9720             (message "This message would go to no groups"))
9721           groups)))))
9722
9723 (defun gnus-summary-respool-trace ()
9724   "Trace where the respool algorithm would put this article.
9725 Display a buffer showing all fancy splitting patterns which matched."
9726   (interactive)
9727   (gnus-summary-respool-query nil t))
9728
9729 ;; Summary marking commands.
9730
9731 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9732   "Mark articles which has the same subject as read, and then select the next.
9733 If UNMARK is positive, remove any kind of mark.
9734 If UNMARK is negative, tick articles."
9735   (interactive "P")
9736   (when unmark
9737     (setq unmark (prefix-numeric-value unmark)))
9738   (let ((count
9739          (gnus-summary-mark-same-subject
9740           (gnus-summary-article-subject) unmark)))
9741     ;; Select next unread article.  If auto-select-same mode, should
9742     ;; select the first unread article.
9743     (gnus-summary-next-article t (and gnus-auto-select-same
9744                                       (gnus-summary-article-subject)))
9745     (gnus-message 7 "%d article%s marked as %s"
9746                   count (if (= count 1) " is" "s are")
9747                   (if unmark "unread" "read"))))
9748
9749 (defun gnus-summary-kill-same-subject (&optional unmark)
9750   "Mark articles which has the same subject as read.
9751 If UNMARK is positive, remove any kind of mark.
9752 If UNMARK is negative, tick articles."
9753   (interactive "P")
9754   (when unmark
9755     (setq unmark (prefix-numeric-value unmark)))
9756   (let ((count
9757          (gnus-summary-mark-same-subject
9758           (gnus-summary-article-subject) unmark)))
9759     ;; If marked as read, go to next unread subject.
9760     (when (null unmark)
9761       ;; Go to next unread subject.
9762       (gnus-summary-next-subject 1 t))
9763     (gnus-message 7 "%d articles are marked as %s"
9764                   count (if unmark "unread" "read"))))
9765
9766 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9767   "Mark articles with same SUBJECT as read, and return marked number.
9768 If optional argument UNMARK is positive, remove any kinds of marks.
9769 If optional argument UNMARK is negative, mark articles as unread instead."
9770   (let ((count 1))
9771     (save-excursion
9772       (cond
9773        ((null unmark)                   ; Mark as read.
9774         (while (and
9775                 (progn
9776                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9777                   (gnus-summary-show-thread) t)
9778                 (gnus-summary-find-subject subject))
9779           (setq count (1+ count))))
9780        ((> unmark 0)                    ; Tick.
9781         (while (and
9782                 (progn
9783                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9784                   (gnus-summary-show-thread) t)
9785                 (gnus-summary-find-subject subject))
9786           (setq count (1+ count))))
9787        (t                               ; Mark as unread.
9788         (while (and
9789                 (progn
9790                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9791                   (gnus-summary-show-thread) t)
9792                 (gnus-summary-find-subject subject))
9793           (setq count (1+ count)))))
9794       (gnus-set-mode-line 'summary)
9795       ;; Return the number of marked articles.
9796       count)))
9797
9798 (defun gnus-summary-mark-as-processable (n &optional unmark)
9799   "Set the process mark on the next N articles.
9800 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9801 the process mark instead.  The difference between N and the actual
9802 number of articles marked is returned."
9803   (interactive "P")
9804   (if (and (null n) (gnus-region-active-p))
9805       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9806     (setq n (prefix-numeric-value n))
9807     (let ((backward (< n 0))
9808           (n (abs n)))
9809       (while (and
9810               (> n 0)
9811               (if unmark
9812                   (gnus-summary-remove-process-mark
9813                    (gnus-summary-article-number))
9814                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9815               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9816         (setq n (1- n)))
9817       (when (/= 0 n)
9818         (gnus-message 7 "No more articles"))
9819       (gnus-summary-recenter)
9820       (gnus-summary-position-point)
9821       n)))
9822
9823 (defun gnus-summary-unmark-as-processable (n)
9824   "Remove the process mark from the next N articles.
9825 If N is negative, unmark backward instead.  The difference between N and
9826 the actual number of articles unmarked is returned."
9827   (interactive "P")
9828   (gnus-summary-mark-as-processable n t))
9829
9830 (defun gnus-summary-unmark-all-processable ()
9831   "Remove the process mark from all articles."
9832   (interactive)
9833   (save-excursion
9834     (while gnus-newsgroup-processable
9835       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9836   (gnus-summary-position-point))
9837
9838 (defun gnus-summary-add-mark (article type)
9839   "Mark ARTICLE with a mark of TYPE."
9840   (let ((vtype (car (assq type gnus-article-mark-lists)))
9841         var)
9842     (if (not vtype)
9843         (error "No such mark type: %s" type)
9844       (setq var (intern (format "gnus-newsgroup-%s" type)))
9845       (set var (cons article (symbol-value var)))
9846       (if (memq type '(processable cached replied forwarded recent saved))
9847           (gnus-summary-update-secondary-mark article)
9848         ;;; !!! This is bogus.  We should find out what primary
9849         ;;; !!! mark we want to set.
9850         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9851
9852 (defun gnus-summary-mark-as-expirable (n)
9853   "Mark N articles forward as expirable.
9854 If N is negative, mark backward instead.  The difference between N and
9855 the actual number of articles marked is returned."
9856   (interactive "p")
9857   (gnus-summary-mark-forward n gnus-expirable-mark))
9858
9859 (defun gnus-summary-mark-as-spam (n)
9860   "Mark N articles forward as spam.
9861 If N is negative, mark backward instead.  The difference between N and
9862 the actual number of articles marked is returned."
9863   (interactive "p")
9864   (gnus-summary-mark-forward n gnus-spam-mark))
9865
9866 (defun gnus-summary-mark-article-as-replied (article)
9867   "Mark ARTICLE as replied to and update the summary line.
9868 ARTICLE can also be a list of articles."
9869   (interactive (list (gnus-summary-article-number)))
9870   (let ((articles (if (listp article) article (list article))))
9871     (dolist (article articles)
9872       (unless (numberp article)
9873         (error "%s is not a number" article))
9874       (push article gnus-newsgroup-replied)
9875       (let ((buffer-read-only nil))
9876         (when (gnus-summary-goto-subject article nil t)
9877           (gnus-summary-update-secondary-mark article))))))
9878
9879 (defun gnus-summary-mark-article-as-forwarded (article)
9880   "Mark ARTICLE as forwarded and update the summary line.
9881 ARTICLE can also be a list of articles."
9882   (let ((articles (if (listp article) article (list article))))
9883     (dolist (article articles)
9884       (push article gnus-newsgroup-forwarded)
9885       (let ((buffer-read-only nil))
9886         (when (gnus-summary-goto-subject article nil t)
9887           (gnus-summary-update-secondary-mark article))))))
9888
9889 (defun gnus-summary-set-bookmark (article)
9890   "Set a bookmark in current article."
9891   (interactive (list (gnus-summary-article-number)))
9892   (when (or (not (get-buffer gnus-article-buffer))
9893             (not gnus-current-article)
9894             (not gnus-article-current)
9895             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9896     (error "No current article selected"))
9897   ;; Remove old bookmark, if one exists.
9898   (gnus-pull article gnus-newsgroup-bookmarks)
9899   ;; Set the new bookmark, which is on the form
9900   ;; (article-number . line-number-in-body).
9901   (push
9902    (cons article
9903          (with-current-buffer gnus-article-buffer
9904            (count-lines
9905             (min (point)
9906                  (save-excursion
9907                    (article-goto-body)
9908                    (point)))
9909             (point))))
9910    gnus-newsgroup-bookmarks)
9911   (gnus-message 6 "A bookmark has been added to the current article."))
9912
9913 (defun gnus-summary-remove-bookmark (article)
9914   "Remove the bookmark from the current article."
9915   (interactive (list (gnus-summary-article-number)))
9916   ;; Remove old bookmark, if one exists.
9917   (if (not (assq article gnus-newsgroup-bookmarks))
9918       (gnus-message 6 "No bookmark in current article.")
9919     (gnus-pull article gnus-newsgroup-bookmarks)
9920     (gnus-message 6 "Removed bookmark.")))
9921
9922 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9923 (defun gnus-summary-mark-as-dormant (n)
9924   "Mark N articles forward as dormant.
9925 If N is negative, mark backward instead.  The difference between N and
9926 the actual number of articles marked is returned."
9927   (interactive "p")
9928   (gnus-summary-mark-forward n gnus-dormant-mark))
9929
9930 (defun gnus-summary-set-process-mark (article)
9931   "Set the process mark on ARTICLE and update the summary line."
9932   (setq gnus-newsgroup-processable
9933         (cons article
9934               (delq article gnus-newsgroup-processable)))
9935   (when (gnus-summary-goto-subject article)
9936     (gnus-summary-show-thread)
9937     (gnus-summary-goto-subject article)
9938     (gnus-summary-update-secondary-mark article)))
9939
9940 (defun gnus-summary-remove-process-mark (article)
9941   "Remove the process mark from ARTICLE and update the summary line."
9942   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9943   (when (gnus-summary-goto-subject article)
9944     (gnus-summary-show-thread)
9945     (gnus-summary-goto-subject article)
9946     (gnus-summary-update-secondary-mark article)))
9947
9948 (defun gnus-summary-set-saved-mark (article)
9949   "Set the process mark on ARTICLE and update the summary line."
9950   (push article gnus-newsgroup-saved)
9951   (when (gnus-summary-goto-subject article)
9952     (gnus-summary-update-secondary-mark article)))
9953
9954 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9955   "Mark N articles as read forwards.
9956 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9957 The difference between N and the actual number of articles marked is
9958 returned.
9959 If NO-EXPIRE, auto-expiry will be inhibited."
9960   (interactive "p")
9961   (gnus-summary-show-thread)
9962   (let ((backward (< n 0))
9963         (gnus-summary-goto-unread
9964          (and gnus-summary-goto-unread
9965               (not (eq gnus-summary-goto-unread 'never))
9966               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9967                                     gnus-ticked-mark gnus-dormant-mark)))))
9968         (n (abs n))
9969         (mark (or mark gnus-del-mark)))
9970     (while (and (> n 0)
9971                 (gnus-summary-mark-article nil mark no-expire)
9972                 (zerop (gnus-summary-next-subject
9973                         (if backward -1 1)
9974                         (and gnus-summary-goto-unread
9975                              (not (eq gnus-summary-goto-unread 'never)))
9976                         t)))
9977       (setq n (1- n)))
9978     (when (/= 0 n)
9979       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9980     (gnus-summary-recenter)
9981     (gnus-summary-position-point)
9982     (gnus-set-mode-line 'summary)
9983     n))
9984
9985 (defun gnus-summary-mark-article-as-read (mark)
9986   "Mark the current article quickly as read with MARK."
9987   (let ((article (gnus-summary-article-number)))
9988     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9989     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9990     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9991     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9992     (push (cons article mark) gnus-newsgroup-reads)
9993     ;; Possibly remove from cache, if that is used.
9994     (when gnus-use-cache
9995       (gnus-cache-enter-remove-article article))
9996     ;; Allow the backend to change the mark.
9997     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9998     ;; Check for auto-expiry.
9999     (when (and gnus-newsgroup-auto-expire
10000                (memq mark gnus-auto-expirable-marks))
10001       (setq mark gnus-expirable-mark)
10002       ;; Let the backend know about the mark change.
10003       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10004       (push article gnus-newsgroup-expirable))
10005     ;; Set the mark in the buffer.
10006     (gnus-summary-update-mark mark 'unread)
10007     t))
10008
10009 (defun gnus-summary-mark-article-as-unread (mark)
10010   "Mark the current article quickly as unread with MARK."
10011   (let* ((article (gnus-summary-article-number))
10012          (old-mark (gnus-summary-article-mark article)))
10013     ;; Allow the backend to change the mark.
10014     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10015     (if (eq mark old-mark)
10016         t
10017       (if (<= article 0)
10018           (progn
10019             (gnus-error 1 "Can't mark negative article numbers")
10020             nil)
10021         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10022         (setq gnus-newsgroup-spam-marked
10023               (delq article gnus-newsgroup-spam-marked))
10024         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10025         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10026         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10027         (cond ((= mark gnus-ticked-mark)
10028                (setq gnus-newsgroup-marked
10029                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10030                                               article)))
10031               ((= mark gnus-spam-mark)
10032                (setq gnus-newsgroup-spam-marked
10033                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10034                                               article)))
10035               ((= mark gnus-dormant-mark)
10036                (setq gnus-newsgroup-dormant
10037                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10038                                               article)))
10039               (t
10040                (setq gnus-newsgroup-unreads
10041                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10042                                               article))))
10043         (gnus-pull article gnus-newsgroup-reads)
10044
10045         ;; See whether the article is to be put in the cache.
10046         (and gnus-use-cache
10047              (vectorp (gnus-summary-article-header article))
10048              (save-excursion
10049                (gnus-cache-possibly-enter-article
10050                 gnus-newsgroup-name article
10051                 (= mark gnus-ticked-mark)
10052                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10053
10054         ;; Fix the mark.
10055         (gnus-summary-update-mark mark 'unread)
10056         t))))
10057
10058 (defun gnus-summary-mark-article (&optional article mark no-expire)
10059   "Mark ARTICLE with MARK.  MARK can be any character.
10060 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10061 `??' (dormant) and `?E' (expirable).
10062 If MARK is nil, then the default character `?r' is used.
10063 If ARTICLE is nil, then the article on the current line will be
10064 marked.
10065 If NO-EXPIRE, auto-expiry will be inhibited."
10066   ;; The mark might be a string.
10067   (when (stringp mark)
10068     (setq mark (aref mark 0)))
10069   ;; If no mark is given, then we check auto-expiring.
10070   (when (null mark)
10071     (setq mark gnus-del-mark))
10072   (when (and (not no-expire)
10073              gnus-newsgroup-auto-expire
10074              (memq mark gnus-auto-expirable-marks))
10075     (setq mark gnus-expirable-mark))
10076   (let ((article (or article (gnus-summary-article-number)))
10077         (old-mark (gnus-summary-article-mark article)))
10078     ;; Allow the backend to change the mark.
10079     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10080     (if (eq mark old-mark)
10081         t
10082       (unless article
10083         (error "No article on current line"))
10084       (if (not (if (or (= mark gnus-unread-mark)
10085                        (= mark gnus-ticked-mark)
10086                        (= mark gnus-spam-mark)
10087                        (= mark gnus-dormant-mark))
10088                    (gnus-mark-article-as-unread article mark)
10089                  (gnus-mark-article-as-read article mark)))
10090           t
10091         ;; See whether the article is to be put in the cache.
10092         (and gnus-use-cache
10093              (not (= mark gnus-canceled-mark))
10094              (vectorp (gnus-summary-article-header article))
10095              (save-excursion
10096                (gnus-cache-possibly-enter-article
10097                 gnus-newsgroup-name article
10098                 (= mark gnus-ticked-mark)
10099                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10100
10101         (when (gnus-summary-goto-subject article nil t)
10102           (let ((buffer-read-only nil))
10103             (gnus-summary-show-thread)
10104             ;; Fix the mark.
10105             (gnus-summary-update-mark mark 'unread)
10106             t))))))
10107
10108 (defun gnus-summary-update-secondary-mark (article)
10109   "Update the secondary (read, process, cache) mark."
10110   (gnus-summary-update-mark
10111    (cond ((memq article gnus-newsgroup-processable)
10112           gnus-process-mark)
10113          ((memq article gnus-newsgroup-cached)
10114           gnus-cached-mark)
10115          ((memq article gnus-newsgroup-replied)
10116           gnus-replied-mark)
10117          ((memq article gnus-newsgroup-forwarded)
10118           gnus-forwarded-mark)
10119          ((memq article gnus-newsgroup-saved)
10120           gnus-saved-mark)
10121          ((memq article gnus-newsgroup-recent)
10122           gnus-recent-mark)
10123          ((memq article gnus-newsgroup-unseen)
10124           gnus-unseen-mark)
10125          (t gnus-no-mark))
10126    'replied)
10127   (when (gnus-visual-p 'summary-highlight 'highlight)
10128     (gnus-run-hooks 'gnus-summary-update-hook))
10129   t)
10130
10131 (defun gnus-summary-update-download-mark (article)
10132   "Update the download mark."
10133   (gnus-summary-update-mark
10134    (cond ((memq article gnus-newsgroup-undownloaded)
10135           gnus-undownloaded-mark)
10136          (gnus-newsgroup-agentized
10137           gnus-downloaded-mark)
10138          (t
10139           gnus-no-mark))
10140    'download)
10141   (gnus-summary-update-line t)
10142   t)
10143
10144 (defun gnus-summary-update-mark (mark type)
10145   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10146         (buffer-read-only nil))
10147     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10148     (when forward
10149       (when (looking-at "\r")
10150         (incf forward))
10151       (when (<= (+ forward (point)) (point-max))
10152         ;; Go to the right position on the line.
10153         (goto-char (+ forward (point)))
10154         ;; Replace the old mark with the new mark.
10155         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10156         ;; Optionally update the marks by some user rule.
10157         (when (eq type 'unread)
10158           (gnus-data-set-mark
10159            (gnus-data-find (gnus-summary-article-number)) mark)
10160           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10161
10162 (defun gnus-mark-article-as-read (article &optional mark)
10163   "Enter ARTICLE in the pertinent lists and remove it from others."
10164   ;; Make the article expirable.
10165   (let ((mark (or mark gnus-del-mark)))
10166     (setq gnus-newsgroup-expirable
10167           (if (= mark gnus-expirable-mark)
10168               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10169             (delq article gnus-newsgroup-expirable)))
10170     ;; Remove from unread and marked lists.
10171     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10172     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10173     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10174     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10175     (push (cons article mark) gnus-newsgroup-reads)
10176     ;; Possibly remove from cache, if that is used.
10177     (when gnus-use-cache
10178       (gnus-cache-enter-remove-article article))
10179     t))
10180
10181 (defun gnus-mark-article-as-unread (article &optional mark)
10182   "Enter ARTICLE in the pertinent lists and remove it from others."
10183   (let ((mark (or mark gnus-ticked-mark)))
10184     (if (<= article 0)
10185         (progn
10186           (gnus-error 1 "Can't mark negative article numbers")
10187           nil)
10188       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10189             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10190             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10191             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10192             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10193
10194       ;; Unsuppress duplicates?
10195       (when gnus-suppress-duplicates
10196         (gnus-dup-unsuppress-article article))
10197
10198       (cond ((= mark gnus-ticked-mark)
10199              (setq gnus-newsgroup-marked
10200                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10201             ((= mark gnus-spam-mark)
10202              (setq gnus-newsgroup-spam-marked
10203                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10204                                             article)))
10205             ((= mark gnus-dormant-mark)
10206              (setq gnus-newsgroup-dormant
10207                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10208             (t
10209              (setq gnus-newsgroup-unreads
10210                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10211       (gnus-pull article gnus-newsgroup-reads)
10212       t)))
10213
10214 (defalias 'gnus-summary-mark-as-unread-forward
10215   'gnus-summary-tick-article-forward)
10216 (make-obsolete 'gnus-summary-mark-as-unread-forward
10217                'gnus-summary-tick-article-forward)
10218 (defun gnus-summary-tick-article-forward (n)
10219   "Tick N articles forwards.
10220 If N is negative, tick backwards instead.
10221 The difference between N and the number of articles ticked is returned."
10222   (interactive "p")
10223   (gnus-summary-mark-forward n gnus-ticked-mark))
10224
10225 (defalias 'gnus-summary-mark-as-unread-backward
10226   'gnus-summary-tick-article-backward)
10227 (make-obsolete 'gnus-summary-mark-as-unread-backward
10228                'gnus-summary-tick-article-backward)
10229 (defun gnus-summary-tick-article-backward (n)
10230   "Tick N articles backwards.
10231 The difference between N and the number of articles ticked is returned."
10232   (interactive "p")
10233   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10234
10235 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10236 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10237 (defun gnus-summary-tick-article (&optional article clear-mark)
10238   "Mark current article as unread.
10239 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10240 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10241   (interactive)
10242   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10243                                        gnus-ticked-mark)))
10244
10245 (defun gnus-summary-mark-as-read-forward (n)
10246   "Mark N articles as read forwards.
10247 If N is negative, mark backwards instead.
10248 The difference between N and the actual number of articles marked is
10249 returned."
10250   (interactive "p")
10251   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10252
10253 (defun gnus-summary-mark-as-read-backward (n)
10254   "Mark the N articles as read backwards.
10255 The difference between N and the actual number of articles marked is
10256 returned."
10257   (interactive "p")
10258   (gnus-summary-mark-forward
10259    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10260
10261 (defun gnus-summary-mark-as-read (&optional article mark)
10262   "Mark current article as read.
10263 ARTICLE specifies the article to be marked as read.
10264 MARK specifies a string to be inserted at the beginning of the line."
10265   (gnus-summary-mark-article article mark))
10266
10267 (defun gnus-summary-clear-mark-forward (n)
10268   "Clear marks from N articles forward.
10269 If N is negative, clear backward instead.
10270 The difference between N and the number of marks cleared is returned."
10271   (interactive "p")
10272   (gnus-summary-mark-forward n gnus-unread-mark))
10273
10274 (defun gnus-summary-clear-mark-backward (n)
10275   "Clear marks from N articles backward.
10276 The difference between N and the number of marks cleared is returned."
10277   (interactive "p")
10278   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10279
10280 (defun gnus-summary-mark-unread-as-read ()
10281   "Intended to be used by `gnus-summary-mark-article-hook'."
10282   (when (memq gnus-current-article gnus-newsgroup-unreads)
10283     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10284
10285 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10286   "Intended to be used by `gnus-summary-mark-article-hook'."
10287   (let ((mark (gnus-summary-article-mark)))
10288     (when (or (gnus-unread-mark-p mark)
10289               (gnus-read-mark-p mark))
10290       (gnus-summary-mark-article gnus-current-article
10291                                  (or new-mark gnus-read-mark)))))
10292
10293 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10294   "Intended to be used by `gnus-summary-mark-article-hook'."
10295   (let ((mark (gnus-summary-article-mark)))
10296     (when (or (gnus-unread-mark-p mark)
10297               (gnus-read-mark-p mark))
10298       (gnus-summary-mark-article (gnus-summary-article-number)
10299                                  (or new-mark gnus-read-mark)))))
10300
10301 (defun gnus-summary-mark-unread-as-ticked ()
10302   "Intended to be used by `gnus-summary-mark-article-hook'."
10303   (when (memq gnus-current-article gnus-newsgroup-unreads)
10304     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10305
10306 (defun gnus-summary-mark-region-as-read (point mark all)
10307   "Mark all unread articles between point and mark as read.
10308 If given a prefix, mark all articles between point and mark as read,
10309 even ticked and dormant ones."
10310   (interactive "r\nP")
10311   (save-excursion
10312     (let (article)
10313       (goto-char point)
10314       (beginning-of-line)
10315       (while (and
10316               (< (point) mark)
10317               (progn
10318                 (when (or all
10319                           (memq (setq article (gnus-summary-article-number))
10320                                 gnus-newsgroup-unreads))
10321                   (gnus-summary-mark-article article gnus-del-mark))
10322                 t)
10323               (gnus-summary-find-next))))))
10324
10325 (defun gnus-summary-mark-below (score mark)
10326   "Mark articles with score less than SCORE with MARK."
10327   (interactive "P\ncMark: ")
10328   (setq score (if score
10329                   (prefix-numeric-value score)
10330                 (or gnus-summary-default-score 0)))
10331   (save-excursion
10332     (set-buffer gnus-summary-buffer)
10333     (goto-char (point-min))
10334     (while
10335         (progn
10336           (and (< (gnus-summary-article-score) score)
10337                (gnus-summary-mark-article nil mark))
10338           (gnus-summary-find-next)))))
10339
10340 (defun gnus-summary-kill-below (&optional score)
10341   "Mark articles with score below SCORE as read."
10342   (interactive "P")
10343   (gnus-summary-mark-below score gnus-killed-mark))
10344
10345 (defun gnus-summary-clear-above (&optional score)
10346   "Clear all marks from articles with score above SCORE."
10347   (interactive "P")
10348   (gnus-summary-mark-above score gnus-unread-mark))
10349
10350 (defun gnus-summary-tick-above (&optional score)
10351   "Tick all articles with score above SCORE."
10352   (interactive "P")
10353   (gnus-summary-mark-above score gnus-ticked-mark))
10354
10355 (defun gnus-summary-mark-above (score mark)
10356   "Mark articles with score over SCORE with MARK."
10357   (interactive "P\ncMark: ")
10358   (setq score (if score
10359                   (prefix-numeric-value score)
10360                 (or gnus-summary-default-score 0)))
10361   (save-excursion
10362     (set-buffer gnus-summary-buffer)
10363     (goto-char (point-min))
10364     (while (and (progn
10365                   (when (> (gnus-summary-article-score) score)
10366                     (gnus-summary-mark-article nil mark))
10367                   t)
10368                 (gnus-summary-find-next)))))
10369
10370 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10371 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10372 (defun gnus-summary-limit-include-expunged (&optional no-error)
10373   "Display all the hidden articles that were expunged for low scores."
10374   (interactive)
10375   (let ((buffer-read-only nil))
10376     (let ((scored gnus-newsgroup-scored)
10377           headers h)
10378       (while scored
10379         (unless (gnus-summary-article-header (caar scored))
10380           (and (setq h (gnus-number-to-header (caar scored)))
10381                (< (cdar scored) gnus-summary-expunge-below)
10382                (push h headers)))
10383         (setq scored (cdr scored)))
10384       (if (not headers)
10385           (when (not no-error)
10386             (error "No expunged articles hidden"))
10387         (goto-char (point-min))
10388         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10389         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10390         (mapcar (lambda (x) (push (mail-header-number x)
10391                                   gnus-newsgroup-limit))
10392                 headers)
10393         (gnus-summary-prepare-unthreaded (nreverse headers))
10394         (goto-char (point-min))
10395         (gnus-summary-position-point)
10396         t))))
10397
10398 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10399   "Mark all unread articles in this newsgroup as read.
10400 If prefix argument ALL is non-nil, ticked and dormant articles will
10401 also be marked as read.
10402 If QUIETLY is non-nil, no questions will be asked.
10403
10404 If TO-HERE is non-nil, it should be a point in the buffer.  All
10405 articles before (after, if REVERSE is set) this point will be marked
10406 as read.
10407
10408 Note that this function will only catch up the unread article
10409 in the current summary buffer limitation.
10410
10411 The number of articles marked as read is returned."
10412   (interactive "P")
10413   (prog1
10414       (save-excursion
10415         (when (or quietly
10416                   (not gnus-interactive-catchup) ;Without confirmation?
10417                   gnus-expert-user
10418                   (gnus-y-or-n-p
10419                    (if all
10420                        "Mark absolutely all articles as read? "
10421                      "Mark all unread articles as read? ")))
10422           (if (and not-mark
10423                    (not gnus-newsgroup-adaptive)
10424                    (not gnus-newsgroup-auto-expire)
10425                    (not gnus-suppress-duplicates)
10426                    (or (not gnus-use-cache)
10427                        (eq gnus-use-cache 'passive)))
10428               (progn
10429                 (when all
10430                   (setq gnus-newsgroup-marked nil
10431                         gnus-newsgroup-spam-marked nil
10432                         gnus-newsgroup-dormant nil))
10433                 (setq gnus-newsgroup-unreads
10434                       (gnus-sorted-nunion
10435                        (gnus-intersection gnus-newsgroup-unreads
10436                                           gnus-newsgroup-downloadable)
10437                        gnus-newsgroup-unfetched)))
10438             ;; We actually mark all articles as canceled, which we
10439             ;; have to do when using auto-expiry or adaptive scoring.
10440             (gnus-summary-show-all-threads)
10441             (if (and to-here reverse)
10442                 (progn
10443                   (goto-char to-here)
10444                   (gnus-summary-mark-current-read-and-unread-as-read
10445                    gnus-catchup-mark)
10446                   (while (gnus-summary-find-next (not all))
10447                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10448               (when (gnus-summary-first-subject (not all))
10449                 (while (and
10450                         (if to-here (< (point) to-here) t)
10451                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10452                         (gnus-summary-find-next (not all))))))
10453             (gnus-set-mode-line 'summary))
10454           t))
10455     (gnus-summary-position-point)))
10456
10457 (defun gnus-summary-catchup-to-here (&optional all)
10458   "Mark all unticked articles before the current one as read.
10459 If ALL is non-nil, also mark ticked and dormant articles as read."
10460   (interactive "P")
10461   (save-excursion
10462     (gnus-save-hidden-threads
10463       (let ((beg (point)))
10464         ;; We check that there are unread articles.
10465         (when (or all (gnus-summary-find-prev))
10466           (gnus-summary-catchup all t beg)))))
10467   (gnus-summary-position-point))
10468
10469 (defun gnus-summary-catchup-from-here (&optional all)
10470   "Mark all unticked articles after (and including) the current one as read.
10471 If ALL is non-nil, also mark ticked and dormant articles as read."
10472   (interactive "P")
10473   (save-excursion
10474     (gnus-save-hidden-threads
10475       (let ((beg (point)))
10476         ;; We check that there are unread articles.
10477         (when (or all (gnus-summary-find-next))
10478           (gnus-summary-catchup all t beg nil t)))))
10479   (gnus-summary-position-point))
10480
10481 (defun gnus-summary-catchup-all (&optional quietly)
10482   "Mark all articles in this newsgroup as read.
10483 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10484 instead, which marks only unread articles as read."
10485   (interactive "P")
10486   (gnus-summary-catchup t quietly))
10487
10488 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10489   "Mark all unread articles in this group as read, then exit.
10490 If prefix argument ALL is non-nil, all articles are marked as read.
10491 If QUIETLY is non-nil, no questions will be asked."
10492   (interactive "P")
10493   (when (gnus-summary-catchup all quietly nil 'fast)
10494     ;; Select next newsgroup or exit.
10495     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10496              (eq gnus-auto-select-next 'quietly))
10497         (gnus-summary-next-group nil)
10498       (gnus-summary-exit))))
10499
10500 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10501   "Mark all articles in this newsgroup as read, and then exit.
10502 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10503 instead, which marks only unread articles as read."
10504   (interactive "P")
10505   (gnus-summary-catchup-and-exit t quietly))
10506
10507 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10508   "Mark all articles in this group as read and select the next group.
10509 If given a prefix, mark all articles, unread as well as ticked, as
10510 read."
10511   (interactive "P")
10512   (save-excursion
10513     (gnus-summary-catchup all))
10514   (gnus-summary-next-group))
10515
10516 ;;;
10517 ;;; with article
10518 ;;;
10519
10520 (defmacro gnus-with-article (article &rest forms)
10521   "Select ARTICLE and perform FORMS in the original article buffer.
10522 Then replace the article with the result."
10523   `(progn
10524      ;; We don't want the article to be marked as read.
10525      (let (gnus-mark-article-hook)
10526        (gnus-summary-select-article t t nil ,article))
10527      (set-buffer gnus-original-article-buffer)
10528      ,@forms
10529      (if (not (gnus-check-backend-function
10530                'request-replace-article (car gnus-article-current)))
10531          (gnus-message 5 "Read-only group; not replacing")
10532        (unless (gnus-request-replace-article
10533                 ,article (car gnus-article-current)
10534                 (current-buffer) t)
10535          (error "Couldn't replace article")))
10536      ;; The cache and backlog have to be flushed somewhat.
10537      (when gnus-keep-backlog
10538        (gnus-backlog-remove-article
10539         (car gnus-article-current) (cdr gnus-article-current)))
10540      (when gnus-use-cache
10541        (gnus-cache-update-article
10542         (car gnus-article-current) (cdr gnus-article-current)))))
10543
10544 (put 'gnus-with-article 'lisp-indent-function 1)
10545 (put 'gnus-with-article 'edebug-form-spec '(form body))
10546
10547 ;; Thread-based commands.
10548
10549 (defun gnus-summary-articles-in-thread (&optional article)
10550   "Return a list of all articles in the current thread.
10551 If ARTICLE is non-nil, return all articles in the thread that starts
10552 with that article."
10553   (let* ((article (or article (gnus-summary-article-number)))
10554          (data (gnus-data-find-list article))
10555          (top-level (gnus-data-level (car data)))
10556          (top-subject
10557           (cond ((null gnus-thread-operation-ignore-subject)
10558                  (gnus-simplify-subject-re
10559                   (mail-header-subject (gnus-data-header (car data)))))
10560                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10561                  (gnus-simplify-subject-fuzzy
10562                   (mail-header-subject (gnus-data-header (car data)))))
10563                 (t nil)))
10564          (end-point (save-excursion
10565                       (if (gnus-summary-go-to-next-thread)
10566                           (point) (point-max))))
10567          articles)
10568     (while (and data
10569                 (< (gnus-data-pos (car data)) end-point))
10570       (when (or (not top-subject)
10571                 (string= top-subject
10572                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10573                              (gnus-simplify-subject-fuzzy
10574                               (mail-header-subject
10575                                (gnus-data-header (car data))))
10576                            (gnus-simplify-subject-re
10577                             (mail-header-subject
10578                              (gnus-data-header (car data)))))))
10579         (push (gnus-data-number (car data)) articles))
10580       (unless (and (setq data (cdr data))
10581                    (> (gnus-data-level (car data)) top-level))
10582         (setq data nil)))
10583     ;; Return the list of articles.
10584     (nreverse articles)))
10585
10586 (defun gnus-summary-rethread-current ()
10587   "Rethread the thread the current article is part of."
10588   (interactive)
10589   (let* ((gnus-show-threads t)
10590          (article (gnus-summary-article-number))
10591          (id (mail-header-id (gnus-summary-article-header)))
10592          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10593     (unless id
10594       (error "No article on the current line"))
10595     (gnus-rebuild-thread id)
10596     (gnus-summary-goto-subject article)))
10597
10598 (defun gnus-summary-reparent-thread ()
10599   "Make the current article child of the marked (or previous) article.
10600
10601 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10602 is non-nil or the Subject: of both articles are the same."
10603   (interactive)
10604   (unless (not (gnus-group-read-only-p))
10605     (error "The current newsgroup does not support article editing"))
10606   (unless (<= (length gnus-newsgroup-processable) 1)
10607     (error "No more than one article may be marked"))
10608   (save-window-excursion
10609     (let ((gnus-article-buffer " *reparent*")
10610           (current-article (gnus-summary-article-number))
10611           ;; First grab the marked article, otherwise one line up.
10612           (parent-article (if (not (null gnus-newsgroup-processable))
10613                               (car gnus-newsgroup-processable)
10614                             (save-excursion
10615                               (if (eq (forward-line -1) 0)
10616                                   (gnus-summary-article-number)
10617                                 (error "Beginning of summary buffer"))))))
10618       (unless (not (eq current-article parent-article))
10619         (error "An article may not be self-referential"))
10620       (let ((message-id (mail-header-id
10621                          (gnus-summary-article-header parent-article))))
10622         (unless (and message-id (not (equal message-id "")))
10623           (error "No message-id in desired parent"))
10624         (gnus-with-article current-article
10625           (save-restriction
10626             (goto-char (point-min))
10627             (message-narrow-to-head)
10628             (if (re-search-forward "^References: " nil t)
10629                 (progn
10630                   (re-search-forward "^[^ \t]" nil t)
10631                   (forward-line -1)
10632                   (end-of-line)
10633                   (insert " " message-id))
10634               (insert "References: " message-id "\n"))))
10635         (set-buffer gnus-summary-buffer)
10636         (gnus-summary-unmark-all-processable)
10637         (gnus-summary-update-article current-article)
10638         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10639             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10640         (gnus-summary-rethread-current)
10641         (gnus-message 3 "Article %d is now the child of article %d"
10642                       current-article parent-article)))))
10643
10644 (defun gnus-summary-toggle-threads (&optional arg)
10645   "Toggle showing conversation threads.
10646 If ARG is positive number, turn showing conversation threads on."
10647   (interactive "P")
10648   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10649     (setq gnus-show-threads
10650           (if (null arg) (not gnus-show-threads)
10651             (> (prefix-numeric-value arg) 0)))
10652     (gnus-summary-prepare)
10653     (gnus-summary-goto-subject current)
10654     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10655     (gnus-summary-position-point)))
10656
10657 (defun gnus-summary-show-all-threads ()
10658   "Show all threads."
10659   (interactive)
10660   (save-excursion
10661     (let ((buffer-read-only nil))
10662       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10663   (gnus-summary-position-point))
10664
10665 (defun gnus-summary-show-thread ()
10666   "Show thread subtrees.
10667 Returns nil if no thread was there to be shown."
10668   (interactive)
10669   (let ((buffer-read-only nil)
10670         (orig (point))
10671         (end (point-at-eol))
10672         ;; Leave point at bol
10673         (beg (progn (beginning-of-line) (point))))
10674     (prog1
10675         ;; Any hidden lines here?
10676         (search-forward "\r" end t)
10677       (subst-char-in-region beg end ?\^M ?\n t)
10678       (goto-char orig)
10679       (gnus-summary-position-point))))
10680
10681 (defun gnus-summary-maybe-hide-threads ()
10682   "If requested, hide the threads that should be hidden."
10683   (when (and gnus-show-threads
10684              gnus-thread-hide-subtree)
10685     (gnus-summary-hide-all-threads
10686      (if (or (consp gnus-thread-hide-subtree)
10687              (functionp gnus-thread-hide-subtree))
10688          (gnus-make-predicate gnus-thread-hide-subtree)
10689        nil))))
10690
10691 ;;; Hiding predicates.
10692
10693 (defun gnus-article-unread-p (header)
10694   (memq (mail-header-number header) gnus-newsgroup-unreads))
10695
10696 (defun gnus-article-unseen-p (header)
10697   (memq (mail-header-number header) gnus-newsgroup-unseen))
10698
10699 (defun gnus-map-articles (predicate articles)
10700   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10701   (apply 'gnus-or (mapcar predicate
10702                           (mapcar 'gnus-summary-article-header articles))))
10703
10704 (defun gnus-summary-hide-all-threads (&optional predicate)
10705   "Hide all thread subtrees.
10706 If PREDICATE is supplied, threads that satisfy this predicate
10707 will not be hidden."
10708   (interactive)
10709   (save-excursion
10710     (goto-char (point-min))
10711     (let ((end nil))
10712       (while (not end)
10713         (when (or (not predicate)
10714                   (gnus-map-articles
10715                    predicate (gnus-summary-article-children)))
10716             (gnus-summary-hide-thread))
10717         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10718   (gnus-summary-position-point))
10719
10720 (defun gnus-summary-hide-thread ()
10721   "Hide thread subtrees.
10722 If PREDICATE is supplied, threads that satisfy this predicate
10723 will not be hidden.
10724 Returns nil if no threads were there to be hidden."
10725   (interactive)
10726   (let ((buffer-read-only nil)
10727         (start (point))
10728         (article (gnus-summary-article-number)))
10729     (goto-char start)
10730     ;; Go forward until either the buffer ends or the subthread
10731     ;; ends.
10732     (when (and (not (eobp))
10733                (or (zerop (gnus-summary-next-thread 1 t))
10734                    (goto-char (point-max))))
10735       (prog1
10736           (if (and (> (point) start)
10737                    (search-backward "\n" start t))
10738               (progn
10739                 (subst-char-in-region start (point) ?\n ?\^M)
10740                 (gnus-summary-goto-subject article))
10741             (goto-char start)
10742             nil)))))
10743
10744 (defun gnus-summary-go-to-next-thread (&optional previous)
10745   "Go to the same level (or less) next thread.
10746 If PREVIOUS is non-nil, go to previous thread instead.
10747 Return the article number moved to, or nil if moving was impossible."
10748   (let ((level (gnus-summary-thread-level))
10749         (way (if previous -1 1))
10750         (beg (point)))
10751     (forward-line way)
10752     (while (and (not (eobp))
10753                 (< level (gnus-summary-thread-level)))
10754       (forward-line way))
10755     (if (eobp)
10756         (progn
10757           (goto-char beg)
10758           nil)
10759       (setq beg (point))
10760       (prog1
10761           (gnus-summary-article-number)
10762         (goto-char beg)))))
10763
10764 (defun gnus-summary-next-thread (n &optional silent)
10765   "Go to the same level next N'th thread.
10766 If N is negative, search backward instead.
10767 Returns the difference between N and the number of skips actually
10768 done.
10769
10770 If SILENT, don't output messages."
10771   (interactive "p")
10772   (let ((backward (< n 0))
10773         (n (abs n)))
10774     (while (and (> n 0)
10775                 (gnus-summary-go-to-next-thread backward))
10776       (decf n))
10777     (unless silent
10778       (gnus-summary-position-point))
10779     (when (and (not silent) (/= 0 n))
10780       (gnus-message 7 "No more threads"))
10781     n))
10782
10783 (defun gnus-summary-prev-thread (n)
10784   "Go to the same level previous N'th thread.
10785 Returns the difference between N and the number of skips actually
10786 done."
10787   (interactive "p")
10788   (gnus-summary-next-thread (- n)))
10789
10790 (defun gnus-summary-go-down-thread ()
10791   "Go down one level in the current thread."
10792   (let ((children (gnus-summary-article-children)))
10793     (when children
10794       (gnus-summary-goto-subject (car children)))))
10795
10796 (defun gnus-summary-go-up-thread ()
10797   "Go up one level in the current thread."
10798   (let ((parent (gnus-summary-article-parent)))
10799     (when parent
10800       (gnus-summary-goto-subject parent))))
10801
10802 (defun gnus-summary-down-thread (n)
10803   "Go down thread N steps.
10804 If N is negative, go up instead.
10805 Returns the difference between N and how many steps down that were
10806 taken."
10807   (interactive "p")
10808   (let ((up (< n 0))
10809         (n (abs n)))
10810     (while (and (> n 0)
10811                 (if up (gnus-summary-go-up-thread)
10812                   (gnus-summary-go-down-thread)))
10813       (setq n (1- n)))
10814     (gnus-summary-position-point)
10815     (when (/= 0 n)
10816       (gnus-message 7 "Can't go further"))
10817     n))
10818
10819 (defun gnus-summary-up-thread (n)
10820   "Go up thread N steps.
10821 If N is negative, go down instead.
10822 Returns the difference between N and how many steps down that were
10823 taken."
10824   (interactive "p")
10825   (gnus-summary-down-thread (- n)))
10826
10827 (defun gnus-summary-top-thread ()
10828   "Go to the top of the thread."
10829   (interactive)
10830   (while (gnus-summary-go-up-thread))
10831   (gnus-summary-article-number))
10832
10833 (defun gnus-summary-kill-thread (&optional unmark)
10834   "Mark articles under current thread as read.
10835 If the prefix argument is positive, remove any kinds of marks.
10836 If the prefix argument is negative, tick articles instead."
10837   (interactive "P")
10838   (when unmark
10839     (setq unmark (prefix-numeric-value unmark)))
10840   (let ((articles (gnus-summary-articles-in-thread)))
10841     (save-excursion
10842       ;; Expand the thread.
10843       (gnus-summary-show-thread)
10844       ;; Mark all the articles.
10845       (while articles
10846         (gnus-summary-goto-subject (car articles))
10847         (cond ((null unmark)
10848                (gnus-summary-mark-article-as-read gnus-killed-mark))
10849               ((> unmark 0)
10850                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10851               (t
10852                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10853         (setq articles (cdr articles))))
10854     ;; Hide killed subtrees.
10855     (and (null unmark)
10856          gnus-thread-hide-killed
10857          (gnus-summary-hide-thread))
10858     ;; If marked as read, go to next unread subject.
10859     (when (null unmark)
10860       ;; Go to next unread subject.
10861       (gnus-summary-next-subject 1 t)))
10862   (gnus-set-mode-line 'summary))
10863
10864 ;; Summary sorting commands
10865
10866 (defun gnus-summary-sort-by-number (&optional reverse)
10867   "Sort the summary buffer by article number.
10868 Argument REVERSE means reverse order."
10869   (interactive "P")
10870   (gnus-summary-sort 'number reverse))
10871
10872 (defun gnus-summary-sort-by-random (&optional reverse)
10873   "Randomize the order in the summary buffer.
10874 Argument REVERSE means to randomize in reverse order."
10875   (interactive "P")
10876   (gnus-summary-sort 'random reverse))
10877
10878 (defun gnus-summary-sort-by-author (&optional reverse)
10879   "Sort the summary buffer by author name alphabetically.
10880 If `case-fold-search' is non-nil, case of letters is ignored.
10881 Argument REVERSE means reverse order."
10882   (interactive "P")
10883   (gnus-summary-sort 'author reverse))
10884
10885 (defun gnus-summary-sort-by-recipient (&optional reverse)
10886   "Sort the summary buffer by recipient name alphabetically.
10887 If `case-fold-search' is non-nil, case of letters is ignored.
10888 Argument REVERSE means reverse order."
10889   (interactive "P")
10890   (gnus-summary-sort 'recipient reverse))
10891
10892 (defun gnus-summary-sort-by-subject (&optional reverse)
10893   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10894 If `case-fold-search' is non-nil, case of letters is ignored.
10895 Argument REVERSE means reverse order."
10896   (interactive "P")
10897   (gnus-summary-sort 'subject reverse))
10898
10899 (defun gnus-summary-sort-by-date (&optional reverse)
10900   "Sort the summary buffer by date.
10901 Argument REVERSE means reverse order."
10902   (interactive "P")
10903   (gnus-summary-sort 'date reverse))
10904
10905 (defun gnus-summary-sort-by-score (&optional reverse)
10906   "Sort the summary buffer by score.
10907 Argument REVERSE means reverse order."
10908   (interactive "P")
10909   (gnus-summary-sort 'score reverse))
10910
10911 (defun gnus-summary-sort-by-lines (&optional reverse)
10912   "Sort the summary buffer by the number of lines.
10913 Argument REVERSE means reverse order."
10914   (interactive "P")
10915   (gnus-summary-sort 'lines reverse))
10916
10917 (defun gnus-summary-sort-by-chars (&optional reverse)
10918   "Sort the summary buffer by article length.
10919 Argument REVERSE means reverse order."
10920   (interactive "P")
10921   (gnus-summary-sort 'chars reverse))
10922
10923 (defun gnus-summary-sort-by-original (&optional reverse)
10924   "Sort the summary buffer using the default sorting method.
10925 Argument REVERSE means reverse order."
10926   (interactive "P")
10927   (let* ((buffer-read-only)
10928          (gnus-summary-prepare-hook nil))
10929     ;; We do the sorting by regenerating the threads.
10930     (gnus-summary-prepare)
10931     ;; Hide subthreads if needed.
10932     (gnus-summary-maybe-hide-threads)))
10933
10934 (defun gnus-summary-sort (predicate reverse)
10935   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10936   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10937          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10938          (gnus-thread-sort-functions
10939           (if (not reverse)
10940               thread
10941             `(lambda (t1 t2)
10942                (,thread t2 t1))))
10943          (gnus-sort-gathered-threads-function
10944           gnus-thread-sort-functions)
10945          (gnus-article-sort-functions
10946           (if (not reverse)
10947               article
10948             `(lambda (t1 t2)
10949                (,article t2 t1))))
10950          (buffer-read-only)
10951          (gnus-summary-prepare-hook nil))
10952     ;; We do the sorting by regenerating the threads.
10953     (gnus-summary-prepare)
10954     ;; Hide subthreads if needed.
10955     (gnus-summary-maybe-hide-threads)))
10956
10957 ;; Summary saving commands.
10958
10959 (defun gnus-summary-save-article (&optional n not-saved)
10960   "Save the current article using the default saver function.
10961 If N is a positive number, save the N next articles.
10962 If N is a negative number, save the N previous articles.
10963 If N is nil and any articles have been marked with the process mark,
10964 save those articles instead.
10965 The variable `gnus-default-article-saver' specifies the saver function."
10966   (interactive "P")
10967   (let* ((articles (gnus-summary-work-articles n))
10968          (save-buffer (save-excursion
10969                         (nnheader-set-temp-buffer " *Gnus Save*")))
10970          (num (length articles))
10971          header file)
10972     (dolist (article articles)
10973       (setq header (gnus-summary-article-header article))
10974       (if (not (vectorp header))
10975           ;; This is a pseudo-article.
10976           (if (assq 'name header)
10977               (gnus-copy-file (cdr (assq 'name header)))
10978             (gnus-message 1 "Article %d is unsaveable" article))
10979         ;; This is a real article.
10980         (save-window-excursion
10981           (let ((gnus-display-mime-function nil)
10982                 (gnus-article-prepare-hook nil))
10983             (gnus-summary-select-article t nil nil article)))
10984         (save-excursion
10985           (set-buffer save-buffer)
10986           (erase-buffer)
10987           (insert-buffer-substring gnus-original-article-buffer))
10988         (setq file (gnus-article-save save-buffer file num))
10989         (gnus-summary-remove-process-mark article)
10990         (unless not-saved
10991           (gnus-summary-set-saved-mark article))))
10992     (gnus-kill-buffer save-buffer)
10993     (gnus-summary-position-point)
10994     (gnus-set-mode-line 'summary)
10995     n))
10996
10997 (defun gnus-summary-pipe-output (&optional arg headers)
10998   "Pipe the current article to a subprocess.
10999 If N is a positive number, pipe the N next articles.
11000 If N is a negative number, pipe the N previous articles.
11001 If N is nil and any articles have been marked with the process mark,
11002 pipe those articles instead.
11003 If HEADERS (the symbolic prefix), include the headers, too."
11004   (interactive (gnus-interactive "P\ny"))
11005   (require 'gnus-art)
11006   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11007         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11008     (gnus-summary-save-article arg t))
11009   (let ((buffer (get-buffer "*Shell Command Output*")))
11010     (when (and buffer
11011                (not (zerop (buffer-size buffer))))
11012       (gnus-configure-windows 'pipe))))
11013
11014 (defun gnus-summary-save-article-mail (&optional arg)
11015   "Append the current article to an mail file.
11016 If N is a positive number, save the N next articles.
11017 If N is a negative number, save the N previous articles.
11018 If N is nil and any articles have been marked with the process mark,
11019 save those articles instead."
11020   (interactive "P")
11021   (require 'gnus-art)
11022   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11023     (gnus-summary-save-article arg)))
11024
11025 (defun gnus-summary-save-article-rmail (&optional arg)
11026   "Append the current article to an rmail file.
11027 If N is a positive number, save the N next articles.
11028 If N is a negative number, save the N previous articles.
11029 If N is nil and any articles have been marked with the process mark,
11030 save those articles instead."
11031   (interactive "P")
11032   (require 'gnus-art)
11033   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11034     (gnus-summary-save-article arg)))
11035
11036 (defun gnus-summary-save-article-file (&optional arg)
11037   "Append the current article to a file.
11038 If N is a positive number, save the N next articles.
11039 If N is a negative number, save the N previous articles.
11040 If N is nil and any articles have been marked with the process mark,
11041 save those articles instead."
11042   (interactive "P")
11043   (require 'gnus-art)
11044   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11045     (gnus-summary-save-article arg)))
11046
11047 (defun gnus-summary-write-article-file (&optional arg)
11048   "Write the current article to a file, deleting the previous file.
11049 If N is a positive number, save the N next articles.
11050 If N is a negative number, save the N previous articles.
11051 If N is nil and any articles have been marked with the process mark,
11052 save those articles instead."
11053   (interactive "P")
11054   (require 'gnus-art)
11055   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11056     (gnus-summary-save-article arg)))
11057
11058 (defun gnus-summary-save-article-body-file (&optional arg)
11059   "Append the current article body to a file.
11060 If N is a positive number, save the N next articles.
11061 If N is a negative number, save the N previous articles.
11062 If N is nil and any articles have been marked with the process mark,
11063 save those articles instead."
11064   (interactive "P")
11065   (require 'gnus-art)
11066   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11067     (gnus-summary-save-article arg)))
11068
11069 (defun gnus-summary-muttprint (&optional arg)
11070   "Print the current article using Muttprint.
11071 If N is a positive number, save the N next articles.
11072 If N is a negative number, save the N previous articles.
11073 If N is nil and any articles have been marked with the process mark,
11074 save those articles instead."
11075   (interactive "P")
11076   (require 'gnus-art)
11077   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11078     (gnus-summary-save-article arg t)))
11079
11080 (defun gnus-summary-pipe-message (program)
11081   "Pipe the current article through PROGRAM."
11082   (interactive "sProgram: ")
11083   (gnus-summary-select-article)
11084   (let ((mail-header-separator ""))
11085     (gnus-eval-in-buffer-window gnus-article-buffer
11086       (save-restriction
11087         (widen)
11088         (let ((start (window-start))
11089               buffer-read-only)
11090           (message-pipe-buffer-body program)
11091           (set-window-start (get-buffer-window (current-buffer)) start))))))
11092
11093 (defun gnus-get-split-value (methods)
11094   "Return a value based on the split METHODS."
11095   (let (split-name method result match)
11096     (when methods
11097       (save-excursion
11098         (set-buffer gnus-original-article-buffer)
11099         (save-restriction
11100           (nnheader-narrow-to-headers)
11101           (while (and methods (not split-name))
11102             (goto-char (point-min))
11103             (setq method (pop methods))
11104             (setq match (car method))
11105             (when (cond
11106                    ((stringp match)
11107                     ;; Regular expression.
11108                     (ignore-errors
11109                       (re-search-forward match nil t)))
11110                    ((functionp match)
11111                     ;; Function.
11112                     (save-restriction
11113                       (widen)
11114                       (setq result (funcall match gnus-newsgroup-name))))
11115                    ((consp match)
11116                     ;; Form.
11117                     (save-restriction
11118                       (widen)
11119                       (setq result (eval match)))))
11120               (setq split-name (cdr method))
11121               (cond ((stringp result)
11122                      (push (expand-file-name
11123                             result gnus-article-save-directory)
11124                            split-name))
11125                     ((consp result)
11126                      (setq split-name (append result split-name)))))))))
11127     (nreverse split-name)))
11128
11129 (defun gnus-valid-move-group-p (group)
11130   (and (boundp group)
11131        (symbol-name group)
11132        (symbol-value group)
11133        (gnus-get-function (gnus-find-method-for-group
11134                            (symbol-name group)) 'request-accept-article t)))
11135
11136 (defun gnus-read-move-group-name (prompt default articles prefix)
11137   "Read a group name."
11138   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11139          (minibuffer-confirm-incomplete nil) ; XEmacs
11140          (prom
11141           (format "%s %s to:"
11142                   prompt
11143                   (if (> (length articles) 1)
11144                       (format "these %d articles" (length articles))
11145                     "this article")))
11146          (to-newsgroup
11147           (cond
11148            ((null split-name)
11149             (gnus-completing-read-with-default
11150              default prom
11151              gnus-active-hashtb
11152              'gnus-valid-move-group-p
11153              nil prefix
11154              'gnus-group-history))
11155            ((= 1 (length split-name))
11156             (gnus-completing-read-with-default
11157              (car split-name) prom
11158              gnus-active-hashtb
11159              'gnus-valid-move-group-p
11160              nil nil
11161              'gnus-group-history))
11162            (t
11163             (gnus-completing-read-with-default
11164              nil prom
11165              (mapcar 'list (nreverse split-name))
11166              nil nil nil
11167              'gnus-group-history))))
11168          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11169     (when to-newsgroup
11170       (if (or (string= to-newsgroup "")
11171               (string= to-newsgroup prefix))
11172           (setq to-newsgroup default))
11173       (unless to-newsgroup
11174         (error "No group name entered"))
11175       (or (gnus-active to-newsgroup)
11176           (gnus-activate-group to-newsgroup nil nil to-method)
11177           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11178                                      to-newsgroup))
11179               (or (and (gnus-request-create-group to-newsgroup to-method)
11180                        (gnus-activate-group
11181                         to-newsgroup nil nil to-method)
11182                        (gnus-subscribe-group to-newsgroup))
11183                   (error "Couldn't create group %s" to-newsgroup)))
11184           (error "No such group: %s" to-newsgroup)))
11185     to-newsgroup))
11186
11187 (defun gnus-summary-save-parts (type dir n &optional reverse)
11188   "Save parts matching TYPE to DIR.
11189 If REVERSE, save parts that do not match TYPE."
11190   (interactive
11191    (list (read-string "Save parts of type: "
11192                       (or (car gnus-summary-save-parts-type-history)
11193                           gnus-summary-save-parts-default-mime)
11194                       'gnus-summary-save-parts-type-history)
11195          (setq gnus-summary-save-parts-last-directory
11196                (read-file-name "Save to directory: "
11197                                gnus-summary-save-parts-last-directory
11198                                nil t))
11199          current-prefix-arg))
11200   (gnus-summary-iterate n
11201     (let ((gnus-display-mime-function nil)
11202           (gnus-inhibit-treatment t))
11203       (gnus-summary-select-article))
11204     (save-excursion
11205       (set-buffer gnus-article-buffer)
11206       (let ((handles (or gnus-article-mime-handles
11207                          (mm-dissect-buffer nil gnus-article-loose-mime)
11208                          (and gnus-article-emulate-mime
11209                               (mm-uu-dissect)))))
11210         (when handles
11211           (gnus-summary-save-parts-1 type dir handles reverse)
11212           (unless gnus-article-mime-handles ;; Don't destroy this case.
11213             (mm-destroy-parts handles)))))))
11214
11215 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11216   (if (stringp (car handle))
11217       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11218               (cdr handle))
11219     (when (if reverse
11220               (not (string-match type (mm-handle-media-type handle)))
11221             (string-match type (mm-handle-media-type handle)))
11222       (let ((file (expand-file-name
11223                    (gnus-map-function
11224                     mm-file-name-rewrite-functions
11225                     (file-name-nondirectory
11226                      (or
11227                       (mail-content-type-get
11228                        (mm-handle-disposition handle) 'filename)
11229                       (mail-content-type-get
11230                        (mm-handle-type handle) 'name)
11231                       (concat gnus-newsgroup-name
11232                               "." (number-to-string
11233                                    (cdr gnus-article-current))))))
11234                    dir)))
11235         (unless (file-exists-p file)
11236           (mm-save-part-to-file handle file))))))
11237
11238 ;; Summary extract commands
11239
11240 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11241   (let ((buffer-read-only nil)
11242         (article (gnus-summary-article-number))
11243         after-article b e)
11244     (unless (gnus-summary-goto-subject article)
11245       (error "No such article: %d" article))
11246     (gnus-summary-position-point)
11247     ;; If all commands are to be bunched up on one line, we collect
11248     ;; them here.
11249     (unless gnus-view-pseudos-separately
11250       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11251             files action)
11252         (while ps
11253           (setq action (cdr (assq 'action (car ps))))
11254           (setq files (list (cdr (assq 'name (car ps)))))
11255           (while (and ps (cdr ps)
11256                       (string= (or action "1")
11257                                (or (cdr (assq 'action (cadr ps))) "2")))
11258             (push (cdr (assq 'name (cadr ps))) files)
11259             (setcdr ps (cddr ps)))
11260           (when files
11261             (when (not (string-match "%s" action))
11262               (push " " files))
11263             (push " " files)
11264             (when (assq 'execute (car ps))
11265               (setcdr (assq 'execute (car ps))
11266                       (funcall (if (string-match "%s" action)
11267                                    'format 'concat)
11268                                action
11269                                (mapconcat
11270                                 (lambda (f)
11271                                   (if (equal f " ")
11272                                       f
11273                                     (shell-quote-argument f)))
11274                                 files " ")))))
11275           (setq ps (cdr ps)))))
11276     (if (and gnus-view-pseudos (not not-view))
11277         (while pslist
11278           (when (assq 'execute (car pslist))
11279             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11280                                   (eq gnus-view-pseudos 'not-confirm)))
11281           (setq pslist (cdr pslist)))
11282       (save-excursion
11283         (while pslist
11284           (setq after-article (or (cdr (assq 'article (car pslist)))
11285                                   (gnus-summary-article-number)))
11286           (gnus-summary-goto-subject after-article)
11287           (forward-line 1)
11288           (setq b (point))
11289           (insert "    " (file-name-nondirectory
11290                           (cdr (assq 'name (car pslist))))
11291                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11292           (setq e (point))
11293           (forward-line -1)             ; back to `b'
11294           (gnus-add-text-properties
11295            b (1- e) (list 'gnus-number gnus-reffed-article-number
11296                           gnus-mouse-face-prop gnus-mouse-face))
11297           (gnus-data-enter
11298            after-article gnus-reffed-article-number
11299            gnus-unread-mark b (car pslist) 0 (- e b))
11300           (setq gnus-newsgroup-unreads
11301                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11302                                          gnus-reffed-article-number))
11303           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11304           (setq pslist (cdr pslist)))))))
11305
11306 (defun gnus-pseudos< (p1 p2)
11307   (let ((c1 (cdr (assq 'action p1)))
11308         (c2 (cdr (assq 'action p2))))
11309     (and c1 c2 (string< c1 c2))))
11310
11311 (defun gnus-request-pseudo-article (props)
11312   (cond ((assq 'execute props)
11313          (gnus-execute-command (cdr (assq 'execute props)))))
11314   (let ((gnus-current-article (gnus-summary-article-number)))
11315     (gnus-run-hooks 'gnus-mark-article-hook)))
11316
11317 (defun gnus-execute-command (command &optional automatic)
11318   (save-excursion
11319     (gnus-article-setup-buffer)
11320     (set-buffer gnus-article-buffer)
11321     (setq buffer-read-only nil)
11322     (let ((command (if automatic command
11323                      (read-string "Command: " (cons command 0)))))
11324       (erase-buffer)
11325       (insert "$ " command "\n\n")
11326       (if gnus-view-pseudo-asynchronously
11327           (start-process "gnus-execute" (current-buffer) shell-file-name
11328                          shell-command-switch command)
11329         (call-process shell-file-name nil t nil
11330                       shell-command-switch command)))))
11331
11332 ;; Summary kill commands.
11333
11334 (defun gnus-summary-edit-global-kill (article)
11335   "Edit the \"global\" kill file."
11336   (interactive (list (gnus-summary-article-number)))
11337   (gnus-group-edit-global-kill article))
11338
11339 (defun gnus-summary-edit-local-kill ()
11340   "Edit a local kill file applied to the current newsgroup."
11341   (interactive)
11342   (setq gnus-current-headers (gnus-summary-article-header))
11343   (gnus-group-edit-local-kill
11344    (gnus-summary-article-number) gnus-newsgroup-name))
11345
11346 ;;; Header reading.
11347
11348 (defun gnus-read-header (id &optional header)
11349   "Read the headers of article ID and enter them into the Gnus system."
11350   (let ((group gnus-newsgroup-name)
11351         (gnus-override-method
11352          (or
11353           gnus-override-method
11354           (and (gnus-news-group-p gnus-newsgroup-name)
11355                (car (gnus-refer-article-methods)))))
11356         where)
11357     ;; First we check to see whether the header in question is already
11358     ;; fetched.
11359     (if (stringp id)
11360         ;; This is a Message-ID.
11361         (setq header (or header (gnus-id-to-header id)))
11362       ;; This is an article number.
11363       (setq header (or header (gnus-summary-article-header id))))
11364     (if (and header
11365              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11366         ;; We have found the header.
11367         header
11368       ;; We have to really fetch the header to this article.
11369       (save-excursion
11370         (set-buffer nntp-server-buffer)
11371         (when (setq where (gnus-request-head id group))
11372           (nnheader-fold-continuation-lines)
11373           (goto-char (point-max))
11374           (insert ".\n")
11375           (goto-char (point-min))
11376           (insert "211 ")
11377           (princ (cond
11378                   ((numberp id) id)
11379                   ((cdr where) (cdr where))
11380                   (header (mail-header-number header))
11381                   (t gnus-reffed-article-number))
11382                  (current-buffer))
11383           (insert " Article retrieved.\n"))
11384         (if (or (not where)
11385                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11386             ()                          ; Malformed head.
11387           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11388             (when (and (stringp id)
11389                        (not (string= (gnus-group-real-name group)
11390                                      (car where))))
11391               ;; If we fetched by Message-ID and the article came
11392               ;; from a different group, we fudge some bogus article
11393               ;; numbers for this article.
11394               (mail-header-set-number header gnus-reffed-article-number))
11395             (save-excursion
11396               (set-buffer gnus-summary-buffer)
11397               (decf gnus-reffed-article-number)
11398               (gnus-remove-header (mail-header-number header))
11399               (push header gnus-newsgroup-headers)
11400               (setq gnus-current-headers header)
11401               (push (mail-header-number header) gnus-newsgroup-limit)))
11402           header)))))
11403
11404 (defun gnus-remove-header (number)
11405   "Remove header NUMBER from `gnus-newsgroup-headers'."
11406   (if (and gnus-newsgroup-headers
11407            (= number (mail-header-number (car gnus-newsgroup-headers))))
11408       (pop gnus-newsgroup-headers)
11409     (let ((headers gnus-newsgroup-headers))
11410       (while (and (cdr headers)
11411                   (not (= number (mail-header-number (cadr headers)))))
11412         (pop headers))
11413       (when (cdr headers)
11414         (setcdr headers (cddr headers))))))
11415
11416 ;;;
11417 ;;; summary highlights
11418 ;;;
11419
11420 (defun gnus-highlight-selected-summary ()
11421   "Highlight selected article in summary buffer."
11422   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11423   (when gnus-summary-selected-face
11424     (save-excursion
11425       (let* ((beg (point-at-bol))
11426              (end (point-at-eol))
11427              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11428              (from (if (get-text-property beg gnus-mouse-face-prop)
11429                        beg
11430                      (or (next-single-property-change
11431                           beg gnus-mouse-face-prop nil end)
11432                          beg)))
11433              (to
11434               (if (= from end)
11435                   (- from 2)
11436                 (or (next-single-property-change
11437                      from gnus-mouse-face-prop nil end)
11438                     end))))
11439         ;; If no mouse-face prop on line we will have to = from = end,
11440         ;; so we highlight the entire line instead.
11441         (when (= (+ to 2) from)
11442           (setq from beg)
11443           (setq to end))
11444         (if gnus-newsgroup-selected-overlay
11445             ;; Move old overlay.
11446             (gnus-move-overlay
11447              gnus-newsgroup-selected-overlay from to (current-buffer))
11448           ;; Create new overlay.
11449           (gnus-overlay-put
11450            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11451            'face gnus-summary-selected-face))))))
11452
11453 (defvar gnus-summary-highlight-line-cached nil)
11454 (defvar gnus-summary-highlight-line-trigger nil)
11455
11456 (defun gnus-summary-highlight-line-0 ()
11457   (if (and (eq gnus-summary-highlight-line-trigger
11458                gnus-summary-highlight)
11459            gnus-summary-highlight-line-cached)
11460       gnus-summary-highlight-line-cached
11461     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11462           gnus-summary-highlight-line-cached
11463           (let* ((cond (list 'cond))
11464                  (c cond)
11465                  (list gnus-summary-highlight))
11466             (while list
11467               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11468                               nil))
11469               (setq c (cdr c)
11470                     list (cdr list)))
11471             (gnus-byte-compile (list 'lambda nil cond))))))
11472
11473 (defun gnus-summary-highlight-line ()
11474   "Highlight current line according to `gnus-summary-highlight'."
11475   (let* ((beg (point-at-bol))
11476          (article (or (gnus-summary-article-number) gnus-current-article))
11477          (score (or (cdr (assq article
11478                                gnus-newsgroup-scored))
11479                     gnus-summary-default-score 0))
11480          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11481          (inhibit-read-only t)
11482          (default gnus-summary-default-score)
11483          (default-high gnus-summary-default-high-score)
11484          (default-low gnus-summary-default-low-score)
11485          (uncached (and gnus-summary-use-undownloaded-faces
11486                         (memq article gnus-newsgroup-undownloaded)
11487                         (not (memq article gnus-newsgroup-cached)))))
11488     (let ((face (funcall (gnus-summary-highlight-line-0))))
11489       (unless (eq face (get-text-property beg 'face))
11490         (gnus-put-text-property-excluding-characters-with-faces
11491          beg (point-at-eol) 'face
11492          (setq face (if (boundp face) (symbol-value face) face)))
11493         (when gnus-summary-highlight-line-function
11494           (funcall gnus-summary-highlight-line-function article face))))))
11495
11496 (defun gnus-update-read-articles (group unread &optional compute)
11497   "Update the list of read articles in GROUP.
11498 UNREAD is a sorted list."
11499   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11500         (info (gnus-get-info group))
11501         (prev 1)
11502         read)
11503     (if (or (not info) (not active))
11504         ;; There is no info on this group if it was, in fact,
11505         ;; killed.  Gnus stores no information on killed groups, so
11506         ;; there's nothing to be done.
11507         ;; One could store the information somewhere temporarily,
11508         ;; perhaps...  Hmmm...
11509         ()
11510       ;; Remove any negative articles numbers.
11511       (while (and unread (< (car unread) 0))
11512         (setq unread (cdr unread)))
11513       ;; Remove any expired article numbers
11514       (while (and unread (< (car unread) (car active)))
11515         (setq unread (cdr unread)))
11516       ;; Compute the ranges of read articles by looking at the list of
11517       ;; unread articles.
11518       (while unread
11519         (when (/= (car unread) prev)
11520           (push (if (= prev (1- (car unread))) prev
11521                   (cons prev (1- (car unread))))
11522                 read))
11523         (setq prev (1+ (car unread)))
11524         (setq unread (cdr unread)))
11525       (when (<= prev (cdr active))
11526         (push (cons prev (cdr active)) read))
11527       (setq read (if (> (length read) 1) (nreverse read) read))
11528       (if compute
11529           read
11530         (save-excursion
11531           (let (setmarkundo)
11532             ;; Propagate the read marks to the backend.
11533             (when (gnus-check-backend-function 'request-set-mark group)
11534               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11535                     (add (gnus-remove-from-range read (gnus-info-read info))))
11536                 (when (or add del)
11537                   (unless (gnus-check-group group)
11538                     (error "Can't open server for %s" group))
11539                   (gnus-request-set-mark
11540                    group (delq nil (list (if add (list add 'add '(read)))
11541                                          (if del (list del 'del '(read))))))
11542                   (setq setmarkundo
11543                         `(gnus-request-set-mark
11544                           ,group
11545                           ',(delq nil (list
11546                                        (if del (list del 'add '(read)))
11547                                        (if add (list add 'del '(read))))))))))
11548             (set-buffer gnus-group-buffer)
11549             (gnus-undo-register
11550               `(progn
11551                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11552                  (gnus-info-set-read ',info ',(gnus-info-read info))
11553                  (gnus-get-unread-articles-in-group ',info
11554                                                     (gnus-active ,group))
11555                  (gnus-group-update-group ,group t)
11556                  ,setmarkundo))))
11557         ;; Enter this list into the group info.
11558         (gnus-info-set-read info read)
11559         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11560         (gnus-get-unread-articles-in-group info (gnus-active group))
11561         t))))
11562
11563 (defun gnus-offer-save-summaries ()
11564   "Offer to save all active summary buffers."
11565   (let (buffers)
11566     ;; Go through all buffers and find all summaries.
11567     (dolist (buffer (buffer-list))
11568       (when (and (setq buffer (buffer-name buffer))
11569                  (string-match "Summary" buffer)
11570                  (with-current-buffer buffer
11571                    ;; We check that this is, indeed, a summary buffer.
11572                    (and (eq major-mode 'gnus-summary-mode)
11573                         ;; Also make sure this isn't bogus.
11574                         gnus-newsgroup-prepared
11575                         ;; Also make sure that this isn't a
11576                         ;; dead summary buffer.
11577                         (not gnus-dead-summary-mode))))
11578         (push buffer buffers)))
11579     ;; Go through all these summary buffers and offer to save them.
11580     (when buffers
11581       (save-excursion
11582         (map-y-or-n-p
11583          "Update summary buffer %s? "
11584          (lambda (buf)
11585            (switch-to-buffer buf)
11586            (gnus-summary-exit))
11587          buffers)))))
11588
11589 (defun gnus-summary-setup-default-charset ()
11590   "Setup newsgroup default charset."
11591   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11592       (setq gnus-newsgroup-charset nil)
11593     (let* ((ignored-charsets
11594             (or gnus-newsgroup-ephemeral-ignored-charsets
11595                 (append
11596                  (and gnus-newsgroup-name
11597                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11598                  gnus-newsgroup-ignored-charsets))))
11599       (setq gnus-newsgroup-charset
11600             (or gnus-newsgroup-ephemeral-charset
11601                 (and gnus-newsgroup-name
11602                      (gnus-parameter-charset gnus-newsgroup-name))
11603                 gnus-default-charset))
11604       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11605            ignored-charsets))))
11606
11607 ;;;
11608 ;;; Mime Commands
11609 ;;;
11610
11611 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11612   "Display the current article buffer fully MIME-buttonized.
11613 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11614 treated as multipart/mixed."
11615   (interactive "P")
11616   (require 'gnus-art)
11617   (let ((gnus-unbuttonized-mime-types nil)
11618         (gnus-mime-display-multipart-as-mixed show-all-parts))
11619     (gnus-summary-show-article)))
11620
11621 (defun gnus-summary-repair-multipart (article)
11622   "Add a Content-Type header to a multipart article without one."
11623   (interactive (list (gnus-summary-article-number)))
11624   (gnus-with-article article
11625     (message-narrow-to-head)
11626     (message-remove-header "Mime-Version")
11627     (goto-char (point-max))
11628     (insert "Mime-Version: 1.0\n")
11629     (widen)
11630     (when (search-forward "\n--" nil t)
11631       (let ((separator (buffer-substring (point) (point-at-eol))))
11632         (message-narrow-to-head)
11633         (message-remove-header "Content-Type")
11634         (goto-char (point-max))
11635         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11636                         separator))
11637         (widen))))
11638   (let (gnus-mark-article-hook)
11639     (gnus-summary-select-article t t nil article)))
11640
11641 (defun gnus-summary-toggle-display-buttonized ()
11642   "Toggle the buttonizing of the article buffer."
11643   (interactive)
11644   (require 'gnus-art)
11645   (if (setq gnus-inhibit-mime-unbuttonizing
11646             (not gnus-inhibit-mime-unbuttonizing))
11647       (let ((gnus-unbuttonized-mime-types nil))
11648         (gnus-summary-show-article))
11649     (gnus-summary-show-article)))
11650
11651 ;;;
11652 ;;; Generic summary marking commands
11653 ;;;
11654
11655 (defvar gnus-summary-marking-alist
11656   '((read gnus-del-mark "d")
11657     (unread gnus-unread-mark "u")
11658     (ticked gnus-ticked-mark "!")
11659     (dormant gnus-dormant-mark "?")
11660     (expirable gnus-expirable-mark "e"))
11661   "An alist of names/marks/keystrokes.")
11662
11663 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11664 (defvar gnus-summary-mark-map)
11665
11666 (defun gnus-summary-make-all-marking-commands ()
11667   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11668   (dolist (elem gnus-summary-marking-alist)
11669     (apply 'gnus-summary-make-marking-command elem)))
11670
11671 (defun gnus-summary-make-marking-command (name mark keystroke)
11672   (let ((map (make-sparse-keymap)))
11673     (define-key gnus-summary-generic-mark-map keystroke map)
11674     (dolist (lway `((next "next" next nil "n")
11675                     (next-unread "next unread" next t "N")
11676                     (prev "previous" prev nil "p")
11677                     (prev-unread "previous unread" prev t "P")
11678                     (nomove "" nil nil ,keystroke)))
11679       (let ((func (gnus-summary-make-marking-command-1
11680                    mark (car lway) lway name)))
11681         (setq func (eval func))
11682         (define-key map (nth 4 lway) func)))))
11683
11684 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11685   `(defun ,(intern
11686             (format "gnus-summary-put-mark-as-%s%s"
11687                     name (if (eq way 'nomove)
11688                              ""
11689                            (concat "-" (symbol-name way)))))
11690      (n)
11691      ,(format
11692        "Mark the current article as %s%s.
11693 If N, the prefix, then repeat N times.
11694 If N is negative, move in reverse order.
11695 The difference between N and the actual number of articles marked is
11696 returned."
11697        name (cadr lway))
11698      (interactive "p")
11699      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11700
11701 (defun gnus-summary-generic-mark (n mark move unread)
11702   "Mark N articles with MARK."
11703   (unless (eq major-mode 'gnus-summary-mode)
11704     (error "This command can only be used in the summary buffer"))
11705   (gnus-summary-show-thread)
11706   (let ((nummove
11707          (cond
11708           ((eq move 'next) 1)
11709           ((eq move 'prev) -1)
11710           (t 0))))
11711     (if (zerop nummove)
11712         (setq n 1)
11713       (when (< n 0)
11714         (setq n (abs n)
11715               nummove (* -1 nummove))))
11716     (while (and (> n 0)
11717                 (gnus-summary-mark-article nil mark)
11718                 (zerop (gnus-summary-next-subject nummove unread t)))
11719       (setq n (1- n)))
11720     (when (/= 0 n)
11721       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11722     (gnus-summary-recenter)
11723     (gnus-summary-position-point)
11724     (gnus-set-mode-line 'summary)
11725     n))
11726
11727 (defun gnus-summary-insert-articles (articles)
11728   (when (setq articles
11729               (gnus-sorted-difference articles
11730                                       (mapcar (lambda (h)
11731                                                 (mail-header-number h))
11732                                               gnus-newsgroup-headers)))
11733     (setq gnus-newsgroup-headers
11734           (gnus-merge 'list
11735                       gnus-newsgroup-headers
11736                       (gnus-fetch-headers articles)
11737                       'gnus-article-sort-by-number))
11738     ;; Suppress duplicates?
11739     (when gnus-suppress-duplicates
11740       (gnus-dup-suppress-articles))
11741
11742     ;; We might want to build some more threads first.
11743     (when (and gnus-fetch-old-headers
11744                (eq gnus-headers-retrieved-by 'nov))
11745       (if (eq gnus-fetch-old-headers 'invisible)
11746           (gnus-build-all-threads)
11747         (gnus-build-old-threads)))
11748     ;; Let the Gnus agent mark articles as read.
11749     (when gnus-agent
11750       (gnus-agent-get-undownloaded-list))
11751     ;; Remove list identifiers from subject
11752     (when gnus-list-identifiers
11753       (gnus-summary-remove-list-identifiers))
11754     ;; First and last article in this newsgroup.
11755     (when gnus-newsgroup-headers
11756       (setq gnus-newsgroup-begin
11757             (mail-header-number (car gnus-newsgroup-headers))
11758             gnus-newsgroup-end
11759             (mail-header-number
11760              (gnus-last-element gnus-newsgroup-headers))))
11761     (when gnus-use-scoring
11762       (gnus-possibly-score-headers))))
11763
11764 (defun gnus-summary-insert-old-articles (&optional all)
11765   "Insert all old articles in this group.
11766 If ALL is non-nil, already read articles become readable.
11767 If ALL is a number, fetch this number of articles."
11768   (interactive "P")
11769   (prog1
11770       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11771             older len)
11772         (setq older
11773               ;; Some nntp servers lie about their active range.  When
11774               ;; this happens, the active range can be in the millions.
11775               ;; Use a compressed range to avoid creating a huge list.
11776               (gnus-range-difference (list gnus-newsgroup-active) old))
11777         (setq len (gnus-range-length older))
11778         (cond
11779          ((null older) nil)
11780          ((numberp all)
11781           (if (< all len)
11782               (let ((older-range (nreverse older)))
11783                 (setq older nil)
11784
11785                 (while (> all 0)
11786                   (let* ((r (pop older-range))
11787                          (min (if (numberp r) r (car r)))
11788                          (max (if (numberp r) r (cdr r))))
11789                     (while (and (<= min max)
11790                                 (> all 0))
11791                       (push max older)
11792                       (setq all (1- all)
11793                             max (1- max))))))
11794             (setq older (gnus-uncompress-range older))))
11795          (all
11796           (setq older (gnus-uncompress-range older)))
11797          (t
11798           (when (and (numberp gnus-large-newsgroup)
11799                    (> len gnus-large-newsgroup))
11800               (let* ((cursor-in-echo-area nil)
11801                      (initial (gnus-parameter-large-newsgroup-initial
11802                                gnus-newsgroup-name))
11803                      (input
11804                       (read-string
11805                        (format
11806                         "How many articles from %s (%s %d): "
11807                         (gnus-limit-string
11808                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11809                         (if initial "max" "default")
11810                         len)
11811                        (if initial
11812                            (cons (number-to-string initial)
11813                                  0)))))
11814                 (unless (string-match "^[ \t]*$" input)
11815                   (setq all (string-to-number input))
11816                   (if (< all len)
11817                       (let ((older-range (nreverse older)))
11818                         (setq older nil)
11819
11820                         (while (> all 0)
11821                           (let* ((r (pop older-range))
11822                                  (min (if (numberp r) r (car r)))
11823                                  (max (if (numberp r) r (cdr r))))
11824                             (while (and (<= min max)
11825                                         (> all 0))
11826                               (push max older)
11827                               (setq all (1- all)
11828                                     max (1- max))))))))))
11829           (setq older (gnus-uncompress-range older))))
11830         (if (not older)
11831             (message "No old news.")
11832           (gnus-summary-insert-articles older)
11833           (gnus-summary-limit (gnus-sorted-nunion old older))))
11834     (gnus-summary-position-point)))
11835
11836 (defun gnus-summary-insert-new-articles ()
11837   "Insert all new articles in this group."
11838   (interactive)
11839   (prog1
11840       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11841             (old-active gnus-newsgroup-active)
11842             (nnmail-fetched-sources (list t))
11843             i new)
11844         (setq gnus-newsgroup-active
11845               (gnus-activate-group gnus-newsgroup-name 'scan))
11846         (setq i (cdr gnus-newsgroup-active))
11847         (while (> i (cdr old-active))
11848           (push i new)
11849           (decf i))
11850         (if (not new)
11851             (message "No gnus is bad news")
11852           (gnus-summary-insert-articles new)
11853           (setq gnus-newsgroup-unreads
11854                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11855           (gnus-summary-limit (gnus-sorted-nunion old new))))
11856     (gnus-summary-position-point)))
11857
11858 (gnus-summary-make-all-marking-commands)
11859
11860 (gnus-ems-redefine)
11861
11862 (provide 'gnus-sum)
11863
11864 (run-hooks 'gnus-sum-load-hook)
11865
11866 ;; Local Variables:
11867 ;; coding: iso-8859-1
11868 ;; End:
11869
11870 ;;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11871 ;;; gnus-sum.el ends here