ed2c1c7a14ccfa2d2ba7078ddbc2b8d5dc9acb33
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;;; Code:
29
30 (eval-when-compile
31   (require 'cl)
32   (defvar tool-bar-mode))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'gmm-utils)
42 (require 'mm-decode)
43 (require 'nnoo)
44
45 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
46 (autoload 'gnus-cache-write-active "gnus-cache")
47 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
48 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
49 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
50 (autoload 'mm-uu-dissect "mm-uu")
51 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
52   "Deuglify broken Outlook (Express) articles and redisplay."
53   t)
54 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
55 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
56 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
57
58 (defcustom gnus-kill-summary-on-exit t
59   "*If non-nil, kill the summary buffer when you exit from it.
60 If nil, the summary will become a \"*Dead Summary*\" buffer, and
61 it will be killed sometime later."
62   :group 'gnus-summary-exit
63   :type 'boolean)
64
65 (defcustom gnus-fetch-old-headers nil
66   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
67 If an unread article in the group refers to an older, already
68 read (or just marked as read) article, the old article will not
69 normally be displayed in the Summary buffer.  If this variable is
70 t, Gnus will attempt to grab the headers to the old articles, and
71 thereby build complete threads.  If it has the value `some', all
72 old headers will be fetched but only enough headers to connect
73 otherwise loose threads will be displayed.  This variable can
74 also be a number.  In that case, no more than that number of old
75 headers will be fetched.  If it has the value `invisible', all
76 old headers will be fetched, but none will be displayed.
77
78 The server has to support NOV for any of this to work.
79
80 This feature can seriously impact performance it ignores all
81 locally cached header entries."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const :tag "on" t)
85                  (const some)
86                  (const invisible)
87                  number
88                  (sexp :menu-tag "other" t)))
89
90 (defcustom gnus-refer-thread-limit 500
91   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
92 If t, fetch all the available old headers."
93   :group 'gnus-thread
94   :type '(choice number
95                  (sexp :menu-tag "other" t)))
96
97 (defcustom gnus-summary-make-false-root 'adopt
98   "*nil means that Gnus won't gather loose threads.
99 If the root of a thread has expired or been read in a previous
100 session, the information necessary to build a complete thread has been
101 lost.  Instead of having many small sub-threads from this original thread
102 scattered all over the summary buffer, Gnus can gather them.
103
104 If non-nil, Gnus will try to gather all loose sub-threads from an
105 original thread into one large thread.
106
107 If this variable is non-nil, it should be one of `none', `adopt',
108 `dummy' or `empty'.
109
110 If this variable is `none', Gnus will not make a false root, but just
111 present the sub-threads after another.
112 If this variable is `dummy', Gnus will create a dummy root that will
113 have all the sub-threads as children.
114 If this variable is `adopt', Gnus will make one of the \"children\"
115 the parent and mark all the step-children as such.
116 If this variable is `empty', the \"children\" are printed with empty
117 subject fields.  (Or rather, they will be printed with a string
118 given by the `gnus-summary-same-subject' variable.)"
119   :group 'gnus-thread
120   :type '(choice (const :tag "off" nil)
121                  (const none)
122                  (const dummy)
123                  (const adopt)
124                  (const empty)))
125
126 (defcustom gnus-summary-make-false-root-always nil
127   "Always make a false dummy root."
128   :version "22.1"
129   :group 'gnus-thread
130   :type 'boolean)
131
132 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
133   "*A regexp to match subjects to be excluded from loose thread gathering.
134 As loose thread gathering is done on subjects only, that means that
135 there can be many false gatherings performed.  By rooting out certain
136 common subjects, gathering might become saner."
137   :group 'gnus-thread
138   :type 'regexp)
139
140 (defcustom gnus-summary-gather-subject-limit nil
141   "*Maximum length of subject comparisons when gathering loose threads.
142 Use nil to compare full subjects.  Setting this variable to a low
143 number will help gather threads that have been corrupted by
144 newsreaders chopping off subject lines, but it might also mean that
145 unrelated articles that have subject that happen to begin with the
146 same few characters will be incorrectly gathered.
147
148 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
149 comparing subjects."
150   :group 'gnus-thread
151   :type '(choice (const :tag "off" nil)
152                  (const fuzzy)
153                  (sexp :menu-tag "on" t)))
154
155 (defcustom gnus-simplify-subject-functions nil
156   "List of functions taking a string argument that simplify subjects.
157 The functions are applied recursively.
158
159 Useful functions to put in this list include:
160 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
161 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
162   :group 'gnus-thread
163   :type '(repeat function))
164
165 (defcustom gnus-simplify-ignored-prefixes nil
166   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  regexp))
170
171 (defcustom gnus-build-sparse-threads nil
172   "*If non-nil, fill in the gaps in threads.
173 If `some', only fill in the gaps that are needed to tie loose threads
174 together.  If `more', fill in all leaf nodes that Gnus can find.  If
175 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
176   :group 'gnus-thread
177   :type '(choice (const :tag "off" nil)
178                  (const some)
179                  (const more)
180                  (sexp :menu-tag "all" t)))
181
182 (defcustom gnus-summary-thread-gathering-function
183   'gnus-gather-threads-by-subject
184   "*Function used for gathering loose threads.
185 There are two pre-defined functions: `gnus-gather-threads-by-subject',
186 which only takes Subjects into consideration; and
187 `gnus-gather-threads-by-references', which compared the References
188 headers of the articles to find matches."
189   :group 'gnus-thread
190   :type '(radio (function-item gnus-gather-threads-by-subject)
191                 (function-item gnus-gather-threads-by-references)
192                 (function :tag "other")))
193
194 (defcustom gnus-summary-same-subject ""
195   "*String indicating that the current article has the same subject as the previous.
196 This variable will only be used if the value of
197 `gnus-summary-make-false-root' is `empty'."
198   :group 'gnus-summary-format
199   :type 'string)
200
201 (defcustom gnus-summary-goto-unread t
202   "*If t, many commands will go to the next unread article.
203 This applies to marking commands as well as other commands that
204 \"naturally\" select the next article, like, for instance, `SPC' at
205 the end of an article.
206
207 If nil, the marking commands do NOT go to the next unread article
208 \(they go to the next article instead).  If `never', commands that
209 usually go to the next unread article, will go to the next article,
210 whether it is read or not."
211   :group 'gnus-summary-marks
212   :link '(custom-manual "(gnus)Setting Marks")
213   :type '(choice (const :tag "off" nil)
214                  (const never)
215                  (sexp :menu-tag "on" t)))
216
217 (defcustom gnus-summary-default-score 0
218   "*Default article score level.
219 All scores generated by the score files will be added to this score.
220 If this variable is nil, scoring will be disabled."
221   :group 'gnus-score-default
222   :type '(choice (const :tag "disable")
223                  integer))
224
225 (defcustom gnus-summary-default-high-score 0
226   "*Default threshold for a high scored article.
227 An article will be highlighted as high scored if its score is greater
228 than this score."
229   :version "22.1"
230   :group 'gnus-score-default
231   :type 'integer)
232
233 (defcustom gnus-summary-default-low-score 0
234   "*Default threshold for a low scored article.
235 An article will be highlighted as low scored if its score is smaller
236 than this score."
237   :version "22.1"
238   :group 'gnus-score-default
239   :type 'integer)
240
241 (defcustom gnus-summary-zcore-fuzz 0
242   "*Fuzziness factor for the zcore in the summary buffer.
243 Articles with scores closer than this to `gnus-summary-default-score'
244 will not be marked."
245   :group 'gnus-summary-format
246   :type 'integer)
247
248 (defcustom gnus-simplify-subject-fuzzy-regexp nil
249   "*Strings to be removed when doing fuzzy matches.
250 This can either be a regular expression or list of regular expressions
251 that will be removed from subject strings if fuzzy subject
252 simplification is selected."
253   :group 'gnus-thread
254   :type '(repeat regexp))
255
256 (defcustom gnus-show-threads t
257   "*If non-nil, display threads in summary mode."
258   :group 'gnus-thread
259   :type 'boolean)
260
261 (defcustom gnus-thread-hide-subtree nil
262   "*If non-nil, hide all threads initially.
263 This can be a predicate specifier which says which threads to hide.
264 If threads are hidden, you have to run the command
265 `gnus-summary-show-thread' by hand or select an article."
266   :group 'gnus-thread
267   :type '(radio (sexp :format "Non-nil\n"
268                       :match (lambda (widget value)
269                                (not (or (consp value) (functionp value))))
270                       :value t)
271                 (const nil)
272                 (sexp :tag "Predicate specifier")))
273
274 (defcustom gnus-thread-hide-killed t
275   "*If non-nil, hide killed threads automatically."
276   :group 'gnus-thread
277   :type 'boolean)
278
279 (defcustom gnus-thread-ignore-subject t
280   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
281 If nil, articles that have different subjects from their parents will
282 start separate threads."
283   :group 'gnus-thread
284   :type 'boolean)
285
286 (defcustom gnus-thread-operation-ignore-subject t
287   "*If non-nil, subjects will be ignored when doing thread commands.
288 This affects commands like `gnus-summary-kill-thread' and
289 `gnus-summary-lower-thread'.
290
291 If this variable is nil, articles in the same thread with different
292 subjects will not be included in the operation in question.  If this
293 variable is `fuzzy', only articles that have subjects that are fuzzily
294 equal will be included."
295   :group 'gnus-thread
296   :type '(choice (const :tag "off" nil)
297                  (const fuzzy)
298                  (sexp :tag "on" t)))
299
300 (defcustom gnus-thread-indent-level 4
301   "*Number that says how much each sub-thread should be indented."
302   :group 'gnus-thread
303   :type 'integer)
304
305 (defcustom gnus-auto-extend-newsgroup t
306   "*If non-nil, extend newsgroup forward and backward when requested."
307   :group 'gnus-summary-choose
308   :type 'boolean)
309
310 (defcustom gnus-auto-select-first t
311   "*If non-nil, select the article under point.
312 Which article this is is controlled by the `gnus-auto-select-subject'
313 variable.
314
315 If you want to prevent automatic selection of articles in some
316 newsgroups, set the variable to nil in `gnus-select-group-hook'."
317   :group 'gnus-group-select
318   :type '(choice (const :tag "none" nil)
319                  (sexp :menu-tag "first" t)))
320
321 (defcustom gnus-auto-select-subject 'unread
322   "*Says what subject to place under point when entering a group.
323
324 This variable can either be the symbols `first' (place point on the
325 first subject), `unread' (place point on the subject line of the first
326 unread article), `best' (place point on the subject line of the
327 higest-scored article), `unseen' (place point on the subject line of
328 the first unseen article), `unseen-or-unread' (place point on the subject
329 line of the first unseen article or, if all article have been seen, on the
330 subject line of the first unread article), or a function to be called to
331 place point on some subject line."
332   :version "22.1"
333   :group 'gnus-group-select
334   :type '(choice (const best)
335                  (const unread)
336                  (const first)
337                  (const unseen)
338                  (const unseen-or-unread)))
339
340 (defcustom gnus-auto-select-next t
341   "*If non-nil, offer to go to the next group from the end of the previous.
342 If the value is t and the next newsgroup is empty, Gnus will exit
343 summary mode and go back to group mode.  If the value is neither nil
344 nor t, Gnus will select the following unread newsgroup.  In
345 particular, if the value is the symbol `quietly', the next unread
346 newsgroup will be selected without any confirmation, and if it is
347 `almost-quietly', the next group will be selected without any
348 confirmation if you are located on the last article in the group.
349 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
350 will go to the next group without confirmation."
351   :group 'gnus-summary-maneuvering
352   :type '(choice (const :tag "off" nil)
353                  (const quietly)
354                  (const almost-quietly)
355                  (const slightly-quietly)
356                  (sexp :menu-tag "on" t)))
357
358 (defcustom gnus-auto-select-same nil
359   "*If non-nil, select the next article with the same subject.
360 If there are no more articles with the same subject, go to
361 the first unread article."
362   :group 'gnus-summary-maneuvering
363   :type 'boolean)
364
365 (defcustom gnus-auto-goto-ignores 'unfetched
366   "*Says how to handle unfetched articles when maneuvering.
367
368 This variable can either be the symbols nil (maneuver to any
369 article), `undownloaded' (maneuvering while unplugged ignores articles
370 that have not been fetched), `always-undownloaded' (maneuvering always
371 ignores articles that have not been fetched), `unfetched' (maneuvering
372 ignores articles whose headers have not been fetched).
373
374 NOTE: The list of unfetched articles will always be nil when plugged
375 and, when unplugged, a subset of the undownloaded article list."
376   :version "22.1"
377   :group 'gnus-summary-maneuvering
378   :type '(choice (const :tag "None" nil)
379                  (const :tag "Undownloaded when unplugged" undownloaded)
380                  (const :tag "Undownloaded" always-undownloaded)
381                  (const :tag "Unfetched" unfetched)))
382
383 (defcustom gnus-summary-check-current nil
384   "*If non-nil, consider the current article when moving.
385 The \"unread\" movement commands will stay on the same line if the
386 current article is unread."
387   :group 'gnus-summary-maneuvering
388   :type 'boolean)
389
390 (defcustom gnus-auto-center-summary 2
391   "*If non-nil, always center the current summary buffer.
392 In particular, if `vertical' do only vertical recentering.  If non-nil
393 and non-`vertical', do both horizontal and vertical recentering."
394   :group 'gnus-summary-maneuvering
395   :type '(choice (const :tag "none" nil)
396                  (const vertical)
397                  (integer :tag "height")
398                  (sexp :menu-tag "both" t)))
399
400 (defvar gnus-auto-center-group t
401   "*If non-nil, always center the group buffer.")
402
403 (defcustom gnus-show-all-headers nil
404   "*If non-nil, don't hide any headers."
405   :group 'gnus-article-hiding
406   :group 'gnus-article-headers
407   :type 'boolean)
408
409 (defcustom gnus-summary-ignore-duplicates nil
410   "*If non-nil, ignore articles with identical Message-ID headers."
411   :group 'gnus-summary
412   :type 'boolean)
413
414 (defcustom gnus-single-article-buffer t
415   "*If non-nil, display all articles in the same buffer.
416 If nil, each group will get its own article buffer."
417   :group 'gnus-article-various
418   :type 'boolean)
419
420 (defcustom gnus-break-pages t
421   "*If non-nil, do page breaking on articles.
422 The page delimiter is specified by the `gnus-page-delimiter'
423 variable."
424   :group 'gnus-article-various
425   :type 'boolean)
426
427 (defcustom gnus-move-split-methods nil
428   "*Variable used to suggest where articles are to be moved to.
429 It uses the same syntax as the `gnus-split-methods' variable.
430 However, whereas `gnus-split-methods' specifies file names as targets,
431 this variable specifies group names."
432   :group 'gnus-summary-mail
433   :type '(repeat (choice (list :value (fun) function)
434                          (cons :value ("" "") regexp (repeat string))
435                          (sexp :value nil))))
436
437 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
438   "Function used to compute default prefix for article move/copy/etc prompts.
439 The function should take one argument, a group name, and return a
440 string with the suggested prefix."
441   :group 'gnus-summary-mail
442   :type 'function)
443
444 ;; FIXME: Although the custom type is `character' for the following variables,
445 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
446
447 (defcustom gnus-unread-mark ?           ;Whitespace
448   "*Mark used for unread articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-ticked-mark ?!
453   "*Mark used for ticked articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-dormant-mark ??
458   "*Mark used for dormant articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-del-mark ?r
463   "*Mark used for del'd articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-read-mark ?R
468   "*Mark used for read articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-expirable-mark ?E
473   "*Mark used for expirable articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-killed-mark ?K
478   "*Mark used for killed articles."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-spam-mark ?$
483   "*Mark used for spam articles."
484   :version "22.1"
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-souped-mark ?F
489   "*Mark used for souped articles."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-kill-file-mark ?X
494   "*Mark used for articles killed by kill files."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-low-score-mark ?Y
499   "*Mark used for articles with a low score."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-catchup-mark ?C
504   "*Mark used for articles that are caught up."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-replied-mark ?A
509   "*Mark used for articles that have been replied to."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-forwarded-mark ?F
514   "*Mark used for articles that have been forwarded."
515   :version "22.1"
516   :group 'gnus-summary-marks
517   :type 'character)
518
519 (defcustom gnus-recent-mark ?N
520   "*Mark used for articles that are recent."
521   :version "22.1"
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-cached-mark ?*
526   "*Mark used for articles that are in the cache."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-saved-mark ?S
531   "*Mark used for articles that have been saved."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unseen-mark ?.
536   "*Mark used for articles that haven't been seen."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-no-mark ?               ;Whitespace
542   "*Mark used for articles that have no other secondary mark."
543   :version "22.1"
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-ancient-mark ?O
548   "*Mark used for ancient articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-sparse-mark ?Q
553   "*Mark used for sparsely reffed articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-canceled-mark ?G
558   "*Mark used for canceled articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-duplicate-mark ?M
563   "*Mark used for duplicate articles."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-undownloaded-mark ?-
568   "*Mark used for articles that weren't downloaded."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloaded-mark ?+
574   "*Mark used for articles that were downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-downloadable-mark ?%
579   "*Mark used for articles that are to be downloaded."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unsendable-mark ?=
584   "*Mark used for articles that won't be sent."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-over-mark ?+
589   "*Score mark used for articles with high scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-score-below-mark ?-
594   "*Score mark used for articles with low scores."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-empty-thread-mark ?     ;Whitespace
599   "*There is no thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-not-empty-thread-mark ?=
604   "*There is a thread under the article."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-view-pseudo-asynchronously nil
609   "*If non-nil, Gnus will view pseudo-articles asynchronously."
610   :group 'gnus-extract-view
611   :type 'boolean)
612
613 (defcustom gnus-auto-expirable-marks
614   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
615         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
616         gnus-souped-mark gnus-duplicate-mark)
617   "*The list of marks converted into expiration if a group is auto-expirable."
618   :version "21.1"
619   :group 'gnus-summary
620   :type '(repeat character))
621
622 (defcustom gnus-inhibit-user-auto-expire t
623   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
624   :version "21.1"
625   :group 'gnus-summary
626   :type 'boolean)
627
628 (defcustom gnus-view-pseudos nil
629   "*If `automatic', pseudo-articles will be viewed automatically.
630 If `not-confirm', pseudos will be viewed automatically, and the user
631 will not be asked to confirm the command."
632   :group 'gnus-extract-view
633   :type '(choice (const :tag "off" nil)
634                  (const automatic)
635                  (const not-confirm)))
636
637 (defcustom gnus-view-pseudos-separately t
638   "*If non-nil, one pseudo-article will be created for each file to be viewed.
639 If nil, all files that use the same viewing command will be given as a
640 list of parameters to that command."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-insert-pseudo-articles t
645   "*If non-nil, insert pseudo-articles when decoding articles."
646   :group 'gnus-extract-view
647   :type 'boolean)
648
649 (defcustom gnus-summary-dummy-line-format
650   "   %(:                             :%) %S\n"
651   "*The format specification for the dummy roots in the summary buffer.
652 It works along the same lines as a normal formatting string,
653 with some simple extensions.
654
655 %S  The subject
656
657 General format specifiers can also be used.
658 See `(gnus)Formatting Variables'."
659   :link '(custom-manual "(gnus)Formatting Variables")
660   :group 'gnus-threading
661   :type 'string)
662
663 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
664   "*The format specification for the summary mode line.
665 It works along the same lines as a normal formatting string,
666 with some simple extensions:
667
668 %G  Group name
669 %p  Unprefixed group name
670 %A  Current article number
671 %z  Current article score
672 %V  Gnus version
673 %U  Number of unread articles in the group
674 %e  Number of unselected articles in the group
675 %Z  A string with unread/unselected article counts
676 %g  Shortish group name
677 %S  Subject of the current article
678 %u  User-defined spec
679 %s  Current score file name
680 %d  Number of dormant articles
681 %r  Number of articles that have been marked as read in this session
682 %E  Number of articles expunged by the score files"
683   :group 'gnus-summary-format
684   :type 'string)
685
686 (defcustom gnus-list-identifiers nil
687   "Regexp that matches list identifiers to be removed from subject.
688 This can also be a list of regexps."
689   :version "21.1"
690   :group 'gnus-summary-format
691   :group 'gnus-article-hiding
692   :type '(choice (const :tag "none" nil)
693                  (regexp :value ".*")
694                  (repeat :value (".*") regexp)))
695
696 (defcustom gnus-summary-mark-below 0
697   "*Mark all articles with a score below this variable as read.
698 This variable is local to each summary buffer and usually set by the
699 score file."
700   :group 'gnus-score-default
701   :type 'integer)
702
703 (defun gnus-widget-reversible-match (widget value)
704   "Ignoring WIDGET, convert VALUE to internal form.
705 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
706   ;; (debug value)
707   (or (symbolp value)
708       (and (listp value)
709            (eq (length value) 2)
710            (eq (nth 0 value) 'not)
711            (symbolp (nth 1 value)))))
712
713 (defun gnus-widget-reversible-to-internal (widget value)
714   "Ignoring WIDGET, convert VALUE to internal form.
715 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
716 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
717   ;; (debug value)
718   (if (atom value)
719       (list value nil)
720     (list (nth 1 value) t)))
721
722 (defun gnus-widget-reversible-to-external (widget value)
723   "Ignoring WIDGET, convert VALUE to external form.
724 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
725 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
726   ;; (debug value)
727   (if (nth 1 value)
728       (list 'not (nth 0 value))
729     (nth 0 value)))
730
731 (define-widget 'gnus-widget-reversible 'group
732   "A `group' that convert values."
733   :match 'gnus-widget-reversible-match
734   :value-to-internal 'gnus-widget-reversible-to-internal
735   :value-to-external 'gnus-widget-reversible-to-external)
736
737 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
738   "*List of functions used for sorting articles in the summary buffer.
739
740 Each function takes two articles and returns non-nil if the first
741 article should be sorted before the other.  If you use more than one
742 function, the primary sort function should be the last.  You should
743 probably always include `gnus-article-sort-by-number' in the list of
744 sorting functions -- preferably first.  Also note that sorting by date
745 is often much slower than sorting by number, and the sorting order is
746 very similar.  (Sorting by date means sorting by the time the message
747 was sent, sorting by number means sorting by arrival time.)
748
749 Each item can also be a list `(not F)' where F is a function;
750 this reverses the sort order.
751
752 Ready-made functions include `gnus-article-sort-by-number',
753 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
754 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
755 and `gnus-article-sort-by-score'.
756
757 When threading is turned on, the variable `gnus-thread-sort-functions'
758 controls how articles are sorted."
759   :group 'gnus-summary-sort
760   :type '(repeat (gnus-widget-reversible
761                   (choice (function-item gnus-article-sort-by-number)
762                           (function-item gnus-article-sort-by-author)
763                           (function-item gnus-article-sort-by-subject)
764                           (function-item gnus-article-sort-by-date)
765                           (function-item gnus-article-sort-by-score)
766                           (function-item gnus-article-sort-by-random)
767                           (function :tag "other"))
768                   (boolean :tag "Reverse order"))))
769
770
771 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
772   "*List of functions used for sorting threads in the summary buffer.
773 By default, threads are sorted by article number.
774
775 Each function takes two threads and returns non-nil if the first
776 thread should be sorted before the other.  If you use more than one
777 function, the primary sort function should be the last.  You should
778 probably always include `gnus-thread-sort-by-number' in the list of
779 sorting functions -- preferably first.  Also note that sorting by date
780 is often much slower than sorting by number, and the sorting order is
781 very similar.  (Sorting by date means sorting by the time the message
782 was sent, sorting by number means sorting by arrival time.)
783
784 Each list item can also be a list `(not F)' where F is a
785 function; this specifies reversed sort order.
786
787 Ready-made functions include `gnus-thread-sort-by-number',
788 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
789 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
790 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
791 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
792 and `gnus-thread-sort-by-total-score' (see
793 `gnus-thread-score-function').
794
795 When threading is turned off, the variable
796 `gnus-article-sort-functions' controls how articles are sorted."
797   :group 'gnus-summary-sort
798   :type '(repeat
799           (gnus-widget-reversible
800            (choice (function-item gnus-thread-sort-by-number)
801                    (function-item gnus-thread-sort-by-author)
802                    (function-item gnus-thread-sort-by-recipient)
803                    (function-item gnus-thread-sort-by-subject)
804                    (function-item gnus-thread-sort-by-date)
805                    (function-item gnus-thread-sort-by-score)
806                    (function-item gnus-thread-sort-by-most-recent-number)
807                    (function-item gnus-thread-sort-by-most-recent-date)
808                    (function-item gnus-thread-sort-by-random)
809                    (function-item gnus-thread-sort-by-total-score)
810                    (function :tag "other"))
811            (boolean :tag "Reverse order"))))
812
813 (defcustom gnus-thread-score-function '+
814   "*Function used for calculating the total score of a thread.
815
816 The function is called with the scores of the article and each
817 subthread and should then return the score of the thread.
818
819 Some functions you can use are `+', `max', or `min'."
820   :group 'gnus-summary-sort
821   :type 'function)
822
823 (defcustom gnus-summary-expunge-below nil
824   "All articles that have a score less than this variable will be expunged.
825 This variable is local to the summary buffers."
826   :group 'gnus-score-default
827   :type '(choice (const :tag "off" nil)
828                  integer))
829
830 (defcustom gnus-thread-expunge-below nil
831   "All threads that have a total score less than this variable will be expunged.
832 See `gnus-thread-score-function' for en explanation of what a
833 \"thread score\" is.
834
835 This variable is local to the summary buffers."
836   :group 'gnus-threading
837   :group 'gnus-score-default
838   :type '(choice (const :tag "off" nil)
839                  integer))
840
841 (defcustom gnus-summary-mode-hook nil
842   "*A hook for Gnus summary mode.
843 This hook is run before any variables are set in the summary buffer."
844   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
845   :group 'gnus-summary-various
846   :type 'hook)
847
848 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
849 (when (featurep 'xemacs)
850   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
851   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
852   (add-hook 'gnus-summary-mode-hook
853             'gnus-xmas-switch-horizontal-scrollbar-off))
854
855 (defcustom gnus-summary-menu-hook nil
856   "*Hook run after the creation of the summary mode menu."
857   :group 'gnus-summary-visual
858   :type 'hook)
859
860 (defcustom gnus-summary-exit-hook nil
861   "*A hook called on exit from the summary buffer.
862 It will be called with point in the group buffer."
863   :group 'gnus-summary-exit
864   :type 'hook)
865
866 (defcustom gnus-summary-prepare-hook nil
867   "*A hook called after the summary buffer has been generated.
868 If you want to modify the summary buffer, you can use this hook."
869   :group 'gnus-summary-various
870   :type 'hook)
871
872 (defcustom gnus-summary-prepared-hook nil
873   "*A hook called as the last thing after the summary buffer has been generated."
874   :group 'gnus-summary-various
875   :type 'hook)
876
877 (defcustom gnus-summary-generate-hook nil
878   "*A hook run just before generating the summary buffer.
879 This hook is commonly used to customize threading variables and the
880 like."
881   :group 'gnus-summary-various
882   :type 'hook)
883
884 (defcustom gnus-select-group-hook nil
885   "*A hook called when a newsgroup is selected.
886
887 If you'd like to simplify subjects like the
888 `gnus-summary-next-same-subject' command does, you can use the
889 following hook:
890
891  (add-hook gnus-select-group-hook
892            (lambda ()
893              (mapcar (lambda (header)
894                        (mail-header-set-subject
895                         header
896                         (gnus-simplify-subject
897                          (mail-header-subject header) 're-only)))
898                      gnus-newsgroup-headers)))"
899   :group 'gnus-group-select
900   :type 'hook)
901
902 (defcustom gnus-select-article-hook nil
903   "*A hook called when an article is selected."
904   :group 'gnus-summary-choose
905   :options '(gnus-agent-fetch-selected-article)
906   :type 'hook)
907
908 (defcustom gnus-visual-mark-article-hook
909   (list 'gnus-highlight-selected-summary)
910   "*Hook run after selecting an article in the summary buffer.
911 It is meant to be used for highlighting the article in some way.  It
912 is not run if `gnus-visual' is nil."
913   :group 'gnus-summary-visual
914   :type 'hook)
915
916 (defcustom gnus-parse-headers-hook nil
917   "*A hook called before parsing the headers."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-exit-group-hook nil
922   "*A hook called when exiting summary mode.
923 This hook is not called from the non-updating exit commands like `Q'."
924   :group 'gnus-various
925   :type 'hook)
926
927 (defcustom gnus-summary-update-hook
928   (list 'gnus-summary-highlight-line)
929   "*A hook called when a summary line is changed.
930 The hook will not be called if `gnus-visual' is nil.
931
932 The default function `gnus-summary-highlight-line' will
933 highlight the line according to the `gnus-summary-highlight'
934 variable."
935   :group 'gnus-summary-visual
936   :type 'hook)
937
938 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
939   "*A hook called when an article is selected for the first time.
940 The hook is intended to mark an article as read (or unread)
941 automatically when it is selected."
942   :group 'gnus-summary-choose
943   :type 'hook)
944
945 (defcustom gnus-group-no-more-groups-hook nil
946   "*A hook run when returning to group mode having no more (unread) groups."
947   :group 'gnus-group-select
948   :type 'hook)
949
950 (defcustom gnus-ps-print-hook nil
951   "*A hook run before ps-printing something from Gnus."
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-move-hook nil
956   "*A hook called after an article is moved, copied, respooled, or crossposted."
957   :version "22.1"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-delete-hook nil
962   "*A hook called after an article is deleted."
963   :version "22.1"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-article-expire-hook nil
968   "*A hook called after an article is expired."
969   :version "22.1"
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-display-arrow
974   (and (fboundp 'display-graphic-p)
975        (display-graphic-p))
976   "*If non-nil, display an arrow highlighting the current article."
977   :version "22.1"
978   :group 'gnus-summary
979   :type 'boolean)
980
981 (defcustom gnus-summary-selected-face 'gnus-summary-selected
982   "Face used for highlighting the current article in the summary buffer."
983   :group 'gnus-summary-visual
984   :type 'face)
985
986 (defvar gnus-tmp-downloaded nil)
987
988 (defcustom gnus-summary-highlight
989   '(((eq mark gnus-canceled-mark)
990      . gnus-summary-cancelled)
991     ((and uncached (> score default-high))
992      . gnus-summary-high-undownloaded)
993     ((and uncached (< score default-low))
994      . gnus-summary-low-undownloaded)
995     (uncached
996      . gnus-summary-normal-undownloaded)
997     ((and (> score default-high)
998           (or (eq mark gnus-dormant-mark)
999               (eq mark gnus-ticked-mark)))
1000      . gnus-summary-high-ticked)
1001     ((and (< score default-low)
1002           (or (eq mark gnus-dormant-mark)
1003               (eq mark gnus-ticked-mark)))
1004      . gnus-summary-low-ticked)
1005     ((or (eq mark gnus-dormant-mark)
1006          (eq mark gnus-ticked-mark))
1007      . gnus-summary-normal-ticked)
1008     ((and (> score default-high) (eq mark gnus-ancient-mark))
1009      . gnus-summary-high-ancient)
1010     ((and (< score default-low) (eq mark gnus-ancient-mark))
1011      . gnus-summary-low-ancient)
1012     ((eq mark gnus-ancient-mark)
1013      . gnus-summary-normal-ancient)
1014     ((and (> score default-high) (eq mark gnus-unread-mark))
1015      . gnus-summary-high-unread)
1016     ((and (< score default-low) (eq mark gnus-unread-mark))
1017      . gnus-summary-low-unread)
1018     ((eq mark gnus-unread-mark)
1019      . gnus-summary-normal-unread)
1020     ((> score default-high)
1021      . gnus-summary-high-read)
1022     ((< score default-low)
1023      . gnus-summary-low-read)
1024     (t
1025      . gnus-summary-normal-read))
1026   "*Controls the highlighting of summary buffer lines.
1027
1028 A list of (FORM . FACE) pairs.  When deciding how a a particular
1029 summary line should be displayed, each form is evaluated.  The content
1030 of the face field after the first true form is used.  You can change
1031 how those summary lines are displayed, by editing the face field.
1032
1033 You can use the following variables in the FORM field.
1034
1035 score:        The article's score
1036 default:      The default article score.
1037 default-high: The default score for high scored articles.
1038 default-low:  The default score for low scored articles.
1039 below:        The score below which articles are automatically marked as read.
1040 mark:         The article's mark.
1041 uncached:     Non-nil if the article is uncached."
1042   :group 'gnus-summary-visual
1043   :type '(repeat (cons (sexp :tag "Form" nil)
1044                        face)))
1045
1046 (defcustom gnus-alter-header-function nil
1047   "Function called to allow alteration of article header structures.
1048 The function is called with one parameter, the article header vector,
1049 which it may alter in any way."
1050   :type '(choice (const :tag "None" nil)
1051                  function)
1052   :group 'gnus-summary)
1053
1054 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1055   "Variable that says which function should be used to decode a string with encoded words.")
1056
1057 (defcustom gnus-extra-headers '(To Newsgroups)
1058   "*Extra headers to parse."
1059   :version "21.1"
1060   :group 'gnus-summary
1061   :type '(repeat symbol))
1062
1063 (defcustom gnus-ignored-from-addresses
1064   (and user-mail-address  
1065        (not (string= user-mail-address ""))
1066        (regexp-quote user-mail-address))
1067   "*Regexp of From headers that may be suppressed in favor of To headers."
1068   :version "21.1"
1069   :group 'gnus-summary
1070   :type 'regexp)
1071
1072 (defcustom gnus-summary-to-prefix "-> "
1073   "*String prefixed to the To field in the summary line when
1074 using `gnus-ignored-from-addresses'."
1075   :version "22.1"
1076   :group 'gnus-summary
1077   :type 'string)
1078
1079 (defcustom gnus-summary-newsgroup-prefix "=> "
1080   "*String prefixed to the Newsgroup field in the summary
1081 line when using `gnus-ignored-from-addresses'."
1082   :version "22.1"
1083   :group 'gnus-summary
1084   :type 'string)
1085
1086 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1087   "List of charsets that should be ignored.
1088 When these charsets are used in the \"charset\" parameter, the
1089 default charset will be used instead."
1090   :version "21.1"
1091   :type '(repeat symbol)
1092   :group 'gnus-charset)
1093
1094 (gnus-define-group-parameter
1095  ignored-charsets
1096  :type list
1097  :function-document
1098  "Return the ignored charsets of GROUP."
1099  :variable gnus-group-ignored-charsets-alist
1100  :variable-default
1101  '(("alt\\.chinese\\.text" iso-8859-1))
1102  :variable-document
1103  "Alist of regexps (to match group names) and charsets that should be ignored.
1104 When these charsets are used in the \"charset\" parameter, the
1105 default charset will be used instead."
1106  :variable-group gnus-charset
1107  :variable-type '(repeat (cons (regexp :tag "Group")
1108                                (repeat symbol)))
1109  :parameter-type '(choice :tag "Ignored charsets"
1110                           :value nil
1111                           (repeat (symbol)))
1112  :parameter-document       "\
1113 List of charsets that should be ignored.
1114
1115 When these charsets are used in the \"charset\" parameter, the
1116 default charset will be used instead.")
1117
1118 (defcustom gnus-group-highlight-words-alist nil
1119   "Alist of group regexps and highlight regexps.
1120 This variable uses the same syntax as `gnus-emphasis-alist'."
1121   :version "21.1"
1122   :type '(repeat (cons (regexp :tag "Group")
1123                        (repeat (list (regexp :tag "Highlight regexp")
1124                                      (number :tag "Group for entire word" 0)
1125                                      (number :tag "Group for displayed part" 0)
1126                                      (symbol :tag "Face"
1127                                              gnus-emphasis-highlight-words)))))
1128   :group 'gnus-summary-visual)
1129
1130 (defcustom gnus-summary-show-article-charset-alist
1131   nil
1132   "Alist of number and charset.
1133 The article will be shown with the charset corresponding to the
1134 numbered argument.
1135 For example: ((1 . cn-gb-2312) (2 . big5))."
1136   :version "21.1"
1137   :type '(repeat (cons (number :tag "Argument" 1)
1138                        (symbol :tag "Charset")))
1139   :group 'gnus-charset)
1140
1141 (defcustom gnus-preserve-marks t
1142   "Whether marks are preserved when moving, copying and respooling messages."
1143   :version "21.1"
1144   :type 'boolean
1145   :group 'gnus-summary-marks)
1146
1147 (defcustom gnus-alter-articles-to-read-function nil
1148   "Function to be called to alter the list of articles to be selected."
1149   :type '(choice (const nil) function)
1150   :group 'gnus-summary)
1151
1152 (defcustom gnus-orphan-score nil
1153   "*All orphans get this score added.  Set in the score file."
1154   :group 'gnus-score-default
1155   :type '(choice (const nil)
1156                  integer))
1157
1158 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1159   "*A regexp to match MIME parts when saving multiple parts of a
1160 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1161 This regexp will be used by default when prompting the user for which
1162 type of files to save."
1163   :group 'gnus-summary
1164   :type 'regexp)
1165
1166 (defcustom gnus-read-all-available-headers nil
1167   "Whether Gnus should parse all headers made available to it.
1168 This is mostly relevant for slow back ends where the user may
1169 wish to widen the summary buffer to include all headers
1170 that were fetched.  Say, for nnultimate groups."
1171   :version "22.1"
1172   :group 'gnus-summary
1173   :type '(choice boolean regexp))
1174
1175 (defcustom gnus-summary-muttprint-program "muttprint"
1176   "Command (and optional arguments) used to run Muttprint."
1177   :version "22.1"
1178   :group 'gnus-summary
1179   :type 'string)
1180
1181 (defcustom gnus-article-loose-mime t
1182   "If non-nil, don't require MIME-Version header.
1183 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1184 supply the MIME-Version header or deliberately strip it from the mail.
1185 If non-nil (the default), Gnus will treat some articles as MIME
1186 even if the MIME-Version header is missing."
1187   :version "22.1"
1188   :type 'boolean
1189   :group 'gnus-article-mime)
1190
1191 (defcustom gnus-article-emulate-mime t
1192   "If non-nil, use MIME emulation for uuencode and the like.
1193 This means that Gnus will search message bodies for text that look
1194 like uuencoded bits, yEncoded bits, and so on, and present that using
1195 the normal Gnus MIME machinery."
1196   :version "22.1"
1197   :type 'boolean
1198   :group 'gnus-article-mime)
1199
1200 ;;; Internal variables
1201
1202 (defvar gnus-summary-display-cache nil)
1203 (defvar gnus-article-mime-handles nil)
1204 (defvar gnus-article-decoded-p nil)
1205 (defvar gnus-article-charset nil)
1206 (defvar gnus-article-ignored-charsets nil)
1207 (defvar gnus-scores-exclude-files nil)
1208 (defvar gnus-page-broken nil)
1209
1210 (defvar gnus-original-article nil)
1211 (defvar gnus-article-internal-prepare-hook nil)
1212 (defvar gnus-newsgroup-process-stack nil)
1213
1214 (defvar gnus-thread-indent-array nil)
1215 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1216 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1217   "Function called to sort the articles within a thread after it has been gathered together.")
1218
1219 (defvar gnus-summary-save-parts-type-history nil)
1220 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1221
1222 ;; Avoid highlighting in kill files.
1223 (defvar gnus-summary-inhibit-highlight nil)
1224 (defvar gnus-newsgroup-selected-overlay nil)
1225 (defvar gnus-inhibit-limiting nil)
1226 (defvar gnus-newsgroup-adaptive-score-file nil)
1227 (defvar gnus-current-score-file nil)
1228 (defvar gnus-current-move-group nil)
1229 (defvar gnus-current-copy-group nil)
1230 (defvar gnus-current-crosspost-group nil)
1231 (defvar gnus-newsgroup-display nil)
1232
1233 (defvar gnus-newsgroup-dependencies nil)
1234 (defvar gnus-newsgroup-adaptive nil)
1235 (defvar gnus-summary-display-article-function nil)
1236 (defvar gnus-summary-highlight-line-function nil
1237   "Function called after highlighting a summary line.")
1238
1239 (defvar gnus-summary-line-format-alist
1240   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1241     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1242     (?s gnus-tmp-subject-or-nil ?s)
1243     (?n gnus-tmp-name ?s)
1244     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1245         ?s)
1246     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1247             gnus-tmp-from) ?s)
1248     (?F gnus-tmp-from ?s)
1249     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1250     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1251     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1252     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1253     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1254     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1255     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1256     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1257     (?L gnus-tmp-lines ?s)
1258     (?O gnus-tmp-downloaded ?c)
1259     (?I gnus-tmp-indentation ?s)
1260     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1261     (?R gnus-tmp-replied ?c)
1262     (?\[ gnus-tmp-opening-bracket ?c)
1263     (?\] gnus-tmp-closing-bracket ?c)
1264     (?\> (make-string gnus-tmp-level ? ) ?s)
1265     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1266     (?i gnus-tmp-score ?d)
1267     (?z gnus-tmp-score-char ?c)
1268     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1269     (?U gnus-tmp-unread ?c)
1270     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1271         ?s)
1272     (?t (gnus-summary-number-of-articles-in-thread
1273          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1274         ?d)
1275     (?e (gnus-summary-number-of-articles-in-thread
1276          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1277         ?c)
1278     (?u gnus-tmp-user-defined ?s)
1279     (?P (gnus-pick-line-number) ?d)
1280     (?B gnus-tmp-thread-tree-header-string ?s)
1281     (user-date (gnus-user-date
1282                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1283   "An alist of format specifications that can appear in summary lines.
1284 These are paired with what variables they correspond with, along with
1285 the type of the variable (string, integer, character, etc).")
1286
1287 (defvar gnus-summary-dummy-line-format-alist
1288   `((?S gnus-tmp-subject ?s)
1289     (?N gnus-tmp-number ?d)
1290     (?u gnus-tmp-user-defined ?s)))
1291
1292 (defvar gnus-summary-mode-line-format-alist
1293   `((?G gnus-tmp-group-name ?s)
1294     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1295     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1296     (?A gnus-tmp-article-number ?d)
1297     (?Z gnus-tmp-unread-and-unselected ?s)
1298     (?V gnus-version ?s)
1299     (?U gnus-tmp-unread-and-unticked ?d)
1300     (?S gnus-tmp-subject ?s)
1301     (?e gnus-tmp-unselected ?d)
1302     (?u gnus-tmp-user-defined ?s)
1303     (?d (length gnus-newsgroup-dormant) ?d)
1304     (?t (length gnus-newsgroup-marked) ?d)
1305     (?h (length gnus-newsgroup-spam-marked) ?d)
1306     (?r (length gnus-newsgroup-reads) ?d)
1307     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1308     (?E gnus-newsgroup-expunged-tally ?d)
1309     (?s (gnus-current-score-file-nondirectory) ?s)))
1310
1311 (defvar gnus-last-search-regexp nil
1312   "Default regexp for article search command.")
1313
1314 (defvar gnus-last-shell-command nil
1315   "Default shell command on article.")
1316
1317 (defvar gnus-newsgroup-agentized nil
1318   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1319 (defvar gnus-newsgroup-begin nil)
1320 (defvar gnus-newsgroup-end nil)
1321 (defvar gnus-newsgroup-last-rmail nil)
1322 (defvar gnus-newsgroup-last-mail nil)
1323 (defvar gnus-newsgroup-last-folder nil)
1324 (defvar gnus-newsgroup-last-file nil)
1325 (defvar gnus-newsgroup-last-directory nil)
1326 (defvar gnus-newsgroup-auto-expire nil)
1327 (defvar gnus-newsgroup-active nil)
1328
1329 (defvar gnus-newsgroup-data nil)
1330 (defvar gnus-newsgroup-data-reverse nil)
1331 (defvar gnus-newsgroup-limit nil)
1332 (defvar gnus-newsgroup-limits nil)
1333 (defvar gnus-summary-use-undownloaded-faces nil)
1334
1335 (defvar gnus-newsgroup-unreads nil
1336   "Sorted list of unread articles in the current newsgroup.")
1337
1338 (defvar gnus-newsgroup-unselected nil
1339   "Sorted list of unselected unread articles in the current newsgroup.")
1340
1341 (defvar gnus-newsgroup-reads nil
1342   "Alist of read articles and article marks in the current newsgroup.")
1343
1344 (defvar gnus-newsgroup-expunged-tally nil)
1345
1346 (defvar gnus-newsgroup-marked nil
1347   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1348
1349 (defvar gnus-newsgroup-spam-marked nil
1350   "List of ranges of articles that have been marked as spam.")
1351
1352 (defvar gnus-newsgroup-killed nil
1353   "List of ranges of articles that have been through the scoring process.")
1354
1355 (defvar gnus-newsgroup-cached nil
1356   "Sorted list of articles that come from the article cache.")
1357
1358 (defvar gnus-newsgroup-saved nil
1359   "List of articles that have been saved.")
1360
1361 (defvar gnus-newsgroup-kill-headers nil)
1362
1363 (defvar gnus-newsgroup-replied nil
1364   "List of articles that have been replied to in the current newsgroup.")
1365
1366 (defvar gnus-newsgroup-forwarded nil
1367   "List of articles that have been forwarded in the current newsgroup.")
1368
1369 (defvar gnus-newsgroup-recent nil
1370   "List of articles that have are recent in the current newsgroup.")
1371
1372 (defvar gnus-newsgroup-expirable nil
1373   "Sorted list of articles in the current newsgroup that can be expired.")
1374
1375 (defvar gnus-newsgroup-processable nil
1376   "List of articles in the current newsgroup that can be processed.")
1377
1378 (defvar gnus-newsgroup-downloadable nil
1379   "Sorted list of articles in the current newsgroup that can be processed.")
1380
1381 (defvar gnus-newsgroup-unfetched nil
1382   "Sorted list of articles in the current newsgroup whose headers have
1383 not been fetched into the agent.
1384
1385 This list will always be a subset of gnus-newsgroup-undownloaded.")
1386
1387 (defvar gnus-newsgroup-undownloaded nil
1388   "List of articles in the current newsgroup that haven't been downloaded.")
1389
1390 (defvar gnus-newsgroup-unsendable nil
1391   "List of articles in the current newsgroup that won't be sent.")
1392
1393 (defvar gnus-newsgroup-bookmarks nil
1394   "List of articles in the current newsgroup that have bookmarks.")
1395
1396 (defvar gnus-newsgroup-dormant nil
1397   "Sorted list of dormant articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-unseen nil
1400   "List of unseen articles in the current newsgroup.")
1401
1402 (defvar gnus-newsgroup-seen nil
1403   "Range of seen articles in the current newsgroup.")
1404
1405 (defvar gnus-newsgroup-articles nil
1406   "List of articles in the current newsgroup.")
1407
1408 (defvar gnus-newsgroup-scored nil
1409   "List of scored articles in the current newsgroup.")
1410
1411 (defvar gnus-newsgroup-headers nil
1412   "List of article headers in the current newsgroup.")
1413
1414 (defvar gnus-newsgroup-threads nil)
1415
1416 (defvar gnus-newsgroup-prepared nil
1417   "Whether the current group has been prepared properly.")
1418
1419 (defvar gnus-newsgroup-ancient nil
1420   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1421
1422 (defvar gnus-newsgroup-sparse nil)
1423
1424 (defvar gnus-current-article nil)
1425 (defvar gnus-article-current nil)
1426 (defvar gnus-current-headers nil)
1427 (defvar gnus-have-all-headers nil)
1428 (defvar gnus-last-article nil)
1429 (defvar gnus-newsgroup-history nil)
1430 (defvar gnus-newsgroup-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-charset nil)
1432 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1433
1434 (defvar gnus-article-before-search nil)
1435
1436 (defvar gnus-summary-local-variables
1437   '(gnus-newsgroup-name
1438     gnus-newsgroup-begin gnus-newsgroup-end
1439     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1440     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1441     gnus-newsgroup-last-directory
1442     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1443     gnus-newsgroup-unselected gnus-newsgroup-marked
1444     gnus-newsgroup-spam-marked
1445     gnus-newsgroup-reads gnus-newsgroup-saved
1446     gnus-newsgroup-replied gnus-newsgroup-forwarded
1447     gnus-newsgroup-recent
1448     gnus-newsgroup-expirable
1449     gnus-newsgroup-processable gnus-newsgroup-killed
1450     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1451     gnus-newsgroup-unfetched
1452     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1453     gnus-newsgroup-seen gnus-newsgroup-articles
1454     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1455     gnus-newsgroup-headers gnus-newsgroup-threads
1456     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1457     gnus-current-article gnus-current-headers gnus-have-all-headers
1458     gnus-last-article gnus-article-internal-prepare-hook
1459     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1460     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1461     gnus-thread-expunge-below
1462     gnus-score-alist gnus-current-score-file
1463     (gnus-summary-expunge-below . global)
1464     (gnus-summary-mark-below . global)
1465     (gnus-orphan-score . global)
1466     gnus-newsgroup-active gnus-scores-exclude-files
1467     gnus-newsgroup-history gnus-newsgroup-ancient
1468     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1469     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1470     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1471     (gnus-newsgroup-expunged-tally . 0)
1472     gnus-cache-removable-articles gnus-newsgroup-cached
1473     gnus-newsgroup-data gnus-newsgroup-data-reverse
1474     gnus-newsgroup-limit gnus-newsgroup-limits
1475     gnus-newsgroup-charset gnus-newsgroup-display
1476     gnus-summary-use-undownloaded-faces)
1477   "Variables that are buffer-local to the summary buffers.")
1478
1479 (defvar gnus-newsgroup-variables nil
1480   "A list of variables that have separate values in different newsgroups.
1481 A list of newsgroup (summary buffer) local variables, or cons of
1482 variables and their default expressions to be evalled (when the default
1483 values are not nil), that should be made global while the summary buffer
1484 is active.
1485
1486 Note: The default expressions will be evaluated (using function `eval')
1487 before assignment to the local variable rather than just assigned to it.
1488 If the default expression is the symbol `global', that symbol will not
1489 be evaluated but the global value of the local variable will be used
1490 instead.
1491
1492 These variables can be used to set variables in the group parameters
1493 while still allowing them to affect operations done in other buffers.
1494 For example:
1495
1496 \(setq gnus-newsgroup-variables
1497      '(message-use-followup-to
1498        (gnus-visible-headers .
1499          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1500 ")
1501
1502 ;; Byte-compiler warning.
1503 (eval-when-compile
1504   ;; Bind features so that require will believe that gnus-sum has
1505   ;; already been loaded (avoids infinite recursion)
1506   (let ((features (cons 'gnus-sum features)))
1507     ;; Several of the declarations in gnus-sum are needed to load the
1508     ;; following files. Right now, these definitions have been
1509     ;; compiled but not defined (evaluated).  We could either do a
1510     ;; eval-and-compile about all of the declarations or evaluate the
1511     ;; source file.
1512     (if (boundp 'gnus-newsgroup-variables)
1513         nil
1514       (load "gnus-sum.el" t t t))
1515     (require 'gnus)
1516     (require 'gnus-art)))
1517
1518 ;; MIME stuff.
1519
1520 (defvar gnus-decode-encoded-word-methods
1521   '(mail-decode-encoded-word-string)
1522   "List of methods used to decode encoded words.
1523
1524 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1525 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1526 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1527 whose names match REGEXP.
1528
1529 For example:
1530 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1531  mail-decode-encoded-word-string
1532  (\"chinese\" . rfc1843-decode-string))")
1533
1534 (defvar gnus-decode-encoded-word-methods-cache nil)
1535
1536 (defun gnus-multi-decode-encoded-word-string (string)
1537   "Apply the functions from `gnus-encoded-word-methods' that match."
1538   (unless (and gnus-decode-encoded-word-methods-cache
1539                (eq gnus-newsgroup-name
1540                    (car gnus-decode-encoded-word-methods-cache)))
1541     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1542     (mapcar (lambda (x)
1543               (if (symbolp x)
1544                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1545                 (if (and gnus-newsgroup-name
1546                          (string-match (car x) gnus-newsgroup-name))
1547                     (nconc gnus-decode-encoded-word-methods-cache
1548                            (list (cdr x))))))
1549             gnus-decode-encoded-word-methods))
1550   (let ((xlist gnus-decode-encoded-word-methods-cache))
1551     (pop xlist)
1552     (while xlist
1553       (setq string (funcall (pop xlist) string))))
1554   string)
1555
1556 ;; Subject simplification.
1557
1558 (defun gnus-simplify-whitespace (str)
1559   "Remove excessive whitespace from STR."
1560   ;; Multiple spaces.
1561   (while (string-match "[ \t][ \t]+" str)
1562     (setq str (concat (substring str 0 (match-beginning 0))
1563                         " "
1564                         (substring str (match-end 0)))))
1565   ;; Leading spaces.
1566   (when (string-match "^[ \t]+" str)
1567     (setq str (substring str (match-end 0))))
1568   ;; Trailing spaces.
1569   (when (string-match "[ \t]+$" str)
1570     (setq str (substring str 0 (match-beginning 0))))
1571   str)
1572
1573 (defun gnus-simplify-all-whitespace (str)
1574   "Remove all whitespace from STR."
1575   (while (string-match "[ \t\n]+" str)
1576     (setq str (replace-match "" nil nil str)))
1577   str)
1578
1579 (defsubst gnus-simplify-subject-re (subject)
1580   "Remove \"Re:\" from subject lines."
1581   (if (string-match message-subject-re-regexp subject)
1582       (substring subject (match-end 0))
1583     subject))
1584
1585 (defun gnus-simplify-subject (subject &optional re-only)
1586   "Remove `Re:' and words in parentheses.
1587 If RE-ONLY is non-nil, strip leading `Re:'s only."
1588   (let ((case-fold-search t))           ;Ignore case.
1589     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1590     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1591       (setq subject (substring subject (match-end 0))))
1592     ;; Remove uninteresting prefixes.
1593     (when (and (not re-only)
1594                gnus-simplify-ignored-prefixes
1595                (string-match gnus-simplify-ignored-prefixes subject))
1596       (setq subject (substring subject (match-end 0))))
1597     ;; Remove words in parentheses from end.
1598     (unless re-only
1599       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1600         (setq subject (substring subject 0 (match-beginning 0)))))
1601     ;; Return subject string.
1602     subject))
1603
1604 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1605 ;; all whitespace.
1606 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1607   (goto-char (point-min))
1608   (while (re-search-forward regexp nil t)
1609     (replace-match (or newtext ""))))
1610
1611 (defun gnus-simplify-buffer-fuzzy ()
1612   "Simplify string in the buffer fuzzily.
1613 The string in the accessible portion of the current buffer is simplified.
1614 It is assumed to be a single-line subject.
1615 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1616 matter is removed.  Additional things can be deleted by setting
1617 `gnus-simplify-subject-fuzzy-regexp'."
1618   (let ((case-fold-search t)
1619         (modified-tick))
1620     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1621
1622     (while (not (eq modified-tick (buffer-modified-tick)))
1623       (setq modified-tick (buffer-modified-tick))
1624       (cond
1625        ((listp gnus-simplify-subject-fuzzy-regexp)
1626         (mapcar 'gnus-simplify-buffer-fuzzy-step
1627                 gnus-simplify-subject-fuzzy-regexp))
1628        (gnus-simplify-subject-fuzzy-regexp
1629         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1630       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1631       (gnus-simplify-buffer-fuzzy-step
1632        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1633       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1634
1635     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1636     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1637     (gnus-simplify-buffer-fuzzy-step " $")
1638     (gnus-simplify-buffer-fuzzy-step "^ +")))
1639
1640 (defun gnus-simplify-subject-fuzzy (subject)
1641   "Simplify a subject string fuzzily.
1642 See `gnus-simplify-buffer-fuzzy' for details."
1643   (save-excursion
1644     (gnus-set-work-buffer)
1645     (let ((case-fold-search t))
1646       ;; Remove uninteresting prefixes.
1647       (when (and gnus-simplify-ignored-prefixes
1648                  (string-match gnus-simplify-ignored-prefixes subject))
1649         (setq subject (substring subject (match-end 0))))
1650       (insert subject)
1651       (inline (gnus-simplify-buffer-fuzzy))
1652       (buffer-string))))
1653
1654 (defsubst gnus-simplify-subject-fully (subject)
1655   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1656   (cond
1657    (gnus-simplify-subject-functions
1658     (gnus-map-function gnus-simplify-subject-functions subject))
1659    ((null gnus-summary-gather-subject-limit)
1660     (gnus-simplify-subject-re subject))
1661    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1662     (gnus-simplify-subject-fuzzy subject))
1663    ((numberp gnus-summary-gather-subject-limit)
1664     (gnus-limit-string (gnus-simplify-subject-re subject)
1665                        gnus-summary-gather-subject-limit))
1666    (t
1667     subject)))
1668
1669 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1670   "Check whether two subjects are equal.
1671 If optional argument SIMPLE-FIRST is t, first argument is already
1672 simplified."
1673   (cond
1674    ((null simple-first)
1675     (equal (gnus-simplify-subject-fully s1)
1676            (gnus-simplify-subject-fully s2)))
1677    (t
1678     (equal s1
1679            (gnus-simplify-subject-fully s2)))))
1680
1681 (defun gnus-summary-bubble-group ()
1682   "Increase the score of the current group.
1683 This is a handy function to add to `gnus-summary-exit-hook' to
1684 increase the score of each group you read."
1685   (gnus-group-add-score gnus-newsgroup-name))
1686
1687 \f
1688 ;;;
1689 ;;; Gnus summary mode
1690 ;;;
1691
1692 (put 'gnus-summary-mode 'mode-class 'special)
1693
1694 (defvar gnus-article-commands-menu)
1695
1696 ;; Non-orthogonal keys
1697
1698 (gnus-define-keys gnus-summary-mode-map
1699   " " gnus-summary-next-page
1700   "\177" gnus-summary-prev-page
1701   [delete] gnus-summary-prev-page
1702   [backspace] gnus-summary-prev-page
1703   "\r" gnus-summary-scroll-up
1704   "\M-\r" gnus-summary-scroll-down
1705   "n" gnus-summary-next-unread-article
1706   "p" gnus-summary-prev-unread-article
1707   "N" gnus-summary-next-article
1708   "P" gnus-summary-prev-article
1709   "\M-\C-n" gnus-summary-next-same-subject
1710   "\M-\C-p" gnus-summary-prev-same-subject
1711   "\M-n" gnus-summary-next-unread-subject
1712   "\M-p" gnus-summary-prev-unread-subject
1713   "." gnus-summary-first-unread-article
1714   "," gnus-summary-best-unread-article
1715   "\M-s" gnus-summary-search-article-forward
1716   "\M-r" gnus-summary-search-article-backward
1717   "\M-S" gnus-summary-repeat-search-article-forward
1718   "\M-R" gnus-summary-repeat-search-article-backward
1719   "<" gnus-summary-beginning-of-article
1720   ">" gnus-summary-end-of-article
1721   "j" gnus-summary-goto-article
1722   "^" gnus-summary-refer-parent-article
1723   "\M-^" gnus-summary-refer-article
1724   "u" gnus-summary-tick-article-forward
1725   "!" gnus-summary-tick-article-forward
1726   "U" gnus-summary-tick-article-backward
1727   "d" gnus-summary-mark-as-read-forward
1728   "D" gnus-summary-mark-as-read-backward
1729   "E" gnus-summary-mark-as-expirable
1730   "\M-u" gnus-summary-clear-mark-forward
1731   "\M-U" gnus-summary-clear-mark-backward
1732   "k" gnus-summary-kill-same-subject-and-select
1733   "\C-k" gnus-summary-kill-same-subject
1734   "\M-\C-k" gnus-summary-kill-thread
1735   "\M-\C-l" gnus-summary-lower-thread
1736   "e" gnus-summary-edit-article
1737   "#" gnus-summary-mark-as-processable
1738   "\M-#" gnus-summary-unmark-as-processable
1739   "\M-\C-t" gnus-summary-toggle-threads
1740   "\M-\C-s" gnus-summary-show-thread
1741   "\M-\C-h" gnus-summary-hide-thread
1742   "\M-\C-f" gnus-summary-next-thread
1743   "\M-\C-b" gnus-summary-prev-thread
1744   [(meta down)] gnus-summary-next-thread
1745   [(meta up)] gnus-summary-prev-thread
1746   "\M-\C-u" gnus-summary-up-thread
1747   "\M-\C-d" gnus-summary-down-thread
1748   "&" gnus-summary-execute-command
1749   "c" gnus-summary-catchup-and-exit
1750   "\C-w" gnus-summary-mark-region-as-read
1751   "\C-t" gnus-summary-toggle-truncation
1752   "?" gnus-summary-mark-as-dormant
1753   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1754   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1755   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1756   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1757   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1758   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1759   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1760   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1761   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1762   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1763   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1764   "=" gnus-summary-expand-window
1765   "\C-x\C-s" gnus-summary-reselect-current-group
1766   "\M-g" gnus-summary-rescan-group
1767   "w" gnus-summary-stop-page-breaking
1768   "\C-c\C-r" gnus-summary-caesar-message
1769   "f" gnus-summary-followup
1770   "F" gnus-summary-followup-with-original
1771   "C" gnus-summary-cancel-article
1772   "r" gnus-summary-reply
1773   "R" gnus-summary-reply-with-original
1774   "\C-c\C-f" gnus-summary-mail-forward
1775   "o" gnus-summary-save-article
1776   "\C-o" gnus-summary-save-article-mail
1777   "|" gnus-summary-pipe-output
1778   "\M-k" gnus-summary-edit-local-kill
1779   "\M-K" gnus-summary-edit-global-kill
1780   ;; "V" gnus-version
1781   "\C-c\C-d" gnus-summary-describe-group
1782   "q" gnus-summary-exit
1783   "Q" gnus-summary-exit-no-update
1784   "\C-c\C-i" gnus-info-find-node
1785   gnus-mouse-2 gnus-mouse-pick-article
1786   [follow-link] mouse-face
1787   "m" gnus-summary-mail-other-window
1788   "a" gnus-summary-post-news
1789   "i" gnus-summary-news-other-window
1790   "x" gnus-summary-limit-to-unread
1791   "s" gnus-summary-isearch-article
1792   "t" gnus-summary-toggle-header
1793   "g" gnus-summary-show-article
1794   "l" gnus-summary-goto-last-article
1795   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1796   "\C-d" gnus-summary-enter-digest-group
1797   "\M-\C-d" gnus-summary-read-document
1798   "\M-\C-e" gnus-summary-edit-parameters
1799   "\M-\C-a" gnus-summary-customize-parameters
1800   "\C-c\C-b" gnus-bug
1801   "*" gnus-cache-enter-article
1802   "\M-*" gnus-cache-remove-article
1803   "\M-&" gnus-summary-universal-argument
1804   "\C-l" gnus-recenter
1805   "I" gnus-summary-increase-score
1806   "L" gnus-summary-lower-score
1807   "\M-i" gnus-symbolic-argument
1808   "h" gnus-summary-select-article-buffer
1809
1810   "b" gnus-article-view-part
1811   "\M-t" gnus-summary-toggle-display-buttonized
1812
1813   "V" gnus-summary-score-map
1814   "X" gnus-uu-extract-map
1815   "S" gnus-summary-send-map)
1816
1817 ;; Sort of orthogonal keymap
1818 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1819   "t" gnus-summary-tick-article-forward
1820   "!" gnus-summary-tick-article-forward
1821   "d" gnus-summary-mark-as-read-forward
1822   "r" gnus-summary-mark-as-read-forward
1823   "c" gnus-summary-clear-mark-forward
1824   " " gnus-summary-clear-mark-forward
1825   "e" gnus-summary-mark-as-expirable
1826   "x" gnus-summary-mark-as-expirable
1827   "?" gnus-summary-mark-as-dormant
1828   "b" gnus-summary-set-bookmark
1829   "B" gnus-summary-remove-bookmark
1830   "#" gnus-summary-mark-as-processable
1831   "\M-#" gnus-summary-unmark-as-processable
1832   "S" gnus-summary-limit-include-expunged
1833   "C" gnus-summary-catchup
1834   "H" gnus-summary-catchup-to-here
1835   "h" gnus-summary-catchup-from-here
1836   "\C-c" gnus-summary-catchup-all
1837   "k" gnus-summary-kill-same-subject-and-select
1838   "K" gnus-summary-kill-same-subject
1839   "P" gnus-uu-mark-map)
1840
1841 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1842   "c" gnus-summary-clear-above
1843   "u" gnus-summary-tick-above
1844   "m" gnus-summary-mark-above
1845   "k" gnus-summary-kill-below)
1846
1847 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1848   "/" gnus-summary-limit-to-subject
1849   "n" gnus-summary-limit-to-articles
1850   "b" gnus-summary-limit-to-bodies
1851   "w" gnus-summary-pop-limit
1852   "s" gnus-summary-limit-to-subject
1853   "a" gnus-summary-limit-to-author
1854   "u" gnus-summary-limit-to-unread
1855   "m" gnus-summary-limit-to-marks
1856   "M" gnus-summary-limit-exclude-marks
1857   "v" gnus-summary-limit-to-score
1858   "*" gnus-summary-limit-include-cached
1859   "D" gnus-summary-limit-include-dormant
1860   "T" gnus-summary-limit-include-thread
1861   "d" gnus-summary-limit-exclude-dormant
1862   "t" gnus-summary-limit-to-age
1863   "." gnus-summary-limit-to-unseen
1864   "x" gnus-summary-limit-to-extra
1865   "p" gnus-summary-limit-to-display-predicate
1866   "E" gnus-summary-limit-include-expunged
1867   "c" gnus-summary-limit-exclude-childless-dormant
1868   "C" gnus-summary-limit-mark-excluded-as-read
1869   "o" gnus-summary-insert-old-articles
1870   "N" gnus-summary-insert-new-articles
1871   "r" gnus-summary-limit-to-replied
1872   "R" gnus-summary-limit-to-recipient)
1873
1874 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1875   "n" gnus-summary-next-unread-article
1876   "p" gnus-summary-prev-unread-article
1877   "N" gnus-summary-next-article
1878   "P" gnus-summary-prev-article
1879   "\C-n" gnus-summary-next-same-subject
1880   "\C-p" gnus-summary-prev-same-subject
1881   "\M-n" gnus-summary-next-unread-subject
1882   "\M-p" gnus-summary-prev-unread-subject
1883   "f" gnus-summary-first-unread-article
1884   "b" gnus-summary-best-unread-article
1885   "j" gnus-summary-goto-article
1886   "g" gnus-summary-goto-subject
1887   "l" gnus-summary-goto-last-article
1888   "o" gnus-summary-pop-article)
1889
1890 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1891   "k" gnus-summary-kill-thread
1892   "l" gnus-summary-lower-thread
1893   "i" gnus-summary-raise-thread
1894   "T" gnus-summary-toggle-threads
1895   "t" gnus-summary-rethread-current
1896   "^" gnus-summary-reparent-thread
1897   "\M-^" gnus-summary-reparent-children
1898   "s" gnus-summary-show-thread
1899   "S" gnus-summary-show-all-threads
1900   "h" gnus-summary-hide-thread
1901   "H" gnus-summary-hide-all-threads
1902   "n" gnus-summary-next-thread
1903   "p" gnus-summary-prev-thread
1904   "u" gnus-summary-up-thread
1905   "o" gnus-summary-top-thread
1906   "d" gnus-summary-down-thread
1907   "#" gnus-uu-mark-thread
1908   "\M-#" gnus-uu-unmark-thread)
1909
1910 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1911   "g" gnus-summary-prepare
1912   "c" gnus-summary-insert-cached-articles
1913   "d" gnus-summary-insert-dormant-articles)
1914
1915 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1916   "c" gnus-summary-catchup-and-exit
1917   "C" gnus-summary-catchup-all-and-exit
1918   "E" gnus-summary-exit-no-update
1919   "Q" gnus-summary-exit
1920   "Z" gnus-summary-exit
1921   "n" gnus-summary-catchup-and-goto-next-group
1922   "p" gnus-summary-catchup-and-goto-prev-group
1923   "R" gnus-summary-reselect-current-group
1924   "G" gnus-summary-rescan-group
1925   "N" gnus-summary-next-group
1926   "s" gnus-summary-save-newsrc
1927   "P" gnus-summary-prev-group)
1928
1929 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1930   " " gnus-summary-next-page
1931   "n" gnus-summary-next-page
1932   "\177" gnus-summary-prev-page
1933   [delete] gnus-summary-prev-page
1934   "p" gnus-summary-prev-page
1935   "\r" gnus-summary-scroll-up
1936   "\M-\r" gnus-summary-scroll-down
1937   "<" gnus-summary-beginning-of-article
1938   ">" gnus-summary-end-of-article
1939   "b" gnus-summary-beginning-of-article
1940   "e" gnus-summary-end-of-article
1941   "^" gnus-summary-refer-parent-article
1942   "r" gnus-summary-refer-parent-article
1943   "D" gnus-summary-enter-digest-group
1944   "R" gnus-summary-refer-references
1945   "T" gnus-summary-refer-thread
1946   "g" gnus-summary-show-article
1947   "s" gnus-summary-isearch-article
1948   "P" gnus-summary-print-article
1949   "M" gnus-mailing-list-insinuate
1950   "t" gnus-article-babel)
1951
1952 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1953   "b" gnus-article-add-buttons
1954   "B" gnus-article-add-buttons-to-head
1955   "o" gnus-article-treat-overstrike
1956   "e" gnus-article-emphasize
1957   "w" gnus-article-fill-cited-article
1958   "Q" gnus-article-fill-long-lines
1959   "L" gnus-article-toggle-truncate-lines
1960   "C" gnus-article-capitalize-sentences
1961   "c" gnus-article-remove-cr
1962   "q" gnus-article-de-quoted-unreadable
1963   "6" gnus-article-de-base64-unreadable
1964   "Z" gnus-article-decode-HZ
1965   "A" gnus-article-treat-ansi-sequences
1966   "h" gnus-article-wash-html
1967   "u" gnus-article-unsplit-urls
1968   "s" gnus-summary-force-verify-and-decrypt
1969   "f" gnus-article-display-x-face
1970   "l" gnus-summary-stop-page-breaking
1971   "r" gnus-summary-caesar-message
1972   "m" gnus-summary-morse-message
1973   "t" gnus-summary-toggle-header
1974   "g" gnus-treat-smiley
1975   "v" gnus-summary-verbose-headers
1976   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1977   "p" gnus-article-verify-x-pgp-sig
1978   "d" gnus-article-treat-dumbquotes
1979   "i" gnus-summary-idna-message)
1980
1981 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1982   ;; mnemonic: deuglif*Y*
1983   "u" gnus-article-outlook-unwrap-lines
1984   "a" gnus-article-outlook-repair-attribution
1985   "c" gnus-article-outlook-rearrange-citation
1986   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1987
1988 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1989   "a" gnus-article-hide
1990   "h" gnus-article-hide-headers
1991   "b" gnus-article-hide-boring-headers
1992   "s" gnus-article-hide-signature
1993   "c" gnus-article-hide-citation
1994   "C" gnus-article-hide-citation-in-followups
1995   "l" gnus-article-hide-list-identifiers
1996   "B" gnus-article-strip-banner
1997   "P" gnus-article-hide-pem
1998   "\C-c" gnus-article-hide-citation-maybe)
1999
2000 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2001   "a" gnus-article-highlight
2002   "h" gnus-article-highlight-headers
2003   "c" gnus-article-highlight-citation
2004   "s" gnus-article-highlight-signature)
2005
2006 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2007   "f" gnus-article-treat-fold-headers
2008   "u" gnus-article-treat-unfold-headers
2009   "n" gnus-article-treat-fold-newsgroups)
2010
2011 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2012   "x" gnus-article-display-x-face
2013   "d" gnus-article-display-face
2014   "s" gnus-treat-smiley
2015   "D" gnus-article-remove-images
2016   "f" gnus-treat-from-picon
2017   "m" gnus-treat-mail-picon
2018   "n" gnus-treat-newsgroups-picon)
2019
2020 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2021   "w" gnus-article-decode-mime-words
2022   "c" gnus-article-decode-charset
2023   "v" gnus-mime-view-all-parts
2024   "b" gnus-article-view-part)
2025
2026 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2027   "z" gnus-article-date-ut
2028   "u" gnus-article-date-ut
2029   "l" gnus-article-date-local
2030   "p" gnus-article-date-english
2031   "e" gnus-article-date-lapsed
2032   "o" gnus-article-date-original
2033   "i" gnus-article-date-iso8601
2034   "s" gnus-article-date-user)
2035
2036 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2037   "t" gnus-article-remove-trailing-blank-lines
2038   "l" gnus-article-strip-leading-blank-lines
2039   "m" gnus-article-strip-multiple-blank-lines
2040   "a" gnus-article-strip-blank-lines
2041   "A" gnus-article-strip-all-blank-lines
2042   "s" gnus-article-strip-leading-space
2043   "e" gnus-article-strip-trailing-space
2044   "w" gnus-article-remove-leading-whitespace)
2045
2046 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2047   "v" gnus-version
2048   "f" gnus-summary-fetch-faq
2049   "d" gnus-summary-describe-group
2050   "h" gnus-summary-describe-briefly
2051   "i" gnus-info-find-node
2052   "c" gnus-group-fetch-charter
2053   "C" gnus-group-fetch-control)
2054
2055 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2056   "e" gnus-summary-expire-articles
2057   "\M-\C-e" gnus-summary-expire-articles-now
2058   "\177" gnus-summary-delete-article
2059   [delete] gnus-summary-delete-article
2060   [backspace] gnus-summary-delete-article
2061   "m" gnus-summary-move-article
2062   "r" gnus-summary-respool-article
2063   "w" gnus-summary-edit-article
2064   "c" gnus-summary-copy-article
2065   "B" gnus-summary-crosspost-article
2066   "q" gnus-summary-respool-query
2067   "t" gnus-summary-respool-trace
2068   "i" gnus-summary-import-article
2069   "I" gnus-summary-create-article
2070   "p" gnus-summary-article-posted-p)
2071
2072 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2073   "o" gnus-summary-save-article
2074   "m" gnus-summary-save-article-mail
2075   "F" gnus-summary-write-article-file
2076   "r" gnus-summary-save-article-rmail
2077   "f" gnus-summary-save-article-file
2078   "b" gnus-summary-save-article-body-file
2079   "B" gnus-summary-write-article-body-file
2080   "h" gnus-summary-save-article-folder
2081   "v" gnus-summary-save-article-vm
2082   "p" gnus-summary-pipe-output
2083   "P" gnus-summary-muttprint
2084   "s" gnus-soup-add-article)
2085
2086 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2087   "b" gnus-summary-display-buttonized
2088   "m" gnus-summary-repair-multipart
2089   "v" gnus-article-view-part
2090   "o" gnus-article-save-part
2091   "O" gnus-article-save-part-and-strip
2092   "r" gnus-article-replace-part
2093   "d" gnus-article-delete-part
2094   "t" gnus-article-view-part-as-type
2095   "j" gnus-article-jump-to-part
2096   "c" gnus-article-copy-part
2097   "C" gnus-article-view-part-as-charset
2098   "e" gnus-article-view-part-externally
2099   "H" gnus-article-browse-html-article
2100   "E" gnus-article-encrypt-body
2101   "i" gnus-article-inline-part
2102   "|" gnus-article-pipe-part)
2103
2104 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2105   "p" gnus-summary-mark-as-processable
2106   "u" gnus-summary-unmark-as-processable
2107   "U" gnus-summary-unmark-all-processable
2108   "v" gnus-uu-mark-over
2109   "s" gnus-uu-mark-series
2110   "r" gnus-uu-mark-region
2111   "g" gnus-uu-unmark-region
2112   "R" gnus-uu-mark-by-regexp
2113   "G" gnus-uu-unmark-by-regexp
2114   "t" gnus-uu-mark-thread
2115   "T" gnus-uu-unmark-thread
2116   "a" gnus-uu-mark-all
2117   "b" gnus-uu-mark-buffer
2118   "S" gnus-uu-mark-sparse
2119   "k" gnus-summary-kill-process-mark
2120   "y" gnus-summary-yank-process-mark
2121   "w" gnus-summary-save-process-mark
2122   "i" gnus-uu-invert-processable)
2123
2124 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2125   ;;"x" gnus-uu-extract-any
2126   "m" gnus-summary-save-parts
2127   "u" gnus-uu-decode-uu
2128   "U" gnus-uu-decode-uu-and-save
2129   "s" gnus-uu-decode-unshar
2130   "S" gnus-uu-decode-unshar-and-save
2131   "o" gnus-uu-decode-save
2132   "O" gnus-uu-decode-save
2133   "b" gnus-uu-decode-binhex
2134   "B" gnus-uu-decode-binhex
2135   "p" gnus-uu-decode-postscript
2136   "P" gnus-uu-decode-postscript-and-save)
2137
2138 (gnus-define-keys
2139     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2140   "u" gnus-uu-decode-uu-view
2141   "U" gnus-uu-decode-uu-and-save-view
2142   "s" gnus-uu-decode-unshar-view
2143   "S" gnus-uu-decode-unshar-and-save-view
2144   "o" gnus-uu-decode-save-view
2145   "O" gnus-uu-decode-save-view
2146   "b" gnus-uu-decode-binhex-view
2147   "B" gnus-uu-decode-binhex-view
2148   "p" gnus-uu-decode-postscript-view
2149   "P" gnus-uu-decode-postscript-and-save-view)
2150
2151 (defvar gnus-article-post-menu nil)
2152
2153 (defconst gnus-summary-menu-maxlen 20)
2154
2155 (defun gnus-summary-menu-split (menu)
2156   ;; If we have lots of elements, divide them into groups of 20
2157   ;; and make a pane (or submenu) for each one.
2158   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2159       (let ((menu menu) sublists next
2160             (i 1))
2161         (while menu
2162           ;; Pull off the next gnus-summary-menu-maxlen elements
2163           ;; and make them the next element of sublist.
2164           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2165           (if next
2166               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2167                       nil))
2168           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2169                                              (aref (car (last menu)) 0)) menu)
2170                                sublists))
2171           (setq i (1+ i))
2172           (setq menu next))
2173         (nreverse sublists))
2174     ;; Few elements--put them all in one pane.
2175     menu))
2176
2177 (defun gnus-summary-make-menu-bar ()
2178   (gnus-turn-off-edit-menu 'summary)
2179
2180   (unless (boundp 'gnus-summary-misc-menu)
2181
2182     (easy-menu-define
2183       gnus-summary-kill-menu gnus-summary-mode-map ""
2184       (cons
2185        "Score"
2186        (nconc
2187         (list
2188          ["Customize" gnus-score-customize t])
2189         (gnus-make-score-map 'increase)
2190         (gnus-make-score-map 'lower)
2191         '(("Mark"
2192            ["Kill below" gnus-summary-kill-below t]
2193            ["Mark above" gnus-summary-mark-above t]
2194            ["Tick above" gnus-summary-tick-above t]
2195            ["Clear above" gnus-summary-clear-above t])
2196           ["Current score" gnus-summary-current-score t]
2197           ["Set score" gnus-summary-set-score t]
2198           ["Switch current score file..." gnus-score-change-score-file t]
2199           ["Set mark below..." gnus-score-set-mark-below t]
2200           ["Set expunge below..." gnus-score-set-expunge-below t]
2201           ["Edit current score file" gnus-score-edit-current-scores t]
2202           ["Edit score file" gnus-score-edit-file t]
2203           ["Trace score" gnus-score-find-trace t]
2204           ["Find words" gnus-score-find-favourite-words t]
2205           ["Rescore buffer" gnus-summary-rescore t]
2206           ["Increase score..." gnus-summary-increase-score t]
2207           ["Lower score..." gnus-summary-lower-score t]))))
2208
2209     ;; Define both the Article menu in the summary buffer and the
2210     ;; equivalent Commands menu in the article buffer here for
2211     ;; consistency.
2212     (let ((innards
2213            `(("Hide"
2214               ["All" gnus-article-hide t]
2215               ["Headers" gnus-article-hide-headers t]
2216               ["Signature" gnus-article-hide-signature t]
2217               ["Citation" gnus-article-hide-citation t]
2218               ["List identifiers" gnus-article-hide-list-identifiers t]
2219               ["Banner" gnus-article-strip-banner t]
2220               ["Boring headers" gnus-article-hide-boring-headers t])
2221              ("Highlight"
2222               ["All" gnus-article-highlight t]
2223               ["Headers" gnus-article-highlight-headers t]
2224               ["Signature" gnus-article-highlight-signature t]
2225               ["Citation" gnus-article-highlight-citation t])
2226              ("MIME"
2227               ["Words" gnus-article-decode-mime-words t]
2228               ["Charset" gnus-article-decode-charset t]
2229               ["QP" gnus-article-de-quoted-unreadable t]
2230               ["Base64" gnus-article-de-base64-unreadable t]
2231               ["View MIME buttons" gnus-summary-display-buttonized t]
2232               ["View all" gnus-mime-view-all-parts t]
2233               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2234               ["Encrypt body" gnus-article-encrypt-body
2235                :active (not (gnus-group-read-only-p))
2236                ,@(if (featurep 'xemacs) nil
2237                    '(:help "Encrypt the message body on disk"))]
2238               ["Extract all parts..." gnus-summary-save-parts t]
2239               ("Multipart"
2240                ["Repair multipart" gnus-summary-repair-multipart t]
2241                ["Pipe part..." gnus-article-pipe-part t]
2242                ["Inline part" gnus-article-inline-part t]
2243                ["View part as type..." gnus-article-view-part-as-type t]
2244                ["Encrypt body" gnus-article-encrypt-body
2245                 :active (not (gnus-group-read-only-p))
2246                ,@(if (featurep 'xemacs) nil
2247                    '(:help "Encrypt the message body on disk"))]
2248                ["View part externally" gnus-article-view-part-externally t]
2249                ["View HTML parts in browser" gnus-article-browse-html-article t]
2250                ["View part with charset..." gnus-article-view-part-as-charset t]
2251                ["Copy part" gnus-article-copy-part t]
2252                ["Save part..." gnus-article-save-part t]
2253                ["View part" gnus-article-view-part t]))
2254              ("Date"
2255               ["Local" gnus-article-date-local t]
2256               ["ISO8601" gnus-article-date-iso8601 t]
2257               ["UT" gnus-article-date-ut t]
2258               ["Original" gnus-article-date-original t]
2259               ["Lapsed" gnus-article-date-lapsed t]
2260               ["User-defined" gnus-article-date-user t])
2261              ("Display"
2262               ["Remove images" gnus-article-remove-images t]
2263               ["Toggle smiley" gnus-treat-smiley t]
2264               ["Show X-Face" gnus-article-display-x-face t]
2265               ["Show picons in From" gnus-treat-from-picon t]
2266               ["Show picons in mail headers" gnus-treat-mail-picon t]
2267               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2268               ("View as different encoding"
2269                ,@(gnus-summary-menu-split
2270                   (mapcar
2271                    (lambda (cs)
2272                      ;; Since easymenu under Emacs doesn't allow
2273                      ;; lambda forms for menu commands, we should
2274                      ;; provide intern'ed function symbols.
2275                      (let ((command (intern (format "\
2276 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2277                        (fset command
2278                              `(lambda ()
2279                                 (interactive)
2280                                 (let ((gnus-summary-show-article-charset-alist
2281                                        '((1 . ,cs))))
2282                                   (gnus-summary-show-article 1))))
2283                        `[,(symbol-name cs) ,command t]))
2284                    (sort (if (fboundp 'coding-system-list)
2285                              (coding-system-list)
2286                            (mapcar 'car mm-mime-mule-charset-alist))
2287                          'string<)))))
2288              ("Washing"
2289               ("Remove Blanks"
2290                ["Leading" gnus-article-strip-leading-blank-lines t]
2291                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2292                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2293                ["All of the above" gnus-article-strip-blank-lines t]
2294                ["All" gnus-article-strip-all-blank-lines t]
2295                ["Leading space" gnus-article-strip-leading-space t]
2296                ["Trailing space" gnus-article-strip-trailing-space t]
2297                ["Leading space in headers"
2298                 gnus-article-remove-leading-whitespace t])
2299               ["Overstrike" gnus-article-treat-overstrike t]
2300               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2301               ["Emphasis" gnus-article-emphasize t]
2302               ["Word wrap" gnus-article-fill-cited-article t]
2303               ["Fill long lines" gnus-article-fill-long-lines t]
2304               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2305               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2306               ["Remove CR" gnus-article-remove-cr t]
2307               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2308               ["Base64" gnus-article-de-base64-unreadable t]
2309               ["Rot 13" gnus-summary-caesar-message
2310                ,@(if (featurep 'xemacs) '(t)
2311                    '(:help "\"Caesar rotate\" article by 13"))]
2312               ["De-IDNA" gnus-summary-idna-message t]
2313               ["Morse decode" gnus-summary-morse-message t]
2314               ["Unix pipe..." gnus-summary-pipe-message t]
2315               ["Add buttons" gnus-article-add-buttons t]
2316               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2317               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2318               ["Verbose header" gnus-summary-verbose-headers t]
2319               ["Toggle header" gnus-summary-toggle-header t]
2320               ["Unfold headers" gnus-article-treat-unfold-headers t]
2321               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2322               ["Html" gnus-article-wash-html t]
2323               ["Unsplit URLs" gnus-article-unsplit-urls t]
2324               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2325               ["Decode HZ" gnus-article-decode-HZ t]
2326               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2327               ("(Outlook) Deuglify"
2328                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2329                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2330                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2331                ["Full (Outlook) deuglify"
2332                 gnus-article-outlook-deuglify-article t])
2333               )
2334              ("Output"
2335               ["Save in default format..." gnus-summary-save-article
2336                ,@(if (featurep 'xemacs) '(t)
2337                    '(:help "Save article using default method"))]
2338               ["Save in file..." gnus-summary-save-article-file
2339                ,@(if (featurep 'xemacs) '(t)
2340                    '(:help "Save article in file"))]
2341               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2342               ["Save in MH folder..." gnus-summary-save-article-folder t]
2343               ["Save in VM folder..." gnus-summary-save-article-vm t]
2344               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2345               ["Save body in file..." gnus-summary-save-article-body-file t]
2346               ["Pipe through a filter..." gnus-summary-pipe-output t]
2347               ["Add to SOUP packet" gnus-soup-add-article t]
2348               ["Print with Muttprint..." gnus-summary-muttprint t]
2349               ["Print" gnus-summary-print-article
2350                ,@(if (featurep 'xemacs) '(t)
2351                    '(:help "Generate and print a PostScript image"))])
2352              ("Copy, move,... (Backend)"
2353               ,@(if (featurep 'xemacs) nil
2354                   '(:help "Copying, moving, expiring articles..."))
2355               ["Respool article..." gnus-summary-respool-article t]
2356               ["Move article..." gnus-summary-move-article
2357                (gnus-check-backend-function
2358                 'request-move-article gnus-newsgroup-name)]
2359               ["Copy article..." gnus-summary-copy-article t]
2360               ["Crosspost article..." gnus-summary-crosspost-article
2361                (gnus-check-backend-function
2362                 'request-replace-article gnus-newsgroup-name)]
2363               ["Import file..." gnus-summary-import-article
2364                (gnus-check-backend-function
2365                 'request-accept-article gnus-newsgroup-name)]
2366               ["Create article..." gnus-summary-create-article
2367                (gnus-check-backend-function
2368                 'request-accept-article gnus-newsgroup-name)]
2369               ["Check if posted" gnus-summary-article-posted-p t]
2370               ["Edit article" gnus-summary-edit-article
2371                (not (gnus-group-read-only-p))]
2372               ["Delete article" gnus-summary-delete-article
2373                (gnus-check-backend-function
2374                 'request-expire-articles gnus-newsgroup-name)]
2375               ["Query respool" gnus-summary-respool-query t]
2376               ["Trace respool" gnus-summary-respool-trace t]
2377               ["Delete expirable articles" gnus-summary-expire-articles-now
2378                (gnus-check-backend-function
2379                 'request-expire-articles gnus-newsgroup-name)])
2380              ("Extract"
2381               ["Uudecode" gnus-uu-decode-uu
2382                ,@(if (featurep 'xemacs) '(t)
2383                    '(:help "Decode uuencoded article(s)"))]
2384               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2385               ["Unshar" gnus-uu-decode-unshar t]
2386               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2387               ["Save" gnus-uu-decode-save t]
2388               ["Binhex" gnus-uu-decode-binhex t]
2389               ["Postscript" gnus-uu-decode-postscript t]
2390               ["All MIME parts" gnus-summary-save-parts t])
2391              ("Cache"
2392               ["Enter article" gnus-cache-enter-article t]
2393               ["Remove article" gnus-cache-remove-article t])
2394              ["Translate" gnus-article-babel t]
2395              ["Select article buffer" gnus-summary-select-article-buffer t]
2396              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2397              ["Isearch article..." gnus-summary-isearch-article t]
2398              ["Beginning of the article" gnus-summary-beginning-of-article t]
2399              ["End of the article" gnus-summary-end-of-article t]
2400              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2401              ["Fetch referenced articles" gnus-summary-refer-references t]
2402              ["Fetch current thread" gnus-summary-refer-thread t]
2403              ["Fetch article with id..." gnus-summary-refer-article t]
2404              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2405              ["Redisplay" gnus-summary-show-article t]
2406              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2407       (easy-menu-define
2408         gnus-summary-article-menu gnus-summary-mode-map ""
2409         (cons "Article" innards))
2410
2411       (if (not (keymapp gnus-summary-article-menu))
2412           (easy-menu-define
2413             gnus-article-commands-menu gnus-article-mode-map ""
2414             (cons "Commands" innards))
2415         ;; in Emacs, don't share menu.
2416         (setq gnus-article-commands-menu
2417               (copy-keymap gnus-summary-article-menu))
2418         (define-key gnus-article-mode-map [menu-bar commands]
2419           (cons "Commands" gnus-article-commands-menu))))
2420
2421     (easy-menu-define
2422       gnus-summary-thread-menu gnus-summary-mode-map ""
2423       '("Threads"
2424         ["Find all messages in thread" gnus-summary-refer-thread t]
2425         ["Toggle threading" gnus-summary-toggle-threads t]
2426         ["Hide threads" gnus-summary-hide-all-threads t]
2427         ["Show threads" gnus-summary-show-all-threads t]
2428         ["Hide thread" gnus-summary-hide-thread t]
2429         ["Show thread" gnus-summary-show-thread t]
2430         ["Go to next thread" gnus-summary-next-thread t]
2431         ["Go to previous thread" gnus-summary-prev-thread t]
2432         ["Go down thread" gnus-summary-down-thread t]
2433         ["Go up thread" gnus-summary-up-thread t]
2434         ["Top of thread" gnus-summary-top-thread t]
2435         ["Mark thread as read" gnus-summary-kill-thread t]
2436         ["Lower thread score" gnus-summary-lower-thread t]
2437         ["Raise thread score" gnus-summary-raise-thread t]
2438         ["Rethread current" gnus-summary-rethread-current t]))
2439
2440     (easy-menu-define
2441       gnus-summary-post-menu gnus-summary-mode-map ""
2442       `("Post"
2443         ["Send a message (mail or news)" gnus-summary-post-news
2444          ,@(if (featurep 'xemacs) '(t)
2445              '(:help "Compose a new message (mail or news)"))]
2446         ["Followup" gnus-summary-followup
2447          ,@(if (featurep 'xemacs) '(t)
2448              '(:help "Post followup to this article"))]
2449         ["Followup and yank" gnus-summary-followup-with-original
2450          ,@(if (featurep 'xemacs) '(t)
2451              '(:help "Post followup to this article, quoting its contents"))]
2452         ["Supersede article" gnus-summary-supersede-article t]
2453         ["Cancel article" gnus-summary-cancel-article
2454          ,@(if (featurep 'xemacs) '(t)
2455              '(:help "Cancel an article you posted"))]
2456         ["Reply" gnus-summary-reply t]
2457         ["Reply and yank" gnus-summary-reply-with-original t]
2458         ["Wide reply" gnus-summary-wide-reply t]
2459         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2460          ,@(if (featurep 'xemacs) '(t)
2461              '(:help "Mail a reply, quoting this article"))]
2462         ["Very wide reply" gnus-summary-very-wide-reply t]
2463         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2464          ,@(if (featurep 'xemacs) '(t)
2465              '(:help "Mail a very wide reply, quoting this article"))]
2466         ["Mail forward" gnus-summary-mail-forward t]
2467         ["Post forward" gnus-summary-post-forward t]
2468         ["Digest and mail" gnus-uu-digest-mail-forward t]
2469         ["Digest and post" gnus-uu-digest-post-forward t]
2470         ["Resend message" gnus-summary-resend-message t]
2471         ["Resend message edit" gnus-summary-resend-message-edit t]
2472         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2473         ["Send a mail" gnus-summary-mail-other-window t]
2474         ["Create a local message" gnus-summary-news-other-window t]
2475         ["Uuencode and post" gnus-uu-post-news
2476          ,@(if (featurep 'xemacs) '(t)
2477              '(:help "Post a uuencoded article"))]
2478         ["Followup via news" gnus-summary-followup-to-mail t]
2479         ["Followup via news and yank"
2480          gnus-summary-followup-to-mail-with-original t]
2481         ;;("Draft"
2482         ;;["Send" gnus-summary-send-draft t]
2483         ;;["Send bounced" gnus-resend-bounced-mail t])
2484         ))
2485
2486     (cond
2487      ((not (keymapp gnus-summary-post-menu))
2488       (setq gnus-article-post-menu gnus-summary-post-menu))
2489      ((not gnus-article-post-menu)
2490       ;; Don't share post menu.
2491       (setq gnus-article-post-menu
2492             (copy-keymap gnus-summary-post-menu))))
2493     (define-key gnus-article-mode-map [menu-bar post]
2494       (cons "Post" gnus-article-post-menu))
2495
2496     (easy-menu-define
2497       gnus-summary-misc-menu gnus-summary-mode-map ""
2498       `("Gnus"
2499         ("Mark Read"
2500          ["Mark as read" gnus-summary-mark-as-read-forward t]
2501          ["Mark same subject and select"
2502           gnus-summary-kill-same-subject-and-select t]
2503          ["Mark same subject" gnus-summary-kill-same-subject t]
2504          ["Catchup" gnus-summary-catchup
2505           ,@(if (featurep 'xemacs) '(t)
2506               '(:help "Mark unread articles in this group as read"))]
2507          ["Catchup all" gnus-summary-catchup-all t]
2508          ["Catchup to here" gnus-summary-catchup-to-here t]
2509          ["Catchup from here" gnus-summary-catchup-from-here t]
2510          ["Catchup region" gnus-summary-mark-region-as-read
2511           (gnus-mark-active-p)]
2512          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2513         ("Mark Various"
2514          ["Tick" gnus-summary-tick-article-forward t]
2515          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2516          ["Remove marks" gnus-summary-clear-mark-forward t]
2517          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2518          ["Set bookmark" gnus-summary-set-bookmark t]
2519          ["Remove bookmark" gnus-summary-remove-bookmark t])
2520         ("Limit to"
2521          ["Marks..." gnus-summary-limit-to-marks t]
2522          ["Subject..." gnus-summary-limit-to-subject t]
2523          ["Author..." gnus-summary-limit-to-author t]
2524          ["Recipient..." gnus-summary-limit-to-recipient t]
2525          ["Age..." gnus-summary-limit-to-age t]
2526          ["Extra..." gnus-summary-limit-to-extra t]
2527          ["Score..." gnus-summary-limit-to-score t]
2528          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2529          ["Unread" gnus-summary-limit-to-unread t]
2530          ["Unseen" gnus-summary-limit-to-unseen t]
2531          ["Replied" gnus-summary-limit-to-replied t]
2532          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2533          ["Next articles" gnus-summary-limit-to-articles t]
2534          ["Pop limit" gnus-summary-pop-limit t]
2535          ["Show dormant" gnus-summary-limit-include-dormant t]
2536          ["Hide childless dormant"
2537           gnus-summary-limit-exclude-childless-dormant t]
2538          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2539          ["Hide marked" gnus-summary-limit-exclude-marks t]
2540          ["Show expunged" gnus-summary-limit-include-expunged t])
2541         ("Process Mark"
2542          ["Set mark" gnus-summary-mark-as-processable t]
2543          ["Remove mark" gnus-summary-unmark-as-processable t]
2544          ["Remove all marks" gnus-summary-unmark-all-processable t]
2545          ["Invert marks" gnus-uu-invert-processable t]
2546          ["Mark above" gnus-uu-mark-over t]
2547          ["Mark series" gnus-uu-mark-series t]
2548          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2549          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2550          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2551          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2552          ["Mark all" gnus-uu-mark-all t]
2553          ["Mark buffer" gnus-uu-mark-buffer t]
2554          ["Mark sparse" gnus-uu-mark-sparse t]
2555          ["Mark thread" gnus-uu-mark-thread t]
2556          ["Unmark thread" gnus-uu-unmark-thread t]
2557          ("Process Mark Sets"
2558           ["Kill" gnus-summary-kill-process-mark t]
2559           ["Yank" gnus-summary-yank-process-mark
2560            gnus-newsgroup-process-stack]
2561           ["Save" gnus-summary-save-process-mark t]
2562           ["Run command on marked..." gnus-summary-universal-argument t]))
2563         ("Scroll article"
2564          ["Page forward" gnus-summary-next-page
2565           ,@(if (featurep 'xemacs) '(t)
2566               '(:help "Show next page of article"))]
2567          ["Page backward" gnus-summary-prev-page
2568           ,@(if (featurep 'xemacs) '(t)
2569               '(:help "Show previous page of article"))]
2570          ["Line forward" gnus-summary-scroll-up t])
2571         ("Move"
2572          ["Next unread article" gnus-summary-next-unread-article t]
2573          ["Previous unread article" gnus-summary-prev-unread-article t]
2574          ["Next article" gnus-summary-next-article t]
2575          ["Previous article" gnus-summary-prev-article t]
2576          ["Next unread subject" gnus-summary-next-unread-subject t]
2577          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2578          ["Next article same subject" gnus-summary-next-same-subject t]
2579          ["Previous article same subject" gnus-summary-prev-same-subject t]
2580          ["First unread article" gnus-summary-first-unread-article t]
2581          ["Best unread article" gnus-summary-best-unread-article t]
2582          ["Go to subject number..." gnus-summary-goto-subject t]
2583          ["Go to article number..." gnus-summary-goto-article t]
2584          ["Go to the last article" gnus-summary-goto-last-article t]
2585          ["Pop article off history" gnus-summary-pop-article t])
2586         ("Sort"
2587          ["Sort by number" gnus-summary-sort-by-number t]
2588          ["Sort by author" gnus-summary-sort-by-author t]
2589          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2590          ["Sort by subject" gnus-summary-sort-by-subject t]
2591          ["Sort by date" gnus-summary-sort-by-date t]
2592          ["Sort by score" gnus-summary-sort-by-score t]
2593          ["Sort by lines" gnus-summary-sort-by-lines t]
2594          ["Sort by characters" gnus-summary-sort-by-chars t]
2595          ["Randomize" gnus-summary-sort-by-random t]
2596          ["Original sort" gnus-summary-sort-by-original t])
2597         ("Help"
2598          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2599          ["Describe group" gnus-summary-describe-group t]
2600          ["Fetch charter" gnus-group-fetch-charter
2601           ,@(if (featurep 'xemacs) nil
2602               '(:help "Display the charter of the current group"))]
2603          ["Fetch control message" gnus-group-fetch-control
2604           ,@(if (featurep 'xemacs) nil
2605               '(:help "Display the archived control message for the current group"))]
2606          ["Read manual" gnus-info-find-node t])
2607         ("Modes"
2608          ["Pick and read" gnus-pick-mode t]
2609          ["Binary" gnus-binary-mode t])
2610         ("Regeneration"
2611          ["Regenerate" gnus-summary-prepare t]
2612          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2613          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2614          ["Toggle threading" gnus-summary-toggle-threads t])
2615         ["See old articles" gnus-summary-insert-old-articles t]
2616         ["See new articles" gnus-summary-insert-new-articles t]
2617         ["Filter articles..." gnus-summary-execute-command t]
2618         ["Run command on articles..." gnus-summary-universal-argument t]
2619         ["Search articles forward..." gnus-summary-search-article-forward t]
2620         ["Search articles backward..." gnus-summary-search-article-backward t]
2621         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2622         ["Expand window" gnus-summary-expand-window t]
2623         ["Expire expirable articles" gnus-summary-expire-articles
2624          (gnus-check-backend-function
2625           'request-expire-articles gnus-newsgroup-name)]
2626         ["Edit local kill file" gnus-summary-edit-local-kill t]
2627         ["Edit main kill file" gnus-summary-edit-global-kill t]
2628         ["Edit group parameters" gnus-summary-edit-parameters t]
2629         ["Customize group parameters" gnus-summary-customize-parameters t]
2630         ["Send a bug report" gnus-bug t]
2631         ("Exit"
2632          ["Catchup and exit" gnus-summary-catchup-and-exit
2633           ,@(if (featurep 'xemacs) '(t)
2634               '(:help "Mark unread articles in this group as read, then exit"))]
2635          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2636          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2637          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2638          ["Exit group" gnus-summary-exit
2639           ,@(if (featurep 'xemacs) '(t)
2640               '(:help "Exit current group, return to group selection mode"))]
2641          ["Exit group without updating" gnus-summary-exit-no-update t]
2642          ["Exit and goto next group" gnus-summary-next-group t]
2643          ["Exit and goto prev group" gnus-summary-prev-group t]
2644          ["Reselect group" gnus-summary-reselect-current-group t]
2645          ["Rescan group" gnus-summary-rescan-group t]
2646          ["Update dribble" gnus-summary-save-newsrc t])))
2647
2648     (gnus-run-hooks 'gnus-summary-menu-hook)))
2649
2650 (defvar gnus-summary-tool-bar-map nil)
2651
2652 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2653 ;; affect _new_ message buffers.  We might add a function that walks thru all
2654 ;; summary-mode buffers and force the update.
2655 (defun gnus-summary-tool-bar-update (&optional symbol value)
2656   "Update summary mode toolbar.
2657 Setter function for custom variables."
2658   (setq-default gnus-summary-tool-bar-map nil)
2659   (when symbol
2660     ;; When used as ":set" function:
2661     (set-default symbol value))
2662   (when (gnus-buffer-live-p gnus-summary-buffer)
2663     (with-current-buffer gnus-summary-buffer
2664       (gnus-summary-make-tool-bar))))
2665
2666 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2667                                      'gnus-summary-tool-bar-gnome
2668                                    'gnus-summary-tool-bar-retro)
2669   "Specifies the Gnus summary tool bar.
2670
2671 It can be either a list or a symbol refering to a list.  See
2672 `gmm-tool-bar-from-list' for the format of the list.  The
2673 default key map is `gnus-summary-mode-map'.
2674
2675 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2676 `gnus-summary-tool-bar-retro'."
2677   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2678                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2679                  (repeat :tag "User defined list" gmm-tool-bar-item)
2680                  (symbol))
2681   :version "23.0" ;; No Gnus
2682   :initialize 'custom-initialize-default
2683   :set 'gnus-summary-tool-bar-update
2684   :group 'gnus-summary)
2685
2686 (defcustom gnus-summary-tool-bar-gnome
2687   '((gnus-summary-post-news "mail/compose" nil)
2688     (gnus-summary-insert-new-articles "mail/inbox" nil
2689                                       :visible (or (not gnus-agent)
2690                                                    gnus-plugged))
2691     (gnus-summary-reply-with-original "mail/reply")
2692     (gnus-summary-reply "mail/reply" nil :visible nil)
2693     (gnus-summary-followup-with-original "mail/reply-all")
2694     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2695     (gnus-summary-mail-forward "mail/forward")
2696     (gnus-summary-save-article "mail/save")
2697     (gnus-summary-search-article-forward "search" nil :visible nil)
2698     (gnus-summary-print-article "print")
2699     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2700     ;; Some new commands that may need more suitable icons:
2701     (gnus-summary-save-newsrc "save" nil :visible nil)
2702     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2703     (gnus-summary-prev-article "left-arrow")
2704     (gnus-summary-next-article "right-arrow")
2705     (gnus-summary-next-page "next-page")
2706     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2707     ;;
2708     ;; Maybe some sort-by-... could be added:
2709     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2710     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2711     (gnus-summary-mark-as-expirable
2712      "delete" nil
2713      :visible (gnus-check-backend-function 'request-expire-articles
2714                                            gnus-newsgroup-name))
2715     (gnus-summary-mark-as-spam
2716      "mail/spam" t
2717      :visible (and (fboundp 'spam-group-ham-contents-p)
2718                    (spam-group-ham-contents-p gnus-newsgroup-name))
2719      :help "Mark as spam")
2720     (gnus-summary-mark-as-read-forward
2721      "mail/not-spam" nil
2722      :visible (and (fboundp 'spam-group-spam-contents-p)
2723                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2724     ;;
2725     (gnus-summary-exit "exit")
2726     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2727     (gnus-info-find-node "help"))
2728   "List of functions for the summary tool bar (GNOME style).
2729
2730 See `gmm-tool-bar-from-list' for the format of the list."
2731   :type '(repeat gmm-tool-bar-item)
2732   :version "23.0" ;; No Gnus
2733   :initialize 'custom-initialize-default
2734   :set 'gnus-summary-tool-bar-update
2735   :group 'gnus-summary)
2736
2737 (defcustom gnus-summary-tool-bar-retro
2738   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2739     (gnus-summary-next-unread-article "gnus/next-ur")
2740     (gnus-summary-post-news "gnus/post")
2741     (gnus-summary-followup-with-original "gnus/fuwo")
2742     (gnus-summary-followup "gnus/followup")
2743     (gnus-summary-reply-with-original "gnus/reply-wo")
2744     (gnus-summary-reply "gnus/reply")
2745     (gnus-summary-caesar-message "gnus/rot13")
2746     (gnus-uu-decode-uu "gnus/uu-decode")
2747     (gnus-summary-save-article-file "gnus/save-aif")
2748     (gnus-summary-save-article "gnus/save-art")
2749     (gnus-uu-post-news "gnus/uu-post")
2750     (gnus-summary-catchup "gnus/catchup")
2751     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2752     (gnus-summary-exit "gnus/exit-summ")
2753     ;; Some new command that may need more suitable icons:
2754     (gnus-summary-print-article "gnus/print" nil :visible nil)
2755     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2756     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2757     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2758     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2759     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2760     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2761     ;;
2762     (gnus-info-find-node "gnus/help" nil :visible nil))
2763   "List of functions for the summary tool bar (retro look).
2764
2765 See `gmm-tool-bar-from-list' for the format of the list."
2766   :type '(repeat gmm-tool-bar-item)
2767   :version "23.0" ;; No Gnus
2768   :initialize 'custom-initialize-default
2769   :set 'gnus-summary-tool-bar-update
2770   :group 'gnus-summary)
2771
2772 (defcustom gnus-summary-tool-bar-zap-list t
2773   "List of icon items from the global tool bar.
2774 These items are not displayed in the Gnus summary mode tool bar.
2775
2776 See `gmm-tool-bar-from-list' for the format of the list."
2777   :type 'gmm-tool-bar-zap-list
2778   :version "23.0" ;; No Gnus
2779   :initialize 'custom-initialize-default
2780   :set 'gnus-summary-tool-bar-update
2781   :group 'gnus-summary)
2782
2783 (defvar image-load-path)
2784
2785 (defun gnus-summary-make-tool-bar (&optional force)
2786   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2787 When FORCE, rebuild the tool bar."
2788   (when (and (not (featurep 'xemacs))
2789              (boundp 'tool-bar-mode)
2790              tool-bar-mode
2791              (or (not gnus-summary-tool-bar-map) force))
2792     (let* ((load-path
2793             (gmm-image-load-path-for-library "gnus"
2794                                              "mail/save.xpm"
2795                                              nil t))
2796            (image-load-path (cons (car load-path)
2797                                   (when (boundp 'image-load-path)
2798                                     image-load-path)))
2799            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2800                                         gnus-summary-tool-bar-zap-list
2801                                         'gnus-summary-mode-map)))
2802       (when map
2803         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2804         ;; uses it's value.
2805         (setq gnus-summary-tool-bar-map map))))
2806   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2807
2808 (defun gnus-score-set-default (var value)
2809   "A version of set that updates the GNU Emacs menu-bar."
2810   (set var value)
2811   ;; It is the message that forces the active status to be updated.
2812   (message ""))
2813
2814 (defun gnus-make-score-map (type)
2815   "Make a summary score map of type TYPE."
2816   (if t
2817       nil
2818     (let ((headers '(("author" "from" string)
2819                      ("subject" "subject" string)
2820                      ("article body" "body" string)
2821                      ("article head" "head" string)
2822                      ("xref" "xref" string)
2823                      ("extra header" "extra" string)
2824                      ("lines" "lines" number)
2825                      ("followups to author" "followup" string)))
2826           (types '((number ("less than" <)
2827                            ("greater than" >)
2828                            ("equal" =))
2829                    (string ("substring" s)
2830                            ("exact string" e)
2831                            ("fuzzy string" f)
2832                            ("regexp" r))))
2833           (perms '(("temporary" (current-time-string))
2834                    ("permanent" nil)
2835                    ("immediate" now)))
2836           header)
2837       (list
2838        (apply
2839         'nconc
2840         (list
2841          (if (eq type 'lower)
2842              "Lower score"
2843            "Increase score"))
2844         (let (outh)
2845           (while headers
2846             (setq header (car headers))
2847             (setq outh
2848                   (cons
2849                    (apply
2850                     'nconc
2851                     (list (car header))
2852                     (let ((ts (cdr (assoc (nth 2 header) types)))
2853                           outt)
2854                       (while ts
2855                         (setq outt
2856                               (cons
2857                                (apply
2858                                 'nconc
2859                                 (list (caar ts))
2860                                 (let ((ps perms)
2861                                       outp)
2862                                   (while ps
2863                                     (setq outp
2864                                           (cons
2865                                            (vector
2866                                             (caar ps)
2867                                             (list
2868                                              'gnus-summary-score-entry
2869                                              (nth 1 header)
2870                                              (if (or (string= (nth 1 header)
2871                                                               "head")
2872                                                      (string= (nth 1 header)
2873                                                               "body"))
2874                                                  ""
2875                                                (list 'gnus-summary-header
2876                                                      (nth 1 header)))
2877                                              (list 'quote (nth 1 (car ts)))
2878                                              (list 'gnus-score-delta-default
2879                                                    nil)
2880                                              (nth 1 (car ps))
2881                                              t)
2882                                             t)
2883                                            outp))
2884                                     (setq ps (cdr ps)))
2885                                   (list (nreverse outp))))
2886                                outt))
2887                         (setq ts (cdr ts)))
2888                       (list (nreverse outt))))
2889                    outh))
2890             (setq headers (cdr headers)))
2891           (list (nreverse outh))))))))
2892
2893 \f
2894
2895 (defun gnus-summary-mode (&optional group)
2896   "Major mode for reading articles.
2897
2898 All normal editing commands are switched off.
2899 \\<gnus-summary-mode-map>
2900 Each line in this buffer represents one article.  To read an
2901 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2902 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2903 respectively.
2904
2905 You can also post articles and send mail from this buffer.  To
2906 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2907 of an article, type `\\[gnus-summary-reply]'.
2908
2909 There are approx. one gazillion commands you can execute in this
2910 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2911
2912 The following commands are available:
2913
2914 \\{gnus-summary-mode-map}"
2915   (interactive)
2916   (kill-all-local-variables)
2917   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2918     (gnus-summary-make-local-variables))
2919   (gnus-summary-make-local-variables)
2920   (setq gnus-newsgroup-name group)
2921   (when (gnus-visual-p 'summary-menu 'menu)
2922     (gnus-summary-make-menu-bar)
2923     (gnus-summary-make-tool-bar))
2924   (gnus-make-thread-indent-array)
2925   (gnus-simplify-mode-line)
2926   (setq major-mode 'gnus-summary-mode)
2927   (setq mode-name "Summary")
2928   (make-local-variable 'minor-mode-alist)
2929   (use-local-map gnus-summary-mode-map)
2930   (buffer-disable-undo)
2931   (setq buffer-read-only t              ;Disable modification
2932         show-trailing-whitespace nil)
2933   (setq truncate-lines t)
2934   (setq selective-display t)
2935   (setq selective-display-ellipses t)   ;Display `...'
2936   (gnus-summary-set-display-table)
2937   (gnus-set-default-directory)
2938   (make-local-variable 'gnus-summary-line-format)
2939   (make-local-variable 'gnus-summary-line-format-spec)
2940   (make-local-variable 'gnus-summary-dummy-line-format)
2941   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2942   (make-local-variable 'gnus-summary-mark-positions)
2943   (gnus-make-local-hook 'pre-command-hook)
2944   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2945   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2946   (turn-on-gnus-mailing-list-mode)
2947   (mm-enable-multibyte)
2948   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2949   (gnus-update-summary-mark-positions))
2950
2951 (defun gnus-summary-make-local-variables ()
2952   "Make all the local summary buffer variables."
2953   (let (global)
2954     (dolist (local gnus-summary-local-variables)
2955       (if (consp local)
2956           (progn
2957             (if (eq (cdr local) 'global)
2958                 ;; Copy the global value of the variable.
2959                 (setq global (symbol-value (car local)))
2960               ;; Use the value from the list.
2961               (setq global (eval (cdr local))))
2962             (set (make-local-variable (car local)) global))
2963         ;; Simple nil-valued local variable.
2964         (set (make-local-variable local) nil)))))
2965
2966 (defun gnus-summary-clear-local-variables ()
2967   (let ((locals gnus-summary-local-variables))
2968     (while locals
2969       (if (consp (car locals))
2970           (and (symbolp (caar locals))
2971                (set (caar locals) nil))
2972         (and (symbolp (car locals))
2973              (set (car locals) nil)))
2974       (setq locals (cdr locals)))))
2975
2976 ;; Summary data functions.
2977
2978 (defmacro gnus-data-number (data)
2979   `(car ,data))
2980
2981 (defmacro gnus-data-set-number (data number)
2982   `(setcar ,data ,number))
2983
2984 (defmacro gnus-data-mark (data)
2985   `(nth 1 ,data))
2986
2987 (defmacro gnus-data-set-mark (data mark)
2988   `(setcar (nthcdr 1 ,data) ,mark))
2989
2990 (defmacro gnus-data-pos (data)
2991   `(nth 2 ,data))
2992
2993 (defmacro gnus-data-set-pos (data pos)
2994   `(setcar (nthcdr 2 ,data) ,pos))
2995
2996 (defmacro gnus-data-header (data)
2997   `(nth 3 ,data))
2998
2999 (defmacro gnus-data-set-header (data header)
3000   `(setf (nth 3 ,data) ,header))
3001
3002 (defmacro gnus-data-level (data)
3003   `(nth 4 ,data))
3004
3005 (defmacro gnus-data-unread-p (data)
3006   `(= (nth 1 ,data) gnus-unread-mark))
3007
3008 (defmacro gnus-data-read-p (data)
3009   `(/= (nth 1 ,data) gnus-unread-mark))
3010
3011 (defmacro gnus-data-pseudo-p (data)
3012   `(consp (nth 3 ,data)))
3013
3014 (defmacro gnus-data-find (number)
3015   `(assq ,number gnus-newsgroup-data))
3016
3017 (defmacro gnus-data-find-list (number &optional data)
3018   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3019      (memq (assq ,number bdata)
3020            bdata)))
3021
3022 (defmacro gnus-data-make (number mark pos header level)
3023   `(list ,number ,mark ,pos ,header ,level))
3024
3025 (defun gnus-data-enter (after-article number mark pos header level offset)
3026   (let ((data (gnus-data-find-list after-article)))
3027     (unless data
3028       (error "No such article: %d" after-article))
3029     (setcdr data (cons (gnus-data-make number mark pos header level)
3030                        (cdr data)))
3031     (setq gnus-newsgroup-data-reverse nil)
3032     (gnus-data-update-list (cddr data) offset)))
3033
3034 (defun gnus-data-enter-list (after-article list &optional offset)
3035   (when list
3036     (let ((data (and after-article (gnus-data-find-list after-article)))
3037           (ilist list))
3038       (if (not (or data
3039                    after-article))
3040           (let ((odata gnus-newsgroup-data))
3041             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3042             (when offset
3043               (gnus-data-update-list odata offset)))
3044         ;; Find the last element in the list to be spliced into the main
3045         ;; list.
3046         (setq list (last list))
3047         (if (not data)
3048             (progn
3049               (setcdr list gnus-newsgroup-data)
3050               (setq gnus-newsgroup-data ilist)
3051               (when offset
3052                 (gnus-data-update-list (cdr list) offset)))
3053           (setcdr list (cdr data))
3054           (setcdr data ilist)
3055           (when offset
3056             (gnus-data-update-list (cdr list) offset))))
3057       (setq gnus-newsgroup-data-reverse nil))))
3058
3059 (defun gnus-data-remove (article &optional offset)
3060   (let ((data gnus-newsgroup-data))
3061     (if (= (gnus-data-number (car data)) article)
3062         (progn
3063           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3064                 gnus-newsgroup-data-reverse nil)
3065           (when offset
3066             (gnus-data-update-list gnus-newsgroup-data offset)))
3067       (while (cdr data)
3068         (when (= (gnus-data-number (cadr data)) article)
3069           (setcdr data (cddr data))
3070           (when offset
3071             (gnus-data-update-list (cdr data) offset))
3072           (setq data nil
3073                 gnus-newsgroup-data-reverse nil))
3074         (setq data (cdr data))))))
3075
3076 (defmacro gnus-data-list (backward)
3077   `(if ,backward
3078        (or gnus-newsgroup-data-reverse
3079            (setq gnus-newsgroup-data-reverse
3080                  (reverse gnus-newsgroup-data)))
3081      gnus-newsgroup-data))
3082
3083 (defun gnus-data-update-list (data offset)
3084   "Add OFFSET to the POS of all data entries in DATA."
3085   (setq gnus-newsgroup-data-reverse nil)
3086   (while data
3087     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3088     (setq data (cdr data))))
3089
3090 (defun gnus-summary-article-pseudo-p (article)
3091   "Say whether this article is a pseudo article or not."
3092   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3093
3094 (defmacro gnus-summary-article-sparse-p (article)
3095   "Say whether this article is a sparse article or not."
3096   `(memq ,article gnus-newsgroup-sparse))
3097
3098 (defmacro gnus-summary-article-ancient-p (article)
3099   "Say whether this article is a sparse article or not."
3100   `(memq ,article gnus-newsgroup-ancient))
3101
3102 (defun gnus-article-parent-p (number)
3103   "Say whether this article is a parent or not."
3104   (let ((data (gnus-data-find-list number)))
3105     (and (cdr data)              ; There has to be an article after...
3106          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3107             (gnus-data-level (nth 1 data))))))
3108
3109 (defun gnus-article-children (number)
3110   "Return a list of all children to NUMBER."
3111   (let* ((data (gnus-data-find-list number))
3112          (level (gnus-data-level (car data)))
3113          children)
3114     (setq data (cdr data))
3115     (while (and data
3116                 (= (gnus-data-level (car data)) (1+ level)))
3117       (push (gnus-data-number (car data)) children)
3118       (setq data (cdr data)))
3119     children))
3120
3121 (defmacro gnus-summary-skip-intangible ()
3122   "If the current article is intangible, then jump to a different article."
3123   '(let ((to (get-text-property (point) 'gnus-intangible)))
3124      (and to (gnus-summary-goto-subject to))))
3125
3126 (defmacro gnus-summary-article-intangible-p ()
3127   "Say whether this article is intangible or not."
3128   '(get-text-property (point) 'gnus-intangible))
3129
3130 (defun gnus-article-read-p (article)
3131   "Say whether ARTICLE is read or not."
3132   (not (or (memq article gnus-newsgroup-marked)
3133            (memq article gnus-newsgroup-spam-marked)
3134            (memq article gnus-newsgroup-unreads)
3135            (memq article gnus-newsgroup-unselected)
3136            (memq article gnus-newsgroup-dormant))))
3137
3138 ;; Some summary mode macros.
3139
3140 (defmacro gnus-summary-article-number ()
3141   "The article number of the article on the current line.
3142 If there isn't an article number here, then we return the current
3143 article number."
3144   '(progn
3145      (gnus-summary-skip-intangible)
3146      (or (get-text-property (point) 'gnus-number)
3147          (gnus-summary-last-subject))))
3148
3149 (defmacro gnus-summary-article-header (&optional number)
3150   "Return the header of article NUMBER."
3151   `(gnus-data-header (gnus-data-find
3152                       ,(or number '(gnus-summary-article-number)))))
3153
3154 (defmacro gnus-summary-thread-level (&optional number)
3155   "Return the level of thread that starts with article NUMBER."
3156   `(if (and (eq gnus-summary-make-false-root 'dummy)
3157             (get-text-property (point) 'gnus-intangible))
3158        0
3159      (gnus-data-level (gnus-data-find
3160                        ,(or number '(gnus-summary-article-number))))))
3161
3162 (defmacro gnus-summary-article-mark (&optional number)
3163   "Return the mark of article NUMBER."
3164   `(gnus-data-mark (gnus-data-find
3165                     ,(or number '(gnus-summary-article-number)))))
3166
3167 (defmacro gnus-summary-article-pos (&optional number)
3168   "Return the position of the line of article NUMBER."
3169   `(gnus-data-pos (gnus-data-find
3170                    ,(or number '(gnus-summary-article-number)))))
3171
3172 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3173 (defmacro gnus-summary-article-subject (&optional number)
3174   "Return current subject string or nil if nothing."
3175   `(let ((headers
3176           ,(if number
3177                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3178              '(gnus-data-header (assq (gnus-summary-article-number)
3179                                       gnus-newsgroup-data)))))
3180      (and headers
3181           (vectorp headers)
3182           (mail-header-subject headers))))
3183
3184 (defmacro gnus-summary-article-score (&optional number)
3185   "Return current article score."
3186   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3187                   gnus-newsgroup-scored))
3188        gnus-summary-default-score 0))
3189
3190 (defun gnus-summary-article-children (&optional number)
3191   "Return a list of article numbers that are children of article NUMBER."
3192   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3193          (level (gnus-data-level (car data)))
3194          l children)
3195     (while (and (setq data (cdr data))
3196                 (> (setq l (gnus-data-level (car data))) level))
3197       (and (= (1+ level) l)
3198            (push (gnus-data-number (car data))
3199                  children)))
3200     (nreverse children)))
3201
3202 (defun gnus-summary-article-parent (&optional number)
3203   "Return the article number of the parent of article NUMBER."
3204   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3205                                     (gnus-data-list t)))
3206          (level (gnus-data-level (car data))))
3207     (if (zerop level)
3208         ()                              ; This is a root.
3209       ;; We search until we find an article with a level less than
3210       ;; this one.  That function has to be the parent.
3211       (while (and (setq data (cdr data))
3212                   (not (< (gnus-data-level (car data)) level))))
3213       (and data (gnus-data-number (car data))))))
3214
3215 (defun gnus-unread-mark-p (mark)
3216   "Say whether MARK is the unread mark."
3217   (= mark gnus-unread-mark))
3218
3219 (defun gnus-read-mark-p (mark)
3220   "Say whether MARK is one of the marks that mark as read.
3221 This is all marks except unread, ticked, dormant, and expirable."
3222   (not (or (= mark gnus-unread-mark)
3223            (= mark gnus-ticked-mark)
3224            (= mark gnus-spam-mark)
3225            (= mark gnus-dormant-mark)
3226            (= mark gnus-expirable-mark))))
3227
3228 (defmacro gnus-article-mark (number)
3229   "Return the MARK of article NUMBER.
3230 This macro should only be used when computing the mark the \"first\"
3231 time; i.e., when generating the summary lines.  After that,
3232 `gnus-summary-article-mark' should be used to examine the
3233 marks of articles."
3234   `(cond
3235     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3236     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3237     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3238     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3239     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3240     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3241     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3242     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3243            gnus-ancient-mark))))
3244
3245 ;; Saving hidden threads.
3246
3247 (defmacro gnus-save-hidden-threads (&rest forms)
3248   "Save hidden threads, eval FORMS, and restore the hidden threads."
3249   (let ((config (make-symbol "config")))
3250     `(let ((,config (gnus-hidden-threads-configuration)))
3251        (unwind-protect
3252            (save-excursion
3253              ,@forms)
3254          (gnus-restore-hidden-threads-configuration ,config)))))
3255 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3256 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3257
3258 (defun gnus-data-compute-positions ()
3259   "Compute the positions of all articles."
3260   (setq gnus-newsgroup-data-reverse nil)
3261   (let ((data gnus-newsgroup-data))
3262     (save-excursion
3263       (gnus-save-hidden-threads
3264         (gnus-summary-show-all-threads)
3265         (goto-char (point-min))
3266         (while data
3267           (while (get-text-property (point) 'gnus-intangible)
3268             (forward-line 1))
3269           (gnus-data-set-pos (car data) (+ (point) 3))
3270           (setq data (cdr data))
3271           (forward-line 1))))))
3272
3273 (defun gnus-hidden-threads-configuration ()
3274   "Return the current hidden threads configuration."
3275   (save-excursion
3276     (let (config)
3277       (goto-char (point-min))
3278       (while (search-forward "\r" nil t)
3279         (push (1- (point)) config))
3280       config)))
3281
3282 (defun gnus-restore-hidden-threads-configuration (config)
3283   "Restore hidden threads configuration from CONFIG."
3284   (save-excursion
3285     (let (point buffer-read-only)
3286       (while (setq point (pop config))
3287         (when (and (< point (point-max))
3288                    (goto-char point)
3289                    (eq (char-after) ?\n))
3290           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3291
3292 ;; Various summary mode internalish functions.
3293
3294 (defun gnus-mouse-pick-article (e)
3295   (interactive "e")
3296   (mouse-set-point e)
3297   (gnus-summary-next-page nil t))
3298
3299 (defun gnus-summary-set-display-table ()
3300   "Change the display table.
3301 Odd characters have a tendency to mess
3302 up nicely formatted displays - we make all possible glyphs
3303 display only a single character."
3304
3305   ;; We start from the standard display table, if any.
3306   (let ((table (or (copy-sequence standard-display-table)
3307                    (make-display-table)))
3308         (i 32))
3309     ;; Nix out all the control chars...
3310     (while (>= (setq i (1- i)) 0)
3311       (aset table i [??]))
3312    ;; ... but not newline and cr, of course.  (cr is necessary for the
3313     ;; selective display).
3314     (aset table ?\n nil)
3315     (aset table ?\r nil)
3316     ;; We keep TAB as well.
3317     (aset table ?\t nil)
3318     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3319     ;; Emacs 23 (unicode), that are not set already.
3320     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3321                  160
3322                256)))
3323       (while (>= (setq i (1- i)) 127)
3324         ;; Only modify if the entry is nil.
3325         (unless (aref table i)
3326           (aset table i [??]))))
3327     (setq buffer-display-table table)))
3328
3329 (defun gnus-summary-set-article-display-arrow (pos)
3330   "Update the overlay arrow to point to line at position POS."
3331   (when (and gnus-summary-display-arrow
3332              (boundp 'overlay-arrow-position)
3333              (boundp 'overlay-arrow-string))
3334     (save-excursion
3335       (goto-char pos)
3336       (beginning-of-line)
3337       (unless overlay-arrow-position
3338         (setq overlay-arrow-position (make-marker)))
3339       (setq overlay-arrow-string "=>"
3340             overlay-arrow-position (set-marker overlay-arrow-position
3341                                                (point)
3342                                                (current-buffer))))))
3343
3344 (defun gnus-summary-setup-buffer (group)
3345   "Initialize summary buffer."
3346   (let ((buffer (gnus-summary-buffer-name group))
3347         (dead-name (concat "*Dead Summary "
3348                            (gnus-group-decoded-name group) "*")))
3349     ;; If a dead summary buffer exists, we kill it.
3350     (when (gnus-buffer-live-p dead-name)
3351       (gnus-kill-buffer dead-name))
3352     (if (get-buffer buffer)
3353         (progn
3354           (set-buffer buffer)
3355           (setq gnus-summary-buffer (current-buffer))
3356           (not gnus-newsgroup-prepared))
3357       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3358       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3359       (gnus-summary-mode group)
3360       (when gnus-carpal
3361         (gnus-carpal-setup-buffer 'summary))
3362       (when (gnus-group-quit-config group)
3363         (set (make-local-variable 'gnus-single-article-buffer) nil))
3364       (make-local-variable 'gnus-article-buffer)
3365       (make-local-variable 'gnus-article-current)
3366       (make-local-variable 'gnus-original-article-buffer)
3367       (setq gnus-newsgroup-name group)
3368       ;; Set any local variables in the group parameters.
3369       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3370       t)))
3371
3372 (defun gnus-set-global-variables ()
3373   "Set the global equivalents of the buffer-local variables.
3374 They are set to the latest values they had.  These reflect the summary
3375 buffer that was in action when the last article was fetched."
3376   (when (eq major-mode 'gnus-summary-mode)
3377     (setq gnus-summary-buffer (current-buffer))
3378     (let ((name gnus-newsgroup-name)
3379           (marked gnus-newsgroup-marked)
3380           (spam gnus-newsgroup-spam-marked)
3381           (unread gnus-newsgroup-unreads)
3382           (headers gnus-current-headers)
3383           (data gnus-newsgroup-data)
3384           (summary gnus-summary-buffer)
3385           (article-buffer gnus-article-buffer)
3386           (original gnus-original-article-buffer)
3387           (gac gnus-article-current)
3388           (reffed gnus-reffed-article-number)
3389           (score-file gnus-current-score-file)
3390           (default-charset gnus-newsgroup-charset)
3391           vlist)
3392       (let ((locals gnus-newsgroup-variables))
3393         (while locals
3394           (if (consp (car locals))
3395               (push (eval (caar locals)) vlist)
3396             (push (eval (car locals)) vlist))
3397           (setq locals (cdr locals)))
3398         (setq vlist (nreverse vlist)))
3399       (with-current-buffer gnus-group-buffer
3400         (setq gnus-newsgroup-name name
3401               gnus-newsgroup-marked marked
3402               gnus-newsgroup-spam-marked spam
3403               gnus-newsgroup-unreads unread
3404               gnus-current-headers headers
3405               gnus-newsgroup-data data
3406               gnus-article-current gac
3407               gnus-summary-buffer summary
3408               gnus-article-buffer article-buffer
3409               gnus-original-article-buffer original
3410               gnus-reffed-article-number reffed
3411               gnus-current-score-file score-file
3412               gnus-newsgroup-charset default-charset)
3413         (let ((locals gnus-newsgroup-variables))
3414           (while locals
3415             (if (consp (car locals))
3416                 (set (caar locals) (pop vlist))
3417               (set (car locals) (pop vlist)))
3418             (setq locals (cdr locals))))
3419         ;; The article buffer also has local variables.
3420         (when (gnus-buffer-live-p gnus-article-buffer)
3421           (set-buffer gnus-article-buffer)
3422           (setq gnus-summary-buffer summary))))))
3423
3424 (defun gnus-summary-article-unread-p (article)
3425   "Say whether ARTICLE is unread or not."
3426   (memq article gnus-newsgroup-unreads))
3427
3428 (defun gnus-summary-first-article-p (&optional article)
3429   "Return whether ARTICLE is the first article in the buffer."
3430   (if (not (setq article (or article (gnus-summary-article-number))))
3431       nil
3432     (eq article (caar gnus-newsgroup-data))))
3433
3434 (defun gnus-summary-last-article-p (&optional article)
3435   "Return whether ARTICLE is the last article in the buffer."
3436   (if (not (setq article (or article (gnus-summary-article-number))))
3437       ;; All non-existent numbers are the last article.  :-)
3438       t
3439     (not (cdr (gnus-data-find-list article)))))
3440
3441 (defun gnus-make-thread-indent-array ()
3442   (let ((n 200))
3443     (unless (and gnus-thread-indent-array
3444                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3445       (setq gnus-thread-indent-array (make-vector 201 "")
3446             gnus-thread-indent-array-level gnus-thread-indent-level)
3447       (while (>= n 0)
3448         (aset gnus-thread-indent-array n
3449               (make-string (* n gnus-thread-indent-level) ? ))
3450         (setq n (1- n))))))
3451
3452 (defun gnus-update-summary-mark-positions ()
3453   "Compute where the summary marks are to go."
3454   (save-excursion
3455     (when (gnus-buffer-exists-p gnus-summary-buffer)
3456       (set-buffer gnus-summary-buffer))
3457     (let ((spec gnus-summary-line-format-spec)
3458           pos)
3459       (save-excursion
3460         (gnus-set-work-buffer)
3461         (let ((gnus-tmp-unread ?Z)
3462               (gnus-replied-mark ?Z)
3463               (gnus-score-below-mark ?Z)
3464               (gnus-score-over-mark ?Z)
3465               (gnus-undownloaded-mark ?Z)
3466               (gnus-summary-line-format-spec spec)
3467               (gnus-newsgroup-downloadable '(0))
3468               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3469               case-fold-search ignores)
3470           ;; Here, all marks are bound to Z.
3471           (gnus-summary-insert-line header
3472                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3473           (goto-char (point-min))
3474           ;; Memorize the positions of the same characters as dummy marks.
3475           (while (re-search-forward "[A-D]" nil t)
3476             (push (point) ignores))
3477           (erase-buffer)
3478           ;; We use A-D as dummy marks in order to know column positions
3479           ;; where marks should be inserted.
3480           (setq gnus-tmp-unread ?A
3481                 gnus-replied-mark ?B
3482                 gnus-score-below-mark ?C
3483                 gnus-score-over-mark ?C
3484                 gnus-undownloaded-mark ?D)
3485           (gnus-summary-insert-line header
3486                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3487           ;; Ignore characters which aren't dummy marks.
3488           (dolist (p ignores)
3489             (delete-region (goto-char (1- p)) p)
3490             (insert ?Z))
3491           (goto-char (point-min))
3492           (setq pos (list (cons 'unread
3493                                 (and (search-forward "A" nil t)
3494                                      (- (point) (point-min) 1)))))
3495           (goto-char (point-min))
3496           (push (cons 'replied (and (search-forward "B" nil t)
3497                                     (- (point) (point-min) 1)))
3498                 pos)
3499           (goto-char (point-min))
3500           (push (cons 'score (and (search-forward "C" nil t)
3501                                   (- (point) (point-min) 1)))
3502                 pos)
3503           (goto-char (point-min))
3504           (push (cons 'download (and (search-forward "D" nil t)
3505                                      (- (point) (point-min) 1)))
3506                 pos)))
3507       (setq gnus-summary-mark-positions pos))))
3508
3509 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3510   "Insert a dummy root in the summary buffer."
3511   (beginning-of-line)
3512   (gnus-add-text-properties
3513    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3514    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3515
3516 (defun gnus-summary-extract-address-component (from)
3517   (or (car (funcall gnus-extract-address-components from))
3518       from))
3519
3520 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3521   (let ((mail-parse-charset gnus-newsgroup-charset)
3522         ; Is it really necessary to do this next part for each summary line?
3523         ; Luckily, doesn't seem to slow things down much.
3524         (mail-parse-ignored-charsets
3525          (with-current-buffer gnus-summary-buffer
3526            gnus-newsgroup-ignored-charsets)))
3527     (or
3528      (and gnus-ignored-from-addresses
3529           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3530           (let ((extra-headers (mail-header-extra header))
3531                 to
3532                 newsgroups)
3533             (cond
3534              ((setq to (cdr (assq 'To extra-headers)))
3535               (concat gnus-summary-to-prefix
3536                       (inline
3537                         (gnus-summary-extract-address-component
3538                          (funcall gnus-decode-encoded-word-function to)))))
3539              ((setq newsgroups
3540                     (or
3541                      (cdr (assq 'Newsgroups extra-headers))
3542                      (and
3543                       (memq 'Newsgroups gnus-extra-headers)
3544                       (eq (car (gnus-find-method-for-group
3545                                 gnus-newsgroup-name)) 'nntp)
3546                       (gnus-group-real-name gnus-newsgroup-name))))
3547               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3548      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3549
3550 (defun gnus-summary-insert-line (gnus-tmp-header
3551                                  gnus-tmp-level gnus-tmp-current
3552                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3553                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3554                                  &optional gnus-tmp-dummy gnus-tmp-score
3555                                  gnus-tmp-process)
3556   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3557          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3558          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3559          (gnus-tmp-score-char
3560           (if (or (null gnus-summary-default-score)
3561                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3562                       gnus-summary-zcore-fuzz))
3563               ?                         ;Whitespace
3564             (if (< gnus-tmp-score gnus-summary-default-score)
3565                 gnus-score-below-mark gnus-score-over-mark)))
3566          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3567          (gnus-tmp-replied
3568           (cond (gnus-tmp-process gnus-process-mark)
3569                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3570                  gnus-cached-mark)
3571                 (gnus-tmp-replied gnus-replied-mark)
3572                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3573                  gnus-forwarded-mark)
3574                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3575                  gnus-saved-mark)
3576                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3577                  gnus-recent-mark)
3578                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3579                  gnus-unseen-mark)
3580                 (t gnus-no-mark)))
3581          (gnus-tmp-downloaded
3582           (cond (undownloaded
3583                  gnus-undownloaded-mark)
3584                 (gnus-newsgroup-agentized
3585                  gnus-downloaded-mark)
3586                 (t
3587                  gnus-no-mark)))
3588          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3589          (gnus-tmp-name
3590           (cond
3591            ((string-match "<[^>]+> *$" gnus-tmp-from)
3592             (let ((beg (match-beginning 0)))
3593               (or (and (string-match "^\".+\"" gnus-tmp-from)
3594                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3595                   (substring gnus-tmp-from 0 beg))))
3596            ((string-match "(.+)" gnus-tmp-from)
3597             (substring gnus-tmp-from
3598                        (1+ (match-beginning 0)) (1- (match-end 0))))
3599            (t gnus-tmp-from)))
3600          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3601          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3602          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3603          (buffer-read-only nil))
3604     (when (string= gnus-tmp-name "")
3605       (setq gnus-tmp-name gnus-tmp-from))
3606     (unless (numberp gnus-tmp-lines)
3607       (setq gnus-tmp-lines -1))
3608     (if (= gnus-tmp-lines -1)
3609         (setq gnus-tmp-lines "?")
3610       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3611       (gnus-put-text-property
3612      (point)
3613      (progn (eval gnus-summary-line-format-spec) (point))
3614        'gnus-number gnus-tmp-number)
3615     (when (gnus-visual-p 'summary-highlight 'highlight)
3616       (forward-line -1)
3617       (gnus-run-hooks 'gnus-summary-update-hook)
3618       (forward-line 1))))
3619
3620 (defun gnus-summary-update-line (&optional dont-update)
3621   "Update summary line after change."
3622   (when (and gnus-summary-default-score
3623              (not gnus-summary-inhibit-highlight))
3624     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3625            (article (gnus-summary-article-number))
3626            (score (gnus-summary-article-score article)))
3627       (unless dont-update
3628         (if (and gnus-summary-mark-below
3629                  (< (gnus-summary-article-score)
3630                     gnus-summary-mark-below))
3631             ;; This article has a low score, so we mark it as read.
3632             (when (memq article gnus-newsgroup-unreads)
3633               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3634           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3635             ;; This article was previously marked as read on account
3636             ;; of a low score, but now it has risen, so we mark it as
3637             ;; unread.
3638             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3639         (gnus-summary-update-mark
3640          (if (or (null gnus-summary-default-score)
3641                  (<= (abs (- score gnus-summary-default-score))
3642                      gnus-summary-zcore-fuzz))
3643              ?                          ;Whitespace
3644            (if (< score gnus-summary-default-score)
3645                gnus-score-below-mark gnus-score-over-mark))
3646          'score))
3647       ;; Do visual highlighting.
3648       (when (gnus-visual-p 'summary-highlight 'highlight)
3649         (gnus-run-hooks 'gnus-summary-update-hook)))))
3650
3651 (defvar gnus-tmp-new-adopts nil)
3652
3653 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3654   "Return the number of articles in THREAD.
3655 This may be 0 in some cases -- if none of the articles in
3656 the thread are to be displayed."
3657   (let* ((number
3658          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3659           (cond
3660            ((not (listp thread))
3661             1)
3662            ((and (consp thread) (cdr thread))
3663             (apply
3664              '+ 1 (mapcar
3665                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3666            ((null thread)
3667             1)
3668            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3669             1)
3670            (t 0))))
3671     (when (and level (zerop level) gnus-tmp-new-adopts)
3672       (incf number
3673             (apply '+ (mapcar
3674                        'gnus-summary-number-of-articles-in-thread
3675                        gnus-tmp-new-adopts))))
3676     (if char
3677         (if (> number 1) gnus-not-empty-thread-mark
3678           gnus-empty-thread-mark)
3679       number)))
3680
3681 (defsubst gnus-summary-line-message-size (head)
3682   "Return pretty-printed version of message size.
3683 This function is intended to be used in
3684 `gnus-summary-line-format-alist'."
3685   (let ((c (or (mail-header-chars head) -1)))
3686     (cond ((< c 0) "n/a")               ; chars not available
3687           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3688           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3689           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3690           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3691
3692
3693 (defun gnus-summary-set-local-parameters (group)
3694   "Go through the local params of GROUP and set all variable specs in that list."
3695   (let ((vars '(quit-config)))          ; Ignore quit-config.
3696     (dolist (elem (gnus-group-find-parameter group))
3697       (and (consp elem)                 ; Has to be a cons.
3698            (consp (cdr elem))           ; The cdr has to be a list.
3699            (symbolp (car elem))         ; Has to be a symbol in there.
3700            (not (memq (car elem) vars))
3701            (ignore-errors               ; So we set it.
3702              (push (car elem) vars)
3703              (make-local-variable (car elem))
3704              (set (car elem) (eval (nth 1 elem))))))))
3705
3706 (defun gnus-summary-read-group (group &optional show-all no-article
3707                                       kill-buffer no-display backward
3708                                       select-articles)
3709   "Start reading news in newsgroup GROUP.
3710 If SHOW-ALL is non-nil, already read articles are also listed.
3711 If NO-ARTICLE is non-nil, no article is selected initially.
3712 If NO-DISPLAY, don't generate a summary buffer."
3713   (let (result)
3714     (while (and group
3715                 (null (setq result
3716                             (let ((gnus-auto-select-next nil))
3717                               (or (gnus-summary-read-group-1
3718                                    group show-all no-article
3719                                    kill-buffer no-display
3720                                    select-articles)
3721                                   (setq show-all nil
3722                                         select-articles nil)))))
3723                 (eq gnus-auto-select-next 'quietly))
3724       (set-buffer gnus-group-buffer)
3725       ;; The entry function called above goes to the next
3726       ;; group automatically, so we go two groups back
3727       ;; if we are searching for the previous group.
3728       (when backward
3729         (gnus-group-prev-unread-group 2))
3730       (if (not (equal group (gnus-group-group-name)))
3731           (setq group (gnus-group-group-name))
3732         (setq group nil)))
3733     result))
3734
3735 (defun gnus-summary-read-group-1 (group show-all no-article
3736                                         kill-buffer no-display
3737                                         &optional select-articles)
3738   ;; Killed foreign groups can't be entered.
3739   ;;  (when (and (not (gnus-group-native-p group))
3740   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3741   ;;    (error "Dead non-native groups can't be entered"))
3742   (gnus-message 5 "Retrieving newsgroup: %s..."
3743                 (gnus-group-decoded-name group))
3744   (let* ((new-group (gnus-summary-setup-buffer group))
3745          (quit-config (gnus-group-quit-config group))
3746          (did-select (and new-group (gnus-select-newsgroup
3747                                      group show-all select-articles))))
3748     (cond
3749      ;; This summary buffer exists already, so we just select it.
3750      ((not new-group)
3751       (gnus-set-global-variables)
3752       (when kill-buffer
3753         (gnus-kill-or-deaden-summary kill-buffer))
3754       (gnus-configure-windows 'summary 'force)
3755       (gnus-set-mode-line 'summary)
3756       (gnus-summary-position-point)
3757       (message "")
3758       t)
3759      ;; We couldn't select this group.
3760      ((null did-select)
3761       (when (and (eq major-mode 'gnus-summary-mode)
3762                  (not (equal (current-buffer) kill-buffer)))
3763         (kill-buffer (current-buffer))
3764         (if (not quit-config)
3765             (progn
3766               ;; Update the info -- marks might need to be removed,
3767               ;; for instance.
3768               (gnus-summary-update-info)
3769               (set-buffer gnus-group-buffer)
3770               (gnus-group-jump-to-group group)
3771               (gnus-group-next-unread-group 1))
3772           (gnus-handle-ephemeral-exit quit-config)))
3773       (let ((grpinfo (gnus-get-info group)))
3774         (if (null (gnus-info-read grpinfo))
3775             (gnus-message 3 "Group %s contains no messages"
3776                           (gnus-group-decoded-name group))
3777           (gnus-message 3 "Can't select group")))
3778       nil)
3779      ;; The user did a `C-g' while prompting for number of articles,
3780      ;; so we exit this group.
3781      ((eq did-select 'quit)
3782       (and (eq major-mode 'gnus-summary-mode)
3783            (not (equal (current-buffer) kill-buffer))
3784            (kill-buffer (current-buffer)))
3785       (when kill-buffer
3786         (gnus-kill-or-deaden-summary kill-buffer))
3787       (if (not quit-config)
3788           (progn
3789             (set-buffer gnus-group-buffer)
3790             (gnus-group-jump-to-group group)
3791             (gnus-group-next-unread-group 1)
3792             (gnus-configure-windows 'group 'force))
3793         (gnus-handle-ephemeral-exit quit-config))
3794       ;; Finally signal the quit.
3795       (signal 'quit nil))
3796      ;; The group was successfully selected.
3797      (t
3798       (gnus-set-global-variables)
3799       ;; Save the active value in effect when the group was entered.
3800       (setq gnus-newsgroup-active
3801             (gnus-copy-sequence
3802              (gnus-active gnus-newsgroup-name)))
3803       ;; You can change the summary buffer in some way with this hook.
3804       (gnus-run-hooks 'gnus-select-group-hook)
3805       (when (memq 'summary (gnus-update-format-specifications
3806                             nil 'summary 'summary-mode 'summary-dummy))
3807         ;; The format specification for the summary line was updated,
3808         ;; so we need to update the mark positions as well.
3809         (gnus-update-summary-mark-positions))
3810       ;; Do score processing.
3811       (when gnus-use-scoring
3812         (gnus-possibly-score-headers))
3813       ;; Check whether to fill in the gaps in the threads.
3814       (when gnus-build-sparse-threads
3815         (gnus-build-sparse-threads))
3816       ;; Find the initial limit.
3817       (if show-all
3818           (let ((gnus-newsgroup-dormant nil))
3819             (gnus-summary-initial-limit show-all))
3820         (gnus-summary-initial-limit show-all))
3821       ;; Generate the summary buffer.
3822       (unless no-display
3823         (gnus-summary-prepare))
3824       (when gnus-use-trees
3825         (gnus-tree-open group)
3826         (setq gnus-summary-highlight-line-function
3827               'gnus-tree-highlight-article))
3828       ;; If the summary buffer is empty, but there are some low-scored
3829       ;; articles or some excluded dormants, we include these in the
3830       ;; buffer.
3831       (when (and (zerop (buffer-size))
3832                  (not no-display))
3833         (cond (gnus-newsgroup-dormant
3834                (gnus-summary-limit-include-dormant))
3835               ((and gnus-newsgroup-scored show-all)
3836                (gnus-summary-limit-include-expunged t))))
3837       ;; Function `gnus-apply-kill-file' must be called in this hook.
3838       (gnus-run-hooks 'gnus-apply-kill-hook)
3839       (if (and (zerop (buffer-size))
3840                (not no-display))
3841           (progn
3842             ;; This newsgroup is empty.
3843             (gnus-summary-catchup-and-exit nil t)
3844             (gnus-message 6 "No unread news")
3845             (when kill-buffer
3846               (gnus-kill-or-deaden-summary kill-buffer))
3847             ;; Return nil from this function.
3848             nil)
3849         ;; Hide conversation thread subtrees.  We cannot do this in
3850         ;; gnus-summary-prepare-hook since kill processing may not
3851         ;; work with hidden articles.
3852         (gnus-summary-maybe-hide-threads)
3853         (when kill-buffer
3854           (gnus-kill-or-deaden-summary kill-buffer))
3855         (gnus-summary-auto-select-subject)
3856         ;; Show first unread article if requested.
3857         (if (and (not no-article)
3858                  (not no-display)
3859                  gnus-newsgroup-unreads
3860                  gnus-auto-select-first)
3861             (progn
3862               (gnus-configure-windows 'summary)
3863               (let ((art (gnus-summary-article-number)))
3864                 (unless (and (not gnus-plugged)
3865                              (or (memq art gnus-newsgroup-undownloaded)
3866                                  (memq art gnus-newsgroup-downloadable)))
3867                   (gnus-summary-goto-article art))))
3868           ;; Don't select any articles.
3869           (gnus-summary-position-point)
3870           (gnus-configure-windows 'summary 'force)
3871           (gnus-set-mode-line 'summary))
3872         (when (and gnus-auto-center-group
3873                    (get-buffer-window gnus-group-buffer t))
3874           ;; Gotta use windows, because recenter does weird stuff if
3875           ;; the current buffer ain't the displayed window.
3876           (let ((owin (selected-window)))
3877             (select-window (get-buffer-window gnus-group-buffer t))
3878             (when (gnus-group-goto-group group)
3879               (recenter))
3880             (select-window owin)))
3881         ;; Mark this buffer as "prepared".
3882         (setq gnus-newsgroup-prepared t)
3883         (gnus-run-hooks 'gnus-summary-prepared-hook)
3884         (unless (gnus-ephemeral-group-p group)
3885           (gnus-group-update-group group))
3886         t)))))
3887
3888 (defun gnus-summary-auto-select-subject ()
3889   "Select the subject line on initial group entry."
3890   (goto-char (point-min))
3891   (cond
3892    ((eq gnus-auto-select-subject 'best)
3893     (gnus-summary-best-unread-subject))
3894    ((eq gnus-auto-select-subject 'unread)
3895     (gnus-summary-first-unread-subject))
3896    ((eq gnus-auto-select-subject 'unseen)
3897     (gnus-summary-first-unseen-subject))
3898    ((eq gnus-auto-select-subject 'unseen-or-unread)
3899     (gnus-summary-first-unseen-or-unread-subject))
3900    ((eq gnus-auto-select-subject 'first)
3901     ;; Do nothing.
3902     )
3903    ((functionp gnus-auto-select-subject)
3904     (funcall gnus-auto-select-subject))))
3905
3906 (defun gnus-summary-prepare ()
3907   "Generate the summary buffer."
3908   (interactive)
3909   (let ((buffer-read-only nil))
3910     (erase-buffer)
3911     (setq gnus-newsgroup-data nil
3912           gnus-newsgroup-data-reverse nil)
3913     (gnus-run-hooks 'gnus-summary-generate-hook)
3914     ;; Generate the buffer, either with threads or without.
3915     (when gnus-newsgroup-headers
3916       (gnus-summary-prepare-threads
3917        (if gnus-show-threads
3918            (gnus-sort-gathered-threads
3919             (funcall gnus-summary-thread-gathering-function
3920                      (gnus-sort-threads
3921                       (gnus-cut-threads (gnus-make-threads)))))
3922          ;; Unthreaded display.
3923          (gnus-sort-articles gnus-newsgroup-headers))))
3924     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3925     ;; Call hooks for modifying summary buffer.
3926     (goto-char (point-min))
3927     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3928
3929 (defsubst gnus-general-simplify-subject (subject)
3930   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3931   (setq subject
3932         (cond
3933          ;; Truncate the subject.
3934          (gnus-simplify-subject-functions
3935           (gnus-map-function gnus-simplify-subject-functions subject))
3936          ((numberp gnus-summary-gather-subject-limit)
3937           (setq subject (gnus-simplify-subject-re subject))
3938           (if (> (length subject) gnus-summary-gather-subject-limit)
3939               (substring subject 0 gnus-summary-gather-subject-limit)
3940             subject))
3941          ;; Fuzzily simplify it.
3942          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3943           (gnus-simplify-subject-fuzzy subject))
3944          ;; Just remove the leading "Re:".
3945          (t
3946           (gnus-simplify-subject-re subject))))
3947
3948   (if (and gnus-summary-gather-exclude-subject
3949            (string-match gnus-summary-gather-exclude-subject subject))
3950       nil                         ; This article shouldn't be gathered
3951     subject))
3952
3953 (defun gnus-summary-simplify-subject-query ()
3954   "Query where the respool algorithm would put this article."
3955   (interactive)
3956   (gnus-summary-select-article)
3957   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3958
3959 (defun gnus-gather-threads-by-subject (threads)
3960   "Gather threads by looking at Subject headers."
3961   (if (not gnus-summary-make-false-root)
3962       threads
3963     (let ((hashtb (gnus-make-hashtable 1024))
3964           (prev threads)
3965           (result threads)
3966           subject hthread whole-subject)
3967       (while threads
3968         (setq subject (gnus-general-simplify-subject
3969                        (setq whole-subject (mail-header-subject
3970                                             (caar threads)))))
3971         (when subject
3972           (if (setq hthread (gnus-gethash subject hashtb))
3973               (progn
3974                 ;; We enter a dummy root into the thread, if we
3975                 ;; haven't done that already.
3976                 (unless (stringp (caar hthread))
3977                   (setcar hthread (list whole-subject (car hthread))))
3978                 ;; We add this new gathered thread to this gathered
3979                 ;; thread.
3980                 (setcdr (car hthread)
3981                         (nconc (cdar hthread) (list (car threads))))
3982                 ;; Remove it from the list of threads.
3983                 (setcdr prev (cdr threads))
3984                 (setq threads prev))
3985             ;; Enter this thread into the hash table.
3986             (gnus-sethash subject
3987                           (if gnus-summary-make-false-root-always
3988                               (progn
3989                                 ;; If you want a dummy root above all
3990                                 ;; threads...
3991                                 (setcar threads (list whole-subject
3992                                                       (car threads)))
3993                                 threads)
3994                             threads)
3995                           hashtb)))
3996         (setq prev threads)
3997         (setq threads (cdr threads)))
3998       result)))
3999
4000 (defun gnus-gather-threads-by-references (threads)
4001   "Gather threads by looking at References headers."
4002   (let ((idhashtb (gnus-make-hashtable 1024))
4003         (thhashtb (gnus-make-hashtable 1024))
4004         (prev threads)
4005         (result threads)
4006         ids references id gthread gid entered ref)
4007     (while threads
4008       (when (setq references (mail-header-references (caar threads)))
4009         (setq id (mail-header-id (caar threads))
4010               ids (inline (gnus-split-references references))
4011               entered nil)
4012         (while (setq ref (pop ids))
4013           (setq ids (delete ref ids))
4014           (if (not (setq gid (gnus-gethash ref idhashtb)))
4015               (progn
4016                 (gnus-sethash ref id idhashtb)
4017                 (gnus-sethash id threads thhashtb))
4018             (setq gthread (gnus-gethash gid thhashtb))
4019             (unless entered
4020               ;; We enter a dummy root into the thread, if we
4021               ;; haven't done that already.
4022               (unless (stringp (caar gthread))
4023                 (setcar gthread (list (mail-header-subject (caar gthread))
4024                                       (car gthread))))
4025               ;; We add this new gathered thread to this gathered
4026               ;; thread.
4027               (setcdr (car gthread)
4028                       (nconc (cdar gthread) (list (car threads)))))
4029             ;; Add it into the thread hash table.
4030             (gnus-sethash id gthread thhashtb)
4031             (setq entered t)
4032             ;; Remove it from the list of threads.
4033             (setcdr prev (cdr threads))
4034             (setq threads prev))))
4035       (setq prev threads)
4036       (setq threads (cdr threads)))
4037     result))
4038
4039 (defun gnus-sort-gathered-threads (threads)
4040   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4041   (let ((result threads))
4042     (while threads
4043       (when (stringp (caar threads))
4044         (setcdr (car threads)
4045                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4046       (setq threads (cdr threads)))
4047     result))
4048
4049 (defun gnus-thread-loop-p (root thread)
4050   "Say whether ROOT is in THREAD."
4051   (let ((stack (list thread))
4052         (infloop 0)
4053         th)
4054     (while (setq thread (pop stack))
4055       (setq th (cdr thread))
4056       (while (and th
4057                   (not (eq (caar th) root)))
4058         (pop th))
4059       (if th
4060           ;; We have found a loop.
4061           (let (ref-dep)
4062             (setcdr thread (delq (car th) (cdr thread)))
4063             (if (boundp (setq ref-dep (intern "none"
4064                                               gnus-newsgroup-dependencies)))
4065                 (setcdr (symbol-value ref-dep)
4066                         (nconc (cdr (symbol-value ref-dep))
4067                                (list (car th))))
4068               (set ref-dep (list nil (car th))))
4069             (setq infloop 1
4070                   stack nil))
4071         ;; Push all the subthreads onto the stack.
4072         (push (cdr thread) stack)))
4073     infloop))
4074
4075 (defun gnus-make-threads ()
4076   "Go through the dependency hashtb and find the roots.  Return all threads."
4077   (let (threads)
4078     (while (catch 'infloop
4079              (mapatoms
4080               (lambda (refs)
4081                 ;; Deal with self-referencing References loops.
4082                 (when (and (car (symbol-value refs))
4083                            (not (zerop
4084                                  (apply
4085                                   '+
4086                                   (mapcar
4087                                    (lambda (thread)
4088                                      (gnus-thread-loop-p
4089                                       (car (symbol-value refs)) thread))
4090                                    (cdr (symbol-value refs)))))))
4091                   (setq threads nil)
4092                   (throw 'infloop t))
4093                 (unless (car (symbol-value refs))
4094                   ;; These threads do not refer back to any other
4095                   ;; articles, so they're roots.
4096                   (setq threads (append (cdr (symbol-value refs)) threads))))
4097               gnus-newsgroup-dependencies)))
4098     threads))
4099
4100 ;; Build the thread tree.
4101 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4102   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4103
4104 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4105 if it was already present.
4106
4107 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4108 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4109 Message-IDs will be renamed to a unique Message-ID before being
4110 entered.
4111
4112 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4113   (let* ((id (mail-header-id header))
4114          (id-dep (and id (intern id dependencies)))
4115          parent-id ref ref-dep ref-header replaced)
4116     ;; Enter this `header' in the `dependencies' table.
4117     (cond
4118      ((not id-dep)
4119       (setq header nil))
4120      ;; The first two cases do the normal part: enter a new `header'
4121      ;; in the `dependencies' table.
4122      ((not (boundp id-dep))
4123       (set id-dep (list header)))
4124      ((null (car (symbol-value id-dep)))
4125       (setcar (symbol-value id-dep) header))
4126
4127      ;; From here the `header' was already present in the
4128      ;; `dependencies' table.
4129      (force-new
4130       ;; Overrides an existing entry;
4131       ;; just set the header part of the entry.
4132       (setcar (symbol-value id-dep) header)
4133       (setq replaced t))
4134
4135      ;; Renames the existing `header' to a unique Message-ID.
4136      ((not gnus-summary-ignore-duplicates)
4137       ;; An article with this Message-ID has already been seen.
4138       ;; We rename the Message-ID.
4139       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4140            (list header))
4141       (mail-header-set-id header id))
4142
4143      ;; The last case ignores an existing entry, except it adds any
4144      ;; additional Xrefs (in case the two articles came from different
4145      ;; servers.
4146      ;; Also sets `header' to `nil' meaning that the `dependencies'
4147      ;; table was *not* modified.
4148      (t
4149       (mail-header-set-xref
4150        (car (symbol-value id-dep))
4151        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4152                    "")
4153                (or (mail-header-xref header) "")))
4154       (setq header nil)))
4155
4156     (when (and header (not replaced))
4157       ;; First check that we are not creating a References loop.
4158       (setq parent-id (gnus-parent-id (mail-header-references header)))
4159       (setq ref parent-id)
4160       (while (and ref
4161                   (setq ref-dep (intern-soft ref dependencies))
4162                   (boundp ref-dep)
4163                   (setq ref-header (car (symbol-value ref-dep))))
4164         (if (string= id ref)
4165             ;; Yuk!  This is a reference loop.  Make the article be a
4166             ;; root article.
4167             (progn
4168               (mail-header-set-references (car (symbol-value id-dep)) "none")
4169               (setq ref nil)
4170               (setq parent-id nil))
4171           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4172       (setq ref-dep (intern (or parent-id "none") dependencies))
4173       (if (boundp ref-dep)
4174           (setcdr (symbol-value ref-dep)
4175                   (nconc (cdr (symbol-value ref-dep))
4176                          (list (symbol-value id-dep))))
4177         (set ref-dep (list nil (symbol-value id-dep)))))
4178     header))
4179
4180 (defun gnus-extract-message-id-from-in-reply-to (string)
4181   (if (string-match "<[^>]+>" string)
4182       (substring string (match-beginning 0) (match-end 0))
4183     nil))
4184
4185 (defun gnus-build-sparse-threads ()
4186   (let ((headers gnus-newsgroup-headers)
4187         (mail-parse-charset gnus-newsgroup-charset)
4188         (gnus-summary-ignore-duplicates t)
4189         header references generation relations
4190         subject child end new-child date)
4191     ;; First we create an alist of generations/relations, where
4192     ;; generations is how much we trust the relation, and the relation
4193     ;; is parent/child.
4194     (gnus-message 7 "Making sparse threads...")
4195     (save-excursion
4196       (nnheader-set-temp-buffer " *gnus sparse threads*")
4197       (while (setq header (pop headers))
4198         (when (and (setq references (mail-header-references header))
4199                    (not (string= references "")))
4200           (insert references)
4201           (setq child (mail-header-id header)
4202                 subject (mail-header-subject header)
4203                 date (mail-header-date header)
4204                 generation 0)
4205           (while (search-backward ">" nil t)
4206             (setq end (1+ (point)))
4207             (when (search-backward "<" nil t)
4208               (setq new-child (buffer-substring (point) end))
4209               (push (list (incf generation)
4210                           child (setq child new-child)
4211                           subject date)
4212                     relations)))
4213           (when child
4214             (push (list (1+ generation) child nil subject) relations))
4215           (erase-buffer)))
4216       (kill-buffer (current-buffer)))
4217     ;; Sort over trustworthiness.
4218     (mapcar
4219      (lambda (relation)
4220        (when (gnus-dependencies-add-header
4221               (make-full-mail-header
4222                gnus-reffed-article-number
4223                (nth 3 relation) "" (or (nth 4 relation) "")
4224                (nth 1 relation)
4225                (or (nth 2 relation) "") 0 0 "")
4226               gnus-newsgroup-dependencies nil)
4227          (push gnus-reffed-article-number gnus-newsgroup-limit)
4228          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4229          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4230                gnus-newsgroup-reads)
4231          (decf gnus-reffed-article-number)))
4232      (sort relations 'car-less-than-car))
4233     (gnus-message 7 "Making sparse threads...done")))
4234
4235 (defun gnus-build-old-threads ()
4236   ;; Look at all the articles that refer back to old articles, and
4237   ;; fetch the headers for the articles that aren't there.  This will
4238   ;; build complete threads - if the roots haven't been expired by the
4239   ;; server, that is.
4240   (let ((mail-parse-charset gnus-newsgroup-charset)
4241         id heads)
4242     (mapatoms
4243      (lambda (refs)
4244        (when (not (car (symbol-value refs)))
4245          (setq heads (cdr (symbol-value refs)))
4246          (while heads
4247            (if (memq (mail-header-number (caar heads))
4248                      gnus-newsgroup-dormant)
4249                (setq heads (cdr heads))
4250              (setq id (symbol-name refs))
4251              (while (and (setq id (gnus-build-get-header id))
4252                          (not (car (gnus-id-to-thread id)))))
4253              (setq heads nil)))))
4254      gnus-newsgroup-dependencies)))
4255
4256 (defsubst gnus-remove-odd-characters (string)
4257   "Translate STRING into something that doesn't contain weird characters."
4258   (mm-subst-char-in-string
4259    ?\r ?\-
4260    (mm-subst-char-in-string ?\n ?\- string t) t))
4261
4262 ;; This function has to be called with point after the article number
4263 ;; on the beginning of the line.
4264 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4265   (let ((eol (point-at-eol))
4266         (buffer (current-buffer))
4267         header references in-reply-to)
4268
4269     ;; overview: [num subject from date id refs chars lines misc]
4270     (unwind-protect
4271         (let (x)
4272           (narrow-to-region (point) eol)
4273           (unless (eobp)
4274             (forward-char))
4275
4276           (setq header
4277                 (make-full-mail-header
4278                  number                 ; number
4279                  (condition-case ()     ; subject
4280                      (gnus-remove-odd-characters
4281                       (funcall gnus-decode-encoded-word-function
4282                                (setq x (nnheader-nov-field))))
4283                    (error x))
4284                  (condition-case ()     ; from
4285                      (gnus-remove-odd-characters
4286                       (funcall gnus-decode-encoded-word-function
4287                                (setq x (nnheader-nov-field))))
4288                    (error x))
4289                  (nnheader-nov-field)   ; date
4290                  (nnheader-nov-read-message-id number)  ; id
4291                  (setq references (nnheader-nov-field)) ; refs
4292                  (nnheader-nov-read-integer) ; chars
4293                  (nnheader-nov-read-integer) ; lines
4294                  (unless (eobp)
4295                    (if (looking-at "Xref: ")
4296                        (goto-char (match-end 0)))
4297                    (nnheader-nov-field)) ; Xref
4298                  (nnheader-nov-parse-extra)))) ; extra
4299
4300       (widen))
4301
4302     (when (and (string= references "")
4303                (setq in-reply-to (mail-header-extra header))
4304                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4305       (mail-header-set-references
4306        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4307
4308     (when gnus-alter-header-function
4309       (funcall gnus-alter-header-function header))
4310     (gnus-dependencies-add-header header dependencies force-new)))
4311
4312 (defun gnus-build-get-header (id)
4313   "Look through the buffer of NOV lines and find the header to ID.
4314 Enter this line into the dependencies hash table, and return
4315 the id of the parent article (if any)."
4316   (let ((deps gnus-newsgroup-dependencies)
4317         found header)
4318     (prog1
4319         (save-excursion
4320           (set-buffer nntp-server-buffer)
4321           (let ((case-fold-search nil))
4322             (goto-char (point-min))
4323             (while (and (not found)
4324                         (search-forward id nil t))
4325               (beginning-of-line)
4326               (setq found (looking-at
4327                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4328                                    (regexp-quote id))))
4329               (or found (beginning-of-line 2)))
4330             (when found
4331               (beginning-of-line)
4332               (and
4333                (setq header (gnus-nov-parse-line
4334                              (read (current-buffer)) deps))
4335                (gnus-parent-id (mail-header-references header))))))
4336       (when header
4337         (let ((number (mail-header-number header)))
4338           (push number gnus-newsgroup-limit)
4339           (push header gnus-newsgroup-headers)
4340           (if (memq number gnus-newsgroup-unselected)
4341               (progn
4342                 (setq gnus-newsgroup-unreads
4343                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4344                                                number))
4345                 (setq gnus-newsgroup-unselected
4346                       (delq number gnus-newsgroup-unselected)))
4347             (push number gnus-newsgroup-ancient)))))))
4348
4349 (defun gnus-build-all-threads ()
4350   "Read all the headers."
4351   (let ((gnus-summary-ignore-duplicates t)
4352         (mail-parse-charset gnus-newsgroup-charset)
4353         (dependencies gnus-newsgroup-dependencies)
4354         header article)
4355     (save-excursion
4356       (set-buffer nntp-server-buffer)
4357       (let ((case-fold-search nil))
4358         (goto-char (point-min))
4359         (while (not (eobp))
4360           (ignore-errors
4361             (setq article (read (current-buffer))
4362                   header (gnus-nov-parse-line article dependencies)))
4363           (when header
4364             (with-current-buffer gnus-summary-buffer
4365               (push header gnus-newsgroup-headers)
4366               (if (memq (setq article (mail-header-number header))
4367                         gnus-newsgroup-unselected)
4368                   (progn
4369                     (setq gnus-newsgroup-unreads
4370                           (gnus-add-to-sorted-list
4371                            gnus-newsgroup-unreads article))
4372                     (setq gnus-newsgroup-unselected
4373                           (delq article gnus-newsgroup-unselected)))
4374                 (push article gnus-newsgroup-ancient)))
4375             (forward-line 1)))))))
4376
4377 (defun gnus-summary-update-article-line (article header)
4378   "Update the line for ARTICLE using HEADER."
4379   (let* ((id (mail-header-id header))
4380          (thread (gnus-id-to-thread id)))
4381     (unless thread
4382       (error "Article in no thread"))
4383     ;; Update the thread.
4384     (setcar thread header)
4385     (gnus-summary-goto-subject article)
4386     (let* ((datal (gnus-data-find-list article))
4387            (data (car datal))
4388            (buffer-read-only nil)
4389            (level (gnus-summary-thread-level)))
4390       (gnus-delete-line)
4391       (let ((inserted (- (point)
4392                          (progn
4393                            (gnus-summary-insert-line
4394                             header level nil
4395                             (memq article gnus-newsgroup-undownloaded)
4396                             (gnus-article-mark article)
4397                             (memq article gnus-newsgroup-replied)
4398                             (memq article gnus-newsgroup-expirable)
4399                             ;; Only insert the Subject string when it's different
4400                             ;; from the previous Subject string.
4401                             (if (and
4402                                  gnus-show-threads
4403                                  (gnus-subject-equal
4404                                   (condition-case ()
4405                                       (mail-header-subject
4406                                        (gnus-data-header
4407                                         (cadr
4408                                          (gnus-data-find-list
4409                                           article
4410                                           (gnus-data-list t)))))
4411                                     ;; Error on the side of excessive subjects.
4412                                     (error ""))
4413                                   (mail-header-subject header)))
4414                                 ""
4415                               (mail-header-subject header))
4416                             nil (cdr (assq article gnus-newsgroup-scored))
4417                             (memq article gnus-newsgroup-processable))
4418                            (point)))))
4419         (when (cdr datal)
4420           (gnus-data-update-list
4421            (cdr datal)
4422            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4423
4424 (defun gnus-summary-update-article (article &optional iheader)
4425   "Update ARTICLE in the summary buffer."
4426   (set-buffer gnus-summary-buffer)
4427   (let* ((header (gnus-summary-article-header article))
4428          (id (mail-header-id header))
4429          (data (gnus-data-find article))
4430          (thread (gnus-id-to-thread id))
4431          (references (mail-header-references header))
4432          (parent
4433           (gnus-id-to-thread
4434            (or (gnus-parent-id
4435                 (when (and references
4436                            (not (equal "" references)))
4437                   references))
4438                "none")))
4439          (buffer-read-only nil)
4440          (old (car thread)))
4441     (when thread
4442       (unless iheader
4443         (setcar thread nil)
4444         (when parent
4445           (delq thread parent)))
4446       (if (gnus-summary-insert-subject id header)
4447           ;; Set the (possibly) new article number in the data structure.
4448           (gnus-data-set-number data (gnus-id-to-article id))
4449         (setcar thread old)
4450         nil))))
4451
4452 (defun gnus-rebuild-thread (id &optional line)
4453   "Rebuild the thread containing ID.
4454 If LINE, insert the rebuilt thread starting on line LINE."
4455   (let ((buffer-read-only nil)
4456         old-pos current thread data)
4457     (if (not gnus-show-threads)
4458         (setq thread (list (car (gnus-id-to-thread id))))
4459       ;; Get the thread this article is part of.
4460       (setq thread (gnus-remove-thread id)))
4461     (setq old-pos (point-at-bol))
4462     (setq current (save-excursion
4463                     (and (re-search-backward "[\r\n]" nil t)
4464                          (gnus-summary-article-number))))
4465     ;; If this is a gathered thread, we have to go some re-gathering.
4466     (when (stringp (car thread))
4467       (let ((subject (car thread))
4468             roots thr)
4469         (setq thread (cdr thread))
4470         (while thread
4471           (unless (memq (setq thr (gnus-id-to-thread
4472                                    (gnus-root-id
4473                                     (mail-header-id (caar thread)))))
4474                         roots)
4475             (push thr roots))
4476           (setq thread (cdr thread)))
4477         ;; We now have all (unique) roots.
4478         (if (= (length roots) 1)
4479             ;; All the loose roots are now one solid root.
4480             (setq thread (car roots))
4481           (setq thread (cons subject (gnus-sort-threads roots))))))
4482     (let (threads)
4483       ;; We then insert this thread into the summary buffer.
4484       (when line
4485         (goto-char (point-min))
4486         (forward-line (1- line)))
4487       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4488         (if gnus-show-threads
4489             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4490           (gnus-summary-prepare-unthreaded thread))
4491         (setq data (nreverse gnus-newsgroup-data))
4492         (setq threads gnus-newsgroup-threads))
4493       ;; We splice the new data into the data structure.
4494       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4495       ;;!!! then we want to insert at the beginning of the buffer.
4496       ;;!!! That happens to be true with Gnus now, but that may
4497       ;;!!! change in the future.  Perhaps.
4498       (gnus-data-enter-list
4499        (if line nil current) data (- (point) old-pos))
4500       (setq gnus-newsgroup-threads
4501             (nconc threads gnus-newsgroup-threads))
4502       (gnus-data-compute-positions))))
4503
4504 (defun gnus-number-to-header (number)
4505   "Return the header for article NUMBER."
4506   (let ((headers gnus-newsgroup-headers))
4507     (while (and headers
4508                 (not (= number (mail-header-number (car headers)))))
4509       (pop headers))
4510     (when headers
4511       (car headers))))
4512
4513 (defun gnus-parent-headers (in-headers &optional generation)
4514   "Return the headers of the GENERATIONeth parent of HEADERS."
4515   (unless generation
4516     (setq generation 1))
4517   (let ((parent t)
4518         (headers in-headers)
4519         references)
4520     (while (and parent
4521                 (not (zerop generation))
4522                 (setq references (mail-header-references headers)))
4523       (setq headers (if (and references
4524                              (setq parent (gnus-parent-id references)))
4525                         (car (gnus-id-to-thread parent))
4526                       nil))
4527       (decf generation))
4528     (and (not (eq headers in-headers))
4529          headers)))
4530
4531 (defun gnus-id-to-thread (id)
4532   "Return the (sub-)thread where ID appears."
4533   (gnus-gethash id gnus-newsgroup-dependencies))
4534
4535 (defun gnus-id-to-article (id)
4536   "Return the article number of ID."
4537   (let ((thread (gnus-id-to-thread id)))
4538     (when (and thread
4539                (car thread))
4540       (mail-header-number (car thread)))))
4541
4542 (defun gnus-id-to-header (id)
4543   "Return the article headers of ID."
4544   (car (gnus-id-to-thread id)))
4545
4546 (defun gnus-article-displayed-root-p (article)
4547   "Say whether ARTICLE is a root(ish) article."
4548   (let ((level (gnus-summary-thread-level article))
4549         (refs (mail-header-references  (gnus-summary-article-header article)))
4550         particle)
4551     (cond
4552      ((null level) nil)
4553      ((zerop level) t)
4554      ((null refs) t)
4555      ((null (gnus-parent-id refs)) t)
4556      ((and (= 1 level)
4557            (null (setq particle (gnus-id-to-article
4558                                  (gnus-parent-id refs))))
4559            (null (gnus-summary-thread-level particle)))))))
4560
4561 (defun gnus-root-id (id)
4562   "Return the id of the root of the thread where ID appears."
4563   (let (last-id prev)
4564     (while (and id (setq prev (car (gnus-id-to-thread id))))
4565       (setq last-id id
4566             id (gnus-parent-id (mail-header-references prev))))
4567     last-id))
4568
4569 (defun gnus-articles-in-thread (thread)
4570   "Return the list of articles in THREAD."
4571   (cons (mail-header-number (car thread))
4572         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4573
4574 (defun gnus-remove-thread (id &optional dont-remove)
4575   "Remove the thread that has ID in it."
4576   (let (headers thread last-id)
4577     ;; First go up in this thread until we find the root.
4578     (setq last-id (gnus-root-id id)
4579           headers (message-flatten-list (gnus-id-to-thread last-id)))
4580     ;; We have now found the real root of this thread.  It might have
4581     ;; been gathered into some loose thread, so we have to search
4582     ;; through the threads to find the thread we wanted.
4583     (let ((threads gnus-newsgroup-threads)
4584           sub)
4585       (while threads
4586         (setq sub (car threads))
4587         (if (stringp (car sub))
4588             ;; This is a gathered thread, so we look at the roots
4589             ;; below it to find whether this article is in this
4590             ;; gathered root.
4591             (progn
4592               (setq sub (cdr sub))
4593               (while sub
4594                 (when (member (caar sub) headers)
4595                   (setq thread (car threads)
4596                         threads nil
4597                         sub nil))
4598                 (setq sub (cdr sub))))
4599           ;; It's an ordinary thread, so we check it.
4600           (when (eq (car sub) (car headers))
4601             (setq thread sub
4602                   threads nil)))
4603         (setq threads (cdr threads)))
4604       ;; If this article is in no thread, then it's a root.
4605       (if thread
4606           (unless dont-remove
4607             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4608         (setq thread (gnus-id-to-thread last-id)))
4609       (when thread
4610         (prog1
4611             thread                      ; We return this thread.
4612           (unless dont-remove
4613             (if (stringp (car thread))
4614                 (progn
4615                   ;; If we use dummy roots, then we have to remove the
4616                   ;; dummy root as well.
4617                   (when (eq gnus-summary-make-false-root 'dummy)
4618                     ;; We go to the dummy root by going to
4619                     ;; the first sub-"thread", and then one line up.
4620                     (gnus-summary-goto-article
4621                      (mail-header-number (caadr thread)))
4622                     (forward-line -1)
4623                     (gnus-delete-line)
4624                     (gnus-data-compute-positions))
4625                   (setq thread (cdr thread))
4626                   (while thread
4627                     (gnus-remove-thread-1 (car thread))
4628                     (setq thread (cdr thread))))
4629               (gnus-remove-thread-1 thread))))))))
4630
4631 (defun gnus-remove-thread-1 (thread)
4632   "Remove the thread THREAD recursively."
4633   (let ((number (mail-header-number (pop thread)))
4634         d)
4635     (setq thread (reverse thread))
4636     (while thread
4637       (gnus-remove-thread-1 (pop thread)))
4638     (when (setq d (gnus-data-find number))
4639       (goto-char (gnus-data-pos d))
4640       (gnus-summary-show-thread)
4641       (gnus-data-remove
4642        number
4643        (- (point-at-bol)
4644           (prog1
4645               (1+ (point-at-eol))
4646             (gnus-delete-line)))))))
4647
4648 (defun gnus-sort-threads-1 (threads func)
4649   (sort (mapcar (lambda (thread)
4650                   (cons (car thread)
4651                         (and (cdr thread)
4652                              (gnus-sort-threads-1 (cdr thread) func))))
4653                 threads) func))
4654
4655 (defun gnus-sort-threads (threads)
4656   "Sort THREADS."
4657   (if (not gnus-thread-sort-functions)
4658       threads
4659     (gnus-message 8 "Sorting threads...")
4660     (let ((max-lisp-eval-depth 5000))
4661       (prog1 (gnus-sort-threads-1
4662          threads
4663          (gnus-make-sort-function gnus-thread-sort-functions))
4664         (gnus-message 8 "Sorting threads...done")))))
4665
4666 (defun gnus-sort-articles (articles)
4667   "Sort ARTICLES."
4668   (when gnus-article-sort-functions
4669     (gnus-message 7 "Sorting articles...")
4670     (prog1
4671         (setq gnus-newsgroup-headers
4672               (sort articles (gnus-make-sort-function
4673                               gnus-article-sort-functions)))
4674       (gnus-message 7 "Sorting articles...done"))))
4675
4676 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4677 (defmacro gnus-thread-header (thread)
4678   "Return header of first article in THREAD.
4679 Note that THREAD must never, ever be anything else than a variable -
4680 using some other form will lead to serious barfage."
4681   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4682   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4683   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4684         (vector thread) 2))
4685
4686 (defsubst gnus-article-sort-by-number (h1 h2)
4687   "Sort articles by article number."
4688   (< (mail-header-number h1)
4689      (mail-header-number h2)))
4690
4691 (defun gnus-thread-sort-by-number (h1 h2)
4692   "Sort threads by root article number."
4693   (gnus-article-sort-by-number
4694    (gnus-thread-header h1) (gnus-thread-header h2)))
4695
4696 (defsubst gnus-article-sort-by-random (h1 h2)
4697   "Sort articles by article number."
4698   (zerop (random 2)))
4699
4700 (defun gnus-thread-sort-by-random (h1 h2)
4701   "Sort threads by root article number."
4702   (gnus-article-sort-by-random
4703    (gnus-thread-header h1) (gnus-thread-header h2)))
4704
4705 (defsubst gnus-article-sort-by-lines (h1 h2)
4706   "Sort articles by article Lines header."
4707   (< (mail-header-lines h1)
4708      (mail-header-lines h2)))
4709
4710 (defun gnus-thread-sort-by-lines (h1 h2)
4711   "Sort threads by root article Lines header."
4712   (gnus-article-sort-by-lines
4713    (gnus-thread-header h1) (gnus-thread-header h2)))
4714
4715 (defsubst gnus-article-sort-by-chars (h1 h2)
4716   "Sort articles by octet length."
4717   (< (mail-header-chars h1)
4718      (mail-header-chars h2)))
4719
4720 (defun gnus-thread-sort-by-chars (h1 h2)
4721   "Sort threads by root article octet length."
4722   (gnus-article-sort-by-chars
4723    (gnus-thread-header h1) (gnus-thread-header h2)))
4724
4725 (defsubst gnus-article-sort-by-author (h1 h2)
4726   "Sort articles by root author."
4727   (string-lessp
4728    (let ((extract (funcall
4729                    gnus-extract-address-components
4730                    (mail-header-from h1))))
4731      (or (car extract) (cadr extract) ""))
4732    (let ((extract (funcall
4733                    gnus-extract-address-components
4734                    (mail-header-from h2))))
4735      (or (car extract) (cadr extract) ""))))
4736
4737 (defun gnus-thread-sort-by-author (h1 h2)
4738   "Sort threads by root author."
4739   (gnus-article-sort-by-author
4740    (gnus-thread-header h1)  (gnus-thread-header h2)))
4741
4742 (defsubst gnus-article-sort-by-recipient (h1 h2)
4743   "Sort articles by recipient."
4744   (string-lessp
4745    (let ((extract (funcall
4746                    gnus-extract-address-components
4747                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4748      (or (car extract) (cadr extract)))
4749    (let ((extract (funcall
4750                    gnus-extract-address-components
4751                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4752      (or (car extract) (cadr extract)))))
4753
4754 (defun gnus-thread-sort-by-recipient (h1 h2)
4755   "Sort threads by root recipient."
4756   (gnus-article-sort-by-recipient
4757    (gnus-thread-header h1) (gnus-thread-header h2)))
4758
4759 (defsubst gnus-article-sort-by-subject (h1 h2)
4760   "Sort articles by root subject."
4761   (string-lessp
4762    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4763    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4764
4765 (defun gnus-thread-sort-by-subject (h1 h2)
4766   "Sort threads by root subject."
4767   (gnus-article-sort-by-subject
4768    (gnus-thread-header h1) (gnus-thread-header h2)))
4769
4770 (defsubst gnus-article-sort-by-date (h1 h2)
4771   "Sort articles by root article date."
4772   (time-less-p
4773    (gnus-date-get-time (mail-header-date h1))
4774    (gnus-date-get-time (mail-header-date h2))))
4775
4776 (defun gnus-thread-sort-by-date (h1 h2)
4777   "Sort threads by root article date."
4778   (gnus-article-sort-by-date
4779    (gnus-thread-header h1) (gnus-thread-header h2)))
4780
4781 (defsubst gnus-article-sort-by-score (h1 h2)
4782   "Sort articles by root article score.
4783 Unscored articles will be counted as having a score of zero."
4784   (> (or (cdr (assq (mail-header-number h1)
4785                     gnus-newsgroup-scored))
4786          gnus-summary-default-score 0)
4787      (or (cdr (assq (mail-header-number h2)
4788                     gnus-newsgroup-scored))
4789          gnus-summary-default-score 0)))
4790
4791 (defun gnus-thread-sort-by-score (h1 h2)
4792   "Sort threads by root article score."
4793   (gnus-article-sort-by-score
4794    (gnus-thread-header h1) (gnus-thread-header h2)))
4795
4796 (defun gnus-thread-sort-by-total-score (h1 h2)
4797   "Sort threads by the sum of all scores in the thread.
4798 Unscored articles will be counted as having a score of zero."
4799   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4800
4801 (defun gnus-thread-total-score (thread)
4802   ;; This function find the total score of THREAD.
4803   (cond
4804    ((null thread)
4805     0)
4806    ((consp thread)
4807     (if (stringp (car thread))
4808         (apply gnus-thread-score-function 0
4809                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4810       (gnus-thread-total-score-1 thread)))
4811    (t
4812     (gnus-thread-total-score-1 (list thread)))))
4813
4814 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4815   "Sort threads such that the thread with the most recently arrived article comes first."
4816   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4817
4818 (defun gnus-thread-highest-number (thread)
4819   "Return the highest article number in THREAD."
4820   (apply 'max (mapcar (lambda (header)
4821                         (mail-header-number header))
4822                       (message-flatten-list thread))))
4823
4824 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4825   "Sort threads such that the thread with the most recently dated article comes first."
4826   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4827
4828 (defun gnus-thread-latest-date (thread)
4829   "Return the highest article date in THREAD."
4830   (let ((previous-time 0))
4831     (apply 'max
4832            (mapcar
4833             (lambda (header)
4834               (setq previous-time
4835                     (condition-case ()
4836                         (time-to-seconds (mail-header-parse-date
4837                                           (mail-header-date header)))
4838                       (error previous-time))))
4839             (sort
4840              (message-flatten-list thread)
4841              (lambda (h1 h2)
4842                (< (mail-header-number h1)
4843                   (mail-header-number h2))))))))
4844
4845 (defun gnus-thread-total-score-1 (root)
4846   ;; This function find the total score of the thread below ROOT.
4847   (setq root (car root))
4848   (apply gnus-thread-score-function
4849          (or (append
4850               (mapcar 'gnus-thread-total-score
4851                       (cdr (gnus-id-to-thread (mail-header-id root))))
4852               (when (> (mail-header-number root) 0)
4853                 (list (or (cdr (assq (mail-header-number root)
4854                                      gnus-newsgroup-scored))
4855                           gnus-summary-default-score 0))))
4856              (list gnus-summary-default-score)
4857              '(0))))
4858
4859 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4860 (defvar gnus-tmp-prev-subject nil)
4861 (defvar gnus-tmp-false-parent nil)
4862 (defvar gnus-tmp-root-expunged nil)
4863 (defvar gnus-tmp-dummy-line nil)
4864
4865 (eval-when-compile (defvar gnus-tmp-header))
4866 (defun gnus-extra-header (type &optional header)
4867   "Return the extra header of TYPE."
4868   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4869       ""))
4870
4871 (defvar gnus-tmp-thread-tree-header-string "")
4872
4873 (defcustom gnus-sum-thread-tree-root "> "
4874   "With %B spec, used for the root of a thread.
4875 If nil, use subject instead."
4876   :version "22.1"
4877   :type '(radio (const :format "%v  " nil) string)
4878   :group 'gnus-thread)
4879
4880 (defcustom gnus-sum-thread-tree-false-root "> "
4881   "With %B spec, used for a false root of a thread.
4882 If nil, use subject instead."
4883   :version "22.1"
4884   :type '(radio (const :format "%v  " nil) string)
4885   :group 'gnus-thread)
4886
4887 (defcustom gnus-sum-thread-tree-single-indent ""
4888   "With %B spec, used for a thread with just one message.
4889 If nil, use subject instead."
4890   :version "22.1"
4891   :type '(radio (const :format "%v  " nil) string)
4892   :group 'gnus-thread)
4893
4894 (defcustom gnus-sum-thread-tree-vertical "| "
4895   "With %B spec, used for drawing a vertical line."
4896   :version "22.1"
4897   :type 'string
4898   :group 'gnus-thread)
4899
4900 (defcustom gnus-sum-thread-tree-indent "  "
4901   "With %B spec, used for indenting."
4902   :version "22.1"
4903   :type 'string
4904   :group 'gnus-thread)
4905
4906 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4907   "With %B spec, used for a leaf with brothers."
4908   :version "22.1"
4909   :type 'string
4910   :group 'gnus-thread)
4911
4912 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4913   "With %B spec, used for a leaf without brothers."
4914   :version "22.1"
4915   :type 'string
4916   :group 'gnus-thread)
4917
4918 (defun gnus-summary-prepare-threads (threads)
4919   "Prepare summary buffer from THREADS and indentation LEVEL.
4920 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4921 or a straight list of headers."
4922   (gnus-message 7 "Generating summary...")
4923
4924   (setq gnus-newsgroup-threads threads)
4925   (beginning-of-line)
4926
4927   (let ((gnus-tmp-level 0)
4928         (default-score (or gnus-summary-default-score 0))
4929         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4930         (building-line-count gnus-summary-display-while-building)
4931         (building-count (integerp gnus-summary-display-while-building))
4932         thread number subject stack state gnus-tmp-gathered beg-match
4933         new-roots gnus-tmp-new-adopts thread-end simp-subject
4934         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4935         gnus-tmp-replied gnus-tmp-subject-or-nil
4936         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4937         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4938         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4939         tree-stack)
4940
4941     (setq gnus-tmp-prev-subject nil
4942           gnus-tmp-thread-tree-header-string "")
4943
4944     (if (vectorp (car threads))
4945         ;; If this is a straight (sic) list of headers, then a
4946         ;; threaded summary display isn't required, so we just create
4947         ;; an unthreaded one.
4948         (gnus-summary-prepare-unthreaded threads)
4949
4950       ;; Do the threaded display.
4951
4952       (if gnus-summary-display-while-building
4953           (switch-to-buffer (buffer-name)))
4954       (while (or threads stack gnus-tmp-new-adopts new-roots)
4955
4956         (if (and (= gnus-tmp-level 0)
4957                  (or (not stack)
4958                      (= (caar stack) 0))
4959                  (not gnus-tmp-false-parent)
4960                  (or gnus-tmp-new-adopts new-roots))
4961             (if gnus-tmp-new-adopts
4962                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4963                       thread (list (car gnus-tmp-new-adopts))
4964                       gnus-tmp-header (caar thread)
4965                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4966               (when new-roots
4967                 (setq thread (list (car new-roots))
4968                       gnus-tmp-header (caar thread)
4969                       new-roots (cdr new-roots))))
4970
4971           (if threads
4972               ;; If there are some threads, we do them before the
4973               ;; threads on the stack.
4974               (setq thread threads
4975                     gnus-tmp-header (caar thread))
4976             ;; There were no current threads, so we pop something off
4977             ;; the stack.
4978             (setq state (car stack)
4979                   gnus-tmp-level (car state)
4980                   tree-stack (cadr state)
4981                   thread (caddr state)
4982                   stack (cdr stack)
4983                   gnus-tmp-header (caar thread))))
4984
4985         (setq gnus-tmp-false-parent nil)
4986         (setq gnus-tmp-root-expunged nil)
4987         (setq thread-end nil)
4988
4989         (if (stringp gnus-tmp-header)
4990             ;; The header is a dummy root.
4991             (cond
4992              ((eq gnus-summary-make-false-root 'adopt)
4993               ;; We let the first article adopt the rest.
4994               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4995                                                (cddar thread)))
4996               (setq gnus-tmp-gathered
4997                     (nconc (mapcar
4998                             (lambda (h) (mail-header-number (car h)))
4999                             (cddar thread))
5000                            gnus-tmp-gathered))
5001               (setq thread (cons (list (caar thread)
5002                                        (cadar thread))
5003                                  (cdr thread)))
5004               (setq gnus-tmp-level -1
5005                     gnus-tmp-false-parent t))
5006              ((eq gnus-summary-make-false-root 'empty)
5007               ;; We print adopted articles with empty subject fields.
5008               (setq gnus-tmp-gathered
5009                     (nconc (mapcar
5010                             (lambda (h) (mail-header-number (car h)))
5011                             (cddar thread))
5012                            gnus-tmp-gathered))
5013               (setq gnus-tmp-level -1))
5014              ((eq gnus-summary-make-false-root 'dummy)
5015               ;; We remember that we probably want to output a dummy
5016               ;; root.
5017               (setq gnus-tmp-dummy-line gnus-tmp-header)
5018               (setq gnus-tmp-prev-subject gnus-tmp-header))
5019              (t
5020               ;; We do not make a root for the gathered
5021               ;; sub-threads at all.
5022               (setq gnus-tmp-level -1)))
5023
5024           (setq number (mail-header-number gnus-tmp-header)
5025                 subject (mail-header-subject gnus-tmp-header)
5026                 simp-subject (gnus-simplify-subject-fully subject))
5027
5028           (cond
5029            ;; If the thread has changed subject, we might want to make
5030            ;; this subthread into a root.
5031            ((and (null gnus-thread-ignore-subject)
5032                  (not (zerop gnus-tmp-level))
5033                  gnus-tmp-prev-subject
5034                  (not (string= gnus-tmp-prev-subject simp-subject)))
5035             (setq new-roots (nconc new-roots (list (car thread)))
5036                   thread-end t
5037                   gnus-tmp-header nil))
5038            ;; If the article lies outside the current limit,
5039            ;; then we do not display it.
5040            ((not (memq number gnus-newsgroup-limit))
5041             (setq gnus-tmp-gathered
5042                   (nconc (mapcar
5043                           (lambda (h) (mail-header-number (car h)))
5044                           (cdar thread))
5045                          gnus-tmp-gathered))
5046             (setq gnus-tmp-new-adopts (if (cdar thread)
5047                                           (append gnus-tmp-new-adopts
5048                                                   (cdar thread))
5049                                         gnus-tmp-new-adopts)
5050                   thread-end t
5051                   gnus-tmp-header nil)
5052             (when (zerop gnus-tmp-level)
5053               (setq gnus-tmp-root-expunged t)))
5054            ;; Perhaps this article is to be marked as read?
5055            ((and gnus-summary-mark-below
5056                  (< (or (cdr (assq number gnus-newsgroup-scored))
5057                         default-score)
5058                     gnus-summary-mark-below)
5059                  ;; Don't touch sparse articles.
5060                  (not (gnus-summary-article-sparse-p number))
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                 (setq gnus-newsgroup-expirable
5066                       (gnus-add-to-sorted-list
5067                        gnus-newsgroup-expirable number))
5068               (push (cons number gnus-low-score-mark)
5069                     gnus-newsgroup-reads))))
5070
5071           (when gnus-tmp-header
5072             ;; We may have an old dummy line to output before this
5073             ;; article.
5074             (when (and gnus-tmp-dummy-line
5075                        (gnus-subject-equal
5076                         gnus-tmp-dummy-line
5077                         (mail-header-subject gnus-tmp-header)))
5078               (gnus-summary-insert-dummy-line
5079                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5080               (setq gnus-tmp-dummy-line nil))
5081
5082             ;; Compute the mark.
5083             (setq gnus-tmp-unread (gnus-article-mark number))
5084
5085             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5086                                   gnus-tmp-header gnus-tmp-level)
5087                   gnus-newsgroup-data)
5088
5089             ;; Actually insert the line.
5090             (setq
5091              gnus-tmp-subject-or-nil
5092              (cond
5093               ((and gnus-thread-ignore-subject
5094                     gnus-tmp-prev-subject
5095                     (not (string= gnus-tmp-prev-subject simp-subject)))
5096                subject)
5097               ((zerop gnus-tmp-level)
5098                (if (and (eq gnus-summary-make-false-root 'empty)
5099                         (memq number gnus-tmp-gathered)
5100                         gnus-tmp-prev-subject
5101                         (string= gnus-tmp-prev-subject simp-subject))
5102                    gnus-summary-same-subject
5103                  subject))
5104               (t gnus-summary-same-subject)))
5105             (if (and (eq gnus-summary-make-false-root 'adopt)
5106                      (= gnus-tmp-level 1)
5107                      (memq number gnus-tmp-gathered))
5108                 (setq gnus-tmp-opening-bracket ?\<
5109                       gnus-tmp-closing-bracket ?\>)
5110               (setq gnus-tmp-opening-bracket ?\[
5111                     gnus-tmp-closing-bracket ?\]))
5112             (setq
5113              gnus-tmp-indentation
5114              (aref gnus-thread-indent-array gnus-tmp-level)
5115              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5116              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5117                                 gnus-summary-default-score 0)
5118              gnus-tmp-score-char
5119              (if (or (null gnus-summary-default-score)
5120                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5121                          gnus-summary-zcore-fuzz))
5122                  ?                      ;Whitespace
5123                (if (< gnus-tmp-score gnus-summary-default-score)
5124                    gnus-score-below-mark gnus-score-over-mark))
5125              gnus-tmp-replied
5126              (cond ((memq number gnus-newsgroup-processable)
5127                     gnus-process-mark)
5128                    ((memq number gnus-newsgroup-cached)
5129                     gnus-cached-mark)
5130                    ((memq number gnus-newsgroup-replied)
5131                     gnus-replied-mark)
5132                    ((memq number gnus-newsgroup-forwarded)
5133                     gnus-forwarded-mark)
5134                    ((memq number gnus-newsgroup-saved)
5135                     gnus-saved-mark)
5136                    ((memq number gnus-newsgroup-recent)
5137                     gnus-recent-mark)
5138                    ((memq number gnus-newsgroup-unseen)
5139                     gnus-unseen-mark)
5140                    (t gnus-no-mark))
5141              gnus-tmp-downloaded
5142              (cond ((memq number gnus-newsgroup-undownloaded)
5143                     gnus-undownloaded-mark)
5144                    (gnus-newsgroup-agentized
5145                     gnus-downloaded-mark)
5146                    (t
5147                     gnus-no-mark))
5148              gnus-tmp-from (mail-header-from gnus-tmp-header)
5149              gnus-tmp-name
5150              (cond
5151               ((string-match "<[^>]+> *$" gnus-tmp-from)
5152                (setq beg-match (match-beginning 0))
5153                (or (and (string-match "^\".+\"" gnus-tmp-from)
5154                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5155                    (substring gnus-tmp-from 0 beg-match)))
5156               ((string-match "(.+)" gnus-tmp-from)
5157                (substring gnus-tmp-from
5158                           (1+ (match-beginning 0)) (1- (match-end 0))))
5159               (t gnus-tmp-from))
5160
5161              ;; Do the %B string
5162              gnus-tmp-thread-tree-header-string
5163              (cond
5164               ((not gnus-show-threads) "")
5165               ((zerop gnus-tmp-level)
5166                (cond ((cdar thread)
5167                       (or gnus-sum-thread-tree-root subject))
5168                      (gnus-tmp-new-adopts
5169                       (or gnus-sum-thread-tree-false-root subject))
5170                      (t
5171                       (or gnus-sum-thread-tree-single-indent subject))))
5172               (t
5173                (concat (apply 'concat
5174                               (mapcar (lambda (item)
5175                                         (if (= item 1)
5176                                             gnus-sum-thread-tree-vertical
5177                                           gnus-sum-thread-tree-indent))
5178                                       (cdr (reverse tree-stack))))
5179                        (if (nth 1 thread)
5180                            gnus-sum-thread-tree-leaf-with-other
5181                          gnus-sum-thread-tree-single-leaf)))))
5182             (when (string= gnus-tmp-name "")
5183               (setq gnus-tmp-name gnus-tmp-from))
5184             (unless (numberp gnus-tmp-lines)
5185               (setq gnus-tmp-lines -1))
5186             (if (= gnus-tmp-lines -1)
5187                 (setq gnus-tmp-lines "?")
5188               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5189               (gnus-put-text-property
5190              (point)
5191              (progn (eval gnus-summary-line-format-spec) (point))
5192                'gnus-number number)
5193             (when gnus-visual-p
5194               (forward-line -1)
5195               (gnus-run-hooks 'gnus-summary-update-hook)
5196               (forward-line 1))
5197
5198             (setq gnus-tmp-prev-subject simp-subject)))
5199
5200         (when (nth 1 thread)
5201           (push (list (max 0 gnus-tmp-level)
5202                       (copy-sequence tree-stack)
5203                       (nthcdr 1 thread))
5204                 stack))
5205         (push (if (nth 1 thread) 1 0) tree-stack)
5206         (incf gnus-tmp-level)
5207         (setq threads (if thread-end nil (cdar thread)))
5208         (if gnus-summary-display-while-building
5209             (if building-count
5210                 (progn
5211                   ;; use a set frequency
5212                   (setq building-line-count (1- building-line-count))
5213                   (when (= building-line-count 0)
5214                     (sit-for 0)
5215                     (setq building-line-count
5216                           gnus-summary-display-while-building)))
5217               ;; always
5218               (sit-for 0)))
5219         (unless threads
5220           (setq gnus-tmp-level 0)))))
5221   (gnus-message 7 "Generating summary...done"))
5222
5223 (defun gnus-summary-prepare-unthreaded (headers)
5224   "Generate an unthreaded summary buffer based on HEADERS."
5225   (let (header number mark)
5226
5227     (beginning-of-line)
5228
5229     (while headers
5230       ;; We may have to root out some bad articles...
5231       (when (memq (setq number (mail-header-number
5232                                 (setq header (pop headers))))
5233                   gnus-newsgroup-limit)
5234         ;; Mark article as read when it has a low score.
5235         (when (and gnus-summary-mark-below
5236                    (< (or (cdr (assq number gnus-newsgroup-scored))
5237                           gnus-summary-default-score 0)
5238                       gnus-summary-mark-below)
5239                    (not (gnus-summary-article-ancient-p number)))
5240           (setq gnus-newsgroup-unreads
5241                 (delq number gnus-newsgroup-unreads))
5242           (if gnus-newsgroup-auto-expire
5243               (push number gnus-newsgroup-expirable)
5244             (push (cons number gnus-low-score-mark)
5245                   gnus-newsgroup-reads)))
5246
5247         (setq mark (gnus-article-mark number))
5248         (push (gnus-data-make number mark (1+ (point)) header 0)
5249               gnus-newsgroup-data)
5250         (gnus-summary-insert-line
5251          header 0 number
5252          (memq number gnus-newsgroup-undownloaded)
5253          mark (memq number gnus-newsgroup-replied)
5254          (memq number gnus-newsgroup-expirable)
5255          (mail-header-subject header) nil
5256          (cdr (assq number gnus-newsgroup-scored))
5257          (memq number gnus-newsgroup-processable))))))
5258
5259 (defun gnus-summary-remove-list-identifiers ()
5260   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5261   (let ((regexp (if (consp gnus-list-identifiers)
5262                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5263                   gnus-list-identifiers))
5264         changed subject)
5265     (when regexp
5266       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5267       (dolist (header gnus-newsgroup-headers)
5268         (setq subject (mail-header-subject header)
5269               changed nil)
5270         (while (string-match regexp subject)
5271           (setq subject
5272                 (concat (substring subject 0 (match-beginning 1))
5273                         (substring subject (match-end 0)))
5274                 changed t))
5275         (when changed
5276           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5277             (setq subject
5278                   (concat (substring subject 0 (match-beginning 1))
5279                           (substring subject (match-end 1)))))
5280           (mail-header-set-subject header subject))))))
5281
5282 (defun gnus-fetch-headers (articles)
5283   "Fetch headers of ARTICLES."
5284   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5285     (gnus-message 5 "Fetching headers for %s..." name)
5286     (prog1
5287         (if (eq 'nov
5288                 (setq gnus-headers-retrieved-by
5289                       (gnus-retrieve-headers
5290                        articles gnus-newsgroup-name
5291                        ;; We might want to fetch old headers, but
5292                        ;; not if there is only 1 article.
5293                        (and (or (and
5294                                  (not (eq gnus-fetch-old-headers 'some))
5295                                  (not (numberp gnus-fetch-old-headers)))
5296                                 (> (length articles) 1))
5297                             gnus-fetch-old-headers))))
5298             (gnus-get-newsgroup-headers-xover
5299              articles nil nil gnus-newsgroup-name t)
5300           (gnus-get-newsgroup-headers))
5301       (gnus-message 5 "Fetching headers for %s...done" name))))
5302
5303 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5304   "Select newsgroup GROUP.
5305 If READ-ALL is non-nil, all articles in the group are selected.
5306 If SELECT-ARTICLES, only select those articles from GROUP."
5307   (let* ((entry (gnus-group-entry group))
5308          ;;!!! Dirty hack; should be removed.
5309          (gnus-summary-ignore-duplicates
5310           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5311               t
5312             gnus-summary-ignore-duplicates))
5313          (info (nth 2 entry))
5314          articles fetched-articles cached)
5315
5316     (unless (gnus-check-server
5317              (set (make-local-variable 'gnus-current-select-method)
5318                   (gnus-find-method-for-group group)))
5319       (error "Couldn't open server"))
5320
5321     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5322         (gnus-activate-group group)     ; Or we can activate it...
5323         (progn                          ; Or we bug out.
5324           (when (equal major-mode 'gnus-summary-mode)
5325             (gnus-kill-buffer (current-buffer)))
5326           (error "Couldn't activate group %s: %s"
5327                  group (gnus-status-message group))))
5328
5329     (unless (gnus-request-group group t)
5330       (when (equal major-mode 'gnus-summary-mode)
5331         (gnus-kill-buffer (current-buffer)))
5332       (error "Couldn't request group %s: %s"
5333              group (gnus-status-message group)))
5334
5335     (when gnus-agent
5336       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5337
5338       (setq gnus-summary-use-undownloaded-faces
5339             (gnus-agent-find-parameter
5340              group
5341              'agent-enable-undownloaded-faces)))
5342
5343     (setq gnus-newsgroup-name group
5344           gnus-newsgroup-unselected nil
5345           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5346
5347     (let ((display (gnus-group-find-parameter group 'display)))
5348       (setq gnus-newsgroup-display
5349             (cond
5350              ((not (zerop (or (car-safe read-all) 0)))
5351               ;; The user entered the group with C-u SPC/RET, let's show
5352               ;; all articles.
5353               'gnus-not-ignore)
5354              ((eq display 'all)
5355               'gnus-not-ignore)
5356              ((arrayp display)
5357               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5358              ((numberp display)
5359               ;; The following is probably the "correct" solution, but
5360               ;; it makes Gnus fetch all headers and then limit the
5361               ;; articles (which is slow), so instead we hack the
5362               ;; select-articles parameter instead. -- Simon Josefsson
5363               ;; <jas@kth.se>
5364               ;;
5365               ;; (gnus-byte-compile
5366               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5367               ;;                         display)))))
5368               (setq select-articles
5369                     (gnus-uncompress-range
5370                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5371                              (if (> tmp 0)
5372                                  tmp
5373                                1))
5374                            (cdr (gnus-active group)))))
5375               nil)
5376              (t
5377               nil))))
5378
5379     (gnus-summary-setup-default-charset)
5380
5381     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5382     (when (gnus-virtual-group-p group)
5383       (setq cached gnus-newsgroup-cached))
5384
5385     (setq gnus-newsgroup-unreads
5386           (gnus-sorted-ndifference
5387            (gnus-sorted-ndifference gnus-newsgroup-unreads
5388                                     gnus-newsgroup-marked)
5389            gnus-newsgroup-dormant))
5390
5391     (setq gnus-newsgroup-processable nil)
5392
5393     (gnus-update-read-articles group gnus-newsgroup-unreads)
5394
5395     ;; Adjust and set lists of article marks.
5396     (when info
5397       (gnus-adjust-marked-articles info))
5398     (if (setq articles select-articles)
5399         (setq gnus-newsgroup-unselected
5400               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5401       (setq articles (gnus-articles-to-read group read-all)))
5402
5403     (cond
5404      ((null articles)
5405       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5406       'quit)
5407      ((eq articles 0) nil)
5408      (t
5409       ;; Init the dependencies hash table.
5410       (setq gnus-newsgroup-dependencies
5411             (gnus-make-hashtable (length articles)))
5412       (gnus-set-global-variables)
5413       ;; Retrieve the headers and read them in.
5414
5415       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5416
5417       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5418       (when cached
5419         (setq gnus-newsgroup-cached cached))
5420
5421       ;; Suppress duplicates?
5422       (when gnus-suppress-duplicates
5423         (gnus-dup-suppress-articles))
5424
5425       ;; Set the initial limit.
5426       (setq gnus-newsgroup-limit (copy-sequence articles))
5427       ;; Remove canceled articles from the list of unread articles.
5428       (setq fetched-articles
5429             (mapcar (lambda (headers) (mail-header-number headers))
5430                     gnus-newsgroup-headers))
5431       (setq gnus-newsgroup-articles fetched-articles)
5432       (setq gnus-newsgroup-unreads
5433             (gnus-sorted-nintersection
5434              gnus-newsgroup-unreads fetched-articles))
5435       (gnus-compute-unseen-list)
5436
5437       ;; Removed marked articles that do not exist.
5438       (gnus-update-missing-marks
5439        (gnus-sorted-difference articles fetched-articles))
5440       ;; We might want to build some more threads first.
5441       (when (and gnus-fetch-old-headers
5442                  (eq gnus-headers-retrieved-by 'nov))
5443         (if (eq gnus-fetch-old-headers 'invisible)
5444             (gnus-build-all-threads)
5445           (gnus-build-old-threads)))
5446       ;; Let the Gnus agent mark articles as read.
5447       (when gnus-agent
5448         (gnus-agent-get-undownloaded-list))
5449       ;; Remove list identifiers from subject
5450       (when gnus-list-identifiers
5451         (gnus-summary-remove-list-identifiers))
5452       ;; Check whether auto-expire is to be done in this group.
5453       (setq gnus-newsgroup-auto-expire
5454             (gnus-group-auto-expirable-p group))
5455       ;; Set up the article buffer now, if necessary.
5456       (unless (and gnus-single-article-buffer
5457                    (equal gnus-article-buffer "*Article*"))
5458         (gnus-article-setup-buffer))
5459       ;; First and last article in this newsgroup.
5460       (when gnus-newsgroup-headers
5461         (setq gnus-newsgroup-begin
5462               (mail-header-number (car gnus-newsgroup-headers))
5463               gnus-newsgroup-end
5464               (mail-header-number
5465                (gnus-last-element gnus-newsgroup-headers))))
5466       ;; GROUP is successfully selected.
5467       (or gnus-newsgroup-headers t)))))
5468
5469 (defun gnus-compute-unseen-list ()
5470   ;; The `seen' marks are treated specially.
5471   (if (not gnus-newsgroup-seen)
5472       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5473     (setq gnus-newsgroup-unseen
5474           (gnus-inverse-list-range-intersection
5475            gnus-newsgroup-articles gnus-newsgroup-seen))))
5476
5477 (defun gnus-summary-display-make-predicate (display)
5478   (require 'gnus-agent)
5479   (when (= (length display) 1)
5480     (setq display (car display)))
5481   (unless gnus-summary-display-cache
5482     (dolist (elem (append '((unread . unread)
5483                             (read . read)
5484                             (unseen . unseen))
5485                           gnus-article-mark-lists))
5486       (push (cons (cdr elem)
5487                   (gnus-byte-compile
5488                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5489             gnus-summary-display-cache)))
5490   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5491         (gnus-category-predicate-cache gnus-summary-display-cache))
5492     (gnus-get-predicate display)))
5493
5494 ;; Uses the dynamically bound `number' variable.
5495 (eval-when-compile
5496   (defvar number))
5497 (defun gnus-article-marked-p (type &optional article)
5498   (let ((article (or article number)))
5499     (cond
5500      ((eq type 'tick)
5501       (memq article gnus-newsgroup-marked))
5502      ((eq type 'spam)
5503       (memq article gnus-newsgroup-spam-marked))
5504      ((eq type 'unsend)
5505       (memq article gnus-newsgroup-unsendable))
5506      ((eq type 'undownload)
5507       (memq article gnus-newsgroup-undownloaded))
5508      ((eq type 'download)
5509       (memq article gnus-newsgroup-downloadable))
5510      ((eq type 'unread)
5511       (memq article gnus-newsgroup-unreads))
5512      ((eq type 'read)
5513       (memq article gnus-newsgroup-reads))
5514      ((eq type 'dormant)
5515       (memq article gnus-newsgroup-dormant) )
5516      ((eq type 'expire)
5517       (memq article gnus-newsgroup-expirable))
5518      ((eq type 'reply)
5519       (memq article gnus-newsgroup-replied))
5520      ((eq type 'killed)
5521       (memq article gnus-newsgroup-killed))
5522      ((eq type 'bookmark)
5523       (assq article gnus-newsgroup-bookmarks))
5524      ((eq type 'score)
5525       (assq article gnus-newsgroup-scored))
5526      ((eq type 'save)
5527       (memq article gnus-newsgroup-saved))
5528      ((eq type 'cache)
5529       (memq article gnus-newsgroup-cached))
5530      ((eq type 'forward)
5531       (memq article gnus-newsgroup-forwarded))
5532      ((eq type 'seen)
5533       (not (memq article gnus-newsgroup-unseen)))
5534      ((eq type 'recent)
5535       (memq article gnus-newsgroup-recent))
5536      (t t))))
5537
5538 (defun gnus-articles-to-read (group &optional read-all)
5539   "Find out what articles the user wants to read."
5540   (let* ((articles
5541           ;; Select all articles if `read-all' is non-nil, or if there
5542           ;; are no unread articles.
5543           (if (or read-all
5544                   (and (zerop (length gnus-newsgroup-marked))
5545                        (zerop (length gnus-newsgroup-unreads)))
5546                   ;; Fetch all if the predicate is non-nil.
5547                   gnus-newsgroup-display)
5548               ;; We want to select the headers for all the articles in
5549               ;; the group, so we select either all the active
5550               ;; articles in the group, or (if that's nil), the
5551               ;; articles in the cache.
5552               (or
5553                (gnus-uncompress-range (gnus-active group))
5554                (gnus-cache-articles-in-group group))
5555             ;; Select only the "normal" subset of articles.
5556             (gnus-sorted-nunion
5557              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5558              gnus-newsgroup-unreads)))
5559          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5560          (scored (length scored-list))
5561          (number (length articles))
5562          (marked (+ (length gnus-newsgroup-marked)
5563                     (length gnus-newsgroup-dormant)))
5564          (select
5565           (cond
5566            ((numberp read-all)
5567             read-all)
5568            ((numberp gnus-newsgroup-display)
5569             gnus-newsgroup-display)
5570            (t
5571             (condition-case ()
5572                 (cond
5573                  ((and (or (<= scored marked) (= scored number))
5574                        (numberp gnus-large-newsgroup)
5575                        (> number gnus-large-newsgroup))
5576                   (let* ((cursor-in-echo-area nil)
5577                          (initial (gnus-parameter-large-newsgroup-initial
5578                                    gnus-newsgroup-name))
5579                          (input
5580                           (read-string
5581                            (format
5582                             "How many articles from %s (%s %d): "
5583                             (gnus-limit-string
5584                              (gnus-group-decoded-name gnus-newsgroup-name)
5585                              35)
5586                             (if initial "max" "default")
5587                             number)
5588                            (if initial
5589                                (cons (number-to-string initial)
5590                                      0)))))
5591                     (if (string-match "^[ \t]*$" input) number input)))
5592                  ((and (> scored marked) (< scored number)
5593                        (> (- scored number) 20))
5594                   (let ((input
5595                          (read-string
5596                           (format "%s %s (%d scored, %d total): "
5597                                   "How many articles from"
5598                                   (gnus-group-decoded-name group)
5599                                   scored number))))
5600                     (if (string-match "^[ \t]*$" input)
5601                         number input)))
5602                  (t number))
5603               (quit
5604                (message "Quit getting the articles to read")
5605                nil))))))
5606     (setq select (if (stringp select) (string-to-number select) select))
5607     (if (or (null select) (zerop select))
5608         select
5609       (if (and (not (zerop scored)) (<= (abs select) scored))
5610           (progn
5611             (setq articles (sort scored-list '<))
5612             (setq number (length articles)))
5613         (setq articles (copy-sequence articles)))
5614
5615       (when (< (abs select) number)
5616         (if (< select 0)
5617             ;; Select the N oldest articles.
5618             (setcdr (nthcdr (1- (abs select)) articles) nil)
5619           ;; Select the N most recent articles.
5620           (setq articles (nthcdr (- number select) articles))))
5621       (setq gnus-newsgroup-unselected
5622             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5623       (when gnus-alter-articles-to-read-function
5624         (setq articles
5625               (sort
5626                (funcall gnus-alter-articles-to-read-function
5627                         gnus-newsgroup-name articles)
5628                '<)))
5629       articles)))
5630
5631 (defun gnus-killed-articles (killed articles)
5632   (let (out)
5633     (while articles
5634       (when (inline (gnus-member-of-range (car articles) killed))
5635         (push (car articles) out))
5636       (setq articles (cdr articles)))
5637     out))
5638
5639 (defun gnus-uncompress-marks (marks)
5640   "Uncompress the mark ranges in MARKS."
5641   (let ((uncompressed '(score bookmark))
5642         out)
5643     (while marks
5644       (if (memq (caar marks) uncompressed)
5645           (push (car marks) out)
5646         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5647       (setq marks (cdr marks)))
5648     out))
5649
5650 (defun gnus-article-mark-to-type (mark)
5651   "Return the type of MARK."
5652   (or (cadr (assq mark gnus-article-special-mark-lists))
5653       'list))
5654
5655 (defun gnus-article-unpropagatable-p (mark)
5656   "Return whether MARK should be propagated to back end."
5657   (memq mark gnus-article-unpropagated-mark-lists))
5658
5659 (defun gnus-adjust-marked-articles (info)
5660   "Set all article lists and remove all marks that are no longer valid."
5661   (let* ((marked-lists (gnus-info-marks info))
5662          (active (gnus-active (gnus-info-group info)))
5663          (min (car active))
5664          (max (cdr active))
5665          (types gnus-article-mark-lists)
5666          marks var articles article mark mark-type
5667          bgn end)
5668
5669     (dolist (marks marked-lists)
5670       (setq mark (car marks)
5671             mark-type (gnus-article-mark-to-type mark)
5672             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5673
5674       ;; We set the variable according to the type of the marks list,
5675       ;; and then adjust the marks to a subset of the active articles.
5676       (cond
5677        ;; Adjust "simple" lists - compressed yet unsorted
5678        ((eq mark-type 'list)
5679         ;; Simultaneously uncompress and clip to active range
5680         ;; See gnus-uncompress-range for a description of possible marks
5681         (let (l lh)
5682           (if (not (cadr marks))
5683               (set var nil)
5684             (setq articles (if (numberp (cddr marks))
5685                                (list (cdr marks))
5686                              (cdr marks))
5687                   lh (cons nil nil)
5688                   l lh)
5689
5690             (while (setq article (pop articles))
5691               (cond ((consp article)
5692                      (setq bgn (max (car article) min)
5693                            end (min (cdr article) max))
5694                      (while (<= bgn end)
5695                        (setq l (setcdr l (cons bgn nil))
5696                              bgn (1+ bgn))))
5697                     ((and (<= min article)
5698                           (>= max article))
5699                      (setq l (setcdr l (cons article nil))))))
5700             (set var (cdr lh)))))
5701        ;; Adjust assocs.
5702        ((eq mark-type 'tuple)
5703         (set var (setq articles (cdr marks)))
5704         (when (not (listp (cdr (symbol-value var))))
5705           (set var (list (symbol-value var))))
5706         (when (not (listp (cdr articles)))
5707           (setq articles (list articles)))
5708         (while articles
5709           (when (or (not (consp (setq article (pop articles))))
5710                     (< (car article) min)
5711                     (> (car article) max))
5712             (set var (delq article (symbol-value var))))))
5713        ;; Adjust ranges (sloppily).
5714        ((eq mark-type 'range)
5715         (cond
5716          ((eq mark 'seen)
5717           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5718           ;; It should be (seen (NUM1 . NUM2)).
5719           (when (numberp (cddr marks))
5720             (setcdr marks (list (cdr marks))))
5721           (setq articles (cdr marks))
5722           (while (and articles
5723                       (or (and (consp (car articles))
5724                                (> min (cdar articles)))
5725                           (and (numberp (car articles))
5726                                (> min (car articles)))))
5727             (pop articles))
5728           (set var articles))))))))
5729
5730 (defun gnus-update-missing-marks (missing)
5731   "Go through the list of MISSING articles and remove them from the mark lists."
5732   (when missing
5733     (let (var m)
5734       ;; Go through all types.
5735       (dolist (elem gnus-article-mark-lists)
5736         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5737           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5738           (when (symbol-value var)
5739             ;; This list has articles.  So we delete all missing
5740             ;; articles from it.
5741             (setq m missing)
5742             (while m
5743               (set var (delq (pop m) (symbol-value var))))))))))
5744
5745 (defun gnus-update-marks ()
5746   "Enter the various lists of marked articles into the newsgroup info list."
5747   (let ((types gnus-article-mark-lists)
5748         (info (gnus-get-info gnus-newsgroup-name))
5749         type list newmarked symbol delta-marks)
5750     (when info
5751       ;; Add all marks lists to the list of marks lists.
5752       (while (setq type (pop types))
5753         (setq list (symbol-value
5754                     (setq symbol
5755                           (intern (format "gnus-newsgroup-%s" (car type))))))
5756
5757         (when list
5758           ;; Get rid of the entries of the articles that have the
5759           ;; default score.
5760           (when (and (eq (cdr type) 'score)
5761                      gnus-save-score
5762                      list)
5763             (let* ((arts list)
5764                    (prev (cons nil list))
5765                    (all prev))
5766               (while arts
5767                 (if (or (not (consp (car arts)))
5768                         (= (cdar arts) gnus-summary-default-score))
5769                     (setcdr prev (cdr arts))
5770                   (setq prev arts))
5771                 (setq arts (cdr arts)))
5772               (setq list (cdr all)))))
5773
5774         (when (eq (cdr type) 'seen)
5775           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5776
5777         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5778           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5779
5780         (when (and (gnus-check-backend-function
5781                     'request-set-mark gnus-newsgroup-name)
5782                    (not (gnus-article-unpropagatable-p (cdr type))))
5783           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5784                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5785                  (add (gnus-remove-from-range
5786                        (gnus-copy-sequence list) old)))
5787             (when add
5788               (push (list add 'add (list (cdr type))) delta-marks))
5789             (when del
5790               (push (list del 'del (list (cdr type))) delta-marks))))
5791
5792         (when list
5793           (push (cons (cdr type) list) newmarked)))
5794
5795       (when delta-marks
5796         (unless (gnus-check-group gnus-newsgroup-name)
5797           (error "Can't open server for %s" gnus-newsgroup-name))
5798         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5799
5800       ;; Enter these new marks into the info of the group.
5801       (if (nthcdr 3 info)
5802           (setcar (nthcdr 3 info) newmarked)
5803         ;; Add the marks lists to the end of the info.
5804         (when newmarked
5805           (setcdr (nthcdr 2 info) (list newmarked))))
5806
5807       ;; Cut off the end of the info if there's nothing else there.
5808       (let ((i 5))
5809         (while (and (> i 2)
5810                     (not (nth i info)))
5811           (when (nthcdr (decf i) info)
5812             (setcdr (nthcdr i info) nil)))))))
5813
5814 (defun gnus-set-mode-line (where)
5815   "Set the mode line of the article or summary buffers.
5816 If WHERE is `summary', the summary mode line format will be used."
5817   ;; Is this mode line one we keep updated?
5818   (when (and (memq where gnus-updated-mode-lines)
5819              (symbol-value
5820               (intern (format "gnus-%s-mode-line-format-spec" where))))
5821     (let (mode-string)
5822       (save-excursion
5823         ;; We evaluate this in the summary buffer since these
5824         ;; variables are buffer-local to that buffer.
5825         (set-buffer gnus-summary-buffer)
5826        ;; We bind all these variables that are used in the `eval' form
5827         ;; below.
5828         (let* ((mformat (symbol-value
5829                          (intern
5830                           (format "gnus-%s-mode-line-format-spec" where))))
5831                (gnus-tmp-group-name (gnus-group-decoded-name
5832                                      gnus-newsgroup-name))
5833                (gnus-tmp-article-number (or gnus-current-article 0))
5834                (gnus-tmp-unread gnus-newsgroup-unreads)
5835                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5836                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5837                (gnus-tmp-unread-and-unselected
5838                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5839                             (zerop gnus-tmp-unselected))
5840                        "")
5841                       ((zerop gnus-tmp-unselected)
5842                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5843                       (t (format "{%d(+%d) more}"
5844                                  gnus-tmp-unread-and-unticked
5845                                  gnus-tmp-unselected))))
5846                (gnus-tmp-subject
5847                 (if (and gnus-current-headers
5848                          (vectorp gnus-current-headers))
5849                     (gnus-mode-string-quote
5850                      (mail-header-subject gnus-current-headers))
5851                   ""))
5852                bufname-length max-len
5853                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5854           (setq mode-string (eval mformat))
5855           (setq bufname-length (if (string-match "%b" mode-string)
5856                                    (- (length
5857                                        (buffer-name
5858                                         (if (eq where 'summary)
5859                                             nil
5860                                           (get-buffer gnus-article-buffer))))
5861                                       2)
5862                                  0))
5863           (setq max-len (max 4 (if gnus-mode-non-string-length
5864                                    (- (window-width)
5865                                       gnus-mode-non-string-length
5866                                       bufname-length)
5867                                  (length mode-string))))
5868           ;; We might have to chop a bit of the string off...
5869           (when (> (length mode-string) max-len)
5870             (setq mode-string
5871                   (concat (truncate-string-to-width mode-string (- max-len 3))
5872                           "...")))
5873           ;; Pad the mode string a bit.
5874           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5875       ;; Update the mode line.
5876       (setq mode-line-buffer-identification
5877             (gnus-mode-line-buffer-identification (list mode-string)))
5878       (set-buffer-modified-p t))))
5879
5880 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5881   "Go through the HEADERS list and add all Xrefs to a hash table.
5882 The resulting hash table is returned, or nil if no Xrefs were found."
5883   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5884          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5885          (xref-hashtb (gnus-make-hashtable))
5886          start group entry number xrefs header)
5887     (while headers
5888       (setq header (pop headers))
5889       (when (and (setq xrefs (mail-header-xref header))
5890                  (not (memq (setq number (mail-header-number header))
5891                             unreads)))
5892         (setq start 0)
5893         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5894           (setq start (match-end 0))
5895           (setq group (if prefix
5896                           (concat prefix (substring xrefs (match-beginning 1)
5897                                                     (match-end 1)))
5898                         (substring xrefs (match-beginning 1) (match-end 1))))
5899           (setq number
5900                 (string-to-number (substring xrefs (match-beginning 2)
5901                                           (match-end 2))))
5902           (if (setq entry (gnus-gethash group xref-hashtb))
5903               (setcdr entry (cons number (cdr entry)))
5904             (gnus-sethash group (cons number nil) xref-hashtb)))))
5905     (and start xref-hashtb)))
5906
5907 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5908   "Look through all the headers and mark the Xrefs as read."
5909   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5910         name info xref-hashtb idlist method nth4)
5911     (save-excursion
5912       (set-buffer gnus-group-buffer)
5913       (when (setq xref-hashtb
5914                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5915         (mapatoms
5916          (lambda (group)
5917            (unless (string= from-newsgroup (setq name (symbol-name group)))
5918              (setq idlist (symbol-value group))
5919              ;; Dead groups are not updated.
5920              (and (prog1
5921                       (setq info (gnus-get-info name))
5922                     (when (stringp (setq nth4 (gnus-info-method info)))
5923                       (setq nth4 (gnus-server-to-method nth4))))
5924                   ;; Only do the xrefs if the group has the same
5925                   ;; select method as the group we have just read.
5926                   (or (gnus-methods-equal-p
5927                        nth4 (gnus-find-method-for-group from-newsgroup))
5928                       virtual
5929                       (equal nth4 (setq method (gnus-find-method-for-group
5930                                                 from-newsgroup)))
5931                       (and (equal (car nth4) (car method))
5932                            (equal (nth 1 nth4) (nth 1 method))))
5933                   gnus-use-cross-reference
5934                   (or (not (eq gnus-use-cross-reference t))
5935                       virtual
5936                       ;; Only do cross-references on subscribed
5937                       ;; groups, if that is what is wanted.
5938                       (<= (gnus-info-level info) gnus-level-subscribed))
5939                   (gnus-group-make-articles-read name idlist))))
5940          xref-hashtb)))))
5941
5942 (defun gnus-compute-read-articles (group articles)
5943   (let* ((entry (gnus-group-entry group))
5944          (info (nth 2 entry))
5945          (active (gnus-active group))
5946          ninfo)
5947     (when entry
5948       ;; First peel off all invalid article numbers.
5949       (when active
5950         (let ((ids articles)
5951               id first)
5952           (while (setq id (pop ids))
5953             (when (and first (> id (cdr active)))
5954               ;; We'll end up in this situation in one particular
5955               ;; obscure situation.  If you re-scan a group and get
5956               ;; a new article that is cross-posted to a different
5957               ;; group that has not been re-scanned, you might get
5958               ;; crossposted article that has a higher number than
5959               ;; Gnus believes possible.  So we re-activate this
5960               ;; group as well.  This might mean doing the
5961               ;; crossposting thingy will *increase* the number
5962               ;; of articles in some groups.  Tsk, tsk.
5963               (setq active (or (gnus-activate-group group) active)))
5964             (when (or (> id (cdr active))
5965                       (< id (car active)))
5966               (setq articles (delq id articles))))))
5967       ;; If the read list is nil, we init it.
5968       (if (and active
5969                (null (gnus-info-read info))
5970                (> (car active) 1))
5971           (setq ninfo (cons 1 (1- (car active))))
5972         (setq ninfo (gnus-info-read info)))
5973       ;; Then we add the read articles to the range.
5974       (gnus-add-to-range
5975        ninfo (setq articles (sort articles '<))))))
5976
5977 (defun gnus-group-make-articles-read (group articles)
5978   "Update the info of GROUP to say that ARTICLES are read."
5979   (let* ((num 0)
5980          (entry (gnus-group-entry group))
5981          (info (nth 2 entry))
5982          (active (gnus-active group))
5983          range)
5984     (when entry
5985       (setq range (gnus-compute-read-articles group articles))
5986       (with-current-buffer gnus-group-buffer
5987         (gnus-undo-register
5988           `(progn
5989              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5990              (gnus-info-set-read ',info ',(gnus-info-read info))
5991              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5992              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5993              (gnus-group-update-group ,group t))))
5994       ;; Add the read articles to the range.
5995       (gnus-info-set-read info range)
5996       (gnus-request-set-mark group (list (list range 'add '(read))))
5997       ;; Then we have to re-compute how many unread
5998       ;; articles there are in this group.
5999       (when active
6000         (cond
6001          ((not range)
6002           (setq num (- (1+ (cdr active)) (car active))))
6003          ((not (listp (cdr range)))
6004           (setq num (- (cdr active) (- (1+ (cdr range))
6005                                        (car range)))))
6006          (t
6007           (while range
6008             (if (numberp (car range))
6009                 (setq num (1+ num))
6010               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6011             (setq range (cdr range)))
6012           (setq num (- (cdr active) num))))
6013         ;; Update the number of unread articles.
6014         (setcar entry num)
6015         ;; Update the group buffer.
6016         (unless (gnus-ephemeral-group-p group)
6017           (gnus-group-update-group group t))))))
6018
6019 (defvar gnus-newsgroup-none-id 0)
6020
6021 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6022   (let ((cur nntp-server-buffer)
6023         (dependencies
6024          (or dependencies
6025              (with-current-buffer gnus-summary-buffer
6026                gnus-newsgroup-dependencies)))
6027         headers id end ref number
6028         (mail-parse-charset gnus-newsgroup-charset)
6029         (mail-parse-ignored-charsets
6030          (save-excursion (condition-case nil
6031                              (set-buffer gnus-summary-buffer)
6032                            (error))
6033                          gnus-newsgroup-ignored-charsets)))
6034     (save-excursion
6035       (set-buffer nntp-server-buffer)
6036       ;; Translate all TAB characters into SPACE characters.
6037       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6038       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6039       (ietf-drums-unfold-fws)
6040       (gnus-run-hooks 'gnus-parse-headers-hook)
6041       (let ((case-fold-search t)
6042             in-reply-to header p lines chars)
6043         (goto-char (point-min))
6044         ;; Search to the beginning of the next header.  Error messages
6045         ;; do not begin with 2 or 3.
6046         (while (re-search-forward "^[23][0-9]+ " nil t)
6047           (setq id nil
6048                 ref nil)
6049           ;; This implementation of this function, with nine
6050           ;; search-forwards instead of the one re-search-forward and
6051           ;; a case (which basically was the old function) is actually
6052           ;; about twice as fast, even though it looks messier.  You
6053           ;; can't have everything, I guess.  Speed and elegance
6054           ;; doesn't always go hand in hand.
6055           (setq
6056            header
6057            (vector
6058             ;; Number.
6059             (prog1
6060                 (setq number (read cur))
6061               (end-of-line)
6062               (setq p (point))
6063               (narrow-to-region (point)
6064                                 (or (and (search-forward "\n.\n" nil t)
6065                                          (- (point) 2))
6066                                     (point))))
6067             ;; Subject.
6068             (progn
6069               (goto-char p)
6070               (if (search-forward "\nsubject:" nil t)
6071                   (funcall gnus-decode-encoded-word-function
6072                            (nnheader-header-value))
6073                 "(none)"))
6074             ;; From.
6075             (progn
6076               (goto-char p)
6077               (if (search-forward "\nfrom:" nil t)
6078                   (funcall gnus-decode-encoded-word-function
6079                            (nnheader-header-value))
6080                 "(nobody)"))
6081             ;; Date.
6082             (progn
6083               (goto-char p)
6084               (if (search-forward "\ndate:" nil t)
6085                   (nnheader-header-value) ""))
6086             ;; Message-ID.
6087             (progn
6088               (goto-char p)
6089               (setq id (if (re-search-forward
6090                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6091                            ;; We do it this way to make sure the Message-ID
6092                            ;; is (somewhat) syntactically valid.
6093                            (buffer-substring (match-beginning 1)
6094                                              (match-end 1))
6095                          ;; If there was no message-id, we just fake one
6096                          ;; to make subsequent routines simpler.
6097                          (nnheader-generate-fake-message-id number))))
6098             ;; References.
6099             (progn
6100               (goto-char p)
6101               (if (search-forward "\nreferences:" nil t)
6102                   (progn
6103                     (setq end (point))
6104                     (prog1
6105                         (nnheader-header-value)
6106                       (setq ref
6107                             (buffer-substring
6108                              (progn
6109                                (end-of-line)
6110                                (search-backward ">" end t)
6111                                (1+ (point)))
6112                              (progn
6113                                (search-backward "<" end t)
6114                                (point))))))
6115                 ;; Get the references from the in-reply-to header if there
6116                 ;; were no references and the in-reply-to header looks
6117                 ;; promising.
6118                 (if (and (search-forward "\nin-reply-to:" nil t)
6119                          (setq in-reply-to (nnheader-header-value))
6120                          (string-match "<[^>]+>" in-reply-to))
6121                     (let (ref2)
6122                       (setq ref (substring in-reply-to (match-beginning 0)
6123                                            (match-end 0)))
6124                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6125                         (setq ref2 (substring in-reply-to (match-beginning 0)
6126                                               (match-end 0)))
6127                         (when (> (length ref2) (length ref))
6128                           (setq ref ref2)))
6129                       ref)
6130                   (setq ref nil))))
6131             ;; Chars.
6132             (progn
6133               (goto-char p)
6134               (if (search-forward "\nchars: " nil t)
6135                   (if (numberp (setq chars (ignore-errors (read cur))))
6136                       chars -1)
6137                 -1))
6138             ;; Lines.
6139             (progn
6140               (goto-char p)
6141               (if (search-forward "\nlines: " nil t)
6142                   (if (numberp (setq lines (ignore-errors (read cur))))
6143                       lines -1)
6144                 -1))
6145             ;; Xref.
6146             (progn
6147               (goto-char p)
6148               (and (search-forward "\nxref:" nil t)
6149                    (nnheader-header-value)))
6150             ;; Extra.
6151             (when gnus-extra-headers
6152               (let ((extra gnus-extra-headers)
6153                     out)
6154                 (while extra
6155                   (goto-char p)
6156                   (when (search-forward
6157                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6158                     (push (cons (car extra) (nnheader-header-value))
6159                           out))
6160                   (pop extra))
6161                 out))))
6162           (when (equal id ref)
6163             (setq ref nil))
6164
6165           (when gnus-alter-header-function
6166             (funcall gnus-alter-header-function header)
6167             (setq id (mail-header-id header)
6168                   ref (gnus-parent-id (mail-header-references header))))
6169
6170           (when (setq header
6171                       (gnus-dependencies-add-header
6172                        header dependencies force-new))
6173             (push header headers))
6174           (goto-char (point-max))
6175           (widen))
6176         (nreverse headers)))))
6177
6178 ;; Goes through the xover lines and returns a list of vectors
6179 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6180                                                   force-new dependencies
6181                                                   group also-fetch-heads)
6182   "Parse the news overview data in the server buffer.
6183 Return a list of headers that match SEQUENCE (see
6184 `nntp-retrieve-headers')."
6185   ;; Get the Xref when the users reads the articles since most/some
6186   ;; NNTP servers do not include Xrefs when using XOVER.
6187   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6188   (let ((mail-parse-charset gnus-newsgroup-charset)
6189         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6190         (cur nntp-server-buffer)
6191         (dependencies (or dependencies gnus-newsgroup-dependencies))
6192         (allp (cond
6193                ((eq gnus-read-all-available-headers t)
6194                 t)
6195                ((and (stringp gnus-read-all-available-headers)
6196                      group)
6197                 (string-match gnus-read-all-available-headers group))
6198                (t
6199                 nil)))
6200         number headers header)
6201     (save-excursion
6202       (set-buffer nntp-server-buffer)
6203       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6204       ;; Allow the user to mangle the headers before parsing them.
6205       (gnus-run-hooks 'gnus-parse-headers-hook)
6206       (goto-char (point-min))
6207       (gnus-parse-without-error
6208         (while (and (or sequence allp)
6209                     (not (eobp)))
6210           (setq number (read cur))
6211           (when (not allp)
6212             (while (and sequence
6213                         (< (car sequence) number))
6214               (setq sequence (cdr sequence))))
6215           (when (and (or allp
6216                          (and sequence
6217                               (eq number (car sequence))))
6218                      (progn
6219                        (setq sequence (cdr sequence))
6220                        (setq header (inline
6221                                       (gnus-nov-parse-line
6222                                        number dependencies force-new)))))
6223             (push header headers))
6224           (forward-line 1)))
6225       ;; A common bug in inn is that if you have posted an article and
6226       ;; then retrieves the active file, it will answer correctly --
6227       ;; the new article is included.  However, a NOV entry for the
6228       ;; article may not have been generated yet, so this may fail.
6229       ;; We work around this problem by retrieving the last few
6230       ;; headers using HEAD.
6231       (if (or (not also-fetch-heads)
6232               (not sequence))
6233           ;; We (probably) got all the headers.
6234           (nreverse headers)
6235         (let ((gnus-nov-is-evil t))
6236           (nconc
6237            (nreverse headers)
6238            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6239              (gnus-get-newsgroup-headers))))))))
6240
6241 (defun gnus-article-get-xrefs ()
6242   "Fill in the Xref value in `gnus-current-headers', if necessary.
6243 This is meant to be called in `gnus-article-internal-prepare-hook'."
6244   (let ((headers (with-current-buffer gnus-summary-buffer
6245                    gnus-current-headers)))
6246     (or (not gnus-use-cross-reference)
6247         (not headers)
6248         (and (mail-header-xref headers)
6249              (not (string= (mail-header-xref headers) "")))
6250         (let ((case-fold-search t)
6251               xref)
6252           (save-restriction
6253             (nnheader-narrow-to-headers)
6254             (goto-char (point-min))
6255             (when (or (and (not (eobp))
6256                            (eq (downcase (char-after)) ?x)
6257                            (looking-at "Xref:"))
6258                       (search-forward "\nXref:" nil t))
6259               (goto-char (1+ (match-end 0)))
6260               (setq xref (buffer-substring (point) (point-at-eol)))
6261               (mail-header-set-xref headers xref)))))))
6262
6263 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6264   "Find article ID and insert the summary line for that article.
6265 OLD-HEADER can either be a header or a line number to insert
6266 the subject line on."
6267   (let* ((line (and (numberp old-header) old-header))
6268          (old-header (and (vectorp old-header) old-header))
6269          (header (cond ((and old-header use-old-header)
6270                         old-header)
6271                        ((and (numberp id)
6272                              (gnus-number-to-header id))
6273                         (gnus-number-to-header id))
6274                        (t
6275                         (gnus-read-header id))))
6276          (number (and (numberp id) id))
6277          d)
6278     (when header
6279       ;; Rebuild the thread that this article is part of and go to the
6280       ;; article we have fetched.
6281       (when (and (not gnus-show-threads)
6282                  old-header)
6283         (when (and number
6284                    (setq d (gnus-data-find (mail-header-number old-header))))
6285           (goto-char (gnus-data-pos d))
6286           (gnus-data-remove
6287            number
6288            (- (point-at-bol)
6289               (prog1
6290                   (1+ (point-at-eol))
6291                 (gnus-delete-line))))))
6292       ;; Remove list identifiers from subject.
6293       (when gnus-list-identifiers
6294         (let ((gnus-newsgroup-headers (list header)))
6295           (gnus-summary-remove-list-identifiers)))
6296       (when old-header
6297         (mail-header-set-number header (mail-header-number old-header)))
6298       (setq gnus-newsgroup-sparse
6299             (delq (setq number (mail-header-number header))
6300                   gnus-newsgroup-sparse))
6301       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6302       (push number gnus-newsgroup-limit)
6303       (gnus-rebuild-thread (mail-header-id header) line)
6304       (gnus-summary-goto-subject number nil t))
6305     (when (and (numberp number)
6306                (> number 0))
6307       ;; We have to update the boundaries even if we can't fetch the
6308       ;; article if ID is a number -- so that the next `P' or `N'
6309       ;; command will fetch the previous (or next) article even
6310       ;; if the one we tried to fetch this time has been canceled.
6311       (when (> number gnus-newsgroup-end)
6312         (setq gnus-newsgroup-end number))
6313       (when (< number gnus-newsgroup-begin)
6314         (setq gnus-newsgroup-begin number))
6315       (setq gnus-newsgroup-unselected
6316             (delq number gnus-newsgroup-unselected)))
6317     ;; Report back a success?
6318     (and header (mail-header-number header))))
6319
6320 ;;; Process/prefix in the summary buffer
6321
6322 (defun gnus-summary-work-articles (n)
6323   "Return a list of articles to be worked upon.
6324 The prefix argument, the list of process marked articles, and the
6325 current article will be taken into consideration."
6326   (save-excursion
6327     (set-buffer gnus-summary-buffer)
6328     (cond
6329      (n
6330       ;; A numerical prefix has been given.
6331       (setq n (prefix-numeric-value n))
6332       (let ((backward (< n 0))
6333             (n (abs (prefix-numeric-value n)))
6334             articles article)
6335         (save-excursion
6336           (while
6337               (and (> n 0)
6338                    (push (setq article (gnus-summary-article-number))
6339                          articles)
6340                    (if backward
6341                        (gnus-summary-find-prev nil article)
6342                      (gnus-summary-find-next nil article)))
6343             (decf n)))
6344         (nreverse articles)))
6345      ((and (gnus-region-active-p) (mark))
6346       (message "region active")
6347       ;; Work on the region between point and mark.
6348       (let ((max (max (point) (mark)))
6349             articles article)
6350         (save-excursion
6351           (goto-char (min (point) (mark)))
6352           (while
6353               (and
6354                (push (setq article (gnus-summary-article-number)) articles)
6355                (gnus-summary-find-next nil article)
6356                (< (point) max)))
6357           (nreverse articles))))
6358      (gnus-newsgroup-processable
6359       ;; There are process-marked articles present.
6360       ;; Save current state.
6361       (gnus-summary-save-process-mark)
6362       ;; Return the list.
6363       (reverse gnus-newsgroup-processable))
6364      (t
6365       ;; Just return the current article.
6366       (list (gnus-summary-article-number))))))
6367
6368 (defmacro gnus-summary-iterate (arg &rest forms)
6369   "Iterate over the process/prefixed articles and do FORMS.
6370 ARG is the interactive prefix given to the command.  FORMS will be
6371 executed with point over the summary line of the articles."
6372   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6373     `(let ((,articles (gnus-summary-work-articles ,arg)))
6374        (while ,articles
6375          (gnus-summary-goto-subject (car ,articles))
6376          ,@forms
6377          (pop ,articles)))))
6378
6379 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6380 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6381
6382 (defun gnus-summary-save-process-mark ()
6383   "Push the current set of process marked articles on the stack."
6384   (interactive)
6385   (push (copy-sequence gnus-newsgroup-processable)
6386         gnus-newsgroup-process-stack))
6387
6388 (defun gnus-summary-kill-process-mark ()
6389   "Push the current set of process marked articles on the stack and unmark."
6390   (interactive)
6391   (gnus-summary-save-process-mark)
6392   (gnus-summary-unmark-all-processable))
6393
6394 (defun gnus-summary-yank-process-mark ()
6395   "Pop the last process mark state off the stack and restore it."
6396   (interactive)
6397   (unless gnus-newsgroup-process-stack
6398     (error "Empty mark stack"))
6399   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6400
6401 (defun gnus-summary-process-mark-set (set)
6402   "Make SET into the current process marked articles."
6403   (gnus-summary-unmark-all-processable)
6404   (mapc 'gnus-summary-set-process-mark set))
6405
6406 ;;; Searching and stuff
6407
6408 (defun gnus-summary-search-group (&optional backward use-level)
6409   "Search for next unread newsgroup.
6410 If optional argument BACKWARD is non-nil, search backward instead."
6411   (save-excursion
6412     (set-buffer gnus-group-buffer)
6413     (when (gnus-group-search-forward
6414            backward nil (if use-level (gnus-group-group-level) nil))
6415       (gnus-group-group-name))))
6416
6417 (defun gnus-summary-best-group (&optional exclude-group)
6418   "Find the name of the best unread group.
6419 If EXCLUDE-GROUP, do not go to this group."
6420   (with-current-buffer gnus-group-buffer
6421     (save-excursion
6422       (gnus-group-best-unread-group exclude-group))))
6423
6424 (defun gnus-summary-find-next (&optional unread article backward)
6425   (if backward
6426       (gnus-summary-find-prev unread article)
6427     (let* ((dummy (gnus-summary-article-intangible-p))
6428            (article (or article (gnus-summary-article-number)))
6429            (data (gnus-data-find-list article))
6430            result)
6431       (when (and (not dummy)
6432                  (or (not gnus-summary-check-current)
6433                      (not unread)
6434                      (not (gnus-data-unread-p (car data)))))
6435         (setq data (cdr data)))
6436       (when (setq result
6437                   (if unread
6438                       (progn
6439                         (while data
6440                           (unless (memq (gnus-data-number (car data))
6441                                         (cond
6442                                          ((eq gnus-auto-goto-ignores
6443                                               'always-undownloaded)
6444                                           gnus-newsgroup-undownloaded)
6445                                          (gnus-plugged
6446                                           nil)
6447                                          ((eq gnus-auto-goto-ignores
6448                                               'unfetched)
6449                                           gnus-newsgroup-unfetched)
6450                                          ((eq gnus-auto-goto-ignores
6451                                               'undownloaded)
6452                                           gnus-newsgroup-undownloaded)))
6453                             (when (gnus-data-unread-p (car data))
6454                               (setq result (car data)
6455                                     data nil)))
6456                           (setq data (cdr data)))
6457                         result)
6458                     (car data)))
6459         (goto-char (gnus-data-pos result))
6460         (gnus-data-number result)))))
6461
6462 (defun gnus-summary-find-prev (&optional unread article)
6463   (let* ((eobp (eobp))
6464          (article (or article (gnus-summary-article-number)))
6465          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6466          result)
6467     (when (and (not eobp)
6468                (or (not gnus-summary-check-current)
6469                    (not unread)
6470                    (not (gnus-data-unread-p (car data)))))
6471       (setq data (cdr data)))
6472     (when (setq result
6473                 (if unread
6474                     (progn
6475                       (while data
6476                         (unless (memq (gnus-data-number (car data))
6477                                       (cond
6478                                        ((eq gnus-auto-goto-ignores
6479                                             'always-undownloaded)
6480                                         gnus-newsgroup-undownloaded)
6481                                        (gnus-plugged
6482                                         nil)
6483                                        ((eq gnus-auto-goto-ignores
6484                                             'unfetched)
6485                                         gnus-newsgroup-unfetched)
6486                                        ((eq gnus-auto-goto-ignores
6487                                             'undownloaded)
6488                                         gnus-newsgroup-undownloaded)))
6489                           (when (gnus-data-unread-p (car data))
6490                             (setq result (car data)
6491                                   data nil)))
6492                         (setq data (cdr data)))
6493                       result)
6494                   (car data)))
6495       (goto-char (gnus-data-pos result))
6496       (gnus-data-number result))))
6497
6498 (defun gnus-summary-find-subject (subject &optional unread backward article)
6499   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6500          (article (or article (gnus-summary-article-number)))
6501          (articles (gnus-data-list backward))
6502          (arts (gnus-data-find-list article articles))
6503          result)
6504     (when (or (not gnus-summary-check-current)
6505               (not unread)
6506               (not (gnus-data-unread-p (car arts))))
6507       (setq arts (cdr arts)))
6508     (while arts
6509       (and (or (not unread)
6510                (gnus-data-unread-p (car arts)))
6511            (vectorp (gnus-data-header (car arts)))
6512            (gnus-subject-equal
6513             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6514            (setq result (car arts)
6515                  arts nil))
6516       (setq arts (cdr arts)))
6517     (and result
6518          (goto-char (gnus-data-pos result))
6519          (gnus-data-number result))))
6520
6521 (defun gnus-summary-search-forward (&optional unread subject backward)
6522   "Search forward for an article.
6523 If UNREAD, look for unread articles.  If SUBJECT, look for
6524 articles with that subject.  If BACKWARD, search backward instead."
6525   (cond (subject (gnus-summary-find-subject subject unread backward))
6526         (backward (gnus-summary-find-prev unread))
6527         (t (gnus-summary-find-next unread))))
6528
6529 (defun gnus-recenter (&optional n)
6530   "Center point in window and redisplay frame.
6531 Also do horizontal recentering."
6532   (interactive "P")
6533   (when (and gnus-auto-center-summary
6534              (not (eq gnus-auto-center-summary 'vertical)))
6535     (gnus-horizontal-recenter))
6536   (recenter n))
6537
6538 (defun gnus-summary-recenter ()
6539   "Center point in the summary window.
6540 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6541 displayed, no centering will be performed."
6542   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6543   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6544   (interactive)
6545   ;; The user has to want it.
6546   (when gnus-auto-center-summary
6547     (let* ((top (cond ((< (window-height) 4) 0)
6548                       ((< (window-height) 7) 1)
6549                       (t (if (numberp gnus-auto-center-summary)
6550                              gnus-auto-center-summary
6551                            (/ (1- (window-height)) 2)))))
6552            (height (1- (window-height)))
6553            (bottom (save-excursion (goto-char (point-max))
6554                                    (forward-line (- height))
6555                                    (point)))
6556            (window (get-buffer-window (current-buffer))))
6557       (when (get-buffer-window gnus-article-buffer)
6558         ;; Only do recentering when the article buffer is displayed,
6559         ;; Set the window start to either `bottom', which is the biggest
6560         ;; possible valid number, or the second line from the top,
6561         ;; whichever is the least.
6562         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6563           (if (> bottom top-pos)
6564               ;; Keep the second line from the top visible
6565               (set-window-start window top-pos t)
6566             ;; Try to keep the bottom line visible; if it's partially
6567             ;; obscured, either scroll one more line to make it fully
6568             ;; visible, or revert to using TOP-POS.
6569             (save-excursion
6570               (goto-char (point-max))
6571               (forward-line -1)
6572               (let ((last-line-start (point)))
6573                 (goto-char bottom)
6574                 (set-window-start window (point) t)
6575                 (when (not (pos-visible-in-window-p last-line-start window))
6576                   (forward-line 1)
6577                   (set-window-start window (min (point) top-pos) t)))))))
6578       ;; Do horizontal recentering while we're at it.
6579       (when (and (get-buffer-window (current-buffer) t)
6580                  (not (eq gnus-auto-center-summary 'vertical)))
6581         (let ((selected (selected-window)))
6582           (select-window (get-buffer-window (current-buffer) t))
6583           (gnus-summary-position-point)
6584           (gnus-horizontal-recenter)
6585           (select-window selected))))))
6586
6587 (defun gnus-summary-jump-to-group (newsgroup)
6588   "Move point to NEWSGROUP in group mode buffer."
6589   ;; Keep update point of group mode buffer if visible.
6590   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6591       (save-window-excursion
6592         ;; Take care of tree window mode.
6593         (when (get-buffer-window gnus-group-buffer)
6594           (pop-to-buffer gnus-group-buffer))
6595         (gnus-group-jump-to-group newsgroup))
6596     (save-excursion
6597       ;; Take care of tree window mode.
6598       (if (get-buffer-window gnus-group-buffer)
6599           (pop-to-buffer gnus-group-buffer)
6600         (set-buffer gnus-group-buffer))
6601       (gnus-group-jump-to-group newsgroup))))
6602
6603 ;; This function returns a list of article numbers based on the
6604 ;; difference between the ranges of read articles in this group and
6605 ;; the range of active articles.
6606 (defun gnus-list-of-unread-articles (group)
6607   (let* ((read (gnus-info-read (gnus-get-info group)))
6608          (active (or (gnus-active group) (gnus-activate-group group)))
6609          (last (or (cdr active)
6610                    (error "Group %s couldn't be activated " group)))
6611          first nlast unread)
6612     ;; If none are read, then all are unread.
6613     (if (not read)
6614         (setq first (car active))
6615       ;; If the range of read articles is a single range, then the
6616       ;; first unread article is the article after the last read
6617       ;; article.  Sounds logical, doesn't it?
6618       (if (and (not (listp (cdr read)))
6619                (or (< (car read) (car active))
6620                    (progn (setq read (list read))
6621                           nil)))
6622           (setq first (max (car active) (1+ (cdr read))))
6623         ;; `read' is a list of ranges.
6624         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6625                                   (caar read)))
6626                   1)
6627           (setq first (car active)))
6628         (while read
6629           (when first
6630             (while (< first nlast)
6631               (setq unread (cons first unread)
6632                     first (1+ first))))
6633           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6634           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6635           (setq read (cdr read)))))
6636     ;; And add the last unread articles.
6637     (while (<= first last)
6638       (setq unread (cons first unread)
6639             first (1+ first)))
6640     ;; Return the list of unread articles.
6641     (delq 0 (nreverse unread))))
6642
6643 (defun gnus-list-of-read-articles (group)
6644   "Return a list of unread, unticked and non-dormant articles."
6645   (let* ((info (gnus-get-info group))
6646          (marked (gnus-info-marks info))
6647          (active (gnus-active group)))
6648     (and info active
6649          (gnus-list-range-difference
6650           (gnus-list-range-difference
6651            (gnus-sorted-complement
6652             (gnus-uncompress-range active)
6653             (gnus-list-of-unread-articles group))
6654            (cdr (assq 'dormant marked)))
6655           (cdr (assq 'tick marked))))))
6656
6657 ;; This function returns a sequence of article numbers based on the
6658 ;; difference between the ranges of read articles in this group and
6659 ;; the range of active articles.
6660 (defun gnus-sequence-of-unread-articles (group)
6661   (let* ((read (gnus-info-read (gnus-get-info group)))
6662          (active (or (gnus-active group) (gnus-activate-group group)))
6663          (last (cdr active))
6664          first nlast unread)
6665     ;; If none are read, then all are unread.
6666     (if (not read)
6667         (setq first (car active))
6668       ;; If the range of read articles is a single range, then the
6669       ;; first unread article is the article after the last read
6670       ;; article.  Sounds logical, doesn't it?
6671       (if (and (not (listp (cdr read)))
6672                (or (< (car read) (car active))
6673                    (progn (setq read (list read))
6674                           nil)))
6675           (setq first (max (car active) (1+ (cdr read))))
6676         ;; `read' is a list of ranges.
6677         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6678                                   (caar read)))
6679                   1)
6680           (setq first (car active)))
6681         (while read
6682           (when first
6683             (push (cons first nlast) unread))
6684           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6685           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6686           (setq read (cdr read)))))
6687     ;; And add the last unread articles.
6688     (cond ((not (and first last))
6689            nil)
6690           ((< first last)
6691            (push (cons first last) unread))
6692           ((= first last)
6693            (push first unread)))
6694     ;; Return the sequence of unread articles.
6695     (delq 0 (nreverse unread))))
6696
6697 ;; Various summary commands
6698
6699 (defun gnus-summary-select-article-buffer ()
6700   "Reconfigure windows to show article buffer."
6701   (interactive)
6702   (if (not (gnus-buffer-live-p gnus-article-buffer))
6703       (error "There is no article buffer for this summary buffer")
6704     (gnus-configure-windows 'article)
6705     (select-window (get-buffer-window gnus-article-buffer))))
6706
6707 (defun gnus-summary-universal-argument (arg)
6708   "Perform any operation on all articles that are process/prefixed."
6709   (interactive "P")
6710   (let ((articles (gnus-summary-work-articles arg))
6711         func article)
6712     (if (eq
6713          (setq
6714           func
6715           (key-binding
6716            (read-key-sequence
6717             (substitute-command-keys
6718              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6719          'undefined)
6720         (gnus-error 1 "Undefined key")
6721       (save-excursion
6722         (while articles
6723           (gnus-summary-goto-subject (setq article (pop articles)))
6724           (let (gnus-newsgroup-processable)
6725             (command-execute func))
6726           (gnus-summary-remove-process-mark article)))))
6727   (gnus-summary-position-point))
6728
6729 (defun gnus-summary-toggle-truncation (&optional arg)
6730   "Toggle truncation of summary lines.
6731 With ARG, turn line truncation on if ARG is positive."
6732   (interactive "P")
6733   (setq truncate-lines
6734         (if (null arg) (not truncate-lines)
6735           (> (prefix-numeric-value arg) 0)))
6736   (redraw-display))
6737
6738 (defun gnus-summary-find-for-reselect ()
6739   "Return the number of an article to stay on across a reselect.
6740 The current article is considered, then following articles, then previous
6741 articles.  An article is sought which is not cancelled and isn't a temporary
6742 insertion from another group.  If there's no such then return a dummy 0."
6743   (let (found)
6744     (dolist (rev '(nil t))
6745       (unless found      ; don't demand the reverse list if we don't need it
6746         (let ((data (gnus-data-find-list
6747                      (gnus-summary-article-number) (gnus-data-list rev))))
6748           (while (and data (not found))
6749             (if (and (< 0 (gnus-data-number (car data)))
6750                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6751                 (setq found (gnus-data-number (car data))))
6752             (setq data (cdr data))))))
6753     (or found 0)))
6754
6755 (defun gnus-summary-reselect-current-group (&optional all rescan)
6756   "Exit and then reselect the current newsgroup.
6757 The prefix argument ALL means to select all articles."
6758   (interactive "P")
6759   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6760     (error "Ephemeral groups can't be reselected"))
6761   (let ((current-subject (gnus-summary-find-for-reselect))
6762         (group gnus-newsgroup-name))
6763     (setq gnus-newsgroup-begin nil)
6764     (gnus-summary-exit nil 'leave-hidden)
6765     ;; We have to adjust the point of group mode buffer because
6766     ;; point was moved to the next unread newsgroup by exiting.
6767     (gnus-summary-jump-to-group group)
6768     (when rescan
6769       (save-excursion
6770         (gnus-group-get-new-news-this-group 1)))
6771     (gnus-group-read-group all t)
6772     (gnus-summary-goto-subject current-subject nil t)))
6773
6774 (defun gnus-summary-rescan-group (&optional all)
6775   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6776   (interactive "P")
6777   (gnus-summary-reselect-current-group all t))
6778
6779 (defun gnus-summary-update-info (&optional non-destructive)
6780   (save-excursion
6781     (let ((group gnus-newsgroup-name))
6782       (when group
6783         (when gnus-newsgroup-kill-headers
6784           (setq gnus-newsgroup-killed
6785                 (gnus-compress-sequence
6786                  (gnus-sorted-union
6787                   (gnus-list-range-intersection
6788                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6789                   gnus-newsgroup-unreads)
6790                  t)))
6791         (unless (listp (cdr gnus-newsgroup-killed))
6792           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6793         (let ((headers gnus-newsgroup-headers))
6794           ;; Set the new ranges of read articles.
6795           (with-current-buffer gnus-group-buffer
6796             (gnus-undo-force-boundary))
6797           (gnus-update-read-articles
6798            group (gnus-sorted-union
6799                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6800           ;; Set the current article marks.
6801           (let ((gnus-newsgroup-scored
6802                  (if (and (not gnus-save-score)
6803                           (not non-destructive))
6804                      nil
6805                    gnus-newsgroup-scored)))
6806             (save-excursion
6807               (gnus-update-marks)))
6808           ;; Do the cross-ref thing.
6809           (when gnus-use-cross-reference
6810             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6811           ;; Do not switch windows but change the buffer to work.
6812           (set-buffer gnus-group-buffer)
6813           (unless (gnus-ephemeral-group-p group)
6814             (gnus-group-update-group group)))))))
6815
6816 (defun gnus-summary-save-newsrc (&optional force)
6817   "Save the current number of read/marked articles in the dribble buffer.
6818 The dribble buffer will then be saved.
6819 If FORCE (the prefix), also save the .newsrc file(s)."
6820   (interactive "P")
6821   (gnus-summary-update-info t)
6822   (if force
6823       (gnus-save-newsrc-file)
6824     (gnus-dribble-save)))
6825
6826 (defun gnus-summary-exit (&optional temporary leave-hidden)
6827   "Exit reading current newsgroup, and then return to group selection mode.
6828 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6829   (interactive)
6830   (gnus-set-global-variables)
6831   (when (gnus-buffer-live-p gnus-article-buffer)
6832     (save-excursion
6833       (set-buffer gnus-article-buffer)
6834       (mm-destroy-parts gnus-article-mime-handles)
6835       ;; Set it to nil for safety reason.
6836       (setq gnus-article-mime-handle-alist nil)
6837       (setq gnus-article-mime-handles nil)))
6838   (gnus-kill-save-kill-buffer)
6839   (gnus-async-halt-prefetch)
6840   (let* ((group gnus-newsgroup-name)
6841          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6842          (gnus-group-is-exiting-p t)
6843          (mode major-mode)
6844          (group-point nil)
6845          (buf (current-buffer)))
6846     (unless quit-config
6847       ;; Do adaptive scoring, and possibly save score files.
6848       (when gnus-newsgroup-adaptive
6849         (gnus-score-adaptive))
6850       (when gnus-use-scoring
6851         (gnus-score-save)))
6852     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6853     ;; If we have several article buffers, we kill them at exit.
6854     (unless gnus-single-article-buffer
6855       (gnus-kill-buffer gnus-article-buffer)
6856       (gnus-kill-buffer gnus-original-article-buffer)
6857       (setq gnus-article-current nil))
6858     (when gnus-use-cache
6859       (gnus-cache-possibly-remove-articles)
6860       (gnus-cache-save-buffers))
6861     (gnus-async-prefetch-remove-group group)
6862     (when gnus-suppress-duplicates
6863       (gnus-dup-enter-articles))
6864     (when gnus-use-trees
6865       (gnus-tree-close group))
6866     (when gnus-use-cache
6867       (gnus-cache-write-active))
6868     ;; Remove entries for this group.
6869     (nnmail-purge-split-history (gnus-group-real-name group))
6870     ;; Make all changes in this group permanent.
6871     (unless quit-config
6872       (gnus-run-hooks 'gnus-exit-group-hook)
6873       (gnus-summary-update-info))
6874     (gnus-close-group group)
6875     ;; Make sure where we were, and go to next newsgroup.
6876     (set-buffer gnus-group-buffer)
6877     (unless quit-config
6878       (gnus-group-jump-to-group group))
6879     (gnus-run-hooks 'gnus-summary-exit-hook)
6880     (unless (or quit-config
6881                 ;; If this group has disappeared from the summary
6882                 ;; buffer, don't skip forwards.
6883                 (not (string= group (gnus-group-group-name))))
6884       (gnus-group-next-unread-group 1))
6885     (setq group-point (point))
6886     (if temporary
6887         nil                             ;Nothing to do.
6888       ;; If we have several article buffers, we kill them at exit.
6889       (unless gnus-single-article-buffer
6890         (gnus-kill-buffer gnus-article-buffer)
6891         (gnus-kill-buffer gnus-original-article-buffer)
6892         (setq gnus-article-current nil))
6893       (set-buffer buf)
6894       (if (not gnus-kill-summary-on-exit)
6895           (progn
6896             (gnus-deaden-summary)
6897             (setq mode nil))
6898         ;; We set all buffer-local variables to nil.  It is unclear why
6899         ;; this is needed, but if we don't, buffer-local variables are
6900         ;; not garbage-collected, it seems.  This would the lead to en
6901         ;; ever-growing Emacs.
6902         (gnus-summary-clear-local-variables)
6903         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6904           (gnus-summary-clear-local-variables))
6905         (when (get-buffer gnus-article-buffer)
6906           (bury-buffer gnus-article-buffer))
6907         ;; Return to group mode buffer.
6908         (when (eq mode 'gnus-summary-mode)
6909           (gnus-kill-buffer buf)))
6910       (setq gnus-current-select-method gnus-select-method)
6911       (set-buffer gnus-group-buffer)
6912       (if quit-config
6913           (gnus-handle-ephemeral-exit quit-config)
6914         (goto-char group-point)
6915         ;; If gnus-group-buffer is already displayed, make sure we also move
6916         ;; the cursor in the window that displays it.
6917         (let ((win (get-buffer-window (current-buffer) 0)))
6918           (if win (set-window-point win (point))))
6919         (unless leave-hidden
6920           (gnus-configure-windows 'group 'force)))
6921       ;; Clear the current group name.
6922       (unless quit-config
6923         (setq gnus-newsgroup-name nil)))))
6924
6925 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6926 (defun gnus-summary-exit-no-update (&optional no-questions)
6927   "Quit reading current newsgroup without updating read article info."
6928   (interactive)
6929   (let* ((group gnus-newsgroup-name)
6930          (gnus-group-is-exiting-p t)
6931          (gnus-group-is-exiting-without-update-p t)
6932          (quit-config (gnus-group-quit-config group)))
6933     (when (or no-questions
6934               gnus-expert-user
6935               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6936       (gnus-async-halt-prefetch)
6937       (run-hooks 'gnus-summary-prepare-exit-hook)
6938       (when (gnus-buffer-live-p gnus-article-buffer)
6939         (save-excursion
6940           (set-buffer gnus-article-buffer)
6941           (mm-destroy-parts gnus-article-mime-handles)
6942           ;; Set it to nil for safety reason.
6943           (setq gnus-article-mime-handle-alist nil)
6944           (setq gnus-article-mime-handles nil)))
6945       ;; If we have several article buffers, we kill them at exit.
6946       (unless gnus-single-article-buffer
6947         (gnus-kill-buffer gnus-article-buffer)
6948         (gnus-kill-buffer gnus-original-article-buffer)
6949         (setq gnus-article-current nil))
6950       (if (not gnus-kill-summary-on-exit)
6951           (gnus-deaden-summary)
6952         (gnus-close-group group)
6953         (gnus-summary-clear-local-variables)
6954         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6955           (gnus-summary-clear-local-variables))
6956         (gnus-kill-buffer gnus-summary-buffer))
6957       (unless gnus-single-article-buffer
6958         (setq gnus-article-current nil))
6959       (when gnus-use-trees
6960         (gnus-tree-close group))
6961       (gnus-async-prefetch-remove-group group)
6962       (when (get-buffer gnus-article-buffer)
6963         (bury-buffer gnus-article-buffer))
6964       ;; Return to the group buffer.
6965       (gnus-configure-windows 'group 'force)
6966       ;; Clear the current group name.
6967       (setq gnus-newsgroup-name nil)
6968       (unless (gnus-ephemeral-group-p group)
6969         (gnus-group-update-group group))
6970       (when (equal (gnus-group-group-name) group)
6971         (gnus-group-next-unread-group 1))
6972       (when quit-config
6973         (gnus-handle-ephemeral-exit quit-config)))))
6974
6975 (defun gnus-handle-ephemeral-exit (quit-config)
6976   "Handle movement when leaving an ephemeral group.
6977 The state which existed when entering the ephemeral is reset."
6978   (if (not (buffer-name (car quit-config)))
6979       (gnus-configure-windows 'group 'force)
6980     (set-buffer (car quit-config))
6981     (cond ((eq major-mode 'gnus-summary-mode)
6982            (gnus-set-global-variables))
6983           ((eq major-mode 'gnus-article-mode)
6984            (save-excursion
6985              ;; The `gnus-summary-buffer' variable may point
6986              ;; to the old summary buffer when using a single
6987              ;; article buffer.
6988              (unless (gnus-buffer-live-p gnus-summary-buffer)
6989                (set-buffer gnus-group-buffer))
6990              (set-buffer gnus-summary-buffer)
6991              (gnus-set-global-variables))))
6992     (if (or (eq (cdr quit-config) 'article)
6993             (eq (cdr quit-config) 'pick))
6994         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6995             (gnus-configure-windows 'pick 'force)
6996           (gnus-configure-windows (cdr quit-config) 'force))
6997       (gnus-configure-windows (cdr quit-config) 'force))
6998     (when (eq major-mode 'gnus-summary-mode)
6999       (gnus-summary-recenter)
7000       (gnus-summary-position-point))))
7001
7002 ;;; Dead summaries.
7003
7004 (defvar gnus-dead-summary-mode-map nil)
7005
7006 (unless gnus-dead-summary-mode-map
7007   (setq gnus-dead-summary-mode-map (make-keymap))
7008   (suppress-keymap gnus-dead-summary-mode-map)
7009   (substitute-key-definition
7010    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7011   (dolist (key '("\C-d" "\r" "\177" [delete]))
7012     (define-key gnus-dead-summary-mode-map
7013       key 'gnus-summary-wake-up-the-dead))
7014   (dolist (key '("q" "Q"))
7015     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7016
7017 (defvar gnus-dead-summary-mode nil
7018   "Minor mode for Gnus summary buffers.")
7019
7020 (defun gnus-dead-summary-mode (&optional arg)
7021   "Minor mode for Gnus summary buffers."
7022   (interactive "P")
7023   (when (eq major-mode 'gnus-summary-mode)
7024     (make-local-variable 'gnus-dead-summary-mode)
7025     (setq gnus-dead-summary-mode
7026           (if (null arg) (not gnus-dead-summary-mode)
7027             (> (prefix-numeric-value arg) 0)))
7028     (when gnus-dead-summary-mode
7029       (add-minor-mode
7030        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7031
7032 (defun gnus-deaden-summary ()
7033   "Make the current summary buffer into a dead summary buffer."
7034   ;; Kill any previous dead summary buffer.
7035   (when (and gnus-dead-summary
7036              (buffer-name gnus-dead-summary))
7037     (with-current-buffer gnus-dead-summary
7038       (when gnus-dead-summary-mode
7039         (kill-buffer (current-buffer)))))
7040   ;; Make this the current dead summary.
7041   (setq gnus-dead-summary (current-buffer))
7042   (gnus-dead-summary-mode 1)
7043   (let ((name (buffer-name)))
7044     (when (string-match "Summary" name)
7045       (rename-buffer
7046        (concat (substring name 0 (match-beginning 0)) "Dead "
7047                (substring name (match-beginning 0)))
7048        t)
7049       (bury-buffer))))
7050
7051 (defun gnus-kill-or-deaden-summary (buffer)
7052   "Kill or deaden the summary BUFFER."
7053   (save-excursion
7054     (when (and (buffer-name buffer)
7055                (not gnus-single-article-buffer))
7056       (with-current-buffer buffer
7057         (gnus-kill-buffer gnus-article-buffer)
7058         (gnus-kill-buffer gnus-original-article-buffer)))
7059     (cond
7060      ;; Kill the buffer.
7061      (gnus-kill-summary-on-exit
7062       (when (and gnus-use-trees
7063                  (gnus-buffer-exists-p buffer))
7064         (save-excursion
7065           (set-buffer buffer)
7066           (gnus-tree-close gnus-newsgroup-name)))
7067       (gnus-kill-buffer buffer))
7068      ;; Deaden the buffer.
7069      ((gnus-buffer-exists-p buffer)
7070       (save-excursion
7071         (set-buffer buffer)
7072         (gnus-deaden-summary))))))
7073
7074 (defun gnus-summary-wake-up-the-dead (&rest args)
7075   "Wake up the dead summary buffer."
7076   (interactive)
7077   (gnus-dead-summary-mode -1)
7078   (let ((name (buffer-name)))
7079     (when (string-match "Dead " name)
7080       (rename-buffer
7081        (concat (substring name 0 (match-beginning 0))
7082                (substring name (match-end 0)))
7083        t)))
7084   (gnus-message 3 "This dead summary is now alive again"))
7085
7086 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7087 (defun gnus-summary-fetch-faq (&optional faq-dir)
7088   "Fetch the FAQ for the current group.
7089 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7090 in."
7091   (interactive
7092    (list
7093     (when current-prefix-arg
7094       (completing-read
7095        "FAQ dir: " (and (listp gnus-group-faq-directory)
7096                         (mapcar 'list
7097                                 gnus-group-faq-directory))))))
7098   (let (gnus-faq-buffer)
7099     (when (setq gnus-faq-buffer
7100                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7101       (gnus-configure-windows 'summary-faq))))
7102
7103 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7104 (defun gnus-summary-describe-group (&optional force)
7105   "Describe the current newsgroup."
7106   (interactive "P")
7107   (gnus-group-describe-group force gnus-newsgroup-name))
7108
7109 (defun gnus-summary-describe-briefly ()
7110   "Describe summary mode commands briefly."
7111   (interactive)
7112   (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")))
7113
7114 ;; Walking around group mode buffer from summary mode.
7115
7116 (defun gnus-summary-next-group (&optional no-article target-group backward)
7117   "Exit current newsgroup and then select next unread newsgroup.
7118 If prefix argument NO-ARTICLE is non-nil, no article is selected
7119 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7120 previous group instead."
7121   (interactive "P")
7122   ;; Stop pre-fetching.
7123   (gnus-async-halt-prefetch)
7124   (let ((current-group gnus-newsgroup-name)
7125         (current-buffer (current-buffer))
7126         entered)
7127     ;; First we semi-exit this group to update Xrefs and all variables.
7128     ;; We can't do a real exit, because the window conf must remain
7129     ;; the same in case the user is prompted for info, and we don't
7130     ;; want the window conf to change before that...
7131     (gnus-summary-exit t)
7132     (while (not entered)
7133       ;; Then we find what group we are supposed to enter.
7134       (set-buffer gnus-group-buffer)
7135       (gnus-group-jump-to-group current-group)
7136       (setq target-group
7137             (or target-group
7138                 (if (eq gnus-keep-same-level 'best)
7139                     (gnus-summary-best-group gnus-newsgroup-name)
7140                   (gnus-summary-search-group backward gnus-keep-same-level))))
7141       (if (not target-group)
7142           ;; There are no further groups, so we return to the group
7143           ;; buffer.
7144           (progn
7145             (gnus-message 5 "Returning to the group buffer")
7146             (setq entered t)
7147             (when (gnus-buffer-live-p current-buffer)
7148               (set-buffer current-buffer)
7149               (gnus-summary-exit))
7150             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7151         ;; We try to enter the target group.
7152         (gnus-group-jump-to-group target-group)
7153         (let ((unreads (gnus-group-group-unread)))
7154           (if (and (or (eq t unreads)
7155                        (and unreads (not (zerop unreads))))
7156                    (gnus-summary-read-group
7157                     target-group nil no-article
7158                     (and (buffer-name current-buffer) current-buffer)
7159                     nil backward))
7160               (setq entered t)
7161             (setq current-group target-group
7162                   target-group nil)))))))
7163
7164 (defun gnus-summary-prev-group (&optional no-article)
7165   "Exit current newsgroup and then select previous unread newsgroup.
7166 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7167   (interactive "P")
7168   (gnus-summary-next-group no-article nil t))
7169
7170 ;; Walking around summary lines.
7171
7172 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7173   "Go to the first subject satisfying any non-nil constraint.
7174 If UNREAD is non-nil, the article should be unread.
7175 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7176 If UNSEEN is non-nil, the article should be unseen.
7177 Returns the article selected or nil if there are no matching articles."
7178   (interactive "P")
7179   (cond
7180    ;; Empty summary.
7181    ((null gnus-newsgroup-data)
7182     (gnus-message 3 "No articles in the group")
7183     nil)
7184    ;; Pick the first article.
7185    ((not (or unread undownloaded unseen))
7186     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7187     (gnus-data-number (car gnus-newsgroup-data)))
7188    ;; Find the first unread article.
7189    (t
7190     (let ((data gnus-newsgroup-data))
7191       (while (and data
7192                   (let ((num (gnus-data-number (car data))))
7193                     (or (memq num gnus-newsgroup-unfetched)
7194                         (not (or (and unread
7195                                       (memq num gnus-newsgroup-unreads))
7196                                  (and undownloaded
7197                                       (memq num gnus-newsgroup-undownloaded))
7198                                  (and unseen
7199                                       (memq num gnus-newsgroup-unseen)))))))
7200         (setq data (cdr data)))
7201       (prog1
7202           (if data
7203               (progn
7204                 (goto-char (gnus-data-pos (car data)))
7205                 (gnus-data-number (car data)))
7206             (gnus-message 3 "No more%s articles"
7207                           (let* ((r (when unread " unread"))
7208                                  (d (when undownloaded " undownloaded"))
7209                                  (s (when unseen " unseen"))
7210                                  (l (delq nil (list r d s))))
7211                             (cond ((= 3 (length l))
7212                                    (concat r "," d ", or" s))
7213                                   ((= 2 (length l))
7214                                    (concat (car l) ", or" (cadr l)))
7215                                   ((= 1 (length l))
7216                                    (car l))
7217                                   (t
7218                                    ""))))
7219             nil
7220             )
7221         (gnus-summary-position-point))))))
7222
7223 (defun gnus-summary-next-subject (n &optional unread dont-display)
7224   "Go to next N'th summary line.
7225 If N is negative, go to the previous N'th subject line.
7226 If UNREAD is non-nil, only unread articles are selected.
7227 The difference between N and the actual number of steps taken is
7228 returned."
7229   (interactive "p")
7230   (let ((backward (< n 0))
7231         (n (abs n)))
7232     (while (and (> n 0)
7233                 (if backward
7234                     (gnus-summary-find-prev unread)
7235                   (gnus-summary-find-next unread)))
7236       (unless (zerop (setq n (1- n)))
7237         (gnus-summary-show-thread)))
7238     (when (/= 0 n)
7239       (gnus-message 7 "No more%s articles"
7240                     (if unread " unread" "")))
7241     (unless dont-display
7242       (gnus-summary-recenter)
7243       (gnus-summary-position-point))
7244     n))
7245
7246 (defun gnus-summary-next-unread-subject (n)
7247   "Go to next N'th unread summary line."
7248   (interactive "p")
7249   (gnus-summary-next-subject n t))
7250
7251 (defun gnus-summary-prev-subject (n &optional unread)
7252   "Go to previous N'th summary line.
7253 If optional argument UNREAD is non-nil, only unread article is selected."
7254   (interactive "p")
7255   (gnus-summary-next-subject (- n) unread))
7256
7257 (defun gnus-summary-prev-unread-subject (n)
7258   "Go to previous N'th unread summary line."
7259   (interactive "p")
7260   (gnus-summary-next-subject (- n) t))
7261
7262 (defun gnus-summary-goto-subjects (articles)
7263   "Insert the subject header for ARTICLES in the current buffer."
7264   (save-excursion
7265     (dolist (article articles)
7266       (gnus-summary-goto-subject article t)))
7267   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7268   (gnus-summary-position-point))
7269
7270 (defun gnus-summary-goto-subject (article &optional force silent)
7271   "Go the subject line of ARTICLE.
7272 If FORCE, also allow jumping to articles not currently shown."
7273   (interactive "nArticle number: ")
7274   (unless (numberp article)
7275     (error "Article %s is not a number" article))
7276   (let ((b (point))
7277         (data (gnus-data-find article)))
7278     ;; We read in the article if we have to.
7279     (and (not data)
7280          force
7281          (gnus-summary-insert-subject
7282           article
7283           (if (or (numberp force) (vectorp force)) force)
7284           t)
7285          (setq data (gnus-data-find article)))
7286     (goto-char b)
7287     (if (not data)
7288         (progn
7289           (unless silent
7290             (gnus-message 3 "Can't find article %d" article))
7291           nil)
7292       (let ((pt (gnus-data-pos data)))
7293         (goto-char pt)
7294         (gnus-summary-set-article-display-arrow pt))
7295       (gnus-summary-position-point)
7296       article)))
7297
7298 ;; Walking around summary lines with displaying articles.
7299
7300 (defun gnus-summary-expand-window (&optional arg)
7301   "Make the summary buffer take up the entire Emacs frame.
7302 Given a prefix, will force an `article' buffer configuration."
7303   (interactive "P")
7304   (if arg
7305       (gnus-configure-windows 'article 'force)
7306     (gnus-configure-windows 'summary 'force)))
7307
7308 (defun gnus-summary-display-article (article &optional all-header)
7309   "Display ARTICLE in article buffer."
7310   (when (gnus-buffer-live-p gnus-article-buffer)
7311     (with-current-buffer gnus-article-buffer
7312       (mm-enable-multibyte)))
7313   (gnus-set-global-variables)
7314   (when (gnus-buffer-live-p gnus-article-buffer)
7315     (with-current-buffer gnus-article-buffer
7316       (setq gnus-article-charset gnus-newsgroup-charset)
7317       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7318       (mm-enable-multibyte)))
7319   (if (null article)
7320       nil
7321     (prog1
7322         (if gnus-summary-display-article-function
7323             (funcall gnus-summary-display-article-function article all-header)
7324           (gnus-article-prepare article all-header))
7325       (gnus-run-hooks 'gnus-select-article-hook)
7326       (when (and gnus-current-article
7327                  (not (zerop gnus-current-article)))
7328         (gnus-summary-goto-subject gnus-current-article))
7329       (gnus-summary-recenter)
7330       (when (and gnus-use-trees gnus-show-threads)
7331         (gnus-possibly-generate-tree article)
7332         (gnus-highlight-selected-tree article))
7333       ;; Successfully display article.
7334       (gnus-article-set-window-start
7335        (cdr (assq article gnus-newsgroup-bookmarks))))))
7336
7337 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7338   "Select the current article.
7339 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7340 non-nil, the article will be re-fetched even if it already present in
7341 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7342 be displayed."
7343   ;; Make sure we are in the summary buffer to work around bbdb bug.
7344   (unless (eq major-mode 'gnus-summary-mode)
7345     (set-buffer gnus-summary-buffer))
7346   (let ((article (or article (gnus-summary-article-number)))
7347         (all-headers (not (not all-headers))) ;Must be t or nil.
7348         gnus-summary-display-article-function)
7349     (and (not pseudo)
7350          (gnus-summary-article-pseudo-p article)
7351          (error "This is a pseudo-article"))
7352     (save-excursion
7353       (set-buffer gnus-summary-buffer)
7354       (if (or (and gnus-single-article-buffer
7355                    (or (null gnus-current-article)
7356                        (null gnus-article-current)
7357                        (null (get-buffer gnus-article-buffer))
7358                        (not (eq article (cdr gnus-article-current)))
7359                        (not (equal (car gnus-article-current)
7360                                    gnus-newsgroup-name))))
7361               (and (not gnus-single-article-buffer)
7362                    (or (null gnus-current-article)
7363                        (not (eq gnus-current-article article))))
7364               force)
7365           ;; The requested article is different from the current article.
7366           (progn
7367             (gnus-summary-display-article article all-headers)
7368             (when (gnus-buffer-live-p gnus-article-buffer)
7369               (with-current-buffer gnus-article-buffer
7370                 (if (not gnus-article-decoded-p) ;; a local variable
7371                     (mm-disable-multibyte))))
7372             (gnus-article-set-window-start
7373              (cdr (assq article gnus-newsgroup-bookmarks)))
7374             article)
7375         'old))))
7376
7377 (defun gnus-summary-force-verify-and-decrypt ()
7378   "Display buttons for signed/encrypted parts and verify/decrypt them."
7379   (interactive)
7380   (let ((mm-verify-option 'known)
7381         (mm-decrypt-option 'known)
7382         (gnus-article-emulate-mime t)
7383         (gnus-buttonized-mime-types (append (list "multipart/signed"
7384                                                   "multipart/encrypted")
7385                                             gnus-buttonized-mime-types)))
7386     (gnus-summary-select-article nil 'force)))
7387
7388 (defun gnus-summary-set-current-mark (&optional current-mark)
7389   "Obsolete function."
7390   nil)
7391
7392 (defun gnus-summary-next-article (&optional unread subject backward push)
7393   "Select the next article.
7394 If UNREAD, only unread articles are selected.
7395 If SUBJECT, only articles with SUBJECT are selected.
7396 If BACKWARD, the previous article is selected instead of the next."
7397   (interactive "P")
7398   (cond
7399    ;; Is there such an article?
7400    ((and (gnus-summary-search-forward unread subject backward)
7401          (or (gnus-summary-display-article (gnus-summary-article-number))
7402              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7403     (gnus-summary-position-point))
7404    ;; If not, we try the first unread, if that is wanted.
7405    ((and subject
7406          gnus-auto-select-same
7407          (gnus-summary-first-unread-article))
7408     (gnus-summary-position-point)
7409     (gnus-message 6 "Wrapped"))
7410    ;; Try to get next/previous article not displayed in this group.
7411    ((and gnus-auto-extend-newsgroup
7412          (not unread) (not subject))
7413     (gnus-summary-goto-article
7414      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7415      nil (count-lines (point-min) (point))))
7416    ;; Go to next/previous group.
7417    (t
7418     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7419       (gnus-summary-jump-to-group gnus-newsgroup-name))
7420     (let ((cmd last-command-char)
7421           (point
7422            (with-current-buffer gnus-group-buffer
7423              (point)))
7424           (group
7425            (if (eq gnus-keep-same-level 'best)
7426                (gnus-summary-best-group gnus-newsgroup-name)
7427              (gnus-summary-search-group backward gnus-keep-same-level))))
7428       ;; For some reason, the group window gets selected.  We change
7429       ;; it back.
7430       (select-window (get-buffer-window (current-buffer)))
7431       ;; Select next unread newsgroup automagically.
7432       (cond
7433        ((or (not gnus-auto-select-next)
7434             (not cmd))
7435         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7436        ((or (eq gnus-auto-select-next 'quietly)
7437             (and (eq gnus-auto-select-next 'slightly-quietly)
7438                  push)
7439             (and (eq gnus-auto-select-next 'almost-quietly)
7440                  (gnus-summary-last-article-p)))
7441         ;; Select quietly.
7442         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7443             (gnus-summary-exit)
7444           (gnus-message 7 "No more%s articles (%s)..."
7445                         (if unread " unread" "")
7446                         (if group (concat "selecting " group)
7447                           "exiting"))
7448           (gnus-summary-next-group nil group backward)))
7449        (t
7450         (when (gnus-key-press-event-p last-input-event)
7451           (gnus-summary-walk-group-buffer
7452            gnus-newsgroup-name cmd unread backward point))))))))
7453
7454 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7455   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7456                       (?\C-p (gnus-group-prev-unread-group 1))))
7457         (cursor-in-echo-area t)
7458         keve key group ended prompt)
7459     (save-excursion
7460       (set-buffer gnus-group-buffer)
7461       (goto-char start)
7462       (setq group
7463             (if (eq gnus-keep-same-level 'best)
7464                 (gnus-summary-best-group gnus-newsgroup-name)
7465               (gnus-summary-search-group backward gnus-keep-same-level))))
7466     (while (not ended)
7467       (setq prompt
7468             (format
7469              "No more%s articles%s " (if unread " unread" "")
7470              (if (and group
7471                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7472                  (format " (Type %s for %s [%s])"
7473                          (single-key-description cmd)
7474                          (gnus-group-decoded-name group)
7475                          (gnus-group-unread group))
7476                (format " (Type %s to exit %s)"
7477                        (single-key-description cmd)
7478                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7479       ;; Confirm auto selection.
7480       (setq key (car (setq keve (gnus-read-event-char prompt)))
7481             ended t)
7482       (cond
7483        ((assq key keystrokes)
7484         (let ((obuf (current-buffer)))
7485           (switch-to-buffer gnus-group-buffer)
7486           (when group
7487             (gnus-group-jump-to-group group))
7488           (eval (cadr (assq key keystrokes)))
7489           (setq group (gnus-group-group-name))
7490           (switch-to-buffer obuf))
7491         (setq ended nil))
7492        ((equal key cmd)
7493         (if (or (not group)
7494                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7495             (gnus-summary-exit)
7496           (gnus-summary-next-group nil group backward)))
7497        (t
7498         (push (cdr keve) unread-command-events))))))
7499
7500 (defun gnus-summary-next-unread-article ()
7501   "Select unread article after current one."
7502   (interactive)
7503   (gnus-summary-next-article
7504    (or (not (eq gnus-summary-goto-unread 'never))
7505        (gnus-summary-last-article-p (gnus-summary-article-number)))
7506    (and gnus-auto-select-same
7507         (gnus-summary-article-subject))))
7508
7509 (defun gnus-summary-prev-article (&optional unread subject)
7510   "Select the article after the current one.
7511 If UNREAD is non-nil, only unread articles are selected."
7512   (interactive "P")
7513   (gnus-summary-next-article unread subject t))
7514
7515 (defun gnus-summary-prev-unread-article ()
7516   "Select unread article before current one."
7517   (interactive)
7518   (gnus-summary-prev-article
7519    (or (not (eq gnus-summary-goto-unread 'never))
7520        (gnus-summary-first-article-p (gnus-summary-article-number)))
7521    (and gnus-auto-select-same
7522         (gnus-summary-article-subject))))
7523
7524 (defun gnus-summary-next-page (&optional lines circular stop)
7525   "Show next page of the selected article.
7526 If at the end of the current article, select the next article.
7527 LINES says how many lines should be scrolled up.
7528
7529 If CIRCULAR is non-nil, go to the start of the article instead of
7530 selecting the next article when reaching the end of the current
7531 article.
7532
7533 If STOP is non-nil, just stop when reaching the end of the message.
7534
7535 Also see the variable `gnus-article-skip-boring'."
7536   (interactive "P")
7537   (setq gnus-summary-buffer (current-buffer))
7538   (gnus-set-global-variables)
7539   (let ((article (gnus-summary-article-number))
7540         (article-window (get-buffer-window gnus-article-buffer t))
7541         endp)
7542     ;; If the buffer is empty, we have no article.
7543     (unless article
7544       (error "No article to select"))
7545     (gnus-configure-windows 'article)
7546     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7547         (if (and (eq gnus-summary-goto-unread 'never)
7548                  (not (gnus-summary-last-article-p article)))
7549             (gnus-summary-next-article)
7550           (gnus-summary-next-unread-article))
7551       (if (or (null gnus-current-article)
7552               (null gnus-article-current)
7553               (/= article (cdr gnus-article-current))
7554               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7555           ;; Selected subject is different from current article's.
7556           (gnus-summary-display-article article)
7557         (when article-window
7558           (gnus-eval-in-buffer-window gnus-article-buffer
7559             (setq endp (or (gnus-article-next-page lines)
7560                            (gnus-article-only-boring-p))))
7561           (when endp
7562             (cond (stop
7563                    (gnus-message 3 "End of message"))
7564                   (circular
7565                    (gnus-summary-beginning-of-article))
7566                   (lines
7567                    (gnus-message 3 "End of message"))
7568                   ((null lines)
7569                    (if (and (eq gnus-summary-goto-unread 'never)
7570                             (not (gnus-summary-last-article-p article)))
7571                        (gnus-summary-next-article)
7572                      (gnus-summary-next-unread-article))))))))
7573     (gnus-summary-recenter)
7574     (gnus-summary-position-point)))
7575
7576 (defun gnus-summary-prev-page (&optional lines move)
7577   "Show previous page of selected article.
7578 Argument LINES specifies lines to be scrolled down.
7579 If MOVE, move to the previous unread article if point is at
7580 the beginning of the buffer."
7581   (interactive "P")
7582   (let ((article (gnus-summary-article-number))
7583         (article-window (get-buffer-window gnus-article-buffer t))
7584         endp)
7585     (gnus-configure-windows 'article)
7586     (if (or (null gnus-current-article)
7587             (null gnus-article-current)
7588             (/= article (cdr gnus-article-current))
7589             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7590         ;; Selected subject is different from current article's.
7591         (gnus-summary-display-article article)
7592       (gnus-summary-recenter)
7593       (when article-window
7594         (gnus-eval-in-buffer-window gnus-article-buffer
7595           (setq endp (gnus-article-prev-page lines)))
7596         (when (and move endp)
7597           (cond (lines
7598                  (gnus-message 3 "Beginning of message"))
7599                 ((null lines)
7600                  (if (and (eq gnus-summary-goto-unread 'never)
7601                           (not (gnus-summary-first-article-p article)))
7602                      (gnus-summary-prev-article)
7603                    (gnus-summary-prev-unread-article))))))))
7604   (gnus-summary-position-point))
7605
7606 (defun gnus-summary-prev-page-or-article (&optional lines)
7607   "Show previous page of selected article.
7608 Argument LINES specifies lines to be scrolled down.
7609 If at the beginning of the article, go to the next article."
7610   (interactive "P")
7611   (gnus-summary-prev-page lines t))
7612
7613 (defun gnus-summary-scroll-up (lines)
7614   "Scroll up (or down) one line current article.
7615 Argument LINES specifies lines to be scrolled up (or down if negative)."
7616   (interactive "p")
7617   (gnus-configure-windows 'article)
7618   (gnus-summary-show-thread)
7619   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7620     (gnus-eval-in-buffer-window gnus-article-buffer
7621       (cond ((> lines 0)
7622              (when (gnus-article-next-page lines)
7623                (gnus-message 3 "End of message")))
7624             ((< lines 0)
7625              (gnus-article-prev-page (- lines))))))
7626   (gnus-summary-recenter)
7627   (gnus-summary-position-point))
7628
7629 (defun gnus-summary-scroll-down (lines)
7630   "Scroll down (or up) one line current article.
7631 Argument LINES specifies lines to be scrolled down (or up if negative)."
7632   (interactive "p")
7633   (gnus-summary-scroll-up (- lines)))
7634
7635 (defun gnus-summary-next-same-subject ()
7636   "Select next article which has the same subject as current one."
7637   (interactive)
7638   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7639
7640 (defun gnus-summary-prev-same-subject ()
7641   "Select previous article which has the same subject as current one."
7642   (interactive)
7643   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7644
7645 (defun gnus-summary-next-unread-same-subject ()
7646   "Select next unread article which has the same subject as current one."
7647   (interactive)
7648   (gnus-summary-next-article t (gnus-summary-article-subject)))
7649
7650 (defun gnus-summary-prev-unread-same-subject ()
7651   "Select previous unread article which has the same subject as current one."
7652   (interactive)
7653   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7654
7655 (defun gnus-summary-first-unread-article ()
7656   "Select the first unread article.
7657 Return nil if there are no unread articles."
7658   (interactive)
7659   (prog1
7660       (when (gnus-summary-first-subject t)
7661         (gnus-summary-show-thread)
7662         (gnus-summary-first-subject t)
7663         (gnus-summary-display-article (gnus-summary-article-number)))
7664     (gnus-summary-position-point)))
7665
7666 (defun gnus-summary-first-unread-subject ()
7667   "Place the point on the subject line of the first unread article.
7668 Return nil if there are no unread articles."
7669   (interactive)
7670   (prog1
7671       (when (gnus-summary-first-subject t)
7672         (gnus-summary-show-thread)
7673         (gnus-summary-first-subject t))
7674     (gnus-summary-position-point)))
7675
7676 (defun gnus-summary-first-unseen-subject ()
7677   "Place the point on the subject line of the first unseen article.
7678 Return nil if there are no unseen articles."
7679   (interactive)
7680   (prog1
7681       (when (gnus-summary-first-subject nil nil t)
7682         (gnus-summary-show-thread)
7683         (gnus-summary-first-subject nil nil t))
7684     (gnus-summary-position-point)))
7685
7686 (defun gnus-summary-first-unseen-or-unread-subject ()
7687   "Place the point on the subject line of the first unseen article or,
7688 if all article have been seen, on the subject line of the first unread
7689 article."
7690   (interactive)
7691   (prog1
7692       (unless (when (gnus-summary-first-subject nil nil t)
7693                 (gnus-summary-show-thread)
7694                 (gnus-summary-first-subject nil nil t))
7695         (when (gnus-summary-first-subject t)
7696           (gnus-summary-show-thread)
7697           (gnus-summary-first-subject t)))
7698     (gnus-summary-position-point)))
7699
7700 (defun gnus-summary-first-article ()
7701   "Select the first article.
7702 Return nil if there are no articles."
7703   (interactive)
7704   (prog1
7705       (when (gnus-summary-first-subject)
7706         (gnus-summary-show-thread)
7707         (gnus-summary-first-subject)
7708         (gnus-summary-display-article (gnus-summary-article-number)))
7709     (gnus-summary-position-point)))
7710
7711 (defun gnus-summary-best-unread-article (&optional arg)
7712   "Select the unread article with the highest score.
7713 If given a prefix argument, select the next unread article that has a
7714 score higher than the default score."
7715   (interactive "P")
7716   (let ((article (if arg
7717                      (gnus-summary-better-unread-subject)
7718                    (gnus-summary-best-unread-subject))))
7719     (if article
7720         (gnus-summary-goto-article article)
7721       (error "No unread articles"))))
7722
7723 (defun gnus-summary-best-unread-subject ()
7724   "Select the unread subject with the highest score."
7725   (interactive)
7726   (let ((best -1000000)
7727         (data gnus-newsgroup-data)
7728         article score)
7729     (while data
7730       (and (gnus-data-unread-p (car data))
7731            (> (setq score
7732                     (gnus-summary-article-score (gnus-data-number (car data))))
7733               best)
7734            (setq best score
7735                  article (gnus-data-number (car data))))
7736       (setq data (cdr data)))
7737     (when article
7738       (gnus-summary-goto-subject article))
7739     (gnus-summary-position-point)
7740     article))
7741
7742 (defun gnus-summary-better-unread-subject ()
7743   "Select the first unread subject that has a score over the default score."
7744   (interactive)
7745   (let ((data gnus-newsgroup-data)
7746         article score)
7747     (while (and (setq article (gnus-data-number (car data)))
7748                 (or (gnus-data-read-p (car data))
7749                     (not (> (gnus-summary-article-score article)
7750                             gnus-summary-default-score))))
7751       (setq data (cdr data)))
7752     (when article
7753       (gnus-summary-goto-subject article))
7754     (gnus-summary-position-point)
7755     article))
7756
7757 (defun gnus-summary-last-subject ()
7758   "Go to the last displayed subject line in the group."
7759   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7760     (when article
7761       (gnus-summary-goto-subject article))))
7762
7763 (defun gnus-summary-goto-article (article &optional all-headers force)
7764   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7765 If ALL-HEADERS is non-nil, no header lines are hidden.
7766 If FORCE, go to the article even if it isn't displayed.  If FORCE
7767 is a number, it is the line the article is to be displayed on."
7768   (interactive
7769    (list
7770     (completing-read
7771      "Article number or Message-ID: "
7772      (mapcar (lambda (number) (list (int-to-string number)))
7773              gnus-newsgroup-limit))
7774     current-prefix-arg
7775     t))
7776   (prog1
7777       (if (and (stringp article)
7778                (string-match "@\\|%40" article))
7779           (gnus-summary-refer-article article)
7780         (when (stringp article)
7781           (setq article (string-to-number article)))
7782         (if (gnus-summary-goto-subject article force)
7783             (gnus-summary-display-article article all-headers)
7784           (gnus-message 4 "Couldn't go to article %s" article) nil))
7785     (gnus-summary-position-point)))
7786
7787 (defun gnus-summary-goto-last-article ()
7788   "Go to the previously read article."
7789   (interactive)
7790   (prog1
7791       (when gnus-last-article
7792         (gnus-summary-goto-article gnus-last-article nil t))
7793     (gnus-summary-position-point)))
7794
7795 (defun gnus-summary-pop-article (number)
7796   "Pop one article off the history and go to the previous.
7797 NUMBER articles will be popped off."
7798   (interactive "p")
7799   (let (to)
7800     (setq gnus-newsgroup-history
7801           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7802     (if to
7803         (gnus-summary-goto-article (car to) nil t)
7804       (error "Article history empty")))
7805   (gnus-summary-position-point))
7806
7807 ;; Summary commands and functions for limiting the summary buffer.
7808
7809 (defun gnus-summary-limit-to-articles (n)
7810   "Limit the summary buffer to the next N articles.
7811 If not given a prefix, use the process marked articles instead."
7812   (interactive "P")
7813   (prog1
7814       (let ((articles (gnus-summary-work-articles n)))
7815         (setq gnus-newsgroup-processable nil)
7816         (gnus-summary-limit articles))
7817     (gnus-summary-position-point)))
7818
7819 (defun gnus-summary-pop-limit (&optional total)
7820   "Restore the previous limit.
7821 If given a prefix, remove all limits."
7822   (interactive "P")
7823   (when total
7824     (setq gnus-newsgroup-limits
7825           (list (mapcar (lambda (h) (mail-header-number h))
7826                         gnus-newsgroup-headers))))
7827   (unless gnus-newsgroup-limits
7828     (error "No limit to pop"))
7829   (prog1
7830       (gnus-summary-limit nil 'pop)
7831     (gnus-summary-position-point)))
7832
7833 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7834   "Limit the summary buffer to articles that have subjects that match a regexp.
7835 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7836   (interactive
7837    (list (read-string (if current-prefix-arg
7838                           "Exclude subject (regexp): "
7839                         "Limit to subject (regexp): "))
7840          nil current-prefix-arg))
7841   (unless header
7842     (setq header "subject"))
7843   (when (not (equal "" subject))
7844     (prog1
7845         (let ((articles (gnus-summary-find-matching
7846                          (or header "subject") subject 'all nil nil
7847                          not-matching)))
7848           (unless articles
7849             (error "Found no matches for \"%s\"" subject))
7850           (gnus-summary-limit articles))
7851       (gnus-summary-position-point))))
7852
7853 (defun gnus-summary-limit-to-author (from &optional not-matching)
7854   "Limit the summary buffer to articles that have authors that match a regexp.
7855 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7856   (interactive
7857    (list (read-string (if current-prefix-arg
7858                           "Exclude author (regexp): "
7859                         "Limit to author (regexp): "))
7860          current-prefix-arg))
7861   (gnus-summary-limit-to-subject from "from" not-matching))
7862
7863 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7864   "Limit the summary buffer to articles with the given RECIPIENT.
7865
7866 If NOT-MATCHING, exclude RECIPIENT.
7867
7868 To and Cc headers are checked.  You need to include them in
7869 `nnmail-extra-headers'."
7870   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7871   (interactive
7872    (list (read-string (format "%s recipient (regexp): "
7873                               (if current-prefix-arg "Exclude" "Limit to")))
7874          current-prefix-arg))
7875   (when (not (equal "" recipient))
7876     (prog1 (let* ((to
7877                    (if (memq 'To nnmail-extra-headers)
7878                        (gnus-summary-find-matching
7879                         (cons 'extra 'To) recipient 'all nil nil
7880                         not-matching)
7881                      (gnus-message
7882                       1 "`To' isn't present in `nnmail-extra-headers'")
7883                      (sit-for 1)
7884                      nil))
7885                   (cc
7886                    (if (memq 'Cc nnmail-extra-headers)
7887                        (gnus-summary-find-matching
7888                         (cons 'extra 'Cc) recipient 'all nil nil
7889                         not-matching)
7890                      (gnus-message
7891                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7892                      (sit-for 1)
7893                      nil))
7894                   (articles
7895                    (if not-matching
7896                        ;; We need the numbers that are in both lists:
7897                        (mapcar (lambda (a)
7898                                  (and (memq a to) a))
7899                                cc)
7900                      (nconc to cc))))
7901              (unless articles
7902                (error "Found no matches for \"%s\"" recipient))
7903              (gnus-summary-limit articles))
7904       (gnus-summary-position-point))))
7905
7906 (defun gnus-summary-limit-to-age (age &optional younger-p)
7907   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7908 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7909 articles that are younger than AGE days."
7910   (interactive
7911    (let ((younger current-prefix-arg)
7912          (days-got nil)
7913          days)
7914      (while (not days-got)
7915        (setq days (if younger
7916                       (read-string "Limit to articles younger than (in days, older when negative): ")
7917                     (read-string
7918                      "Limit to articles older than (in days, younger when negative): ")))
7919        (when (> (length days) 0)
7920          (setq days (read days)))
7921        (if (numberp days)
7922            (progn
7923              (setq days-got t)
7924              (when (< days 0)
7925                (setq younger (not younger))
7926                (setq days (* days -1))))
7927          (message "Please enter a number.")
7928          (sleep-for 1)))
7929      (list days younger)))
7930   (prog1
7931       (let ((data gnus-newsgroup-data)
7932             (cutoff (days-to-time age))
7933             articles d date is-younger)
7934         (while (setq d (pop data))
7935           (when (and (vectorp (gnus-data-header d))
7936                      (setq date (mail-header-date (gnus-data-header d))))
7937             (setq is-younger (time-less-p
7938                               (time-since (condition-case ()
7939                                               (date-to-time date)
7940                                             (error '(0 0))))
7941                               cutoff))
7942             (when (if younger-p
7943                       is-younger
7944                     (not is-younger))
7945               (push (gnus-data-number d) articles))))
7946         (gnus-summary-limit (nreverse articles)))
7947     (gnus-summary-position-point)))
7948
7949 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7950   "Limit the summary buffer to articles that match an 'extra' header."
7951   (interactive
7952    (let ((header
7953           (intern
7954            (gnus-completing-read-with-default
7955             (symbol-name (car gnus-extra-headers))
7956             (if current-prefix-arg
7957                 "Exclude extra header"
7958               "Limit extra header")
7959             (mapcar (lambda (x)
7960                       (cons (symbol-name x) x))
7961                     gnus-extra-headers)
7962             nil
7963             t))))
7964      (list header
7965            (read-string (format "%s header %s (regexp): "
7966                                 (if current-prefix-arg "Exclude" "Limit to")
7967                                 header))
7968            current-prefix-arg)))
7969   (when (not (equal "" regexp))
7970     (prog1
7971         (let ((articles (gnus-summary-find-matching
7972                          (cons 'extra header) regexp 'all nil nil
7973                          not-matching)))
7974           (unless articles
7975             (error "Found no matches for \"%s\"" regexp))
7976           (gnus-summary-limit articles))
7977       (gnus-summary-position-point))))
7978
7979 (defun gnus-summary-limit-to-display-predicate ()
7980   "Limit the summary buffer to the predicated in the `display' group parameter."
7981   (interactive)
7982   (unless gnus-newsgroup-display
7983     (error "There is no `display' group parameter"))
7984   (let (articles)
7985     (dolist (number gnus-newsgroup-articles)
7986       (when (funcall gnus-newsgroup-display)
7987         (push number articles)))
7988     (gnus-summary-limit articles))
7989   (gnus-summary-position-point))
7990
7991 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7992 (make-obsolete
7993  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7994
7995 (defun gnus-summary-limit-to-unread (&optional all)
7996   "Limit the summary buffer to articles that are not marked as read.
7997 If ALL is non-nil, limit strictly to unread articles."
7998   (interactive "P")
7999   (if all
8000       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8001     (gnus-summary-limit-to-marks
8002      ;; Concat all the marks that say that an article is read and have
8003      ;; those removed.
8004      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8005            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8006            gnus-low-score-mark gnus-expirable-mark
8007            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8008            gnus-duplicate-mark gnus-souped-mark)
8009      'reverse)))
8010
8011 (defun gnus-summary-limit-to-bodies (match &optional reverse)
8012   "Limit the summary buffer to articles that have bodies that match MATCH.
8013 If REVERSE (the prefix), limit to articles that don't match."
8014   (interactive "sMatch body (regexp): \nP")
8015   (let ((articles nil)
8016         (gnus-select-article-hook nil)  ;Disable hook.
8017         (gnus-article-prepare-hook nil)
8018         (gnus-use-article-prefetch nil)
8019         (gnus-keep-backlog nil)
8020         (gnus-break-pages nil)
8021         (gnus-summary-display-arrow nil)
8022         (gnus-updated-mode-lines nil)
8023         (gnus-auto-center-summary nil)
8024         (gnus-display-mime-function nil))
8025     (dolist (data gnus-newsgroup-data)
8026       (let (gnus-mark-article-hook)
8027         (gnus-summary-select-article t t nil (gnus-data-number data)))
8028       (save-excursion
8029         (set-buffer gnus-article-buffer)
8030         (article-goto-body)
8031         (let* ((case-fold-search t)
8032                (found (re-search-forward match nil t)))
8033           (when (or (and found
8034                          (not reverse))
8035                     (and (not found)
8036                          reverse))
8037             (push (gnus-data-number data) articles)))))
8038     (if (not articles)
8039         (message "No messages matched")
8040       (gnus-summary-limit articles)))
8041   (gnus-summary-position-point))
8042
8043 (defun gnus-summary-limit-to-replied (&optional unreplied)
8044   "Limit the summary buffer to replied articles.
8045 If UNREPLIED (the prefix), limit to unreplied articles."
8046   (interactive "P")
8047   (if unreplied
8048       (gnus-summary-limit
8049        (gnus-set-difference gnus-newsgroup-articles
8050         gnus-newsgroup-replied))
8051     (gnus-summary-limit gnus-newsgroup-replied))
8052   (gnus-summary-position-point))
8053
8054 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8055 (make-obsolete 'gnus-summary-delete-marked-with
8056                'gnus-summary-limit-exclude-marks)
8057
8058 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8059   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8060 If REVERSE, limit the summary buffer to articles that are marked
8061 with MARKS.  MARKS can either be a string of marks or a list of marks.
8062 Returns how many articles were removed."
8063   (interactive "sMarks: ")
8064   (gnus-summary-limit-to-marks marks t))
8065
8066 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8067   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8068 If REVERSE (the prefix), limit the summary buffer to articles that are
8069 not marked with MARKS.  MARKS can either be a string of marks or a
8070 list of marks.
8071 Returns how many articles were removed."
8072   (interactive "sMarks: \nP")
8073   (prog1
8074       (let ((data gnus-newsgroup-data)
8075             (marks (if (listp marks) marks
8076                      (append marks nil))) ; Transform to list.
8077             articles)
8078         (while data
8079           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8080                   (memq (gnus-data-mark (car data)) marks))
8081             (push (gnus-data-number (car data)) articles))
8082           (setq data (cdr data)))
8083         (gnus-summary-limit articles))
8084     (gnus-summary-position-point)))
8085
8086 (defun gnus-summary-limit-to-score (score)
8087   "Limit to articles with score at or above SCORE."
8088   (interactive "NLimit to articles with score of at least: ")
8089   (let ((data gnus-newsgroup-data)
8090         articles)
8091     (while data
8092       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8093                 score)
8094         (push (gnus-data-number (car data)) articles))
8095       (setq data (cdr data)))
8096     (prog1
8097         (gnus-summary-limit articles)
8098       (gnus-summary-position-point))))
8099
8100 (defun gnus-summary-limit-to-unseen ()
8101   "Limit to unseen articles."
8102   (interactive)
8103   (prog1
8104       (gnus-summary-limit gnus-newsgroup-unseen)
8105     (gnus-summary-position-point)))
8106
8107 (defun gnus-summary-limit-include-thread (id)
8108   "Display all the hidden articles that is in the thread with ID in it.
8109 When called interactively, ID is the Message-ID of the current
8110 article."
8111   (interactive (list (mail-header-id (gnus-summary-article-header))))
8112   (let ((articles (gnus-articles-in-thread
8113                    (gnus-id-to-thread (gnus-root-id id)))))
8114     (prog1
8115         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8116       (gnus-summary-limit-include-matching-articles
8117        "subject"
8118        (regexp-quote (gnus-simplify-subject-re
8119                       (mail-header-subject (gnus-id-to-header id)))))
8120       (gnus-summary-position-point))))
8121
8122 (defun gnus-summary-limit-include-matching-articles (header regexp)
8123   "Display all the hidden articles that have HEADERs that match REGEXP."
8124   (interactive (list (read-string "Match on header: ")
8125                      (read-string "Regexp: ")))
8126   (let ((articles (gnus-find-matching-articles header regexp)))
8127     (prog1
8128         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8129       (gnus-summary-position-point))))
8130
8131 (defun gnus-summary-insert-dormant-articles ()
8132   "Insert all the dormant articles for this group into the current buffer."
8133   (interactive)
8134   (let ((gnus-verbose (max 6 gnus-verbose)))
8135     (if (not gnus-newsgroup-dormant)
8136         (gnus-message 3 "No cached articles for this group")
8137       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8138
8139 (defun gnus-summary-limit-include-dormant ()
8140   "Display all the hidden articles that are marked as dormant.
8141 Note that this command only works on a subset of the articles currently
8142 fetched for this group."
8143   (interactive)
8144   (unless gnus-newsgroup-dormant
8145     (error "There are no dormant articles in this group"))
8146   (prog1
8147       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8148     (gnus-summary-position-point)))
8149
8150 (defun gnus-summary-limit-exclude-dormant ()
8151   "Hide all dormant articles."
8152   (interactive)
8153   (prog1
8154       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8155     (gnus-summary-position-point)))
8156
8157 (defun gnus-summary-limit-exclude-childless-dormant ()
8158   "Hide all dormant articles that have no children."
8159   (interactive)
8160   (let ((data (gnus-data-list t))
8161         articles d children)
8162     ;; Find all articles that are either not dormant or have
8163     ;; children.
8164     (while (setq d (pop data))
8165       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8166                 (and (setq children
8167                            (gnus-article-children (gnus-data-number d)))
8168                      (let (found)
8169                        (while children
8170                          (when (memq (car children) articles)
8171                            (setq children nil
8172                                  found t))
8173                          (pop children))
8174                        found)))
8175         (push (gnus-data-number d) articles)))
8176     ;; Do the limiting.
8177     (prog1
8178         (gnus-summary-limit articles)
8179       (gnus-summary-position-point))))
8180
8181 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8182   "Mark all unread excluded articles as read.
8183 If ALL, mark even excluded ticked and dormants as read."
8184   (interactive "P")
8185   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8186   (let ((articles (gnus-sorted-ndifference
8187                    (sort
8188                     (mapcar (lambda (h) (mail-header-number h))
8189                             gnus-newsgroup-headers)
8190                     '<)
8191                    gnus-newsgroup-limit))
8192         article)
8193     (setq gnus-newsgroup-unreads
8194           (gnus-sorted-intersection gnus-newsgroup-unreads
8195                                     gnus-newsgroup-limit))
8196     (if all
8197         (setq gnus-newsgroup-dormant nil
8198               gnus-newsgroup-marked nil
8199               gnus-newsgroup-reads
8200               (nconc
8201                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8202                gnus-newsgroup-reads))
8203       (while (setq article (pop articles))
8204         (unless (or (memq article gnus-newsgroup-dormant)
8205                     (memq article gnus-newsgroup-marked))
8206           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8207
8208 (defun gnus-summary-limit (articles &optional pop)
8209   (if pop
8210       ;; We pop the previous limit off the stack and use that.
8211       (setq articles (car gnus-newsgroup-limits)
8212             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8213     ;; We use the new limit, so we push the old limit on the stack.
8214     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8215   ;; Set the limit.
8216   (setq gnus-newsgroup-limit articles)
8217   (let ((total (length gnus-newsgroup-data))
8218         (data (gnus-data-find-list (gnus-summary-article-number)))
8219         (gnus-summary-mark-below nil)   ; Inhibit this.
8220         found)
8221     ;; This will do all the work of generating the new summary buffer
8222     ;; according to the new limit.
8223     (gnus-summary-prepare)
8224     ;; Hide any threads, possibly.
8225     (gnus-summary-maybe-hide-threads)
8226     ;; Try to return to the article you were at, or one in the
8227     ;; neighborhood.
8228     (when data
8229       ;; We try to find some article after the current one.
8230       (while data
8231         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8232           (setq data nil
8233                 found t))
8234         (setq data (cdr data))))
8235     (unless found
8236       ;; If there is no data, that means that we were after the last
8237       ;; article.  The same goes when we can't find any articles
8238       ;; after the current one.
8239       (goto-char (point-max))
8240       (gnus-summary-find-prev))
8241     (gnus-set-mode-line 'summary)
8242     ;; We return how many articles were removed from the summary
8243     ;; buffer as a result of the new limit.
8244     (- total (length gnus-newsgroup-data))))
8245
8246 (defsubst gnus-invisible-cut-children (threads)
8247   (let ((num 0))
8248     (while threads
8249       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8250         (incf num))
8251       (pop threads))
8252     (< num 2)))
8253
8254 (defsubst gnus-cut-thread (thread)
8255   "Go forwards in the thread until we find an article that we want to display."
8256   (when (or (eq gnus-fetch-old-headers 'some)
8257             (eq gnus-fetch-old-headers 'invisible)
8258             (numberp gnus-fetch-old-headers)
8259             (eq gnus-build-sparse-threads 'some)
8260             (eq gnus-build-sparse-threads 'more))
8261     ;; Deal with old-fetched headers and sparse threads.
8262     (while (and
8263             thread
8264             (or
8265              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8266              (gnus-summary-article-ancient-p
8267               (mail-header-number (car thread))))
8268             (if (or (<= (length (cdr thread)) 1)
8269                     (eq gnus-fetch-old-headers 'invisible))
8270                 (setq gnus-newsgroup-limit
8271                       (delq (mail-header-number (car thread))
8272                             gnus-newsgroup-limit)
8273                       thread (cadr thread))
8274               (when (gnus-invisible-cut-children (cdr thread))
8275                 (let ((th (cdr thread)))
8276                   (while th
8277                     (if (memq (mail-header-number (caar th))
8278                               gnus-newsgroup-limit)
8279                         (setq thread (car th)
8280                               th nil)
8281                       (setq th (cdr th))))))))))
8282   thread)
8283
8284 (defun gnus-cut-threads (threads)
8285   "Cut off all uninteresting articles from the beginning of THREADS."
8286   (when (or (eq gnus-fetch-old-headers 'some)
8287             (eq gnus-fetch-old-headers 'invisible)
8288             (numberp gnus-fetch-old-headers)
8289             (eq gnus-build-sparse-threads 'some)
8290             (eq gnus-build-sparse-threads 'more))
8291     (let ((th threads))
8292       (while th
8293         (setcar th (gnus-cut-thread (car th)))
8294         (setq th (cdr th)))))
8295   ;; Remove nixed out threads.
8296   (delq nil threads))
8297
8298 (defun gnus-summary-initial-limit (&optional show-if-empty)
8299   "Figure out what the initial limit is supposed to be on group entry.
8300 This entails weeding out unwanted dormants, low-scored articles,
8301 fetch-old-headers verbiage, and so on."
8302   ;; Most groups have nothing to remove.
8303   (if (or gnus-inhibit-limiting
8304           (and (null gnus-newsgroup-dormant)
8305                (eq gnus-newsgroup-display 'gnus-not-ignore)
8306                (not (eq gnus-fetch-old-headers 'some))
8307                (not (numberp gnus-fetch-old-headers))
8308                (not (eq gnus-fetch-old-headers 'invisible))
8309                (null gnus-summary-expunge-below)
8310                (not (eq gnus-build-sparse-threads 'some))
8311                (not (eq gnus-build-sparse-threads 'more))
8312                (null gnus-thread-expunge-below)
8313                (not gnus-use-nocem)))
8314       ()                                ; Do nothing.
8315     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8316     (setq gnus-newsgroup-limit nil)
8317     (mapatoms
8318      (lambda (node)
8319        (unless (car (symbol-value node))
8320          ;; These threads have no parents -- they are roots.
8321          (let ((nodes (cdr (symbol-value node)))
8322                thread)
8323            (while nodes
8324              (if (and gnus-thread-expunge-below
8325                       (< (gnus-thread-total-score (car nodes))
8326                          gnus-thread-expunge-below))
8327                  (gnus-expunge-thread (pop nodes))
8328                (setq thread (pop nodes))
8329                (gnus-summary-limit-children thread))))))
8330      gnus-newsgroup-dependencies)
8331     ;; If this limitation resulted in an empty group, we might
8332     ;; pop the previous limit and use it instead.
8333     (when (and (not gnus-newsgroup-limit)
8334                show-if-empty)
8335       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8336     gnus-newsgroup-limit))
8337
8338 (defun gnus-summary-limit-children (thread)
8339   "Return 1 if this subthread is visible and 0 if it is not."
8340   ;; First we get the number of visible children to this thread.  This
8341   ;; is done by recursing down the thread using this function, so this
8342   ;; will really go down to a leaf article first, before slowly
8343   ;; working its way up towards the root.
8344   (when thread
8345     (let* ((max-lisp-eval-depth 5000)
8346            (children
8347            (if (cdr thread)
8348                (apply '+ (mapcar 'gnus-summary-limit-children
8349                                  (cdr thread)))
8350              0))
8351           (number (mail-header-number (car thread)))
8352           score)
8353       (if (and
8354            (not (memq number gnus-newsgroup-marked))
8355            (or
8356             ;; If this article is dormant and has absolutely no visible
8357             ;; children, then this article isn't visible.
8358             (and (memq number gnus-newsgroup-dormant)
8359                  (zerop children))
8360             ;; If this is "fetch-old-headered" and there is no
8361             ;; visible children, then we don't want this article.
8362             (and (or (eq gnus-fetch-old-headers 'some)
8363                      (numberp gnus-fetch-old-headers))
8364                  (gnus-summary-article-ancient-p number)
8365                  (zerop children))
8366             ;; If this is "fetch-old-headered" and `invisible', then
8367             ;; we don't want this article.
8368             (and (eq gnus-fetch-old-headers 'invisible)
8369                  (gnus-summary-article-ancient-p number))
8370             ;; If this is a sparsely inserted article with no children,
8371             ;; we don't want it.
8372             (and (eq gnus-build-sparse-threads 'some)
8373                  (gnus-summary-article-sparse-p number)
8374                  (zerop children))
8375             ;; If we use expunging, and this article is really
8376             ;; low-scored, then we don't want this article.
8377             (when (and gnus-summary-expunge-below
8378                        (< (setq score
8379                                 (or (cdr (assq number gnus-newsgroup-scored))
8380                                     gnus-summary-default-score))
8381                           gnus-summary-expunge-below))
8382               ;; We increase the expunge-tally here, but that has
8383               ;; nothing to do with the limits, really.
8384               (incf gnus-newsgroup-expunged-tally)
8385               ;; We also mark as read here, if that's wanted.
8386               (when (and gnus-summary-mark-below
8387                          (< score gnus-summary-mark-below))
8388                 (setq gnus-newsgroup-unreads
8389                       (delq number gnus-newsgroup-unreads))
8390                 (if gnus-newsgroup-auto-expire
8391                     (push number gnus-newsgroup-expirable)
8392                   (push (cons number gnus-low-score-mark)
8393                         gnus-newsgroup-reads)))
8394               t)
8395             ;; Do the `display' group parameter.
8396             (and gnus-newsgroup-display
8397                  (not (funcall gnus-newsgroup-display)))
8398             ;; Check NoCeM things.
8399             (when (and gnus-use-nocem
8400                        (gnus-nocem-unwanted-article-p
8401                         (mail-header-id (car thread))))
8402               (setq gnus-newsgroup-unreads
8403                     (delq number gnus-newsgroup-unreads))
8404               t)))
8405           ;; Nope, invisible article.
8406           0
8407         ;; Ok, this article is to be visible, so we add it to the limit
8408         ;; and return 1.
8409         (push number gnus-newsgroup-limit)
8410         1))))
8411
8412 (defun gnus-expunge-thread (thread)
8413   "Mark all articles in THREAD as read."
8414   (let* ((number (mail-header-number (car thread))))
8415     (incf gnus-newsgroup-expunged-tally)
8416     ;; We also mark as read here, if that's wanted.
8417     (setq gnus-newsgroup-unreads
8418           (delq number gnus-newsgroup-unreads))
8419     (if gnus-newsgroup-auto-expire
8420         (push number gnus-newsgroup-expirable)
8421       (push (cons number gnus-low-score-mark)
8422             gnus-newsgroup-reads)))
8423   ;; Go recursively through all subthreads.
8424   (mapcar 'gnus-expunge-thread (cdr thread)))
8425
8426 ;; Summary article oriented commands
8427
8428 (defun gnus-summary-refer-parent-article (n)
8429   "Refer parent article N times.
8430 If N is negative, go to ancestor -N instead.
8431 The difference between N and the number of articles fetched is returned."
8432   (interactive "p")
8433   (let ((skip 1)
8434         error header ref)
8435     (when (not (natnump n))
8436       (setq skip (abs n)
8437             n 1))
8438     (while (and (> n 0)
8439                 (not error))
8440       (setq header (gnus-summary-article-header))
8441       (if (and (eq (mail-header-number header)
8442                    (cdr gnus-article-current))
8443                (equal gnus-newsgroup-name
8444                       (car gnus-article-current)))
8445           ;; If we try to find the parent of the currently
8446           ;; displayed article, then we take a look at the actual
8447           ;; References header, since this is slightly more
8448           ;; reliable than the References field we got from the
8449           ;; server.
8450           (save-excursion
8451             (set-buffer gnus-original-article-buffer)
8452             (nnheader-narrow-to-headers)
8453             (unless (setq ref (message-fetch-field "references"))
8454               (when (setq ref (message-fetch-field "in-reply-to"))
8455                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8456             (widen))
8457         (setq ref
8458               ;; It's not the current article, so we take a bet on
8459               ;; the value we got from the server.
8460               (mail-header-references header)))
8461       (if (and ref
8462                (not (equal ref "")))
8463           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8464             (gnus-message 1 "Couldn't find parent"))
8465         (gnus-message 1 "No references in article %d"
8466                       (gnus-summary-article-number))
8467         (setq error t))
8468       (decf n))
8469     (gnus-summary-position-point)
8470     n))
8471
8472 (defun gnus-summary-refer-references ()
8473   "Fetch all articles mentioned in the References header.
8474 Return the number of articles fetched."
8475   (interactive)
8476   (let ((ref (mail-header-references (gnus-summary-article-header)))
8477         (current (gnus-summary-article-number))
8478         (n 0))
8479     (if (or (not ref)
8480             (equal ref ""))
8481         (error "No References in the current article")
8482       ;; For each Message-ID in the References header...
8483       (while (string-match "<[^>]*>" ref)
8484         (incf n)
8485         ;; ... fetch that article.
8486         (gnus-summary-refer-article
8487          (prog1 (match-string 0 ref)
8488            (setq ref (substring ref (match-end 0))))))
8489       (gnus-summary-goto-subject current)
8490       (gnus-summary-position-point)
8491       n)))
8492
8493 (defun gnus-summary-refer-thread (&optional limit)
8494   "Fetch all articles in the current thread.
8495 If LIMIT (the numerical prefix), fetch that many old headers instead
8496 of what's specified by the `gnus-refer-thread-limit' variable."
8497   (interactive "P")
8498   (let ((id (mail-header-id (gnus-summary-article-header)))
8499         (limit (if limit (prefix-numeric-value limit)
8500                  gnus-refer-thread-limit)))
8501     (unless (eq gnus-fetch-old-headers 'invisible)
8502       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8503       ;; Retrieve the headers and read them in.
8504       (if (eq (if (numberp limit)
8505                   (gnus-retrieve-headers
8506                    (list (min
8507                           (+ (mail-header-number
8508                               (gnus-summary-article-header))
8509                              limit)
8510                           gnus-newsgroup-end))
8511                    gnus-newsgroup-name (* limit 2))
8512                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8513                 ;; headers.
8514                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8515                                        gnus-newsgroup-name limit))
8516               'nov)
8517           (gnus-build-all-threads)
8518         (error "Can't fetch thread from back ends that don't support NOV"))
8519       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8520     (gnus-summary-limit-include-thread id)))
8521
8522 (defun gnus-summary-refer-article (message-id)
8523   "Fetch an article specified by MESSAGE-ID."
8524   (interactive "sMessage-ID: ")
8525   (when (and (stringp message-id)
8526              (not (zerop (length message-id))))
8527     (setq message-id (gnus-replace-in-string message-id " " ""))
8528     ;; Construct the correct Message-ID if necessary.
8529     ;; Suggested by tale@pawl.rpi.edu.
8530     (unless (string-match "^<" message-id)
8531       (setq message-id (concat "<" message-id)))
8532     (unless (string-match ">$" message-id)
8533       (setq message-id (concat message-id ">")))
8534     ;; People often post MIDs from URLs, so unhex it:
8535     (unless (string-match "@" message-id)
8536       (setq message-id (gnus-url-unhex-string message-id)))
8537     (let* ((header (gnus-id-to-header message-id))
8538            (sparse (and header
8539                         (gnus-summary-article-sparse-p
8540                          (mail-header-number header))
8541                         (memq (mail-header-number header)
8542                               gnus-newsgroup-limit)))
8543            number)
8544       (cond
8545        ;; If the article is present in the buffer we just go to it.
8546        ((and header
8547              (or (not (gnus-summary-article-sparse-p
8548                        (mail-header-number header)))
8549                  sparse))
8550         (prog1
8551             (gnus-summary-goto-article
8552              (mail-header-number header) nil t)
8553           (when sparse
8554             (gnus-summary-update-article (mail-header-number header)))))
8555        (t
8556         ;; We fetch the article.
8557         (catch 'found
8558           (dolist (gnus-override-method (gnus-refer-article-methods))
8559             (when (and (gnus-check-server gnus-override-method)
8560                        ;; Fetch the header,
8561                        (setq number (gnus-summary-insert-subject message-id)))
8562               ;; and display the article.
8563               (gnus-summary-select-article nil nil nil number)
8564               (throw 'found t)))
8565           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8566
8567 (defun gnus-refer-article-methods ()
8568   "Return a list of referable methods."
8569   (cond
8570    ;; No method, so we default to current and native.
8571    ((null gnus-refer-article-method)
8572     (list gnus-current-select-method gnus-select-method))
8573    ;; Current.
8574    ((eq 'current gnus-refer-article-method)
8575     (list gnus-current-select-method))
8576    ;; List of select methods.
8577    ((not (and (symbolp (car gnus-refer-article-method))
8578               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8579     (let (out)
8580       (dolist (method gnus-refer-article-method)
8581         (push (if (eq 'current method)
8582                   gnus-current-select-method
8583                 method)
8584               out))
8585       (nreverse out)))
8586    ;; One single select method.
8587    (t
8588     (list gnus-refer-article-method))))
8589
8590 (defun gnus-summary-edit-parameters ()
8591   "Edit the group parameters of the current group."
8592   (interactive)
8593   (gnus-group-edit-group gnus-newsgroup-name 'params))
8594
8595 (defun gnus-summary-customize-parameters ()
8596   "Customize the group parameters of the current group."
8597   (interactive)
8598   (gnus-group-customize gnus-newsgroup-name))
8599
8600 (defun gnus-summary-enter-digest-group (&optional force)
8601   "Enter an nndoc group based on the current article.
8602 If FORCE, force a digest interpretation.  If not, try
8603 to guess what the document format is."
8604   (interactive "P")
8605   (let ((conf gnus-current-window-configuration))
8606     (save-window-excursion
8607       (save-excursion
8608         (let (gnus-article-prepare-hook
8609               gnus-display-mime-function
8610               gnus-break-pages)
8611           (gnus-summary-select-article))))
8612     (setq gnus-current-window-configuration conf)
8613     (let* ((name (format "%s-%d"
8614                          (gnus-group-prefixed-name
8615                           gnus-newsgroup-name (list 'nndoc ""))
8616                          (with-current-buffer gnus-summary-buffer
8617                            gnus-current-article)))
8618            (ogroup gnus-newsgroup-name)
8619            (params (append (gnus-info-params (gnus-get-info ogroup))
8620                            (list (cons 'to-group ogroup))
8621                            (list (cons 'parent-group ogroup))
8622                            (list (cons 'save-article-group ogroup))))
8623            (case-fold-search t)
8624            (buf (current-buffer))
8625            dig to-address)
8626       (save-excursion
8627         (set-buffer gnus-original-article-buffer)
8628         ;; Have the digest group inherit the main mail address of
8629         ;; the parent article.
8630         (when (setq to-address (or (gnus-fetch-field "reply-to")
8631                                    (gnus-fetch-field "from")))
8632           (setq params (append
8633                         (list (cons 'to-address
8634                                     (funcall gnus-decode-encoded-word-function
8635                                              to-address))))))
8636         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8637         (insert-buffer-substring gnus-original-article-buffer)
8638         ;; Remove lines that may lead nndoc to misinterpret the
8639         ;; document type.
8640         (narrow-to-region
8641          (goto-char (point-min))
8642          (or (search-forward "\n\n" nil t) (point)))
8643         (goto-char (point-min))
8644         (delete-matching-lines "^Path:\\|^From ")
8645         (widen))
8646       (unwind-protect
8647           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8648                     (gnus-newsgroup-ephemeral-ignored-charsets
8649                      gnus-newsgroup-ignored-charsets))
8650                 (gnus-group-read-ephemeral-group
8651                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8652                               (nndoc-article-type
8653                                ,(if force 'mbox 'guess)))
8654                  t nil nil nil
8655                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8656                                                         "ADAPT")))))
8657               ;; Make all postings to this group go to the parent group.
8658               (nconc (gnus-info-params (gnus-get-info name))
8659                      params)
8660             ;; Couldn't select this doc group.
8661             (switch-to-buffer buf)
8662             (gnus-set-global-variables)
8663             (gnus-configure-windows 'summary)
8664             (gnus-message 3 "Article couldn't be entered?"))
8665         (kill-buffer dig)))))
8666
8667 (defun gnus-summary-read-document (n)
8668   "Open a new group based on the current article(s).
8669 This will allow you to read digests and other similar
8670 documents as newsgroups.
8671 Obeys the standard process/prefix convention."
8672   (interactive "P")
8673   (let* ((ogroup gnus-newsgroup-name)
8674          (params (append (gnus-info-params (gnus-get-info ogroup))
8675                          (list (cons 'to-group ogroup))))
8676          group egroup groups vgroup)
8677     (dolist (article (gnus-summary-work-articles n))
8678       (setq group (format "%s-%d" gnus-newsgroup-name article))
8679       (gnus-summary-remove-process-mark article)
8680       (when (gnus-summary-display-article article)
8681         (save-excursion
8682           (with-temp-buffer
8683             (insert-buffer-substring gnus-original-article-buffer)
8684             ;; Remove some headers that may lead nndoc to make
8685             ;; the wrong guess.
8686             (message-narrow-to-head)
8687             (goto-char (point-min))
8688             (delete-matching-lines "^Path:\\|^From ")
8689             (widen)
8690             (if (setq egroup
8691                       (gnus-group-read-ephemeral-group
8692                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8693                                      (nndoc-article-type guess))
8694                        t nil t))
8695                 (progn
8696             ;; Make all postings to this group go to the parent group.
8697                   (nconc (gnus-info-params (gnus-get-info egroup))
8698                          params)
8699                   (push egroup groups))
8700               ;; Couldn't select this doc group.
8701               (gnus-error 3 "Article couldn't be entered"))))))
8702     ;; Now we have selected all the documents.
8703     (cond
8704      ((not groups)
8705       (error "None of the articles could be interpreted as documents"))
8706      ((gnus-group-read-ephemeral-group
8707        (setq vgroup (format
8708                      "nnvirtual:%s-%s" gnus-newsgroup-name
8709                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8710        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8711        t
8712        (cons (current-buffer) 'summary)))
8713      (t
8714       (error "Couldn't select virtual nndoc group")))))
8715
8716 (defun gnus-summary-isearch-article (&optional regexp-p)
8717   "Do incremental search forward on the current article.
8718 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8719   (interactive "P")
8720   (gnus-summary-select-article)
8721   (gnus-configure-windows 'article)
8722   (gnus-eval-in-buffer-window gnus-article-buffer
8723     (save-restriction
8724       (widen)
8725       (isearch-forward regexp-p))))
8726
8727 (defun gnus-summary-repeat-search-article-forward ()
8728   "Repeat the previous search forwards."
8729   (interactive)
8730   (unless gnus-last-search-regexp
8731     (error "No previous search"))
8732   (gnus-summary-search-article-forward gnus-last-search-regexp))
8733
8734 (defun gnus-summary-repeat-search-article-backward ()
8735   "Repeat the previous search backwards."
8736   (interactive)
8737   (unless gnus-last-search-regexp
8738     (error "No previous search"))
8739   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8740
8741 (defun gnus-summary-search-article-forward (regexp &optional backward)
8742   "Search for an article containing REGEXP forward.
8743 If BACKWARD, search backward instead."
8744   (interactive
8745    (list (read-string
8746           (format "Search article %s (regexp%s): "
8747                   (if current-prefix-arg "backward" "forward")
8748                   (if gnus-last-search-regexp
8749                       (concat ", default " gnus-last-search-regexp)
8750                     "")))
8751          current-prefix-arg))
8752   (if (string-equal regexp "")
8753       (setq regexp (or gnus-last-search-regexp ""))
8754     (setq gnus-last-search-regexp regexp)
8755     (setq gnus-article-before-search gnus-current-article))
8756   ;; Intentionally set gnus-last-article.
8757   (setq gnus-last-article gnus-article-before-search)
8758   (let ((gnus-last-article gnus-last-article))
8759     (if (gnus-summary-search-article regexp backward)
8760         (gnus-summary-show-thread)
8761       (signal 'search-failed (list regexp)))))
8762
8763 (defun gnus-summary-search-article-backward (regexp)
8764   "Search for an article containing REGEXP backward."
8765   (interactive
8766    (list (read-string
8767           (format "Search article backward (regexp%s): "
8768                   (if gnus-last-search-regexp
8769                       (concat ", default " gnus-last-search-regexp)
8770                     "")))))
8771   (gnus-summary-search-article-forward regexp 'backward))
8772
8773 (defun gnus-summary-search-article (regexp &optional backward)
8774   "Search for an article containing REGEXP.
8775 Optional argument BACKWARD means do search for backward.
8776 `gnus-select-article-hook' is not called during the search."
8777   ;; We have to require this here to make sure that the following
8778   ;; dynamic binding isn't shadowed by autoloading.
8779   (require 'gnus-async)
8780   (require 'gnus-art)
8781   (let ((gnus-select-article-hook nil)  ;Disable hook.
8782         (gnus-article-prepare-hook nil)
8783         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8784         (gnus-use-article-prefetch nil)
8785         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8786         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8787         (gnus-visual nil)
8788         (gnus-keep-backlog nil)
8789         (gnus-break-pages nil)
8790         (gnus-summary-display-arrow nil)
8791         (gnus-updated-mode-lines nil)
8792         (gnus-auto-center-summary nil)
8793         (sum (current-buffer))
8794         (gnus-display-mime-function nil)
8795         (found nil)
8796         point)
8797     (gnus-save-hidden-threads
8798       (gnus-summary-select-article)
8799       (set-buffer gnus-article-buffer)
8800       (goto-char (window-point (get-buffer-window (current-buffer))))
8801       (when backward
8802         (forward-line -1))
8803       (while (not found)
8804         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8805         (if (if backward
8806                 (re-search-backward regexp nil t)
8807               (re-search-forward regexp nil t))
8808             ;; We found the regexp.
8809             (progn
8810               (setq found 'found)
8811               (beginning-of-line)
8812               (set-window-start
8813                (get-buffer-window (current-buffer))
8814                (point))
8815               (forward-line 1)
8816               (set-window-point
8817                (get-buffer-window (current-buffer))
8818                (point))
8819               (set-buffer sum)
8820               (setq point (point)))
8821           ;; We didn't find it, so we go to the next article.
8822           (set-buffer sum)
8823           (setq found 'not)
8824           (while (eq found 'not)
8825             (if (not (if backward (gnus-summary-find-prev)
8826                        (gnus-summary-find-next)))
8827                 ;; No more articles.
8828                 (setq found t)
8829               ;; Select the next article and adjust point.
8830               (unless (gnus-summary-article-sparse-p
8831                        (gnus-summary-article-number))
8832                 (setq found nil)
8833                 (gnus-summary-select-article)
8834                 (set-buffer gnus-article-buffer)
8835                 (widen)
8836                 (goto-char (if backward (point-max) (point-min))))))))
8837       (gnus-message 7 ""))
8838     ;; Return whether we found the regexp.
8839     (when (eq found 'found)
8840       (goto-char point)
8841       (gnus-summary-show-thread)
8842       (gnus-summary-goto-subject gnus-current-article)
8843       (gnus-summary-position-point)
8844       t)))
8845
8846 (defun gnus-find-matching-articles (header regexp)
8847   "Return a list of all articles that match REGEXP on HEADER.
8848 This search includes all articles in the current group that Gnus has
8849 fetched headers for, whether they are displayed or not."
8850   (let ((articles nil)
8851         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8852         (case-fold-search t))
8853     (dolist (header gnus-newsgroup-headers)
8854       (when (string-match regexp (funcall func header))
8855         (push (mail-header-number header) articles)))
8856     (nreverse articles)))
8857
8858 (defun gnus-summary-find-matching (header regexp &optional backward unread
8859                                           not-case-fold not-matching)
8860   "Return a list of all articles that match REGEXP on HEADER.
8861 The search stars on the current article and goes forwards unless
8862 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8863 If UNREAD is non-nil, only unread articles will
8864 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8865 in the comparisons. If NOT-MATCHING, return a list of all articles that
8866 not match REGEXP on HEADER."
8867   (let ((case-fold-search (not not-case-fold))
8868         articles d func)
8869     (if (consp header)
8870         (if (eq (car header) 'extra)
8871             (setq func
8872                   `(lambda (h)
8873                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8874                          "")))
8875           (error "%s is an invalid header" header))
8876       (unless (fboundp (intern (concat "mail-header-" header)))
8877         (error "%s is not a valid header" header))
8878       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8879     (dolist (d (if (eq backward 'all)
8880                    gnus-newsgroup-data
8881                  (gnus-data-find-list
8882                   (gnus-summary-article-number)
8883                   (gnus-data-list backward))))
8884       (when (and (or (not unread)       ; We want all articles...
8885                      (gnus-data-unread-p d)) ; Or just unreads.
8886                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8887                  (if not-matching
8888                      (not (string-match
8889                            regexp
8890                            (funcall func (gnus-data-header d))))
8891                    (string-match regexp
8892                                  (funcall func (gnus-data-header d)))))
8893         (push (gnus-data-number d) articles))) ; Success!
8894     (nreverse articles)))
8895
8896 (defun gnus-summary-execute-command (header regexp command &optional backward)
8897   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8898 If HEADER is an empty string (or nil), the match is done on the entire
8899 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8900   (interactive
8901    (list (let ((completion-ignore-case t))
8902            (completing-read
8903             "Header name: "
8904             (mapcar (lambda (header) (list (format "%s" header)))
8905                     (append
8906                      '("Number" "Subject" "From" "Lines" "Date"
8907                        "Message-ID" "Xref" "References" "Body")
8908                      gnus-extra-headers))
8909             nil 'require-match))
8910          (read-string "Regexp: ")
8911          (read-key-sequence "Command: ")
8912          current-prefix-arg))
8913   (when (equal header "Body")
8914     (setq header ""))
8915   ;; Hidden thread subtrees must be searched as well.
8916   (gnus-summary-show-all-threads)
8917   ;; We don't want to change current point nor window configuration.
8918   (save-excursion
8919     (save-window-excursion
8920       (let (gnus-visual
8921             gnus-treat-strip-trailing-blank-lines
8922             gnus-treat-strip-leading-blank-lines
8923             gnus-treat-strip-multiple-blank-lines
8924             gnus-treat-hide-boring-headers
8925             gnus-treat-fold-newsgroups
8926             gnus-article-prepare-hook)
8927         (gnus-message 6 "Executing %s..." (key-description command))
8928         ;; We'd like to execute COMMAND interactively so as to give arguments.
8929         (gnus-execute header regexp
8930                       `(call-interactively ',(key-binding command))
8931                       backward)
8932         (gnus-message 6 "Executing %s...done" (key-description command))))))
8933
8934 (defun gnus-summary-beginning-of-article ()
8935   "Scroll the article back to the beginning."
8936   (interactive)
8937   (gnus-summary-select-article)
8938   (gnus-configure-windows 'article)
8939   (gnus-eval-in-buffer-window gnus-article-buffer
8940     (widen)
8941     (goto-char (point-min))
8942     (when gnus-break-pages
8943       (gnus-narrow-to-page))))
8944
8945 (defun gnus-summary-end-of-article ()
8946   "Scroll to the end of the article."
8947   (interactive)
8948   (gnus-summary-select-article)
8949   (gnus-configure-windows 'article)
8950   (gnus-eval-in-buffer-window gnus-article-buffer
8951     (widen)
8952     (goto-char (point-max))
8953     (recenter -3)
8954     (when gnus-break-pages
8955       (when (re-search-backward page-delimiter nil t)
8956         (narrow-to-region (match-end 0) (point-max)))
8957       (gnus-narrow-to-page))))
8958
8959 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8960   "Truncate to LEN and quote all \"(\"'s in STRING."
8961   (gnus-replace-in-string (if (and len (> (length string) len))
8962                               (substring string 0 len)
8963                             string)
8964                           "[()]" "\\\\\\&"))
8965
8966 (defun gnus-summary-print-article (&optional filename n)
8967   "Generate and print a PostScript image of the process-marked (mail) articles.
8968
8969 If used interactively, print the current article if none are
8970 process-marked.  With prefix arg, prompt the user for the name of the
8971 file to save in.
8972
8973 When used from Lisp, accept two optional args FILENAME and N.  N means
8974 to print the next N articles.  If N is negative, print the N previous
8975 articles.  If N is nil and articles have been marked with the process
8976 mark, print these instead.
8977
8978 If the optional first argument FILENAME is nil, send the image to the
8979 printer.  If FILENAME is a string, save the PostScript image in a file with
8980 that name.  If FILENAME is a number, prompt the user for the name of the file
8981 to save in."
8982   (interactive (list (ps-print-preprint current-prefix-arg)))
8983   (dolist (article (gnus-summary-work-articles n))
8984     (gnus-summary-select-article nil nil 'pseudo article)
8985     (gnus-eval-in-buffer-window gnus-article-buffer
8986       (gnus-print-buffer))
8987     (gnus-summary-remove-process-mark article))
8988   (ps-despool filename))
8989
8990 (defun gnus-print-buffer ()
8991   (let ((buffer (generate-new-buffer " *print*")))
8992     (unwind-protect
8993         (progn
8994           (copy-to-buffer buffer (point-min) (point-max))
8995           (set-buffer buffer)
8996           (gnus-remove-text-with-property 'gnus-decoration)
8997           (when (gnus-visual-p 'article-highlight 'highlight)
8998             ;; Copy-to-buffer doesn't copy overlay.  So redo
8999             ;; highlight.
9000             (let ((gnus-article-buffer buffer))
9001               (gnus-article-highlight-citation t)
9002               (gnus-article-highlight-signature)
9003               (gnus-article-emphasize)
9004               (gnus-article-delete-invisible-text)))
9005           (let ((ps-left-header
9006                  (list
9007                   (concat "("
9008                           (gnus-summary-print-truncate-and-quote
9009                            (mail-header-subject gnus-current-headers)
9010                            66) ")")
9011                   (concat "("
9012                           (gnus-summary-print-truncate-and-quote
9013                            (mail-header-from gnus-current-headers)
9014                            45) ")")))
9015                 (ps-right-header
9016                  (list
9017                   "/pagenumberstring load"
9018                   (concat "("
9019                           (mail-header-date gnus-current-headers) ")"))))
9020             (gnus-run-hooks 'gnus-ps-print-hook)
9021             (save-excursion
9022               (if window-system
9023                   (ps-spool-buffer-with-faces)
9024                 (ps-spool-buffer)))))
9025       (kill-buffer buffer))))
9026
9027 (defun gnus-summary-show-article (&optional arg)
9028   "Force redisplaying of the current article.
9029 If ARG (the prefix) is a number, show the article with the charset
9030 defined in `gnus-summary-show-article-charset-alist', or the charset
9031 input.
9032 If ARG (the prefix) is non-nil and not a number, show the raw article
9033 without any article massaging functions being run.  Normally, the key
9034 strokes are `C-u g'."
9035   (interactive "P")
9036   (cond
9037    ((numberp arg)
9038     (gnus-summary-show-article t)
9039     (let ((gnus-newsgroup-charset
9040            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9041                (mm-read-coding-system
9042                 "View as charset: " ;; actually it is coding system.
9043                 (with-current-buffer gnus-article-buffer
9044                   (mm-detect-coding-region (point) (point-max))))))
9045           (gnus-newsgroup-ignored-charsets 'gnus-all))
9046       (gnus-summary-select-article nil 'force)
9047       (let ((deps gnus-newsgroup-dependencies)
9048             head header lines)
9049         (save-excursion
9050           (set-buffer gnus-original-article-buffer)
9051           (save-restriction
9052             (message-narrow-to-head)
9053             (setq head (buffer-string))
9054             (goto-char (point-min))
9055             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9056               (goto-char (point-max))
9057               (widen)
9058               (setq lines (1- (count-lines (point) (point-max))))))
9059           (with-temp-buffer
9060             (insert (format "211 %d Article retrieved.\n"
9061                             (cdr gnus-article-current)))
9062             (insert head)
9063             (if lines (insert (format "Lines: %d\n" lines)))
9064             (insert ".\n")
9065             (let ((nntp-server-buffer (current-buffer)))
9066               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9067         (gnus-data-set-header
9068          (gnus-data-find (cdr gnus-article-current))
9069          header)
9070         (gnus-summary-update-article-line
9071          (cdr gnus-article-current) header)
9072         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9073           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9074    ((not arg)
9075     ;; Select the article the normal way.
9076     (gnus-summary-select-article nil 'force))
9077    (t
9078     ;; We have to require this here to make sure that the following
9079     ;; dynamic binding isn't shadowed by autoloading.
9080     (require 'gnus-async)
9081     (require 'gnus-art)
9082     ;; Bind the article treatment functions to nil.
9083     (let ((gnus-have-all-headers t)
9084           gnus-article-prepare-hook
9085           gnus-article-decode-hook
9086           gnus-display-mime-function
9087           gnus-break-pages)
9088       ;; Destroy any MIME parts.
9089       (when (gnus-buffer-live-p gnus-article-buffer)
9090         (save-excursion
9091           (set-buffer gnus-article-buffer)
9092           (mm-destroy-parts gnus-article-mime-handles)
9093           ;; Set it to nil for safety reason.
9094           (setq gnus-article-mime-handle-alist nil)
9095           (setq gnus-article-mime-handles nil)))
9096       (gnus-summary-select-article nil 'force))))
9097   (gnus-summary-goto-subject gnus-current-article)
9098   (gnus-summary-position-point))
9099
9100 (defun gnus-summary-show-raw-article ()
9101   "Show the raw article without any article massaging functions being run."
9102   (interactive)
9103   (gnus-summary-show-article t))
9104
9105 (defun gnus-summary-verbose-headers (&optional arg)
9106   "Toggle permanent full header display.
9107 If ARG is a positive number, turn header display on.
9108 If ARG is a negative number, turn header display off."
9109   (interactive "P")
9110   (setq gnus-show-all-headers
9111         (cond ((or (not (numberp arg))
9112                    (zerop arg))
9113                (not gnus-show-all-headers))
9114               ((natnump arg)
9115                t)))
9116   (gnus-summary-show-article))
9117
9118 (defun gnus-summary-toggle-header (&optional arg)
9119   "Show the headers if they are hidden, or hide them if they are shown.
9120 If ARG is a positive number, show the entire header.
9121 If ARG is a negative number, hide the unwanted header lines."
9122   (interactive "P")
9123   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9124                      (get-buffer-window gnus-article-buffer t))))
9125     (with-current-buffer gnus-article-buffer
9126       (widen)
9127       (article-narrow-to-head)
9128       (let* ((buffer-read-only nil)
9129              (inhibit-point-motion-hooks t)
9130              (hidden (if (numberp arg)
9131                          (>= arg 0)
9132                        (or (not (looking-at "[^ \t\n]+:"))
9133                            (gnus-article-hidden-text-p 'headers))))
9134              s e)
9135         (delete-region (point-min) (point-max))
9136         (with-current-buffer gnus-original-article-buffer
9137           (goto-char (setq s (point-min)))
9138           (setq e (if (search-forward "\n\n" nil t)
9139                       (1- (point))
9140                     (point-max))))
9141         (insert-buffer-substring gnus-original-article-buffer s e)
9142         (run-hooks 'gnus-article-decode-hook)
9143         (if hidden
9144             (let ((gnus-treat-hide-headers nil)
9145                   (gnus-treat-hide-boring-headers nil))
9146               (gnus-delete-wash-type 'headers)
9147               (gnus-treat-article 'head))
9148           (gnus-treat-article 'head))
9149         (widen)
9150         (if window
9151             (set-window-start window (goto-char (point-min))))
9152         (if gnus-break-pages
9153             (gnus-narrow-to-page)
9154           (when (gnus-visual-p 'page-marker)
9155             (let ((buffer-read-only nil))
9156               (gnus-remove-text-with-property 'gnus-prev)
9157               (gnus-remove-text-with-property 'gnus-next))))
9158         (gnus-set-mode-line 'article)))))
9159
9160 (defun gnus-summary-show-all-headers ()
9161   "Make all header lines visible."
9162   (interactive)
9163   (gnus-summary-toggle-header 1))
9164
9165 (defun gnus-summary-caesar-message (&optional arg)
9166   "Caesar rotate the current article by 13.
9167 The numerical prefix specifies how many places to rotate each letter
9168 forward."
9169   (interactive "P")
9170   (gnus-summary-select-article)
9171   (let ((mail-header-separator ""))
9172     (gnus-eval-in-buffer-window gnus-article-buffer
9173       (save-restriction
9174         (widen)
9175         (let ((start (window-start))
9176               buffer-read-only)
9177           (message-caesar-buffer-body arg)
9178           (set-window-start (get-buffer-window (current-buffer)) start)))))
9179   ;; Create buttons and stuff...
9180   (gnus-treat-article nil))
9181
9182 (defun gnus-summary-idna-message (&optional arg)
9183   "Decode IDNA encoded domain names in the current articles.
9184 IDNA encoded domain names looks like `xn--bar'.  If a string
9185 remain unencoded after running this function, it is likely an
9186 invalid IDNA string (`xn--bar' is invalid).
9187
9188 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9189 installed for this command to work."
9190   (interactive "P")
9191   (if (not (and (condition-case nil (require 'idna)
9192                   (file-error))
9193                 (mm-coding-system-p 'utf-8)
9194                 (executable-find (symbol-value 'idna-program))))
9195       (gnus-message
9196        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9197     (gnus-summary-select-article)
9198     (let ((mail-header-separator ""))
9199       (gnus-eval-in-buffer-window gnus-article-buffer
9200         (save-restriction
9201           (widen)
9202           (let ((start (window-start))
9203                 buffer-read-only)
9204             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9205               (replace-match (idna-to-unicode (match-string 1))))
9206             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9207
9208 (defun gnus-summary-morse-message (&optional arg)
9209   "Morse decode the current article."
9210   (interactive "P")
9211   (gnus-summary-select-article)
9212   (let ((mail-header-separator ""))
9213     (gnus-eval-in-buffer-window gnus-article-buffer
9214       (save-excursion
9215         (save-restriction
9216           (widen)
9217           (let ((pos (window-start))
9218                 buffer-read-only)
9219             (goto-char (point-min))
9220             (when (message-goto-body)
9221               (gnus-narrow-to-body))
9222             (goto-char (point-min))
9223             (while (search-forward "·" (point-max) t)
9224               (replace-match "."))
9225             (unmorse-region (point-min) (point-max))
9226             (widen)
9227             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9228
9229 (defun gnus-summary-stop-page-breaking ()
9230   "Stop page breaking in the current article."
9231   (interactive)
9232   (gnus-summary-select-article)
9233   (gnus-eval-in-buffer-window gnus-article-buffer
9234     (widen)
9235     (when (gnus-visual-p 'page-marker)
9236       (let ((buffer-read-only nil))
9237         (gnus-remove-text-with-property 'gnus-prev)
9238         (gnus-remove-text-with-property 'gnus-next))
9239       (setq gnus-page-broken nil))))
9240
9241 (defun gnus-summary-move-article (&optional n to-newsgroup
9242                                             select-method action)
9243   "Move the current article to a different newsgroup.
9244 If N is a positive number, move the N next articles.
9245 If N is a negative number, move the N previous articles.
9246 If N is nil and any articles have been marked with the process mark,
9247 move those articles instead.
9248 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9249 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9250 re-spool using this method.
9251
9252 When called interactively with TO-NEWSGROUP being nil, the value of
9253 the variable `gnus-move-split-methods' is used for finding a default
9254 for the target newsgroup.
9255
9256 For this function to work, both the current newsgroup and the
9257 newsgroup that you want to move to have to support the `request-move'
9258 and `request-accept' functions.
9259
9260 ACTION can be either `move' (the default), `crosspost' or `copy'."
9261   (interactive "P")
9262   (unless action
9263     (setq action 'move))
9264   ;; Check whether the source group supports the required functions.
9265   (cond ((and (eq action 'move)
9266               (not (gnus-check-backend-function
9267                     'request-move-article gnus-newsgroup-name)))
9268          (error "The current group does not support article moving"))
9269         ((and (eq action 'crosspost)
9270               (not (gnus-check-backend-function
9271                     'request-replace-article gnus-newsgroup-name)))
9272          (error "The current group does not support article editing")))
9273   (let ((articles (gnus-summary-work-articles n))
9274         (prefix (if (gnus-check-backend-function
9275                      'request-move-article gnus-newsgroup-name)
9276                     (funcall gnus-move-group-prefix-function
9277                              gnus-newsgroup-name)
9278                   ""))
9279         (names '((move "Move" "Moving")
9280                  (copy "Copy" "Copying")
9281                  (crosspost "Crosspost" "Crossposting")))
9282         (copy-buf (save-excursion
9283                     (nnheader-set-temp-buffer " *copy article*")))
9284         art-group to-method new-xref article to-groups articles-to-update-marks)
9285     (unless (assq action names)
9286       (error "Unknown action %s" action))
9287     ;; Read the newsgroup name.
9288     (when (and (not to-newsgroup)
9289                (not select-method))
9290       (if (and gnus-move-split-methods
9291                (not
9292                 (and (memq gnus-current-article articles)
9293                      (gnus-buffer-live-p gnus-original-article-buffer))))
9294           ;; When `gnus-move-split-methods' is non-nil, we have to
9295           ;; select an article to give `gnus-read-move-group-name' an
9296           ;; opportunity to suggest an appropriate default.  However,
9297           ;; we needn't render or mark the article.
9298           (let ((gnus-display-mime-function nil)
9299                 (gnus-article-prepare-hook nil)
9300                 (gnus-mark-article-hook nil))
9301             (gnus-summary-select-article nil nil nil (car articles))))
9302       (setq to-newsgroup
9303             (gnus-read-move-group-name
9304              (cadr (assq action names))
9305              (symbol-value (intern (format "gnus-current-%s-group" action)))
9306              articles prefix))
9307       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9308     (setq to-method (or select-method
9309                         (gnus-server-to-method
9310                          (gnus-group-method to-newsgroup))))
9311     ;; Check the method we are to move this article to...
9312     (unless (gnus-check-backend-function
9313              'request-accept-article (car to-method))
9314       (error "%s does not support article copying" (car to-method)))
9315     (unless (gnus-check-server to-method)
9316       (error "Can't open server %s" (car to-method)))
9317     (gnus-message 6 "%s to %s: %s..."
9318                   (caddr (assq action names))
9319                   (or (car select-method) to-newsgroup) articles)
9320     (while articles
9321       (setq article (pop articles))
9322       (setq
9323        art-group
9324        (cond
9325         ;; Move the article.
9326         ((eq action 'move)
9327          ;; Remove this article from future suppression.
9328          (gnus-dup-unsuppress-article article)
9329          (let* ((from-method (gnus-find-method-for-group
9330                               gnus-newsgroup-name))
9331                 (to-method (gnus-find-method-for-group
9332                             to-newsgroup))
9333                 (move-is-internal (gnus-method-equal from-method to-method)))
9334          (gnus-request-move-article
9335           article                       ; Article to move
9336           gnus-newsgroup-name           ; From newsgroup
9337           (nth 1 (gnus-find-method-for-group
9338                   gnus-newsgroup-name)) ; Server
9339           (list 'gnus-request-accept-article
9340                 to-newsgroup (list 'quote select-method)
9341                 (not articles) t)       ; Accept form
9342           (not articles)                ; Only save nov last time
9343           move-is-internal)))           ; is this move internal?
9344         ;; Copy the article.
9345         ((eq action 'copy)
9346          (save-excursion
9347            (set-buffer copy-buf)
9348            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9349              (save-restriction
9350                (nnheader-narrow-to-headers)
9351                (dolist (hdr gnus-copy-article-ignored-headers)
9352                  (message-remove-header hdr t)))
9353              (gnus-request-accept-article
9354               to-newsgroup select-method (not articles) t))))
9355         ;; Crosspost the article.
9356         ((eq action 'crosspost)
9357          (let ((xref (message-tokenize-header
9358                       (mail-header-xref (gnus-summary-article-header article))
9359                       " ")))
9360            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9361                                   ":" (number-to-string article)))
9362            (unless xref
9363              (setq xref (list (system-name))))
9364            (setq new-xref
9365                  (concat
9366                   (mapconcat 'identity
9367                              (delete "Xref:" (delete new-xref xref))
9368                              " ")
9369                   " " new-xref))
9370            (save-excursion
9371              (set-buffer copy-buf)
9372              ;; First put the article in the destination group.
9373              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9374              (when (consp (setq art-group
9375                                 (gnus-request-accept-article
9376                                  to-newsgroup select-method (not articles))))
9377                (setq new-xref (concat new-xref " " (car art-group)
9378                                       ":"
9379                                       (number-to-string (cdr art-group))))
9380                ;; Now we have the new Xrefs header, so we insert
9381                ;; it and replace the new article.
9382                (nnheader-replace-header "Xref" new-xref)
9383                (gnus-request-replace-article
9384                 (cdr art-group) to-newsgroup (current-buffer))
9385                art-group))))))
9386       (cond
9387        ((not art-group)
9388         (gnus-message 1 "Couldn't %s article %s: %s"
9389                       (cadr (assq action names)) article
9390                       (nnheader-get-report (car to-method))))
9391        ((eq art-group 'junk)
9392         (when (eq action 'move)
9393           (gnus-summary-mark-article article gnus-canceled-mark)
9394           (gnus-message 4 "Deleted article %s" article)
9395           ;; run the delete hook
9396           (run-hook-with-args 'gnus-summary-article-delete-hook
9397                               action
9398                               (gnus-data-header
9399                                (assoc article (gnus-data-list nil)))
9400                               gnus-newsgroup-name nil
9401                               select-method)))
9402        (t
9403         (let* ((pto-group (gnus-group-prefixed-name
9404                            (car art-group) to-method))
9405                (info (gnus-get-info pto-group))
9406                (to-group (gnus-info-group info))
9407                to-marks)
9408           ;; Update the group that has been moved to.
9409           (when (and info
9410                      (memq action '(move copy)))
9411             (unless (member to-group to-groups)
9412               (push to-group to-groups))
9413
9414             (unless (memq article gnus-newsgroup-unreads)
9415               (push 'read to-marks)
9416               (gnus-info-set-read
9417                info (gnus-add-to-range (gnus-info-read info)
9418                                        (list (cdr art-group)))))
9419
9420             ;; See whether the article is to be put in the cache.
9421             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9422                              gnus-article-mark-lists
9423                            (delete '(expirable . expire)
9424                                    (copy-sequence gnus-article-mark-lists))))
9425                   (to-article (cdr art-group)))
9426
9427               ;; Enter the article into the cache in the new group,
9428               ;; if that is required.
9429               (when gnus-use-cache
9430                 (gnus-cache-possibly-enter-article
9431                  to-group to-article
9432                  (memq article gnus-newsgroup-marked)
9433                  (memq article gnus-newsgroup-dormant)
9434                  (memq article gnus-newsgroup-unreads)))
9435
9436               (when gnus-preserve-marks
9437                 ;; Copy any marks over to the new group.
9438                 (when (and (equal to-group gnus-newsgroup-name)
9439                            (not (memq article gnus-newsgroup-unreads)))
9440                   ;; Mark this article as read in this group.
9441                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9442                   (setcdr (gnus-active to-group) to-article)
9443                   (setcdr gnus-newsgroup-active to-article))
9444
9445                 (while marks
9446                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9447                     (when (memq article (symbol-value
9448                                          (intern (format "gnus-newsgroup-%s"
9449                                                          (caar marks)))))
9450                       (push (cdar marks) to-marks)
9451                       ;; If the other group is the same as this group,
9452                       ;; then we have to add the mark to the list.
9453                       (when (equal to-group gnus-newsgroup-name)
9454                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9455                              (cons to-article
9456                                    (symbol-value
9457                                     (intern (format "gnus-newsgroup-%s"
9458                                                     (caar marks)))))))
9459                       ;; Copy the marks to other group.
9460                       (gnus-add-marked-articles
9461                        to-group (cdar marks) (list to-article) info)))
9462                   (setq marks (cdr marks)))
9463
9464                 (gnus-request-set-mark
9465                  to-group (list (list (list to-article) 'add to-marks))))
9466
9467               (gnus-dribble-enter
9468                (concat "(gnus-group-set-info '"
9469                        (gnus-prin1-to-string (gnus-get-info to-group))
9470                        ")"))))
9471
9472           ;; Update the Xref header in this article to point to
9473           ;; the new crossposted article we have just created.
9474           (when (eq action 'crosspost)
9475             (save-excursion
9476               (set-buffer copy-buf)
9477               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9478               (nnheader-replace-header "Xref" new-xref)
9479               (gnus-request-replace-article
9480                article gnus-newsgroup-name (current-buffer))))
9481
9482           ;; run the move/copy/crosspost/respool hook
9483           (run-hook-with-args 'gnus-summary-article-move-hook
9484                               action
9485                               (gnus-data-header
9486                                (assoc article (gnus-data-list nil)))
9487                               gnus-newsgroup-name
9488                               to-newsgroup
9489                               select-method))
9490
9491         ;;;!!!Why is this necessary?
9492         (set-buffer gnus-summary-buffer)
9493         
9494         (gnus-summary-goto-subject article)
9495         (when (eq action 'move)
9496           (gnus-summary-mark-article article gnus-canceled-mark))))
9497       (push article articles-to-update-marks))
9498
9499     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9500     ;; Re-activate all groups that have been moved to.
9501     (save-excursion
9502       (set-buffer gnus-group-buffer)
9503       (let ((gnus-group-marked to-groups))
9504         (gnus-group-get-new-news-this-group nil t)))
9505     
9506     (gnus-kill-buffer copy-buf)
9507     (gnus-summary-position-point)
9508     (gnus-set-mode-line 'summary)))
9509
9510 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9511   "Copy the current article to some other group.
9512 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9513 When called interactively, if TO-NEWSGROUP is nil, use the value of
9514 the variable `gnus-move-split-methods' for finding a default target
9515 newsgroup.
9516 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9517 re-spool using this method."
9518   (interactive "P")
9519   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9520
9521 (defun gnus-summary-crosspost-article (&optional n)
9522   "Crosspost the current article to some other group."
9523   (interactive "P")
9524   (gnus-summary-move-article n nil nil 'crosspost))
9525
9526 (defcustom gnus-summary-respool-default-method nil
9527   "Default method type for respooling an article.
9528 If nil, use to the current newsgroup method."
9529   :type 'symbol
9530   :group 'gnus-summary-mail)
9531
9532 (defcustom gnus-summary-display-while-building nil
9533   "If non-nil, show and update the summary buffer as it's being built.
9534 If the value is t, update the buffer after every line is inserted.  If
9535 the value is an integer (N), update the display every N lines."
9536   :version "22.1"
9537   :group 'gnus-thread
9538   :type '(choice (const :tag "off" nil)
9539                  number
9540                  (const :tag "frequently" t)))
9541
9542 (defun gnus-summary-respool-article (&optional n method)
9543   "Respool the current article.
9544 The article will be squeezed through the mail spooling process again,
9545 which means that it will be put in some mail newsgroup or other
9546 depending on `nnmail-split-methods'.
9547 If N is a positive number, respool the N next articles.
9548 If N is a negative number, respool the N previous articles.
9549 If N is nil and any articles have been marked with the process mark,
9550 respool those articles instead.
9551
9552 Respooling can be done both from mail groups and \"real\" newsgroups.
9553 In the former case, the articles in question will be moved from the
9554 current group into whatever groups they are destined to.  In the
9555 latter case, they will be copied into the relevant groups."
9556   (interactive
9557    (list current-prefix-arg
9558          (let* ((methods (gnus-methods-using 'respool))
9559                 (methname
9560                  (symbol-name (or gnus-summary-respool-default-method
9561                                   (car (gnus-find-method-for-group
9562                                         gnus-newsgroup-name)))))
9563                 (method
9564                  (gnus-completing-read-with-default
9565                   methname "Backend to use when respooling"
9566                   methods nil t nil 'gnus-mail-method-history))
9567                 ms)
9568            (cond
9569             ((zerop (length (setq ms (gnus-servers-using-backend
9570                                       (intern method)))))
9571              (list (intern method) ""))
9572             ((= 1 (length ms))
9573              (car ms))
9574             (t
9575              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9576                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9577                            ms-alist))))))))
9578   (unless method
9579     (error "No method given for respooling"))
9580   (if (assoc (symbol-name
9581               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9582              (gnus-methods-using 'respool))
9583       (gnus-summary-move-article n nil method)
9584     (gnus-summary-copy-article n nil method)))
9585
9586 (defun gnus-summary-import-article (file &optional edit)
9587   "Import an arbitrary file into a mail newsgroup."
9588   (interactive "fImport file: \nP")
9589   (let ((group gnus-newsgroup-name)
9590         (now (current-time))
9591         atts lines group-art)
9592     (unless (gnus-check-backend-function 'request-accept-article group)
9593       (error "%s does not support article importing" group))
9594     (or (file-readable-p file)
9595         (not (file-regular-p file))
9596         (error "Can't read %s" file))
9597     (save-excursion
9598       (set-buffer (gnus-get-buffer-create " *import file*"))
9599       (erase-buffer)
9600       (nnheader-insert-file-contents file)
9601       (goto-char (point-min))
9602       (if (nnheader-article-p)
9603           (save-restriction
9604             (goto-char (point-min))
9605             (search-forward "\n\n" nil t)
9606             (narrow-to-region (point-min) (1- (point)))
9607             (goto-char (point-min))
9608             (unless (re-search-forward "^date:" nil t)
9609               (goto-char (point-max))
9610               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9611        ;; This doesn't look like an article, so we fudge some headers.
9612         (setq atts (file-attributes file)
9613               lines (count-lines (point-min) (point-max)))
9614         (insert "From: " (read-string "From: ") "\n"
9615                 "Subject: " (read-string "Subject: ") "\n"
9616                 "Date: " (message-make-date (nth 5 atts)) "\n"
9617                 "Message-ID: " (message-make-message-id) "\n"
9618                 "Lines: " (int-to-string lines) "\n"
9619                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9620       (setq group-art (gnus-request-accept-article group nil t))
9621       (kill-buffer (current-buffer)))
9622     (setq gnus-newsgroup-active (gnus-activate-group group))
9623     (forward-line 1)
9624     (gnus-summary-goto-article (cdr group-art) nil t)
9625     (when edit
9626       (gnus-summary-edit-article))))
9627
9628 (defun gnus-summary-create-article ()
9629   "Create an article in a mail newsgroup."
9630   (interactive)
9631   (let ((group gnus-newsgroup-name)
9632         (now (current-time))
9633         group-art)
9634     (unless (gnus-check-backend-function 'request-accept-article group)
9635       (error "%s does not support article importing" group))
9636     (save-excursion
9637       (set-buffer (gnus-get-buffer-create " *import file*"))
9638       (erase-buffer)
9639       (goto-char (point-min))
9640       ;; This doesn't look like an article, so we fudge some headers.
9641       (insert "From: " (read-string "From: ") "\n"
9642               "Subject: " (read-string "Subject: ") "\n"
9643               "Date: " (message-make-date now) "\n"
9644               "Message-ID: " (message-make-message-id) "\n")
9645       (setq group-art (gnus-request-accept-article group nil t))
9646       (kill-buffer (current-buffer)))
9647     (setq gnus-newsgroup-active (gnus-activate-group group))
9648     (forward-line 1)
9649     (gnus-summary-goto-article (cdr group-art) nil t)
9650     (gnus-summary-edit-article)))
9651
9652 (defun gnus-summary-article-posted-p ()
9653   "Say whether the current (mail) article is available from news as well.
9654 This will be the case if the article has both been mailed and posted."
9655   (interactive)
9656   (let ((id (mail-header-references (gnus-summary-article-header)))
9657         (gnus-override-method (car (gnus-refer-article-methods))))
9658     (if (gnus-request-head id "")
9659         (gnus-message 2 "The current message was found on %s"
9660                       gnus-override-method)
9661       (gnus-message 2 "The current message couldn't be found on %s"
9662                     gnus-override-method)
9663       nil)))
9664
9665 (defun gnus-summary-expire-articles (&optional now)
9666   "Expire all articles that are marked as expirable in the current group."
9667   (interactive)
9668   (when (and (not gnus-group-is-exiting-without-update-p)
9669              (gnus-check-backend-function
9670               'request-expire-articles gnus-newsgroup-name))
9671     ;; This backend supports expiry.
9672     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9673            (expirable (if total
9674                           (progn
9675                             ;; We need to update the info for
9676                             ;; this group for `gnus-list-of-read-articles'
9677                             ;; to give us the right answer.
9678                             (gnus-run-hooks 'gnus-exit-group-hook)
9679                             (gnus-summary-update-info)
9680                             (gnus-list-of-read-articles gnus-newsgroup-name))
9681                         (setq gnus-newsgroup-expirable
9682                               (sort gnus-newsgroup-expirable '<))))
9683            (expiry-wait (if now 'immediate
9684                           (gnus-group-find-parameter
9685                            gnus-newsgroup-name 'expiry-wait)))
9686            (nnmail-expiry-target
9687             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9688                 nnmail-expiry-target))
9689            es)
9690       (when expirable
9691         ;; There are expirable articles in this group, so we run them
9692         ;; through the expiry process.
9693         (gnus-message 6 "Expiring articles...")
9694         (unless (gnus-check-group gnus-newsgroup-name)
9695           (error "Can't open server for %s" gnus-newsgroup-name))
9696         ;; The list of articles that weren't expired is returned.
9697         (save-excursion
9698           (if expiry-wait
9699               (let ((nnmail-expiry-wait-function nil)
9700                     (nnmail-expiry-wait expiry-wait))
9701                 (setq es (gnus-request-expire-articles
9702                           expirable gnus-newsgroup-name)))
9703             (setq es (gnus-request-expire-articles
9704                       expirable gnus-newsgroup-name)))
9705           (unless total
9706             (setq gnus-newsgroup-expirable es))
9707           ;; We go through the old list of expirable, and mark all
9708           ;; really expired articles as nonexistent.
9709           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9710             (let ((gnus-use-cache nil))
9711               (dolist (article expirable)
9712                 (when (and (not (memq article es))
9713                            (gnus-data-find article))
9714                   (gnus-summary-mark-article article gnus-canceled-mark)
9715                   (run-hook-with-args 'gnus-summary-article-expire-hook
9716                                       'delete
9717                                       (gnus-data-header
9718                                        (assoc article (gnus-data-list nil)))
9719                                       gnus-newsgroup-name
9720                                       nil
9721                                       nil))))))
9722         (gnus-message 6 "Expiring articles...done")))))
9723
9724 (defun gnus-summary-expire-articles-now ()
9725   "Expunge all expirable articles in the current group.
9726 This means that *all* articles that are marked as expirable will be
9727 deleted forever, right now."
9728   (interactive)
9729   (or gnus-expert-user
9730       (gnus-yes-or-no-p
9731        "Are you really, really sure you want to delete all expirable messages? ")
9732       (error "Phew!"))
9733   (gnus-summary-expire-articles t))
9734
9735 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9736 (defun gnus-summary-delete-article (&optional n)
9737   "Delete the N next (mail) articles.
9738 This command actually deletes articles.  This is not a marking
9739 command.  The article will disappear forever from your life, never to
9740 return.
9741
9742 If N is negative, delete backwards.
9743 If N is nil and articles have been marked with the process mark,
9744 delete these instead.
9745
9746 If `gnus-novice-user' is non-nil you will be asked for
9747 confirmation before the articles are deleted."
9748   (interactive "P")
9749   (unless (gnus-check-backend-function 'request-expire-articles
9750                                        gnus-newsgroup-name)
9751     (error "The current newsgroup does not support article deletion"))
9752   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9753     (error "Couldn't open server"))
9754   ;; Compute the list of articles to delete.
9755   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9756         (nnmail-expiry-target 'delete)
9757         not-deleted)
9758     (if (and gnus-novice-user
9759              (not (gnus-yes-or-no-p
9760                    (format "Do you really want to delete %s forever? "
9761                            (if (> (length articles) 1)
9762                                (format "these %s articles" (length articles))
9763                              "this article")))))
9764         ()
9765       ;; Delete the articles.
9766       (setq not-deleted (gnus-request-expire-articles
9767                          articles gnus-newsgroup-name 'force))
9768       (while articles
9769         (gnus-summary-remove-process-mark (car articles))
9770         ;; The backend might not have been able to delete the article
9771         ;; after all.
9772         (unless (memq (car articles) not-deleted)
9773           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9774         (let* ((article (car articles))
9775                (ghead  (gnus-data-header
9776                                     (assoc article (gnus-data-list nil)))))
9777           (run-hook-with-args 'gnus-summary-article-delete-hook
9778                               'delete ghead gnus-newsgroup-name nil
9779                               nil))
9780         (setq articles (cdr articles)))
9781       (when not-deleted
9782         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9783     (gnus-summary-position-point)
9784     (gnus-set-mode-line 'summary)
9785     not-deleted))
9786
9787 (defun gnus-summary-edit-article (&optional arg)
9788   "Edit the current article.
9789 This will have permanent effect only in mail groups.
9790 If ARG is nil, edit the decoded articles.
9791 If ARG is 1, edit the raw articles.
9792 If ARG is 2, edit the raw articles even in read-only groups.
9793 If ARG is 3, edit the articles with the current handles.
9794 Otherwise, allow editing of articles even in read-only
9795 groups."
9796   (interactive "P")
9797   (let (force raw current-handles)
9798     (cond
9799      ((null arg))
9800      ((eq arg 1)
9801       (setq raw t))
9802      ((eq arg 2)
9803       (setq raw t
9804             force t))
9805      ((eq arg 3)
9806       (setq current-handles
9807             (and (gnus-buffer-live-p gnus-article-buffer)
9808                  (with-current-buffer gnus-article-buffer
9809                    (prog1
9810                        gnus-article-mime-handles
9811                      (setq gnus-article-mime-handles nil))))))
9812      (t
9813       (setq force t)))
9814     (when (and raw (not force)
9815                (member gnus-newsgroup-name '("nndraft:delayed"
9816                                              "nndraft:drafts"
9817                                              "nndraft:queue")))
9818       (error "Can't edit the raw article in group %s"
9819              gnus-newsgroup-name))
9820     (save-excursion
9821       (set-buffer gnus-summary-buffer)
9822       (let ((mail-parse-charset gnus-newsgroup-charset)
9823             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9824         (gnus-set-global-variables)
9825         (when (and (not force)
9826                    (gnus-group-read-only-p))
9827           (error "The current newsgroup does not support article editing"))
9828         (gnus-summary-show-article t)
9829         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9830           (with-current-buffer gnus-article-buffer
9831             (mm-enable-multibyte)))
9832         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9833             (setq raw t))
9834         (gnus-article-edit-article
9835          (if raw 'ignore
9836            `(lambda ()
9837               (let ((mbl mml-buffer-list))
9838                 (setq mml-buffer-list nil)
9839                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9840                   (mime-to-mml ,'current-handles))
9841                 (let ((mbl1 mml-buffer-list))
9842                   (setq mml-buffer-list mbl)
9843                   (set (make-local-variable 'mml-buffer-list) mbl1))
9844                 (gnus-make-local-hook 'kill-buffer-hook)
9845                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9846          `(lambda (no-highlight)
9847             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9848                   (message-options message-options)
9849                   (message-options-set-recipient)
9850                   (mail-parse-ignored-charsets
9851                    ',gnus-newsgroup-ignored-charsets))
9852               ,(if (not raw) '(progn
9853                                 (mml-to-mime)
9854                                 (mml-destroy-buffers)
9855                                 (remove-hook 'kill-buffer-hook
9856                                              'mml-destroy-buffers t)
9857                                 (kill-local-variable 'mml-buffer-list)))
9858               (gnus-summary-edit-article-done
9859                ,(or (mail-header-references gnus-current-headers) "")
9860                ,(gnus-group-read-only-p)
9861                ,gnus-summary-buffer no-highlight))))))))
9862
9863 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9864
9865 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9866                                                  no-highlight)
9867   "Make edits to the current article permanent."
9868   (interactive)
9869   (save-excursion
9870    ;; The buffer restriction contains the entire article if it exists.
9871     (when (article-goto-body)
9872       (let ((lines (count-lines (point) (point-max)))
9873             (length (- (point-max) (point)))
9874             (case-fold-search t)
9875             (body (copy-marker (point))))
9876         (goto-char (point-min))
9877         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9878           (delete-region (match-beginning 1) (match-end 1))
9879           (insert (number-to-string length)))
9880         (goto-char (point-min))
9881         (when (re-search-forward
9882                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9883           (delete-region (match-beginning 1) (match-end 1))
9884           (insert (number-to-string length)))
9885         (goto-char (point-min))
9886         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9887           (delete-region (match-beginning 1) (match-end 1))
9888           (insert (number-to-string lines))))))
9889   ;; Replace the article.
9890   (let ((buf (current-buffer)))
9891     (with-temp-buffer
9892       (insert-buffer-substring buf)
9893
9894       (if (and (not read-only)
9895                (not (gnus-request-replace-article
9896                      (cdr gnus-article-current) (car gnus-article-current)
9897                      (current-buffer) t)))
9898           (error "Couldn't replace article")
9899         ;; Update the summary buffer.
9900         (if (and references
9901                  (equal (message-tokenize-header references " ")
9902                         (message-tokenize-header
9903                          (or (message-fetch-field "references") "") " ")))
9904             ;; We only have to update this line.
9905             (save-excursion
9906               (save-restriction
9907                 (message-narrow-to-head)
9908                 (let ((head (buffer-substring-no-properties
9909                              (point-min) (point-max)))
9910                       header)
9911                   (with-temp-buffer
9912                     (insert (format "211 %d Article retrieved.\n"
9913                                     (cdr gnus-article-current)))
9914                     (insert head)
9915                     (insert ".\n")
9916                     (let ((nntp-server-buffer (current-buffer)))
9917                       (setq header (car (gnus-get-newsgroup-headers
9918                                          nil t))))
9919                     (save-excursion
9920                       (set-buffer gnus-summary-buffer)
9921                       (gnus-data-set-header
9922                        (gnus-data-find (cdr gnus-article-current))
9923                        header)
9924                       (gnus-summary-update-article-line
9925                        (cdr gnus-article-current) header)
9926                       (if (gnus-summary-goto-subject
9927                            (cdr gnus-article-current) nil t)
9928                           (gnus-summary-update-secondary-mark
9929                            (cdr gnus-article-current))))))))
9930           ;; Update threads.
9931           (set-buffer (or buffer gnus-summary-buffer))
9932           (gnus-summary-update-article (cdr gnus-article-current))
9933           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9934               (gnus-summary-update-secondary-mark
9935                (cdr gnus-article-current))))
9936         ;; Prettify the article buffer again.
9937         (unless no-highlight
9938           (save-excursion
9939             (set-buffer gnus-article-buffer)
9940             ;;;!!! Fix this -- article should be rehighlighted.
9941             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9942             (set-buffer gnus-original-article-buffer)
9943             (gnus-request-article
9944              (cdr gnus-article-current)
9945              (car gnus-article-current) (current-buffer))))
9946         ;; Prettify the summary buffer line.
9947         (when (gnus-visual-p 'summary-highlight 'highlight)
9948           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9949
9950 (defun gnus-summary-edit-wash (key)
9951   "Perform editing command KEY in the article buffer."
9952   (interactive
9953    (list
9954     (progn
9955       (message "%s" (concat (this-command-keys) "- "))
9956       (read-char))))
9957   (message "")
9958   (gnus-summary-edit-article)
9959   (execute-kbd-macro (concat (this-command-keys) key))
9960   (gnus-article-edit-done))
9961
9962 ;;; Respooling
9963
9964 (defun gnus-summary-respool-query (&optional silent trace)
9965   "Query where the respool algorithm would put this article."
9966   (interactive)
9967   (let (gnus-mark-article-hook)
9968     (gnus-summary-select-article)
9969     (save-excursion
9970       (set-buffer gnus-original-article-buffer)
9971       (let ((groups (nnmail-article-group 'identity trace)))
9972         (unless silent
9973           (if groups
9974               (message "This message would go to %s"
9975                        (mapconcat 'car groups ", "))
9976             (message "This message would go to no groups"))
9977           groups)))))
9978
9979 (defun gnus-summary-respool-trace ()
9980   "Trace where the respool algorithm would put this article.
9981 Display a buffer showing all fancy splitting patterns which matched."
9982   (interactive)
9983   (gnus-summary-respool-query nil t))
9984
9985 ;; Summary marking commands.
9986
9987 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9988   "Mark articles which has the same subject as read, and then select the next.
9989 If UNMARK is positive, remove any kind of mark.
9990 If UNMARK is negative, tick articles."
9991   (interactive "P")
9992   (when unmark
9993     (setq unmark (prefix-numeric-value unmark)))
9994   (let ((count
9995          (gnus-summary-mark-same-subject
9996           (gnus-summary-article-subject) unmark)))
9997     ;; Select next unread article.  If auto-select-same mode, should
9998     ;; select the first unread article.
9999     (gnus-summary-next-article t (and gnus-auto-select-same
10000                                       (gnus-summary-article-subject)))
10001     (gnus-message 7 "%d article%s marked as %s"
10002                   count (if (= count 1) " is" "s are")
10003                   (if unmark "unread" "read"))))
10004
10005 (defun gnus-summary-kill-same-subject (&optional unmark)
10006   "Mark articles which has the same subject as read.
10007 If UNMARK is positive, remove any kind of mark.
10008 If UNMARK is negative, tick articles."
10009   (interactive "P")
10010   (when unmark
10011     (setq unmark (prefix-numeric-value unmark)))
10012   (let ((count
10013          (gnus-summary-mark-same-subject
10014           (gnus-summary-article-subject) unmark)))
10015     ;; If marked as read, go to next unread subject.
10016     (when (null unmark)
10017       ;; Go to next unread subject.
10018       (gnus-summary-next-subject 1 t))
10019     (gnus-message 7 "%d articles are marked as %s"
10020                   count (if unmark "unread" "read"))))
10021
10022 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10023   "Mark articles with same SUBJECT as read, and return marked number.
10024 If optional argument UNMARK is positive, remove any kinds of marks.
10025 If optional argument UNMARK is negative, mark articles as unread instead."
10026   (let ((count 1))
10027     (save-excursion
10028       (cond
10029        ((null unmark)                   ; Mark as read.
10030         (while (and
10031                 (progn
10032                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10033                   (gnus-summary-show-thread) t)
10034                 (gnus-summary-find-subject subject))
10035           (setq count (1+ count))))
10036        ((> unmark 0)                    ; Tick.
10037         (while (and
10038                 (progn
10039                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10040                   (gnus-summary-show-thread) t)
10041                 (gnus-summary-find-subject subject))
10042           (setq count (1+ count))))
10043        (t                               ; Mark as unread.
10044         (while (and
10045                 (progn
10046                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10047                   (gnus-summary-show-thread) t)
10048                 (gnus-summary-find-subject subject))
10049           (setq count (1+ count)))))
10050       (gnus-set-mode-line 'summary)
10051       ;; Return the number of marked articles.
10052       count)))
10053
10054 (defun gnus-summary-mark-as-processable (n &optional unmark)
10055   "Set the process mark on the next N articles.
10056 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10057 the process mark instead.  The difference between N and the actual
10058 number of articles marked is returned."
10059   (interactive "P")
10060   (if (and (null n) (gnus-region-active-p))
10061       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10062     (setq n (prefix-numeric-value n))
10063     (let ((backward (< n 0))
10064           (n (abs n)))
10065       (while (and
10066               (> n 0)
10067               (if unmark
10068                   (gnus-summary-remove-process-mark
10069                    (gnus-summary-article-number))
10070                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10071               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10072         (setq n (1- n)))
10073       (when (/= 0 n)
10074         (gnus-message 7 "No more articles"))
10075       (gnus-summary-recenter)
10076       (gnus-summary-position-point)
10077       n)))
10078
10079 (defun gnus-summary-unmark-as-processable (n)
10080   "Remove the process mark from the next N articles.
10081 If N is negative, unmark backward instead.  The difference between N and
10082 the actual number of articles unmarked is returned."
10083   (interactive "P")
10084   (gnus-summary-mark-as-processable n t))
10085
10086 (defun gnus-summary-unmark-all-processable ()
10087   "Remove the process mark from all articles."
10088   (interactive)
10089   (save-excursion
10090     (while gnus-newsgroup-processable
10091       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10092   (gnus-summary-position-point))
10093
10094 (defun gnus-summary-add-mark (article type)
10095   "Mark ARTICLE with a mark of TYPE."
10096   (let ((vtype (car (assq type gnus-article-mark-lists)))
10097         var)
10098     (if (not vtype)
10099         (error "No such mark type: %s" type)
10100       (setq var (intern (format "gnus-newsgroup-%s" type)))
10101       (set var (cons article (symbol-value var)))
10102       (if (memq type '(processable cached replied forwarded recent saved))
10103           (gnus-summary-update-secondary-mark article)
10104         ;;; !!! This is bogus.  We should find out what primary
10105         ;;; !!! mark we want to set.
10106         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10107
10108 (defun gnus-summary-mark-as-expirable (n)
10109   "Mark N articles forward as expirable.
10110 If N is negative, mark backward instead.  The difference between N and
10111 the actual number of articles marked is returned."
10112   (interactive "p")
10113   (gnus-summary-mark-forward n gnus-expirable-mark))
10114
10115 (defun gnus-summary-mark-as-spam (n)
10116   "Mark N articles forward as spam.
10117 If N is negative, mark backward instead.  The difference between N and
10118 the actual number of articles marked is returned."
10119   (interactive "p")
10120   (gnus-summary-mark-forward n gnus-spam-mark))
10121
10122 (defun gnus-summary-mark-article-as-replied (article)
10123   "Mark ARTICLE as replied to and update the summary line.
10124 ARTICLE can also be a list of articles."
10125   (interactive (list (gnus-summary-article-number)))
10126   (let ((articles (if (listp article) article (list article))))
10127     (dolist (article articles)
10128       (unless (numberp article)
10129         (error "%s is not a number" article))
10130       (push article gnus-newsgroup-replied)
10131       (let ((buffer-read-only nil))
10132         (when (gnus-summary-goto-subject article nil t)
10133           (gnus-summary-update-secondary-mark article))))))
10134
10135 (defun gnus-summary-mark-article-as-forwarded (article)
10136   "Mark ARTICLE as forwarded and update the summary line.
10137 ARTICLE can also be a list of articles."
10138   (let ((articles (if (listp article) article (list article))))
10139     (dolist (article articles)
10140       (push article gnus-newsgroup-forwarded)
10141       (let ((buffer-read-only nil))
10142         (when (gnus-summary-goto-subject article nil t)
10143           (gnus-summary-update-secondary-mark article))))))
10144
10145 (defun gnus-summary-set-bookmark (article)
10146   "Set a bookmark in current article."
10147   (interactive (list (gnus-summary-article-number)))
10148   (when (or (not (get-buffer gnus-article-buffer))
10149             (not gnus-current-article)
10150             (not gnus-article-current)
10151             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10152     (error "No current article selected"))
10153   ;; Remove old bookmark, if one exists.
10154   (gnus-pull article gnus-newsgroup-bookmarks)
10155   ;; Set the new bookmark, which is on the form
10156   ;; (article-number . line-number-in-body).
10157   (push
10158    (cons article
10159          (with-current-buffer gnus-article-buffer
10160            (count-lines
10161             (min (point)
10162                  (save-excursion
10163                    (article-goto-body)
10164                    (point)))
10165             (point))))
10166    gnus-newsgroup-bookmarks)
10167   (gnus-message 6 "A bookmark has been added to the current article."))
10168
10169 (defun gnus-summary-remove-bookmark (article)
10170   "Remove the bookmark from the current article."
10171   (interactive (list (gnus-summary-article-number)))
10172   ;; Remove old bookmark, if one exists.
10173   (if (not (assq article gnus-newsgroup-bookmarks))
10174       (gnus-message 6 "No bookmark in current article.")
10175     (gnus-pull article gnus-newsgroup-bookmarks)
10176     (gnus-message 6 "Removed bookmark.")))
10177
10178 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10179 (defun gnus-summary-mark-as-dormant (n)
10180   "Mark N articles forward as dormant.
10181 If N is negative, mark backward instead.  The difference between N and
10182 the actual number of articles marked is returned."
10183   (interactive "p")
10184   (gnus-summary-mark-forward n gnus-dormant-mark))
10185
10186 (defun gnus-summary-set-process-mark (article)
10187   "Set the process mark on ARTICLE and update the summary line."
10188   (setq gnus-newsgroup-processable
10189         (cons article
10190               (delq article gnus-newsgroup-processable)))
10191   (when (gnus-summary-goto-subject article)
10192     (gnus-summary-show-thread)
10193     (gnus-summary-goto-subject article)
10194     (gnus-summary-update-secondary-mark article)))
10195
10196 (defun gnus-summary-remove-process-mark (&rest articles)
10197   "Remove the process mark from ARTICLES and update the summary line."
10198   (dolist (article articles)
10199     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10200     (when (gnus-summary-goto-subject article)
10201       (gnus-summary-show-thread)
10202       (gnus-summary-goto-subject article)
10203       (gnus-summary-update-secondary-mark article)))
10204   t)
10205
10206 (defun gnus-summary-set-saved-mark (article)
10207   "Set the process mark on ARTICLE and update the summary line."
10208   (push article gnus-newsgroup-saved)
10209   (when (gnus-summary-goto-subject article)
10210     (gnus-summary-update-secondary-mark article)))
10211
10212 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10213   "Mark N articles as read forwards.
10214 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10215 The difference between N and the actual number of articles marked is
10216 returned.
10217 If NO-EXPIRE, auto-expiry will be inhibited."
10218   (interactive "p")
10219   (gnus-summary-show-thread)
10220   (let ((backward (< n 0))
10221         (gnus-summary-goto-unread
10222          (and gnus-summary-goto-unread
10223               (not (eq gnus-summary-goto-unread 'never))
10224               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10225                                     gnus-ticked-mark gnus-dormant-mark)))))
10226         (n (abs n))
10227         (mark (or mark gnus-del-mark)))
10228     (while (and (> n 0)
10229                 (gnus-summary-mark-article nil mark no-expire)
10230                 (zerop (gnus-summary-next-subject
10231                         (if backward -1 1)
10232                         (and gnus-summary-goto-unread
10233                              (not (eq gnus-summary-goto-unread 'never)))
10234                         t)))
10235       (setq n (1- n)))
10236     (when (/= 0 n)
10237       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10238     (gnus-summary-recenter)
10239     (gnus-summary-position-point)
10240     (gnus-set-mode-line 'summary)
10241     n))
10242
10243 (defun gnus-summary-mark-article-as-read (mark)
10244   "Mark the current article quickly as read with MARK."
10245   (let ((article (gnus-summary-article-number)))
10246     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10247     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10248     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10249     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10250     (push (cons article mark) gnus-newsgroup-reads)
10251     ;; Possibly remove from cache, if that is used.
10252     (when gnus-use-cache
10253       (gnus-cache-enter-remove-article article))
10254     ;; Allow the backend to change the mark.
10255     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10256     ;; Check for auto-expiry.
10257     (when (and gnus-newsgroup-auto-expire
10258                (memq mark gnus-auto-expirable-marks))
10259       (setq mark gnus-expirable-mark)
10260       ;; Let the backend know about the mark change.
10261       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10262       (push article gnus-newsgroup-expirable))
10263     ;; Set the mark in the buffer.
10264     (gnus-summary-update-mark mark 'unread)
10265     t))
10266
10267 (defun gnus-summary-mark-article-as-unread (mark)
10268   "Mark the current article quickly as unread with MARK."
10269   (let* ((article (gnus-summary-article-number))
10270          (old-mark (gnus-summary-article-mark article)))
10271     ;; Allow the backend to change the mark.
10272     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10273     (if (eq mark old-mark)
10274         t
10275       (if (<= article 0)
10276           (progn
10277             (gnus-error 1 "Can't mark negative article numbers")
10278             nil)
10279         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10280         (setq gnus-newsgroup-spam-marked
10281               (delq article gnus-newsgroup-spam-marked))
10282         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10283         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10284         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10285         (cond ((= mark gnus-ticked-mark)
10286                (setq gnus-newsgroup-marked
10287                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10288                                               article)))
10289               ((= mark gnus-spam-mark)
10290                (setq gnus-newsgroup-spam-marked
10291                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10292                                               article)))
10293               ((= mark gnus-dormant-mark)
10294                (setq gnus-newsgroup-dormant
10295                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10296                                               article)))
10297               (t
10298                (setq gnus-newsgroup-unreads
10299                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10300                                               article))))
10301         (gnus-pull article gnus-newsgroup-reads)
10302
10303         ;; See whether the article is to be put in the cache.
10304         (and gnus-use-cache
10305              (vectorp (gnus-summary-article-header article))
10306              (save-excursion
10307                (gnus-cache-possibly-enter-article
10308                 gnus-newsgroup-name article
10309                 (= mark gnus-ticked-mark)
10310                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10311
10312         ;; Fix the mark.
10313         (gnus-summary-update-mark mark 'unread)
10314         t))))
10315
10316 (defun gnus-summary-mark-article (&optional article mark no-expire)
10317   "Mark ARTICLE with MARK.  MARK can be any character.
10318 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10319 `??' (dormant) and `?E' (expirable).
10320 If MARK is nil, then the default character `?r' is used.
10321 If ARTICLE is nil, then the article on the current line will be
10322 marked.
10323 If NO-EXPIRE, auto-expiry will be inhibited."
10324   ;; The mark might be a string.
10325   (when (stringp mark)
10326     (setq mark (aref mark 0)))
10327   ;; If no mark is given, then we check auto-expiring.
10328   (when (null mark)
10329     (setq mark gnus-del-mark))
10330   (when (and (not no-expire)
10331              gnus-newsgroup-auto-expire
10332              (memq mark gnus-auto-expirable-marks))
10333     (setq mark gnus-expirable-mark))
10334   (let ((article (or article (gnus-summary-article-number)))
10335         (old-mark (gnus-summary-article-mark article)))
10336     ;; Allow the backend to change the mark.
10337     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10338     (if (eq mark old-mark)
10339         t
10340       (unless article
10341         (error "No article on current line"))
10342       (if (not (if (or (= mark gnus-unread-mark)
10343                        (= mark gnus-ticked-mark)
10344                        (= mark gnus-spam-mark)
10345                        (= mark gnus-dormant-mark))
10346                    (gnus-mark-article-as-unread article mark)
10347                  (gnus-mark-article-as-read article mark)))
10348           t
10349         ;; See whether the article is to be put in the cache.
10350         (and gnus-use-cache
10351              (not (= mark gnus-canceled-mark))
10352              (vectorp (gnus-summary-article-header article))
10353              (save-excursion
10354                (gnus-cache-possibly-enter-article
10355                 gnus-newsgroup-name article
10356                 (= mark gnus-ticked-mark)
10357                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10358
10359         (when (gnus-summary-goto-subject article nil t)
10360           (let ((buffer-read-only nil))
10361             (gnus-summary-show-thread)
10362             ;; Fix the mark.
10363             (gnus-summary-update-mark mark 'unread)
10364             t))))))
10365
10366 (defun gnus-summary-update-secondary-mark (article)
10367   "Update the secondary (read, process, cache) mark."
10368   (gnus-summary-update-mark
10369    (cond ((memq article gnus-newsgroup-processable)
10370           gnus-process-mark)
10371          ((memq article gnus-newsgroup-cached)
10372           gnus-cached-mark)
10373          ((memq article gnus-newsgroup-replied)
10374           gnus-replied-mark)
10375          ((memq article gnus-newsgroup-forwarded)
10376           gnus-forwarded-mark)
10377          ((memq article gnus-newsgroup-saved)
10378           gnus-saved-mark)
10379          ((memq article gnus-newsgroup-recent)
10380           gnus-recent-mark)
10381          ((memq article gnus-newsgroup-unseen)
10382           gnus-unseen-mark)
10383          (t gnus-no-mark))
10384    'replied)
10385   (when (gnus-visual-p 'summary-highlight 'highlight)
10386     (gnus-run-hooks 'gnus-summary-update-hook))
10387   t)
10388
10389 (defun gnus-summary-update-download-mark (article)
10390   "Update the download mark."
10391   (gnus-summary-update-mark
10392    (cond ((memq article gnus-newsgroup-undownloaded)
10393           gnus-undownloaded-mark)
10394          (gnus-newsgroup-agentized
10395           gnus-downloaded-mark)
10396          (t
10397           gnus-no-mark))
10398    'download)
10399   (gnus-summary-update-line t)
10400   t)
10401
10402 (defun gnus-summary-update-mark (mark type)
10403   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10404         (buffer-read-only nil))
10405     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10406     (when forward
10407       (when (looking-at "\r")
10408         (incf forward))
10409       (when (<= (+ forward (point)) (point-max))
10410         ;; Go to the right position on the line.
10411         (goto-char (+ forward (point)))
10412         ;; Replace the old mark with the new mark.
10413         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10414         ;; Optionally update the marks by some user rule.
10415         (when (eq type 'unread)
10416           (gnus-data-set-mark
10417            (gnus-data-find (gnus-summary-article-number)) mark)
10418           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10419
10420 (defun gnus-mark-article-as-read (article &optional mark)
10421   "Enter ARTICLE in the pertinent lists and remove it from others."
10422   ;; Make the article expirable.
10423   (let ((mark (or mark gnus-del-mark)))
10424     (setq gnus-newsgroup-expirable
10425           (if (= mark gnus-expirable-mark)
10426               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10427             (delq article gnus-newsgroup-expirable)))
10428     ;; Remove from unread and marked lists.
10429     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10430     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10431     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10432     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10433     (push (cons article mark) gnus-newsgroup-reads)
10434     ;; Possibly remove from cache, if that is used.
10435     (when gnus-use-cache
10436       (gnus-cache-enter-remove-article article))
10437     t))
10438
10439 (defun gnus-mark-article-as-unread (article &optional mark)
10440   "Enter ARTICLE in the pertinent lists and remove it from others."
10441   (let ((mark (or mark gnus-ticked-mark)))
10442     (if (<= article 0)
10443         (progn
10444           (gnus-error 1 "Can't mark negative article numbers")
10445           nil)
10446       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10447             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10448             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10449             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10450             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10451
10452       ;; Unsuppress duplicates?
10453       (when gnus-suppress-duplicates
10454         (gnus-dup-unsuppress-article article))
10455
10456       (cond ((= mark gnus-ticked-mark)
10457              (setq gnus-newsgroup-marked
10458                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10459             ((= mark gnus-spam-mark)
10460              (setq gnus-newsgroup-spam-marked
10461                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10462                                             article)))
10463             ((= mark gnus-dormant-mark)
10464              (setq gnus-newsgroup-dormant
10465                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10466             (t
10467              (setq gnus-newsgroup-unreads
10468                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10469       (gnus-pull article gnus-newsgroup-reads)
10470       t)))
10471
10472 (defalias 'gnus-summary-mark-as-unread-forward
10473   'gnus-summary-tick-article-forward)
10474 (make-obsolete 'gnus-summary-mark-as-unread-forward
10475                'gnus-summary-tick-article-forward)
10476 (defun gnus-summary-tick-article-forward (n)
10477   "Tick N articles forwards.
10478 If N is negative, tick backwards instead.
10479 The difference between N and the number of articles ticked is returned."
10480   (interactive "p")
10481   (gnus-summary-mark-forward n gnus-ticked-mark))
10482
10483 (defalias 'gnus-summary-mark-as-unread-backward
10484   'gnus-summary-tick-article-backward)
10485 (make-obsolete 'gnus-summary-mark-as-unread-backward
10486                'gnus-summary-tick-article-backward)
10487 (defun gnus-summary-tick-article-backward (n)
10488   "Tick N articles backwards.
10489 The difference between N and the number of articles ticked is returned."
10490   (interactive "p")
10491   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10492
10493 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10494 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10495 (defun gnus-summary-tick-article (&optional article clear-mark)
10496   "Mark current article as unread.
10497 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10498 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10499   (interactive)
10500   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10501                                        gnus-ticked-mark)))
10502
10503 (defun gnus-summary-mark-as-read-forward (n)
10504   "Mark N articles as read forwards.
10505 If N is negative, mark backwards instead.
10506 The difference between N and the actual number of articles marked is
10507 returned."
10508   (interactive "p")
10509   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10510
10511 (defun gnus-summary-mark-as-read-backward (n)
10512   "Mark the N articles as read backwards.
10513 The difference between N and the actual number of articles marked is
10514 returned."
10515   (interactive "p")
10516   (gnus-summary-mark-forward
10517    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10518
10519 (defun gnus-summary-mark-as-read (&optional article mark)
10520   "Mark current article as read.
10521 ARTICLE specifies the article to be marked as read.
10522 MARK specifies a string to be inserted at the beginning of the line."
10523   (gnus-summary-mark-article article mark))
10524
10525 (defun gnus-summary-clear-mark-forward (n)
10526   "Clear marks from N articles forward.
10527 If N is negative, clear backward instead.
10528 The difference between N and the number of marks cleared is returned."
10529   (interactive "p")
10530   (gnus-summary-mark-forward n gnus-unread-mark))
10531
10532 (defun gnus-summary-clear-mark-backward (n)
10533   "Clear marks from N articles backward.
10534 The difference between N and the number of marks cleared is returned."
10535   (interactive "p")
10536   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10537
10538 (defun gnus-summary-mark-unread-as-read ()
10539   "Intended to be used by `gnus-summary-mark-article-hook'."
10540   (when (memq gnus-current-article gnus-newsgroup-unreads)
10541     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10542
10543 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10544   "Intended to be used by `gnus-summary-mark-article-hook'."
10545   (let ((mark (gnus-summary-article-mark)))
10546     (when (or (gnus-unread-mark-p mark)
10547               (gnus-read-mark-p mark))
10548       (gnus-summary-mark-article gnus-current-article
10549                                  (or new-mark gnus-read-mark)))))
10550
10551 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10552   "Intended to be used by `gnus-summary-mark-article-hook'."
10553   (let ((mark (gnus-summary-article-mark)))
10554     (when (or (gnus-unread-mark-p mark)
10555               (gnus-read-mark-p mark))
10556       (gnus-summary-mark-article (gnus-summary-article-number)
10557                                  (or new-mark gnus-read-mark)))))
10558
10559 (defun gnus-summary-mark-unread-as-ticked ()
10560   "Intended to be used by `gnus-summary-mark-article-hook'."
10561   (when (memq gnus-current-article gnus-newsgroup-unreads)
10562     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10563
10564 (defun gnus-summary-mark-region-as-read (point mark all)
10565   "Mark all unread articles between point and mark as read.
10566 If given a prefix, mark all articles between point and mark as read,
10567 even ticked and dormant ones."
10568   (interactive "r\nP")
10569   (save-excursion
10570     (let (article)
10571       (goto-char point)
10572       (beginning-of-line)
10573       (while (and
10574               (< (point) mark)
10575               (progn
10576                 (when (or all
10577                           (memq (setq article (gnus-summary-article-number))
10578                                 gnus-newsgroup-unreads))
10579                   (gnus-summary-mark-article article gnus-del-mark))
10580                 t)
10581               (gnus-summary-find-next))))))
10582
10583 (defun gnus-summary-mark-below (score mark)
10584   "Mark articles with score less than SCORE with MARK."
10585   (interactive "P\ncMark: ")
10586   (setq score (if score
10587                   (prefix-numeric-value score)
10588                 (or gnus-summary-default-score 0)))
10589   (save-excursion
10590     (set-buffer gnus-summary-buffer)
10591     (goto-char (point-min))
10592     (while
10593         (progn
10594           (and (< (gnus-summary-article-score) score)
10595                (gnus-summary-mark-article nil mark))
10596           (gnus-summary-find-next)))))
10597
10598 (defun gnus-summary-kill-below (&optional score)
10599   "Mark articles with score below SCORE as read."
10600   (interactive "P")
10601   (gnus-summary-mark-below score gnus-killed-mark))
10602
10603 (defun gnus-summary-clear-above (&optional score)
10604   "Clear all marks from articles with score above SCORE."
10605   (interactive "P")
10606   (gnus-summary-mark-above score gnus-unread-mark))
10607
10608 (defun gnus-summary-tick-above (&optional score)
10609   "Tick all articles with score above SCORE."
10610   (interactive "P")
10611   (gnus-summary-mark-above score gnus-ticked-mark))
10612
10613 (defun gnus-summary-mark-above (score mark)
10614   "Mark articles with score over SCORE with MARK."
10615   (interactive "P\ncMark: ")
10616   (setq score (if score
10617                   (prefix-numeric-value score)
10618                 (or gnus-summary-default-score 0)))
10619   (save-excursion
10620     (set-buffer gnus-summary-buffer)
10621     (goto-char (point-min))
10622     (while (and (progn
10623                   (when (> (gnus-summary-article-score) score)
10624                     (gnus-summary-mark-article nil mark))
10625                   t)
10626                 (gnus-summary-find-next)))))
10627
10628 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10629 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10630 (defun gnus-summary-limit-include-expunged (&optional no-error)
10631   "Display all the hidden articles that were expunged for low scores."
10632   (interactive)
10633   (let ((buffer-read-only nil))
10634     (let ((scored gnus-newsgroup-scored)
10635           headers h)
10636       (while scored
10637         (unless (gnus-summary-article-header (caar scored))
10638           (and (setq h (gnus-number-to-header (caar scored)))
10639                (< (cdar scored) gnus-summary-expunge-below)
10640                (push h headers)))
10641         (setq scored (cdr scored)))
10642       (if (not headers)
10643           (when (not no-error)
10644             (error "No expunged articles hidden"))
10645         (goto-char (point-min))
10646         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10647         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10648         (mapcar (lambda (x) (push (mail-header-number x)
10649                                   gnus-newsgroup-limit))
10650                 headers)
10651         (gnus-summary-prepare-unthreaded (nreverse headers))
10652         (goto-char (point-min))
10653         (gnus-summary-position-point)
10654         t))))
10655
10656 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10657   "Mark all unread articles in this newsgroup as read.
10658 If prefix argument ALL is non-nil, ticked and dormant articles will
10659 also be marked as read.
10660 If QUIETLY is non-nil, no questions will be asked.
10661
10662 If TO-HERE is non-nil, it should be a point in the buffer.  All
10663 articles before (after, if REVERSE is set) this point will be marked
10664 as read.
10665
10666 Note that this function will only catch up the unread article
10667 in the current summary buffer limitation.
10668
10669 The number of articles marked as read is returned."
10670   (interactive "P")
10671   (prog1
10672       (save-excursion
10673         (when (or quietly
10674                   (not gnus-interactive-catchup) ;Without confirmation?
10675                   gnus-expert-user
10676                   (gnus-y-or-n-p
10677                    (if all
10678                        "Mark absolutely all articles as read? "
10679                      "Mark all unread articles as read? ")))
10680           (if (and not-mark
10681                    (not gnus-newsgroup-adaptive)
10682                    (not gnus-newsgroup-auto-expire)
10683                    (not gnus-suppress-duplicates)
10684                    (or (not gnus-use-cache)
10685                        (eq gnus-use-cache 'passive)))
10686               (progn
10687                 (when all
10688                   (setq gnus-newsgroup-marked nil
10689                         gnus-newsgroup-spam-marked nil
10690                         gnus-newsgroup-dormant nil))
10691                 (setq gnus-newsgroup-unreads
10692                       (gnus-sorted-nunion
10693                        (gnus-intersection gnus-newsgroup-unreads
10694                                           gnus-newsgroup-downloadable)
10695                        gnus-newsgroup-unfetched)))
10696             ;; We actually mark all articles as canceled, which we
10697             ;; have to do when using auto-expiry or adaptive scoring.
10698             (gnus-summary-show-all-threads)
10699             (if (and to-here reverse)
10700                 (progn
10701                   (goto-char to-here)
10702                   (gnus-summary-mark-current-read-and-unread-as-read
10703                    gnus-catchup-mark)
10704                   (while (gnus-summary-find-next (not all))
10705                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10706               (when (gnus-summary-first-subject (not all))
10707                 (while (and
10708                         (if to-here (< (point) to-here) t)
10709                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10710                         (gnus-summary-find-next (not all))))))
10711             (gnus-set-mode-line 'summary))
10712           t))
10713     (gnus-summary-position-point)))
10714
10715 (defun gnus-summary-catchup-to-here (&optional all)
10716   "Mark all unticked articles before the current one as read.
10717 If ALL is non-nil, also mark ticked and dormant articles as read."
10718   (interactive "P")
10719   (save-excursion
10720     (gnus-save-hidden-threads
10721       (let ((beg (point)))
10722         ;; We check that there are unread articles.
10723         (when (or all (gnus-summary-find-prev))
10724           (gnus-summary-catchup all t beg)))))
10725   (gnus-summary-position-point))
10726
10727 (defun gnus-summary-catchup-from-here (&optional all)
10728   "Mark all unticked articles after (and including) the current one as read.
10729 If ALL is non-nil, also mark ticked and dormant articles as read."
10730   (interactive "P")
10731   (save-excursion
10732     (gnus-save-hidden-threads
10733       (let ((beg (point)))
10734         ;; We check that there are unread articles.
10735         (when (or all (gnus-summary-find-next))
10736           (gnus-summary-catchup all t beg nil t)))))
10737   (gnus-summary-position-point))
10738
10739 (defun gnus-summary-catchup-all (&optional quietly)
10740   "Mark all articles in this newsgroup as read.
10741 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10742 instead, which marks only unread articles as read."
10743   (interactive "P")
10744   (gnus-summary-catchup t quietly))
10745
10746 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10747   "Mark all unread articles in this group as read, then exit.
10748 If prefix argument ALL is non-nil, all articles are marked as read.
10749 If QUIETLY is non-nil, no questions will be asked."
10750   (interactive "P")
10751   (when (gnus-summary-catchup all quietly nil 'fast)
10752     ;; Select next newsgroup or exit.
10753     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10754              (eq gnus-auto-select-next 'quietly))
10755         (gnus-summary-next-group nil)
10756       (gnus-summary-exit))))
10757
10758 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10759   "Mark all articles in this newsgroup as read, and then exit.
10760 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10761 instead, which marks only unread articles as read."
10762   (interactive "P")
10763   (gnus-summary-catchup-and-exit t quietly))
10764
10765 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10766   "Mark all articles in this group as read and select the next group.
10767 If given a prefix, mark all articles, unread as well as ticked, as
10768 read."
10769   (interactive "P")
10770   (save-excursion
10771     (gnus-summary-catchup all))
10772   (gnus-summary-next-group))
10773
10774 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10775   "Mark all articles in this group as read and select the previous group.
10776 If given a prefix, mark all articles, unread as well as ticked, as
10777 read."
10778   (interactive "P")
10779   (save-excursion
10780     (gnus-summary-catchup all))
10781   (gnus-summary-next-group nil nil t))
10782
10783 ;;;
10784 ;;; with article
10785 ;;;
10786
10787 (defmacro gnus-with-article (article &rest forms)
10788   "Select ARTICLE and perform FORMS in the original article buffer.
10789 Then replace the article with the result."
10790   `(progn
10791      ;; We don't want the article to be marked as read.
10792      (let (gnus-mark-article-hook)
10793        (gnus-summary-select-article t t nil ,article))
10794      (set-buffer gnus-original-article-buffer)
10795      ,@forms
10796      (if (not (gnus-check-backend-function
10797                'request-replace-article (car gnus-article-current)))
10798          (gnus-message 5 "Read-only group; not replacing")
10799        (unless (gnus-request-replace-article
10800                 ,article (car gnus-article-current)
10801                 (current-buffer) t)
10802          (error "Couldn't replace article")))
10803      ;; The cache and backlog have to be flushed somewhat.
10804      (when gnus-keep-backlog
10805        (gnus-backlog-remove-article
10806         (car gnus-article-current) (cdr gnus-article-current)))
10807      (when gnus-use-cache
10808        (gnus-cache-update-article
10809         (car gnus-article-current) (cdr gnus-article-current)))))
10810
10811 (put 'gnus-with-article 'lisp-indent-function 1)
10812 (put 'gnus-with-article 'edebug-form-spec '(form body))
10813
10814 ;; Thread-based commands.
10815
10816 (defun gnus-summary-articles-in-thread (&optional article)
10817   "Return a list of all articles in the current thread.
10818 If ARTICLE is non-nil, return all articles in the thread that starts
10819 with that article."
10820   (let* ((article (or article (gnus-summary-article-number)))
10821          (data (gnus-data-find-list article))
10822          (top-level (gnus-data-level (car data)))
10823          (top-subject
10824           (cond ((null gnus-thread-operation-ignore-subject)
10825                  (gnus-simplify-subject-re
10826                   (mail-header-subject (gnus-data-header (car data)))))
10827                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10828                  (gnus-simplify-subject-fuzzy
10829                   (mail-header-subject (gnus-data-header (car data)))))
10830                 (t nil)))
10831          (end-point (save-excursion
10832                       (if (gnus-summary-go-to-next-thread)
10833                           (point) (point-max))))
10834          articles)
10835     (while (and data
10836                 (< (gnus-data-pos (car data)) end-point))
10837       (when (or (not top-subject)
10838                 (string= top-subject
10839                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10840                              (gnus-simplify-subject-fuzzy
10841                               (mail-header-subject
10842                                (gnus-data-header (car data))))
10843                            (gnus-simplify-subject-re
10844                             (mail-header-subject
10845                              (gnus-data-header (car data)))))))
10846         (push (gnus-data-number (car data)) articles))
10847       (unless (and (setq data (cdr data))
10848                    (> (gnus-data-level (car data)) top-level))
10849         (setq data nil)))
10850     ;; Return the list of articles.
10851     (nreverse articles)))
10852
10853 (defun gnus-summary-rethread-current ()
10854   "Rethread the thread the current article is part of."
10855   (interactive)
10856   (let* ((gnus-show-threads t)
10857          (article (gnus-summary-article-number))
10858          (id (mail-header-id (gnus-summary-article-header)))
10859          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10860     (unless id
10861       (error "No article on the current line"))
10862     (gnus-rebuild-thread id)
10863     (gnus-summary-goto-subject article)))
10864
10865 (defun gnus-summary-reparent-thread ()
10866   "Make the current article child of the marked (or previous) article.
10867
10868 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10869 is non-nil or the Subject: of both articles are the same."
10870   (interactive)
10871   (unless (not (gnus-group-read-only-p))
10872     (error "The current newsgroup does not support article editing"))
10873   (unless (<= (length gnus-newsgroup-processable) 1)
10874     (error "No more than one article may be marked"))
10875   (let ((child (gnus-summary-article-number))
10876         ;; First grab the marked article, otherwise one line up.
10877         (parent (if (not (null gnus-newsgroup-processable))
10878                     (car gnus-newsgroup-processable)
10879                   (save-excursion
10880                     (if (eq (forward-line -1) 0)
10881                         (gnus-summary-article-number)
10882                       (error "Beginning of summary buffer"))))))
10883     (gnus-summary-reparent-children parent (list child))))
10884
10885 (defun gnus-summary-reparent-children (parent children)
10886   "Make PARENT the parent of CHILDREN.
10887 When called interactively, PARENT is is current article and
10888 CHILDREN are the process-marked articles."
10889   (interactive
10890    (list (gnus-summary-article-number)
10891          (gnus-summary-work-articles nil)))
10892   (dolist (child children)
10893     (save-window-excursion
10894       (let ((gnus-article-buffer " *reparent*"))
10895         (unless (not (eq parent child))
10896           (error "An article may not be self-referential"))
10897         (let ((message-id (mail-header-id
10898                            (gnus-summary-article-header parent))))
10899           (unless (and message-id (not (equal message-id "")))
10900             (error "No message-id in desired parent"))
10901           (gnus-with-article child
10902             (save-restriction
10903               (goto-char (point-min))
10904               (message-narrow-to-head)
10905               (if (re-search-forward "^References: " nil t)
10906                   (progn
10907                     (re-search-forward "^[^ \t]" nil t)
10908                     (forward-line -1)
10909                     (end-of-line)
10910                     (insert " " message-id))
10911                 (insert "References: " message-id "\n"))))
10912           (set-buffer gnus-summary-buffer)
10913           (gnus-summary-unmark-all-processable)
10914           (gnus-summary-update-article child)
10915           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10916             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10917           (gnus-summary-rethread-current)
10918           (gnus-message 3 "Article %d is now the child of article %d"
10919                         child parent))))))
10920
10921 (defun gnus-summary-toggle-threads (&optional arg)
10922   "Toggle showing conversation threads.
10923 If ARG is positive number, turn showing conversation threads on."
10924   (interactive "P")
10925   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10926     (setq gnus-show-threads
10927           (if (null arg) (not gnus-show-threads)
10928             (> (prefix-numeric-value arg) 0)))
10929     (gnus-summary-prepare)
10930     (gnus-summary-goto-subject current)
10931     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10932     (gnus-summary-position-point)))
10933
10934 (defun gnus-summary-show-all-threads ()
10935   "Show all threads."
10936   (interactive)
10937   (save-excursion
10938     (let ((buffer-read-only nil))
10939       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10940   (gnus-summary-position-point))
10941
10942 (defun gnus-summary-show-thread ()
10943   "Show thread subtrees.
10944 Returns nil if no thread was there to be shown."
10945   (interactive)
10946   (let ((buffer-read-only nil)
10947         (orig (point))
10948         (end (point-at-eol))
10949         ;; Leave point at bol
10950         (beg (progn (beginning-of-line) (point))))
10951     (prog1
10952         ;; Any hidden lines here?
10953         (search-forward "\r" end t)
10954       (subst-char-in-region beg end ?\^M ?\n t)
10955       (goto-char orig)
10956       (gnus-summary-position-point))))
10957
10958 (defun gnus-summary-maybe-hide-threads ()
10959   "If requested, hide the threads that should be hidden."
10960   (when (and gnus-show-threads
10961              gnus-thread-hide-subtree)
10962     (gnus-summary-hide-all-threads
10963      (if (or (consp gnus-thread-hide-subtree)
10964              (functionp gnus-thread-hide-subtree))
10965          (gnus-make-predicate gnus-thread-hide-subtree)
10966        nil))))
10967
10968 ;;; Hiding predicates.
10969
10970 (defun gnus-article-unread-p (header)
10971   (memq (mail-header-number header) gnus-newsgroup-unreads))
10972
10973 (defun gnus-article-unseen-p (header)
10974   (memq (mail-header-number header) gnus-newsgroup-unseen))
10975
10976 (defun gnus-map-articles (predicate articles)
10977   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10978   (apply 'gnus-or (mapcar predicate
10979                           (mapcar (lambda (number)
10980                                     (gnus-summary-article-header number))
10981                                   articles))))
10982
10983 (defun gnus-summary-hide-all-threads (&optional predicate)
10984   "Hide all thread subtrees.
10985 If PREDICATE is supplied, threads that satisfy this predicate
10986 will not be hidden."
10987   (interactive)
10988   (save-excursion
10989     (goto-char (point-min))
10990     (let ((end nil))
10991       (while (not end)
10992         (when (or (not predicate)
10993                   (gnus-map-articles
10994                    predicate (gnus-summary-article-children)))
10995             (gnus-summary-hide-thread))
10996         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10997   (gnus-summary-position-point))
10998
10999 (defun gnus-summary-hide-thread ()
11000   "Hide thread subtrees.
11001 If PREDICATE is supplied, threads that satisfy this predicate
11002 will not be hidden.
11003 Returns nil if no threads were there to be hidden."
11004   (interactive)
11005   (let ((buffer-read-only nil)
11006         (start (point))
11007         (article (gnus-summary-article-number)))
11008     (goto-char start)
11009     ;; Go forward until either the buffer ends or the subthread
11010     ;; ends.
11011     (when (and (not (eobp))
11012                (or (zerop (gnus-summary-next-thread 1 t))
11013                    (goto-char (point-max))))
11014       (prog1
11015           (if (and (> (point) start)
11016                    (search-backward "\n" start t))
11017               (progn
11018                 (subst-char-in-region start (point) ?\n ?\^M)
11019                 (gnus-summary-goto-subject article))
11020             (goto-char start)
11021             nil)))))
11022
11023 (defun gnus-summary-go-to-next-thread (&optional previous)
11024   "Go to the same level (or less) next thread.
11025 If PREVIOUS is non-nil, go to previous thread instead.
11026 Return the article number moved to, or nil if moving was impossible."
11027   (let ((level (gnus-summary-thread-level))
11028         (way (if previous -1 1))
11029         (beg (point)))
11030     (forward-line way)
11031     (while (and (not (eobp))
11032                 (< level (gnus-summary-thread-level)))
11033       (forward-line way))
11034     (if (eobp)
11035         (progn
11036           (goto-char beg)
11037           nil)
11038       (setq beg (point))
11039       (prog1
11040           (gnus-summary-article-number)
11041         (goto-char beg)))))
11042
11043 (defun gnus-summary-next-thread (n &optional silent)
11044   "Go to the same level next N'th thread.
11045 If N is negative, search backward instead.
11046 Returns the difference between N and the number of skips actually
11047 done.
11048
11049 If SILENT, don't output messages."
11050   (interactive "p")
11051   (let ((backward (< n 0))
11052         (n (abs n)))
11053     (while (and (> n 0)
11054                 (gnus-summary-go-to-next-thread backward))
11055       (decf n))
11056     (unless silent
11057       (gnus-summary-position-point))
11058     (when (and (not silent) (/= 0 n))
11059       (gnus-message 7 "No more threads"))
11060     n))
11061
11062 (defun gnus-summary-prev-thread (n)
11063   "Go to the same level previous N'th thread.
11064 Returns the difference between N and the number of skips actually
11065 done."
11066   (interactive "p")
11067   (gnus-summary-next-thread (- n)))
11068
11069 (defun gnus-summary-go-down-thread ()
11070   "Go down one level in the current thread."
11071   (let ((children (gnus-summary-article-children)))
11072     (when children
11073       (gnus-summary-goto-subject (car children)))))
11074
11075 (defun gnus-summary-go-up-thread ()
11076   "Go up one level in the current thread."
11077   (let ((parent (gnus-summary-article-parent)))
11078     (when parent
11079       (gnus-summary-goto-subject parent))))
11080
11081 (defun gnus-summary-down-thread (n)
11082   "Go down thread N steps.
11083 If N is negative, go up instead.
11084 Returns the difference between N and how many steps down that were
11085 taken."
11086   (interactive "p")
11087   (let ((up (< n 0))
11088         (n (abs n)))
11089     (while (and (> n 0)
11090                 (if up (gnus-summary-go-up-thread)
11091                   (gnus-summary-go-down-thread)))
11092       (setq n (1- n)))
11093     (gnus-summary-position-point)
11094     (when (/= 0 n)
11095       (gnus-message 7 "Can't go further"))
11096     n))
11097
11098 (defun gnus-summary-up-thread (n)
11099   "Go up thread N steps.
11100 If N is negative, go down instead.
11101 Returns the difference between N and how many steps down that were
11102 taken."
11103   (interactive "p")
11104   (gnus-summary-down-thread (- n)))
11105
11106 (defun gnus-summary-top-thread ()
11107   "Go to the top of the thread."
11108   (interactive)
11109   (while (gnus-summary-go-up-thread))
11110   (gnus-summary-article-number))
11111
11112 (defun gnus-summary-kill-thread (&optional unmark)
11113   "Mark articles under current thread as read.
11114 If the prefix argument is positive, remove any kinds of marks.
11115 If the prefix argument is negative, tick articles instead."
11116   (interactive "P")
11117   (when unmark
11118     (setq unmark (prefix-numeric-value unmark)))
11119   (let ((articles (gnus-summary-articles-in-thread)))
11120     (save-excursion
11121       ;; Expand the thread.
11122       (gnus-summary-show-thread)
11123       ;; Mark all the articles.
11124       (while articles
11125         (gnus-summary-goto-subject (car articles))
11126         (cond ((null unmark)
11127                (gnus-summary-mark-article-as-read gnus-killed-mark))
11128               ((> unmark 0)
11129                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11130               (t
11131                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11132         (setq articles (cdr articles))))
11133     ;; Hide killed subtrees.
11134     (and (null unmark)
11135          gnus-thread-hide-killed
11136          (gnus-summary-hide-thread))
11137     ;; If marked as read, go to next unread subject.
11138     (when (null unmark)
11139       ;; Go to next unread subject.
11140       (gnus-summary-next-subject 1 t)))
11141   (gnus-set-mode-line 'summary))
11142
11143 ;; Summary sorting commands
11144
11145 (defun gnus-summary-sort-by-number (&optional reverse)
11146   "Sort the summary buffer by article number.
11147 Argument REVERSE means reverse order."
11148   (interactive "P")
11149   (gnus-summary-sort 'number reverse))
11150
11151 (defun gnus-summary-sort-by-random (&optional reverse)
11152   "Randomize the order in the summary buffer.
11153 Argument REVERSE means to randomize in reverse order."
11154   (interactive "P")
11155   (gnus-summary-sort 'random reverse))
11156
11157 (defun gnus-summary-sort-by-author (&optional reverse)
11158   "Sort the summary buffer by author name alphabetically.
11159 If `case-fold-search' is non-nil, case of letters is ignored.
11160 Argument REVERSE means reverse order."
11161   (interactive "P")
11162   (gnus-summary-sort 'author reverse))
11163
11164 (defun gnus-summary-sort-by-recipient (&optional reverse)
11165   "Sort the summary buffer by recipient name alphabetically.
11166 If `case-fold-search' is non-nil, case of letters is ignored.
11167 Argument REVERSE means reverse order."
11168   (interactive "P")
11169   (gnus-summary-sort 'recipient reverse))
11170
11171 (defun gnus-summary-sort-by-subject (&optional reverse)
11172   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11173 If `case-fold-search' is non-nil, case of letters is ignored.
11174 Argument REVERSE means reverse order."
11175   (interactive "P")
11176   (gnus-summary-sort 'subject reverse))
11177
11178 (defun gnus-summary-sort-by-date (&optional reverse)
11179   "Sort the summary buffer by date.
11180 Argument REVERSE means reverse order."
11181   (interactive "P")
11182   (gnus-summary-sort 'date reverse))
11183
11184 (defun gnus-summary-sort-by-score (&optional reverse)
11185   "Sort the summary buffer by score.
11186 Argument REVERSE means reverse order."
11187   (interactive "P")
11188   (gnus-summary-sort 'score reverse))
11189
11190 (defun gnus-summary-sort-by-lines (&optional reverse)
11191   "Sort the summary buffer by the number of lines.
11192 Argument REVERSE means reverse order."
11193   (interactive "P")
11194   (gnus-summary-sort 'lines reverse))
11195
11196 (defun gnus-summary-sort-by-chars (&optional reverse)
11197   "Sort the summary buffer by article length.
11198 Argument REVERSE means reverse order."
11199   (interactive "P")
11200   (gnus-summary-sort 'chars reverse))
11201
11202 (defun gnus-summary-sort-by-original (&optional reverse)
11203   "Sort the summary buffer using the default sorting method.
11204 Argument REVERSE means reverse order."
11205   (interactive "P")
11206   (let* ((buffer-read-only)
11207          (gnus-summary-prepare-hook nil))
11208     ;; We do the sorting by regenerating the threads.
11209     (gnus-summary-prepare)
11210     ;; Hide subthreads if needed.
11211     (gnus-summary-maybe-hide-threads)))
11212
11213 (defun gnus-summary-sort (predicate reverse)
11214   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11215   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11216          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11217          (gnus-thread-sort-functions
11218           (if (not reverse)
11219               thread
11220             `(lambda (t1 t2)
11221                (,thread t2 t1))))
11222          (gnus-sort-gathered-threads-function
11223           gnus-thread-sort-functions)
11224          (gnus-article-sort-functions
11225           (if (not reverse)
11226               article
11227             `(lambda (t1 t2)
11228                (,article t2 t1))))
11229          (buffer-read-only)
11230          (gnus-summary-prepare-hook nil))
11231     ;; We do the sorting by regenerating the threads.
11232     (gnus-summary-prepare)
11233     ;; Hide subthreads if needed.
11234     (gnus-summary-maybe-hide-threads)))
11235
11236 ;; Summary saving commands.
11237
11238 (defun gnus-summary-save-article (&optional n not-saved)
11239   "Save the current article using the default saver function.
11240 If N is a positive number, save the N next articles.
11241 If N is a negative number, save the N previous articles.
11242 If N is nil and any articles have been marked with the process mark,
11243 save those articles instead.
11244 The variable `gnus-default-article-saver' specifies the saver function.
11245
11246 If the optional second argument NOT-SAVED is non-nil, articles saved
11247 will not be marked as saved."
11248   (interactive "P")
11249   (require 'gnus-art)
11250   (let* ((articles (gnus-summary-work-articles n))
11251          (save-buffer (save-excursion
11252                         (nnheader-set-temp-buffer " *Gnus Save*")))
11253          (num (length articles))
11254          ;; Whether to save decoded articles or raw articles.
11255          (decode (when gnus-article-save-coding-system
11256                    (get gnus-default-article-saver :decode)))
11257          ;; When saving many articles in a single file, use the other
11258          ;; function to save articles other than the first one.
11259          (saver2 (get gnus-default-article-saver :function))
11260          (gnus-prompt-before-saving (if saver2
11261                                         t
11262                                       gnus-prompt-before-saving))
11263          (gnus-default-article-saver gnus-default-article-saver)
11264          header file)
11265     (dolist (article articles)
11266       (setq header (gnus-summary-article-header article))
11267       (if (not (vectorp header))
11268           ;; This is a pseudo-article.
11269           (if (assq 'name header)
11270               (gnus-copy-file (cdr (assq 'name header)))
11271             (gnus-message 1 "Article %d is unsaveable" article))
11272         ;; This is a real article.
11273         (save-window-excursion
11274           (let ((gnus-display-mime-function (when decode
11275                                               gnus-display-mime-function))
11276                 (gnus-article-prepare-hook (when decode
11277                                              gnus-article-prepare-hook)))
11278             (gnus-summary-select-article t nil nil article)
11279             (gnus-summary-goto-subject article)))
11280         (save-excursion
11281           (set-buffer save-buffer)
11282           (erase-buffer)
11283           (insert-buffer-substring (if decode
11284                                        gnus-article-buffer
11285                                      gnus-original-article-buffer)))
11286         (setq file (gnus-article-save save-buffer file num))
11287         (gnus-summary-remove-process-mark article)
11288         (unless not-saved
11289           (gnus-summary-set-saved-mark article)))
11290       (when saver2
11291         (setq gnus-default-article-saver saver2
11292               saver2 nil)))
11293     (gnus-kill-buffer save-buffer)
11294     (gnus-summary-position-point)
11295     (gnus-set-mode-line 'summary)
11296     n))
11297
11298 (defun gnus-summary-pipe-output (&optional arg headers)
11299   "Pipe the current article to a subprocess.
11300 If N is a positive number, pipe the N next articles.
11301 If N is a negative number, pipe the N previous articles.
11302 If N is nil and any articles have been marked with the process mark,
11303 pipe those articles instead.
11304 If HEADERS (the symbolic prefix), include the headers, too."
11305   (interactive (gnus-interactive "P\ny"))
11306   (require 'gnus-art)
11307   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11308         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11309     (gnus-summary-save-article arg t))
11310   (let ((buffer (get-buffer "*Shell Command Output*")))
11311     (when (and buffer
11312                (not (zerop (buffer-size buffer))))
11313       (gnus-configure-windows 'pipe))))
11314
11315 (defun gnus-summary-save-article-mail (&optional arg)
11316   "Append the current article to a Unix mail box file.
11317 If N is a positive number, save the N next articles.
11318 If N is a negative number, save the N previous articles.
11319 If N is nil and any articles have been marked with the process mark,
11320 save those articles instead."
11321   (interactive "P")
11322   (require 'gnus-art)
11323   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11324     (gnus-summary-save-article arg)))
11325
11326 (defun gnus-summary-save-article-rmail (&optional arg)
11327   "Append the current article to an rmail file.
11328 If N is a positive number, save the N next articles.
11329 If N is a negative number, save the N previous articles.
11330 If N is nil and any articles have been marked with the process mark,
11331 save those articles instead."
11332   (interactive "P")
11333   (require 'gnus-art)
11334   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11335     (gnus-summary-save-article arg)))
11336
11337 (defun gnus-summary-save-article-file (&optional arg)
11338   "Append the current article to a file.
11339 If N is a positive number, save the N next articles.
11340 If N is a negative number, save the N previous articles.
11341 If N is nil and any articles have been marked with the process mark,
11342 save those articles instead."
11343   (interactive "P")
11344   (require 'gnus-art)
11345   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11346     (gnus-summary-save-article arg)))
11347
11348 (defun gnus-summary-write-article-file (&optional arg)
11349   "Write the current article to a file, deleting the previous file.
11350 If N is a positive number, save the N next articles.
11351 If N is a negative number, save the N previous articles.
11352 If N is nil and any articles have been marked with the process mark,
11353 save those articles instead."
11354   (interactive "P")
11355   (require 'gnus-art)
11356   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11357     (gnus-summary-save-article arg)))
11358
11359 (defun gnus-summary-save-article-body-file (&optional arg)
11360   "Append the current article body to a file.
11361 If N is a positive number, save the N next articles.
11362 If N is a negative number, save the N previous articles.
11363 If N is nil and any articles have been marked with the process mark,
11364 save those articles instead."
11365   (interactive "P")
11366   (require 'gnus-art)
11367   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11368     (gnus-summary-save-article arg)))
11369
11370 (defun gnus-summary-write-article-body-file (&optional arg)
11371   "Write the current article body to a file, deleting the previous file.
11372 If N is a positive number, save the N next articles.
11373 If N is a negative number, save the N previous articles.
11374 If N is nil and any articles have been marked with the process mark,
11375 save those articles instead."
11376   (interactive "P")
11377   (require 'gnus-art)
11378   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11379     (gnus-summary-save-article arg)))
11380
11381 (defun gnus-summary-muttprint (&optional arg)
11382   "Print the current article using Muttprint.
11383 If N is a positive number, save the N next articles.
11384 If N is a negative number, save the N previous articles.
11385 If N is nil and any articles have been marked with the process mark,
11386 save those articles instead."
11387   (interactive "P")
11388   (require 'gnus-art)
11389   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11390     (gnus-summary-save-article arg t)))
11391
11392 (defun gnus-summary-pipe-message (program)
11393   "Pipe the current article through PROGRAM."
11394   (interactive "sProgram: ")
11395   (gnus-summary-select-article)
11396   (let ((mail-header-separator ""))
11397     (gnus-eval-in-buffer-window gnus-article-buffer
11398       (save-restriction
11399         (widen)
11400         (let ((start (window-start))
11401               buffer-read-only)
11402           (message-pipe-buffer-body program)
11403           (set-window-start (get-buffer-window (current-buffer)) start))))))
11404
11405 (defun gnus-get-split-value (methods)
11406   "Return a value based on the split METHODS."
11407   (let (split-name method result match)
11408     (when methods
11409       (save-excursion
11410         (set-buffer gnus-original-article-buffer)
11411         (save-restriction
11412           (nnheader-narrow-to-headers)
11413           (while (and methods (not split-name))
11414             (goto-char (point-min))
11415             (setq method (pop methods))
11416             (setq match (car method))
11417             (when (cond
11418                    ((stringp match)
11419                     ;; Regular expression.
11420                     (ignore-errors
11421                       (re-search-forward match nil t)))
11422                    ((functionp match)
11423                     ;; Function.
11424                     (save-restriction
11425                       (widen)
11426                       (setq result (funcall match gnus-newsgroup-name))))
11427                    ((consp match)
11428                     ;; Form.
11429                     (save-restriction
11430                       (widen)
11431                       (setq result (eval match)))))
11432               (setq split-name (cdr method))
11433               (cond ((stringp result)
11434                      (push (expand-file-name
11435                             result gnus-article-save-directory)
11436                            split-name))
11437                     ((consp result)
11438                      (setq split-name (append result split-name)))))))))
11439     (nreverse split-name)))
11440
11441 (defun gnus-valid-move-group-p (group)
11442   (and (boundp group)
11443        (symbol-name group)
11444        (symbol-value group)
11445        (gnus-get-function (gnus-find-method-for-group
11446                            (symbol-name group)) 'request-accept-article t)))
11447
11448 (defun gnus-read-move-group-name (prompt default articles prefix)
11449   "Read a group name."
11450   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11451          (minibuffer-confirm-incomplete nil) ; XEmacs
11452          (prom
11453           (format "%s %s to"
11454                   prompt
11455                   (if (> (length articles) 1)
11456                       (format "these %d articles" (length articles))
11457                     "this article")))
11458          (to-newsgroup
11459           (cond
11460            ((null split-name)
11461             (gnus-completing-read-with-default
11462              default prom
11463              gnus-active-hashtb
11464              'gnus-valid-move-group-p
11465              nil prefix
11466              'gnus-group-history))
11467            ((= 1 (length split-name))
11468             (gnus-completing-read-with-default
11469              (car split-name) prom
11470              gnus-active-hashtb
11471              'gnus-valid-move-group-p
11472              nil nil
11473              'gnus-group-history))
11474            (t
11475             (gnus-completing-read-with-default
11476              nil prom
11477              (mapcar 'list (nreverse split-name))
11478              nil nil nil
11479              'gnus-group-history))))
11480          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11481     (when to-newsgroup
11482       (if (or (string= to-newsgroup "")
11483               (string= to-newsgroup prefix))
11484           (setq to-newsgroup default))
11485       (unless to-newsgroup
11486         (error "No group name entered"))
11487       (or (gnus-active to-newsgroup)
11488           (gnus-activate-group to-newsgroup nil nil to-method)
11489           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11490                                      to-newsgroup))
11491               (or (and (gnus-request-create-group to-newsgroup to-method)
11492                        (gnus-activate-group
11493                         to-newsgroup nil nil to-method)
11494                        (gnus-subscribe-group to-newsgroup))
11495                   (error "Couldn't create group %s" to-newsgroup)))
11496           (error "No such group: %s" to-newsgroup)))
11497     to-newsgroup))
11498
11499 (defvar gnus-summary-save-parts-counter)
11500
11501 (defun gnus-summary-save-parts (type dir n &optional reverse)
11502   "Save parts matching TYPE to DIR.
11503 If REVERSE, save parts that do not match TYPE."
11504   (interactive
11505    (list (read-string "Save parts of type: "
11506                       (or (car gnus-summary-save-parts-type-history)
11507                           gnus-summary-save-parts-default-mime)
11508                       'gnus-summary-save-parts-type-history)
11509          (setq gnus-summary-save-parts-last-directory
11510                (read-file-name "Save to directory: "
11511                                gnus-summary-save-parts-last-directory
11512                                nil t))
11513          current-prefix-arg))
11514   (gnus-summary-iterate n
11515     (let ((gnus-display-mime-function nil)
11516           (gnus-inhibit-treatment t))
11517       (gnus-summary-select-article))
11518     (save-excursion
11519       (set-buffer gnus-article-buffer)
11520       (let ((handles (or gnus-article-mime-handles
11521                          (mm-dissect-buffer nil gnus-article-loose-mime)
11522                          (and gnus-article-emulate-mime
11523                               (mm-uu-dissect))))
11524             (gnus-summary-save-parts-counter 1))
11525         (when handles
11526           (gnus-summary-save-parts-1 type dir handles reverse)
11527           (unless gnus-article-mime-handles ;; Don't destroy this case.
11528             (mm-destroy-parts handles)))))))
11529
11530 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11531   (if (stringp (car handle))
11532       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11533               (cdr handle))
11534     (when (if reverse
11535               (not (string-match type (mm-handle-media-type handle)))
11536             (string-match type (mm-handle-media-type handle)))
11537       (let ((file (expand-file-name
11538                    (gnus-map-function
11539                     mm-file-name-rewrite-functions
11540                     (file-name-nondirectory
11541                      (or
11542                       (mail-content-type-get
11543                        (mm-handle-disposition handle) 'filename)
11544                       (mail-content-type-get
11545                        (mm-handle-type handle) 'name)
11546                       (format "%s.%d.%d" gnus-newsgroup-name
11547                               (cdr gnus-article-current)
11548                               gnus-summary-save-parts-counter))))
11549                    dir)))
11550         (incf gnus-summary-save-parts-counter)
11551         (unless (file-exists-p file)
11552           (mm-save-part-to-file handle file))))))
11553
11554 ;; Summary extract commands
11555
11556 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11557   (let ((buffer-read-only nil)
11558         (article (gnus-summary-article-number))
11559         after-article b e)
11560     (unless (gnus-summary-goto-subject article)
11561       (error "No such article: %d" article))
11562     (gnus-summary-position-point)
11563     ;; If all commands are to be bunched up on one line, we collect
11564     ;; them here.
11565     (unless gnus-view-pseudos-separately
11566       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11567             files action)
11568         (while ps
11569           (setq action (cdr (assq 'action (car ps))))
11570           (setq files (list (cdr (assq 'name (car ps)))))
11571           (while (and ps (cdr ps)
11572                       (string= (or action "1")
11573                                (or (cdr (assq 'action (cadr ps))) "2")))
11574             (push (cdr (assq 'name (cadr ps))) files)
11575             (setcdr ps (cddr ps)))
11576           (when files
11577             (when (not (string-match "%s" action))
11578               (push " " files))
11579             (push " " files)
11580             (when (assq 'execute (car ps))
11581               (setcdr (assq 'execute (car ps))
11582                       (funcall (if (string-match "%s" action)
11583                                    'format 'concat)
11584                                action
11585                                (mapconcat
11586                                 (lambda (f)
11587                                   (if (equal f " ")
11588                                       f
11589                                     (shell-quote-argument f)))
11590                                 files " ")))))
11591           (setq ps (cdr ps)))))
11592     (if (and gnus-view-pseudos (not not-view))
11593         (while pslist
11594           (when (assq 'execute (car pslist))
11595             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11596                                   (eq gnus-view-pseudos 'not-confirm)))
11597           (setq pslist (cdr pslist)))
11598       (save-excursion
11599         (while pslist
11600           (setq after-article (or (cdr (assq 'article (car pslist)))
11601                                   (gnus-summary-article-number)))
11602           (gnus-summary-goto-subject after-article)
11603           (forward-line 1)
11604           (setq b (point))
11605           (insert "    " (file-name-nondirectory
11606                           (cdr (assq 'name (car pslist))))
11607                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11608           (setq e (point))
11609           (forward-line -1)             ; back to `b'
11610           (gnus-add-text-properties
11611            b (1- e) (list 'gnus-number gnus-reffed-article-number
11612                           gnus-mouse-face-prop gnus-mouse-face))
11613           (gnus-data-enter
11614            after-article gnus-reffed-article-number
11615            gnus-unread-mark b (car pslist) 0 (- e b))
11616           (setq gnus-newsgroup-unreads
11617                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11618                                          gnus-reffed-article-number))
11619           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11620           (setq pslist (cdr pslist)))))))
11621
11622 (defun gnus-pseudos< (p1 p2)
11623   (let ((c1 (cdr (assq 'action p1)))
11624         (c2 (cdr (assq 'action p2))))
11625     (and c1 c2 (string< c1 c2))))
11626
11627 (defun gnus-request-pseudo-article (props)
11628   (cond ((assq 'execute props)
11629          (gnus-execute-command (cdr (assq 'execute props)))))
11630   (let ((gnus-current-article (gnus-summary-article-number)))
11631     (gnus-run-hooks 'gnus-mark-article-hook)))
11632
11633 (defun gnus-execute-command (command &optional automatic)
11634   (save-excursion
11635     (gnus-article-setup-buffer)
11636     (set-buffer gnus-article-buffer)
11637     (setq buffer-read-only nil)
11638     (let ((command (if automatic command
11639                      (read-string "Command: " (cons command 0)))))
11640       (erase-buffer)
11641       (insert "$ " command "\n\n")
11642       (if gnus-view-pseudo-asynchronously
11643           (start-process "gnus-execute" (current-buffer) shell-file-name
11644                          shell-command-switch command)
11645         (call-process shell-file-name nil t nil
11646                       shell-command-switch command)))))
11647
11648 ;; Summary kill commands.
11649
11650 (defun gnus-summary-edit-global-kill (article)
11651   "Edit the \"global\" kill file."
11652   (interactive (list (gnus-summary-article-number)))
11653   (gnus-group-edit-global-kill article))
11654
11655 (defun gnus-summary-edit-local-kill ()
11656   "Edit a local kill file applied to the current newsgroup."
11657   (interactive)
11658   (setq gnus-current-headers (gnus-summary-article-header))
11659   (gnus-group-edit-local-kill
11660    (gnus-summary-article-number) gnus-newsgroup-name))
11661
11662 ;;; Header reading.
11663
11664 (defun gnus-read-header (id &optional header)
11665   "Read the headers of article ID and enter them into the Gnus system."
11666   (let ((group gnus-newsgroup-name)
11667         (gnus-override-method
11668          (or
11669           gnus-override-method
11670           (and (gnus-news-group-p gnus-newsgroup-name)
11671                (car (gnus-refer-article-methods)))))
11672         where)
11673     ;; First we check to see whether the header in question is already
11674     ;; fetched.
11675     (if (stringp id)
11676         ;; This is a Message-ID.
11677         (setq header (or header (gnus-id-to-header id)))
11678       ;; This is an article number.
11679       (setq header (or header (gnus-summary-article-header id))))
11680     (if (and header
11681              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11682         ;; We have found the header.
11683         header
11684       ;; We have to really fetch the header to this article.
11685       (save-excursion
11686         (set-buffer nntp-server-buffer)
11687         (when (setq where (gnus-request-head id group))
11688           (nnheader-fold-continuation-lines)
11689           (goto-char (point-max))
11690           (insert ".\n")
11691           (goto-char (point-min))
11692           (insert "211 ")
11693           (princ (cond
11694                   ((numberp id) id)
11695                   ((cdr where) (cdr where))
11696                   (header (mail-header-number header))
11697                   (t gnus-reffed-article-number))
11698                  (current-buffer))
11699           (insert " Article retrieved.\n"))
11700         (if (or (not where)
11701                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11702             ()                          ; Malformed head.
11703           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11704             (when (and (stringp id)
11705                        (or
11706                         (not (string= (gnus-group-real-name group)
11707                                       (car where)))
11708                         (not (gnus-server-equal gnus-override-method
11709                                                 (gnus-group-method group)))))
11710               ;; If we fetched by Message-ID and the article came from
11711               ;; a different group (or server), we fudge some bogus
11712               ;; article numbers for this article.
11713               (mail-header-set-number header gnus-reffed-article-number))
11714             (save-excursion
11715               (set-buffer gnus-summary-buffer)
11716               (decf gnus-reffed-article-number)
11717               (gnus-remove-header (mail-header-number header))
11718               (push header gnus-newsgroup-headers)
11719               (setq gnus-current-headers header)
11720               (push (mail-header-number header) gnus-newsgroup-limit)))
11721           header)))))
11722
11723 (defun gnus-remove-header (number)
11724   "Remove header NUMBER from `gnus-newsgroup-headers'."
11725   (if (and gnus-newsgroup-headers
11726            (= number (mail-header-number (car gnus-newsgroup-headers))))
11727       (pop gnus-newsgroup-headers)
11728     (let ((headers gnus-newsgroup-headers))
11729       (while (and (cdr headers)
11730                   (not (= number (mail-header-number (cadr headers)))))
11731         (pop headers))
11732       (when (cdr headers)
11733         (setcdr headers (cddr headers))))))
11734
11735 ;;;
11736 ;;; summary highlights
11737 ;;;
11738
11739 (defun gnus-highlight-selected-summary ()
11740   "Highlight selected article in summary buffer."
11741   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11742   (when gnus-summary-selected-face
11743     (save-excursion
11744       (let* ((beg (point-at-bol))
11745              (end (point-at-eol))
11746              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11747              (from (if (get-text-property beg gnus-mouse-face-prop)
11748                        beg
11749                      (or (next-single-property-change
11750                           beg gnus-mouse-face-prop nil end)
11751                          beg)))
11752              (to
11753               (if (= from end)
11754                   (- from 2)
11755                 (or (next-single-property-change
11756                      from gnus-mouse-face-prop nil end)
11757                     end))))
11758         ;; If no mouse-face prop on line we will have to = from = end,
11759         ;; so we highlight the entire line instead.
11760         (when (= (+ to 2) from)
11761           (setq from beg)
11762           (setq to end))
11763         (if gnus-newsgroup-selected-overlay
11764             ;; Move old overlay.
11765             (gnus-move-overlay
11766              gnus-newsgroup-selected-overlay from to (current-buffer))
11767           ;; Create new overlay.
11768           (gnus-overlay-put
11769            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11770            'face gnus-summary-selected-face))))))
11771
11772 (defvar gnus-summary-highlight-line-cached nil)
11773 (defvar gnus-summary-highlight-line-trigger nil)
11774
11775 (defun gnus-summary-highlight-line-0 ()
11776   (if (and (eq gnus-summary-highlight-line-trigger
11777                gnus-summary-highlight)
11778            gnus-summary-highlight-line-cached)
11779       gnus-summary-highlight-line-cached
11780     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11781           gnus-summary-highlight-line-cached
11782           (let* ((cond (list 'cond))
11783                  (c cond)
11784                  (list gnus-summary-highlight))
11785             (while list
11786               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11787                               nil))
11788               (setq c (cdr c)
11789                     list (cdr list)))
11790             (gnus-byte-compile (list 'lambda nil cond))))))
11791
11792 (defun gnus-summary-highlight-line ()
11793   "Highlight current line according to `gnus-summary-highlight'."
11794   (let* ((beg (point-at-bol))
11795          (article (or (gnus-summary-article-number) gnus-current-article))
11796          (score (or (cdr (assq article
11797                                gnus-newsgroup-scored))
11798                     gnus-summary-default-score 0))
11799          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11800          (inhibit-read-only t)
11801          (default gnus-summary-default-score)
11802          (default-high gnus-summary-default-high-score)
11803          (default-low gnus-summary-default-low-score)
11804          (uncached (and gnus-summary-use-undownloaded-faces
11805                         (memq article gnus-newsgroup-undownloaded)
11806                         (not (memq article gnus-newsgroup-cached)))))
11807     (let ((face (funcall (gnus-summary-highlight-line-0))))
11808       (unless (eq face (get-text-property beg 'face))
11809         (gnus-put-text-property-excluding-characters-with-faces
11810          beg (point-at-eol) 'face
11811          (setq face (if (boundp face) (symbol-value face) face)))
11812         (when gnus-summary-highlight-line-function
11813           (funcall gnus-summary-highlight-line-function article face))))))
11814
11815 (defun gnus-update-read-articles (group unread &optional compute)
11816   "Update the list of read articles in GROUP.
11817 UNREAD is a sorted list."
11818   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11819         (info (gnus-get-info group))
11820         (prev 1)
11821         read)
11822     (if (or (not info) (not active))
11823         ;; There is no info on this group if it was, in fact,
11824         ;; killed.  Gnus stores no information on killed groups, so
11825         ;; there's nothing to be done.
11826         ;; One could store the information somewhere temporarily,
11827         ;; perhaps...  Hmmm...
11828         ()
11829       ;; Remove any negative articles numbers.
11830       (while (and unread (< (car unread) 0))
11831         (setq unread (cdr unread)))
11832       ;; Remove any expired article numbers
11833       (while (and unread (< (car unread) (car active)))
11834         (setq unread (cdr unread)))
11835       ;; Compute the ranges of read articles by looking at the list of
11836       ;; unread articles.
11837       (while unread
11838         (when (/= (car unread) prev)
11839           (push (if (= prev (1- (car unread))) prev
11840                   (cons prev (1- (car unread))))
11841                 read))
11842         (setq prev (1+ (car unread)))
11843         (setq unread (cdr unread)))
11844       (when (<= prev (cdr active))
11845         (push (cons prev (cdr active)) read))
11846       (setq read (if (> (length read) 1) (nreverse read) read))
11847       (if compute
11848           read
11849         (save-excursion
11850           (let (setmarkundo)
11851             ;; Propagate the read marks to the backend.
11852             (when (gnus-check-backend-function 'request-set-mark group)
11853               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11854                     (add (gnus-remove-from-range read (gnus-info-read info))))
11855                 (when (or add del)
11856                   (unless (gnus-check-group group)
11857                     (error "Can't open server for %s" group))
11858                   (gnus-request-set-mark
11859                    group (delq nil (list (if add (list add 'add '(read)))
11860                                          (if del (list del 'del '(read))))))
11861                   (setq setmarkundo
11862                         `(gnus-request-set-mark
11863                           ,group
11864                           ',(delq nil (list
11865                                        (if del (list del 'add '(read)))
11866                                        (if add (list add 'del '(read))))))))))
11867             (set-buffer gnus-group-buffer)
11868             (gnus-undo-register
11869               `(progn
11870                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11871                  (gnus-info-set-read ',info ',(gnus-info-read info))
11872                  (gnus-get-unread-articles-in-group ',info
11873                                                     (gnus-active ,group))
11874                  (gnus-group-update-group ,group t)
11875                  ,setmarkundo))))
11876         ;; Enter this list into the group info.
11877         (gnus-info-set-read info read)
11878         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11879         (gnus-get-unread-articles-in-group info (gnus-active group))
11880         t))))
11881
11882 (defun gnus-offer-save-summaries ()
11883   "Offer to save all active summary buffers."
11884   (let (buffers)
11885     ;; Go through all buffers and find all summaries.
11886     (dolist (buffer (buffer-list))
11887       (when (and (setq buffer (buffer-name buffer))
11888                  (string-match "Summary" buffer)
11889                  (with-current-buffer buffer
11890                    ;; We check that this is, indeed, a summary buffer.
11891                    (and (eq major-mode 'gnus-summary-mode)
11892                         ;; Also make sure this isn't bogus.
11893                         gnus-newsgroup-prepared
11894                         ;; Also make sure that this isn't a
11895                         ;; dead summary buffer.
11896                         (not gnus-dead-summary-mode))))
11897         (push buffer buffers)))
11898     ;; Go through all these summary buffers and offer to save them.
11899     (when buffers
11900       (save-excursion
11901         (map-y-or-n-p
11902          "Update summary buffer %s? "
11903          (lambda (buf)
11904            (switch-to-buffer buf)
11905            (gnus-summary-exit))
11906          buffers)))))
11907
11908 (defun gnus-summary-setup-default-charset ()
11909   "Setup newsgroup default charset."
11910   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11911       (setq gnus-newsgroup-charset nil)
11912     (let* ((ignored-charsets
11913             (or gnus-newsgroup-ephemeral-ignored-charsets
11914                 (append
11915                  (and gnus-newsgroup-name
11916                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11917                  gnus-newsgroup-ignored-charsets))))
11918       (setq gnus-newsgroup-charset
11919             (or gnus-newsgroup-ephemeral-charset
11920                 (and gnus-newsgroup-name
11921                      (gnus-parameter-charset gnus-newsgroup-name))
11922                 gnus-default-charset))
11923       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11924            ignored-charsets))))
11925
11926 ;;;
11927 ;;; Mime Commands
11928 ;;;
11929
11930 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11931   "Display the current article buffer fully MIME-buttonized.
11932 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11933 treated as multipart/mixed."
11934   (interactive "P")
11935   (require 'gnus-art)
11936   (let ((gnus-unbuttonized-mime-types nil)
11937         (gnus-mime-display-multipart-as-mixed show-all-parts))
11938     (gnus-summary-show-article)))
11939
11940 (defun gnus-summary-repair-multipart (article)
11941   "Add a Content-Type header to a multipart article without one."
11942   (interactive (list (gnus-summary-article-number)))
11943   (gnus-with-article article
11944     (message-narrow-to-head)
11945     (message-remove-header "Mime-Version")
11946     (goto-char (point-max))
11947     (insert "Mime-Version: 1.0\n")
11948     (widen)
11949     (when (search-forward "\n--" nil t)
11950       (let ((separator (buffer-substring (point) (point-at-eol))))
11951         (message-narrow-to-head)
11952         (message-remove-header "Content-Type")
11953         (goto-char (point-max))
11954         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11955                         separator))
11956         (widen))))
11957   (let (gnus-mark-article-hook)
11958     (gnus-summary-select-article t t nil article)))
11959
11960 (defun gnus-summary-toggle-display-buttonized ()
11961   "Toggle the buttonizing of the article buffer."
11962   (interactive)
11963   (require 'gnus-art)
11964   (if (setq gnus-inhibit-mime-unbuttonizing
11965             (not gnus-inhibit-mime-unbuttonizing))
11966       (let ((gnus-unbuttonized-mime-types nil))
11967         (gnus-summary-show-article))
11968     (gnus-summary-show-article)))
11969
11970 ;;;
11971 ;;; Generic summary marking commands
11972 ;;;
11973
11974 (defvar gnus-summary-marking-alist
11975   '((read gnus-del-mark "d")
11976     (unread gnus-unread-mark "u")
11977     (ticked gnus-ticked-mark "!")
11978     (dormant gnus-dormant-mark "?")
11979     (expirable gnus-expirable-mark "e"))
11980   "An alist of names/marks/keystrokes.")
11981
11982 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11983 (defvar gnus-summary-mark-map)
11984
11985 (defun gnus-summary-make-all-marking-commands ()
11986   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11987   (dolist (elem gnus-summary-marking-alist)
11988     (apply 'gnus-summary-make-marking-command elem)))
11989
11990 (defun gnus-summary-make-marking-command (name mark keystroke)
11991   (let ((map (make-sparse-keymap)))
11992     (define-key gnus-summary-generic-mark-map keystroke map)
11993     (dolist (lway `((next "next" next nil "n")
11994                     (next-unread "next unread" next t "N")
11995                     (prev "previous" prev nil "p")
11996                     (prev-unread "previous unread" prev t "P")
11997                     (nomove "" nil nil ,keystroke)))
11998       (let ((func (gnus-summary-make-marking-command-1
11999                    mark (car lway) lway name)))
12000         (setq func (eval func))
12001         (define-key map (nth 4 lway) func)))))
12002
12003 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12004   `(defun ,(intern
12005             (format "gnus-summary-put-mark-as-%s%s"
12006                     name (if (eq way 'nomove)
12007                              ""
12008                            (concat "-" (symbol-name way)))))
12009      (n)
12010      ,(format
12011        "Mark the current article as %s%s.
12012 If N, the prefix, then repeat N times.
12013 If N is negative, move in reverse order.
12014 The difference between N and the actual number of articles marked is
12015 returned."
12016        name (cadr lway))
12017      (interactive "p")
12018      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12019
12020 (defun gnus-summary-generic-mark (n mark move unread)
12021   "Mark N articles with MARK."
12022   (unless (eq major-mode 'gnus-summary-mode)
12023     (error "This command can only be used in the summary buffer"))
12024   (gnus-summary-show-thread)
12025   (let ((nummove
12026          (cond
12027           ((eq move 'next) 1)
12028           ((eq move 'prev) -1)
12029           (t 0))))
12030     (if (zerop nummove)
12031         (setq n 1)
12032       (when (< n 0)
12033         (setq n (abs n)
12034               nummove (* -1 nummove))))
12035     (while (and (> n 0)
12036                 (gnus-summary-mark-article nil mark)
12037                 (zerop (gnus-summary-next-subject nummove unread t)))
12038       (setq n (1- n)))
12039     (when (/= 0 n)
12040       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12041     (gnus-summary-recenter)
12042     (gnus-summary-position-point)
12043     (gnus-set-mode-line 'summary)
12044     n))
12045
12046 (defun gnus-summary-insert-articles (articles)
12047   (when (setq articles
12048               (gnus-sorted-difference articles
12049                                       (mapcar (lambda (h)
12050                                                 (mail-header-number h))
12051                                               gnus-newsgroup-headers)))
12052     (setq gnus-newsgroup-headers
12053           (gnus-merge 'list
12054                       gnus-newsgroup-headers
12055                       (gnus-fetch-headers articles)
12056                       'gnus-article-sort-by-number))
12057     ;; Suppress duplicates?
12058     (when gnus-suppress-duplicates
12059       (gnus-dup-suppress-articles))
12060
12061     ;; We might want to build some more threads first.
12062     (when (and gnus-fetch-old-headers
12063                (eq gnus-headers-retrieved-by 'nov))
12064       (if (eq gnus-fetch-old-headers 'invisible)
12065           (gnus-build-all-threads)
12066         (gnus-build-old-threads)))
12067     ;; Let the Gnus agent mark articles as read.
12068     (when gnus-agent
12069       (gnus-agent-get-undownloaded-list))
12070     ;; Remove list identifiers from subject
12071     (when gnus-list-identifiers
12072       (gnus-summary-remove-list-identifiers))
12073     ;; First and last article in this newsgroup.
12074     (when gnus-newsgroup-headers
12075       (setq gnus-newsgroup-begin
12076             (mail-header-number (car gnus-newsgroup-headers))
12077             gnus-newsgroup-end
12078             (mail-header-number
12079              (gnus-last-element gnus-newsgroup-headers))))
12080     (when gnus-use-scoring
12081       (gnus-possibly-score-headers))))
12082
12083 (defun gnus-summary-insert-old-articles (&optional all)
12084   "Insert all old articles in this group.
12085 If ALL is non-nil, already read articles become readable.
12086 If ALL is a number, fetch this number of articles."
12087   (interactive "P")
12088   (prog1
12089       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12090             older len)
12091         (setq older
12092               ;; Some nntp servers lie about their active range.  When
12093               ;; this happens, the active range can be in the millions.
12094               ;; Use a compressed range to avoid creating a huge list.
12095               (gnus-range-difference (list gnus-newsgroup-active) old))
12096         (setq len (gnus-range-length older))
12097         (cond
12098          ((null older) nil)
12099          ((numberp all)
12100           (if (< all len)
12101               (let ((older-range (nreverse older)))
12102                 (setq older nil)
12103
12104                 (while (> all 0)
12105                   (let* ((r (pop older-range))
12106                          (min (if (numberp r) r (car r)))
12107                          (max (if (numberp r) r (cdr r))))
12108                     (while (and (<= min max)
12109                                 (> all 0))
12110                       (push max older)
12111                       (setq all (1- all)
12112                             max (1- max))))))
12113             (setq older (gnus-uncompress-range older))))
12114          (all
12115           (setq older (gnus-uncompress-range older)))
12116          (t
12117           (when (and (numberp gnus-large-newsgroup)
12118                    (> len gnus-large-newsgroup))
12119               (let* ((cursor-in-echo-area nil)
12120                      (initial (gnus-parameter-large-newsgroup-initial
12121                                gnus-newsgroup-name))
12122                      (input
12123                       (read-string
12124                        (format
12125                         "How many articles from %s (%s %d): "
12126                         (gnus-limit-string
12127                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12128                         (if initial "max" "default")
12129                         len)
12130                        (if initial
12131                            (cons (number-to-string initial)
12132                                  0)))))
12133                 (unless (string-match "^[ \t]*$" input)
12134                   (setq all (string-to-number input))
12135                   (if (< all len)
12136                       (let ((older-range (nreverse older)))
12137                         (setq older nil)
12138
12139                         (while (> all 0)
12140                           (let* ((r (pop older-range))
12141                                  (min (if (numberp r) r (car r)))
12142                                  (max (if (numberp r) r (cdr r))))
12143                             (while (and (<= min max)
12144                                         (> all 0))
12145                               (push max older)
12146                               (setq all (1- all)
12147                                     max (1- max))))))))))
12148           (setq older (gnus-uncompress-range older))))
12149         (if (not older)
12150             (message "No old news.")
12151           (gnus-summary-insert-articles older)
12152           (gnus-summary-limit (gnus-sorted-nunion old older))))
12153     (gnus-summary-position-point)))
12154
12155 (defun gnus-summary-insert-new-articles ()
12156   "Insert all new articles in this group."
12157   (interactive)
12158   (prog1
12159       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12160             (old-active gnus-newsgroup-active)
12161             (nnmail-fetched-sources (list t))
12162             i new)
12163         (setq gnus-newsgroup-active
12164               (gnus-activate-group gnus-newsgroup-name 'scan))
12165         (setq i (cdr gnus-newsgroup-active))
12166         (while (> i (cdr old-active))
12167           (push i new)
12168           (decf i))
12169         (if (not new)
12170             (message "No gnus is bad news")
12171           (gnus-summary-insert-articles new)
12172           (setq gnus-newsgroup-unreads
12173                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12174           (gnus-summary-limit (gnus-sorted-nunion old new))))
12175     (gnus-summary-position-point)))
12176
12177 (gnus-summary-make-all-marking-commands)
12178
12179 (gnus-ems-redefine)
12180
12181 (provide 'gnus-sum)
12182
12183 (run-hooks 'gnus-sum-load-hook)
12184
12185 ;; Local Variables:
12186 ;; coding: iso-8859-1
12187 ;; End:
12188
12189 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12190 ;;; gnus-sum.el ends here