* gnus-art.el (gnus-default-article-saver): Doc fix.
[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-auto-expire nil)
1326 (defvar gnus-newsgroup-active nil)
1327
1328 (defvar gnus-newsgroup-data nil)
1329 (defvar gnus-newsgroup-data-reverse nil)
1330 (defvar gnus-newsgroup-limit nil)
1331 (defvar gnus-newsgroup-limits nil)
1332 (defvar gnus-summary-use-undownloaded-faces nil)
1333
1334 (defvar gnus-newsgroup-unreads nil
1335   "Sorted list of unread articles in the current newsgroup.")
1336
1337 (defvar gnus-newsgroup-unselected nil
1338   "Sorted list of unselected unread articles in the current newsgroup.")
1339
1340 (defvar gnus-newsgroup-reads nil
1341   "Alist of read articles and article marks in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-expunged-tally nil)
1344
1345 (defvar gnus-newsgroup-marked nil
1346   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1347
1348 (defvar gnus-newsgroup-spam-marked nil
1349   "List of ranges of articles that have been marked as spam.")
1350
1351 (defvar gnus-newsgroup-killed nil
1352   "List of ranges of articles that have been through the scoring process.")
1353
1354 (defvar gnus-newsgroup-cached nil
1355   "Sorted list of articles that come from the article cache.")
1356
1357 (defvar gnus-newsgroup-saved nil
1358   "List of articles that have been saved.")
1359
1360 (defvar gnus-newsgroup-kill-headers nil)
1361
1362 (defvar gnus-newsgroup-replied nil
1363   "List of articles that have been replied to in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-forwarded nil
1366   "List of articles that have been forwarded in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-recent nil
1369   "List of articles that have are recent in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expirable nil
1372   "Sorted list of articles in the current newsgroup that can be expired.")
1373
1374 (defvar gnus-newsgroup-processable nil
1375   "List of articles in the current newsgroup that can be processed.")
1376
1377 (defvar gnus-newsgroup-downloadable nil
1378   "Sorted list of articles in the current newsgroup that can be processed.")
1379
1380 (defvar gnus-newsgroup-unfetched nil
1381   "Sorted list of articles in the current newsgroup whose headers have
1382 not been fetched into the agent.
1383
1384 This list will always be a subset of gnus-newsgroup-undownloaded.")
1385
1386 (defvar gnus-newsgroup-undownloaded nil
1387   "List of articles in the current newsgroup that haven't been downloaded.")
1388
1389 (defvar gnus-newsgroup-unsendable nil
1390   "List of articles in the current newsgroup that won't be sent.")
1391
1392 (defvar gnus-newsgroup-bookmarks nil
1393   "List of articles in the current newsgroup that have bookmarks.")
1394
1395 (defvar gnus-newsgroup-dormant nil
1396   "Sorted list of dormant articles in the current newsgroup.")
1397
1398 (defvar gnus-newsgroup-unseen nil
1399   "List of unseen articles in the current newsgroup.")
1400
1401 (defvar gnus-newsgroup-seen nil
1402   "Range of seen articles in the current newsgroup.")
1403
1404 (defvar gnus-newsgroup-articles nil
1405   "List of articles in the current newsgroup.")
1406
1407 (defvar gnus-newsgroup-scored nil
1408   "List of scored articles in the current newsgroup.")
1409
1410 (defvar gnus-newsgroup-headers nil
1411   "List of article headers in the current newsgroup.")
1412
1413 (defvar gnus-newsgroup-threads nil)
1414
1415 (defvar gnus-newsgroup-prepared nil
1416   "Whether the current group has been prepared properly.")
1417
1418 (defvar gnus-newsgroup-ancient nil
1419   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1420
1421 (defvar gnus-newsgroup-sparse nil)
1422
1423 (defvar gnus-current-article nil)
1424 (defvar gnus-article-current nil)
1425 (defvar gnus-current-headers nil)
1426 (defvar gnus-have-all-headers nil)
1427 (defvar gnus-last-article nil)
1428 (defvar gnus-newsgroup-history nil)
1429 (defvar gnus-newsgroup-charset nil)
1430 (defvar gnus-newsgroup-ephemeral-charset nil)
1431 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1432
1433 (defvar gnus-article-before-search nil)
1434
1435 (defvar gnus-summary-local-variables
1436   '(gnus-newsgroup-name
1437     gnus-newsgroup-begin gnus-newsgroup-end
1438     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1439     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1440     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1441     gnus-newsgroup-unselected gnus-newsgroup-marked
1442     gnus-newsgroup-spam-marked
1443     gnus-newsgroup-reads gnus-newsgroup-saved
1444     gnus-newsgroup-replied gnus-newsgroup-forwarded
1445     gnus-newsgroup-recent
1446     gnus-newsgroup-expirable
1447     gnus-newsgroup-processable gnus-newsgroup-killed
1448     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1449     gnus-newsgroup-unfetched
1450     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1451     gnus-newsgroup-seen gnus-newsgroup-articles
1452     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1453     gnus-newsgroup-headers gnus-newsgroup-threads
1454     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1455     gnus-current-article gnus-current-headers gnus-have-all-headers
1456     gnus-last-article gnus-article-internal-prepare-hook
1457     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1458     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1459     gnus-thread-expunge-below
1460     gnus-score-alist gnus-current-score-file
1461     (gnus-summary-expunge-below . global)
1462     (gnus-summary-mark-below . global)
1463     (gnus-orphan-score . global)
1464     gnus-newsgroup-active gnus-scores-exclude-files
1465     gnus-newsgroup-history gnus-newsgroup-ancient
1466     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1467     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1468     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1469     (gnus-newsgroup-expunged-tally . 0)
1470     gnus-cache-removable-articles gnus-newsgroup-cached
1471     gnus-newsgroup-data gnus-newsgroup-data-reverse
1472     gnus-newsgroup-limit gnus-newsgroup-limits
1473     gnus-newsgroup-charset gnus-newsgroup-display
1474     gnus-summary-use-undownloaded-faces)
1475   "Variables that are buffer-local to the summary buffers.")
1476
1477 (defvar gnus-newsgroup-variables nil
1478   "A list of variables that have separate values in different newsgroups.
1479 A list of newsgroup (summary buffer) local variables, or cons of
1480 variables and their default expressions to be evalled (when the default
1481 values are not nil), that should be made global while the summary buffer
1482 is active.
1483
1484 Note: The default expressions will be evaluated (using function `eval')
1485 before assignment to the local variable rather than just assigned to it.
1486 If the default expression is the symbol `global', that symbol will not
1487 be evaluated but the global value of the local variable will be used
1488 instead.
1489
1490 These variables can be used to set variables in the group parameters
1491 while still allowing them to affect operations done in other buffers.
1492 For example:
1493
1494 \(setq gnus-newsgroup-variables
1495      '(message-use-followup-to
1496        (gnus-visible-headers .
1497          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1498 ")
1499
1500 ;; Byte-compiler warning.
1501 (eval-when-compile
1502   ;; Bind features so that require will believe that gnus-sum has
1503   ;; already been loaded (avoids infinite recursion)
1504   (let ((features (cons 'gnus-sum features)))
1505     ;; Several of the declarations in gnus-sum are needed to load the
1506     ;; following files. Right now, these definitions have been
1507     ;; compiled but not defined (evaluated).  We could either do a
1508     ;; eval-and-compile about all of the declarations or evaluate the
1509     ;; source file.
1510     (if (boundp 'gnus-newsgroup-variables)
1511         nil
1512       (load "gnus-sum.el" t t t))
1513     (require 'gnus)
1514     (require 'gnus-art)))
1515
1516 ;; MIME stuff.
1517
1518 (defvar gnus-decode-encoded-word-methods
1519   '(mail-decode-encoded-word-string)
1520   "List of methods used to decode encoded words.
1521
1522 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1523 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1524 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1525 whose names match REGEXP.
1526
1527 For example:
1528 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1529  mail-decode-encoded-word-string
1530  (\"chinese\" . rfc1843-decode-string))")
1531
1532 (defvar gnus-decode-encoded-word-methods-cache nil)
1533
1534 (defun gnus-multi-decode-encoded-word-string (string)
1535   "Apply the functions from `gnus-encoded-word-methods' that match."
1536   (unless (and gnus-decode-encoded-word-methods-cache
1537                (eq gnus-newsgroup-name
1538                    (car gnus-decode-encoded-word-methods-cache)))
1539     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1540     (mapcar (lambda (x)
1541               (if (symbolp x)
1542                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1543                 (if (and gnus-newsgroup-name
1544                          (string-match (car x) gnus-newsgroup-name))
1545                     (nconc gnus-decode-encoded-word-methods-cache
1546                            (list (cdr x))))))
1547             gnus-decode-encoded-word-methods))
1548   (let ((xlist gnus-decode-encoded-word-methods-cache))
1549     (pop xlist)
1550     (while xlist
1551       (setq string (funcall (pop xlist) string))))
1552   string)
1553
1554 ;; Subject simplification.
1555
1556 (defun gnus-simplify-whitespace (str)
1557   "Remove excessive whitespace from STR."
1558   ;; Multiple spaces.
1559   (while (string-match "[ \t][ \t]+" str)
1560     (setq str (concat (substring str 0 (match-beginning 0))
1561                         " "
1562                         (substring str (match-end 0)))))
1563   ;; Leading spaces.
1564   (when (string-match "^[ \t]+" str)
1565     (setq str (substring str (match-end 0))))
1566   ;; Trailing spaces.
1567   (when (string-match "[ \t]+$" str)
1568     (setq str (substring str 0 (match-beginning 0))))
1569   str)
1570
1571 (defun gnus-simplify-all-whitespace (str)
1572   "Remove all whitespace from STR."
1573   (while (string-match "[ \t\n]+" str)
1574     (setq str (replace-match "" nil nil str)))
1575   str)
1576
1577 (defsubst gnus-simplify-subject-re (subject)
1578   "Remove \"Re:\" from subject lines."
1579   (if (string-match message-subject-re-regexp subject)
1580       (substring subject (match-end 0))
1581     subject))
1582
1583 (defun gnus-simplify-subject (subject &optional re-only)
1584   "Remove `Re:' and words in parentheses.
1585 If RE-ONLY is non-nil, strip leading `Re:'s only."
1586   (let ((case-fold-search t))           ;Ignore case.
1587     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1588     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1589       (setq subject (substring subject (match-end 0))))
1590     ;; Remove uninteresting prefixes.
1591     (when (and (not re-only)
1592                gnus-simplify-ignored-prefixes
1593                (string-match gnus-simplify-ignored-prefixes subject))
1594       (setq subject (substring subject (match-end 0))))
1595     ;; Remove words in parentheses from end.
1596     (unless re-only
1597       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1598         (setq subject (substring subject 0 (match-beginning 0)))))
1599     ;; Return subject string.
1600     subject))
1601
1602 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1603 ;; all whitespace.
1604 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1605   (goto-char (point-min))
1606   (while (re-search-forward regexp nil t)
1607     (replace-match (or newtext ""))))
1608
1609 (defun gnus-simplify-buffer-fuzzy ()
1610   "Simplify string in the buffer fuzzily.
1611 The string in the accessible portion of the current buffer is simplified.
1612 It is assumed to be a single-line subject.
1613 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1614 matter is removed.  Additional things can be deleted by setting
1615 `gnus-simplify-subject-fuzzy-regexp'."
1616   (let ((case-fold-search t)
1617         (modified-tick))
1618     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1619
1620     (while (not (eq modified-tick (buffer-modified-tick)))
1621       (setq modified-tick (buffer-modified-tick))
1622       (cond
1623        ((listp gnus-simplify-subject-fuzzy-regexp)
1624         (mapcar 'gnus-simplify-buffer-fuzzy-step
1625                 gnus-simplify-subject-fuzzy-regexp))
1626        (gnus-simplify-subject-fuzzy-regexp
1627         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1628       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1629       (gnus-simplify-buffer-fuzzy-step
1630        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1631       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1632
1633     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1634     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1635     (gnus-simplify-buffer-fuzzy-step " $")
1636     (gnus-simplify-buffer-fuzzy-step "^ +")))
1637
1638 (defun gnus-simplify-subject-fuzzy (subject)
1639   "Simplify a subject string fuzzily.
1640 See `gnus-simplify-buffer-fuzzy' for details."
1641   (save-excursion
1642     (gnus-set-work-buffer)
1643     (let ((case-fold-search t))
1644       ;; Remove uninteresting prefixes.
1645       (when (and gnus-simplify-ignored-prefixes
1646                  (string-match gnus-simplify-ignored-prefixes subject))
1647         (setq subject (substring subject (match-end 0))))
1648       (insert subject)
1649       (inline (gnus-simplify-buffer-fuzzy))
1650       (buffer-string))))
1651
1652 (defsubst gnus-simplify-subject-fully (subject)
1653   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1654   (cond
1655    (gnus-simplify-subject-functions
1656     (gnus-map-function gnus-simplify-subject-functions subject))
1657    ((null gnus-summary-gather-subject-limit)
1658     (gnus-simplify-subject-re subject))
1659    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1660     (gnus-simplify-subject-fuzzy subject))
1661    ((numberp gnus-summary-gather-subject-limit)
1662     (gnus-limit-string (gnus-simplify-subject-re subject)
1663                        gnus-summary-gather-subject-limit))
1664    (t
1665     subject)))
1666
1667 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1668   "Check whether two subjects are equal.
1669 If optional argument SIMPLE-FIRST is t, first argument is already
1670 simplified."
1671   (cond
1672    ((null simple-first)
1673     (equal (gnus-simplify-subject-fully s1)
1674            (gnus-simplify-subject-fully s2)))
1675    (t
1676     (equal s1
1677            (gnus-simplify-subject-fully s2)))))
1678
1679 (defun gnus-summary-bubble-group ()
1680   "Increase the score of the current group.
1681 This is a handy function to add to `gnus-summary-exit-hook' to
1682 increase the score of each group you read."
1683   (gnus-group-add-score gnus-newsgroup-name))
1684
1685 \f
1686 ;;;
1687 ;;; Gnus summary mode
1688 ;;;
1689
1690 (put 'gnus-summary-mode 'mode-class 'special)
1691
1692 (defvar gnus-article-commands-menu)
1693
1694 ;; Non-orthogonal keys
1695
1696 (gnus-define-keys gnus-summary-mode-map
1697   " " gnus-summary-next-page
1698   "\177" gnus-summary-prev-page
1699   [delete] gnus-summary-prev-page
1700   [backspace] gnus-summary-prev-page
1701   "\r" gnus-summary-scroll-up
1702   "\M-\r" gnus-summary-scroll-down
1703   "n" gnus-summary-next-unread-article
1704   "p" gnus-summary-prev-unread-article
1705   "N" gnus-summary-next-article
1706   "P" gnus-summary-prev-article
1707   "\M-\C-n" gnus-summary-next-same-subject
1708   "\M-\C-p" gnus-summary-prev-same-subject
1709   "\M-n" gnus-summary-next-unread-subject
1710   "\M-p" gnus-summary-prev-unread-subject
1711   "." gnus-summary-first-unread-article
1712   "," gnus-summary-best-unread-article
1713   "\M-s" gnus-summary-search-article-forward
1714   "\M-r" gnus-summary-search-article-backward
1715   "\M-S" gnus-summary-repeat-search-article-forward
1716   "\M-R" gnus-summary-repeat-search-article-backward
1717   "<" gnus-summary-beginning-of-article
1718   ">" gnus-summary-end-of-article
1719   "j" gnus-summary-goto-article
1720   "^" gnus-summary-refer-parent-article
1721   "\M-^" gnus-summary-refer-article
1722   "u" gnus-summary-tick-article-forward
1723   "!" gnus-summary-tick-article-forward
1724   "U" gnus-summary-tick-article-backward
1725   "d" gnus-summary-mark-as-read-forward
1726   "D" gnus-summary-mark-as-read-backward
1727   "E" gnus-summary-mark-as-expirable
1728   "\M-u" gnus-summary-clear-mark-forward
1729   "\M-U" gnus-summary-clear-mark-backward
1730   "k" gnus-summary-kill-same-subject-and-select
1731   "\C-k" gnus-summary-kill-same-subject
1732   "\M-\C-k" gnus-summary-kill-thread
1733   "\M-\C-l" gnus-summary-lower-thread
1734   "e" gnus-summary-edit-article
1735   "#" gnus-summary-mark-as-processable
1736   "\M-#" gnus-summary-unmark-as-processable
1737   "\M-\C-t" gnus-summary-toggle-threads
1738   "\M-\C-s" gnus-summary-show-thread
1739   "\M-\C-h" gnus-summary-hide-thread
1740   "\M-\C-f" gnus-summary-next-thread
1741   "\M-\C-b" gnus-summary-prev-thread
1742   [(meta down)] gnus-summary-next-thread
1743   [(meta up)] gnus-summary-prev-thread
1744   "\M-\C-u" gnus-summary-up-thread
1745   "\M-\C-d" gnus-summary-down-thread
1746   "&" gnus-summary-execute-command
1747   "c" gnus-summary-catchup-and-exit
1748   "\C-w" gnus-summary-mark-region-as-read
1749   "\C-t" gnus-summary-toggle-truncation
1750   "?" gnus-summary-mark-as-dormant
1751   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1752   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1753   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1754   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1755   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1756   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1757   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1758   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1759   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1760   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1761   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1762   "=" gnus-summary-expand-window
1763   "\C-x\C-s" gnus-summary-reselect-current-group
1764   "\M-g" gnus-summary-rescan-group
1765   "w" gnus-summary-stop-page-breaking
1766   "\C-c\C-r" gnus-summary-caesar-message
1767   "f" gnus-summary-followup
1768   "F" gnus-summary-followup-with-original
1769   "C" gnus-summary-cancel-article
1770   "r" gnus-summary-reply
1771   "R" gnus-summary-reply-with-original
1772   "\C-c\C-f" gnus-summary-mail-forward
1773   "o" gnus-summary-save-article
1774   "\C-o" gnus-summary-save-article-mail
1775   "|" gnus-summary-pipe-output
1776   "\M-k" gnus-summary-edit-local-kill
1777   "\M-K" gnus-summary-edit-global-kill
1778   ;; "V" gnus-version
1779   "\C-c\C-d" gnus-summary-describe-group
1780   "q" gnus-summary-exit
1781   "Q" gnus-summary-exit-no-update
1782   "\C-c\C-i" gnus-info-find-node
1783   gnus-mouse-2 gnus-mouse-pick-article
1784   [follow-link] mouse-face
1785   "m" gnus-summary-mail-other-window
1786   "a" gnus-summary-post-news
1787   "i" gnus-summary-news-other-window
1788   "x" gnus-summary-limit-to-unread
1789   "s" gnus-summary-isearch-article
1790   "t" gnus-summary-toggle-header
1791   "g" gnus-summary-show-article
1792   "l" gnus-summary-goto-last-article
1793   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1794   "\C-d" gnus-summary-enter-digest-group
1795   "\M-\C-d" gnus-summary-read-document
1796   "\M-\C-e" gnus-summary-edit-parameters
1797   "\M-\C-a" gnus-summary-customize-parameters
1798   "\C-c\C-b" gnus-bug
1799   "*" gnus-cache-enter-article
1800   "\M-*" gnus-cache-remove-article
1801   "\M-&" gnus-summary-universal-argument
1802   "\C-l" gnus-recenter
1803   "I" gnus-summary-increase-score
1804   "L" gnus-summary-lower-score
1805   "\M-i" gnus-symbolic-argument
1806   "h" gnus-summary-select-article-buffer
1807
1808   "b" gnus-article-view-part
1809   "\M-t" gnus-summary-toggle-display-buttonized
1810
1811   "V" gnus-summary-score-map
1812   "X" gnus-uu-extract-map
1813   "S" gnus-summary-send-map)
1814
1815 ;; Sort of orthogonal keymap
1816 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1817   "t" gnus-summary-tick-article-forward
1818   "!" gnus-summary-tick-article-forward
1819   "d" gnus-summary-mark-as-read-forward
1820   "r" gnus-summary-mark-as-read-forward
1821   "c" gnus-summary-clear-mark-forward
1822   " " gnus-summary-clear-mark-forward
1823   "e" gnus-summary-mark-as-expirable
1824   "x" gnus-summary-mark-as-expirable
1825   "?" gnus-summary-mark-as-dormant
1826   "b" gnus-summary-set-bookmark
1827   "B" gnus-summary-remove-bookmark
1828   "#" gnus-summary-mark-as-processable
1829   "\M-#" gnus-summary-unmark-as-processable
1830   "S" gnus-summary-limit-include-expunged
1831   "C" gnus-summary-catchup
1832   "H" gnus-summary-catchup-to-here
1833   "h" gnus-summary-catchup-from-here
1834   "\C-c" gnus-summary-catchup-all
1835   "k" gnus-summary-kill-same-subject-and-select
1836   "K" gnus-summary-kill-same-subject
1837   "P" gnus-uu-mark-map)
1838
1839 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1840   "c" gnus-summary-clear-above
1841   "u" gnus-summary-tick-above
1842   "m" gnus-summary-mark-above
1843   "k" gnus-summary-kill-below)
1844
1845 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1846   "/" gnus-summary-limit-to-subject
1847   "n" gnus-summary-limit-to-articles
1848   "b" gnus-summary-limit-to-bodies
1849   "w" gnus-summary-pop-limit
1850   "s" gnus-summary-limit-to-subject
1851   "a" gnus-summary-limit-to-author
1852   "u" gnus-summary-limit-to-unread
1853   "m" gnus-summary-limit-to-marks
1854   "M" gnus-summary-limit-exclude-marks
1855   "v" gnus-summary-limit-to-score
1856   "*" gnus-summary-limit-include-cached
1857   "D" gnus-summary-limit-include-dormant
1858   "T" gnus-summary-limit-include-thread
1859   "d" gnus-summary-limit-exclude-dormant
1860   "t" gnus-summary-limit-to-age
1861   "." gnus-summary-limit-to-unseen
1862   "x" gnus-summary-limit-to-extra
1863   "p" gnus-summary-limit-to-display-predicate
1864   "E" gnus-summary-limit-include-expunged
1865   "c" gnus-summary-limit-exclude-childless-dormant
1866   "C" gnus-summary-limit-mark-excluded-as-read
1867   "o" gnus-summary-insert-old-articles
1868   "N" gnus-summary-insert-new-articles
1869   "r" gnus-summary-limit-to-replied
1870   "R" gnus-summary-limit-to-recipient)
1871
1872 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1873   "n" gnus-summary-next-unread-article
1874   "p" gnus-summary-prev-unread-article
1875   "N" gnus-summary-next-article
1876   "P" gnus-summary-prev-article
1877   "\C-n" gnus-summary-next-same-subject
1878   "\C-p" gnus-summary-prev-same-subject
1879   "\M-n" gnus-summary-next-unread-subject
1880   "\M-p" gnus-summary-prev-unread-subject
1881   "f" gnus-summary-first-unread-article
1882   "b" gnus-summary-best-unread-article
1883   "j" gnus-summary-goto-article
1884   "g" gnus-summary-goto-subject
1885   "l" gnus-summary-goto-last-article
1886   "o" gnus-summary-pop-article)
1887
1888 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1889   "k" gnus-summary-kill-thread
1890   "l" gnus-summary-lower-thread
1891   "i" gnus-summary-raise-thread
1892   "T" gnus-summary-toggle-threads
1893   "t" gnus-summary-rethread-current
1894   "^" gnus-summary-reparent-thread
1895   "\M-^" gnus-summary-reparent-children
1896   "s" gnus-summary-show-thread
1897   "S" gnus-summary-show-all-threads
1898   "h" gnus-summary-hide-thread
1899   "H" gnus-summary-hide-all-threads
1900   "n" gnus-summary-next-thread
1901   "p" gnus-summary-prev-thread
1902   "u" gnus-summary-up-thread
1903   "o" gnus-summary-top-thread
1904   "d" gnus-summary-down-thread
1905   "#" gnus-uu-mark-thread
1906   "\M-#" gnus-uu-unmark-thread)
1907
1908 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1909   "g" gnus-summary-prepare
1910   "c" gnus-summary-insert-cached-articles
1911   "d" gnus-summary-insert-dormant-articles)
1912
1913 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1914   "c" gnus-summary-catchup-and-exit
1915   "C" gnus-summary-catchup-all-and-exit
1916   "E" gnus-summary-exit-no-update
1917   "Q" gnus-summary-exit
1918   "Z" gnus-summary-exit
1919   "n" gnus-summary-catchup-and-goto-next-group
1920   "p" gnus-summary-catchup-and-goto-prev-group
1921   "R" gnus-summary-reselect-current-group
1922   "G" gnus-summary-rescan-group
1923   "N" gnus-summary-next-group
1924   "s" gnus-summary-save-newsrc
1925   "P" gnus-summary-prev-group)
1926
1927 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1928   " " gnus-summary-next-page
1929   "n" gnus-summary-next-page
1930   "\177" gnus-summary-prev-page
1931   [delete] gnus-summary-prev-page
1932   "p" gnus-summary-prev-page
1933   "\r" gnus-summary-scroll-up
1934   "\M-\r" gnus-summary-scroll-down
1935   "<" gnus-summary-beginning-of-article
1936   ">" gnus-summary-end-of-article
1937   "b" gnus-summary-beginning-of-article
1938   "e" gnus-summary-end-of-article
1939   "^" gnus-summary-refer-parent-article
1940   "r" gnus-summary-refer-parent-article
1941   "D" gnus-summary-enter-digest-group
1942   "R" gnus-summary-refer-references
1943   "T" gnus-summary-refer-thread
1944   "g" gnus-summary-show-article
1945   "s" gnus-summary-isearch-article
1946   "P" gnus-summary-print-article
1947   "M" gnus-mailing-list-insinuate
1948   "t" gnus-article-babel)
1949
1950 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1951   "b" gnus-article-add-buttons
1952   "B" gnus-article-add-buttons-to-head
1953   "o" gnus-article-treat-overstrike
1954   "e" gnus-article-emphasize
1955   "w" gnus-article-fill-cited-article
1956   "Q" gnus-article-fill-long-lines
1957   "C" gnus-article-capitalize-sentences
1958   "c" gnus-article-remove-cr
1959   "q" gnus-article-de-quoted-unreadable
1960   "6" gnus-article-de-base64-unreadable
1961   "Z" gnus-article-decode-HZ
1962   "A" gnus-article-treat-ansi-sequences
1963   "h" gnus-article-wash-html
1964   "u" gnus-article-unsplit-urls
1965   "s" gnus-summary-force-verify-and-decrypt
1966   "f" gnus-article-display-x-face
1967   "l" gnus-summary-stop-page-breaking
1968   "r" gnus-summary-caesar-message
1969   "m" gnus-summary-morse-message
1970   "t" gnus-summary-toggle-header
1971   "g" gnus-treat-smiley
1972   "v" gnus-summary-verbose-headers
1973   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1974   "p" gnus-article-verify-x-pgp-sig
1975   "d" gnus-article-treat-dumbquotes
1976   "i" gnus-summary-idna-message)
1977
1978 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1979   ;; mnemonic: deuglif*Y*
1980   "u" gnus-article-outlook-unwrap-lines
1981   "a" gnus-article-outlook-repair-attribution
1982   "c" gnus-article-outlook-rearrange-citation
1983   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1984
1985 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1986   "a" gnus-article-hide
1987   "h" gnus-article-hide-headers
1988   "b" gnus-article-hide-boring-headers
1989   "s" gnus-article-hide-signature
1990   "c" gnus-article-hide-citation
1991   "C" gnus-article-hide-citation-in-followups
1992   "l" gnus-article-hide-list-identifiers
1993   "B" gnus-article-strip-banner
1994   "P" gnus-article-hide-pem
1995   "\C-c" gnus-article-hide-citation-maybe)
1996
1997 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1998   "a" gnus-article-highlight
1999   "h" gnus-article-highlight-headers
2000   "c" gnus-article-highlight-citation
2001   "s" gnus-article-highlight-signature)
2002
2003 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2004   "f" gnus-article-treat-fold-headers
2005   "u" gnus-article-treat-unfold-headers
2006   "n" gnus-article-treat-fold-newsgroups)
2007
2008 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2009   "x" gnus-article-display-x-face
2010   "d" gnus-article-display-face
2011   "s" gnus-treat-smiley
2012   "D" gnus-article-remove-images
2013   "f" gnus-treat-from-picon
2014   "m" gnus-treat-mail-picon
2015   "n" gnus-treat-newsgroups-picon)
2016
2017 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2018   "w" gnus-article-decode-mime-words
2019   "c" gnus-article-decode-charset
2020   "v" gnus-mime-view-all-parts
2021   "b" gnus-article-view-part)
2022
2023 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2024   "z" gnus-article-date-ut
2025   "u" gnus-article-date-ut
2026   "l" gnus-article-date-local
2027   "p" gnus-article-date-english
2028   "e" gnus-article-date-lapsed
2029   "o" gnus-article-date-original
2030   "i" gnus-article-date-iso8601
2031   "s" gnus-article-date-user)
2032
2033 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2034   "t" gnus-article-remove-trailing-blank-lines
2035   "l" gnus-article-strip-leading-blank-lines
2036   "m" gnus-article-strip-multiple-blank-lines
2037   "a" gnus-article-strip-blank-lines
2038   "A" gnus-article-strip-all-blank-lines
2039   "s" gnus-article-strip-leading-space
2040   "e" gnus-article-strip-trailing-space
2041   "w" gnus-article-remove-leading-whitespace)
2042
2043 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2044   "v" gnus-version
2045   "f" gnus-summary-fetch-faq
2046   "d" gnus-summary-describe-group
2047   "h" gnus-summary-describe-briefly
2048   "i" gnus-info-find-node
2049   "c" gnus-group-fetch-charter
2050   "C" gnus-group-fetch-control)
2051
2052 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2053   "e" gnus-summary-expire-articles
2054   "\M-\C-e" gnus-summary-expire-articles-now
2055   "\177" gnus-summary-delete-article
2056   [delete] gnus-summary-delete-article
2057   [backspace] gnus-summary-delete-article
2058   "m" gnus-summary-move-article
2059   "r" gnus-summary-respool-article
2060   "w" gnus-summary-edit-article
2061   "c" gnus-summary-copy-article
2062   "B" gnus-summary-crosspost-article
2063   "q" gnus-summary-respool-query
2064   "t" gnus-summary-respool-trace
2065   "i" gnus-summary-import-article
2066   "I" gnus-summary-create-article
2067   "p" gnus-summary-article-posted-p)
2068
2069 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2070   "o" gnus-summary-save-article
2071   "m" gnus-summary-save-article-mail
2072   "F" gnus-summary-write-article-file
2073   "r" gnus-summary-save-article-rmail
2074   "f" gnus-summary-save-article-file
2075   "b" gnus-summary-save-article-body-file
2076   "h" gnus-summary-save-article-folder
2077   "v" gnus-summary-save-article-vm
2078   "p" gnus-summary-pipe-output
2079   "P" gnus-summary-muttprint
2080   "s" gnus-soup-add-article)
2081
2082 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2083   "b" gnus-summary-display-buttonized
2084   "m" gnus-summary-repair-multipart
2085   "v" gnus-article-view-part
2086   "o" gnus-article-save-part
2087   "O" gnus-article-save-part-and-strip
2088   "r" gnus-article-replace-part
2089   "d" gnus-article-delete-part
2090   "t" gnus-article-view-part-as-type
2091   "j" gnus-article-jump-to-part
2092   "c" gnus-article-copy-part
2093   "C" gnus-article-view-part-as-charset
2094   "e" gnus-article-view-part-externally
2095   "H" gnus-article-browse-html-article
2096   "E" gnus-article-encrypt-body
2097   "i" gnus-article-inline-part
2098   "|" gnus-article-pipe-part)
2099
2100 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2101   "p" gnus-summary-mark-as-processable
2102   "u" gnus-summary-unmark-as-processable
2103   "U" gnus-summary-unmark-all-processable
2104   "v" gnus-uu-mark-over
2105   "s" gnus-uu-mark-series
2106   "r" gnus-uu-mark-region
2107   "g" gnus-uu-unmark-region
2108   "R" gnus-uu-mark-by-regexp
2109   "G" gnus-uu-unmark-by-regexp
2110   "t" gnus-uu-mark-thread
2111   "T" gnus-uu-unmark-thread
2112   "a" gnus-uu-mark-all
2113   "b" gnus-uu-mark-buffer
2114   "S" gnus-uu-mark-sparse
2115   "k" gnus-summary-kill-process-mark
2116   "y" gnus-summary-yank-process-mark
2117   "w" gnus-summary-save-process-mark
2118   "i" gnus-uu-invert-processable)
2119
2120 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2121   ;;"x" gnus-uu-extract-any
2122   "m" gnus-summary-save-parts
2123   "u" gnus-uu-decode-uu
2124   "U" gnus-uu-decode-uu-and-save
2125   "s" gnus-uu-decode-unshar
2126   "S" gnus-uu-decode-unshar-and-save
2127   "o" gnus-uu-decode-save
2128   "O" gnus-uu-decode-save
2129   "b" gnus-uu-decode-binhex
2130   "B" gnus-uu-decode-binhex
2131   "p" gnus-uu-decode-postscript
2132   "P" gnus-uu-decode-postscript-and-save)
2133
2134 (gnus-define-keys
2135     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2136   "u" gnus-uu-decode-uu-view
2137   "U" gnus-uu-decode-uu-and-save-view
2138   "s" gnus-uu-decode-unshar-view
2139   "S" gnus-uu-decode-unshar-and-save-view
2140   "o" gnus-uu-decode-save-view
2141   "O" gnus-uu-decode-save-view
2142   "b" gnus-uu-decode-binhex-view
2143   "B" gnus-uu-decode-binhex-view
2144   "p" gnus-uu-decode-postscript-view
2145   "P" gnus-uu-decode-postscript-and-save-view)
2146
2147 (defvar gnus-article-post-menu nil)
2148
2149 (defconst gnus-summary-menu-maxlen 20)
2150
2151 (defun gnus-summary-menu-split (menu)
2152   ;; If we have lots of elements, divide them into groups of 20
2153   ;; and make a pane (or submenu) for each one.
2154   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2155       (let ((menu menu) sublists next
2156             (i 1))
2157         (while menu
2158           ;; Pull off the next gnus-summary-menu-maxlen elements
2159           ;; and make them the next element of sublist.
2160           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2161           (if next
2162               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2163                       nil))
2164           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2165                                              (aref (car (last menu)) 0)) menu)
2166                                sublists))
2167           (setq i (1+ i))
2168           (setq menu next))
2169         (nreverse sublists))
2170     ;; Few elements--put them all in one pane.
2171     menu))
2172
2173 (defun gnus-summary-make-menu-bar ()
2174   (gnus-turn-off-edit-menu 'summary)
2175
2176   (unless (boundp 'gnus-summary-misc-menu)
2177
2178     (easy-menu-define
2179       gnus-summary-kill-menu gnus-summary-mode-map ""
2180       (cons
2181        "Score"
2182        (nconc
2183         (list
2184          ["Customize" gnus-score-customize t])
2185         (gnus-make-score-map 'increase)
2186         (gnus-make-score-map 'lower)
2187         '(("Mark"
2188            ["Kill below" gnus-summary-kill-below t]
2189            ["Mark above" gnus-summary-mark-above t]
2190            ["Tick above" gnus-summary-tick-above t]
2191            ["Clear above" gnus-summary-clear-above t])
2192           ["Current score" gnus-summary-current-score t]
2193           ["Set score" gnus-summary-set-score t]
2194           ["Switch current score file..." gnus-score-change-score-file t]
2195           ["Set mark below..." gnus-score-set-mark-below t]
2196           ["Set expunge below..." gnus-score-set-expunge-below t]
2197           ["Edit current score file" gnus-score-edit-current-scores t]
2198           ["Edit score file" gnus-score-edit-file t]
2199           ["Trace score" gnus-score-find-trace t]
2200           ["Find words" gnus-score-find-favourite-words t]
2201           ["Rescore buffer" gnus-summary-rescore t]
2202           ["Increase score..." gnus-summary-increase-score t]
2203           ["Lower score..." gnus-summary-lower-score t]))))
2204
2205     ;; Define both the Article menu in the summary buffer and the
2206     ;; equivalent Commands menu in the article buffer here for
2207     ;; consistency.
2208     (let ((innards
2209            `(("Hide"
2210               ["All" gnus-article-hide t]
2211               ["Headers" gnus-article-hide-headers t]
2212               ["Signature" gnus-article-hide-signature t]
2213               ["Citation" gnus-article-hide-citation t]
2214               ["List identifiers" gnus-article-hide-list-identifiers t]
2215               ["Banner" gnus-article-strip-banner t]
2216               ["Boring headers" gnus-article-hide-boring-headers t])
2217              ("Highlight"
2218               ["All" gnus-article-highlight t]
2219               ["Headers" gnus-article-highlight-headers t]
2220               ["Signature" gnus-article-highlight-signature t]
2221               ["Citation" gnus-article-highlight-citation t])
2222              ("MIME"
2223               ["Words" gnus-article-decode-mime-words t]
2224               ["Charset" gnus-article-decode-charset t]
2225               ["QP" gnus-article-de-quoted-unreadable t]
2226               ["Base64" gnus-article-de-base64-unreadable t]
2227               ["View MIME buttons" gnus-summary-display-buttonized t]
2228               ["View all" gnus-mime-view-all-parts t]
2229               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2230               ["Encrypt body" gnus-article-encrypt-body
2231                :active (not (gnus-group-read-only-p))
2232                ,@(if (featurep 'xemacs) nil
2233                    '(:help "Encrypt the message body on disk"))]
2234               ["Extract all parts..." gnus-summary-save-parts t]
2235               ("Multipart"
2236                ["Repair multipart" gnus-summary-repair-multipart t]
2237                ["Pipe part..." gnus-article-pipe-part t]
2238                ["Inline part" gnus-article-inline-part t]
2239                ["View part as type..." gnus-article-view-part-as-type t]
2240                ["Encrypt body" gnus-article-encrypt-body
2241                 :active (not (gnus-group-read-only-p))
2242                ,@(if (featurep 'xemacs) nil
2243                    '(:help "Encrypt the message body on disk"))]
2244                ["View part externally" gnus-article-view-part-externally t]
2245                ["View HTML parts in browser" gnus-article-browse-html-article t]
2246                ["View part with charset..." gnus-article-view-part-as-charset t]
2247                ["Copy part" gnus-article-copy-part t]
2248                ["Save part..." gnus-article-save-part t]
2249                ["View part" gnus-article-view-part t]))
2250              ("Date"
2251               ["Local" gnus-article-date-local t]
2252               ["ISO8601" gnus-article-date-iso8601 t]
2253               ["UT" gnus-article-date-ut t]
2254               ["Original" gnus-article-date-original t]
2255               ["Lapsed" gnus-article-date-lapsed t]
2256               ["User-defined" gnus-article-date-user t])
2257              ("Display"
2258               ["Remove images" gnus-article-remove-images t]
2259               ["Toggle smiley" gnus-treat-smiley t]
2260               ["Show X-Face" gnus-article-display-x-face t]
2261               ["Show picons in From" gnus-treat-from-picon t]
2262               ["Show picons in mail headers" gnus-treat-mail-picon t]
2263               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2264               ("View as different encoding"
2265                ,@(gnus-summary-menu-split
2266                   (mapcar
2267                    (lambda (cs)
2268                      ;; Since easymenu under Emacs doesn't allow
2269                      ;; lambda forms for menu commands, we should
2270                      ;; provide intern'ed function symbols.
2271                      (let ((command (intern (format "\
2272 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2273                        (fset command
2274                              `(lambda ()
2275                                 (interactive)
2276                                 (let ((gnus-summary-show-article-charset-alist
2277                                        '((1 . ,cs))))
2278                                   (gnus-summary-show-article 1))))
2279                        `[,(symbol-name cs) ,command t]))
2280                    (sort (if (fboundp 'coding-system-list)
2281                              (coding-system-list)
2282                            (mapcar 'car mm-mime-mule-charset-alist))
2283                          'string<)))))
2284              ("Washing"
2285               ("Remove Blanks"
2286                ["Leading" gnus-article-strip-leading-blank-lines t]
2287                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2288                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2289                ["All of the above" gnus-article-strip-blank-lines t]
2290                ["All" gnus-article-strip-all-blank-lines t]
2291                ["Leading space" gnus-article-strip-leading-space t]
2292                ["Trailing space" gnus-article-strip-trailing-space t]
2293                ["Leading space in headers"
2294                 gnus-article-remove-leading-whitespace t])
2295               ["Overstrike" gnus-article-treat-overstrike t]
2296               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2297               ["Emphasis" gnus-article-emphasize t]
2298               ["Word wrap" gnus-article-fill-cited-article t]
2299               ["Fill long lines" gnus-article-fill-long-lines t]
2300               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2301               ["Remove CR" gnus-article-remove-cr t]
2302               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2303               ["Base64" gnus-article-de-base64-unreadable t]
2304               ["Rot 13" gnus-summary-caesar-message
2305                ,@(if (featurep 'xemacs) '(t)
2306                    '(:help "\"Caesar rotate\" article by 13"))]
2307               ["De-IDNA" gnus-summary-idna-message t]
2308               ["Morse decode" gnus-summary-morse-message t]
2309               ["Unix pipe..." gnus-summary-pipe-message t]
2310               ["Add buttons" gnus-article-add-buttons t]
2311               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2312               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2313               ["Verbose header" gnus-summary-verbose-headers t]
2314               ["Toggle header" gnus-summary-toggle-header t]
2315               ["Unfold headers" gnus-article-treat-unfold-headers t]
2316               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2317               ["Html" gnus-article-wash-html t]
2318               ["Unsplit URLs" gnus-article-unsplit-urls t]
2319               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2320               ["Decode HZ" gnus-article-decode-HZ t]
2321               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2322               ("(Outlook) Deuglify"
2323                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2324                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2325                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2326                ["Full (Outlook) deuglify"
2327                 gnus-article-outlook-deuglify-article t])
2328               )
2329              ("Output"
2330               ["Save in default format..." gnus-summary-save-article
2331                ,@(if (featurep 'xemacs) '(t)
2332                    '(:help "Save article using default method"))]
2333               ["Save in file..." gnus-summary-save-article-file
2334                ,@(if (featurep 'xemacs) '(t)
2335                    '(:help "Save article in file"))]
2336               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2337               ["Save in MH folder..." gnus-summary-save-article-folder t]
2338               ["Save in VM folder..." gnus-summary-save-article-vm t]
2339               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2340               ["Save body in file..." gnus-summary-save-article-body-file t]
2341               ["Pipe through a filter..." gnus-summary-pipe-output t]
2342               ["Add to SOUP packet" gnus-soup-add-article t]
2343               ["Print with Muttprint..." gnus-summary-muttprint t]
2344               ["Print" gnus-summary-print-article
2345                ,@(if (featurep 'xemacs) '(t)
2346                    '(:help "Generate and print a PostScript image"))])
2347              ("Copy, move,... (Backend)"
2348               ,@(if (featurep 'xemacs) nil
2349                   '(:help "Copying, moving, expiring articles..."))
2350               ["Respool article..." gnus-summary-respool-article t]
2351               ["Move article..." gnus-summary-move-article
2352                (gnus-check-backend-function
2353                 'request-move-article gnus-newsgroup-name)]
2354               ["Copy article..." gnus-summary-copy-article t]
2355               ["Crosspost article..." gnus-summary-crosspost-article
2356                (gnus-check-backend-function
2357                 'request-replace-article gnus-newsgroup-name)]
2358               ["Import file..." gnus-summary-import-article
2359                (gnus-check-backend-function
2360                 'request-accept-article gnus-newsgroup-name)]
2361               ["Create article..." gnus-summary-create-article
2362                (gnus-check-backend-function
2363                 'request-accept-article gnus-newsgroup-name)]
2364               ["Check if posted" gnus-summary-article-posted-p t]
2365               ["Edit article" gnus-summary-edit-article
2366                (not (gnus-group-read-only-p))]
2367               ["Delete article" gnus-summary-delete-article
2368                (gnus-check-backend-function
2369                 'request-expire-articles gnus-newsgroup-name)]
2370               ["Query respool" gnus-summary-respool-query t]
2371               ["Trace respool" gnus-summary-respool-trace t]
2372               ["Delete expirable articles" gnus-summary-expire-articles-now
2373                (gnus-check-backend-function
2374                 'request-expire-articles gnus-newsgroup-name)])
2375              ("Extract"
2376               ["Uudecode" gnus-uu-decode-uu
2377                ,@(if (featurep 'xemacs) '(t)
2378                    '(:help "Decode uuencoded article(s)"))]
2379               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2380               ["Unshar" gnus-uu-decode-unshar t]
2381               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2382               ["Save" gnus-uu-decode-save t]
2383               ["Binhex" gnus-uu-decode-binhex t]
2384               ["Postscript" gnus-uu-decode-postscript t]
2385               ["All MIME parts" gnus-summary-save-parts t])
2386              ("Cache"
2387               ["Enter article" gnus-cache-enter-article t]
2388               ["Remove article" gnus-cache-remove-article t])
2389              ["Translate" gnus-article-babel t]
2390              ["Select article buffer" gnus-summary-select-article-buffer t]
2391              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2392              ["Isearch article..." gnus-summary-isearch-article t]
2393              ["Beginning of the article" gnus-summary-beginning-of-article t]
2394              ["End of the article" gnus-summary-end-of-article t]
2395              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2396              ["Fetch referenced articles" gnus-summary-refer-references t]
2397              ["Fetch current thread" gnus-summary-refer-thread t]
2398              ["Fetch article with id..." gnus-summary-refer-article t]
2399              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2400              ["Redisplay" gnus-summary-show-article t]
2401              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2402       (easy-menu-define
2403         gnus-summary-article-menu gnus-summary-mode-map ""
2404         (cons "Article" innards))
2405
2406       (if (not (keymapp gnus-summary-article-menu))
2407           (easy-menu-define
2408             gnus-article-commands-menu gnus-article-mode-map ""
2409             (cons "Commands" innards))
2410         ;; in Emacs, don't share menu.
2411         (setq gnus-article-commands-menu
2412               (copy-keymap gnus-summary-article-menu))
2413         (define-key gnus-article-mode-map [menu-bar commands]
2414           (cons "Commands" gnus-article-commands-menu))))
2415
2416     (easy-menu-define
2417       gnus-summary-thread-menu gnus-summary-mode-map ""
2418       '("Threads"
2419         ["Find all messages in thread" gnus-summary-refer-thread t]
2420         ["Toggle threading" gnus-summary-toggle-threads t]
2421         ["Hide threads" gnus-summary-hide-all-threads t]
2422         ["Show threads" gnus-summary-show-all-threads t]
2423         ["Hide thread" gnus-summary-hide-thread t]
2424         ["Show thread" gnus-summary-show-thread t]
2425         ["Go to next thread" gnus-summary-next-thread t]
2426         ["Go to previous thread" gnus-summary-prev-thread t]
2427         ["Go down thread" gnus-summary-down-thread t]
2428         ["Go up thread" gnus-summary-up-thread t]
2429         ["Top of thread" gnus-summary-top-thread t]
2430         ["Mark thread as read" gnus-summary-kill-thread t]
2431         ["Lower thread score" gnus-summary-lower-thread t]
2432         ["Raise thread score" gnus-summary-raise-thread t]
2433         ["Rethread current" gnus-summary-rethread-current t]))
2434
2435     (easy-menu-define
2436       gnus-summary-post-menu gnus-summary-mode-map ""
2437       `("Post"
2438         ["Send a message (mail or news)" gnus-summary-post-news
2439          ,@(if (featurep 'xemacs) '(t)
2440              '(:help "Compose a new message (mail or news)"))]
2441         ["Followup" gnus-summary-followup
2442          ,@(if (featurep 'xemacs) '(t)
2443              '(:help "Post followup to this article"))]
2444         ["Followup and yank" gnus-summary-followup-with-original
2445          ,@(if (featurep 'xemacs) '(t)
2446              '(:help "Post followup to this article, quoting its contents"))]
2447         ["Supersede article" gnus-summary-supersede-article t]
2448         ["Cancel article" gnus-summary-cancel-article
2449          ,@(if (featurep 'xemacs) '(t)
2450              '(:help "Cancel an article you posted"))]
2451         ["Reply" gnus-summary-reply t]
2452         ["Reply and yank" gnus-summary-reply-with-original t]
2453         ["Wide reply" gnus-summary-wide-reply t]
2454         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2455          ,@(if (featurep 'xemacs) '(t)
2456              '(:help "Mail a reply, quoting this article"))]
2457         ["Very wide reply" gnus-summary-very-wide-reply t]
2458         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2459          ,@(if (featurep 'xemacs) '(t)
2460              '(:help "Mail a very wide reply, quoting this article"))]
2461         ["Mail forward" gnus-summary-mail-forward t]
2462         ["Post forward" gnus-summary-post-forward t]
2463         ["Digest and mail" gnus-uu-digest-mail-forward t]
2464         ["Digest and post" gnus-uu-digest-post-forward t]
2465         ["Resend message" gnus-summary-resend-message t]
2466         ["Resend message edit" gnus-summary-resend-message-edit t]
2467         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2468         ["Send a mail" gnus-summary-mail-other-window t]
2469         ["Create a local message" gnus-summary-news-other-window t]
2470         ["Uuencode and post" gnus-uu-post-news
2471          ,@(if (featurep 'xemacs) '(t)
2472              '(:help "Post a uuencoded article"))]
2473         ["Followup via news" gnus-summary-followup-to-mail t]
2474         ["Followup via news and yank"
2475          gnus-summary-followup-to-mail-with-original t]
2476         ;;("Draft"
2477         ;;["Send" gnus-summary-send-draft t]
2478         ;;["Send bounced" gnus-resend-bounced-mail t])
2479         ))
2480
2481     (cond
2482      ((not (keymapp gnus-summary-post-menu))
2483       (setq gnus-article-post-menu gnus-summary-post-menu))
2484      ((not gnus-article-post-menu)
2485       ;; Don't share post menu.
2486       (setq gnus-article-post-menu
2487             (copy-keymap gnus-summary-post-menu))))
2488     (define-key gnus-article-mode-map [menu-bar post]
2489       (cons "Post" gnus-article-post-menu))
2490
2491     (easy-menu-define
2492       gnus-summary-misc-menu gnus-summary-mode-map ""
2493       `("Gnus"
2494         ("Mark Read"
2495          ["Mark as read" gnus-summary-mark-as-read-forward t]
2496          ["Mark same subject and select"
2497           gnus-summary-kill-same-subject-and-select t]
2498          ["Mark same subject" gnus-summary-kill-same-subject t]
2499          ["Catchup" gnus-summary-catchup
2500           ,@(if (featurep 'xemacs) '(t)
2501               '(:help "Mark unread articles in this group as read"))]
2502          ["Catchup all" gnus-summary-catchup-all t]
2503          ["Catchup to here" gnus-summary-catchup-to-here t]
2504          ["Catchup from here" gnus-summary-catchup-from-here t]
2505          ["Catchup region" gnus-summary-mark-region-as-read
2506           (gnus-mark-active-p)]
2507          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2508         ("Mark Various"
2509          ["Tick" gnus-summary-tick-article-forward t]
2510          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2511          ["Remove marks" gnus-summary-clear-mark-forward t]
2512          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2513          ["Set bookmark" gnus-summary-set-bookmark t]
2514          ["Remove bookmark" gnus-summary-remove-bookmark t])
2515         ("Limit to"
2516          ["Marks..." gnus-summary-limit-to-marks t]
2517          ["Subject..." gnus-summary-limit-to-subject t]
2518          ["Author..." gnus-summary-limit-to-author t]
2519          ["Recipient..." gnus-summary-limit-to-recipient t]
2520          ["Age..." gnus-summary-limit-to-age t]
2521          ["Extra..." gnus-summary-limit-to-extra t]
2522          ["Score..." gnus-summary-limit-to-score t]
2523          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2524          ["Unread" gnus-summary-limit-to-unread t]
2525          ["Unseen" gnus-summary-limit-to-unseen t]
2526          ["Replied" gnus-summary-limit-to-replied t]
2527          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2528          ["Next articles" gnus-summary-limit-to-articles t]
2529          ["Pop limit" gnus-summary-pop-limit t]
2530          ["Show dormant" gnus-summary-limit-include-dormant t]
2531          ["Hide childless dormant"
2532           gnus-summary-limit-exclude-childless-dormant t]
2533          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2534          ["Hide marked" gnus-summary-limit-exclude-marks t]
2535          ["Show expunged" gnus-summary-limit-include-expunged t])
2536         ("Process Mark"
2537          ["Set mark" gnus-summary-mark-as-processable t]
2538          ["Remove mark" gnus-summary-unmark-as-processable t]
2539          ["Remove all marks" gnus-summary-unmark-all-processable t]
2540          ["Invert marks" gnus-uu-invert-processable t]
2541          ["Mark above" gnus-uu-mark-over t]
2542          ["Mark series" gnus-uu-mark-series t]
2543          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2544          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2545          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2546          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2547          ["Mark all" gnus-uu-mark-all t]
2548          ["Mark buffer" gnus-uu-mark-buffer t]
2549          ["Mark sparse" gnus-uu-mark-sparse t]
2550          ["Mark thread" gnus-uu-mark-thread t]
2551          ["Unmark thread" gnus-uu-unmark-thread t]
2552          ("Process Mark Sets"
2553           ["Kill" gnus-summary-kill-process-mark t]
2554           ["Yank" gnus-summary-yank-process-mark
2555            gnus-newsgroup-process-stack]
2556           ["Save" gnus-summary-save-process-mark t]
2557           ["Run command on marked..." gnus-summary-universal-argument t]))
2558         ("Scroll article"
2559          ["Page forward" gnus-summary-next-page
2560           ,@(if (featurep 'xemacs) '(t)
2561               '(:help "Show next page of article"))]
2562          ["Page backward" gnus-summary-prev-page
2563           ,@(if (featurep 'xemacs) '(t)
2564               '(:help "Show previous page of article"))]
2565          ["Line forward" gnus-summary-scroll-up t])
2566         ("Move"
2567          ["Next unread article" gnus-summary-next-unread-article t]
2568          ["Previous unread article" gnus-summary-prev-unread-article t]
2569          ["Next article" gnus-summary-next-article t]
2570          ["Previous article" gnus-summary-prev-article t]
2571          ["Next unread subject" gnus-summary-next-unread-subject t]
2572          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2573          ["Next article same subject" gnus-summary-next-same-subject t]
2574          ["Previous article same subject" gnus-summary-prev-same-subject t]
2575          ["First unread article" gnus-summary-first-unread-article t]
2576          ["Best unread article" gnus-summary-best-unread-article t]
2577          ["Go to subject number..." gnus-summary-goto-subject t]
2578          ["Go to article number..." gnus-summary-goto-article t]
2579          ["Go to the last article" gnus-summary-goto-last-article t]
2580          ["Pop article off history" gnus-summary-pop-article t])
2581         ("Sort"
2582          ["Sort by number" gnus-summary-sort-by-number t]
2583          ["Sort by author" gnus-summary-sort-by-author t]
2584          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2585          ["Sort by subject" gnus-summary-sort-by-subject t]
2586          ["Sort by date" gnus-summary-sort-by-date t]
2587          ["Sort by score" gnus-summary-sort-by-score t]
2588          ["Sort by lines" gnus-summary-sort-by-lines t]
2589          ["Sort by characters" gnus-summary-sort-by-chars t]
2590          ["Randomize" gnus-summary-sort-by-random t]
2591          ["Original sort" gnus-summary-sort-by-original t])
2592         ("Help"
2593          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2594          ["Describe group" gnus-summary-describe-group t]
2595          ["Fetch charter" gnus-group-fetch-charter
2596           ,@(if (featurep 'xemacs) nil
2597               '(:help "Display the charter of the current group"))]
2598          ["Fetch control message" gnus-group-fetch-control
2599           ,@(if (featurep 'xemacs) nil
2600               '(:help "Display the archived control message for the current group"))]
2601          ["Read manual" gnus-info-find-node t])
2602         ("Modes"
2603          ["Pick and read" gnus-pick-mode t]
2604          ["Binary" gnus-binary-mode t])
2605         ("Regeneration"
2606          ["Regenerate" gnus-summary-prepare t]
2607          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2608          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2609          ["Toggle threading" gnus-summary-toggle-threads t])
2610         ["See old articles" gnus-summary-insert-old-articles t]
2611         ["See new articles" gnus-summary-insert-new-articles t]
2612         ["Filter articles..." gnus-summary-execute-command t]
2613         ["Run command on articles..." gnus-summary-universal-argument t]
2614         ["Search articles forward..." gnus-summary-search-article-forward t]
2615         ["Search articles backward..." gnus-summary-search-article-backward t]
2616         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2617         ["Expand window" gnus-summary-expand-window t]
2618         ["Expire expirable articles" gnus-summary-expire-articles
2619          (gnus-check-backend-function
2620           'request-expire-articles gnus-newsgroup-name)]
2621         ["Edit local kill file" gnus-summary-edit-local-kill t]
2622         ["Edit main kill file" gnus-summary-edit-global-kill t]
2623         ["Edit group parameters" gnus-summary-edit-parameters t]
2624         ["Customize group parameters" gnus-summary-customize-parameters t]
2625         ["Send a bug report" gnus-bug t]
2626         ("Exit"
2627          ["Catchup and exit" gnus-summary-catchup-and-exit
2628           ,@(if (featurep 'xemacs) '(t)
2629               '(:help "Mark unread articles in this group as read, then exit"))]
2630          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2631          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2632          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2633          ["Exit group" gnus-summary-exit
2634           ,@(if (featurep 'xemacs) '(t)
2635               '(:help "Exit current group, return to group selection mode"))]
2636          ["Exit group without updating" gnus-summary-exit-no-update t]
2637          ["Exit and goto next group" gnus-summary-next-group t]
2638          ["Exit and goto prev group" gnus-summary-prev-group t]
2639          ["Reselect group" gnus-summary-reselect-current-group t]
2640          ["Rescan group" gnus-summary-rescan-group t]
2641          ["Update dribble" gnus-summary-save-newsrc t])))
2642
2643     (gnus-run-hooks 'gnus-summary-menu-hook)))
2644
2645 (defvar gnus-summary-tool-bar-map nil)
2646
2647 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2648 ;; affect _new_ message buffers.  We might add a function that walks thru all
2649 ;; summary-mode buffers and force the update.
2650 (defun gnus-summary-tool-bar-update (&optional symbol value)
2651   "Update summary mode toolbar.
2652 Setter function for custom variables."
2653   (setq-default gnus-summary-tool-bar-map nil)
2654   (when symbol
2655     ;; When used as ":set" function:
2656     (set-default symbol value))
2657   (when (gnus-buffer-live-p gnus-summary-buffer)
2658     (with-current-buffer gnus-summary-buffer
2659       (gnus-summary-make-tool-bar))))
2660
2661 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2662                                      'gnus-summary-tool-bar-gnome
2663                                    'gnus-summary-tool-bar-retro)
2664   "Specifies the Gnus summary tool bar.
2665
2666 It can be either a list or a symbol refering to a list.  See
2667 `gmm-tool-bar-from-list' for the format of the list.  The
2668 default key map is `gnus-summary-mode-map'.
2669
2670 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2671 `gnus-summary-tool-bar-retro'."
2672   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2673                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2674                  (repeat :tag "User defined list" gmm-tool-bar-item)
2675                  (symbol))
2676   :version "23.0" ;; No Gnus
2677   :initialize 'custom-initialize-default
2678   :set 'gnus-summary-tool-bar-update
2679   :group 'gnus-summary)
2680
2681 (defcustom gnus-summary-tool-bar-gnome
2682   '((gnus-summary-post-news "mail/compose" nil)
2683     (gnus-summary-insert-new-articles "mail/inbox" nil
2684                                       :visible (or (not gnus-agent)
2685                                                    gnus-plugged))
2686     (gnus-summary-reply-with-original "mail/reply")
2687     (gnus-summary-reply "mail/reply" nil :visible nil)
2688     (gnus-summary-followup-with-original "mail/reply-all")
2689     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2690     (gnus-summary-mail-forward "mail/forward")
2691     (gnus-summary-save-article "mail/save")
2692     (gnus-summary-search-article-forward "search" nil :visible nil)
2693     (gnus-summary-print-article "print")
2694     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2695     ;; Some new commands that may need more suitable icons:
2696     (gnus-summary-save-newsrc "save" nil :visible nil)
2697     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2698     (gnus-summary-prev-article "left-arrow")
2699     (gnus-summary-next-article "right-arrow")
2700     (gnus-summary-next-page "next-page")
2701     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2702     ;;
2703     ;; Maybe some sort-by-... could be added:
2704     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2705     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2706     (gnus-summary-mark-as-expirable
2707      "delete" nil
2708      :visible (gnus-check-backend-function 'request-expire-articles
2709                                            gnus-newsgroup-name))
2710     (gnus-summary-mark-as-spam
2711      "mail/spam" t
2712      :visible (and (fboundp 'spam-group-ham-contents-p)
2713                    (spam-group-ham-contents-p gnus-newsgroup-name))
2714      :help "Mark as spam")
2715     (gnus-summary-mark-as-read-forward
2716      "mail/not-spam" nil
2717      :visible (and (fboundp 'spam-group-spam-contents-p)
2718                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2719     ;;
2720     (gnus-summary-exit "exit")
2721     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2722     (gnus-info-find-node "help"))
2723   "List of functions for the summary tool bar (GNOME style).
2724
2725 See `gmm-tool-bar-from-list' for the format of the list."
2726   :type '(repeat gmm-tool-bar-item)
2727   :version "23.0" ;; No Gnus
2728   :initialize 'custom-initialize-default
2729   :set 'gnus-summary-tool-bar-update
2730   :group 'gnus-summary)
2731
2732 (defcustom gnus-summary-tool-bar-retro
2733   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2734     (gnus-summary-next-unread-article "gnus/next-ur")
2735     (gnus-summary-post-news "gnus/post")
2736     (gnus-summary-followup-with-original "gnus/fuwo")
2737     (gnus-summary-followup "gnus/followup")
2738     (gnus-summary-reply-with-original "gnus/reply-wo")
2739     (gnus-summary-reply "gnus/reply")
2740     (gnus-summary-caesar-message "gnus/rot13")
2741     (gnus-uu-decode-uu "gnus/uu-decode")
2742     (gnus-summary-save-article-file "gnus/save-aif")
2743     (gnus-summary-save-article "gnus/save-art")
2744     (gnus-uu-post-news "gnus/uu-post")
2745     (gnus-summary-catchup "gnus/catchup")
2746     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2747     (gnus-summary-exit "gnus/exit-summ")
2748     ;; Some new command that may need more suitable icons:
2749     (gnus-summary-print-article "gnus/print" nil :visible nil)
2750     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2751     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2752     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2753     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2754     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2755     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2756     ;;
2757     (gnus-info-find-node "gnus/help" nil :visible nil))
2758   "List of functions for the summary tool bar (retro look).
2759
2760 See `gmm-tool-bar-from-list' for the format of the list."
2761   :type '(repeat gmm-tool-bar-item)
2762   :version "23.0" ;; No Gnus
2763   :initialize 'custom-initialize-default
2764   :set 'gnus-summary-tool-bar-update
2765   :group 'gnus-summary)
2766
2767 (defcustom gnus-summary-tool-bar-zap-list t
2768   "List of icon items from the global tool bar.
2769 These items are not displayed in the Gnus summary mode tool bar.
2770
2771 See `gmm-tool-bar-from-list' for the format of the list."
2772   :type 'gmm-tool-bar-zap-list
2773   :version "23.0" ;; No Gnus
2774   :initialize 'custom-initialize-default
2775   :set 'gnus-summary-tool-bar-update
2776   :group 'gnus-summary)
2777
2778 (defvar image-load-path)
2779
2780 (defun gnus-summary-make-tool-bar (&optional force)
2781   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2782 When FORCE, rebuild the tool bar."
2783   (when (and (not (featurep 'xemacs))
2784              (boundp 'tool-bar-mode)
2785              tool-bar-mode
2786              (or (not gnus-summary-tool-bar-map) force))
2787     (let* ((load-path
2788             (gmm-image-load-path-for-library "gnus"
2789                                              "mail/save.xpm"
2790                                              nil t))
2791            (image-load-path (cons (car load-path)
2792                                   (when (boundp 'image-load-path)
2793                                     image-load-path)))
2794            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2795                                         gnus-summary-tool-bar-zap-list
2796                                         'gnus-summary-mode-map)))
2797       (when map
2798         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2799         ;; uses it's value.
2800         (setq gnus-summary-tool-bar-map map))))
2801   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2802
2803 (defun gnus-score-set-default (var value)
2804   "A version of set that updates the GNU Emacs menu-bar."
2805   (set var value)
2806   ;; It is the message that forces the active status to be updated.
2807   (message ""))
2808
2809 (defun gnus-make-score-map (type)
2810   "Make a summary score map of type TYPE."
2811   (if t
2812       nil
2813     (let ((headers '(("author" "from" string)
2814                      ("subject" "subject" string)
2815                      ("article body" "body" string)
2816                      ("article head" "head" string)
2817                      ("xref" "xref" string)
2818                      ("extra header" "extra" string)
2819                      ("lines" "lines" number)
2820                      ("followups to author" "followup" string)))
2821           (types '((number ("less than" <)
2822                            ("greater than" >)
2823                            ("equal" =))
2824                    (string ("substring" s)
2825                            ("exact string" e)
2826                            ("fuzzy string" f)
2827                            ("regexp" r))))
2828           (perms '(("temporary" (current-time-string))
2829                    ("permanent" nil)
2830                    ("immediate" now)))
2831           header)
2832       (list
2833        (apply
2834         'nconc
2835         (list
2836          (if (eq type 'lower)
2837              "Lower score"
2838            "Increase score"))
2839         (let (outh)
2840           (while headers
2841             (setq header (car headers))
2842             (setq outh
2843                   (cons
2844                    (apply
2845                     'nconc
2846                     (list (car header))
2847                     (let ((ts (cdr (assoc (nth 2 header) types)))
2848                           outt)
2849                       (while ts
2850                         (setq outt
2851                               (cons
2852                                (apply
2853                                 'nconc
2854                                 (list (caar ts))
2855                                 (let ((ps perms)
2856                                       outp)
2857                                   (while ps
2858                                     (setq outp
2859                                           (cons
2860                                            (vector
2861                                             (caar ps)
2862                                             (list
2863                                              'gnus-summary-score-entry
2864                                              (nth 1 header)
2865                                              (if (or (string= (nth 1 header)
2866                                                               "head")
2867                                                      (string= (nth 1 header)
2868                                                               "body"))
2869                                                  ""
2870                                                (list 'gnus-summary-header
2871                                                      (nth 1 header)))
2872                                              (list 'quote (nth 1 (car ts)))
2873                                              (list 'gnus-score-delta-default
2874                                                    nil)
2875                                              (nth 1 (car ps))
2876                                              t)
2877                                             t)
2878                                            outp))
2879                                     (setq ps (cdr ps)))
2880                                   (list (nreverse outp))))
2881                                outt))
2882                         (setq ts (cdr ts)))
2883                       (list (nreverse outt))))
2884                    outh))
2885             (setq headers (cdr headers)))
2886           (list (nreverse outh))))))))
2887
2888 \f
2889
2890 (defun gnus-summary-mode (&optional group)
2891   "Major mode for reading articles.
2892
2893 All normal editing commands are switched off.
2894 \\<gnus-summary-mode-map>
2895 Each line in this buffer represents one article.  To read an
2896 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2897 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2898 respectively.
2899
2900 You can also post articles and send mail from this buffer.  To
2901 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2902 of an article, type `\\[gnus-summary-reply]'.
2903
2904 There are approx. one gazillion commands you can execute in this
2905 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2906
2907 The following commands are available:
2908
2909 \\{gnus-summary-mode-map}"
2910   (interactive)
2911   (kill-all-local-variables)
2912   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2913     (gnus-summary-make-local-variables))
2914   (gnus-summary-make-local-variables)
2915   (setq gnus-newsgroup-name group)
2916   (when (gnus-visual-p 'summary-menu 'menu)
2917     (gnus-summary-make-menu-bar)
2918     (gnus-summary-make-tool-bar))
2919   (gnus-make-thread-indent-array)
2920   (gnus-simplify-mode-line)
2921   (setq major-mode 'gnus-summary-mode)
2922   (setq mode-name "Summary")
2923   (make-local-variable 'minor-mode-alist)
2924   (use-local-map gnus-summary-mode-map)
2925   (buffer-disable-undo)
2926   (setq buffer-read-only t              ;Disable modification
2927         show-trailing-whitespace nil)
2928   (setq truncate-lines t)
2929   (setq selective-display t)
2930   (setq selective-display-ellipses t)   ;Display `...'
2931   (gnus-summary-set-display-table)
2932   (gnus-set-default-directory)
2933   (make-local-variable 'gnus-summary-line-format)
2934   (make-local-variable 'gnus-summary-line-format-spec)
2935   (make-local-variable 'gnus-summary-dummy-line-format)
2936   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2937   (make-local-variable 'gnus-summary-mark-positions)
2938   (gnus-make-local-hook 'pre-command-hook)
2939   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2940   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2941   (turn-on-gnus-mailing-list-mode)
2942   (mm-enable-multibyte)
2943   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2944   (gnus-update-summary-mark-positions))
2945
2946 (defun gnus-summary-make-local-variables ()
2947   "Make all the local summary buffer variables."
2948   (let (global)
2949     (dolist (local gnus-summary-local-variables)
2950       (if (consp local)
2951           (progn
2952             (if (eq (cdr local) 'global)
2953                 ;; Copy the global value of the variable.
2954                 (setq global (symbol-value (car local)))
2955               ;; Use the value from the list.
2956               (setq global (eval (cdr local))))
2957             (set (make-local-variable (car local)) global))
2958         ;; Simple nil-valued local variable.
2959         (set (make-local-variable local) nil)))))
2960
2961 (defun gnus-summary-clear-local-variables ()
2962   (let ((locals gnus-summary-local-variables))
2963     (while locals
2964       (if (consp (car locals))
2965           (and (symbolp (caar locals))
2966                (set (caar locals) nil))
2967         (and (symbolp (car locals))
2968              (set (car locals) nil)))
2969       (setq locals (cdr locals)))))
2970
2971 ;; Summary data functions.
2972
2973 (defmacro gnus-data-number (data)
2974   `(car ,data))
2975
2976 (defmacro gnus-data-set-number (data number)
2977   `(setcar ,data ,number))
2978
2979 (defmacro gnus-data-mark (data)
2980   `(nth 1 ,data))
2981
2982 (defmacro gnus-data-set-mark (data mark)
2983   `(setcar (nthcdr 1 ,data) ,mark))
2984
2985 (defmacro gnus-data-pos (data)
2986   `(nth 2 ,data))
2987
2988 (defmacro gnus-data-set-pos (data pos)
2989   `(setcar (nthcdr 2 ,data) ,pos))
2990
2991 (defmacro gnus-data-header (data)
2992   `(nth 3 ,data))
2993
2994 (defmacro gnus-data-set-header (data header)
2995   `(setf (nth 3 ,data) ,header))
2996
2997 (defmacro gnus-data-level (data)
2998   `(nth 4 ,data))
2999
3000 (defmacro gnus-data-unread-p (data)
3001   `(= (nth 1 ,data) gnus-unread-mark))
3002
3003 (defmacro gnus-data-read-p (data)
3004   `(/= (nth 1 ,data) gnus-unread-mark))
3005
3006 (defmacro gnus-data-pseudo-p (data)
3007   `(consp (nth 3 ,data)))
3008
3009 (defmacro gnus-data-find (number)
3010   `(assq ,number gnus-newsgroup-data))
3011
3012 (defmacro gnus-data-find-list (number &optional data)
3013   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3014      (memq (assq ,number bdata)
3015            bdata)))
3016
3017 (defmacro gnus-data-make (number mark pos header level)
3018   `(list ,number ,mark ,pos ,header ,level))
3019
3020 (defun gnus-data-enter (after-article number mark pos header level offset)
3021   (let ((data (gnus-data-find-list after-article)))
3022     (unless data
3023       (error "No such article: %d" after-article))
3024     (setcdr data (cons (gnus-data-make number mark pos header level)
3025                        (cdr data)))
3026     (setq gnus-newsgroup-data-reverse nil)
3027     (gnus-data-update-list (cddr data) offset)))
3028
3029 (defun gnus-data-enter-list (after-article list &optional offset)
3030   (when list
3031     (let ((data (and after-article (gnus-data-find-list after-article)))
3032           (ilist list))
3033       (if (not (or data
3034                    after-article))
3035           (let ((odata gnus-newsgroup-data))
3036             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3037             (when offset
3038               (gnus-data-update-list odata offset)))
3039         ;; Find the last element in the list to be spliced into the main
3040         ;; list.
3041         (setq list (last list))
3042         (if (not data)
3043             (progn
3044               (setcdr list gnus-newsgroup-data)
3045               (setq gnus-newsgroup-data ilist)
3046               (when offset
3047                 (gnus-data-update-list (cdr list) offset)))
3048           (setcdr list (cdr data))
3049           (setcdr data ilist)
3050           (when offset
3051             (gnus-data-update-list (cdr list) offset))))
3052       (setq gnus-newsgroup-data-reverse nil))))
3053
3054 (defun gnus-data-remove (article &optional offset)
3055   (let ((data gnus-newsgroup-data))
3056     (if (= (gnus-data-number (car data)) article)
3057         (progn
3058           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3059                 gnus-newsgroup-data-reverse nil)
3060           (when offset
3061             (gnus-data-update-list gnus-newsgroup-data offset)))
3062       (while (cdr data)
3063         (when (= (gnus-data-number (cadr data)) article)
3064           (setcdr data (cddr data))
3065           (when offset
3066             (gnus-data-update-list (cdr data) offset))
3067           (setq data nil
3068                 gnus-newsgroup-data-reverse nil))
3069         (setq data (cdr data))))))
3070
3071 (defmacro gnus-data-list (backward)
3072   `(if ,backward
3073        (or gnus-newsgroup-data-reverse
3074            (setq gnus-newsgroup-data-reverse
3075                  (reverse gnus-newsgroup-data)))
3076      gnus-newsgroup-data))
3077
3078 (defun gnus-data-update-list (data offset)
3079   "Add OFFSET to the POS of all data entries in DATA."
3080   (setq gnus-newsgroup-data-reverse nil)
3081   (while data
3082     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3083     (setq data (cdr data))))
3084
3085 (defun gnus-summary-article-pseudo-p (article)
3086   "Say whether this article is a pseudo article or not."
3087   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3088
3089 (defmacro gnus-summary-article-sparse-p (article)
3090   "Say whether this article is a sparse article or not."
3091   `(memq ,article gnus-newsgroup-sparse))
3092
3093 (defmacro gnus-summary-article-ancient-p (article)
3094   "Say whether this article is a sparse article or not."
3095   `(memq ,article gnus-newsgroup-ancient))
3096
3097 (defun gnus-article-parent-p (number)
3098   "Say whether this article is a parent or not."
3099   (let ((data (gnus-data-find-list number)))
3100     (and (cdr data)              ; There has to be an article after...
3101          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3102             (gnus-data-level (nth 1 data))))))
3103
3104 (defun gnus-article-children (number)
3105   "Return a list of all children to NUMBER."
3106   (let* ((data (gnus-data-find-list number))
3107          (level (gnus-data-level (car data)))
3108          children)
3109     (setq data (cdr data))
3110     (while (and data
3111                 (= (gnus-data-level (car data)) (1+ level)))
3112       (push (gnus-data-number (car data)) children)
3113       (setq data (cdr data)))
3114     children))
3115
3116 (defmacro gnus-summary-skip-intangible ()
3117   "If the current article is intangible, then jump to a different article."
3118   '(let ((to (get-text-property (point) 'gnus-intangible)))
3119      (and to (gnus-summary-goto-subject to))))
3120
3121 (defmacro gnus-summary-article-intangible-p ()
3122   "Say whether this article is intangible or not."
3123   '(get-text-property (point) 'gnus-intangible))
3124
3125 (defun gnus-article-read-p (article)
3126   "Say whether ARTICLE is read or not."
3127   (not (or (memq article gnus-newsgroup-marked)
3128            (memq article gnus-newsgroup-spam-marked)
3129            (memq article gnus-newsgroup-unreads)
3130            (memq article gnus-newsgroup-unselected)
3131            (memq article gnus-newsgroup-dormant))))
3132
3133 ;; Some summary mode macros.
3134
3135 (defmacro gnus-summary-article-number ()
3136   "The article number of the article on the current line.
3137 If there isn't an article number here, then we return the current
3138 article number."
3139   '(progn
3140      (gnus-summary-skip-intangible)
3141      (or (get-text-property (point) 'gnus-number)
3142          (gnus-summary-last-subject))))
3143
3144 (defmacro gnus-summary-article-header (&optional number)
3145   "Return the header of article NUMBER."
3146   `(gnus-data-header (gnus-data-find
3147                       ,(or number '(gnus-summary-article-number)))))
3148
3149 (defmacro gnus-summary-thread-level (&optional number)
3150   "Return the level of thread that starts with article NUMBER."
3151   `(if (and (eq gnus-summary-make-false-root 'dummy)
3152             (get-text-property (point) 'gnus-intangible))
3153        0
3154      (gnus-data-level (gnus-data-find
3155                        ,(or number '(gnus-summary-article-number))))))
3156
3157 (defmacro gnus-summary-article-mark (&optional number)
3158   "Return the mark of article NUMBER."
3159   `(gnus-data-mark (gnus-data-find
3160                     ,(or number '(gnus-summary-article-number)))))
3161
3162 (defmacro gnus-summary-article-pos (&optional number)
3163   "Return the position of the line of article NUMBER."
3164   `(gnus-data-pos (gnus-data-find
3165                    ,(or number '(gnus-summary-article-number)))))
3166
3167 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3168 (defmacro gnus-summary-article-subject (&optional number)
3169   "Return current subject string or nil if nothing."
3170   `(let ((headers
3171           ,(if number
3172                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3173              '(gnus-data-header (assq (gnus-summary-article-number)
3174                                       gnus-newsgroup-data)))))
3175      (and headers
3176           (vectorp headers)
3177           (mail-header-subject headers))))
3178
3179 (defmacro gnus-summary-article-score (&optional number)
3180   "Return current article score."
3181   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3182                   gnus-newsgroup-scored))
3183        gnus-summary-default-score 0))
3184
3185 (defun gnus-summary-article-children (&optional number)
3186   "Return a list of article numbers that are children of article NUMBER."
3187   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3188          (level (gnus-data-level (car data)))
3189          l children)
3190     (while (and (setq data (cdr data))
3191                 (> (setq l (gnus-data-level (car data))) level))
3192       (and (= (1+ level) l)
3193            (push (gnus-data-number (car data))
3194                  children)))
3195     (nreverse children)))
3196
3197 (defun gnus-summary-article-parent (&optional number)
3198   "Return the article number of the parent of article NUMBER."
3199   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3200                                     (gnus-data-list t)))
3201          (level (gnus-data-level (car data))))
3202     (if (zerop level)
3203         ()                              ; This is a root.
3204       ;; We search until we find an article with a level less than
3205       ;; this one.  That function has to be the parent.
3206       (while (and (setq data (cdr data))
3207                   (not (< (gnus-data-level (car data)) level))))
3208       (and data (gnus-data-number (car data))))))
3209
3210 (defun gnus-unread-mark-p (mark)
3211   "Say whether MARK is the unread mark."
3212   (= mark gnus-unread-mark))
3213
3214 (defun gnus-read-mark-p (mark)
3215   "Say whether MARK is one of the marks that mark as read.
3216 This is all marks except unread, ticked, dormant, and expirable."
3217   (not (or (= mark gnus-unread-mark)
3218            (= mark gnus-ticked-mark)
3219            (= mark gnus-spam-mark)
3220            (= mark gnus-dormant-mark)
3221            (= mark gnus-expirable-mark))))
3222
3223 (defmacro gnus-article-mark (number)
3224   "Return the MARK of article NUMBER.
3225 This macro should only be used when computing the mark the \"first\"
3226 time; i.e., when generating the summary lines.  After that,
3227 `gnus-summary-article-mark' should be used to examine the
3228 marks of articles."
3229   `(cond
3230     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3231     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3232     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3233     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3234     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3235     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3236     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3237     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3238            gnus-ancient-mark))))
3239
3240 ;; Saving hidden threads.
3241
3242 (defmacro gnus-save-hidden-threads (&rest forms)
3243   "Save hidden threads, eval FORMS, and restore the hidden threads."
3244   (let ((config (make-symbol "config")))
3245     `(let ((,config (gnus-hidden-threads-configuration)))
3246        (unwind-protect
3247            (save-excursion
3248              ,@forms)
3249          (gnus-restore-hidden-threads-configuration ,config)))))
3250 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3251 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3252
3253 (defun gnus-data-compute-positions ()
3254   "Compute the positions of all articles."
3255   (setq gnus-newsgroup-data-reverse nil)
3256   (let ((data gnus-newsgroup-data))
3257     (save-excursion
3258       (gnus-save-hidden-threads
3259         (gnus-summary-show-all-threads)
3260         (goto-char (point-min))
3261         (while data
3262           (while (get-text-property (point) 'gnus-intangible)
3263             (forward-line 1))
3264           (gnus-data-set-pos (car data) (+ (point) 3))
3265           (setq data (cdr data))
3266           (forward-line 1))))))
3267
3268 (defun gnus-hidden-threads-configuration ()
3269   "Return the current hidden threads configuration."
3270   (save-excursion
3271     (let (config)
3272       (goto-char (point-min))
3273       (while (search-forward "\r" nil t)
3274         (push (1- (point)) config))
3275       config)))
3276
3277 (defun gnus-restore-hidden-threads-configuration (config)
3278   "Restore hidden threads configuration from CONFIG."
3279   (save-excursion
3280     (let (point buffer-read-only)
3281       (while (setq point (pop config))
3282         (when (and (< point (point-max))
3283                    (goto-char point)
3284                    (eq (char-after) ?\n))
3285           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3286
3287 ;; Various summary mode internalish functions.
3288
3289 (defun gnus-mouse-pick-article (e)
3290   (interactive "e")
3291   (mouse-set-point e)
3292   (gnus-summary-next-page nil t))
3293
3294 (defun gnus-summary-set-display-table ()
3295   "Change the display table.
3296 Odd characters have a tendency to mess
3297 up nicely formatted displays - we make all possible glyphs
3298 display only a single character."
3299
3300   ;; We start from the standard display table, if any.
3301   (let ((table (or (copy-sequence standard-display-table)
3302                    (make-display-table)))
3303         (i 32))
3304     ;; Nix out all the control chars...
3305     (while (>= (setq i (1- i)) 0)
3306       (aset table i [??]))
3307    ;; ... but not newline and cr, of course.  (cr is necessary for the
3308     ;; selective display).
3309     (aset table ?\n nil)
3310     (aset table ?\r nil)
3311     ;; We keep TAB as well.
3312     (aset table ?\t nil)
3313     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3314     ;; Emacs 23 (unicode), that are not set already.
3315     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3316                  160
3317                256)))
3318       (while (>= (setq i (1- i)) 127)
3319         ;; Only modify if the entry is nil.
3320         (unless (aref table i)
3321           (aset table i [??]))))
3322     (setq buffer-display-table table)))
3323
3324 (defun gnus-summary-set-article-display-arrow (pos)
3325   "Update the overlay arrow to point to line at position POS."
3326   (when (and gnus-summary-display-arrow
3327              (boundp 'overlay-arrow-position)
3328              (boundp 'overlay-arrow-string))
3329     (save-excursion
3330       (goto-char pos)
3331       (beginning-of-line)
3332       (unless overlay-arrow-position
3333         (setq overlay-arrow-position (make-marker)))
3334       (setq overlay-arrow-string "=>"
3335             overlay-arrow-position (set-marker overlay-arrow-position
3336                                                (point)
3337                                                (current-buffer))))))
3338
3339 (defun gnus-summary-setup-buffer (group)
3340   "Initialize summary buffer."
3341   (let ((buffer (gnus-summary-buffer-name group))
3342         (dead-name (concat "*Dead Summary "
3343                            (gnus-group-decoded-name group) "*")))
3344     ;; If a dead summary buffer exists, we kill it.
3345     (when (gnus-buffer-live-p dead-name)
3346       (gnus-kill-buffer dead-name))
3347     (if (get-buffer buffer)
3348         (progn
3349           (set-buffer buffer)
3350           (setq gnus-summary-buffer (current-buffer))
3351           (not gnus-newsgroup-prepared))
3352       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3353       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3354       (gnus-summary-mode group)
3355       (when gnus-carpal
3356         (gnus-carpal-setup-buffer 'summary))
3357       (when (gnus-group-quit-config group)
3358         (set (make-local-variable 'gnus-single-article-buffer) nil))
3359       (make-local-variable 'gnus-article-buffer)
3360       (make-local-variable 'gnus-article-current)
3361       (make-local-variable 'gnus-original-article-buffer)
3362       (setq gnus-newsgroup-name group)
3363       ;; Set any local variables in the group parameters.
3364       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3365       t)))
3366
3367 (defun gnus-set-global-variables ()
3368   "Set the global equivalents of the buffer-local variables.
3369 They are set to the latest values they had.  These reflect the summary
3370 buffer that was in action when the last article was fetched."
3371   (when (eq major-mode 'gnus-summary-mode)
3372     (setq gnus-summary-buffer (current-buffer))
3373     (let ((name gnus-newsgroup-name)
3374           (marked gnus-newsgroup-marked)
3375           (spam gnus-newsgroup-spam-marked)
3376           (unread gnus-newsgroup-unreads)
3377           (headers gnus-current-headers)
3378           (data gnus-newsgroup-data)
3379           (summary gnus-summary-buffer)
3380           (article-buffer gnus-article-buffer)
3381           (original gnus-original-article-buffer)
3382           (gac gnus-article-current)
3383           (reffed gnus-reffed-article-number)
3384           (score-file gnus-current-score-file)
3385           (default-charset gnus-newsgroup-charset)
3386           vlist)
3387       (let ((locals gnus-newsgroup-variables))
3388         (while locals
3389           (if (consp (car locals))
3390               (push (eval (caar locals)) vlist)
3391             (push (eval (car locals)) vlist))
3392           (setq locals (cdr locals)))
3393         (setq vlist (nreverse vlist)))
3394       (with-current-buffer gnus-group-buffer
3395         (setq gnus-newsgroup-name name
3396               gnus-newsgroup-marked marked
3397               gnus-newsgroup-spam-marked spam
3398               gnus-newsgroup-unreads unread
3399               gnus-current-headers headers
3400               gnus-newsgroup-data data
3401               gnus-article-current gac
3402               gnus-summary-buffer summary
3403               gnus-article-buffer article-buffer
3404               gnus-original-article-buffer original
3405               gnus-reffed-article-number reffed
3406               gnus-current-score-file score-file
3407               gnus-newsgroup-charset default-charset)
3408         (let ((locals gnus-newsgroup-variables))
3409           (while locals
3410             (if (consp (car locals))
3411                 (set (caar locals) (pop vlist))
3412               (set (car locals) (pop vlist)))
3413             (setq locals (cdr locals))))
3414         ;; The article buffer also has local variables.
3415         (when (gnus-buffer-live-p gnus-article-buffer)
3416           (set-buffer gnus-article-buffer)
3417           (setq gnus-summary-buffer summary))))))
3418
3419 (defun gnus-summary-article-unread-p (article)
3420   "Say whether ARTICLE is unread or not."
3421   (memq article gnus-newsgroup-unreads))
3422
3423 (defun gnus-summary-first-article-p (&optional article)
3424   "Return whether ARTICLE is the first article in the buffer."
3425   (if (not (setq article (or article (gnus-summary-article-number))))
3426       nil
3427     (eq article (caar gnus-newsgroup-data))))
3428
3429 (defun gnus-summary-last-article-p (&optional article)
3430   "Return whether ARTICLE is the last article in the buffer."
3431   (if (not (setq article (or article (gnus-summary-article-number))))
3432       ;; All non-existent numbers are the last article.  :-)
3433       t
3434     (not (cdr (gnus-data-find-list article)))))
3435
3436 (defun gnus-make-thread-indent-array ()
3437   (let ((n 200))
3438     (unless (and gnus-thread-indent-array
3439                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3440       (setq gnus-thread-indent-array (make-vector 201 "")
3441             gnus-thread-indent-array-level gnus-thread-indent-level)
3442       (while (>= n 0)
3443         (aset gnus-thread-indent-array n
3444               (make-string (* n gnus-thread-indent-level) ? ))
3445         (setq n (1- n))))))
3446
3447 (defun gnus-update-summary-mark-positions ()
3448   "Compute where the summary marks are to go."
3449   (save-excursion
3450     (when (gnus-buffer-exists-p gnus-summary-buffer)
3451       (set-buffer gnus-summary-buffer))
3452     (let ((spec gnus-summary-line-format-spec)
3453           pos)
3454       (save-excursion
3455         (gnus-set-work-buffer)
3456         (let ((gnus-tmp-unread ?Z)
3457               (gnus-replied-mark ?Z)
3458               (gnus-score-below-mark ?Z)
3459               (gnus-score-over-mark ?Z)
3460               (gnus-undownloaded-mark ?Z)
3461               (gnus-summary-line-format-spec spec)
3462               (gnus-newsgroup-downloadable '(0))
3463               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3464               case-fold-search ignores)
3465           ;; Here, all marks are bound to Z.
3466           (gnus-summary-insert-line header
3467                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3468           (goto-char (point-min))
3469           ;; Memorize the positions of the same characters as dummy marks.
3470           (while (re-search-forward "[A-D]" nil t)
3471             (push (point) ignores))
3472           (erase-buffer)
3473           ;; We use A-D as dummy marks in order to know column positions
3474           ;; where marks should be inserted.
3475           (setq gnus-tmp-unread ?A
3476                 gnus-replied-mark ?B
3477                 gnus-score-below-mark ?C
3478                 gnus-score-over-mark ?C
3479                 gnus-undownloaded-mark ?D)
3480           (gnus-summary-insert-line header
3481                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3482           ;; Ignore characters which aren't dummy marks.
3483           (dolist (p ignores)
3484             (delete-region (goto-char (1- p)) p)
3485             (insert ?Z))
3486           (goto-char (point-min))
3487           (setq pos (list (cons 'unread
3488                                 (and (search-forward "A" nil t)
3489                                      (- (point) (point-min) 1)))))
3490           (goto-char (point-min))
3491           (push (cons 'replied (and (search-forward "B" nil t)
3492                                     (- (point) (point-min) 1)))
3493                 pos)
3494           (goto-char (point-min))
3495           (push (cons 'score (and (search-forward "C" nil t)
3496                                   (- (point) (point-min) 1)))
3497                 pos)
3498           (goto-char (point-min))
3499           (push (cons 'download (and (search-forward "D" nil t)
3500                                      (- (point) (point-min) 1)))
3501                 pos)))
3502       (setq gnus-summary-mark-positions pos))))
3503
3504 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3505   "Insert a dummy root in the summary buffer."
3506   (beginning-of-line)
3507   (gnus-add-text-properties
3508    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3509    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3510
3511 (defun gnus-summary-extract-address-component (from)
3512   (or (car (funcall gnus-extract-address-components from))
3513       from))
3514
3515 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3516   (let ((mail-parse-charset gnus-newsgroup-charset)
3517         ; Is it really necessary to do this next part for each summary line?
3518         ; Luckily, doesn't seem to slow things down much.
3519         (mail-parse-ignored-charsets
3520          (with-current-buffer gnus-summary-buffer
3521            gnus-newsgroup-ignored-charsets)))
3522     (or
3523      (and gnus-ignored-from-addresses
3524           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3525           (let ((extra-headers (mail-header-extra header))
3526                 to
3527                 newsgroups)
3528             (cond
3529              ((setq to (cdr (assq 'To extra-headers)))
3530               (concat gnus-summary-to-prefix
3531                       (inline
3532                         (gnus-summary-extract-address-component
3533                          (funcall gnus-decode-encoded-word-function to)))))
3534              ((setq newsgroups
3535                     (or
3536                      (cdr (assq 'Newsgroups extra-headers))
3537                      (and
3538                       (memq 'Newsgroups gnus-extra-headers)
3539                       (eq (car (gnus-find-method-for-group
3540                                 gnus-newsgroup-name)) 'nntp)
3541                       (gnus-group-real-name gnus-newsgroup-name))))
3542               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3543      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3544
3545 (defun gnus-summary-insert-line (gnus-tmp-header
3546                                  gnus-tmp-level gnus-tmp-current
3547                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3548                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3549                                  &optional gnus-tmp-dummy gnus-tmp-score
3550                                  gnus-tmp-process)
3551   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3552          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3553          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3554          (gnus-tmp-score-char
3555           (if (or (null gnus-summary-default-score)
3556                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3557                       gnus-summary-zcore-fuzz))
3558               ?                         ;Whitespace
3559             (if (< gnus-tmp-score gnus-summary-default-score)
3560                 gnus-score-below-mark gnus-score-over-mark)))
3561          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3562          (gnus-tmp-replied
3563           (cond (gnus-tmp-process gnus-process-mark)
3564                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3565                  gnus-cached-mark)
3566                 (gnus-tmp-replied gnus-replied-mark)
3567                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3568                  gnus-forwarded-mark)
3569                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3570                  gnus-saved-mark)
3571                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3572                  gnus-recent-mark)
3573                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3574                  gnus-unseen-mark)
3575                 (t gnus-no-mark)))
3576          (gnus-tmp-downloaded
3577           (cond (undownloaded
3578                  gnus-undownloaded-mark)
3579                 (gnus-newsgroup-agentized
3580                  gnus-downloaded-mark)
3581                 (t
3582                  gnus-no-mark)))
3583          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3584          (gnus-tmp-name
3585           (cond
3586            ((string-match "<[^>]+> *$" gnus-tmp-from)
3587             (let ((beg (match-beginning 0)))
3588               (or (and (string-match "^\".+\"" gnus-tmp-from)
3589                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3590                   (substring gnus-tmp-from 0 beg))))
3591            ((string-match "(.+)" gnus-tmp-from)
3592             (substring gnus-tmp-from
3593                        (1+ (match-beginning 0)) (1- (match-end 0))))
3594            (t gnus-tmp-from)))
3595          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3596          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3597          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3598          (buffer-read-only nil))
3599     (when (string= gnus-tmp-name "")
3600       (setq gnus-tmp-name gnus-tmp-from))
3601     (unless (numberp gnus-tmp-lines)
3602       (setq gnus-tmp-lines -1))
3603     (if (= gnus-tmp-lines -1)
3604         (setq gnus-tmp-lines "?")
3605       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3606       (gnus-put-text-property
3607      (point)
3608      (progn (eval gnus-summary-line-format-spec) (point))
3609        'gnus-number gnus-tmp-number)
3610     (when (gnus-visual-p 'summary-highlight 'highlight)
3611       (forward-line -1)
3612       (gnus-run-hooks 'gnus-summary-update-hook)
3613       (forward-line 1))))
3614
3615 (defun gnus-summary-update-line (&optional dont-update)
3616   "Update summary line after change."
3617   (when (and gnus-summary-default-score
3618              (not gnus-summary-inhibit-highlight))
3619     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3620            (article (gnus-summary-article-number))
3621            (score (gnus-summary-article-score article)))
3622       (unless dont-update
3623         (if (and gnus-summary-mark-below
3624                  (< (gnus-summary-article-score)
3625                     gnus-summary-mark-below))
3626             ;; This article has a low score, so we mark it as read.
3627             (when (memq article gnus-newsgroup-unreads)
3628               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3629           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3630             ;; This article was previously marked as read on account
3631             ;; of a low score, but now it has risen, so we mark it as
3632             ;; unread.
3633             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3634         (gnus-summary-update-mark
3635          (if (or (null gnus-summary-default-score)
3636                  (<= (abs (- score gnus-summary-default-score))
3637                      gnus-summary-zcore-fuzz))
3638              ?                          ;Whitespace
3639            (if (< score gnus-summary-default-score)
3640                gnus-score-below-mark gnus-score-over-mark))
3641          'score))
3642       ;; Do visual highlighting.
3643       (when (gnus-visual-p 'summary-highlight 'highlight)
3644         (gnus-run-hooks 'gnus-summary-update-hook)))))
3645
3646 (defvar gnus-tmp-new-adopts nil)
3647
3648 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3649   "Return the number of articles in THREAD.
3650 This may be 0 in some cases -- if none of the articles in
3651 the thread are to be displayed."
3652   (let* ((number
3653          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3654           (cond
3655            ((not (listp thread))
3656             1)
3657            ((and (consp thread) (cdr thread))
3658             (apply
3659              '+ 1 (mapcar
3660                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3661            ((null thread)
3662             1)
3663            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3664             1)
3665            (t 0))))
3666     (when (and level (zerop level) gnus-tmp-new-adopts)
3667       (incf number
3668             (apply '+ (mapcar
3669                        'gnus-summary-number-of-articles-in-thread
3670                        gnus-tmp-new-adopts))))
3671     (if char
3672         (if (> number 1) gnus-not-empty-thread-mark
3673           gnus-empty-thread-mark)
3674       number)))
3675
3676 (defsubst gnus-summary-line-message-size (head)
3677   "Return pretty-printed version of message size.
3678 This function is intended to be used in
3679 `gnus-summary-line-format-alist'."
3680   (let ((c (or (mail-header-chars head) -1)))
3681     (cond ((< c 0) "n/a")               ; chars not available
3682           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3683           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3684           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3685           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3686
3687
3688 (defun gnus-summary-set-local-parameters (group)
3689   "Go through the local params of GROUP and set all variable specs in that list."
3690   (let ((vars '(quit-config)))          ; Ignore quit-config.
3691     (dolist (elem (gnus-group-find-parameter group))
3692       (and (consp elem)                 ; Has to be a cons.
3693            (consp (cdr elem))           ; The cdr has to be a list.
3694            (symbolp (car elem))         ; Has to be a symbol in there.
3695            (not (memq (car elem) vars))
3696            (ignore-errors               ; So we set it.
3697              (push (car elem) vars)
3698              (make-local-variable (car elem))
3699              (set (car elem) (eval (nth 1 elem))))))))
3700
3701 (defun gnus-summary-read-group (group &optional show-all no-article
3702                                       kill-buffer no-display backward
3703                                       select-articles)
3704   "Start reading news in newsgroup GROUP.
3705 If SHOW-ALL is non-nil, already read articles are also listed.
3706 If NO-ARTICLE is non-nil, no article is selected initially.
3707 If NO-DISPLAY, don't generate a summary buffer."
3708   (let (result)
3709     (while (and group
3710                 (null (setq result
3711                             (let ((gnus-auto-select-next nil))
3712                               (or (gnus-summary-read-group-1
3713                                    group show-all no-article
3714                                    kill-buffer no-display
3715                                    select-articles)
3716                                   (setq show-all nil
3717                                         select-articles nil)))))
3718                 (eq gnus-auto-select-next 'quietly))
3719       (set-buffer gnus-group-buffer)
3720       ;; The entry function called above goes to the next
3721       ;; group automatically, so we go two groups back
3722       ;; if we are searching for the previous group.
3723       (when backward
3724         (gnus-group-prev-unread-group 2))
3725       (if (not (equal group (gnus-group-group-name)))
3726           (setq group (gnus-group-group-name))
3727         (setq group nil)))
3728     result))
3729
3730 (defun gnus-summary-read-group-1 (group show-all no-article
3731                                         kill-buffer no-display
3732                                         &optional select-articles)
3733   ;; Killed foreign groups can't be entered.
3734   ;;  (when (and (not (gnus-group-native-p group))
3735   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3736   ;;    (error "Dead non-native groups can't be entered"))
3737   (gnus-message 5 "Retrieving newsgroup: %s..."
3738                 (gnus-group-decoded-name group))
3739   (let* ((new-group (gnus-summary-setup-buffer group))
3740          (quit-config (gnus-group-quit-config group))
3741          (did-select (and new-group (gnus-select-newsgroup
3742                                      group show-all select-articles))))
3743     (cond
3744      ;; This summary buffer exists already, so we just select it.
3745      ((not new-group)
3746       (gnus-set-global-variables)
3747       (when kill-buffer
3748         (gnus-kill-or-deaden-summary kill-buffer))
3749       (gnus-configure-windows 'summary 'force)
3750       (gnus-set-mode-line 'summary)
3751       (gnus-summary-position-point)
3752       (message "")
3753       t)
3754      ;; We couldn't select this group.
3755      ((null did-select)
3756       (when (and (eq major-mode 'gnus-summary-mode)
3757                  (not (equal (current-buffer) kill-buffer)))
3758         (kill-buffer (current-buffer))
3759         (if (not quit-config)
3760             (progn
3761               ;; Update the info -- marks might need to be removed,
3762               ;; for instance.
3763               (gnus-summary-update-info)
3764               (set-buffer gnus-group-buffer)
3765               (gnus-group-jump-to-group group)
3766               (gnus-group-next-unread-group 1))
3767           (gnus-handle-ephemeral-exit quit-config)))
3768       (let ((grpinfo (gnus-get-info group)))
3769         (if (null (gnus-info-read grpinfo))
3770             (gnus-message 3 "Group %s contains no messages"
3771                           (gnus-group-decoded-name group))
3772           (gnus-message 3 "Can't select group")))
3773       nil)
3774      ;; The user did a `C-g' while prompting for number of articles,
3775      ;; so we exit this group.
3776      ((eq did-select 'quit)
3777       (and (eq major-mode 'gnus-summary-mode)
3778            (not (equal (current-buffer) kill-buffer))
3779            (kill-buffer (current-buffer)))
3780       (when kill-buffer
3781         (gnus-kill-or-deaden-summary kill-buffer))
3782       (if (not quit-config)
3783           (progn
3784             (set-buffer gnus-group-buffer)
3785             (gnus-group-jump-to-group group)
3786             (gnus-group-next-unread-group 1)
3787             (gnus-configure-windows 'group 'force))
3788         (gnus-handle-ephemeral-exit quit-config))
3789       ;; Finally signal the quit.
3790       (signal 'quit nil))
3791      ;; The group was successfully selected.
3792      (t
3793       (gnus-set-global-variables)
3794       ;; Save the active value in effect when the group was entered.
3795       (setq gnus-newsgroup-active
3796             (gnus-copy-sequence
3797              (gnus-active gnus-newsgroup-name)))
3798       ;; You can change the summary buffer in some way with this hook.
3799       (gnus-run-hooks 'gnus-select-group-hook)
3800       (when (memq 'summary (gnus-update-format-specifications
3801                             nil 'summary 'summary-mode 'summary-dummy))
3802         ;; The format specification for the summary line was updated,
3803         ;; so we need to update the mark positions as well.
3804         (gnus-update-summary-mark-positions))
3805       ;; Do score processing.
3806       (when gnus-use-scoring
3807         (gnus-possibly-score-headers))
3808       ;; Check whether to fill in the gaps in the threads.
3809       (when gnus-build-sparse-threads
3810         (gnus-build-sparse-threads))
3811       ;; Find the initial limit.
3812       (if show-all
3813           (let ((gnus-newsgroup-dormant nil))
3814             (gnus-summary-initial-limit show-all))
3815         (gnus-summary-initial-limit show-all))
3816       ;; Generate the summary buffer.
3817       (unless no-display
3818         (gnus-summary-prepare))
3819       (when gnus-use-trees
3820         (gnus-tree-open group)
3821         (setq gnus-summary-highlight-line-function
3822               'gnus-tree-highlight-article))
3823       ;; If the summary buffer is empty, but there are some low-scored
3824       ;; articles or some excluded dormants, we include these in the
3825       ;; buffer.
3826       (when (and (zerop (buffer-size))
3827                  (not no-display))
3828         (cond (gnus-newsgroup-dormant
3829                (gnus-summary-limit-include-dormant))
3830               ((and gnus-newsgroup-scored show-all)
3831                (gnus-summary-limit-include-expunged t))))
3832       ;; Function `gnus-apply-kill-file' must be called in this hook.
3833       (gnus-run-hooks 'gnus-apply-kill-hook)
3834       (if (and (zerop (buffer-size))
3835                (not no-display))
3836           (progn
3837             ;; This newsgroup is empty.
3838             (gnus-summary-catchup-and-exit nil t)
3839             (gnus-message 6 "No unread news")
3840             (when kill-buffer
3841               (gnus-kill-or-deaden-summary kill-buffer))
3842             ;; Return nil from this function.
3843             nil)
3844         ;; Hide conversation thread subtrees.  We cannot do this in
3845         ;; gnus-summary-prepare-hook since kill processing may not
3846         ;; work with hidden articles.
3847         (gnus-summary-maybe-hide-threads)
3848         (when kill-buffer
3849           (gnus-kill-or-deaden-summary kill-buffer))
3850         (gnus-summary-auto-select-subject)
3851         ;; Show first unread article if requested.
3852         (if (and (not no-article)
3853                  (not no-display)
3854                  gnus-newsgroup-unreads
3855                  gnus-auto-select-first)
3856             (progn
3857               (gnus-configure-windows 'summary)
3858               (let ((art (gnus-summary-article-number)))
3859                 (unless (and (not gnus-plugged)
3860                              (or (memq art gnus-newsgroup-undownloaded)
3861                                  (memq art gnus-newsgroup-downloadable)))
3862                   (gnus-summary-goto-article art))))
3863           ;; Don't select any articles.
3864           (gnus-summary-position-point)
3865           (gnus-configure-windows 'summary 'force)
3866           (gnus-set-mode-line 'summary))
3867         (when (and gnus-auto-center-group
3868                    (get-buffer-window gnus-group-buffer t))
3869           ;; Gotta use windows, because recenter does weird stuff if
3870           ;; the current buffer ain't the displayed window.
3871           (let ((owin (selected-window)))
3872             (select-window (get-buffer-window gnus-group-buffer t))
3873             (when (gnus-group-goto-group group)
3874               (recenter))
3875             (select-window owin)))
3876         ;; Mark this buffer as "prepared".
3877         (setq gnus-newsgroup-prepared t)
3878         (gnus-run-hooks 'gnus-summary-prepared-hook)
3879         (unless (gnus-ephemeral-group-p group)
3880           (gnus-group-update-group group))
3881         t)))))
3882
3883 (defun gnus-summary-auto-select-subject ()
3884   "Select the subject line on initial group entry."
3885   (goto-char (point-min))
3886   (cond
3887    ((eq gnus-auto-select-subject 'best)
3888     (gnus-summary-best-unread-subject))
3889    ((eq gnus-auto-select-subject 'unread)
3890     (gnus-summary-first-unread-subject))
3891    ((eq gnus-auto-select-subject 'unseen)
3892     (gnus-summary-first-unseen-subject))
3893    ((eq gnus-auto-select-subject 'unseen-or-unread)
3894     (gnus-summary-first-unseen-or-unread-subject))
3895    ((eq gnus-auto-select-subject 'first)
3896     ;; Do nothing.
3897     )
3898    ((functionp gnus-auto-select-subject)
3899     (funcall gnus-auto-select-subject))))
3900
3901 (defun gnus-summary-prepare ()
3902   "Generate the summary buffer."
3903   (interactive)
3904   (let ((buffer-read-only nil))
3905     (erase-buffer)
3906     (setq gnus-newsgroup-data nil
3907           gnus-newsgroup-data-reverse nil)
3908     (gnus-run-hooks 'gnus-summary-generate-hook)
3909     ;; Generate the buffer, either with threads or without.
3910     (when gnus-newsgroup-headers
3911       (gnus-summary-prepare-threads
3912        (if gnus-show-threads
3913            (gnus-sort-gathered-threads
3914             (funcall gnus-summary-thread-gathering-function
3915                      (gnus-sort-threads
3916                       (gnus-cut-threads (gnus-make-threads)))))
3917          ;; Unthreaded display.
3918          (gnus-sort-articles gnus-newsgroup-headers))))
3919     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3920     ;; Call hooks for modifying summary buffer.
3921     (goto-char (point-min))
3922     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3923
3924 (defsubst gnus-general-simplify-subject (subject)
3925   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3926   (setq subject
3927         (cond
3928          ;; Truncate the subject.
3929          (gnus-simplify-subject-functions
3930           (gnus-map-function gnus-simplify-subject-functions subject))
3931          ((numberp gnus-summary-gather-subject-limit)
3932           (setq subject (gnus-simplify-subject-re subject))
3933           (if (> (length subject) gnus-summary-gather-subject-limit)
3934               (substring subject 0 gnus-summary-gather-subject-limit)
3935             subject))
3936          ;; Fuzzily simplify it.
3937          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3938           (gnus-simplify-subject-fuzzy subject))
3939          ;; Just remove the leading "Re:".
3940          (t
3941           (gnus-simplify-subject-re subject))))
3942
3943   (if (and gnus-summary-gather-exclude-subject
3944            (string-match gnus-summary-gather-exclude-subject subject))
3945       nil                         ; This article shouldn't be gathered
3946     subject))
3947
3948 (defun gnus-summary-simplify-subject-query ()
3949   "Query where the respool algorithm would put this article."
3950   (interactive)
3951   (gnus-summary-select-article)
3952   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3953
3954 (defun gnus-gather-threads-by-subject (threads)
3955   "Gather threads by looking at Subject headers."
3956   (if (not gnus-summary-make-false-root)
3957       threads
3958     (let ((hashtb (gnus-make-hashtable 1024))
3959           (prev threads)
3960           (result threads)
3961           subject hthread whole-subject)
3962       (while threads
3963         (setq subject (gnus-general-simplify-subject
3964                        (setq whole-subject (mail-header-subject
3965                                             (caar threads)))))
3966         (when subject
3967           (if (setq hthread (gnus-gethash subject hashtb))
3968               (progn
3969                 ;; We enter a dummy root into the thread, if we
3970                 ;; haven't done that already.
3971                 (unless (stringp (caar hthread))
3972                   (setcar hthread (list whole-subject (car hthread))))
3973                 ;; We add this new gathered thread to this gathered
3974                 ;; thread.
3975                 (setcdr (car hthread)
3976                         (nconc (cdar hthread) (list (car threads))))
3977                 ;; Remove it from the list of threads.
3978                 (setcdr prev (cdr threads))
3979                 (setq threads prev))
3980             ;; Enter this thread into the hash table.
3981             (gnus-sethash subject
3982                           (if gnus-summary-make-false-root-always
3983                               (progn
3984                                 ;; If you want a dummy root above all
3985                                 ;; threads...
3986                                 (setcar threads (list whole-subject
3987                                                       (car threads)))
3988                                 threads)
3989                             threads)
3990                           hashtb)))
3991         (setq prev threads)
3992         (setq threads (cdr threads)))
3993       result)))
3994
3995 (defun gnus-gather-threads-by-references (threads)
3996   "Gather threads by looking at References headers."
3997   (let ((idhashtb (gnus-make-hashtable 1024))
3998         (thhashtb (gnus-make-hashtable 1024))
3999         (prev threads)
4000         (result threads)
4001         ids references id gthread gid entered ref)
4002     (while threads
4003       (when (setq references (mail-header-references (caar threads)))
4004         (setq id (mail-header-id (caar threads))
4005               ids (inline (gnus-split-references references))
4006               entered nil)
4007         (while (setq ref (pop ids))
4008           (setq ids (delete ref ids))
4009           (if (not (setq gid (gnus-gethash ref idhashtb)))
4010               (progn
4011                 (gnus-sethash ref id idhashtb)
4012                 (gnus-sethash id threads thhashtb))
4013             (setq gthread (gnus-gethash gid thhashtb))
4014             (unless entered
4015               ;; We enter a dummy root into the thread, if we
4016               ;; haven't done that already.
4017               (unless (stringp (caar gthread))
4018                 (setcar gthread (list (mail-header-subject (caar gthread))
4019                                       (car gthread))))
4020               ;; We add this new gathered thread to this gathered
4021               ;; thread.
4022               (setcdr (car gthread)
4023                       (nconc (cdar gthread) (list (car threads)))))
4024             ;; Add it into the thread hash table.
4025             (gnus-sethash id gthread thhashtb)
4026             (setq entered t)
4027             ;; Remove it from the list of threads.
4028             (setcdr prev (cdr threads))
4029             (setq threads prev))))
4030       (setq prev threads)
4031       (setq threads (cdr threads)))
4032     result))
4033
4034 (defun gnus-sort-gathered-threads (threads)
4035   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4036   (let ((result threads))
4037     (while threads
4038       (when (stringp (caar threads))
4039         (setcdr (car threads)
4040                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4041       (setq threads (cdr threads)))
4042     result))
4043
4044 (defun gnus-thread-loop-p (root thread)
4045   "Say whether ROOT is in THREAD."
4046   (let ((stack (list thread))
4047         (infloop 0)
4048         th)
4049     (while (setq thread (pop stack))
4050       (setq th (cdr thread))
4051       (while (and th
4052                   (not (eq (caar th) root)))
4053         (pop th))
4054       (if th
4055           ;; We have found a loop.
4056           (let (ref-dep)
4057             (setcdr thread (delq (car th) (cdr thread)))
4058             (if (boundp (setq ref-dep (intern "none"
4059                                               gnus-newsgroup-dependencies)))
4060                 (setcdr (symbol-value ref-dep)
4061                         (nconc (cdr (symbol-value ref-dep))
4062                                (list (car th))))
4063               (set ref-dep (list nil (car th))))
4064             (setq infloop 1
4065                   stack nil))
4066         ;; Push all the subthreads onto the stack.
4067         (push (cdr thread) stack)))
4068     infloop))
4069
4070 (defun gnus-make-threads ()
4071   "Go through the dependency hashtb and find the roots.  Return all threads."
4072   (let (threads)
4073     (while (catch 'infloop
4074              (mapatoms
4075               (lambda (refs)
4076                 ;; Deal with self-referencing References loops.
4077                 (when (and (car (symbol-value refs))
4078                            (not (zerop
4079                                  (apply
4080                                   '+
4081                                   (mapcar
4082                                    (lambda (thread)
4083                                      (gnus-thread-loop-p
4084                                       (car (symbol-value refs)) thread))
4085                                    (cdr (symbol-value refs)))))))
4086                   (setq threads nil)
4087                   (throw 'infloop t))
4088                 (unless (car (symbol-value refs))
4089                   ;; These threads do not refer back to any other
4090                   ;; articles, so they're roots.
4091                   (setq threads (append (cdr (symbol-value refs)) threads))))
4092               gnus-newsgroup-dependencies)))
4093     threads))
4094
4095 ;; Build the thread tree.
4096 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4097   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4098
4099 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4100 if it was already present.
4101
4102 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4103 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4104 Message-IDs will be renamed to a unique Message-ID before being
4105 entered.
4106
4107 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4108   (let* ((id (mail-header-id header))
4109          (id-dep (and id (intern id dependencies)))
4110          parent-id ref ref-dep ref-header replaced)
4111     ;; Enter this `header' in the `dependencies' table.
4112     (cond
4113      ((not id-dep)
4114       (setq header nil))
4115      ;; The first two cases do the normal part: enter a new `header'
4116      ;; in the `dependencies' table.
4117      ((not (boundp id-dep))
4118       (set id-dep (list header)))
4119      ((null (car (symbol-value id-dep)))
4120       (setcar (symbol-value id-dep) header))
4121
4122      ;; From here the `header' was already present in the
4123      ;; `dependencies' table.
4124      (force-new
4125       ;; Overrides an existing entry;
4126       ;; just set the header part of the entry.
4127       (setcar (symbol-value id-dep) header)
4128       (setq replaced t))
4129
4130      ;; Renames the existing `header' to a unique Message-ID.
4131      ((not gnus-summary-ignore-duplicates)
4132       ;; An article with this Message-ID has already been seen.
4133       ;; We rename the Message-ID.
4134       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4135            (list header))
4136       (mail-header-set-id header id))
4137
4138      ;; The last case ignores an existing entry, except it adds any
4139      ;; additional Xrefs (in case the two articles came from different
4140      ;; servers.
4141      ;; Also sets `header' to `nil' meaning that the `dependencies'
4142      ;; table was *not* modified.
4143      (t
4144       (mail-header-set-xref
4145        (car (symbol-value id-dep))
4146        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4147                    "")
4148                (or (mail-header-xref header) "")))
4149       (setq header nil)))
4150
4151     (when (and header (not replaced))
4152       ;; First check that we are not creating a References loop.
4153       (setq parent-id (gnus-parent-id (mail-header-references header)))
4154       (setq ref parent-id)
4155       (while (and ref
4156                   (setq ref-dep (intern-soft ref dependencies))
4157                   (boundp ref-dep)
4158                   (setq ref-header (car (symbol-value ref-dep))))
4159         (if (string= id ref)
4160             ;; Yuk!  This is a reference loop.  Make the article be a
4161             ;; root article.
4162             (progn
4163               (mail-header-set-references (car (symbol-value id-dep)) "none")
4164               (setq ref nil)
4165               (setq parent-id nil))
4166           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4167       (setq ref-dep (intern (or parent-id "none") dependencies))
4168       (if (boundp ref-dep)
4169           (setcdr (symbol-value ref-dep)
4170                   (nconc (cdr (symbol-value ref-dep))
4171                          (list (symbol-value id-dep))))
4172         (set ref-dep (list nil (symbol-value id-dep)))))
4173     header))
4174
4175 (defun gnus-extract-message-id-from-in-reply-to (string)
4176   (if (string-match "<[^>]+>" string)
4177       (substring string (match-beginning 0) (match-end 0))
4178     nil))
4179
4180 (defun gnus-build-sparse-threads ()
4181   (let ((headers gnus-newsgroup-headers)
4182         (mail-parse-charset gnus-newsgroup-charset)
4183         (gnus-summary-ignore-duplicates t)
4184         header references generation relations
4185         subject child end new-child date)
4186     ;; First we create an alist of generations/relations, where
4187     ;; generations is how much we trust the relation, and the relation
4188     ;; is parent/child.
4189     (gnus-message 7 "Making sparse threads...")
4190     (save-excursion
4191       (nnheader-set-temp-buffer " *gnus sparse threads*")
4192       (while (setq header (pop headers))
4193         (when (and (setq references (mail-header-references header))
4194                    (not (string= references "")))
4195           (insert references)
4196           (setq child (mail-header-id header)
4197                 subject (mail-header-subject header)
4198                 date (mail-header-date header)
4199                 generation 0)
4200           (while (search-backward ">" nil t)
4201             (setq end (1+ (point)))
4202             (when (search-backward "<" nil t)
4203               (setq new-child (buffer-substring (point) end))
4204               (push (list (incf generation)
4205                           child (setq child new-child)
4206                           subject date)
4207                     relations)))
4208           (when child
4209             (push (list (1+ generation) child nil subject) relations))
4210           (erase-buffer)))
4211       (kill-buffer (current-buffer)))
4212     ;; Sort over trustworthiness.
4213     (mapcar
4214      (lambda (relation)
4215        (when (gnus-dependencies-add-header
4216               (make-full-mail-header
4217                gnus-reffed-article-number
4218                (nth 3 relation) "" (or (nth 4 relation) "")
4219                (nth 1 relation)
4220                (or (nth 2 relation) "") 0 0 "")
4221               gnus-newsgroup-dependencies nil)
4222          (push gnus-reffed-article-number gnus-newsgroup-limit)
4223          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4224          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4225                gnus-newsgroup-reads)
4226          (decf gnus-reffed-article-number)))
4227      (sort relations 'car-less-than-car))
4228     (gnus-message 7 "Making sparse threads...done")))
4229
4230 (defun gnus-build-old-threads ()
4231   ;; Look at all the articles that refer back to old articles, and
4232   ;; fetch the headers for the articles that aren't there.  This will
4233   ;; build complete threads - if the roots haven't been expired by the
4234   ;; server, that is.
4235   (let ((mail-parse-charset gnus-newsgroup-charset)
4236         id heads)
4237     (mapatoms
4238      (lambda (refs)
4239        (when (not (car (symbol-value refs)))
4240          (setq heads (cdr (symbol-value refs)))
4241          (while heads
4242            (if (memq (mail-header-number (caar heads))
4243                      gnus-newsgroup-dormant)
4244                (setq heads (cdr heads))
4245              (setq id (symbol-name refs))
4246              (while (and (setq id (gnus-build-get-header id))
4247                          (not (car (gnus-id-to-thread id)))))
4248              (setq heads nil)))))
4249      gnus-newsgroup-dependencies)))
4250
4251 (defsubst gnus-remove-odd-characters (string)
4252   "Translate STRING into something that doesn't contain weird characters."
4253   (mm-subst-char-in-string
4254    ?\r ?\-
4255    (mm-subst-char-in-string ?\n ?\- string t) t))
4256
4257 ;; This function has to be called with point after the article number
4258 ;; on the beginning of the line.
4259 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4260   (let ((eol (point-at-eol))
4261         (buffer (current-buffer))
4262         header references in-reply-to)
4263
4264     ;; overview: [num subject from date id refs chars lines misc]
4265     (unwind-protect
4266         (let (x)
4267           (narrow-to-region (point) eol)
4268           (unless (eobp)
4269             (forward-char))
4270
4271           (setq header
4272                 (make-full-mail-header
4273                  number                 ; number
4274                  (condition-case ()     ; subject
4275                      (gnus-remove-odd-characters
4276                       (funcall gnus-decode-encoded-word-function
4277                                (setq x (nnheader-nov-field))))
4278                    (error x))
4279                  (condition-case ()     ; from
4280                      (gnus-remove-odd-characters
4281                       (funcall gnus-decode-encoded-word-function
4282                                (setq x (nnheader-nov-field))))
4283                    (error x))
4284                  (nnheader-nov-field)   ; date
4285                  (nnheader-nov-read-message-id number)  ; id
4286                  (setq references (nnheader-nov-field)) ; refs
4287                  (nnheader-nov-read-integer) ; chars
4288                  (nnheader-nov-read-integer) ; lines
4289                  (unless (eobp)
4290                    (if (looking-at "Xref: ")
4291                        (goto-char (match-end 0)))
4292                    (nnheader-nov-field)) ; Xref
4293                  (nnheader-nov-parse-extra)))) ; extra
4294
4295       (widen))
4296
4297     (when (and (string= references "")
4298                (setq in-reply-to (mail-header-extra header))
4299                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4300       (mail-header-set-references
4301        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4302
4303     (when gnus-alter-header-function
4304       (funcall gnus-alter-header-function header))
4305     (gnus-dependencies-add-header header dependencies force-new)))
4306
4307 (defun gnus-build-get-header (id)
4308   "Look through the buffer of NOV lines and find the header to ID.
4309 Enter this line into the dependencies hash table, and return
4310 the id of the parent article (if any)."
4311   (let ((deps gnus-newsgroup-dependencies)
4312         found header)
4313     (prog1
4314         (save-excursion
4315           (set-buffer nntp-server-buffer)
4316           (let ((case-fold-search nil))
4317             (goto-char (point-min))
4318             (while (and (not found)
4319                         (search-forward id nil t))
4320               (beginning-of-line)
4321               (setq found (looking-at
4322                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4323                                    (regexp-quote id))))
4324               (or found (beginning-of-line 2)))
4325             (when found
4326               (beginning-of-line)
4327               (and
4328                (setq header (gnus-nov-parse-line
4329                              (read (current-buffer)) deps))
4330                (gnus-parent-id (mail-header-references header))))))
4331       (when header
4332         (let ((number (mail-header-number header)))
4333           (push number gnus-newsgroup-limit)
4334           (push header gnus-newsgroup-headers)
4335           (if (memq number gnus-newsgroup-unselected)
4336               (progn
4337                 (setq gnus-newsgroup-unreads
4338                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4339                                                number))
4340                 (setq gnus-newsgroup-unselected
4341                       (delq number gnus-newsgroup-unselected)))
4342             (push number gnus-newsgroup-ancient)))))))
4343
4344 (defun gnus-build-all-threads ()
4345   "Read all the headers."
4346   (let ((gnus-summary-ignore-duplicates t)
4347         (mail-parse-charset gnus-newsgroup-charset)
4348         (dependencies gnus-newsgroup-dependencies)
4349         header article)
4350     (save-excursion
4351       (set-buffer nntp-server-buffer)
4352       (let ((case-fold-search nil))
4353         (goto-char (point-min))
4354         (while (not (eobp))
4355           (ignore-errors
4356             (setq article (read (current-buffer))
4357                   header (gnus-nov-parse-line article dependencies)))
4358           (when header
4359             (with-current-buffer gnus-summary-buffer
4360               (push header gnus-newsgroup-headers)
4361               (if (memq (setq article (mail-header-number header))
4362                         gnus-newsgroup-unselected)
4363                   (progn
4364                     (setq gnus-newsgroup-unreads
4365                           (gnus-add-to-sorted-list
4366                            gnus-newsgroup-unreads article))
4367                     (setq gnus-newsgroup-unselected
4368                           (delq article gnus-newsgroup-unselected)))
4369                 (push article gnus-newsgroup-ancient)))
4370             (forward-line 1)))))))
4371
4372 (defun gnus-summary-update-article-line (article header)
4373   "Update the line for ARTICLE using HEADER."
4374   (let* ((id (mail-header-id header))
4375          (thread (gnus-id-to-thread id)))
4376     (unless thread
4377       (error "Article in no thread"))
4378     ;; Update the thread.
4379     (setcar thread header)
4380     (gnus-summary-goto-subject article)
4381     (let* ((datal (gnus-data-find-list article))
4382            (data (car datal))
4383            (buffer-read-only nil)
4384            (level (gnus-summary-thread-level)))
4385       (gnus-delete-line)
4386       (let ((inserted (- (point)
4387                          (progn
4388                            (gnus-summary-insert-line
4389                             header level nil
4390                             (memq article gnus-newsgroup-undownloaded)
4391                             (gnus-article-mark article)
4392                             (memq article gnus-newsgroup-replied)
4393                             (memq article gnus-newsgroup-expirable)
4394                             ;; Only insert the Subject string when it's different
4395                             ;; from the previous Subject string.
4396                             (if (and
4397                                  gnus-show-threads
4398                                  (gnus-subject-equal
4399                                   (condition-case ()
4400                                       (mail-header-subject
4401                                        (gnus-data-header
4402                                         (cadr
4403                                          (gnus-data-find-list
4404                                           article
4405                                           (gnus-data-list t)))))
4406                                     ;; Error on the side of excessive subjects.
4407                                     (error ""))
4408                                   (mail-header-subject header)))
4409                                 ""
4410                               (mail-header-subject header))
4411                             nil (cdr (assq article gnus-newsgroup-scored))
4412                             (memq article gnus-newsgroup-processable))
4413                            (point)))))
4414         (when (cdr datal)
4415           (gnus-data-update-list
4416            (cdr datal)
4417            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4418
4419 (defun gnus-summary-update-article (article &optional iheader)
4420   "Update ARTICLE in the summary buffer."
4421   (set-buffer gnus-summary-buffer)
4422   (let* ((header (gnus-summary-article-header article))
4423          (id (mail-header-id header))
4424          (data (gnus-data-find article))
4425          (thread (gnus-id-to-thread id))
4426          (references (mail-header-references header))
4427          (parent
4428           (gnus-id-to-thread
4429            (or (gnus-parent-id
4430                 (when (and references
4431                            (not (equal "" references)))
4432                   references))
4433                "none")))
4434          (buffer-read-only nil)
4435          (old (car thread)))
4436     (when thread
4437       (unless iheader
4438         (setcar thread nil)
4439         (when parent
4440           (delq thread parent)))
4441       (if (gnus-summary-insert-subject id header)
4442           ;; Set the (possibly) new article number in the data structure.
4443           (gnus-data-set-number data (gnus-id-to-article id))
4444         (setcar thread old)
4445         nil))))
4446
4447 (defun gnus-rebuild-thread (id &optional line)
4448   "Rebuild the thread containing ID.
4449 If LINE, insert the rebuilt thread starting on line LINE."
4450   (let ((buffer-read-only nil)
4451         old-pos current thread data)
4452     (if (not gnus-show-threads)
4453         (setq thread (list (car (gnus-id-to-thread id))))
4454       ;; Get the thread this article is part of.
4455       (setq thread (gnus-remove-thread id)))
4456     (setq old-pos (point-at-bol))
4457     (setq current (save-excursion
4458                     (and (re-search-backward "[\r\n]" nil t)
4459                          (gnus-summary-article-number))))
4460     ;; If this is a gathered thread, we have to go some re-gathering.
4461     (when (stringp (car thread))
4462       (let ((subject (car thread))
4463             roots thr)
4464         (setq thread (cdr thread))
4465         (while thread
4466           (unless (memq (setq thr (gnus-id-to-thread
4467                                    (gnus-root-id
4468                                     (mail-header-id (caar thread)))))
4469                         roots)
4470             (push thr roots))
4471           (setq thread (cdr thread)))
4472         ;; We now have all (unique) roots.
4473         (if (= (length roots) 1)
4474             ;; All the loose roots are now one solid root.
4475             (setq thread (car roots))
4476           (setq thread (cons subject (gnus-sort-threads roots))))))
4477     (let (threads)
4478       ;; We then insert this thread into the summary buffer.
4479       (when line
4480         (goto-char (point-min))
4481         (forward-line (1- line)))
4482       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4483         (if gnus-show-threads
4484             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4485           (gnus-summary-prepare-unthreaded thread))
4486         (setq data (nreverse gnus-newsgroup-data))
4487         (setq threads gnus-newsgroup-threads))
4488       ;; We splice the new data into the data structure.
4489       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4490       ;;!!! then we want to insert at the beginning of the buffer.
4491       ;;!!! That happens to be true with Gnus now, but that may
4492       ;;!!! change in the future.  Perhaps.
4493       (gnus-data-enter-list
4494        (if line nil current) data (- (point) old-pos))
4495       (setq gnus-newsgroup-threads
4496             (nconc threads gnus-newsgroup-threads))
4497       (gnus-data-compute-positions))))
4498
4499 (defun gnus-number-to-header (number)
4500   "Return the header for article NUMBER."
4501   (let ((headers gnus-newsgroup-headers))
4502     (while (and headers
4503                 (not (= number (mail-header-number (car headers)))))
4504       (pop headers))
4505     (when headers
4506       (car headers))))
4507
4508 (defun gnus-parent-headers (in-headers &optional generation)
4509   "Return the headers of the GENERATIONeth parent of HEADERS."
4510   (unless generation
4511     (setq generation 1))
4512   (let ((parent t)
4513         (headers in-headers)
4514         references)
4515     (while (and parent
4516                 (not (zerop generation))
4517                 (setq references (mail-header-references headers)))
4518       (setq headers (if (and references
4519                              (setq parent (gnus-parent-id references)))
4520                         (car (gnus-id-to-thread parent))
4521                       nil))
4522       (decf generation))
4523     (and (not (eq headers in-headers))
4524          headers)))
4525
4526 (defun gnus-id-to-thread (id)
4527   "Return the (sub-)thread where ID appears."
4528   (gnus-gethash id gnus-newsgroup-dependencies))
4529
4530 (defun gnus-id-to-article (id)
4531   "Return the article number of ID."
4532   (let ((thread (gnus-id-to-thread id)))
4533     (when (and thread
4534                (car thread))
4535       (mail-header-number (car thread)))))
4536
4537 (defun gnus-id-to-header (id)
4538   "Return the article headers of ID."
4539   (car (gnus-id-to-thread id)))
4540
4541 (defun gnus-article-displayed-root-p (article)
4542   "Say whether ARTICLE is a root(ish) article."
4543   (let ((level (gnus-summary-thread-level article))
4544         (refs (mail-header-references  (gnus-summary-article-header article)))
4545         particle)
4546     (cond
4547      ((null level) nil)
4548      ((zerop level) t)
4549      ((null refs) t)
4550      ((null (gnus-parent-id refs)) t)
4551      ((and (= 1 level)
4552            (null (setq particle (gnus-id-to-article
4553                                  (gnus-parent-id refs))))
4554            (null (gnus-summary-thread-level particle)))))))
4555
4556 (defun gnus-root-id (id)
4557   "Return the id of the root of the thread where ID appears."
4558   (let (last-id prev)
4559     (while (and id (setq prev (car (gnus-id-to-thread id))))
4560       (setq last-id id
4561             id (gnus-parent-id (mail-header-references prev))))
4562     last-id))
4563
4564 (defun gnus-articles-in-thread (thread)
4565   "Return the list of articles in THREAD."
4566   (cons (mail-header-number (car thread))
4567         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4568
4569 (defun gnus-remove-thread (id &optional dont-remove)
4570   "Remove the thread that has ID in it."
4571   (let (headers thread last-id)
4572     ;; First go up in this thread until we find the root.
4573     (setq last-id (gnus-root-id id)
4574           headers (message-flatten-list (gnus-id-to-thread last-id)))
4575     ;; We have now found the real root of this thread.  It might have
4576     ;; been gathered into some loose thread, so we have to search
4577     ;; through the threads to find the thread we wanted.
4578     (let ((threads gnus-newsgroup-threads)
4579           sub)
4580       (while threads
4581         (setq sub (car threads))
4582         (if (stringp (car sub))
4583             ;; This is a gathered thread, so we look at the roots
4584             ;; below it to find whether this article is in this
4585             ;; gathered root.
4586             (progn
4587               (setq sub (cdr sub))
4588               (while sub
4589                 (when (member (caar sub) headers)
4590                   (setq thread (car threads)
4591                         threads nil
4592                         sub nil))
4593                 (setq sub (cdr sub))))
4594           ;; It's an ordinary thread, so we check it.
4595           (when (eq (car sub) (car headers))
4596             (setq thread sub
4597                   threads nil)))
4598         (setq threads (cdr threads)))
4599       ;; If this article is in no thread, then it's a root.
4600       (if thread
4601           (unless dont-remove
4602             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4603         (setq thread (gnus-id-to-thread last-id)))
4604       (when thread
4605         (prog1
4606             thread                      ; We return this thread.
4607           (unless dont-remove
4608             (if (stringp (car thread))
4609                 (progn
4610                   ;; If we use dummy roots, then we have to remove the
4611                   ;; dummy root as well.
4612                   (when (eq gnus-summary-make-false-root 'dummy)
4613                     ;; We go to the dummy root by going to
4614                     ;; the first sub-"thread", and then one line up.
4615                     (gnus-summary-goto-article
4616                      (mail-header-number (caadr thread)))
4617                     (forward-line -1)
4618                     (gnus-delete-line)
4619                     (gnus-data-compute-positions))
4620                   (setq thread (cdr thread))
4621                   (while thread
4622                     (gnus-remove-thread-1 (car thread))
4623                     (setq thread (cdr thread))))
4624               (gnus-remove-thread-1 thread))))))))
4625
4626 (defun gnus-remove-thread-1 (thread)
4627   "Remove the thread THREAD recursively."
4628   (let ((number (mail-header-number (pop thread)))
4629         d)
4630     (setq thread (reverse thread))
4631     (while thread
4632       (gnus-remove-thread-1 (pop thread)))
4633     (when (setq d (gnus-data-find number))
4634       (goto-char (gnus-data-pos d))
4635       (gnus-summary-show-thread)
4636       (gnus-data-remove
4637        number
4638        (- (point-at-bol)
4639           (prog1
4640               (1+ (point-at-eol))
4641             (gnus-delete-line)))))))
4642
4643 (defun gnus-sort-threads-1 (threads func)
4644   (sort (mapcar (lambda (thread)
4645                   (cons (car thread)
4646                         (and (cdr thread)
4647                              (gnus-sort-threads-1 (cdr thread) func))))
4648                 threads) func))
4649
4650 (defun gnus-sort-threads (threads)
4651   "Sort THREADS."
4652   (if (not gnus-thread-sort-functions)
4653       threads
4654     (gnus-message 8 "Sorting threads...")
4655     (let ((max-lisp-eval-depth 5000))
4656       (prog1 (gnus-sort-threads-1
4657          threads
4658          (gnus-make-sort-function gnus-thread-sort-functions))
4659         (gnus-message 8 "Sorting threads...done")))))
4660
4661 (defun gnus-sort-articles (articles)
4662   "Sort ARTICLES."
4663   (when gnus-article-sort-functions
4664     (gnus-message 7 "Sorting articles...")
4665     (prog1
4666         (setq gnus-newsgroup-headers
4667               (sort articles (gnus-make-sort-function
4668                               gnus-article-sort-functions)))
4669       (gnus-message 7 "Sorting articles...done"))))
4670
4671 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4672 (defmacro gnus-thread-header (thread)
4673   "Return header of first article in THREAD.
4674 Note that THREAD must never, ever be anything else than a variable -
4675 using some other form will lead to serious barfage."
4676   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4677   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4678   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4679         (vector thread) 2))
4680
4681 (defsubst gnus-article-sort-by-number (h1 h2)
4682   "Sort articles by article number."
4683   (< (mail-header-number h1)
4684      (mail-header-number h2)))
4685
4686 (defun gnus-thread-sort-by-number (h1 h2)
4687   "Sort threads by root article number."
4688   (gnus-article-sort-by-number
4689    (gnus-thread-header h1) (gnus-thread-header h2)))
4690
4691 (defsubst gnus-article-sort-by-random (h1 h2)
4692   "Sort articles by article number."
4693   (zerop (random 2)))
4694
4695 (defun gnus-thread-sort-by-random (h1 h2)
4696   "Sort threads by root article number."
4697   (gnus-article-sort-by-random
4698    (gnus-thread-header h1) (gnus-thread-header h2)))
4699
4700 (defsubst gnus-article-sort-by-lines (h1 h2)
4701   "Sort articles by article Lines header."
4702   (< (mail-header-lines h1)
4703      (mail-header-lines h2)))
4704
4705 (defun gnus-thread-sort-by-lines (h1 h2)
4706   "Sort threads by root article Lines header."
4707   (gnus-article-sort-by-lines
4708    (gnus-thread-header h1) (gnus-thread-header h2)))
4709
4710 (defsubst gnus-article-sort-by-chars (h1 h2)
4711   "Sort articles by octet length."
4712   (< (mail-header-chars h1)
4713      (mail-header-chars h2)))
4714
4715 (defun gnus-thread-sort-by-chars (h1 h2)
4716   "Sort threads by root article octet length."
4717   (gnus-article-sort-by-chars
4718    (gnus-thread-header h1) (gnus-thread-header h2)))
4719
4720 (defsubst gnus-article-sort-by-author (h1 h2)
4721   "Sort articles by root author."
4722   (string-lessp
4723    (let ((extract (funcall
4724                    gnus-extract-address-components
4725                    (mail-header-from h1))))
4726      (or (car extract) (cadr extract) ""))
4727    (let ((extract (funcall
4728                    gnus-extract-address-components
4729                    (mail-header-from h2))))
4730      (or (car extract) (cadr extract) ""))))
4731
4732 (defun gnus-thread-sort-by-author (h1 h2)
4733   "Sort threads by root author."
4734   (gnus-article-sort-by-author
4735    (gnus-thread-header h1)  (gnus-thread-header h2)))
4736
4737 (defsubst gnus-article-sort-by-recipient (h1 h2)
4738   "Sort articles by recipient."
4739   (string-lessp
4740    (let ((extract (funcall
4741                    gnus-extract-address-components
4742                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4743      (or (car extract) (cadr extract)))
4744    (let ((extract (funcall
4745                    gnus-extract-address-components
4746                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4747      (or (car extract) (cadr extract)))))
4748
4749 (defun gnus-thread-sort-by-recipient (h1 h2)
4750   "Sort threads by root recipient."
4751   (gnus-article-sort-by-recipient
4752    (gnus-thread-header h1) (gnus-thread-header h2)))
4753
4754 (defsubst gnus-article-sort-by-subject (h1 h2)
4755   "Sort articles by root subject."
4756   (string-lessp
4757    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4758    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4759
4760 (defun gnus-thread-sort-by-subject (h1 h2)
4761   "Sort threads by root subject."
4762   (gnus-article-sort-by-subject
4763    (gnus-thread-header h1) (gnus-thread-header h2)))
4764
4765 (defsubst gnus-article-sort-by-date (h1 h2)
4766   "Sort articles by root article date."
4767   (time-less-p
4768    (gnus-date-get-time (mail-header-date h1))
4769    (gnus-date-get-time (mail-header-date h2))))
4770
4771 (defun gnus-thread-sort-by-date (h1 h2)
4772   "Sort threads by root article date."
4773   (gnus-article-sort-by-date
4774    (gnus-thread-header h1) (gnus-thread-header h2)))
4775
4776 (defsubst gnus-article-sort-by-score (h1 h2)
4777   "Sort articles by root article score.
4778 Unscored articles will be counted as having a score of zero."
4779   (> (or (cdr (assq (mail-header-number h1)
4780                     gnus-newsgroup-scored))
4781          gnus-summary-default-score 0)
4782      (or (cdr (assq (mail-header-number h2)
4783                     gnus-newsgroup-scored))
4784          gnus-summary-default-score 0)))
4785
4786 (defun gnus-thread-sort-by-score (h1 h2)
4787   "Sort threads by root article score."
4788   (gnus-article-sort-by-score
4789    (gnus-thread-header h1) (gnus-thread-header h2)))
4790
4791 (defun gnus-thread-sort-by-total-score (h1 h2)
4792   "Sort threads by the sum of all scores in the thread.
4793 Unscored articles will be counted as having a score of zero."
4794   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4795
4796 (defun gnus-thread-total-score (thread)
4797   ;; This function find the total score of THREAD.
4798   (cond
4799    ((null thread)
4800     0)
4801    ((consp thread)
4802     (if (stringp (car thread))
4803         (apply gnus-thread-score-function 0
4804                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4805       (gnus-thread-total-score-1 thread)))
4806    (t
4807     (gnus-thread-total-score-1 (list thread)))))
4808
4809 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4810   "Sort threads such that the thread with the most recently arrived article comes first."
4811   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4812
4813 (defun gnus-thread-highest-number (thread)
4814   "Return the highest article number in THREAD."
4815   (apply 'max (mapcar (lambda (header)
4816                         (mail-header-number header))
4817                       (message-flatten-list thread))))
4818
4819 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4820   "Sort threads such that the thread with the most recently dated article comes first."
4821   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4822
4823 (defun gnus-thread-latest-date (thread)
4824   "Return the highest article date in THREAD."
4825   (let ((previous-time 0))
4826     (apply 'max
4827            (mapcar
4828             (lambda (header)
4829               (setq previous-time
4830                     (condition-case ()
4831                         (time-to-seconds (mail-header-parse-date
4832                                           (mail-header-date header)))
4833                       (error previous-time))))
4834             (sort
4835              (message-flatten-list thread)
4836              (lambda (h1 h2)
4837                (< (mail-header-number h1)
4838                   (mail-header-number h2))))))))
4839
4840 (defun gnus-thread-total-score-1 (root)
4841   ;; This function find the total score of the thread below ROOT.
4842   (setq root (car root))
4843   (apply gnus-thread-score-function
4844          (or (append
4845               (mapcar 'gnus-thread-total-score
4846                       (cdr (gnus-id-to-thread (mail-header-id root))))
4847               (when (> (mail-header-number root) 0)
4848                 (list (or (cdr (assq (mail-header-number root)
4849                                      gnus-newsgroup-scored))
4850                           gnus-summary-default-score 0))))
4851              (list gnus-summary-default-score)
4852              '(0))))
4853
4854 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4855 (defvar gnus-tmp-prev-subject nil)
4856 (defvar gnus-tmp-false-parent nil)
4857 (defvar gnus-tmp-root-expunged nil)
4858 (defvar gnus-tmp-dummy-line nil)
4859
4860 (eval-when-compile (defvar gnus-tmp-header))
4861 (defun gnus-extra-header (type &optional header)
4862   "Return the extra header of TYPE."
4863   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4864       ""))
4865
4866 (defvar gnus-tmp-thread-tree-header-string "")
4867
4868 (defcustom gnus-sum-thread-tree-root "> "
4869   "With %B spec, used for the root of a thread.
4870 If nil, use subject instead."
4871   :version "22.1"
4872   :type '(radio (const :format "%v  " nil) string)
4873   :group 'gnus-thread)
4874
4875 (defcustom gnus-sum-thread-tree-false-root "> "
4876   "With %B spec, used for a false root of a thread.
4877 If nil, use subject instead."
4878   :version "22.1"
4879   :type '(radio (const :format "%v  " nil) string)
4880   :group 'gnus-thread)
4881
4882 (defcustom gnus-sum-thread-tree-single-indent ""
4883   "With %B spec, used for a thread with just one message.
4884 If nil, use subject instead."
4885   :version "22.1"
4886   :type '(radio (const :format "%v  " nil) string)
4887   :group 'gnus-thread)
4888
4889 (defcustom gnus-sum-thread-tree-vertical "| "
4890   "With %B spec, used for drawing a vertical line."
4891   :version "22.1"
4892   :type 'string
4893   :group 'gnus-thread)
4894
4895 (defcustom gnus-sum-thread-tree-indent "  "
4896   "With %B spec, used for indenting."
4897   :version "22.1"
4898   :type 'string
4899   :group 'gnus-thread)
4900
4901 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4902   "With %B spec, used for a leaf with brothers."
4903   :version "22.1"
4904   :type 'string
4905   :group 'gnus-thread)
4906
4907 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4908   "With %B spec, used for a leaf without brothers."
4909   :version "22.1"
4910   :type 'string
4911   :group 'gnus-thread)
4912
4913 (defun gnus-summary-prepare-threads (threads)
4914   "Prepare summary buffer from THREADS and indentation LEVEL.
4915 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4916 or a straight list of headers."
4917   (gnus-message 7 "Generating summary...")
4918
4919   (setq gnus-newsgroup-threads threads)
4920   (beginning-of-line)
4921
4922   (let ((gnus-tmp-level 0)
4923         (default-score (or gnus-summary-default-score 0))
4924         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4925         (building-line-count gnus-summary-display-while-building)
4926         (building-count (integerp gnus-summary-display-while-building))
4927         thread number subject stack state gnus-tmp-gathered beg-match
4928         new-roots gnus-tmp-new-adopts thread-end simp-subject
4929         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4930         gnus-tmp-replied gnus-tmp-subject-or-nil
4931         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4932         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4933         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4934         tree-stack)
4935
4936     (setq gnus-tmp-prev-subject nil
4937           gnus-tmp-thread-tree-header-string "")
4938
4939     (if (vectorp (car threads))
4940         ;; If this is a straight (sic) list of headers, then a
4941         ;; threaded summary display isn't required, so we just create
4942         ;; an unthreaded one.
4943         (gnus-summary-prepare-unthreaded threads)
4944
4945       ;; Do the threaded display.
4946
4947       (if gnus-summary-display-while-building
4948           (switch-to-buffer (buffer-name)))
4949       (while (or threads stack gnus-tmp-new-adopts new-roots)
4950
4951         (if (and (= gnus-tmp-level 0)
4952                  (or (not stack)
4953                      (= (caar stack) 0))
4954                  (not gnus-tmp-false-parent)
4955                  (or gnus-tmp-new-adopts new-roots))
4956             (if gnus-tmp-new-adopts
4957                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4958                       thread (list (car gnus-tmp-new-adopts))
4959                       gnus-tmp-header (caar thread)
4960                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4961               (when new-roots
4962                 (setq thread (list (car new-roots))
4963                       gnus-tmp-header (caar thread)
4964                       new-roots (cdr new-roots))))
4965
4966           (if threads
4967               ;; If there are some threads, we do them before the
4968               ;; threads on the stack.
4969               (setq thread threads
4970                     gnus-tmp-header (caar thread))
4971             ;; There were no current threads, so we pop something off
4972             ;; the stack.
4973             (setq state (car stack)
4974                   gnus-tmp-level (car state)
4975                   tree-stack (cadr state)
4976                   thread (caddr state)
4977                   stack (cdr stack)
4978                   gnus-tmp-header (caar thread))))
4979
4980         (setq gnus-tmp-false-parent nil)
4981         (setq gnus-tmp-root-expunged nil)
4982         (setq thread-end nil)
4983
4984         (if (stringp gnus-tmp-header)
4985             ;; The header is a dummy root.
4986             (cond
4987              ((eq gnus-summary-make-false-root 'adopt)
4988               ;; We let the first article adopt the rest.
4989               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4990                                                (cddar thread)))
4991               (setq gnus-tmp-gathered
4992                     (nconc (mapcar
4993                             (lambda (h) (mail-header-number (car h)))
4994                             (cddar thread))
4995                            gnus-tmp-gathered))
4996               (setq thread (cons (list (caar thread)
4997                                        (cadar thread))
4998                                  (cdr thread)))
4999               (setq gnus-tmp-level -1
5000                     gnus-tmp-false-parent t))
5001              ((eq gnus-summary-make-false-root 'empty)
5002               ;; We print adopted articles with empty subject fields.
5003               (setq gnus-tmp-gathered
5004                     (nconc (mapcar
5005                             (lambda (h) (mail-header-number (car h)))
5006                             (cddar thread))
5007                            gnus-tmp-gathered))
5008               (setq gnus-tmp-level -1))
5009              ((eq gnus-summary-make-false-root 'dummy)
5010               ;; We remember that we probably want to output a dummy
5011               ;; root.
5012               (setq gnus-tmp-dummy-line gnus-tmp-header)
5013               (setq gnus-tmp-prev-subject gnus-tmp-header))
5014              (t
5015               ;; We do not make a root for the gathered
5016               ;; sub-threads at all.
5017               (setq gnus-tmp-level -1)))
5018
5019           (setq number (mail-header-number gnus-tmp-header)
5020                 subject (mail-header-subject gnus-tmp-header)
5021                 simp-subject (gnus-simplify-subject-fully subject))
5022
5023           (cond
5024            ;; If the thread has changed subject, we might want to make
5025            ;; this subthread into a root.
5026            ((and (null gnus-thread-ignore-subject)
5027                  (not (zerop gnus-tmp-level))
5028                  gnus-tmp-prev-subject
5029                  (not (string= gnus-tmp-prev-subject simp-subject)))
5030             (setq new-roots (nconc new-roots (list (car thread)))
5031                   thread-end t
5032                   gnus-tmp-header nil))
5033            ;; If the article lies outside the current limit,
5034            ;; then we do not display it.
5035            ((not (memq number gnus-newsgroup-limit))
5036             (setq gnus-tmp-gathered
5037                   (nconc (mapcar
5038                           (lambda (h) (mail-header-number (car h)))
5039                           (cdar thread))
5040                          gnus-tmp-gathered))
5041             (setq gnus-tmp-new-adopts (if (cdar thread)
5042                                           (append gnus-tmp-new-adopts
5043                                                   (cdar thread))
5044                                         gnus-tmp-new-adopts)
5045                   thread-end t
5046                   gnus-tmp-header nil)
5047             (when (zerop gnus-tmp-level)
5048               (setq gnus-tmp-root-expunged t)))
5049            ;; Perhaps this article is to be marked as read?
5050            ((and gnus-summary-mark-below
5051                  (< (or (cdr (assq number gnus-newsgroup-scored))
5052                         default-score)
5053                     gnus-summary-mark-below)
5054                  ;; Don't touch sparse articles.
5055                  (not (gnus-summary-article-sparse-p number))
5056                  (not (gnus-summary-article-ancient-p number)))
5057             (setq gnus-newsgroup-unreads
5058                   (delq number gnus-newsgroup-unreads))
5059             (if gnus-newsgroup-auto-expire
5060                 (setq gnus-newsgroup-expirable
5061                       (gnus-add-to-sorted-list
5062                        gnus-newsgroup-expirable number))
5063               (push (cons number gnus-low-score-mark)
5064                     gnus-newsgroup-reads))))
5065
5066           (when gnus-tmp-header
5067             ;; We may have an old dummy line to output before this
5068             ;; article.
5069             (when (and gnus-tmp-dummy-line
5070                        (gnus-subject-equal
5071                         gnus-tmp-dummy-line
5072                         (mail-header-subject gnus-tmp-header)))
5073               (gnus-summary-insert-dummy-line
5074                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5075               (setq gnus-tmp-dummy-line nil))
5076
5077             ;; Compute the mark.
5078             (setq gnus-tmp-unread (gnus-article-mark number))
5079
5080             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5081                                   gnus-tmp-header gnus-tmp-level)
5082                   gnus-newsgroup-data)
5083
5084             ;; Actually insert the line.
5085             (setq
5086              gnus-tmp-subject-or-nil
5087              (cond
5088               ((and gnus-thread-ignore-subject
5089                     gnus-tmp-prev-subject
5090                     (not (string= gnus-tmp-prev-subject simp-subject)))
5091                subject)
5092               ((zerop gnus-tmp-level)
5093                (if (and (eq gnus-summary-make-false-root 'empty)
5094                         (memq number gnus-tmp-gathered)
5095                         gnus-tmp-prev-subject
5096                         (string= gnus-tmp-prev-subject simp-subject))
5097                    gnus-summary-same-subject
5098                  subject))
5099               (t gnus-summary-same-subject)))
5100             (if (and (eq gnus-summary-make-false-root 'adopt)
5101                      (= gnus-tmp-level 1)
5102                      (memq number gnus-tmp-gathered))
5103                 (setq gnus-tmp-opening-bracket ?\<
5104                       gnus-tmp-closing-bracket ?\>)
5105               (setq gnus-tmp-opening-bracket ?\[
5106                     gnus-tmp-closing-bracket ?\]))
5107             (setq
5108              gnus-tmp-indentation
5109              (aref gnus-thread-indent-array gnus-tmp-level)
5110              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5111              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5112                                 gnus-summary-default-score 0)
5113              gnus-tmp-score-char
5114              (if (or (null gnus-summary-default-score)
5115                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5116                          gnus-summary-zcore-fuzz))
5117                  ?                      ;Whitespace
5118                (if (< gnus-tmp-score gnus-summary-default-score)
5119                    gnus-score-below-mark gnus-score-over-mark))
5120              gnus-tmp-replied
5121              (cond ((memq number gnus-newsgroup-processable)
5122                     gnus-process-mark)
5123                    ((memq number gnus-newsgroup-cached)
5124                     gnus-cached-mark)
5125                    ((memq number gnus-newsgroup-replied)
5126                     gnus-replied-mark)
5127                    ((memq number gnus-newsgroup-forwarded)
5128                     gnus-forwarded-mark)
5129                    ((memq number gnus-newsgroup-saved)
5130                     gnus-saved-mark)
5131                    ((memq number gnus-newsgroup-recent)
5132                     gnus-recent-mark)
5133                    ((memq number gnus-newsgroup-unseen)
5134                     gnus-unseen-mark)
5135                    (t gnus-no-mark))
5136              gnus-tmp-downloaded
5137              (cond ((memq number gnus-newsgroup-undownloaded)
5138                     gnus-undownloaded-mark)
5139                    (gnus-newsgroup-agentized
5140                     gnus-downloaded-mark)
5141                    (t
5142                     gnus-no-mark))
5143              gnus-tmp-from (mail-header-from gnus-tmp-header)
5144              gnus-tmp-name
5145              (cond
5146               ((string-match "<[^>]+> *$" gnus-tmp-from)
5147                (setq beg-match (match-beginning 0))
5148                (or (and (string-match "^\".+\"" gnus-tmp-from)
5149                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5150                    (substring gnus-tmp-from 0 beg-match)))
5151               ((string-match "(.+)" gnus-tmp-from)
5152                (substring gnus-tmp-from
5153                           (1+ (match-beginning 0)) (1- (match-end 0))))
5154               (t gnus-tmp-from))
5155
5156              ;; Do the %B string
5157              gnus-tmp-thread-tree-header-string
5158              (cond
5159               ((not gnus-show-threads) "")
5160               ((zerop gnus-tmp-level)
5161                (cond ((cdar thread)
5162                       (or gnus-sum-thread-tree-root subject))
5163                      (gnus-tmp-new-adopts
5164                       (or gnus-sum-thread-tree-false-root subject))
5165                      (t
5166                       (or gnus-sum-thread-tree-single-indent subject))))
5167               (t
5168                (concat (apply 'concat
5169                               (mapcar (lambda (item)
5170                                         (if (= item 1)
5171                                             gnus-sum-thread-tree-vertical
5172                                           gnus-sum-thread-tree-indent))
5173                                       (cdr (reverse tree-stack))))
5174                        (if (nth 1 thread)
5175                            gnus-sum-thread-tree-leaf-with-other
5176                          gnus-sum-thread-tree-single-leaf)))))
5177             (when (string= gnus-tmp-name "")
5178               (setq gnus-tmp-name gnus-tmp-from))
5179             (unless (numberp gnus-tmp-lines)
5180               (setq gnus-tmp-lines -1))
5181             (if (= gnus-tmp-lines -1)
5182                 (setq gnus-tmp-lines "?")
5183               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5184               (gnus-put-text-property
5185              (point)
5186              (progn (eval gnus-summary-line-format-spec) (point))
5187                'gnus-number number)
5188             (when gnus-visual-p
5189               (forward-line -1)
5190               (gnus-run-hooks 'gnus-summary-update-hook)
5191               (forward-line 1))
5192
5193             (setq gnus-tmp-prev-subject simp-subject)))
5194
5195         (when (nth 1 thread)
5196           (push (list (max 0 gnus-tmp-level)
5197                       (copy-sequence tree-stack)
5198                       (nthcdr 1 thread))
5199                 stack))
5200         (push (if (nth 1 thread) 1 0) tree-stack)
5201         (incf gnus-tmp-level)
5202         (setq threads (if thread-end nil (cdar thread)))
5203         (if gnus-summary-display-while-building
5204             (if building-count
5205                 (progn
5206                   ;; use a set frequency
5207                   (setq building-line-count (1- building-line-count))
5208                   (when (= building-line-count 0)
5209                     (sit-for 0)
5210                     (setq building-line-count
5211                           gnus-summary-display-while-building)))
5212               ;; always
5213               (sit-for 0)))
5214         (unless threads
5215           (setq gnus-tmp-level 0)))))
5216   (gnus-message 7 "Generating summary...done"))
5217
5218 (defun gnus-summary-prepare-unthreaded (headers)
5219   "Generate an unthreaded summary buffer based on HEADERS."
5220   (let (header number mark)
5221
5222     (beginning-of-line)
5223
5224     (while headers
5225       ;; We may have to root out some bad articles...
5226       (when (memq (setq number (mail-header-number
5227                                 (setq header (pop headers))))
5228                   gnus-newsgroup-limit)
5229         ;; Mark article as read when it has a low score.
5230         (when (and gnus-summary-mark-below
5231                    (< (or (cdr (assq number gnus-newsgroup-scored))
5232                           gnus-summary-default-score 0)
5233                       gnus-summary-mark-below)
5234                    (not (gnus-summary-article-ancient-p number)))
5235           (setq gnus-newsgroup-unreads
5236                 (delq number gnus-newsgroup-unreads))
5237           (if gnus-newsgroup-auto-expire
5238               (push number gnus-newsgroup-expirable)
5239             (push (cons number gnus-low-score-mark)
5240                   gnus-newsgroup-reads)))
5241
5242         (setq mark (gnus-article-mark number))
5243         (push (gnus-data-make number mark (1+ (point)) header 0)
5244               gnus-newsgroup-data)
5245         (gnus-summary-insert-line
5246          header 0 number
5247          (memq number gnus-newsgroup-undownloaded)
5248          mark (memq number gnus-newsgroup-replied)
5249          (memq number gnus-newsgroup-expirable)
5250          (mail-header-subject header) nil
5251          (cdr (assq number gnus-newsgroup-scored))
5252          (memq number gnus-newsgroup-processable))))))
5253
5254 (defun gnus-summary-remove-list-identifiers ()
5255   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5256   (let ((regexp (if (consp gnus-list-identifiers)
5257                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5258                   gnus-list-identifiers))
5259         changed subject)
5260     (when regexp
5261       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5262       (dolist (header gnus-newsgroup-headers)
5263         (setq subject (mail-header-subject header)
5264               changed nil)
5265         (while (string-match regexp subject)
5266           (setq subject
5267                 (concat (substring subject 0 (match-beginning 1))
5268                         (substring subject (match-end 0)))
5269                 changed t))
5270         (when changed
5271           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5272             (setq subject
5273                   (concat (substring subject 0 (match-beginning 1))
5274                           (substring subject (match-end 1)))))
5275           (mail-header-set-subject header subject))))))
5276
5277 (defun gnus-fetch-headers (articles)
5278   "Fetch headers of ARTICLES."
5279   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5280     (gnus-message 5 "Fetching headers for %s..." name)
5281     (prog1
5282         (if (eq 'nov
5283                 (setq gnus-headers-retrieved-by
5284                       (gnus-retrieve-headers
5285                        articles gnus-newsgroup-name
5286                        ;; We might want to fetch old headers, but
5287                        ;; not if there is only 1 article.
5288                        (and (or (and
5289                                  (not (eq gnus-fetch-old-headers 'some))
5290                                  (not (numberp gnus-fetch-old-headers)))
5291                                 (> (length articles) 1))
5292                             gnus-fetch-old-headers))))
5293             (gnus-get-newsgroup-headers-xover
5294              articles nil nil gnus-newsgroup-name t)
5295           (gnus-get-newsgroup-headers))
5296       (gnus-message 5 "Fetching headers for %s...done" name))))
5297
5298 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5299   "Select newsgroup GROUP.
5300 If READ-ALL is non-nil, all articles in the group are selected.
5301 If SELECT-ARTICLES, only select those articles from GROUP."
5302   (let* ((entry (gnus-group-entry group))
5303          ;;!!! Dirty hack; should be removed.
5304          (gnus-summary-ignore-duplicates
5305           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5306               t
5307             gnus-summary-ignore-duplicates))
5308          (info (nth 2 entry))
5309          articles fetched-articles cached)
5310
5311     (unless (gnus-check-server
5312              (set (make-local-variable 'gnus-current-select-method)
5313                   (gnus-find-method-for-group group)))
5314       (error "Couldn't open server"))
5315
5316     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5317         (gnus-activate-group group)     ; Or we can activate it...
5318         (progn                          ; Or we bug out.
5319           (when (equal major-mode 'gnus-summary-mode)
5320             (gnus-kill-buffer (current-buffer)))
5321           (error "Couldn't activate group %s: %s"
5322                  group (gnus-status-message group))))
5323
5324     (unless (gnus-request-group group t)
5325       (when (equal major-mode 'gnus-summary-mode)
5326         (gnus-kill-buffer (current-buffer)))
5327       (error "Couldn't request group %s: %s"
5328              group (gnus-status-message group)))
5329
5330     (when gnus-agent
5331       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5332
5333       (setq gnus-summary-use-undownloaded-faces
5334             (gnus-agent-find-parameter
5335              group
5336              'agent-enable-undownloaded-faces)))
5337
5338     (setq gnus-newsgroup-name group
5339           gnus-newsgroup-unselected nil
5340           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5341
5342     (let ((display (gnus-group-find-parameter group 'display)))
5343       (setq gnus-newsgroup-display
5344             (cond
5345              ((not (zerop (or (car-safe read-all) 0)))
5346               ;; The user entered the group with C-u SPC/RET, let's show
5347               ;; all articles.
5348               'gnus-not-ignore)
5349              ((eq display 'all)
5350               'gnus-not-ignore)
5351              ((arrayp display)
5352               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5353              ((numberp display)
5354               ;; The following is probably the "correct" solution, but
5355               ;; it makes Gnus fetch all headers and then limit the
5356               ;; articles (which is slow), so instead we hack the
5357               ;; select-articles parameter instead. -- Simon Josefsson
5358               ;; <jas@kth.se>
5359               ;;
5360               ;; (gnus-byte-compile
5361               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5362               ;;                         display)))))
5363               (setq select-articles
5364                     (gnus-uncompress-range
5365                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5366                              (if (> tmp 0)
5367                                  tmp
5368                                1))
5369                            (cdr (gnus-active group)))))
5370               nil)
5371              (t
5372               nil))))
5373
5374     (gnus-summary-setup-default-charset)
5375
5376     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5377     (when (gnus-virtual-group-p group)
5378       (setq cached gnus-newsgroup-cached))
5379
5380     (setq gnus-newsgroup-unreads
5381           (gnus-sorted-ndifference
5382            (gnus-sorted-ndifference gnus-newsgroup-unreads
5383                                     gnus-newsgroup-marked)
5384            gnus-newsgroup-dormant))
5385
5386     (setq gnus-newsgroup-processable nil)
5387
5388     (gnus-update-read-articles group gnus-newsgroup-unreads)
5389
5390     ;; Adjust and set lists of article marks.
5391     (when info
5392       (gnus-adjust-marked-articles info))
5393     (if (setq articles select-articles)
5394         (setq gnus-newsgroup-unselected
5395               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5396       (setq articles (gnus-articles-to-read group read-all)))
5397
5398     (cond
5399      ((null articles)
5400       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5401       'quit)
5402      ((eq articles 0) nil)
5403      (t
5404       ;; Init the dependencies hash table.
5405       (setq gnus-newsgroup-dependencies
5406             (gnus-make-hashtable (length articles)))
5407       (gnus-set-global-variables)
5408       ;; Retrieve the headers and read them in.
5409
5410       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5411
5412       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5413       (when cached
5414         (setq gnus-newsgroup-cached cached))
5415
5416       ;; Suppress duplicates?
5417       (when gnus-suppress-duplicates
5418         (gnus-dup-suppress-articles))
5419
5420       ;; Set the initial limit.
5421       (setq gnus-newsgroup-limit (copy-sequence articles))
5422       ;; Remove canceled articles from the list of unread articles.
5423       (setq fetched-articles
5424             (mapcar (lambda (headers) (mail-header-number headers))
5425                     gnus-newsgroup-headers))
5426       (setq gnus-newsgroup-articles fetched-articles)
5427       (setq gnus-newsgroup-unreads
5428             (gnus-sorted-nintersection
5429              gnus-newsgroup-unreads fetched-articles))
5430       (gnus-compute-unseen-list)
5431
5432       ;; Removed marked articles that do not exist.
5433       (gnus-update-missing-marks
5434        (gnus-sorted-difference articles fetched-articles))
5435       ;; We might want to build some more threads first.
5436       (when (and gnus-fetch-old-headers
5437                  (eq gnus-headers-retrieved-by 'nov))
5438         (if (eq gnus-fetch-old-headers 'invisible)
5439             (gnus-build-all-threads)
5440           (gnus-build-old-threads)))
5441       ;; Let the Gnus agent mark articles as read.
5442       (when gnus-agent
5443         (gnus-agent-get-undownloaded-list))
5444       ;; Remove list identifiers from subject
5445       (when gnus-list-identifiers
5446         (gnus-summary-remove-list-identifiers))
5447       ;; Check whether auto-expire is to be done in this group.
5448       (setq gnus-newsgroup-auto-expire
5449             (gnus-group-auto-expirable-p group))
5450       ;; Set up the article buffer now, if necessary.
5451       (unless gnus-single-article-buffer
5452         (gnus-article-setup-buffer))
5453       ;; First and last article in this newsgroup.
5454       (when gnus-newsgroup-headers
5455         (setq gnus-newsgroup-begin
5456               (mail-header-number (car gnus-newsgroup-headers))
5457               gnus-newsgroup-end
5458               (mail-header-number
5459                (gnus-last-element gnus-newsgroup-headers))))
5460       ;; GROUP is successfully selected.
5461       (or gnus-newsgroup-headers t)))))
5462
5463 (defun gnus-compute-unseen-list ()
5464   ;; The `seen' marks are treated specially.
5465   (if (not gnus-newsgroup-seen)
5466       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5467     (setq gnus-newsgroup-unseen
5468           (gnus-inverse-list-range-intersection
5469            gnus-newsgroup-articles gnus-newsgroup-seen))))
5470
5471 (defun gnus-summary-display-make-predicate (display)
5472   (require 'gnus-agent)
5473   (when (= (length display) 1)
5474     (setq display (car display)))
5475   (unless gnus-summary-display-cache
5476     (dolist (elem (append '((unread . unread)
5477                             (read . read)
5478                             (unseen . unseen))
5479                           gnus-article-mark-lists))
5480       (push (cons (cdr elem)
5481                   (gnus-byte-compile
5482                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5483             gnus-summary-display-cache)))
5484   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5485         (gnus-category-predicate-cache gnus-summary-display-cache))
5486     (gnus-get-predicate display)))
5487
5488 ;; Uses the dynamically bound `number' variable.
5489 (eval-when-compile
5490   (defvar number))
5491 (defun gnus-article-marked-p (type &optional article)
5492   (let ((article (or article number)))
5493     (cond
5494      ((eq type 'tick)
5495       (memq article gnus-newsgroup-marked))
5496      ((eq type 'spam)
5497       (memq article gnus-newsgroup-spam-marked))
5498      ((eq type 'unsend)
5499       (memq article gnus-newsgroup-unsendable))
5500      ((eq type 'undownload)
5501       (memq article gnus-newsgroup-undownloaded))
5502      ((eq type 'download)
5503       (memq article gnus-newsgroup-downloadable))
5504      ((eq type 'unread)
5505       (memq article gnus-newsgroup-unreads))
5506      ((eq type 'read)
5507       (memq article gnus-newsgroup-reads))
5508      ((eq type 'dormant)
5509       (memq article gnus-newsgroup-dormant) )
5510      ((eq type 'expire)
5511       (memq article gnus-newsgroup-expirable))
5512      ((eq type 'reply)
5513       (memq article gnus-newsgroup-replied))
5514      ((eq type 'killed)
5515       (memq article gnus-newsgroup-killed))
5516      ((eq type 'bookmark)
5517       (assq article gnus-newsgroup-bookmarks))
5518      ((eq type 'score)
5519       (assq article gnus-newsgroup-scored))
5520      ((eq type 'save)
5521       (memq article gnus-newsgroup-saved))
5522      ((eq type 'cache)
5523       (memq article gnus-newsgroup-cached))
5524      ((eq type 'forward)
5525       (memq article gnus-newsgroup-forwarded))
5526      ((eq type 'seen)
5527       (not (memq article gnus-newsgroup-unseen)))
5528      ((eq type 'recent)
5529       (memq article gnus-newsgroup-recent))
5530      (t t))))
5531
5532 (defun gnus-articles-to-read (group &optional read-all)
5533   "Find out what articles the user wants to read."
5534   (let* ((articles
5535           ;; Select all articles if `read-all' is non-nil, or if there
5536           ;; are no unread articles.
5537           (if (or read-all
5538                   (and (zerop (length gnus-newsgroup-marked))
5539                        (zerop (length gnus-newsgroup-unreads)))
5540                   ;; Fetch all if the predicate is non-nil.
5541                   gnus-newsgroup-display)
5542               ;; We want to select the headers for all the articles in
5543               ;; the group, so we select either all the active
5544               ;; articles in the group, or (if that's nil), the
5545               ;; articles in the cache.
5546               (or
5547                (gnus-uncompress-range (gnus-active group))
5548                (gnus-cache-articles-in-group group))
5549             ;; Select only the "normal" subset of articles.
5550             (gnus-sorted-nunion
5551              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5552              gnus-newsgroup-unreads)))
5553          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5554          (scored (length scored-list))
5555          (number (length articles))
5556          (marked (+ (length gnus-newsgroup-marked)
5557                     (length gnus-newsgroup-dormant)))
5558          (select
5559           (cond
5560            ((numberp read-all)
5561             read-all)
5562            ((numberp gnus-newsgroup-display)
5563             gnus-newsgroup-display)
5564            (t
5565             (condition-case ()
5566                 (cond
5567                  ((and (or (<= scored marked) (= scored number))
5568                        (numberp gnus-large-newsgroup)
5569                        (> number gnus-large-newsgroup))
5570                   (let* ((cursor-in-echo-area nil)
5571                          (initial (gnus-parameter-large-newsgroup-initial
5572                                    gnus-newsgroup-name))
5573                          (input
5574                           (read-string
5575                            (format
5576                             "How many articles from %s (%s %d): "
5577                             (gnus-limit-string
5578                              (gnus-group-decoded-name gnus-newsgroup-name)
5579                              35)
5580                             (if initial "max" "default")
5581                             number)
5582                            (if initial
5583                                (cons (number-to-string initial)
5584                                      0)))))
5585                     (if (string-match "^[ \t]*$" input) number input)))
5586                  ((and (> scored marked) (< scored number)
5587                        (> (- scored number) 20))
5588                   (let ((input
5589                          (read-string
5590                           (format "%s %s (%d scored, %d total): "
5591                                   "How many articles from"
5592                                   (gnus-group-decoded-name group)
5593                                   scored number))))
5594                     (if (string-match "^[ \t]*$" input)
5595                         number input)))
5596                  (t number))
5597               (quit
5598                (message "Quit getting the articles to read")
5599                nil))))))
5600     (setq select (if (stringp select) (string-to-number select) select))
5601     (if (or (null select) (zerop select))
5602         select
5603       (if (and (not (zerop scored)) (<= (abs select) scored))
5604           (progn
5605             (setq articles (sort scored-list '<))
5606             (setq number (length articles)))
5607         (setq articles (copy-sequence articles)))
5608
5609       (when (< (abs select) number)
5610         (if (< select 0)
5611             ;; Select the N oldest articles.
5612             (setcdr (nthcdr (1- (abs select)) articles) nil)
5613           ;; Select the N most recent articles.
5614           (setq articles (nthcdr (- number select) articles))))
5615       (setq gnus-newsgroup-unselected
5616             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5617       (when gnus-alter-articles-to-read-function
5618         (setq articles
5619               (sort
5620                (funcall gnus-alter-articles-to-read-function
5621                         gnus-newsgroup-name articles)
5622                '<)))
5623       articles)))
5624
5625 (defun gnus-killed-articles (killed articles)
5626   (let (out)
5627     (while articles
5628       (when (inline (gnus-member-of-range (car articles) killed))
5629         (push (car articles) out))
5630       (setq articles (cdr articles)))
5631     out))
5632
5633 (defun gnus-uncompress-marks (marks)
5634   "Uncompress the mark ranges in MARKS."
5635   (let ((uncompressed '(score bookmark))
5636         out)
5637     (while marks
5638       (if (memq (caar marks) uncompressed)
5639           (push (car marks) out)
5640         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5641       (setq marks (cdr marks)))
5642     out))
5643
5644 (defun gnus-article-mark-to-type (mark)
5645   "Return the type of MARK."
5646   (or (cadr (assq mark gnus-article-special-mark-lists))
5647       'list))
5648
5649 (defun gnus-article-unpropagatable-p (mark)
5650   "Return whether MARK should be propagated to back end."
5651   (memq mark gnus-article-unpropagated-mark-lists))
5652
5653 (defun gnus-adjust-marked-articles (info)
5654   "Set all article lists and remove all marks that are no longer valid."
5655   (let* ((marked-lists (gnus-info-marks info))
5656          (active (gnus-active (gnus-info-group info)))
5657          (min (car active))
5658          (max (cdr active))
5659          (types gnus-article-mark-lists)
5660          marks var articles article mark mark-type
5661          bgn end)
5662
5663     (dolist (marks marked-lists)
5664       (setq mark (car marks)
5665             mark-type (gnus-article-mark-to-type mark)
5666             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5667
5668       ;; We set the variable according to the type of the marks list,
5669       ;; and then adjust the marks to a subset of the active articles.
5670       (cond
5671        ;; Adjust "simple" lists - compressed yet unsorted
5672        ((eq mark-type 'list)
5673         ;; Simultaneously uncompress and clip to active range
5674         ;; See gnus-uncompress-range for a description of possible marks
5675         (let (l lh)
5676           (if (not (cadr marks))
5677               (set var nil)
5678             (setq articles (if (numberp (cddr marks))
5679                                (list (cdr marks))
5680                              (cdr marks))
5681                   lh (cons nil nil)
5682                   l lh)
5683
5684             (while (setq article (pop articles))
5685               (cond ((consp article)
5686                      (setq bgn (max (car article) min)
5687                            end (min (cdr article) max))
5688                      (while (<= bgn end)
5689                        (setq l (setcdr l (cons bgn nil))
5690                              bgn (1+ bgn))))
5691                     ((and (<= min article)
5692                           (>= max article))
5693                      (setq l (setcdr l (cons article nil))))))
5694             (set var (cdr lh)))))
5695        ;; Adjust assocs.
5696        ((eq mark-type 'tuple)
5697         (set var (setq articles (cdr marks)))
5698         (when (not (listp (cdr (symbol-value var))))
5699           (set var (list (symbol-value var))))
5700         (when (not (listp (cdr articles)))
5701           (setq articles (list articles)))
5702         (while articles
5703           (when (or (not (consp (setq article (pop articles))))
5704                     (< (car article) min)
5705                     (> (car article) max))
5706             (set var (delq article (symbol-value var))))))
5707        ;; Adjust ranges (sloppily).
5708        ((eq mark-type 'range)
5709         (cond
5710          ((eq mark 'seen)
5711           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5712           ;; It should be (seen (NUM1 . NUM2)).
5713           (when (numberp (cddr marks))
5714             (setcdr marks (list (cdr marks))))
5715           (setq articles (cdr marks))
5716           (while (and articles
5717                       (or (and (consp (car articles))
5718                                (> min (cdar articles)))
5719                           (and (numberp (car articles))
5720                                (> min (car articles)))))
5721             (pop articles))
5722           (set var articles))))))))
5723
5724 (defun gnus-update-missing-marks (missing)
5725   "Go through the list of MISSING articles and remove them from the mark lists."
5726   (when missing
5727     (let (var m)
5728       ;; Go through all types.
5729       (dolist (elem gnus-article-mark-lists)
5730         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5731           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5732           (when (symbol-value var)
5733             ;; This list has articles.  So we delete all missing
5734             ;; articles from it.
5735             (setq m missing)
5736             (while m
5737               (set var (delq (pop m) (symbol-value var))))))))))
5738
5739 (defun gnus-update-marks ()
5740   "Enter the various lists of marked articles into the newsgroup info list."
5741   (let ((types gnus-article-mark-lists)
5742         (info (gnus-get-info gnus-newsgroup-name))
5743         type list newmarked symbol delta-marks)
5744     (when info
5745       ;; Add all marks lists to the list of marks lists.
5746       (while (setq type (pop types))
5747         (setq list (symbol-value
5748                     (setq symbol
5749                           (intern (format "gnus-newsgroup-%s" (car type))))))
5750
5751         (when list
5752           ;; Get rid of the entries of the articles that have the
5753           ;; default score.
5754           (when (and (eq (cdr type) 'score)
5755                      gnus-save-score
5756                      list)
5757             (let* ((arts list)
5758                    (prev (cons nil list))
5759                    (all prev))
5760               (while arts
5761                 (if (or (not (consp (car arts)))
5762                         (= (cdar arts) gnus-summary-default-score))
5763                     (setcdr prev (cdr arts))
5764                   (setq prev arts))
5765                 (setq arts (cdr arts)))
5766               (setq list (cdr all)))))
5767
5768         (when (eq (cdr type) 'seen)
5769           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5770
5771         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5772           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5773
5774         (when (and (gnus-check-backend-function
5775                     'request-set-mark gnus-newsgroup-name)
5776                    (not (gnus-article-unpropagatable-p (cdr type))))
5777           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5778                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5779                  (add (gnus-remove-from-range
5780                        (gnus-copy-sequence list) old)))
5781             (when add
5782               (push (list add 'add (list (cdr type))) delta-marks))
5783             (when del
5784               (push (list del 'del (list (cdr type))) delta-marks))))
5785
5786         (when list
5787           (push (cons (cdr type) list) newmarked)))
5788
5789       (when delta-marks
5790         (unless (gnus-check-group gnus-newsgroup-name)
5791           (error "Can't open server for %s" gnus-newsgroup-name))
5792         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5793
5794       ;; Enter these new marks into the info of the group.
5795       (if (nthcdr 3 info)
5796           (setcar (nthcdr 3 info) newmarked)
5797         ;; Add the marks lists to the end of the info.
5798         (when newmarked
5799           (setcdr (nthcdr 2 info) (list newmarked))))
5800
5801       ;; Cut off the end of the info if there's nothing else there.
5802       (let ((i 5))
5803         (while (and (> i 2)
5804                     (not (nth i info)))
5805           (when (nthcdr (decf i) info)
5806             (setcdr (nthcdr i info) nil)))))))
5807
5808 (defun gnus-set-mode-line (where)
5809   "Set the mode line of the article or summary buffers.
5810 If WHERE is `summary', the summary mode line format will be used."
5811   ;; Is this mode line one we keep updated?
5812   (when (and (memq where gnus-updated-mode-lines)
5813              (symbol-value
5814               (intern (format "gnus-%s-mode-line-format-spec" where))))
5815     (let (mode-string)
5816       (save-excursion
5817         ;; We evaluate this in the summary buffer since these
5818         ;; variables are buffer-local to that buffer.
5819         (set-buffer gnus-summary-buffer)
5820        ;; We bind all these variables that are used in the `eval' form
5821         ;; below.
5822         (let* ((mformat (symbol-value
5823                          (intern
5824                           (format "gnus-%s-mode-line-format-spec" where))))
5825                (gnus-tmp-group-name (gnus-group-decoded-name
5826                                      gnus-newsgroup-name))
5827                (gnus-tmp-article-number (or gnus-current-article 0))
5828                (gnus-tmp-unread gnus-newsgroup-unreads)
5829                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5830                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5831                (gnus-tmp-unread-and-unselected
5832                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5833                             (zerop gnus-tmp-unselected))
5834                        "")
5835                       ((zerop gnus-tmp-unselected)
5836                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5837                       (t (format "{%d(+%d) more}"
5838                                  gnus-tmp-unread-and-unticked
5839                                  gnus-tmp-unselected))))
5840                (gnus-tmp-subject
5841                 (if (and gnus-current-headers
5842                          (vectorp gnus-current-headers))
5843                     (gnus-mode-string-quote
5844                      (mail-header-subject gnus-current-headers))
5845                   ""))
5846                bufname-length max-len
5847                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5848           (setq mode-string (eval mformat))
5849           (setq bufname-length (if (string-match "%b" mode-string)
5850                                    (- (length
5851                                        (buffer-name
5852                                         (if (eq where 'summary)
5853                                             nil
5854                                           (get-buffer gnus-article-buffer))))
5855                                       2)
5856                                  0))
5857           (setq max-len (max 4 (if gnus-mode-non-string-length
5858                                    (- (window-width)
5859                                       gnus-mode-non-string-length
5860                                       bufname-length)
5861                                  (length mode-string))))
5862           ;; We might have to chop a bit of the string off...
5863           (when (> (length mode-string) max-len)
5864             (setq mode-string
5865                   (concat (truncate-string-to-width mode-string (- max-len 3))
5866                           "...")))
5867           ;; Pad the mode string a bit.
5868           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5869       ;; Update the mode line.
5870       (setq mode-line-buffer-identification
5871             (gnus-mode-line-buffer-identification (list mode-string)))
5872       (set-buffer-modified-p t))))
5873
5874 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5875   "Go through the HEADERS list and add all Xrefs to a hash table.
5876 The resulting hash table is returned, or nil if no Xrefs were found."
5877   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5878          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5879          (xref-hashtb (gnus-make-hashtable))
5880          start group entry number xrefs header)
5881     (while headers
5882       (setq header (pop headers))
5883       (when (and (setq xrefs (mail-header-xref header))
5884                  (not (memq (setq number (mail-header-number header))
5885                             unreads)))
5886         (setq start 0)
5887         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5888           (setq start (match-end 0))
5889           (setq group (if prefix
5890                           (concat prefix (substring xrefs (match-beginning 1)
5891                                                     (match-end 1)))
5892                         (substring xrefs (match-beginning 1) (match-end 1))))
5893           (setq number
5894                 (string-to-number (substring xrefs (match-beginning 2)
5895                                           (match-end 2))))
5896           (if (setq entry (gnus-gethash group xref-hashtb))
5897               (setcdr entry (cons number (cdr entry)))
5898             (gnus-sethash group (cons number nil) xref-hashtb)))))
5899     (and start xref-hashtb)))
5900
5901 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5902   "Look through all the headers and mark the Xrefs as read."
5903   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5904         name info xref-hashtb idlist method nth4)
5905     (save-excursion
5906       (set-buffer gnus-group-buffer)
5907       (when (setq xref-hashtb
5908                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5909         (mapatoms
5910          (lambda (group)
5911            (unless (string= from-newsgroup (setq name (symbol-name group)))
5912              (setq idlist (symbol-value group))
5913              ;; Dead groups are not updated.
5914              (and (prog1
5915                       (setq info (gnus-get-info name))
5916                     (when (stringp (setq nth4 (gnus-info-method info)))
5917                       (setq nth4 (gnus-server-to-method nth4))))
5918                   ;; Only do the xrefs if the group has the same
5919                   ;; select method as the group we have just read.
5920                   (or (gnus-methods-equal-p
5921                        nth4 (gnus-find-method-for-group from-newsgroup))
5922                       virtual
5923                       (equal nth4 (setq method (gnus-find-method-for-group
5924                                                 from-newsgroup)))
5925                       (and (equal (car nth4) (car method))
5926                            (equal (nth 1 nth4) (nth 1 method))))
5927                   gnus-use-cross-reference
5928                   (or (not (eq gnus-use-cross-reference t))
5929                       virtual
5930                       ;; Only do cross-references on subscribed
5931                       ;; groups, if that is what is wanted.
5932                       (<= (gnus-info-level info) gnus-level-subscribed))
5933                   (gnus-group-make-articles-read name idlist))))
5934          xref-hashtb)))))
5935
5936 (defun gnus-compute-read-articles (group articles)
5937   (let* ((entry (gnus-group-entry group))
5938          (info (nth 2 entry))
5939          (active (gnus-active group))
5940          ninfo)
5941     (when entry
5942       ;; First peel off all invalid article numbers.
5943       (when active
5944         (let ((ids articles)
5945               id first)
5946           (while (setq id (pop ids))
5947             (when (and first (> id (cdr active)))
5948               ;; We'll end up in this situation in one particular
5949               ;; obscure situation.  If you re-scan a group and get
5950               ;; a new article that is cross-posted to a different
5951               ;; group that has not been re-scanned, you might get
5952               ;; crossposted article that has a higher number than
5953               ;; Gnus believes possible.  So we re-activate this
5954               ;; group as well.  This might mean doing the
5955               ;; crossposting thingy will *increase* the number
5956               ;; of articles in some groups.  Tsk, tsk.
5957               (setq active (or (gnus-activate-group group) active)))
5958             (when (or (> id (cdr active))
5959                       (< id (car active)))
5960               (setq articles (delq id articles))))))
5961       ;; If the read list is nil, we init it.
5962       (if (and active
5963                (null (gnus-info-read info))
5964                (> (car active) 1))
5965           (setq ninfo (cons 1 (1- (car active))))
5966         (setq ninfo (gnus-info-read info)))
5967       ;; Then we add the read articles to the range.
5968       (gnus-add-to-range
5969        ninfo (setq articles (sort articles '<))))))
5970
5971 (defun gnus-group-make-articles-read (group articles)
5972   "Update the info of GROUP to say that ARTICLES are read."
5973   (let* ((num 0)
5974          (entry (gnus-group-entry group))
5975          (info (nth 2 entry))
5976          (active (gnus-active group))
5977          range)
5978     (when entry
5979       (setq range (gnus-compute-read-articles group articles))
5980       (with-current-buffer gnus-group-buffer
5981         (gnus-undo-register
5982           `(progn
5983              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5984              (gnus-info-set-read ',info ',(gnus-info-read info))
5985              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5986              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5987              (gnus-group-update-group ,group t))))
5988       ;; Add the read articles to the range.
5989       (gnus-info-set-read info range)
5990       (gnus-request-set-mark group (list (list range 'add '(read))))
5991       ;; Then we have to re-compute how many unread
5992       ;; articles there are in this group.
5993       (when active
5994         (cond
5995          ((not range)
5996           (setq num (- (1+ (cdr active)) (car active))))
5997          ((not (listp (cdr range)))
5998           (setq num (- (cdr active) (- (1+ (cdr range))
5999                                        (car range)))))
6000          (t
6001           (while range
6002             (if (numberp (car range))
6003                 (setq num (1+ num))
6004               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6005             (setq range (cdr range)))
6006           (setq num (- (cdr active) num))))
6007         ;; Update the number of unread articles.
6008         (setcar entry num)
6009         ;; Update the group buffer.
6010         (unless (gnus-ephemeral-group-p group)
6011           (gnus-group-update-group group t))))))
6012
6013 (defvar gnus-newsgroup-none-id 0)
6014
6015 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6016   (let ((cur nntp-server-buffer)
6017         (dependencies
6018          (or dependencies
6019              (with-current-buffer gnus-summary-buffer
6020                gnus-newsgroup-dependencies)))
6021         headers id end ref number
6022         (mail-parse-charset gnus-newsgroup-charset)
6023         (mail-parse-ignored-charsets
6024          (save-excursion (condition-case nil
6025                              (set-buffer gnus-summary-buffer)
6026                            (error))
6027                          gnus-newsgroup-ignored-charsets)))
6028     (save-excursion
6029       (set-buffer nntp-server-buffer)
6030       ;; Translate all TAB characters into SPACE characters.
6031       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6032       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6033       (ietf-drums-unfold-fws)
6034       (gnus-run-hooks 'gnus-parse-headers-hook)
6035       (let ((case-fold-search t)
6036             in-reply-to header p lines chars)
6037         (goto-char (point-min))
6038         ;; Search to the beginning of the next header.  Error messages
6039         ;; do not begin with 2 or 3.
6040         (while (re-search-forward "^[23][0-9]+ " nil t)
6041           (setq id nil
6042                 ref nil)
6043           ;; This implementation of this function, with nine
6044           ;; search-forwards instead of the one re-search-forward and
6045           ;; a case (which basically was the old function) is actually
6046           ;; about twice as fast, even though it looks messier.  You
6047           ;; can't have everything, I guess.  Speed and elegance
6048           ;; doesn't always go hand in hand.
6049           (setq
6050            header
6051            (vector
6052             ;; Number.
6053             (prog1
6054                 (setq number (read cur))
6055               (end-of-line)
6056               (setq p (point))
6057               (narrow-to-region (point)
6058                                 (or (and (search-forward "\n.\n" nil t)
6059                                          (- (point) 2))
6060                                     (point))))
6061             ;; Subject.
6062             (progn
6063               (goto-char p)
6064               (if (search-forward "\nsubject:" nil t)
6065                   (funcall gnus-decode-encoded-word-function
6066                            (nnheader-header-value))
6067                 "(none)"))
6068             ;; From.
6069             (progn
6070               (goto-char p)
6071               (if (search-forward "\nfrom:" nil t)
6072                   (funcall gnus-decode-encoded-word-function
6073                            (nnheader-header-value))
6074                 "(nobody)"))
6075             ;; Date.
6076             (progn
6077               (goto-char p)
6078               (if (search-forward "\ndate:" nil t)
6079                   (nnheader-header-value) ""))
6080             ;; Message-ID.
6081             (progn
6082               (goto-char p)
6083               (setq id (if (re-search-forward
6084                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6085                            ;; We do it this way to make sure the Message-ID
6086                            ;; is (somewhat) syntactically valid.
6087                            (buffer-substring (match-beginning 1)
6088                                              (match-end 1))
6089                          ;; If there was no message-id, we just fake one
6090                          ;; to make subsequent routines simpler.
6091                          (nnheader-generate-fake-message-id number))))
6092             ;; References.
6093             (progn
6094               (goto-char p)
6095               (if (search-forward "\nreferences:" nil t)
6096                   (progn
6097                     (setq end (point))
6098                     (prog1
6099                         (nnheader-header-value)
6100                       (setq ref
6101                             (buffer-substring
6102                              (progn
6103                                (end-of-line)
6104                                (search-backward ">" end t)
6105                                (1+ (point)))
6106                              (progn
6107                                (search-backward "<" end t)
6108                                (point))))))
6109                 ;; Get the references from the in-reply-to header if there
6110                 ;; were no references and the in-reply-to header looks
6111                 ;; promising.
6112                 (if (and (search-forward "\nin-reply-to:" nil t)
6113                          (setq in-reply-to (nnheader-header-value))
6114                          (string-match "<[^>]+>" in-reply-to))
6115                     (let (ref2)
6116                       (setq ref (substring in-reply-to (match-beginning 0)
6117                                            (match-end 0)))
6118                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6119                         (setq ref2 (substring in-reply-to (match-beginning 0)
6120                                               (match-end 0)))
6121                         (when (> (length ref2) (length ref))
6122                           (setq ref ref2)))
6123                       ref)
6124                   (setq ref nil))))
6125             ;; Chars.
6126             (progn
6127               (goto-char p)
6128               (if (search-forward "\nchars: " nil t)
6129                   (if (numberp (setq chars (ignore-errors (read cur))))
6130                       chars -1)
6131                 -1))
6132             ;; Lines.
6133             (progn
6134               (goto-char p)
6135               (if (search-forward "\nlines: " nil t)
6136                   (if (numberp (setq lines (ignore-errors (read cur))))
6137                       lines -1)
6138                 -1))
6139             ;; Xref.
6140             (progn
6141               (goto-char p)
6142               (and (search-forward "\nxref:" nil t)
6143                    (nnheader-header-value)))
6144             ;; Extra.
6145             (when gnus-extra-headers
6146               (let ((extra gnus-extra-headers)
6147                     out)
6148                 (while extra
6149                   (goto-char p)
6150                   (when (search-forward
6151                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6152                     (push (cons (car extra) (nnheader-header-value))
6153                           out))
6154                   (pop extra))
6155                 out))))
6156           (when (equal id ref)
6157             (setq ref nil))
6158
6159           (when gnus-alter-header-function
6160             (funcall gnus-alter-header-function header)
6161             (setq id (mail-header-id header)
6162                   ref (gnus-parent-id (mail-header-references header))))
6163
6164           (when (setq header
6165                       (gnus-dependencies-add-header
6166                        header dependencies force-new))
6167             (push header headers))
6168           (goto-char (point-max))
6169           (widen))
6170         (nreverse headers)))))
6171
6172 ;; Goes through the xover lines and returns a list of vectors
6173 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6174                                                   force-new dependencies
6175                                                   group also-fetch-heads)
6176   "Parse the news overview data in the server buffer.
6177 Return a list of headers that match SEQUENCE (see
6178 `nntp-retrieve-headers')."
6179   ;; Get the Xref when the users reads the articles since most/some
6180   ;; NNTP servers do not include Xrefs when using XOVER.
6181   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6182   (let ((mail-parse-charset gnus-newsgroup-charset)
6183         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6184         (cur nntp-server-buffer)
6185         (dependencies (or dependencies gnus-newsgroup-dependencies))
6186         (allp (cond
6187                ((eq gnus-read-all-available-headers t)
6188                 t)
6189                ((and (stringp gnus-read-all-available-headers)
6190                      group)
6191                 (string-match gnus-read-all-available-headers group))
6192                (t
6193                 nil)))
6194         number headers header)
6195     (save-excursion
6196       (set-buffer nntp-server-buffer)
6197       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6198       ;; Allow the user to mangle the headers before parsing them.
6199       (gnus-run-hooks 'gnus-parse-headers-hook)
6200       (goto-char (point-min))
6201       (gnus-parse-without-error
6202         (while (and (or sequence allp)
6203                     (not (eobp)))
6204           (setq number (read cur))
6205           (when (not allp)
6206             (while (and sequence
6207                         (< (car sequence) number))
6208               (setq sequence (cdr sequence))))
6209           (when (and (or allp
6210                          (and sequence
6211                               (eq number (car sequence))))
6212                      (progn
6213                        (setq sequence (cdr sequence))
6214                        (setq header (inline
6215                                       (gnus-nov-parse-line
6216                                        number dependencies force-new)))))
6217             (push header headers))
6218           (forward-line 1)))
6219       ;; A common bug in inn is that if you have posted an article and
6220       ;; then retrieves the active file, it will answer correctly --
6221       ;; the new article is included.  However, a NOV entry for the
6222       ;; article may not have been generated yet, so this may fail.
6223       ;; We work around this problem by retrieving the last few
6224       ;; headers using HEAD.
6225       (if (or (not also-fetch-heads)
6226               (not sequence))
6227           ;; We (probably) got all the headers.
6228           (nreverse headers)
6229         (let ((gnus-nov-is-evil t))
6230           (nconc
6231            (nreverse headers)
6232            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6233              (gnus-get-newsgroup-headers))))))))
6234
6235 (defun gnus-article-get-xrefs ()
6236   "Fill in the Xref value in `gnus-current-headers', if necessary.
6237 This is meant to be called in `gnus-article-internal-prepare-hook'."
6238   (let ((headers (with-current-buffer gnus-summary-buffer
6239                    gnus-current-headers)))
6240     (or (not gnus-use-cross-reference)
6241         (not headers)
6242         (and (mail-header-xref headers)
6243              (not (string= (mail-header-xref headers) "")))
6244         (let ((case-fold-search t)
6245               xref)
6246           (save-restriction
6247             (nnheader-narrow-to-headers)
6248             (goto-char (point-min))
6249             (when (or (and (not (eobp))
6250                            (eq (downcase (char-after)) ?x)
6251                            (looking-at "Xref:"))
6252                       (search-forward "\nXref:" nil t))
6253               (goto-char (1+ (match-end 0)))
6254               (setq xref (buffer-substring (point) (point-at-eol)))
6255               (mail-header-set-xref headers xref)))))))
6256
6257 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6258   "Find article ID and insert the summary line for that article.
6259 OLD-HEADER can either be a header or a line number to insert
6260 the subject line on."
6261   (let* ((line (and (numberp old-header) old-header))
6262          (old-header (and (vectorp old-header) old-header))
6263          (header (cond ((and old-header use-old-header)
6264                         old-header)
6265                        ((and (numberp id)
6266                              (gnus-number-to-header id))
6267                         (gnus-number-to-header id))
6268                        (t
6269                         (gnus-read-header id))))
6270          (number (and (numberp id) id))
6271          d)
6272     (when header
6273       ;; Rebuild the thread that this article is part of and go to the
6274       ;; article we have fetched.
6275       (when (and (not gnus-show-threads)
6276                  old-header)
6277         (when (and number
6278                    (setq d (gnus-data-find (mail-header-number old-header))))
6279           (goto-char (gnus-data-pos d))
6280           (gnus-data-remove
6281            number
6282            (- (point-at-bol)
6283               (prog1
6284                   (1+ (point-at-eol))
6285                 (gnus-delete-line))))))
6286       ;; Remove list identifiers from subject.
6287       (when gnus-list-identifiers
6288         (let ((gnus-newsgroup-headers (list header)))
6289           (gnus-summary-remove-list-identifiers)))
6290       (when old-header
6291         (mail-header-set-number header (mail-header-number old-header)))
6292       (setq gnus-newsgroup-sparse
6293             (delq (setq number (mail-header-number header))
6294                   gnus-newsgroup-sparse))
6295       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6296       (push number gnus-newsgroup-limit)
6297       (gnus-rebuild-thread (mail-header-id header) line)
6298       (gnus-summary-goto-subject number nil t))
6299     (when (and (numberp number)
6300                (> number 0))
6301       ;; We have to update the boundaries even if we can't fetch the
6302       ;; article if ID is a number -- so that the next `P' or `N'
6303       ;; command will fetch the previous (or next) article even
6304       ;; if the one we tried to fetch this time has been canceled.
6305       (when (> number gnus-newsgroup-end)
6306         (setq gnus-newsgroup-end number))
6307       (when (< number gnus-newsgroup-begin)
6308         (setq gnus-newsgroup-begin number))
6309       (setq gnus-newsgroup-unselected
6310             (delq number gnus-newsgroup-unselected)))
6311     ;; Report back a success?
6312     (and header (mail-header-number header))))
6313
6314 ;;; Process/prefix in the summary buffer
6315
6316 (defun gnus-summary-work-articles (n)
6317   "Return a list of articles to be worked upon.
6318 The prefix argument, the list of process marked articles, and the
6319 current article will be taken into consideration."
6320   (save-excursion
6321     (set-buffer gnus-summary-buffer)
6322     (cond
6323      (n
6324       ;; A numerical prefix has been given.
6325       (setq n (prefix-numeric-value n))
6326       (let ((backward (< n 0))
6327             (n (abs (prefix-numeric-value n)))
6328             articles article)
6329         (save-excursion
6330           (while
6331               (and (> n 0)
6332                    (push (setq article (gnus-summary-article-number))
6333                          articles)
6334                    (if backward
6335                        (gnus-summary-find-prev nil article)
6336                      (gnus-summary-find-next nil article)))
6337             (decf n)))
6338         (nreverse articles)))
6339      ((and (gnus-region-active-p) (mark))
6340       (message "region active")
6341       ;; Work on the region between point and mark.
6342       (let ((max (max (point) (mark)))
6343             articles article)
6344         (save-excursion
6345           (goto-char (min (point) (mark)))
6346           (while
6347               (and
6348                (push (setq article (gnus-summary-article-number)) articles)
6349                (gnus-summary-find-next nil article)
6350                (< (point) max)))
6351           (nreverse articles))))
6352      (gnus-newsgroup-processable
6353       ;; There are process-marked articles present.
6354       ;; Save current state.
6355       (gnus-summary-save-process-mark)
6356       ;; Return the list.
6357       (reverse gnus-newsgroup-processable))
6358      (t
6359       ;; Just return the current article.
6360       (list (gnus-summary-article-number))))))
6361
6362 (defmacro gnus-summary-iterate (arg &rest forms)
6363   "Iterate over the process/prefixed articles and do FORMS.
6364 ARG is the interactive prefix given to the command.  FORMS will be
6365 executed with point over the summary line of the articles."
6366   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6367     `(let ((,articles (gnus-summary-work-articles ,arg)))
6368        (while ,articles
6369          (gnus-summary-goto-subject (car ,articles))
6370          ,@forms
6371          (pop ,articles)))))
6372
6373 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6374 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6375
6376 (defun gnus-summary-save-process-mark ()
6377   "Push the current set of process marked articles on the stack."
6378   (interactive)
6379   (push (copy-sequence gnus-newsgroup-processable)
6380         gnus-newsgroup-process-stack))
6381
6382 (defun gnus-summary-kill-process-mark ()
6383   "Push the current set of process marked articles on the stack and unmark."
6384   (interactive)
6385   (gnus-summary-save-process-mark)
6386   (gnus-summary-unmark-all-processable))
6387
6388 (defun gnus-summary-yank-process-mark ()
6389   "Pop the last process mark state off the stack and restore it."
6390   (interactive)
6391   (unless gnus-newsgroup-process-stack
6392     (error "Empty mark stack"))
6393   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6394
6395 (defun gnus-summary-process-mark-set (set)
6396   "Make SET into the current process marked articles."
6397   (gnus-summary-unmark-all-processable)
6398   (mapc 'gnus-summary-set-process-mark set))
6399
6400 ;;; Searching and stuff
6401
6402 (defun gnus-summary-search-group (&optional backward use-level)
6403   "Search for next unread newsgroup.
6404 If optional argument BACKWARD is non-nil, search backward instead."
6405   (save-excursion
6406     (set-buffer gnus-group-buffer)
6407     (when (gnus-group-search-forward
6408            backward nil (if use-level (gnus-group-group-level) nil))
6409       (gnus-group-group-name))))
6410
6411 (defun gnus-summary-best-group (&optional exclude-group)
6412   "Find the name of the best unread group.
6413 If EXCLUDE-GROUP, do not go to this group."
6414   (with-current-buffer gnus-group-buffer
6415     (save-excursion
6416       (gnus-group-best-unread-group exclude-group))))
6417
6418 (defun gnus-summary-find-next (&optional unread article backward)
6419   (if backward
6420       (gnus-summary-find-prev unread article)
6421     (let* ((dummy (gnus-summary-article-intangible-p))
6422            (article (or article (gnus-summary-article-number)))
6423            (data (gnus-data-find-list article))
6424            result)
6425       (when (and (not dummy)
6426                  (or (not gnus-summary-check-current)
6427                      (not unread)
6428                      (not (gnus-data-unread-p (car data)))))
6429         (setq data (cdr data)))
6430       (when (setq result
6431                   (if unread
6432                       (progn
6433                         (while data
6434                           (unless (memq (gnus-data-number (car data))
6435                                         (cond
6436                                          ((eq gnus-auto-goto-ignores
6437                                               'always-undownloaded)
6438                                           gnus-newsgroup-undownloaded)
6439                                          (gnus-plugged
6440                                           nil)
6441                                          ((eq gnus-auto-goto-ignores
6442                                               'unfetched)
6443                                           gnus-newsgroup-unfetched)
6444                                          ((eq gnus-auto-goto-ignores
6445                                               'undownloaded)
6446                                           gnus-newsgroup-undownloaded)))
6447                             (when (gnus-data-unread-p (car data))
6448                               (setq result (car data)
6449                                     data nil)))
6450                           (setq data (cdr data)))
6451                         result)
6452                     (car data)))
6453         (goto-char (gnus-data-pos result))
6454         (gnus-data-number result)))))
6455
6456 (defun gnus-summary-find-prev (&optional unread article)
6457   (let* ((eobp (eobp))
6458          (article (or article (gnus-summary-article-number)))
6459          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6460          result)
6461     (when (and (not eobp)
6462                (or (not gnus-summary-check-current)
6463                    (not unread)
6464                    (not (gnus-data-unread-p (car data)))))
6465       (setq data (cdr data)))
6466     (when (setq result
6467                 (if unread
6468                     (progn
6469                       (while data
6470                         (unless (memq (gnus-data-number (car data))
6471                                       (cond
6472                                        ((eq gnus-auto-goto-ignores
6473                                             'always-undownloaded)
6474                                         gnus-newsgroup-undownloaded)
6475                                        (gnus-plugged
6476                                         nil)
6477                                        ((eq gnus-auto-goto-ignores
6478                                             'unfetched)
6479                                         gnus-newsgroup-unfetched)
6480                                        ((eq gnus-auto-goto-ignores
6481                                             'undownloaded)
6482                                         gnus-newsgroup-undownloaded)))
6483                           (when (gnus-data-unread-p (car data))
6484                             (setq result (car data)
6485                                   data nil)))
6486                         (setq data (cdr data)))
6487                       result)
6488                   (car data)))
6489       (goto-char (gnus-data-pos result))
6490       (gnus-data-number result))))
6491
6492 (defun gnus-summary-find-subject (subject &optional unread backward article)
6493   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6494          (article (or article (gnus-summary-article-number)))
6495          (articles (gnus-data-list backward))
6496          (arts (gnus-data-find-list article articles))
6497          result)
6498     (when (or (not gnus-summary-check-current)
6499               (not unread)
6500               (not (gnus-data-unread-p (car arts))))
6501       (setq arts (cdr arts)))
6502     (while arts
6503       (and (or (not unread)
6504                (gnus-data-unread-p (car arts)))
6505            (vectorp (gnus-data-header (car arts)))
6506            (gnus-subject-equal
6507             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6508            (setq result (car arts)
6509                  arts nil))
6510       (setq arts (cdr arts)))
6511     (and result
6512          (goto-char (gnus-data-pos result))
6513          (gnus-data-number result))))
6514
6515 (defun gnus-summary-search-forward (&optional unread subject backward)
6516   "Search forward for an article.
6517 If UNREAD, look for unread articles.  If SUBJECT, look for
6518 articles with that subject.  If BACKWARD, search backward instead."
6519   (cond (subject (gnus-summary-find-subject subject unread backward))
6520         (backward (gnus-summary-find-prev unread))
6521         (t (gnus-summary-find-next unread))))
6522
6523 (defun gnus-recenter (&optional n)
6524   "Center point in window and redisplay frame.
6525 Also do horizontal recentering."
6526   (interactive "P")
6527   (when (and gnus-auto-center-summary
6528              (not (eq gnus-auto-center-summary 'vertical)))
6529     (gnus-horizontal-recenter))
6530   (recenter n))
6531
6532 (defun gnus-summary-recenter ()
6533   "Center point in the summary window.
6534 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6535 displayed, no centering will be performed."
6536   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6537   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6538   (interactive)
6539   ;; The user has to want it.
6540   (when gnus-auto-center-summary
6541     (let* ((top (cond ((< (window-height) 4) 0)
6542                       ((< (window-height) 7) 1)
6543                       (t (if (numberp gnus-auto-center-summary)
6544                              gnus-auto-center-summary
6545                            (/ (1- (window-height)) 2)))))
6546            (height (1- (window-height)))
6547            (bottom (save-excursion (goto-char (point-max))
6548                                    (forward-line (- height))
6549                                    (point)))
6550            (window (get-buffer-window (current-buffer))))
6551       (when (get-buffer-window gnus-article-buffer)
6552         ;; Only do recentering when the article buffer is displayed,
6553         ;; Set the window start to either `bottom', which is the biggest
6554         ;; possible valid number, or the second line from the top,
6555         ;; whichever is the least.
6556         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6557           (if (> bottom top-pos)
6558               ;; Keep the second line from the top visible
6559               (set-window-start window top-pos t)
6560             ;; Try to keep the bottom line visible; if it's partially
6561             ;; obscured, either scroll one more line to make it fully
6562             ;; visible, or revert to using TOP-POS.
6563             (save-excursion
6564               (goto-char (point-max))
6565               (forward-line -1)
6566               (let ((last-line-start (point)))
6567                 (goto-char bottom)
6568                 (set-window-start window (point) t)
6569                 (when (not (pos-visible-in-window-p last-line-start window))
6570                   (forward-line 1)
6571                   (set-window-start window (min (point) top-pos) t)))))))
6572       ;; Do horizontal recentering while we're at it.
6573       (when (and (get-buffer-window (current-buffer) t)
6574                  (not (eq gnus-auto-center-summary 'vertical)))
6575         (let ((selected (selected-window)))
6576           (select-window (get-buffer-window (current-buffer) t))
6577           (gnus-summary-position-point)
6578           (gnus-horizontal-recenter)
6579           (select-window selected))))))
6580
6581 (defun gnus-summary-jump-to-group (newsgroup)
6582   "Move point to NEWSGROUP in group mode buffer."
6583   ;; Keep update point of group mode buffer if visible.
6584   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6585       (save-window-excursion
6586         ;; Take care of tree window mode.
6587         (when (get-buffer-window gnus-group-buffer)
6588           (pop-to-buffer gnus-group-buffer))
6589         (gnus-group-jump-to-group newsgroup))
6590     (save-excursion
6591       ;; Take care of tree window mode.
6592       (if (get-buffer-window gnus-group-buffer)
6593           (pop-to-buffer gnus-group-buffer)
6594         (set-buffer gnus-group-buffer))
6595       (gnus-group-jump-to-group newsgroup))))
6596
6597 ;; This function returns a list of article numbers based on the
6598 ;; difference between the ranges of read articles in this group and
6599 ;; the range of active articles.
6600 (defun gnus-list-of-unread-articles (group)
6601   (let* ((read (gnus-info-read (gnus-get-info group)))
6602          (active (or (gnus-active group) (gnus-activate-group group)))
6603          (last (or (cdr active)
6604                    (error "Group %s couldn't be activated " group)))
6605          first nlast unread)
6606     ;; If none are read, then all are unread.
6607     (if (not read)
6608         (setq first (car active))
6609       ;; If the range of read articles is a single range, then the
6610       ;; first unread article is the article after the last read
6611       ;; article.  Sounds logical, doesn't it?
6612       (if (and (not (listp (cdr read)))
6613                (or (< (car read) (car active))
6614                    (progn (setq read (list read))
6615                           nil)))
6616           (setq first (max (car active) (1+ (cdr read))))
6617         ;; `read' is a list of ranges.
6618         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6619                                   (caar read)))
6620                   1)
6621           (setq first (car active)))
6622         (while read
6623           (when first
6624             (while (< first nlast)
6625               (setq unread (cons first unread)
6626                     first (1+ first))))
6627           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6628           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6629           (setq read (cdr read)))))
6630     ;; And add the last unread articles.
6631     (while (<= first last)
6632       (setq unread (cons first unread)
6633             first (1+ first)))
6634     ;; Return the list of unread articles.
6635     (delq 0 (nreverse unread))))
6636
6637 (defun gnus-list-of-read-articles (group)
6638   "Return a list of unread, unticked and non-dormant articles."
6639   (let* ((info (gnus-get-info group))
6640          (marked (gnus-info-marks info))
6641          (active (gnus-active group)))
6642     (and info active
6643          (gnus-list-range-difference
6644           (gnus-list-range-difference
6645            (gnus-sorted-complement
6646             (gnus-uncompress-range active)
6647             (gnus-list-of-unread-articles group))
6648            (cdr (assq 'dormant marked)))
6649           (cdr (assq 'tick marked))))))
6650
6651 ;; This function returns a sequence of article numbers based on the
6652 ;; difference between the ranges of read articles in this group and
6653 ;; the range of active articles.
6654 (defun gnus-sequence-of-unread-articles (group)
6655   (let* ((read (gnus-info-read (gnus-get-info group)))
6656          (active (or (gnus-active group) (gnus-activate-group group)))
6657          (last (cdr active))
6658          first nlast unread)
6659     ;; If none are read, then all are unread.
6660     (if (not read)
6661         (setq first (car active))
6662       ;; If the range of read articles is a single range, then the
6663       ;; first unread article is the article after the last read
6664       ;; article.  Sounds logical, doesn't it?
6665       (if (and (not (listp (cdr read)))
6666                (or (< (car read) (car active))
6667                    (progn (setq read (list read))
6668                           nil)))
6669           (setq first (max (car active) (1+ (cdr read))))
6670         ;; `read' is a list of ranges.
6671         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6672                                   (caar read)))
6673                   1)
6674           (setq first (car active)))
6675         (while read
6676           (when first
6677             (push (cons first nlast) unread))
6678           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6679           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6680           (setq read (cdr read)))))
6681     ;; And add the last unread articles.
6682     (cond ((not (and first last))
6683            nil)
6684           ((< first last)
6685            (push (cons first last) unread))
6686           ((= first last)
6687            (push first unread)))
6688     ;; Return the sequence of unread articles.
6689     (delq 0 (nreverse unread))))
6690
6691 ;; Various summary commands
6692
6693 (defun gnus-summary-select-article-buffer ()
6694   "Reconfigure windows to show article buffer."
6695   (interactive)
6696   (if (not (gnus-buffer-live-p gnus-article-buffer))
6697       (error "There is no article buffer for this summary buffer")
6698     (gnus-configure-windows 'article)
6699     (select-window (get-buffer-window gnus-article-buffer))))
6700
6701 (defun gnus-summary-universal-argument (arg)
6702   "Perform any operation on all articles that are process/prefixed."
6703   (interactive "P")
6704   (let ((articles (gnus-summary-work-articles arg))
6705         func article)
6706     (if (eq
6707          (setq
6708           func
6709           (key-binding
6710            (read-key-sequence
6711             (substitute-command-keys
6712              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6713          'undefined)
6714         (gnus-error 1 "Undefined key")
6715       (save-excursion
6716         (while articles
6717           (gnus-summary-goto-subject (setq article (pop articles)))
6718           (let (gnus-newsgroup-processable)
6719             (command-execute func))
6720           (gnus-summary-remove-process-mark article)))))
6721   (gnus-summary-position-point))
6722
6723 (defun gnus-summary-toggle-truncation (&optional arg)
6724   "Toggle truncation of summary lines.
6725 With ARG, turn line truncation on if ARG is positive."
6726   (interactive "P")
6727   (setq truncate-lines
6728         (if (null arg) (not truncate-lines)
6729           (> (prefix-numeric-value arg) 0)))
6730   (redraw-display))
6731
6732 (defun gnus-summary-find-for-reselect ()
6733   "Return the number of an article to stay on across a reselect.
6734 The current article is considered, then following articles, then previous
6735 articles.  An article is sought which is not cancelled and isn't a temporary
6736 insertion from another group.  If there's no such then return a dummy 0."
6737   (let (found)
6738     (dolist (rev '(nil t))
6739       (unless found      ; don't demand the reverse list if we don't need it
6740         (let ((data (gnus-data-find-list
6741                      (gnus-summary-article-number) (gnus-data-list rev))))
6742           (while (and data (not found))
6743             (if (and (< 0 (gnus-data-number (car data)))
6744                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6745                 (setq found (gnus-data-number (car data))))
6746             (setq data (cdr data))))))
6747     (or found 0)))
6748
6749 (defun gnus-summary-reselect-current-group (&optional all rescan)
6750   "Exit and then reselect the current newsgroup.
6751 The prefix argument ALL means to select all articles."
6752   (interactive "P")
6753   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6754     (error "Ephemeral groups can't be reselected"))
6755   (let ((current-subject (gnus-summary-find-for-reselect))
6756         (group gnus-newsgroup-name))
6757     (setq gnus-newsgroup-begin nil)
6758     (gnus-summary-exit nil 'leave-hidden)
6759     ;; We have to adjust the point of group mode buffer because
6760     ;; point was moved to the next unread newsgroup by exiting.
6761     (gnus-summary-jump-to-group group)
6762     (when rescan
6763       (save-excursion
6764         (gnus-group-get-new-news-this-group 1)))
6765     (gnus-group-read-group all t)
6766     (gnus-summary-goto-subject current-subject nil t)))
6767
6768 (defun gnus-summary-rescan-group (&optional all)
6769   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6770   (interactive "P")
6771   (gnus-summary-reselect-current-group all t))
6772
6773 (defun gnus-summary-update-info (&optional non-destructive)
6774   (save-excursion
6775     (let ((group gnus-newsgroup-name))
6776       (when group
6777         (when gnus-newsgroup-kill-headers
6778           (setq gnus-newsgroup-killed
6779                 (gnus-compress-sequence
6780                  (gnus-sorted-union
6781                   (gnus-list-range-intersection
6782                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6783                   gnus-newsgroup-unreads)
6784                  t)))
6785         (unless (listp (cdr gnus-newsgroup-killed))
6786           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6787         (let ((headers gnus-newsgroup-headers))
6788           ;; Set the new ranges of read articles.
6789           (with-current-buffer gnus-group-buffer
6790             (gnus-undo-force-boundary))
6791           (gnus-update-read-articles
6792            group (gnus-sorted-union
6793                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6794           ;; Set the current article marks.
6795           (let ((gnus-newsgroup-scored
6796                  (if (and (not gnus-save-score)
6797                           (not non-destructive))
6798                      nil
6799                    gnus-newsgroup-scored)))
6800             (save-excursion
6801               (gnus-update-marks)))
6802           ;; Do the cross-ref thing.
6803           (when gnus-use-cross-reference
6804             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6805           ;; Do not switch windows but change the buffer to work.
6806           (set-buffer gnus-group-buffer)
6807           (unless (gnus-ephemeral-group-p group)
6808             (gnus-group-update-group group)))))))
6809
6810 (defun gnus-summary-save-newsrc (&optional force)
6811   "Save the current number of read/marked articles in the dribble buffer.
6812 The dribble buffer will then be saved.
6813 If FORCE (the prefix), also save the .newsrc file(s)."
6814   (interactive "P")
6815   (gnus-summary-update-info t)
6816   (if force
6817       (gnus-save-newsrc-file)
6818     (gnus-dribble-save)))
6819
6820 (defun gnus-summary-exit (&optional temporary leave-hidden)
6821   "Exit reading current newsgroup, and then return to group selection mode.
6822 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6823   (interactive)
6824   (gnus-set-global-variables)
6825   (when (gnus-buffer-live-p gnus-article-buffer)
6826     (save-excursion
6827       (set-buffer gnus-article-buffer)
6828       (mm-destroy-parts gnus-article-mime-handles)
6829       ;; Set it to nil for safety reason.
6830       (setq gnus-article-mime-handle-alist nil)
6831       (setq gnus-article-mime-handles nil)))
6832   (gnus-kill-save-kill-buffer)
6833   (gnus-async-halt-prefetch)
6834   (let* ((group gnus-newsgroup-name)
6835          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6836          (gnus-group-is-exiting-p t)
6837          (mode major-mode)
6838          (group-point nil)
6839          (buf (current-buffer)))
6840     (unless quit-config
6841       ;; Do adaptive scoring, and possibly save score files.
6842       (when gnus-newsgroup-adaptive
6843         (gnus-score-adaptive))
6844       (when gnus-use-scoring
6845         (gnus-score-save)))
6846     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6847     ;; If we have several article buffers, we kill them at exit.
6848     (unless gnus-single-article-buffer
6849       (gnus-kill-buffer gnus-article-buffer)
6850       (gnus-kill-buffer gnus-original-article-buffer)
6851       (setq gnus-article-current nil))
6852     (when gnus-use-cache
6853       (gnus-cache-possibly-remove-articles)
6854       (gnus-cache-save-buffers))
6855     (gnus-async-prefetch-remove-group group)
6856     (when gnus-suppress-duplicates
6857       (gnus-dup-enter-articles))
6858     (when gnus-use-trees
6859       (gnus-tree-close group))
6860     (when gnus-use-cache
6861       (gnus-cache-write-active))
6862     ;; Remove entries for this group.
6863     (nnmail-purge-split-history (gnus-group-real-name group))
6864     ;; Make all changes in this group permanent.
6865     (unless quit-config
6866       (gnus-run-hooks 'gnus-exit-group-hook)
6867       (gnus-summary-update-info))
6868     (gnus-close-group group)
6869     ;; Make sure where we were, and go to next newsgroup.
6870     (set-buffer gnus-group-buffer)
6871     (unless quit-config
6872       (gnus-group-jump-to-group group))
6873     (gnus-run-hooks 'gnus-summary-exit-hook)
6874     (unless (or quit-config
6875                 ;; If this group has disappeared from the summary
6876                 ;; buffer, don't skip forwards.
6877                 (not (string= group (gnus-group-group-name))))
6878       (gnus-group-next-unread-group 1))
6879     (setq group-point (point))
6880     (if temporary
6881         nil                             ;Nothing to do.
6882       ;; If we have several article buffers, we kill them at exit.
6883       (unless gnus-single-article-buffer
6884         (gnus-kill-buffer gnus-article-buffer)
6885         (gnus-kill-buffer gnus-original-article-buffer)
6886         (setq gnus-article-current nil))
6887       (set-buffer buf)
6888       (if (not gnus-kill-summary-on-exit)
6889           (progn
6890             (gnus-deaden-summary)
6891             (setq mode nil))
6892         ;; We set all buffer-local variables to nil.  It is unclear why
6893         ;; this is needed, but if we don't, buffer-local variables are
6894         ;; not garbage-collected, it seems.  This would the lead to en
6895         ;; ever-growing Emacs.
6896         (gnus-summary-clear-local-variables)
6897         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6898           (gnus-summary-clear-local-variables))
6899         (when (get-buffer gnus-article-buffer)
6900           (bury-buffer gnus-article-buffer))
6901         ;; Return to group mode buffer.
6902         (when (eq mode 'gnus-summary-mode)
6903           (gnus-kill-buffer buf)))
6904       (setq gnus-current-select-method gnus-select-method)
6905       (set-buffer gnus-group-buffer)
6906       (if quit-config
6907           (gnus-handle-ephemeral-exit quit-config)
6908         (goto-char group-point)
6909         ;; If gnus-group-buffer is already displayed, make sure we also move
6910         ;; the cursor in the window that displays it.
6911         (let ((win (get-buffer-window (current-buffer) 0)))
6912           (if win (set-window-point win (point))))
6913         (unless leave-hidden
6914           (gnus-configure-windows 'group 'force)))
6915       ;; Clear the current group name.
6916       (unless quit-config
6917         (setq gnus-newsgroup-name nil)))))
6918
6919 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6920 (defun gnus-summary-exit-no-update (&optional no-questions)
6921   "Quit reading current newsgroup without updating read article info."
6922   (interactive)
6923   (let* ((group gnus-newsgroup-name)
6924          (gnus-group-is-exiting-p t)
6925          (gnus-group-is-exiting-without-update-p t)
6926          (quit-config (gnus-group-quit-config group)))
6927     (when (or no-questions
6928               gnus-expert-user
6929               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6930       (gnus-async-halt-prefetch)
6931       (run-hooks 'gnus-summary-prepare-exit-hook)
6932       (when (gnus-buffer-live-p gnus-article-buffer)
6933         (save-excursion
6934           (set-buffer gnus-article-buffer)
6935           (mm-destroy-parts gnus-article-mime-handles)
6936           ;; Set it to nil for safety reason.
6937           (setq gnus-article-mime-handle-alist nil)
6938           (setq gnus-article-mime-handles nil)))
6939       ;; If we have several article buffers, we kill them at exit.
6940       (unless gnus-single-article-buffer
6941         (gnus-kill-buffer gnus-article-buffer)
6942         (gnus-kill-buffer gnus-original-article-buffer)
6943         (setq gnus-article-current nil))
6944       (if (not gnus-kill-summary-on-exit)
6945           (gnus-deaden-summary)
6946         (gnus-close-group group)
6947         (gnus-summary-clear-local-variables)
6948         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6949           (gnus-summary-clear-local-variables))
6950         (gnus-kill-buffer gnus-summary-buffer))
6951       (unless gnus-single-article-buffer
6952         (setq gnus-article-current nil))
6953       (when gnus-use-trees
6954         (gnus-tree-close group))
6955       (gnus-async-prefetch-remove-group group)
6956       (when (get-buffer gnus-article-buffer)
6957         (bury-buffer gnus-article-buffer))
6958       ;; Return to the group buffer.
6959       (gnus-configure-windows 'group 'force)
6960       ;; Clear the current group name.
6961       (setq gnus-newsgroup-name nil)
6962       (unless (gnus-ephemeral-group-p group)
6963         (gnus-group-update-group group))
6964       (when (equal (gnus-group-group-name) group)
6965         (gnus-group-next-unread-group 1))
6966       (when quit-config
6967         (gnus-handle-ephemeral-exit quit-config)))))
6968
6969 (defun gnus-handle-ephemeral-exit (quit-config)
6970   "Handle movement when leaving an ephemeral group.
6971 The state which existed when entering the ephemeral is reset."
6972   (if (not (buffer-name (car quit-config)))
6973       (gnus-configure-windows 'group 'force)
6974     (set-buffer (car quit-config))
6975     (cond ((eq major-mode 'gnus-summary-mode)
6976            (gnus-set-global-variables))
6977           ((eq major-mode 'gnus-article-mode)
6978            (save-excursion
6979              ;; The `gnus-summary-buffer' variable may point
6980              ;; to the old summary buffer when using a single
6981              ;; article buffer.
6982              (unless (gnus-buffer-live-p gnus-summary-buffer)
6983                (set-buffer gnus-group-buffer))
6984              (set-buffer gnus-summary-buffer)
6985              (gnus-set-global-variables))))
6986     (if (or (eq (cdr quit-config) 'article)
6987             (eq (cdr quit-config) 'pick))
6988         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6989             (gnus-configure-windows 'pick 'force)
6990           (gnus-configure-windows (cdr quit-config) 'force))
6991       (gnus-configure-windows (cdr quit-config) 'force))
6992     (when (eq major-mode 'gnus-summary-mode)
6993       (gnus-summary-recenter)
6994       (gnus-summary-position-point))))
6995
6996 ;;; Dead summaries.
6997
6998 (defvar gnus-dead-summary-mode-map nil)
6999
7000 (unless gnus-dead-summary-mode-map
7001   (setq gnus-dead-summary-mode-map (make-keymap))
7002   (suppress-keymap gnus-dead-summary-mode-map)
7003   (substitute-key-definition
7004    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7005   (dolist (key '("\C-d" "\r" "\177" [delete]))
7006     (define-key gnus-dead-summary-mode-map
7007       key 'gnus-summary-wake-up-the-dead))
7008   (dolist (key '("q" "Q"))
7009     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7010
7011 (defvar gnus-dead-summary-mode nil
7012   "Minor mode for Gnus summary buffers.")
7013
7014 (defun gnus-dead-summary-mode (&optional arg)
7015   "Minor mode for Gnus summary buffers."
7016   (interactive "P")
7017   (when (eq major-mode 'gnus-summary-mode)
7018     (make-local-variable 'gnus-dead-summary-mode)
7019     (setq gnus-dead-summary-mode
7020           (if (null arg) (not gnus-dead-summary-mode)
7021             (> (prefix-numeric-value arg) 0)))
7022     (when gnus-dead-summary-mode
7023       (add-minor-mode
7024        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7025
7026 (defun gnus-deaden-summary ()
7027   "Make the current summary buffer into a dead summary buffer."
7028   ;; Kill any previous dead summary buffer.
7029   (when (and gnus-dead-summary
7030              (buffer-name gnus-dead-summary))
7031     (with-current-buffer gnus-dead-summary
7032       (when gnus-dead-summary-mode
7033         (kill-buffer (current-buffer)))))
7034   ;; Make this the current dead summary.
7035   (setq gnus-dead-summary (current-buffer))
7036   (gnus-dead-summary-mode 1)
7037   (let ((name (buffer-name)))
7038     (when (string-match "Summary" name)
7039       (rename-buffer
7040        (concat (substring name 0 (match-beginning 0)) "Dead "
7041                (substring name (match-beginning 0)))
7042        t)
7043       (bury-buffer))))
7044
7045 (defun gnus-kill-or-deaden-summary (buffer)
7046   "Kill or deaden the summary BUFFER."
7047   (save-excursion
7048     (when (and (buffer-name buffer)
7049                (not gnus-single-article-buffer))
7050       (with-current-buffer buffer
7051         (gnus-kill-buffer gnus-article-buffer)
7052         (gnus-kill-buffer gnus-original-article-buffer)))
7053     (cond
7054      ;; Kill the buffer.
7055      (gnus-kill-summary-on-exit
7056       (when (and gnus-use-trees
7057                  (gnus-buffer-exists-p buffer))
7058         (save-excursion
7059           (set-buffer buffer)
7060           (gnus-tree-close gnus-newsgroup-name)))
7061       (gnus-kill-buffer buffer))
7062      ;; Deaden the buffer.
7063      ((gnus-buffer-exists-p buffer)
7064       (save-excursion
7065         (set-buffer buffer)
7066         (gnus-deaden-summary))))))
7067
7068 (defun gnus-summary-wake-up-the-dead (&rest args)
7069   "Wake up the dead summary buffer."
7070   (interactive)
7071   (gnus-dead-summary-mode -1)
7072   (let ((name (buffer-name)))
7073     (when (string-match "Dead " name)
7074       (rename-buffer
7075        (concat (substring name 0 (match-beginning 0))
7076                (substring name (match-end 0)))
7077        t)))
7078   (gnus-message 3 "This dead summary is now alive again"))
7079
7080 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7081 (defun gnus-summary-fetch-faq (&optional faq-dir)
7082   "Fetch the FAQ for the current group.
7083 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7084 in."
7085   (interactive
7086    (list
7087     (when current-prefix-arg
7088       (completing-read
7089        "FAQ dir: " (and (listp gnus-group-faq-directory)
7090                         (mapcar 'list
7091                                 gnus-group-faq-directory))))))
7092   (let (gnus-faq-buffer)
7093     (when (setq gnus-faq-buffer
7094                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7095       (gnus-configure-windows 'summary-faq))))
7096
7097 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7098 (defun gnus-summary-describe-group (&optional force)
7099   "Describe the current newsgroup."
7100   (interactive "P")
7101   (gnus-group-describe-group force gnus-newsgroup-name))
7102
7103 (defun gnus-summary-describe-briefly ()
7104   "Describe summary mode commands briefly."
7105   (interactive)
7106   (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")))
7107
7108 ;; Walking around group mode buffer from summary mode.
7109
7110 (defun gnus-summary-next-group (&optional no-article target-group backward)
7111   "Exit current newsgroup and then select next unread newsgroup.
7112 If prefix argument NO-ARTICLE is non-nil, no article is selected
7113 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7114 previous group instead."
7115   (interactive "P")
7116   ;; Stop pre-fetching.
7117   (gnus-async-halt-prefetch)
7118   (let ((current-group gnus-newsgroup-name)
7119         (current-buffer (current-buffer))
7120         entered)
7121     ;; First we semi-exit this group to update Xrefs and all variables.
7122     ;; We can't do a real exit, because the window conf must remain
7123     ;; the same in case the user is prompted for info, and we don't
7124     ;; want the window conf to change before that...
7125     (gnus-summary-exit t)
7126     (while (not entered)
7127       ;; Then we find what group we are supposed to enter.
7128       (set-buffer gnus-group-buffer)
7129       (gnus-group-jump-to-group current-group)
7130       (setq target-group
7131             (or target-group
7132                 (if (eq gnus-keep-same-level 'best)
7133                     (gnus-summary-best-group gnus-newsgroup-name)
7134                   (gnus-summary-search-group backward gnus-keep-same-level))))
7135       (if (not target-group)
7136           ;; There are no further groups, so we return to the group
7137           ;; buffer.
7138           (progn
7139             (gnus-message 5 "Returning to the group buffer")
7140             (setq entered t)
7141             (when (gnus-buffer-live-p current-buffer)
7142               (set-buffer current-buffer)
7143               (gnus-summary-exit))
7144             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7145         ;; We try to enter the target group.
7146         (gnus-group-jump-to-group target-group)
7147         (let ((unreads (gnus-group-group-unread)))
7148           (if (and (or (eq t unreads)
7149                        (and unreads (not (zerop unreads))))
7150                    (gnus-summary-read-group
7151                     target-group nil no-article
7152                     (and (buffer-name current-buffer) current-buffer)
7153                     nil backward))
7154               (setq entered t)
7155             (setq current-group target-group
7156                   target-group nil)))))))
7157
7158 (defun gnus-summary-prev-group (&optional no-article)
7159   "Exit current newsgroup and then select previous unread newsgroup.
7160 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7161   (interactive "P")
7162   (gnus-summary-next-group no-article nil t))
7163
7164 ;; Walking around summary lines.
7165
7166 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7167   "Go to the first subject satisfying any non-nil constraint.
7168 If UNREAD is non-nil, the article should be unread.
7169 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7170 If UNSEEN is non-nil, the article should be unseen.
7171 Returns the article selected or nil if there are no matching articles."
7172   (interactive "P")
7173   (cond
7174    ;; Empty summary.
7175    ((null gnus-newsgroup-data)
7176     (gnus-message 3 "No articles in the group")
7177     nil)
7178    ;; Pick the first article.
7179    ((not (or unread undownloaded unseen))
7180     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7181     (gnus-data-number (car gnus-newsgroup-data)))
7182    ;; Find the first unread article.
7183    (t
7184     (let ((data gnus-newsgroup-data))
7185       (while (and data
7186                   (let ((num (gnus-data-number (car data))))
7187                     (or (memq num gnus-newsgroup-unfetched)
7188                         (not (or (and unread
7189                                       (memq num gnus-newsgroup-unreads))
7190                                  (and undownloaded
7191                                       (memq num gnus-newsgroup-undownloaded))
7192                                  (and unseen
7193                                       (memq num gnus-newsgroup-unseen)))))))
7194         (setq data (cdr data)))
7195       (prog1
7196           (if data
7197               (progn
7198                 (goto-char (gnus-data-pos (car data)))
7199                 (gnus-data-number (car data)))
7200             (gnus-message 3 "No more%s articles"
7201                           (let* ((r (when unread " unread"))
7202                                  (d (when undownloaded " undownloaded"))
7203                                  (s (when unseen " unseen"))
7204                                  (l (delq nil (list r d s))))
7205                             (cond ((= 3 (length l))
7206                                    (concat r "," d ", or" s))
7207                                   ((= 2 (length l))
7208                                    (concat (car l) ", or" (cadr l)))
7209                                   ((= 1 (length l))
7210                                    (car l))
7211                                   (t
7212                                    ""))))
7213             nil
7214             )
7215         (gnus-summary-position-point))))))
7216
7217 (defun gnus-summary-next-subject (n &optional unread dont-display)
7218   "Go to next N'th summary line.
7219 If N is negative, go to the previous N'th subject line.
7220 If UNREAD is non-nil, only unread articles are selected.
7221 The difference between N and the actual number of steps taken is
7222 returned."
7223   (interactive "p")
7224   (let ((backward (< n 0))
7225         (n (abs n)))
7226     (while (and (> n 0)
7227                 (if backward
7228                     (gnus-summary-find-prev unread)
7229                   (gnus-summary-find-next unread)))
7230       (unless (zerop (setq n (1- n)))
7231         (gnus-summary-show-thread)))
7232     (when (/= 0 n)
7233       (gnus-message 7 "No more%s articles"
7234                     (if unread " unread" "")))
7235     (unless dont-display
7236       (gnus-summary-recenter)
7237       (gnus-summary-position-point))
7238     n))
7239
7240 (defun gnus-summary-next-unread-subject (n)
7241   "Go to next N'th unread summary line."
7242   (interactive "p")
7243   (gnus-summary-next-subject n t))
7244
7245 (defun gnus-summary-prev-subject (n &optional unread)
7246   "Go to previous N'th summary line.
7247 If optional argument UNREAD is non-nil, only unread article is selected."
7248   (interactive "p")
7249   (gnus-summary-next-subject (- n) unread))
7250
7251 (defun gnus-summary-prev-unread-subject (n)
7252   "Go to previous N'th unread summary line."
7253   (interactive "p")
7254   (gnus-summary-next-subject (- n) t))
7255
7256 (defun gnus-summary-goto-subjects (articles)
7257   "Insert the subject header for ARTICLES in the current buffer."
7258   (save-excursion
7259     (dolist (article articles)
7260       (gnus-summary-goto-subject article t)))
7261   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7262   (gnus-summary-position-point))
7263
7264 (defun gnus-summary-goto-subject (article &optional force silent)
7265   "Go the subject line of ARTICLE.
7266 If FORCE, also allow jumping to articles not currently shown."
7267   (interactive "nArticle number: ")
7268   (unless (numberp article)
7269     (error "Article %s is not a number" article))
7270   (let ((b (point))
7271         (data (gnus-data-find article)))
7272     ;; We read in the article if we have to.
7273     (and (not data)
7274          force
7275          (gnus-summary-insert-subject
7276           article
7277           (if (or (numberp force) (vectorp force)) force)
7278           t)
7279          (setq data (gnus-data-find article)))
7280     (goto-char b)
7281     (if (not data)
7282         (progn
7283           (unless silent
7284             (gnus-message 3 "Can't find article %d" article))
7285           nil)
7286       (let ((pt (gnus-data-pos data)))
7287         (goto-char pt)
7288         (gnus-summary-set-article-display-arrow pt))
7289       (gnus-summary-position-point)
7290       article)))
7291
7292 ;; Walking around summary lines with displaying articles.
7293
7294 (defun gnus-summary-expand-window (&optional arg)
7295   "Make the summary buffer take up the entire Emacs frame.
7296 Given a prefix, will force an `article' buffer configuration."
7297   (interactive "P")
7298   (if arg
7299       (gnus-configure-windows 'article 'force)
7300     (gnus-configure-windows 'summary 'force)))
7301
7302 (defun gnus-summary-display-article (article &optional all-header)
7303   "Display ARTICLE in article buffer."
7304   (when (gnus-buffer-live-p gnus-article-buffer)
7305     (with-current-buffer gnus-article-buffer
7306       (mm-enable-multibyte)))
7307   (gnus-set-global-variables)
7308   (when (gnus-buffer-live-p gnus-article-buffer)
7309     (with-current-buffer gnus-article-buffer
7310       (setq gnus-article-charset gnus-newsgroup-charset)
7311       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7312       (mm-enable-multibyte)))
7313   (if (null article)
7314       nil
7315     (prog1
7316         (if gnus-summary-display-article-function
7317             (funcall gnus-summary-display-article-function article all-header)
7318           (gnus-article-prepare article all-header))
7319       (gnus-run-hooks 'gnus-select-article-hook)
7320       (when (and gnus-current-article
7321                  (not (zerop gnus-current-article)))
7322         (gnus-summary-goto-subject gnus-current-article))
7323       (gnus-summary-recenter)
7324       (when (and gnus-use-trees gnus-show-threads)
7325         (gnus-possibly-generate-tree article)
7326         (gnus-highlight-selected-tree article))
7327       ;; Successfully display article.
7328       (gnus-article-set-window-start
7329        (cdr (assq article gnus-newsgroup-bookmarks))))))
7330
7331 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7332   "Select the current article.
7333 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7334 non-nil, the article will be re-fetched even if it already present in
7335 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7336 be displayed."
7337   ;; Make sure we are in the summary buffer to work around bbdb bug.
7338   (unless (eq major-mode 'gnus-summary-mode)
7339     (set-buffer gnus-summary-buffer))
7340   (let ((article (or article (gnus-summary-article-number)))
7341         (all-headers (not (not all-headers))) ;Must be t or nil.
7342         gnus-summary-display-article-function)
7343     (and (not pseudo)
7344          (gnus-summary-article-pseudo-p article)
7345          (error "This is a pseudo-article"))
7346     (save-excursion
7347       (set-buffer gnus-summary-buffer)
7348       (if (or (and gnus-single-article-buffer
7349                    (or (null gnus-current-article)
7350                        (null gnus-article-current)
7351                        (null (get-buffer gnus-article-buffer))
7352                        (not (eq article (cdr gnus-article-current)))
7353                        (not (equal (car gnus-article-current)
7354                                    gnus-newsgroup-name))))
7355               (and (not gnus-single-article-buffer)
7356                    (or (null gnus-current-article)
7357                        (not (eq gnus-current-article article))))
7358               force)
7359           ;; The requested article is different from the current article.
7360           (progn
7361             (gnus-summary-display-article article all-headers)
7362             (when (gnus-buffer-live-p gnus-article-buffer)
7363               (with-current-buffer gnus-article-buffer
7364                 (if (not gnus-article-decoded-p) ;; a local variable
7365                     (mm-disable-multibyte))))
7366             (gnus-article-set-window-start
7367              (cdr (assq article gnus-newsgroup-bookmarks)))
7368             article)
7369         'old))))
7370
7371 (defun gnus-summary-force-verify-and-decrypt ()
7372   "Display buttons for signed/encrypted parts and verify/decrypt them."
7373   (interactive)
7374   (let ((mm-verify-option 'known)
7375         (mm-decrypt-option 'known)
7376         (gnus-article-emulate-mime t)
7377         (gnus-buttonized-mime-types (append (list "multipart/signed"
7378                                                   "multipart/encrypted")
7379                                             gnus-buttonized-mime-types)))
7380     (gnus-summary-select-article nil 'force)))
7381
7382 (defun gnus-summary-set-current-mark (&optional current-mark)
7383   "Obsolete function."
7384   nil)
7385
7386 (defun gnus-summary-next-article (&optional unread subject backward push)
7387   "Select the next article.
7388 If UNREAD, only unread articles are selected.
7389 If SUBJECT, only articles with SUBJECT are selected.
7390 If BACKWARD, the previous article is selected instead of the next."
7391   (interactive "P")
7392   (cond
7393    ;; Is there such an article?
7394    ((and (gnus-summary-search-forward unread subject backward)
7395          (or (gnus-summary-display-article (gnus-summary-article-number))
7396              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7397     (gnus-summary-position-point))
7398    ;; If not, we try the first unread, if that is wanted.
7399    ((and subject
7400          gnus-auto-select-same
7401          (gnus-summary-first-unread-article))
7402     (gnus-summary-position-point)
7403     (gnus-message 6 "Wrapped"))
7404    ;; Try to get next/previous article not displayed in this group.
7405    ((and gnus-auto-extend-newsgroup
7406          (not unread) (not subject))
7407     (gnus-summary-goto-article
7408      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7409      nil (count-lines (point-min) (point))))
7410    ;; Go to next/previous group.
7411    (t
7412     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7413       (gnus-summary-jump-to-group gnus-newsgroup-name))
7414     (let ((cmd last-command-char)
7415           (point
7416            (with-current-buffer gnus-group-buffer
7417              (point)))
7418           (group
7419            (if (eq gnus-keep-same-level 'best)
7420                (gnus-summary-best-group gnus-newsgroup-name)
7421              (gnus-summary-search-group backward gnus-keep-same-level))))
7422       ;; For some reason, the group window gets selected.  We change
7423       ;; it back.
7424       (select-window (get-buffer-window (current-buffer)))
7425       ;; Select next unread newsgroup automagically.
7426       (cond
7427        ((or (not gnus-auto-select-next)
7428             (not cmd))
7429         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7430        ((or (eq gnus-auto-select-next 'quietly)
7431             (and (eq gnus-auto-select-next 'slightly-quietly)
7432                  push)
7433             (and (eq gnus-auto-select-next 'almost-quietly)
7434                  (gnus-summary-last-article-p)))
7435         ;; Select quietly.
7436         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7437             (gnus-summary-exit)
7438           (gnus-message 7 "No more%s articles (%s)..."
7439                         (if unread " unread" "")
7440                         (if group (concat "selecting " group)
7441                           "exiting"))
7442           (gnus-summary-next-group nil group backward)))
7443        (t
7444         (when (gnus-key-press-event-p last-input-event)
7445           (gnus-summary-walk-group-buffer
7446            gnus-newsgroup-name cmd unread backward point))))))))
7447
7448 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7449   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7450                       (?\C-p (gnus-group-prev-unread-group 1))))
7451         (cursor-in-echo-area t)
7452         keve key group ended prompt)
7453     (save-excursion
7454       (set-buffer gnus-group-buffer)
7455       (goto-char start)
7456       (setq group
7457             (if (eq gnus-keep-same-level 'best)
7458                 (gnus-summary-best-group gnus-newsgroup-name)
7459               (gnus-summary-search-group backward gnus-keep-same-level))))
7460     (while (not ended)
7461       (setq prompt
7462             (format
7463              "No more%s articles%s " (if unread " unread" "")
7464              (if (and group
7465                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7466                  (format " (Type %s for %s [%s])"
7467                          (single-key-description cmd)
7468                          (gnus-group-decoded-name group)
7469                          (gnus-group-unread group))
7470                (format " (Type %s to exit %s)"
7471                        (single-key-description cmd)
7472                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7473       ;; Confirm auto selection.
7474       (setq key (car (setq keve (gnus-read-event-char prompt)))
7475             ended t)
7476       (cond
7477        ((assq key keystrokes)
7478         (let ((obuf (current-buffer)))
7479           (switch-to-buffer gnus-group-buffer)
7480           (when group
7481             (gnus-group-jump-to-group group))
7482           (eval (cadr (assq key keystrokes)))
7483           (setq group (gnus-group-group-name))
7484           (switch-to-buffer obuf))
7485         (setq ended nil))
7486        ((equal key cmd)
7487         (if (or (not group)
7488                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7489             (gnus-summary-exit)
7490           (gnus-summary-next-group nil group backward)))
7491        (t
7492         (push (cdr keve) unread-command-events))))))
7493
7494 (defun gnus-summary-next-unread-article ()
7495   "Select unread article after current one."
7496   (interactive)
7497   (gnus-summary-next-article
7498    (or (not (eq gnus-summary-goto-unread 'never))
7499        (gnus-summary-last-article-p (gnus-summary-article-number)))
7500    (and gnus-auto-select-same
7501         (gnus-summary-article-subject))))
7502
7503 (defun gnus-summary-prev-article (&optional unread subject)
7504   "Select the article after the current one.
7505 If UNREAD is non-nil, only unread articles are selected."
7506   (interactive "P")
7507   (gnus-summary-next-article unread subject t))
7508
7509 (defun gnus-summary-prev-unread-article ()
7510   "Select unread article before current one."
7511   (interactive)
7512   (gnus-summary-prev-article
7513    (or (not (eq gnus-summary-goto-unread 'never))
7514        (gnus-summary-first-article-p (gnus-summary-article-number)))
7515    (and gnus-auto-select-same
7516         (gnus-summary-article-subject))))
7517
7518 (defun gnus-summary-next-page (&optional lines circular stop)
7519   "Show next page of the selected article.
7520 If at the end of the current article, select the next article.
7521 LINES says how many lines should be scrolled up.
7522
7523 If CIRCULAR is non-nil, go to the start of the article instead of
7524 selecting the next article when reaching the end of the current
7525 article.
7526
7527 If STOP is non-nil, just stop when reaching the end of the message.
7528
7529 Also see the variable `gnus-article-skip-boring'."
7530   (interactive "P")
7531   (setq gnus-summary-buffer (current-buffer))
7532   (gnus-set-global-variables)
7533   (let ((article (gnus-summary-article-number))
7534         (article-window (get-buffer-window gnus-article-buffer t))
7535         endp)
7536     ;; If the buffer is empty, we have no article.
7537     (unless article
7538       (error "No article to select"))
7539     (gnus-configure-windows 'article)
7540     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7541         (if (and (eq gnus-summary-goto-unread 'never)
7542                  (not (gnus-summary-last-article-p article)))
7543             (gnus-summary-next-article)
7544           (gnus-summary-next-unread-article))
7545       (if (or (null gnus-current-article)
7546               (null gnus-article-current)
7547               (/= article (cdr gnus-article-current))
7548               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7549           ;; Selected subject is different from current article's.
7550           (gnus-summary-display-article article)
7551         (when article-window
7552           (gnus-eval-in-buffer-window gnus-article-buffer
7553             (setq endp (or (gnus-article-next-page lines)
7554                            (gnus-article-only-boring-p))))
7555           (when endp
7556             (cond (stop
7557                    (gnus-message 3 "End of message"))
7558                   (circular
7559                    (gnus-summary-beginning-of-article))
7560                   (lines
7561                    (gnus-message 3 "End of message"))
7562                   ((null lines)
7563                    (if (and (eq gnus-summary-goto-unread 'never)
7564                             (not (gnus-summary-last-article-p article)))
7565                        (gnus-summary-next-article)
7566                      (gnus-summary-next-unread-article))))))))
7567     (gnus-summary-recenter)
7568     (gnus-summary-position-point)))
7569
7570 (defun gnus-summary-prev-page (&optional lines move)
7571   "Show previous page of selected article.
7572 Argument LINES specifies lines to be scrolled down.
7573 If MOVE, move to the previous unread article if point is at
7574 the beginning of the buffer."
7575   (interactive "P")
7576   (let ((article (gnus-summary-article-number))
7577         (article-window (get-buffer-window gnus-article-buffer t))
7578         endp)
7579     (gnus-configure-windows 'article)
7580     (if (or (null gnus-current-article)
7581             (null gnus-article-current)
7582             (/= article (cdr gnus-article-current))
7583             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7584         ;; Selected subject is different from current article's.
7585         (gnus-summary-display-article article)
7586       (gnus-summary-recenter)
7587       (when article-window
7588         (gnus-eval-in-buffer-window gnus-article-buffer
7589           (setq endp (gnus-article-prev-page lines)))
7590         (when (and move endp)
7591           (cond (lines
7592                  (gnus-message 3 "Beginning of message"))
7593                 ((null lines)
7594                  (if (and (eq gnus-summary-goto-unread 'never)
7595                           (not (gnus-summary-first-article-p article)))
7596                      (gnus-summary-prev-article)
7597                    (gnus-summary-prev-unread-article))))))))
7598   (gnus-summary-position-point))
7599
7600 (defun gnus-summary-prev-page-or-article (&optional lines)
7601   "Show previous page of selected article.
7602 Argument LINES specifies lines to be scrolled down.
7603 If at the beginning of the article, go to the next article."
7604   (interactive "P")
7605   (gnus-summary-prev-page lines t))
7606
7607 (defun gnus-summary-scroll-up (lines)
7608   "Scroll up (or down) one line current article.
7609 Argument LINES specifies lines to be scrolled up (or down if negative)."
7610   (interactive "p")
7611   (gnus-configure-windows 'article)
7612   (gnus-summary-show-thread)
7613   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7614     (gnus-eval-in-buffer-window gnus-article-buffer
7615       (cond ((> lines 0)
7616              (when (gnus-article-next-page lines)
7617                (gnus-message 3 "End of message")))
7618             ((< lines 0)
7619              (gnus-article-prev-page (- lines))))))
7620   (gnus-summary-recenter)
7621   (gnus-summary-position-point))
7622
7623 (defun gnus-summary-scroll-down (lines)
7624   "Scroll down (or up) one line current article.
7625 Argument LINES specifies lines to be scrolled down (or up if negative)."
7626   (interactive "p")
7627   (gnus-summary-scroll-up (- lines)))
7628
7629 (defun gnus-summary-next-same-subject ()
7630   "Select next article which has the same subject as current one."
7631   (interactive)
7632   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7633
7634 (defun gnus-summary-prev-same-subject ()
7635   "Select previous article which has the same subject as current one."
7636   (interactive)
7637   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7638
7639 (defun gnus-summary-next-unread-same-subject ()
7640   "Select next unread article which has the same subject as current one."
7641   (interactive)
7642   (gnus-summary-next-article t (gnus-summary-article-subject)))
7643
7644 (defun gnus-summary-prev-unread-same-subject ()
7645   "Select previous unread article which has the same subject as current one."
7646   (interactive)
7647   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7648
7649 (defun gnus-summary-first-unread-article ()
7650   "Select the first unread article.
7651 Return nil if there are no unread articles."
7652   (interactive)
7653   (prog1
7654       (when (gnus-summary-first-subject t)
7655         (gnus-summary-show-thread)
7656         (gnus-summary-first-subject t)
7657         (gnus-summary-display-article (gnus-summary-article-number)))
7658     (gnus-summary-position-point)))
7659
7660 (defun gnus-summary-first-unread-subject ()
7661   "Place the point on the subject line of the first unread article.
7662 Return nil if there are no unread articles."
7663   (interactive)
7664   (prog1
7665       (when (gnus-summary-first-subject t)
7666         (gnus-summary-show-thread)
7667         (gnus-summary-first-subject t))
7668     (gnus-summary-position-point)))
7669
7670 (defun gnus-summary-first-unseen-subject ()
7671   "Place the point on the subject line of the first unseen article.
7672 Return nil if there are no unseen articles."
7673   (interactive)
7674   (prog1
7675       (when (gnus-summary-first-subject nil nil t)
7676         (gnus-summary-show-thread)
7677         (gnus-summary-first-subject nil nil t))
7678     (gnus-summary-position-point)))
7679
7680 (defun gnus-summary-first-unseen-or-unread-subject ()
7681   "Place the point on the subject line of the first unseen article or,
7682 if all article have been seen, on the subject line of the first unread
7683 article."
7684   (interactive)
7685   (prog1
7686       (unless (when (gnus-summary-first-subject nil nil t)
7687                 (gnus-summary-show-thread)
7688                 (gnus-summary-first-subject nil nil t))
7689         (when (gnus-summary-first-subject t)
7690           (gnus-summary-show-thread)
7691           (gnus-summary-first-subject t)))
7692     (gnus-summary-position-point)))
7693
7694 (defun gnus-summary-first-article ()
7695   "Select the first article.
7696 Return nil if there are no articles."
7697   (interactive)
7698   (prog1
7699       (when (gnus-summary-first-subject)
7700         (gnus-summary-show-thread)
7701         (gnus-summary-first-subject)
7702         (gnus-summary-display-article (gnus-summary-article-number)))
7703     (gnus-summary-position-point)))
7704
7705 (defun gnus-summary-best-unread-article (&optional arg)
7706   "Select the unread article with the highest score.
7707 If given a prefix argument, select the next unread article that has a
7708 score higher than the default score."
7709   (interactive "P")
7710   (let ((article (if arg
7711                      (gnus-summary-better-unread-subject)
7712                    (gnus-summary-best-unread-subject))))
7713     (if article
7714         (gnus-summary-goto-article article)
7715       (error "No unread articles"))))
7716
7717 (defun gnus-summary-best-unread-subject ()
7718   "Select the unread subject with the highest score."
7719   (interactive)
7720   (let ((best -1000000)
7721         (data gnus-newsgroup-data)
7722         article score)
7723     (while data
7724       (and (gnus-data-unread-p (car data))
7725            (> (setq score
7726                     (gnus-summary-article-score (gnus-data-number (car data))))
7727               best)
7728            (setq best score
7729                  article (gnus-data-number (car data))))
7730       (setq data (cdr data)))
7731     (when article
7732       (gnus-summary-goto-subject article))
7733     (gnus-summary-position-point)
7734     article))
7735
7736 (defun gnus-summary-better-unread-subject ()
7737   "Select the first unread subject that has a score over the default score."
7738   (interactive)
7739   (let ((data gnus-newsgroup-data)
7740         article score)
7741     (while (and (setq article (gnus-data-number (car data)))
7742                 (or (gnus-data-read-p (car data))
7743                     (not (> (gnus-summary-article-score article)
7744                             gnus-summary-default-score))))
7745       (setq data (cdr data)))
7746     (when article
7747       (gnus-summary-goto-subject article))
7748     (gnus-summary-position-point)
7749     article))
7750
7751 (defun gnus-summary-last-subject ()
7752   "Go to the last displayed subject line in the group."
7753   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7754     (when article
7755       (gnus-summary-goto-subject article))))
7756
7757 (defun gnus-summary-goto-article (article &optional all-headers force)
7758   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7759 If ALL-HEADERS is non-nil, no header lines are hidden.
7760 If FORCE, go to the article even if it isn't displayed.  If FORCE
7761 is a number, it is the line the article is to be displayed on."
7762   (interactive
7763    (list
7764     (completing-read
7765      "Article number or Message-ID: "
7766      (mapcar (lambda (number) (list (int-to-string number)))
7767              gnus-newsgroup-limit))
7768     current-prefix-arg
7769     t))
7770   (prog1
7771       (if (and (stringp article)
7772                (string-match "@\\|%40" article))
7773           (gnus-summary-refer-article article)
7774         (when (stringp article)
7775           (setq article (string-to-number article)))
7776         (if (gnus-summary-goto-subject article force)
7777             (gnus-summary-display-article article all-headers)
7778           (gnus-message 4 "Couldn't go to article %s" article) nil))
7779     (gnus-summary-position-point)))
7780
7781 (defun gnus-summary-goto-last-article ()
7782   "Go to the previously read article."
7783   (interactive)
7784   (prog1
7785       (when gnus-last-article
7786         (gnus-summary-goto-article gnus-last-article nil t))
7787     (gnus-summary-position-point)))
7788
7789 (defun gnus-summary-pop-article (number)
7790   "Pop one article off the history and go to the previous.
7791 NUMBER articles will be popped off."
7792   (interactive "p")
7793   (let (to)
7794     (setq gnus-newsgroup-history
7795           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7796     (if to
7797         (gnus-summary-goto-article (car to) nil t)
7798       (error "Article history empty")))
7799   (gnus-summary-position-point))
7800
7801 ;; Summary commands and functions for limiting the summary buffer.
7802
7803 (defun gnus-summary-limit-to-articles (n)
7804   "Limit the summary buffer to the next N articles.
7805 If not given a prefix, use the process marked articles instead."
7806   (interactive "P")
7807   (prog1
7808       (let ((articles (gnus-summary-work-articles n)))
7809         (setq gnus-newsgroup-processable nil)
7810         (gnus-summary-limit articles))
7811     (gnus-summary-position-point)))
7812
7813 (defun gnus-summary-pop-limit (&optional total)
7814   "Restore the previous limit.
7815 If given a prefix, remove all limits."
7816   (interactive "P")
7817   (when total
7818     (setq gnus-newsgroup-limits
7819           (list (mapcar (lambda (h) (mail-header-number h))
7820                         gnus-newsgroup-headers))))
7821   (unless gnus-newsgroup-limits
7822     (error "No limit to pop"))
7823   (prog1
7824       (gnus-summary-limit nil 'pop)
7825     (gnus-summary-position-point)))
7826
7827 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7828   "Limit the summary buffer to articles that have subjects that match a regexp.
7829 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7830   (interactive
7831    (list (read-string (if current-prefix-arg
7832                           "Exclude subject (regexp): "
7833                         "Limit to subject (regexp): "))
7834          nil current-prefix-arg))
7835   (unless header
7836     (setq header "subject"))
7837   (when (not (equal "" subject))
7838     (prog1
7839         (let ((articles (gnus-summary-find-matching
7840                          (or header "subject") subject 'all nil nil
7841                          not-matching)))
7842           (unless articles
7843             (error "Found no matches for \"%s\"" subject))
7844           (gnus-summary-limit articles))
7845       (gnus-summary-position-point))))
7846
7847 (defun gnus-summary-limit-to-author (from &optional not-matching)
7848   "Limit the summary buffer to articles that have authors that match a regexp.
7849 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7850   (interactive
7851    (list (read-string (if current-prefix-arg
7852                           "Exclude author (regexp): "
7853                         "Limit to author (regexp): "))
7854          current-prefix-arg))
7855   (gnus-summary-limit-to-subject from "from" not-matching))
7856
7857 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7858   "Limit the summary buffer to articles with the given RECIPIENT.
7859
7860 If NOT-MATCHING, exclude RECIPIENT.
7861
7862 To and Cc headers are checked.  You need to include them in
7863 `nnmail-extra-headers'."
7864   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7865   (interactive
7866    (list (read-string (format "%s recipient (regexp): "
7867                               (if current-prefix-arg "Exclude" "Limit to")))
7868          current-prefix-arg))
7869   (when (not (equal "" recipient))
7870     (prog1 (let* ((to
7871                    (if (memq 'To nnmail-extra-headers)
7872                        (gnus-summary-find-matching
7873                         (cons 'extra 'To) recipient 'all nil nil
7874                         not-matching)
7875                      (gnus-message
7876                       1 "`To' isn't present in `nnmail-extra-headers'")
7877                      (sit-for 1)
7878                      nil))
7879                   (cc
7880                    (if (memq 'Cc nnmail-extra-headers)
7881                        (gnus-summary-find-matching
7882                         (cons 'extra 'Cc) recipient 'all nil nil
7883                         not-matching)
7884                      (gnus-message
7885                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7886                      (sit-for 1)
7887                      nil))
7888                   (articles
7889                    (if not-matching
7890                        ;; We need the numbers that are in both lists:
7891                        (mapcar (lambda (a)
7892                                  (and (memq a to) a))
7893                                cc)
7894                      (nconc to cc))))
7895              (unless articles
7896                (error "Found no matches for \"%s\"" recipient))
7897              (gnus-summary-limit articles))
7898       (gnus-summary-position-point))))
7899
7900 (defun gnus-summary-limit-to-age (age &optional younger-p)
7901   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7902 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7903 articles that are younger than AGE days."
7904   (interactive
7905    (let ((younger current-prefix-arg)
7906          (days-got nil)
7907          days)
7908      (while (not days-got)
7909        (setq days (if younger
7910                       (read-string "Limit to articles younger than (in days, older when negative): ")
7911                     (read-string
7912                      "Limit to articles older than (in days, younger when negative): ")))
7913        (when (> (length days) 0)
7914          (setq days (read days)))
7915        (if (numberp days)
7916            (progn
7917              (setq days-got t)
7918              (when (< days 0)
7919                (setq younger (not younger))
7920                (setq days (* days -1))))
7921          (message "Please enter a number.")
7922          (sleep-for 1)))
7923      (list days younger)))
7924   (prog1
7925       (let ((data gnus-newsgroup-data)
7926             (cutoff (days-to-time age))
7927             articles d date is-younger)
7928         (while (setq d (pop data))
7929           (when (and (vectorp (gnus-data-header d))
7930                      (setq date (mail-header-date (gnus-data-header d))))
7931             (setq is-younger (time-less-p
7932                               (time-since (condition-case ()
7933                                               (date-to-time date)
7934                                             (error '(0 0))))
7935                               cutoff))
7936             (when (if younger-p
7937                       is-younger
7938                     (not is-younger))
7939               (push (gnus-data-number d) articles))))
7940         (gnus-summary-limit (nreverse articles)))
7941     (gnus-summary-position-point)))
7942
7943 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7944   "Limit the summary buffer to articles that match an 'extra' header."
7945   (interactive
7946    (let ((header
7947           (intern
7948            (gnus-completing-read-with-default
7949             (symbol-name (car gnus-extra-headers))
7950             (if current-prefix-arg
7951                 "Exclude extra header"
7952               "Limit extra header")
7953             (mapcar (lambda (x)
7954                       (cons (symbol-name x) x))
7955                     gnus-extra-headers)
7956             nil
7957             t))))
7958      (list header
7959            (read-string (format "%s header %s (regexp): "
7960                                 (if current-prefix-arg "Exclude" "Limit to")
7961                                 header))
7962            current-prefix-arg)))
7963   (when (not (equal "" regexp))
7964     (prog1
7965         (let ((articles (gnus-summary-find-matching
7966                          (cons 'extra header) regexp 'all nil nil
7967                          not-matching)))
7968           (unless articles
7969             (error "Found no matches for \"%s\"" regexp))
7970           (gnus-summary-limit articles))
7971       (gnus-summary-position-point))))
7972
7973 (defun gnus-summary-limit-to-display-predicate ()
7974   "Limit the summary buffer to the predicated in the `display' group parameter."
7975   (interactive)
7976   (unless gnus-newsgroup-display
7977     (error "There is no `display' group parameter"))
7978   (let (articles)
7979     (dolist (number gnus-newsgroup-articles)
7980       (when (funcall gnus-newsgroup-display)
7981         (push number articles)))
7982     (gnus-summary-limit articles))
7983   (gnus-summary-position-point))
7984
7985 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7986 (make-obsolete
7987  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7988
7989 (defun gnus-summary-limit-to-unread (&optional all)
7990   "Limit the summary buffer to articles that are not marked as read.
7991 If ALL is non-nil, limit strictly to unread articles."
7992   (interactive "P")
7993   (if all
7994       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7995     (gnus-summary-limit-to-marks
7996      ;; Concat all the marks that say that an article is read and have
7997      ;; those removed.
7998      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7999            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8000            gnus-low-score-mark gnus-expirable-mark
8001            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8002            gnus-duplicate-mark gnus-souped-mark)
8003      'reverse)))
8004
8005 (defun gnus-summary-limit-to-bodies (match &optional reverse)
8006   "Limit the summary buffer to articles that have bodies that match MATCH.
8007 If REVERSE (the prefix), limit to articles that don't match."
8008   (interactive "sMatch body (regexp): \nP")
8009   (let ((articles nil)
8010         (gnus-select-article-hook nil)  ;Disable hook.
8011         (gnus-article-prepare-hook nil)
8012         (gnus-use-article-prefetch nil)
8013         (gnus-keep-backlog nil)
8014         (gnus-break-pages nil)
8015         (gnus-summary-display-arrow nil)
8016         (gnus-updated-mode-lines nil)
8017         (gnus-auto-center-summary nil)
8018         (gnus-display-mime-function nil))
8019     (dolist (data gnus-newsgroup-data)
8020       (let (gnus-mark-article-hook)
8021         (gnus-summary-select-article t t nil (gnus-data-number data)))
8022       (save-excursion
8023         (set-buffer gnus-article-buffer)
8024         (article-goto-body)
8025         (let* ((case-fold-search t)
8026                (found (re-search-forward match nil t)))
8027           (when (or (and found
8028                          (not reverse))
8029                     (and (not found)
8030                          reverse))
8031             (push (gnus-data-number data) articles)))))
8032     (if (not articles)
8033         (message "No messages matched")
8034       (gnus-summary-limit articles)))
8035   (gnus-summary-position-point))
8036
8037 (defun gnus-summary-limit-to-replied (&optional unreplied)
8038   "Limit the summary buffer to replied articles.
8039 If UNREPLIED (the prefix), limit to unreplied articles."
8040   (interactive "P")
8041   (if unreplied
8042       (gnus-summary-limit
8043        (gnus-set-difference gnus-newsgroup-articles
8044         gnus-newsgroup-replied))
8045     (gnus-summary-limit gnus-newsgroup-replied))
8046   (gnus-summary-position-point))
8047
8048 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8049 (make-obsolete 'gnus-summary-delete-marked-with
8050                'gnus-summary-limit-exclude-marks)
8051
8052 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8053   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8054 If REVERSE, limit the summary buffer to articles that are marked
8055 with MARKS.  MARKS can either be a string of marks or a list of marks.
8056 Returns how many articles were removed."
8057   (interactive "sMarks: ")
8058   (gnus-summary-limit-to-marks marks t))
8059
8060 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8061   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8062 If REVERSE (the prefix), limit the summary buffer to articles that are
8063 not marked with MARKS.  MARKS can either be a string of marks or a
8064 list of marks.
8065 Returns how many articles were removed."
8066   (interactive "sMarks: \nP")
8067   (prog1
8068       (let ((data gnus-newsgroup-data)
8069             (marks (if (listp marks) marks
8070                      (append marks nil))) ; Transform to list.
8071             articles)
8072         (while data
8073           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8074                   (memq (gnus-data-mark (car data)) marks))
8075             (push (gnus-data-number (car data)) articles))
8076           (setq data (cdr data)))
8077         (gnus-summary-limit articles))
8078     (gnus-summary-position-point)))
8079
8080 (defun gnus-summary-limit-to-score (score)
8081   "Limit to articles with score at or above SCORE."
8082   (interactive "NLimit to articles with score of at least: ")
8083   (let ((data gnus-newsgroup-data)
8084         articles)
8085     (while data
8086       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8087                 score)
8088         (push (gnus-data-number (car data)) articles))
8089       (setq data (cdr data)))
8090     (prog1
8091         (gnus-summary-limit articles)
8092       (gnus-summary-position-point))))
8093
8094 (defun gnus-summary-limit-to-unseen ()
8095   "Limit to unseen articles."
8096   (interactive)
8097   (prog1
8098       (gnus-summary-limit gnus-newsgroup-unseen)
8099     (gnus-summary-position-point)))
8100
8101 (defun gnus-summary-limit-include-thread (id)
8102   "Display all the hidden articles that is in the thread with ID in it.
8103 When called interactively, ID is the Message-ID of the current
8104 article."
8105   (interactive (list (mail-header-id (gnus-summary-article-header))))
8106   (let ((articles (gnus-articles-in-thread
8107                    (gnus-id-to-thread (gnus-root-id id)))))
8108     (prog1
8109         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8110       (gnus-summary-limit-include-matching-articles
8111        "subject"
8112        (regexp-quote (gnus-simplify-subject-re
8113                       (mail-header-subject (gnus-id-to-header id)))))
8114       (gnus-summary-position-point))))
8115
8116 (defun gnus-summary-limit-include-matching-articles (header regexp)
8117   "Display all the hidden articles that have HEADERs that match REGEXP."
8118   (interactive (list (read-string "Match on header: ")
8119                      (read-string "Regexp: ")))
8120   (let ((articles (gnus-find-matching-articles header regexp)))
8121     (prog1
8122         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8123       (gnus-summary-position-point))))
8124
8125 (defun gnus-summary-insert-dormant-articles ()
8126   "Insert all the dormant articles for this group into the current buffer."
8127   (interactive)
8128   (let ((gnus-verbose (max 6 gnus-verbose)))
8129     (if (not gnus-newsgroup-dormant)
8130         (gnus-message 3 "No cached articles for this group")
8131       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8132
8133 (defun gnus-summary-limit-include-dormant ()
8134   "Display all the hidden articles that are marked as dormant.
8135 Note that this command only works on a subset of the articles currently
8136 fetched for this group."
8137   (interactive)
8138   (unless gnus-newsgroup-dormant
8139     (error "There are no dormant articles in this group"))
8140   (prog1
8141       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8142     (gnus-summary-position-point)))
8143
8144 (defun gnus-summary-limit-exclude-dormant ()
8145   "Hide all dormant articles."
8146   (interactive)
8147   (prog1
8148       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8149     (gnus-summary-position-point)))
8150
8151 (defun gnus-summary-limit-exclude-childless-dormant ()
8152   "Hide all dormant articles that have no children."
8153   (interactive)
8154   (let ((data (gnus-data-list t))
8155         articles d children)
8156     ;; Find all articles that are either not dormant or have
8157     ;; children.
8158     (while (setq d (pop data))
8159       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8160                 (and (setq children
8161                            (gnus-article-children (gnus-data-number d)))
8162                      (let (found)
8163                        (while children
8164                          (when (memq (car children) articles)
8165                            (setq children nil
8166                                  found t))
8167                          (pop children))
8168                        found)))
8169         (push (gnus-data-number d) articles)))
8170     ;; Do the limiting.
8171     (prog1
8172         (gnus-summary-limit articles)
8173       (gnus-summary-position-point))))
8174
8175 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8176   "Mark all unread excluded articles as read.
8177 If ALL, mark even excluded ticked and dormants as read."
8178   (interactive "P")
8179   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8180   (let ((articles (gnus-sorted-ndifference
8181                    (sort
8182                     (mapcar (lambda (h) (mail-header-number h))
8183                             gnus-newsgroup-headers)
8184                     '<)
8185                    gnus-newsgroup-limit))
8186         article)
8187     (setq gnus-newsgroup-unreads
8188           (gnus-sorted-intersection gnus-newsgroup-unreads
8189                                     gnus-newsgroup-limit))
8190     (if all
8191         (setq gnus-newsgroup-dormant nil
8192               gnus-newsgroup-marked nil
8193               gnus-newsgroup-reads
8194               (nconc
8195                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8196                gnus-newsgroup-reads))
8197       (while (setq article (pop articles))
8198         (unless (or (memq article gnus-newsgroup-dormant)
8199                     (memq article gnus-newsgroup-marked))
8200           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8201
8202 (defun gnus-summary-limit (articles &optional pop)
8203   (if pop
8204       ;; We pop the previous limit off the stack and use that.
8205       (setq articles (car gnus-newsgroup-limits)
8206             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8207     ;; We use the new limit, so we push the old limit on the stack.
8208     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8209   ;; Set the limit.
8210   (setq gnus-newsgroup-limit articles)
8211   (let ((total (length gnus-newsgroup-data))
8212         (data (gnus-data-find-list (gnus-summary-article-number)))
8213         (gnus-summary-mark-below nil)   ; Inhibit this.
8214         found)
8215     ;; This will do all the work of generating the new summary buffer
8216     ;; according to the new limit.
8217     (gnus-summary-prepare)
8218     ;; Hide any threads, possibly.
8219     (gnus-summary-maybe-hide-threads)
8220     ;; Try to return to the article you were at, or one in the
8221     ;; neighborhood.
8222     (when data
8223       ;; We try to find some article after the current one.
8224       (while data
8225         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8226           (setq data nil
8227                 found t))
8228         (setq data (cdr data))))
8229     (unless found
8230       ;; If there is no data, that means that we were after the last
8231       ;; article.  The same goes when we can't find any articles
8232       ;; after the current one.
8233       (goto-char (point-max))
8234       (gnus-summary-find-prev))
8235     (gnus-set-mode-line 'summary)
8236     ;; We return how many articles were removed from the summary
8237     ;; buffer as a result of the new limit.
8238     (- total (length gnus-newsgroup-data))))
8239
8240 (defsubst gnus-invisible-cut-children (threads)
8241   (let ((num 0))
8242     (while threads
8243       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8244         (incf num))
8245       (pop threads))
8246     (< num 2)))
8247
8248 (defsubst gnus-cut-thread (thread)
8249   "Go forwards in the thread until we find an article that we want to display."
8250   (when (or (eq gnus-fetch-old-headers 'some)
8251             (eq gnus-fetch-old-headers 'invisible)
8252             (numberp gnus-fetch-old-headers)
8253             (eq gnus-build-sparse-threads 'some)
8254             (eq gnus-build-sparse-threads 'more))
8255     ;; Deal with old-fetched headers and sparse threads.
8256     (while (and
8257             thread
8258             (or
8259              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8260              (gnus-summary-article-ancient-p
8261               (mail-header-number (car thread))))
8262             (if (or (<= (length (cdr thread)) 1)
8263                     (eq gnus-fetch-old-headers 'invisible))
8264                 (setq gnus-newsgroup-limit
8265                       (delq (mail-header-number (car thread))
8266                             gnus-newsgroup-limit)
8267                       thread (cadr thread))
8268               (when (gnus-invisible-cut-children (cdr thread))
8269                 (let ((th (cdr thread)))
8270                   (while th
8271                     (if (memq (mail-header-number (caar th))
8272                               gnus-newsgroup-limit)
8273                         (setq thread (car th)
8274                               th nil)
8275                       (setq th (cdr th))))))))))
8276   thread)
8277
8278 (defun gnus-cut-threads (threads)
8279   "Cut off all uninteresting articles from the beginning of THREADS."
8280   (when (or (eq gnus-fetch-old-headers 'some)
8281             (eq gnus-fetch-old-headers 'invisible)
8282             (numberp gnus-fetch-old-headers)
8283             (eq gnus-build-sparse-threads 'some)
8284             (eq gnus-build-sparse-threads 'more))
8285     (let ((th threads))
8286       (while th
8287         (setcar th (gnus-cut-thread (car th)))
8288         (setq th (cdr th)))))
8289   ;; Remove nixed out threads.
8290   (delq nil threads))
8291
8292 (defun gnus-summary-initial-limit (&optional show-if-empty)
8293   "Figure out what the initial limit is supposed to be on group entry.
8294 This entails weeding out unwanted dormants, low-scored articles,
8295 fetch-old-headers verbiage, and so on."
8296   ;; Most groups have nothing to remove.
8297   (if (or gnus-inhibit-limiting
8298           (and (null gnus-newsgroup-dormant)
8299                (eq gnus-newsgroup-display 'gnus-not-ignore)
8300                (not (eq gnus-fetch-old-headers 'some))
8301                (not (numberp gnus-fetch-old-headers))
8302                (not (eq gnus-fetch-old-headers 'invisible))
8303                (null gnus-summary-expunge-below)
8304                (not (eq gnus-build-sparse-threads 'some))
8305                (not (eq gnus-build-sparse-threads 'more))
8306                (null gnus-thread-expunge-below)
8307                (not gnus-use-nocem)))
8308       ()                                ; Do nothing.
8309     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8310     (setq gnus-newsgroup-limit nil)
8311     (mapatoms
8312      (lambda (node)
8313        (unless (car (symbol-value node))
8314          ;; These threads have no parents -- they are roots.
8315          (let ((nodes (cdr (symbol-value node)))
8316                thread)
8317            (while nodes
8318              (if (and gnus-thread-expunge-below
8319                       (< (gnus-thread-total-score (car nodes))
8320                          gnus-thread-expunge-below))
8321                  (gnus-expunge-thread (pop nodes))
8322                (setq thread (pop nodes))
8323                (gnus-summary-limit-children thread))))))
8324      gnus-newsgroup-dependencies)
8325     ;; If this limitation resulted in an empty group, we might
8326     ;; pop the previous limit and use it instead.
8327     (when (and (not gnus-newsgroup-limit)
8328                show-if-empty)
8329       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8330     gnus-newsgroup-limit))
8331
8332 (defun gnus-summary-limit-children (thread)
8333   "Return 1 if this subthread is visible and 0 if it is not."
8334   ;; First we get the number of visible children to this thread.  This
8335   ;; is done by recursing down the thread using this function, so this
8336   ;; will really go down to a leaf article first, before slowly
8337   ;; working its way up towards the root.
8338   (when thread
8339     (let* ((max-lisp-eval-depth 5000)
8340            (children
8341            (if (cdr thread)
8342                (apply '+ (mapcar 'gnus-summary-limit-children
8343                                  (cdr thread)))
8344              0))
8345           (number (mail-header-number (car thread)))
8346           score)
8347       (if (and
8348            (not (memq number gnus-newsgroup-marked))
8349            (or
8350             ;; If this article is dormant and has absolutely no visible
8351             ;; children, then this article isn't visible.
8352             (and (memq number gnus-newsgroup-dormant)
8353                  (zerop children))
8354             ;; If this is "fetch-old-headered" and there is no
8355             ;; visible children, then we don't want this article.
8356             (and (or (eq gnus-fetch-old-headers 'some)
8357                      (numberp gnus-fetch-old-headers))
8358                  (gnus-summary-article-ancient-p number)
8359                  (zerop children))
8360             ;; If this is "fetch-old-headered" and `invisible', then
8361             ;; we don't want this article.
8362             (and (eq gnus-fetch-old-headers 'invisible)
8363                  (gnus-summary-article-ancient-p number))
8364             ;; If this is a sparsely inserted article with no children,
8365             ;; we don't want it.
8366             (and (eq gnus-build-sparse-threads 'some)
8367                  (gnus-summary-article-sparse-p number)
8368                  (zerop children))
8369             ;; If we use expunging, and this article is really
8370             ;; low-scored, then we don't want this article.
8371             (when (and gnus-summary-expunge-below
8372                        (< (setq score
8373                                 (or (cdr (assq number gnus-newsgroup-scored))
8374                                     gnus-summary-default-score))
8375                           gnus-summary-expunge-below))
8376               ;; We increase the expunge-tally here, but that has
8377               ;; nothing to do with the limits, really.
8378               (incf gnus-newsgroup-expunged-tally)
8379               ;; We also mark as read here, if that's wanted.
8380               (when (and gnus-summary-mark-below
8381                          (< score gnus-summary-mark-below))
8382                 (setq gnus-newsgroup-unreads
8383                       (delq number gnus-newsgroup-unreads))
8384                 (if gnus-newsgroup-auto-expire
8385                     (push number gnus-newsgroup-expirable)
8386                   (push (cons number gnus-low-score-mark)
8387                         gnus-newsgroup-reads)))
8388               t)
8389             ;; Do the `display' group parameter.
8390             (and gnus-newsgroup-display
8391                  (not (funcall gnus-newsgroup-display)))
8392             ;; Check NoCeM things.
8393             (when (and gnus-use-nocem
8394                        (gnus-nocem-unwanted-article-p
8395                         (mail-header-id (car thread))))
8396               (setq gnus-newsgroup-unreads
8397                     (delq number gnus-newsgroup-unreads))
8398               t)))
8399           ;; Nope, invisible article.
8400           0
8401         ;; Ok, this article is to be visible, so we add it to the limit
8402         ;; and return 1.
8403         (push number gnus-newsgroup-limit)
8404         1))))
8405
8406 (defun gnus-expunge-thread (thread)
8407   "Mark all articles in THREAD as read."
8408   (let* ((number (mail-header-number (car thread))))
8409     (incf gnus-newsgroup-expunged-tally)
8410     ;; We also mark as read here, if that's wanted.
8411     (setq gnus-newsgroup-unreads
8412           (delq number gnus-newsgroup-unreads))
8413     (if gnus-newsgroup-auto-expire
8414         (push number gnus-newsgroup-expirable)
8415       (push (cons number gnus-low-score-mark)
8416             gnus-newsgroup-reads)))
8417   ;; Go recursively through all subthreads.
8418   (mapcar 'gnus-expunge-thread (cdr thread)))
8419
8420 ;; Summary article oriented commands
8421
8422 (defun gnus-summary-refer-parent-article (n)
8423   "Refer parent article N times.
8424 If N is negative, go to ancestor -N instead.
8425 The difference between N and the number of articles fetched is returned."
8426   (interactive "p")
8427   (let ((skip 1)
8428         error header ref)
8429     (when (not (natnump n))
8430       (setq skip (abs n)
8431             n 1))
8432     (while (and (> n 0)
8433                 (not error))
8434       (setq header (gnus-summary-article-header))
8435       (if (and (eq (mail-header-number header)
8436                    (cdr gnus-article-current))
8437                (equal gnus-newsgroup-name
8438                       (car gnus-article-current)))
8439           ;; If we try to find the parent of the currently
8440           ;; displayed article, then we take a look at the actual
8441           ;; References header, since this is slightly more
8442           ;; reliable than the References field we got from the
8443           ;; server.
8444           (save-excursion
8445             (set-buffer gnus-original-article-buffer)
8446             (nnheader-narrow-to-headers)
8447             (unless (setq ref (message-fetch-field "references"))
8448               (when (setq ref (message-fetch-field "in-reply-to"))
8449                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8450             (widen))
8451         (setq ref
8452               ;; It's not the current article, so we take a bet on
8453               ;; the value we got from the server.
8454               (mail-header-references header)))
8455       (if (and ref
8456                (not (equal ref "")))
8457           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8458             (gnus-message 1 "Couldn't find parent"))
8459         (gnus-message 1 "No references in article %d"
8460                       (gnus-summary-article-number))
8461         (setq error t))
8462       (decf n))
8463     (gnus-summary-position-point)
8464     n))
8465
8466 (defun gnus-summary-refer-references ()
8467   "Fetch all articles mentioned in the References header.
8468 Return the number of articles fetched."
8469   (interactive)
8470   (let ((ref (mail-header-references (gnus-summary-article-header)))
8471         (current (gnus-summary-article-number))
8472         (n 0))
8473     (if (or (not ref)
8474             (equal ref ""))
8475         (error "No References in the current article")
8476       ;; For each Message-ID in the References header...
8477       (while (string-match "<[^>]*>" ref)
8478         (incf n)
8479         ;; ... fetch that article.
8480         (gnus-summary-refer-article
8481          (prog1 (match-string 0 ref)
8482            (setq ref (substring ref (match-end 0))))))
8483       (gnus-summary-goto-subject current)
8484       (gnus-summary-position-point)
8485       n)))
8486
8487 (defun gnus-summary-refer-thread (&optional limit)
8488   "Fetch all articles in the current thread.
8489 If LIMIT (the numerical prefix), fetch that many old headers instead
8490 of what's specified by the `gnus-refer-thread-limit' variable."
8491   (interactive "P")
8492   (let ((id (mail-header-id (gnus-summary-article-header)))
8493         (limit (if limit (prefix-numeric-value limit)
8494                  gnus-refer-thread-limit)))
8495     (unless (eq gnus-fetch-old-headers 'invisible)
8496       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8497       ;; Retrieve the headers and read them in.
8498       (if (eq (if (numberp limit)
8499                   (gnus-retrieve-headers
8500                    (list (min
8501                           (+ (mail-header-number
8502                               (gnus-summary-article-header))
8503                              limit)
8504                           gnus-newsgroup-end))
8505                    gnus-newsgroup-name (* limit 2))
8506                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8507                 ;; headers.
8508                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8509                                        gnus-newsgroup-name limit))
8510               'nov)
8511           (gnus-build-all-threads)
8512         (error "Can't fetch thread from back ends that don't support NOV"))
8513       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8514     (gnus-summary-limit-include-thread id)))
8515
8516 (defun gnus-summary-refer-article (message-id)
8517   "Fetch an article specified by MESSAGE-ID."
8518   (interactive "sMessage-ID: ")
8519   (when (and (stringp message-id)
8520              (not (zerop (length message-id))))
8521     (setq message-id (gnus-replace-in-string message-id " " ""))
8522     ;; Construct the correct Message-ID if necessary.
8523     ;; Suggested by tale@pawl.rpi.edu.
8524     (unless (string-match "^<" message-id)
8525       (setq message-id (concat "<" message-id)))
8526     (unless (string-match ">$" message-id)
8527       (setq message-id (concat message-id ">")))
8528     ;; People often post MIDs from URLs, so unhex it:
8529     (unless (string-match "@" message-id)
8530       (setq message-id (gnus-url-unhex-string message-id)))
8531     (let* ((header (gnus-id-to-header message-id))
8532            (sparse (and header
8533                         (gnus-summary-article-sparse-p
8534                          (mail-header-number header))
8535                         (memq (mail-header-number header)
8536                               gnus-newsgroup-limit)))
8537            number)
8538       (cond
8539        ;; If the article is present in the buffer we just go to it.
8540        ((and header
8541              (or (not (gnus-summary-article-sparse-p
8542                        (mail-header-number header)))
8543                  sparse))
8544         (prog1
8545             (gnus-summary-goto-article
8546              (mail-header-number header) nil t)
8547           (when sparse
8548             (gnus-summary-update-article (mail-header-number header)))))
8549        (t
8550         ;; We fetch the article.
8551         (catch 'found
8552           (dolist (gnus-override-method (gnus-refer-article-methods))
8553             (when (and (gnus-check-server gnus-override-method)
8554                        ;; Fetch the header,
8555                        (setq number (gnus-summary-insert-subject message-id)))
8556               ;; and display the article.
8557               (gnus-summary-select-article nil nil nil number)
8558               (throw 'found t)))
8559           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8560
8561 (defun gnus-refer-article-methods ()
8562   "Return a list of referable methods."
8563   (cond
8564    ;; No method, so we default to current and native.
8565    ((null gnus-refer-article-method)
8566     (list gnus-current-select-method gnus-select-method))
8567    ;; Current.
8568    ((eq 'current gnus-refer-article-method)
8569     (list gnus-current-select-method))
8570    ;; List of select methods.
8571    ((not (and (symbolp (car gnus-refer-article-method))
8572               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8573     (let (out)
8574       (dolist (method gnus-refer-article-method)
8575         (push (if (eq 'current method)
8576                   gnus-current-select-method
8577                 method)
8578               out))
8579       (nreverse out)))
8580    ;; One single select method.
8581    (t
8582     (list gnus-refer-article-method))))
8583
8584 (defun gnus-summary-edit-parameters ()
8585   "Edit the group parameters of the current group."
8586   (interactive)
8587   (gnus-group-edit-group gnus-newsgroup-name 'params))
8588
8589 (defun gnus-summary-customize-parameters ()
8590   "Customize the group parameters of the current group."
8591   (interactive)
8592   (gnus-group-customize gnus-newsgroup-name))
8593
8594 (defun gnus-summary-enter-digest-group (&optional force)
8595   "Enter an nndoc group based on the current article.
8596 If FORCE, force a digest interpretation.  If not, try
8597 to guess what the document format is."
8598   (interactive "P")
8599   (let ((conf gnus-current-window-configuration))
8600     (save-window-excursion
8601       (save-excursion
8602         (let (gnus-article-prepare-hook
8603               gnus-display-mime-function
8604               gnus-break-pages)
8605           (gnus-summary-select-article))))
8606     (setq gnus-current-window-configuration conf)
8607     (let* ((name (format "%s-%d"
8608                          (gnus-group-prefixed-name
8609                           gnus-newsgroup-name (list 'nndoc ""))
8610                          (with-current-buffer gnus-summary-buffer
8611                            gnus-current-article)))
8612            (ogroup gnus-newsgroup-name)
8613            (params (append (gnus-info-params (gnus-get-info ogroup))
8614                            (list (cons 'to-group ogroup))
8615                            (list (cons 'parent-group ogroup))
8616                            (list (cons 'save-article-group ogroup))))
8617            (case-fold-search t)
8618            (buf (current-buffer))
8619            dig to-address)
8620       (save-excursion
8621         (set-buffer gnus-original-article-buffer)
8622         ;; Have the digest group inherit the main mail address of
8623         ;; the parent article.
8624         (when (setq to-address (or (gnus-fetch-field "reply-to")
8625                                    (gnus-fetch-field "from")))
8626           (setq params (append
8627                         (list (cons 'to-address
8628                                     (funcall gnus-decode-encoded-word-function
8629                                              to-address))))))
8630         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8631         (insert-buffer-substring gnus-original-article-buffer)
8632         ;; Remove lines that may lead nndoc to misinterpret the
8633         ;; document type.
8634         (narrow-to-region
8635          (goto-char (point-min))
8636          (or (search-forward "\n\n" nil t) (point)))
8637         (goto-char (point-min))
8638         (delete-matching-lines "^Path:\\|^From ")
8639         (widen))
8640       (unwind-protect
8641           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8642                     (gnus-newsgroup-ephemeral-ignored-charsets
8643                      gnus-newsgroup-ignored-charsets))
8644                 (gnus-group-read-ephemeral-group
8645                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8646                               (nndoc-article-type
8647                                ,(if force 'mbox 'guess)))
8648                  t nil nil nil
8649                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8650                                                         "ADAPT")))))
8651               ;; Make all postings to this group go to the parent group.
8652               (nconc (gnus-info-params (gnus-get-info name))
8653                      params)
8654             ;; Couldn't select this doc group.
8655             (switch-to-buffer buf)
8656             (gnus-set-global-variables)
8657             (gnus-configure-windows 'summary)
8658             (gnus-message 3 "Article couldn't be entered?"))
8659         (kill-buffer dig)))))
8660
8661 (defun gnus-summary-read-document (n)
8662   "Open a new group based on the current article(s).
8663 This will allow you to read digests and other similar
8664 documents as newsgroups.
8665 Obeys the standard process/prefix convention."
8666   (interactive "P")
8667   (let* ((ogroup gnus-newsgroup-name)
8668          (params (append (gnus-info-params (gnus-get-info ogroup))
8669                          (list (cons 'to-group ogroup))))
8670          group egroup groups vgroup)
8671     (dolist (article (gnus-summary-work-articles n))
8672       (setq group (format "%s-%d" gnus-newsgroup-name article))
8673       (gnus-summary-remove-process-mark article)
8674       (when (gnus-summary-display-article article)
8675         (save-excursion
8676           (with-temp-buffer
8677             (insert-buffer-substring gnus-original-article-buffer)
8678             ;; Remove some headers that may lead nndoc to make
8679             ;; the wrong guess.
8680             (message-narrow-to-head)
8681             (goto-char (point-min))
8682             (delete-matching-lines "^Path:\\|^From ")
8683             (widen)
8684             (if (setq egroup
8685                       (gnus-group-read-ephemeral-group
8686                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8687                                      (nndoc-article-type guess))
8688                        t nil t))
8689                 (progn
8690             ;; Make all postings to this group go to the parent group.
8691                   (nconc (gnus-info-params (gnus-get-info egroup))
8692                          params)
8693                   (push egroup groups))
8694               ;; Couldn't select this doc group.
8695               (gnus-error 3 "Article couldn't be entered"))))))
8696     ;; Now we have selected all the documents.
8697     (cond
8698      ((not groups)
8699       (error "None of the articles could be interpreted as documents"))
8700      ((gnus-group-read-ephemeral-group
8701        (setq vgroup (format
8702                      "nnvirtual:%s-%s" gnus-newsgroup-name
8703                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8704        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8705        t
8706        (cons (current-buffer) 'summary)))
8707      (t
8708       (error "Couldn't select virtual nndoc group")))))
8709
8710 (defun gnus-summary-isearch-article (&optional regexp-p)
8711   "Do incremental search forward on the current article.
8712 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8713   (interactive "P")
8714   (gnus-summary-select-article)
8715   (gnus-configure-windows 'article)
8716   (gnus-eval-in-buffer-window gnus-article-buffer
8717     (save-restriction
8718       (widen)
8719       (isearch-forward regexp-p))))
8720
8721 (defun gnus-summary-repeat-search-article-forward ()
8722   "Repeat the previous search forwards."
8723   (interactive)
8724   (unless gnus-last-search-regexp
8725     (error "No previous search"))
8726   (gnus-summary-search-article-forward gnus-last-search-regexp))
8727
8728 (defun gnus-summary-repeat-search-article-backward ()
8729   "Repeat the previous search backwards."
8730   (interactive)
8731   (unless gnus-last-search-regexp
8732     (error "No previous search"))
8733   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8734
8735 (defun gnus-summary-search-article-forward (regexp &optional backward)
8736   "Search for an article containing REGEXP forward.
8737 If BACKWARD, search backward instead."
8738   (interactive
8739    (list (read-string
8740           (format "Search article %s (regexp%s): "
8741                   (if current-prefix-arg "backward" "forward")
8742                   (if gnus-last-search-regexp
8743                       (concat ", default " gnus-last-search-regexp)
8744                     "")))
8745          current-prefix-arg))
8746   (if (string-equal regexp "")
8747       (setq regexp (or gnus-last-search-regexp ""))
8748     (setq gnus-last-search-regexp regexp)
8749     (setq gnus-article-before-search gnus-current-article))
8750   ;; Intentionally set gnus-last-article.
8751   (setq gnus-last-article gnus-article-before-search)
8752   (let ((gnus-last-article gnus-last-article))
8753     (if (gnus-summary-search-article regexp backward)
8754         (gnus-summary-show-thread)
8755       (signal 'search-failed (list regexp)))))
8756
8757 (defun gnus-summary-search-article-backward (regexp)
8758   "Search for an article containing REGEXP backward."
8759   (interactive
8760    (list (read-string
8761           (format "Search article backward (regexp%s): "
8762                   (if gnus-last-search-regexp
8763                       (concat ", default " gnus-last-search-regexp)
8764                     "")))))
8765   (gnus-summary-search-article-forward regexp 'backward))
8766
8767 (defun gnus-summary-search-article (regexp &optional backward)
8768   "Search for an article containing REGEXP.
8769 Optional argument BACKWARD means do search for backward.
8770 `gnus-select-article-hook' is not called during the search."
8771   ;; We have to require this here to make sure that the following
8772   ;; dynamic binding isn't shadowed by autoloading.
8773   (require 'gnus-async)
8774   (require 'gnus-art)
8775   (let ((gnus-select-article-hook nil)  ;Disable hook.
8776         (gnus-article-prepare-hook nil)
8777         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8778         (gnus-use-article-prefetch nil)
8779         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8780         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8781         (gnus-visual nil)
8782         (gnus-keep-backlog nil)
8783         (gnus-break-pages nil)
8784         (gnus-summary-display-arrow nil)
8785         (gnus-updated-mode-lines nil)
8786         (gnus-auto-center-summary nil)
8787         (sum (current-buffer))
8788         (gnus-display-mime-function nil)
8789         (found nil)
8790         point)
8791     (gnus-save-hidden-threads
8792       (gnus-summary-select-article)
8793       (set-buffer gnus-article-buffer)
8794       (goto-char (window-point (get-buffer-window (current-buffer))))
8795       (when backward
8796         (forward-line -1))
8797       (while (not found)
8798         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8799         (if (if backward
8800                 (re-search-backward regexp nil t)
8801               (re-search-forward regexp nil t))
8802             ;; We found the regexp.
8803             (progn
8804               (setq found 'found)
8805               (beginning-of-line)
8806               (set-window-start
8807                (get-buffer-window (current-buffer))
8808                (point))
8809               (forward-line 1)
8810               (set-window-point
8811                (get-buffer-window (current-buffer))
8812                (point))
8813               (set-buffer sum)
8814               (setq point (point)))
8815           ;; We didn't find it, so we go to the next article.
8816           (set-buffer sum)
8817           (setq found 'not)
8818           (while (eq found 'not)
8819             (if (not (if backward (gnus-summary-find-prev)
8820                        (gnus-summary-find-next)))
8821                 ;; No more articles.
8822                 (setq found t)
8823               ;; Select the next article and adjust point.
8824               (unless (gnus-summary-article-sparse-p
8825                        (gnus-summary-article-number))
8826                 (setq found nil)
8827                 (gnus-summary-select-article)
8828                 (set-buffer gnus-article-buffer)
8829                 (widen)
8830                 (goto-char (if backward (point-max) (point-min))))))))
8831       (gnus-message 7 ""))
8832     ;; Return whether we found the regexp.
8833     (when (eq found 'found)
8834       (goto-char point)
8835       (gnus-summary-show-thread)
8836       (gnus-summary-goto-subject gnus-current-article)
8837       (gnus-summary-position-point)
8838       t)))
8839
8840 (defun gnus-find-matching-articles (header regexp)
8841   "Return a list of all articles that match REGEXP on HEADER.
8842 This search includes all articles in the current group that Gnus has
8843 fetched headers for, whether they are displayed or not."
8844   (let ((articles nil)
8845         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8846         (case-fold-search t))
8847     (dolist (header gnus-newsgroup-headers)
8848       (when (string-match regexp (funcall func header))
8849         (push (mail-header-number header) articles)))
8850     (nreverse articles)))
8851
8852 (defun gnus-summary-find-matching (header regexp &optional backward unread
8853                                           not-case-fold not-matching)
8854   "Return a list of all articles that match REGEXP on HEADER.
8855 The search stars on the current article and goes forwards unless
8856 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8857 If UNREAD is non-nil, only unread articles will
8858 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8859 in the comparisons. If NOT-MATCHING, return a list of all articles that
8860 not match REGEXP on HEADER."
8861   (let ((case-fold-search (not not-case-fold))
8862         articles d func)
8863     (if (consp header)
8864         (if (eq (car header) 'extra)
8865             (setq func
8866                   `(lambda (h)
8867                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8868                          "")))
8869           (error "%s is an invalid header" header))
8870       (unless (fboundp (intern (concat "mail-header-" header)))
8871         (error "%s is not a valid header" header))
8872       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8873     (dolist (d (if (eq backward 'all)
8874                    gnus-newsgroup-data
8875                  (gnus-data-find-list
8876                   (gnus-summary-article-number)
8877                   (gnus-data-list backward))))
8878       (when (and (or (not unread)       ; We want all articles...
8879                      (gnus-data-unread-p d)) ; Or just unreads.
8880                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8881                  (if not-matching
8882                      (not (string-match
8883                            regexp
8884                            (funcall func (gnus-data-header d))))
8885                    (string-match regexp
8886                                  (funcall func (gnus-data-header d)))))
8887         (push (gnus-data-number d) articles))) ; Success!
8888     (nreverse articles)))
8889
8890 (defun gnus-summary-execute-command (header regexp command &optional backward)
8891   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8892 If HEADER is an empty string (or nil), the match is done on the entire
8893 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8894   (interactive
8895    (list (let ((completion-ignore-case t))
8896            (completing-read
8897             "Header name: "
8898             (mapcar (lambda (header) (list (format "%s" header)))
8899                     (append
8900                      '("Number" "Subject" "From" "Lines" "Date"
8901                        "Message-ID" "Xref" "References" "Body")
8902                      gnus-extra-headers))
8903             nil 'require-match))
8904          (read-string "Regexp: ")
8905          (read-key-sequence "Command: ")
8906          current-prefix-arg))
8907   (when (equal header "Body")
8908     (setq header ""))
8909   ;; Hidden thread subtrees must be searched as well.
8910   (gnus-summary-show-all-threads)
8911   ;; We don't want to change current point nor window configuration.
8912   (save-excursion
8913     (save-window-excursion
8914       (let (gnus-visual
8915             gnus-treat-strip-trailing-blank-lines
8916             gnus-treat-strip-leading-blank-lines
8917             gnus-treat-strip-multiple-blank-lines
8918             gnus-treat-hide-boring-headers
8919             gnus-treat-fold-newsgroups
8920             gnus-article-prepare-hook)
8921         (gnus-message 6 "Executing %s..." (key-description command))
8922         ;; We'd like to execute COMMAND interactively so as to give arguments.
8923         (gnus-execute header regexp
8924                       `(call-interactively ',(key-binding command))
8925                       backward)
8926         (gnus-message 6 "Executing %s...done" (key-description command))))))
8927
8928 (defun gnus-summary-beginning-of-article ()
8929   "Scroll the article back to the beginning."
8930   (interactive)
8931   (gnus-summary-select-article)
8932   (gnus-configure-windows 'article)
8933   (gnus-eval-in-buffer-window gnus-article-buffer
8934     (widen)
8935     (goto-char (point-min))
8936     (when gnus-break-pages
8937       (gnus-narrow-to-page))))
8938
8939 (defun gnus-summary-end-of-article ()
8940   "Scroll to the end of the article."
8941   (interactive)
8942   (gnus-summary-select-article)
8943   (gnus-configure-windows 'article)
8944   (gnus-eval-in-buffer-window gnus-article-buffer
8945     (widen)
8946     (goto-char (point-max))
8947     (recenter -3)
8948     (when gnus-break-pages
8949       (when (re-search-backward page-delimiter nil t)
8950         (narrow-to-region (match-end 0) (point-max)))
8951       (gnus-narrow-to-page))))
8952
8953 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8954   "Truncate to LEN and quote all \"(\"'s in STRING."
8955   (gnus-replace-in-string (if (and len (> (length string) len))
8956                               (substring string 0 len)
8957                             string)
8958                           "[()]" "\\\\\\&"))
8959
8960 (defun gnus-summary-print-article (&optional filename n)
8961   "Generate and print a PostScript image of the process-marked (mail) articles.
8962
8963 If used interactively, print the current article if none are
8964 process-marked.  With prefix arg, prompt the user for the name of the
8965 file to save in.
8966
8967 When used from Lisp, accept two optional args FILENAME and N.  N means
8968 to print the next N articles.  If N is negative, print the N previous
8969 articles.  If N is nil and articles have been marked with the process
8970 mark, print these instead.
8971
8972 If the optional first argument FILENAME is nil, send the image to the
8973 printer.  If FILENAME is a string, save the PostScript image in a file with
8974 that name.  If FILENAME is a number, prompt the user for the name of the file
8975 to save in."
8976   (interactive (list (ps-print-preprint current-prefix-arg)))
8977   (dolist (article (gnus-summary-work-articles n))
8978     (gnus-summary-select-article nil nil 'pseudo article)
8979     (gnus-eval-in-buffer-window gnus-article-buffer
8980       (gnus-print-buffer))
8981     (gnus-summary-remove-process-mark article))
8982   (ps-despool filename))
8983
8984 (defun gnus-print-buffer ()
8985   (let ((buffer (generate-new-buffer " *print*")))
8986     (unwind-protect
8987         (progn
8988           (copy-to-buffer buffer (point-min) (point-max))
8989           (set-buffer buffer)
8990           (gnus-remove-text-with-property 'gnus-decoration)
8991           (when (gnus-visual-p 'article-highlight 'highlight)
8992             ;; Copy-to-buffer doesn't copy overlay.  So redo
8993             ;; highlight.
8994             (let ((gnus-article-buffer buffer))
8995               (gnus-article-highlight-citation t)
8996               (gnus-article-highlight-signature)
8997               (gnus-article-emphasize)
8998               (gnus-article-delete-invisible-text)))
8999           (let ((ps-left-header
9000                  (list
9001                   (concat "("
9002                           (gnus-summary-print-truncate-and-quote
9003                            (mail-header-subject gnus-current-headers)
9004                            66) ")")
9005                   (concat "("
9006                           (gnus-summary-print-truncate-and-quote
9007                            (mail-header-from gnus-current-headers)
9008                            45) ")")))
9009                 (ps-right-header
9010                  (list
9011                   "/pagenumberstring load"
9012                   (concat "("
9013                           (mail-header-date gnus-current-headers) ")"))))
9014             (gnus-run-hooks 'gnus-ps-print-hook)
9015             (save-excursion
9016               (if window-system
9017                   (ps-spool-buffer-with-faces)
9018                 (ps-spool-buffer)))))
9019       (kill-buffer buffer))))
9020
9021 (defun gnus-summary-show-article (&optional arg)
9022   "Force redisplaying of the current article.
9023 If ARG (the prefix) is a number, show the article with the charset
9024 defined in `gnus-summary-show-article-charset-alist', or the charset
9025 input.
9026 If ARG (the prefix) is non-nil and not a number, show the raw article
9027 without any article massaging functions being run.  Normally, the key
9028 strokes are `C-u g'."
9029   (interactive "P")
9030   (cond
9031    ((numberp arg)
9032     (gnus-summary-show-article t)
9033     (let ((gnus-newsgroup-charset
9034            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9035                (mm-read-coding-system
9036                 "View as charset: " ;; actually it is coding system.
9037                 (with-current-buffer gnus-article-buffer
9038                   (mm-detect-coding-region (point) (point-max))))))
9039           (gnus-newsgroup-ignored-charsets 'gnus-all))
9040       (gnus-summary-select-article nil 'force)
9041       (let ((deps gnus-newsgroup-dependencies)
9042             head header lines)
9043         (save-excursion
9044           (set-buffer gnus-original-article-buffer)
9045           (save-restriction
9046             (message-narrow-to-head)
9047             (setq head (buffer-string))
9048             (goto-char (point-min))
9049             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9050               (goto-char (point-max))
9051               (widen)
9052               (setq lines (1- (count-lines (point) (point-max))))))
9053           (with-temp-buffer
9054             (insert (format "211 %d Article retrieved.\n"
9055                             (cdr gnus-article-current)))
9056             (insert head)
9057             (if lines (insert (format "Lines: %d\n" lines)))
9058             (insert ".\n")
9059             (let ((nntp-server-buffer (current-buffer)))
9060               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9061         (gnus-data-set-header
9062          (gnus-data-find (cdr gnus-article-current))
9063          header)
9064         (gnus-summary-update-article-line
9065          (cdr gnus-article-current) header)
9066         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9067           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9068    ((not arg)
9069     ;; Select the article the normal way.
9070     (gnus-summary-select-article nil 'force))
9071    (t
9072     ;; We have to require this here to make sure that the following
9073     ;; dynamic binding isn't shadowed by autoloading.
9074     (require 'gnus-async)
9075     (require 'gnus-art)
9076     ;; Bind the article treatment functions to nil.
9077     (let ((gnus-have-all-headers t)
9078           gnus-article-prepare-hook
9079           gnus-article-decode-hook
9080           gnus-display-mime-function
9081           gnus-break-pages)
9082       ;; Destroy any MIME parts.
9083       (when (gnus-buffer-live-p gnus-article-buffer)
9084         (save-excursion
9085           (set-buffer gnus-article-buffer)
9086           (mm-destroy-parts gnus-article-mime-handles)
9087           ;; Set it to nil for safety reason.
9088           (setq gnus-article-mime-handle-alist nil)
9089           (setq gnus-article-mime-handles nil)))
9090       (gnus-summary-select-article nil 'force))))
9091   (gnus-summary-goto-subject gnus-current-article)
9092   (gnus-summary-position-point))
9093
9094 (defun gnus-summary-show-raw-article ()
9095   "Show the raw article without any article massaging functions being run."
9096   (interactive)
9097   (gnus-summary-show-article t))
9098
9099 (defun gnus-summary-verbose-headers (&optional arg)
9100   "Toggle permanent full header display.
9101 If ARG is a positive number, turn header display on.
9102 If ARG is a negative number, turn header display off."
9103   (interactive "P")
9104   (setq gnus-show-all-headers
9105         (cond ((or (not (numberp arg))
9106                    (zerop arg))
9107                (not gnus-show-all-headers))
9108               ((natnump arg)
9109                t)))
9110   (gnus-summary-show-article))
9111
9112 (defun gnus-summary-toggle-header (&optional arg)
9113   "Show the headers if they are hidden, or hide them if they are shown.
9114 If ARG is a positive number, show the entire header.
9115 If ARG is a negative number, hide the unwanted header lines."
9116   (interactive "P")
9117   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9118                      (get-buffer-window gnus-article-buffer t))))
9119     (with-current-buffer gnus-article-buffer
9120       (widen)
9121       (article-narrow-to-head)
9122       (let* ((buffer-read-only nil)
9123              (inhibit-point-motion-hooks t)
9124              (hidden (if (numberp arg)
9125                          (>= arg 0)
9126                        (or (not (looking-at "[^ \t\n]+:"))
9127                            (gnus-article-hidden-text-p 'headers))))
9128              s e)
9129         (delete-region (point-min) (point-max))
9130         (with-current-buffer gnus-original-article-buffer
9131           (goto-char (setq s (point-min)))
9132           (setq e (if (search-forward "\n\n" nil t)
9133                       (1- (point))
9134                     (point-max))))
9135         (insert-buffer-substring gnus-original-article-buffer s e)
9136         (run-hooks 'gnus-article-decode-hook)
9137         (if hidden
9138             (let ((gnus-treat-hide-headers nil)
9139                   (gnus-treat-hide-boring-headers nil))
9140               (gnus-delete-wash-type 'headers)
9141               (gnus-treat-article 'head))
9142           (gnus-treat-article 'head))
9143         (widen)
9144         (if window
9145             (set-window-start window (goto-char (point-min))))
9146         (if gnus-break-pages
9147             (gnus-narrow-to-page)
9148           (when (gnus-visual-p 'page-marker)
9149             (let ((buffer-read-only nil))
9150               (gnus-remove-text-with-property 'gnus-prev)
9151               (gnus-remove-text-with-property 'gnus-next))))
9152         (gnus-set-mode-line 'article)))))
9153
9154 (defun gnus-summary-show-all-headers ()
9155   "Make all header lines visible."
9156   (interactive)
9157   (gnus-summary-toggle-header 1))
9158
9159 (defun gnus-summary-caesar-message (&optional arg)
9160   "Caesar rotate the current article by 13.
9161 The numerical prefix specifies how many places to rotate each letter
9162 forward."
9163   (interactive "P")
9164   (gnus-summary-select-article)
9165   (let ((mail-header-separator ""))
9166     (gnus-eval-in-buffer-window gnus-article-buffer
9167       (save-restriction
9168         (widen)
9169         (let ((start (window-start))
9170               buffer-read-only)
9171           (message-caesar-buffer-body arg)
9172           (set-window-start (get-buffer-window (current-buffer)) start)))))
9173   ;; Create buttons and stuff...
9174   (gnus-treat-article nil))
9175
9176 (defun gnus-summary-idna-message (&optional arg)
9177   "Decode IDNA encoded domain names in the current articles.
9178 IDNA encoded domain names looks like `xn--bar'.  If a string
9179 remain unencoded after running this function, it is likely an
9180 invalid IDNA string (`xn--bar' is invalid).
9181
9182 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9183 installed for this command to work."
9184   (interactive "P")
9185   (if (not (and (condition-case nil (require 'idna)
9186                   (file-error))
9187                 (mm-coding-system-p 'utf-8)
9188                 (executable-find (symbol-value 'idna-program))))
9189       (gnus-message
9190        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9191     (gnus-summary-select-article)
9192     (let ((mail-header-separator ""))
9193       (gnus-eval-in-buffer-window gnus-article-buffer
9194         (save-restriction
9195           (widen)
9196           (let ((start (window-start))
9197                 buffer-read-only)
9198             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9199               (replace-match (idna-to-unicode (match-string 1))))
9200             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9201
9202 (defun gnus-summary-morse-message (&optional arg)
9203   "Morse decode the current article."
9204   (interactive "P")
9205   (gnus-summary-select-article)
9206   (let ((mail-header-separator ""))
9207     (gnus-eval-in-buffer-window gnus-article-buffer
9208       (save-excursion
9209         (save-restriction
9210           (widen)
9211           (let ((pos (window-start))
9212                 buffer-read-only)
9213             (goto-char (point-min))
9214             (when (message-goto-body)
9215               (gnus-narrow-to-body))
9216             (goto-char (point-min))
9217             (while (search-forward "·" (point-max) t)
9218               (replace-match "."))
9219             (unmorse-region (point-min) (point-max))
9220             (widen)
9221             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9222
9223 (defun gnus-summary-stop-page-breaking ()
9224   "Stop page breaking in the current article."
9225   (interactive)
9226   (gnus-summary-select-article)
9227   (gnus-eval-in-buffer-window gnus-article-buffer
9228     (widen)
9229     (when (gnus-visual-p 'page-marker)
9230       (let ((buffer-read-only nil))
9231         (gnus-remove-text-with-property 'gnus-prev)
9232         (gnus-remove-text-with-property 'gnus-next))
9233       (setq gnus-page-broken nil))))
9234
9235 (defun gnus-summary-move-article (&optional n to-newsgroup
9236                                             select-method action)
9237   "Move the current article to a different newsgroup.
9238 If N is a positive number, move the N next articles.
9239 If N is a negative number, move the N previous articles.
9240 If N is nil and any articles have been marked with the process mark,
9241 move those articles instead.
9242 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9243 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9244 re-spool using this method.
9245
9246 When called interactively with TO-NEWSGROUP being nil, the value of
9247 the variable `gnus-move-split-methods' is used for finding a default
9248 for the target newsgroup.
9249
9250 For this function to work, both the current newsgroup and the
9251 newsgroup that you want to move to have to support the `request-move'
9252 and `request-accept' functions.
9253
9254 ACTION can be either `move' (the default), `crosspost' or `copy'."
9255   (interactive "P")
9256   (unless action
9257     (setq action 'move))
9258   ;; Check whether the source group supports the required functions.
9259   (cond ((and (eq action 'move)
9260               (not (gnus-check-backend-function
9261                     'request-move-article gnus-newsgroup-name)))
9262          (error "The current group does not support article moving"))
9263         ((and (eq action 'crosspost)
9264               (not (gnus-check-backend-function
9265                     'request-replace-article gnus-newsgroup-name)))
9266          (error "The current group does not support article editing")))
9267   (let ((articles (gnus-summary-work-articles n))
9268         (prefix (if (gnus-check-backend-function
9269                      'request-move-article gnus-newsgroup-name)
9270                     (funcall gnus-move-group-prefix-function
9271                              gnus-newsgroup-name)
9272                   ""))
9273         (names '((move "Move" "Moving")
9274                  (copy "Copy" "Copying")
9275                  (crosspost "Crosspost" "Crossposting")))
9276         (copy-buf (save-excursion
9277                     (nnheader-set-temp-buffer " *copy article*")))
9278         art-group to-method new-xref article to-groups articles-to-update-marks)
9279     (unless (assq action names)
9280       (error "Unknown action %s" action))
9281     ;; Read the newsgroup name.
9282     (when (and (not to-newsgroup)
9283                (not select-method))
9284       (if (and gnus-move-split-methods
9285                (not
9286                 (and (memq gnus-current-article articles)
9287                      (gnus-buffer-live-p gnus-original-article-buffer))))
9288           ;; When `gnus-move-split-methods' is non-nil, we have to
9289           ;; select an article to give `gnus-read-move-group-name' an
9290           ;; opportunity to suggest an appropriate default.  However,
9291           ;; we needn't render or mark the article.
9292           (let ((gnus-display-mime-function nil)
9293                 (gnus-article-prepare-hook nil)
9294                 (gnus-mark-article-hook nil))
9295             (gnus-summary-select-article nil nil nil (car articles))))
9296       (setq to-newsgroup
9297             (gnus-read-move-group-name
9298              (cadr (assq action names))
9299              (symbol-value (intern (format "gnus-current-%s-group" action)))
9300              articles prefix))
9301       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9302     (setq to-method (or select-method
9303                         (gnus-server-to-method
9304                          (gnus-group-method to-newsgroup))))
9305     ;; Check the method we are to move this article to...
9306     (unless (gnus-check-backend-function
9307              'request-accept-article (car to-method))
9308       (error "%s does not support article copying" (car to-method)))
9309     (unless (gnus-check-server to-method)
9310       (error "Can't open server %s" (car to-method)))
9311     (gnus-message 6 "%s to %s: %s..."
9312                   (caddr (assq action names))
9313                   (or (car select-method) to-newsgroup) articles)
9314     (while articles
9315       (setq article (pop articles))
9316       (setq
9317        art-group
9318        (cond
9319         ;; Move the article.
9320         ((eq action 'move)
9321          ;; Remove this article from future suppression.
9322          (gnus-dup-unsuppress-article article)
9323          (let* ((from-method (gnus-find-method-for-group
9324                               gnus-newsgroup-name))
9325                 (to-method (gnus-find-method-for-group
9326                             to-newsgroup))
9327                 (move-is-internal (gnus-method-equal from-method to-method)))
9328          (gnus-request-move-article
9329           article                       ; Article to move
9330           gnus-newsgroup-name           ; From newsgroup
9331           (nth 1 (gnus-find-method-for-group
9332                   gnus-newsgroup-name)) ; Server
9333           (list 'gnus-request-accept-article
9334                 to-newsgroup (list 'quote select-method)
9335                 (not articles) t)       ; Accept form
9336           (not articles)                ; Only save nov last time
9337           move-is-internal)))           ; is this move internal?
9338         ;; Copy the article.
9339         ((eq action 'copy)
9340          (save-excursion
9341            (set-buffer copy-buf)
9342            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9343              (save-restriction
9344                (nnheader-narrow-to-headers)
9345                (dolist (hdr gnus-copy-article-ignored-headers)
9346                  (message-remove-header hdr t)))
9347              (gnus-request-accept-article
9348               to-newsgroup select-method (not articles) t))))
9349         ;; Crosspost the article.
9350         ((eq action 'crosspost)
9351          (let ((xref (message-tokenize-header
9352                       (mail-header-xref (gnus-summary-article-header article))
9353                       " ")))
9354            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9355                                   ":" (number-to-string article)))
9356            (unless xref
9357              (setq xref (list (system-name))))
9358            (setq new-xref
9359                  (concat
9360                   (mapconcat 'identity
9361                              (delete "Xref:" (delete new-xref xref))
9362                              " ")
9363                   " " new-xref))
9364            (save-excursion
9365              (set-buffer copy-buf)
9366              ;; First put the article in the destination group.
9367              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9368              (when (consp (setq art-group
9369                                 (gnus-request-accept-article
9370                                  to-newsgroup select-method (not articles))))
9371                (setq new-xref (concat new-xref " " (car art-group)
9372                                       ":"
9373                                       (number-to-string (cdr art-group))))
9374                ;; Now we have the new Xrefs header, so we insert
9375                ;; it and replace the new article.
9376                (nnheader-replace-header "Xref" new-xref)
9377                (gnus-request-replace-article
9378                 (cdr art-group) to-newsgroup (current-buffer))
9379                art-group))))))
9380       (cond
9381        ((not art-group)
9382         (gnus-message 1 "Couldn't %s article %s: %s"
9383                       (cadr (assq action names)) article
9384                       (nnheader-get-report (car to-method))))
9385        ((eq art-group 'junk)
9386         (when (eq action 'move)
9387           (gnus-summary-mark-article article gnus-canceled-mark)
9388           (gnus-message 4 "Deleted article %s" article)
9389           ;; run the delete hook
9390           (run-hook-with-args 'gnus-summary-article-delete-hook
9391                               action
9392                               (gnus-data-header
9393                                (assoc article (gnus-data-list nil)))
9394                               gnus-newsgroup-name nil
9395                               select-method)))
9396        (t
9397         (let* ((pto-group (gnus-group-prefixed-name
9398                            (car art-group) to-method))
9399                (info (gnus-get-info pto-group))
9400                (to-group (gnus-info-group info))
9401                to-marks)
9402           ;; Update the group that has been moved to.
9403           (when (and info
9404                      (memq action '(move copy)))
9405             (unless (member to-group to-groups)
9406               (push to-group to-groups))
9407
9408             (unless (memq article gnus-newsgroup-unreads)
9409               (push 'read to-marks)
9410               (gnus-info-set-read
9411                info (gnus-add-to-range (gnus-info-read info)
9412                                        (list (cdr art-group)))))
9413
9414             ;; See whether the article is to be put in the cache.
9415             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9416                              gnus-article-mark-lists
9417                            (delete '(expirable . expire)
9418                                    (copy-sequence gnus-article-mark-lists))))
9419                   (to-article (cdr art-group)))
9420
9421               ;; Enter the article into the cache in the new group,
9422               ;; if that is required.
9423               (when gnus-use-cache
9424                 (gnus-cache-possibly-enter-article
9425                  to-group to-article
9426                  (memq article gnus-newsgroup-marked)
9427                  (memq article gnus-newsgroup-dormant)
9428                  (memq article gnus-newsgroup-unreads)))
9429
9430               (when gnus-preserve-marks
9431                 ;; Copy any marks over to the new group.
9432                 (when (and (equal to-group gnus-newsgroup-name)
9433                            (not (memq article gnus-newsgroup-unreads)))
9434                   ;; Mark this article as read in this group.
9435                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9436                   (setcdr (gnus-active to-group) to-article)
9437                   (setcdr gnus-newsgroup-active to-article))
9438
9439                 (while marks
9440                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9441                     (when (memq article (symbol-value
9442                                          (intern (format "gnus-newsgroup-%s"
9443                                                          (caar marks)))))
9444                       (push (cdar marks) to-marks)
9445                       ;; If the other group is the same as this group,
9446                       ;; then we have to add the mark to the list.
9447                       (when (equal to-group gnus-newsgroup-name)
9448                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9449                              (cons to-article
9450                                    (symbol-value
9451                                     (intern (format "gnus-newsgroup-%s"
9452                                                     (caar marks)))))))
9453                       ;; Copy the marks to other group.
9454                       (gnus-add-marked-articles
9455                        to-group (cdar marks) (list to-article) info)))
9456                   (setq marks (cdr marks)))
9457
9458                 (gnus-request-set-mark
9459                  to-group (list (list (list to-article) 'add to-marks))))
9460
9461               (gnus-dribble-enter
9462                (concat "(gnus-group-set-info '"
9463                        (gnus-prin1-to-string (gnus-get-info to-group))
9464                        ")"))))
9465
9466           ;; Update the Xref header in this article to point to
9467           ;; the new crossposted article we have just created.
9468           (when (eq action 'crosspost)
9469             (save-excursion
9470               (set-buffer copy-buf)
9471               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9472               (nnheader-replace-header "Xref" new-xref)
9473               (gnus-request-replace-article
9474                article gnus-newsgroup-name (current-buffer))))
9475
9476           ;; run the move/copy/crosspost/respool hook
9477           (run-hook-with-args 'gnus-summary-article-move-hook
9478                               action
9479                               (gnus-data-header
9480                                (assoc article (gnus-data-list nil)))
9481                               gnus-newsgroup-name
9482                               to-newsgroup
9483                               select-method))
9484
9485         ;;;!!!Why is this necessary?
9486         (set-buffer gnus-summary-buffer)
9487         
9488         (gnus-summary-goto-subject article)
9489         (when (eq action 'move)
9490           (gnus-summary-mark-article article gnus-canceled-mark))))
9491       (push article articles-to-update-marks))
9492
9493     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9494     ;; Re-activate all groups that have been moved to.
9495     (save-excursion
9496       (set-buffer gnus-group-buffer)
9497       (let ((gnus-group-marked to-groups))
9498         (gnus-group-get-new-news-this-group nil t)))
9499     
9500     (gnus-kill-buffer copy-buf)
9501     (gnus-summary-position-point)
9502     (gnus-set-mode-line 'summary)))
9503
9504 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9505   "Copy the current article to some other group.
9506 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9507 When called interactively, if TO-NEWSGROUP is nil, use the value of
9508 the variable `gnus-move-split-methods' for finding a default target
9509 newsgroup.
9510 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9511 re-spool using this method."
9512   (interactive "P")
9513   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9514
9515 (defun gnus-summary-crosspost-article (&optional n)
9516   "Crosspost the current article to some other group."
9517   (interactive "P")
9518   (gnus-summary-move-article n nil nil 'crosspost))
9519
9520 (defcustom gnus-summary-respool-default-method nil
9521   "Default method type for respooling an article.
9522 If nil, use to the current newsgroup method."
9523   :type 'symbol
9524   :group 'gnus-summary-mail)
9525
9526 (defcustom gnus-summary-display-while-building nil
9527   "If non-nil, show and update the summary buffer as it's being built.
9528 If the value is t, update the buffer after every line is inserted.  If
9529 the value is an integer (N), update the display every N lines."
9530   :version "22.1"
9531   :group 'gnus-thread
9532   :type '(choice (const :tag "off" nil)
9533                  number
9534                  (const :tag "frequently" t)))
9535
9536 (defun gnus-summary-respool-article (&optional n method)
9537   "Respool the current article.
9538 The article will be squeezed through the mail spooling process again,
9539 which means that it will be put in some mail newsgroup or other
9540 depending on `nnmail-split-methods'.
9541 If N is a positive number, respool the N next articles.
9542 If N is a negative number, respool the N previous articles.
9543 If N is nil and any articles have been marked with the process mark,
9544 respool those articles instead.
9545
9546 Respooling can be done both from mail groups and \"real\" newsgroups.
9547 In the former case, the articles in question will be moved from the
9548 current group into whatever groups they are destined to.  In the
9549 latter case, they will be copied into the relevant groups."
9550   (interactive
9551    (list current-prefix-arg
9552          (let* ((methods (gnus-methods-using 'respool))
9553                 (methname
9554                  (symbol-name (or gnus-summary-respool-default-method
9555                                   (car (gnus-find-method-for-group
9556                                         gnus-newsgroup-name)))))
9557                 (method
9558                  (gnus-completing-read-with-default
9559                   methname "Backend to use when respooling"
9560                   methods nil t nil 'gnus-mail-method-history))
9561                 ms)
9562            (cond
9563             ((zerop (length (setq ms (gnus-servers-using-backend
9564                                       (intern method)))))
9565              (list (intern method) ""))
9566             ((= 1 (length ms))
9567              (car ms))
9568             (t
9569              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9570                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9571                            ms-alist))))))))
9572   (unless method
9573     (error "No method given for respooling"))
9574   (if (assoc (symbol-name
9575               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9576              (gnus-methods-using 'respool))
9577       (gnus-summary-move-article n nil method)
9578     (gnus-summary-copy-article n nil method)))
9579
9580 (defun gnus-summary-import-article (file &optional edit)
9581   "Import an arbitrary file into a mail newsgroup."
9582   (interactive "fImport file: \nP")
9583   (let ((group gnus-newsgroup-name)
9584         (now (current-time))
9585         atts lines group-art)
9586     (unless (gnus-check-backend-function 'request-accept-article group)
9587       (error "%s does not support article importing" group))
9588     (or (file-readable-p file)
9589         (not (file-regular-p file))
9590         (error "Can't read %s" file))
9591     (save-excursion
9592       (set-buffer (gnus-get-buffer-create " *import file*"))
9593       (erase-buffer)
9594       (nnheader-insert-file-contents file)
9595       (goto-char (point-min))
9596       (if (nnheader-article-p)
9597           (save-restriction
9598             (goto-char (point-min))
9599             (search-forward "\n\n" nil t)
9600             (narrow-to-region (point-min) (1- (point)))
9601             (goto-char (point-min))
9602             (unless (re-search-forward "^date:" nil t)
9603               (goto-char (point-max))
9604               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9605        ;; This doesn't look like an article, so we fudge some headers.
9606         (setq atts (file-attributes file)
9607               lines (count-lines (point-min) (point-max)))
9608         (insert "From: " (read-string "From: ") "\n"
9609                 "Subject: " (read-string "Subject: ") "\n"
9610                 "Date: " (message-make-date (nth 5 atts)) "\n"
9611                 "Message-ID: " (message-make-message-id) "\n"
9612                 "Lines: " (int-to-string lines) "\n"
9613                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9614       (setq group-art (gnus-request-accept-article group nil t))
9615       (kill-buffer (current-buffer)))
9616     (setq gnus-newsgroup-active (gnus-activate-group group))
9617     (forward-line 1)
9618     (gnus-summary-goto-article (cdr group-art) nil t)
9619     (when edit
9620       (gnus-summary-edit-article))))
9621
9622 (defun gnus-summary-create-article ()
9623   "Create an article in a mail newsgroup."
9624   (interactive)
9625   (let ((group gnus-newsgroup-name)
9626         (now (current-time))
9627         group-art)
9628     (unless (gnus-check-backend-function 'request-accept-article group)
9629       (error "%s does not support article importing" group))
9630     (save-excursion
9631       (set-buffer (gnus-get-buffer-create " *import file*"))
9632       (erase-buffer)
9633       (goto-char (point-min))
9634       ;; This doesn't look like an article, so we fudge some headers.
9635       (insert "From: " (read-string "From: ") "\n"
9636               "Subject: " (read-string "Subject: ") "\n"
9637               "Date: " (message-make-date now) "\n"
9638               "Message-ID: " (message-make-message-id) "\n")
9639       (setq group-art (gnus-request-accept-article group nil t))
9640       (kill-buffer (current-buffer)))
9641     (setq gnus-newsgroup-active (gnus-activate-group group))
9642     (forward-line 1)
9643     (gnus-summary-goto-article (cdr group-art) nil t)
9644     (gnus-summary-edit-article)))
9645
9646 (defun gnus-summary-article-posted-p ()
9647   "Say whether the current (mail) article is available from news as well.
9648 This will be the case if the article has both been mailed and posted."
9649   (interactive)
9650   (let ((id (mail-header-references (gnus-summary-article-header)))
9651         (gnus-override-method (car (gnus-refer-article-methods))))
9652     (if (gnus-request-head id "")
9653         (gnus-message 2 "The current message was found on %s"
9654                       gnus-override-method)
9655       (gnus-message 2 "The current message couldn't be found on %s"
9656                     gnus-override-method)
9657       nil)))
9658
9659 (defun gnus-summary-expire-articles (&optional now)
9660   "Expire all articles that are marked as expirable in the current group."
9661   (interactive)
9662   (when (and (not gnus-group-is-exiting-without-update-p)
9663              (gnus-check-backend-function
9664               'request-expire-articles gnus-newsgroup-name))
9665     ;; This backend supports expiry.
9666     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9667            (expirable (if total
9668                           (progn
9669                             ;; We need to update the info for
9670                             ;; this group for `gnus-list-of-read-articles'
9671                             ;; to give us the right answer.
9672                             (gnus-run-hooks 'gnus-exit-group-hook)
9673                             (gnus-summary-update-info)
9674                             (gnus-list-of-read-articles gnus-newsgroup-name))
9675                         (setq gnus-newsgroup-expirable
9676                               (sort gnus-newsgroup-expirable '<))))
9677            (expiry-wait (if now 'immediate
9678                           (gnus-group-find-parameter
9679                            gnus-newsgroup-name 'expiry-wait)))
9680            (nnmail-expiry-target
9681             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9682                 nnmail-expiry-target))
9683            es)
9684       (when expirable
9685         ;; There are expirable articles in this group, so we run them
9686         ;; through the expiry process.
9687         (gnus-message 6 "Expiring articles...")
9688         (unless (gnus-check-group gnus-newsgroup-name)
9689           (error "Can't open server for %s" gnus-newsgroup-name))
9690         ;; The list of articles that weren't expired is returned.
9691         (save-excursion
9692           (if expiry-wait
9693               (let ((nnmail-expiry-wait-function nil)
9694                     (nnmail-expiry-wait expiry-wait))
9695                 (setq es (gnus-request-expire-articles
9696                           expirable gnus-newsgroup-name)))
9697             (setq es (gnus-request-expire-articles
9698                       expirable gnus-newsgroup-name)))
9699           (unless total
9700             (setq gnus-newsgroup-expirable es))
9701           ;; We go through the old list of expirable, and mark all
9702           ;; really expired articles as nonexistent.
9703           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9704             (let ((gnus-use-cache nil))
9705               (dolist (article expirable)
9706                 (when (and (not (memq article es))
9707                            (gnus-data-find article))
9708                   (gnus-summary-mark-article article gnus-canceled-mark)
9709                   (run-hook-with-args 'gnus-summary-article-expire-hook
9710                                       'delete
9711                                       (gnus-data-header
9712                                        (assoc article (gnus-data-list nil)))
9713                                       gnus-newsgroup-name
9714                                       nil
9715                                       nil))))))
9716         (gnus-message 6 "Expiring articles...done")))))
9717
9718 (defun gnus-summary-expire-articles-now ()
9719   "Expunge all expirable articles in the current group.
9720 This means that *all* articles that are marked as expirable will be
9721 deleted forever, right now."
9722   (interactive)
9723   (or gnus-expert-user
9724       (gnus-yes-or-no-p
9725        "Are you really, really sure you want to delete all expirable messages? ")
9726       (error "Phew!"))
9727   (gnus-summary-expire-articles t))
9728
9729 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9730 (defun gnus-summary-delete-article (&optional n)
9731   "Delete the N next (mail) articles.
9732 This command actually deletes articles.  This is not a marking
9733 command.  The article will disappear forever from your life, never to
9734 return.
9735
9736 If N is negative, delete backwards.
9737 If N is nil and articles have been marked with the process mark,
9738 delete these instead.
9739
9740 If `gnus-novice-user' is non-nil you will be asked for
9741 confirmation before the articles are deleted."
9742   (interactive "P")
9743   (unless (gnus-check-backend-function 'request-expire-articles
9744                                        gnus-newsgroup-name)
9745     (error "The current newsgroup does not support article deletion"))
9746   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9747     (error "Couldn't open server"))
9748   ;; Compute the list of articles to delete.
9749   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9750         (nnmail-expiry-target 'delete)
9751         not-deleted)
9752     (if (and gnus-novice-user
9753              (not (gnus-yes-or-no-p
9754                    (format "Do you really want to delete %s forever? "
9755                            (if (> (length articles) 1)
9756                                (format "these %s articles" (length articles))
9757                              "this article")))))
9758         ()
9759       ;; Delete the articles.
9760       (setq not-deleted (gnus-request-expire-articles
9761                          articles gnus-newsgroup-name 'force))
9762       (while articles
9763         (gnus-summary-remove-process-mark (car articles))
9764         ;; The backend might not have been able to delete the article
9765         ;; after all.
9766         (unless (memq (car articles) not-deleted)
9767           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9768         (let* ((article (car articles))
9769                (ghead  (gnus-data-header
9770                                     (assoc article (gnus-data-list nil)))))
9771           (run-hook-with-args 'gnus-summary-article-delete-hook
9772                               'delete ghead gnus-newsgroup-name nil
9773                               nil))
9774         (setq articles (cdr articles)))
9775       (when not-deleted
9776         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9777     (gnus-summary-position-point)
9778     (gnus-set-mode-line 'summary)
9779     not-deleted))
9780
9781 (defun gnus-summary-edit-article (&optional arg)
9782   "Edit the current article.
9783 This will have permanent effect only in mail groups.
9784 If ARG is nil, edit the decoded articles.
9785 If ARG is 1, edit the raw articles.
9786 If ARG is 2, edit the raw articles even in read-only groups.
9787 If ARG is 3, edit the articles with the current handles.
9788 Otherwise, allow editing of articles even in read-only
9789 groups."
9790   (interactive "P")
9791   (let (force raw current-handles)
9792     (cond
9793      ((null arg))
9794      ((eq arg 1)
9795       (setq raw t))
9796      ((eq arg 2)
9797       (setq raw t
9798             force t))
9799      ((eq arg 3)
9800       (setq current-handles
9801             (and (gnus-buffer-live-p gnus-article-buffer)
9802                  (with-current-buffer gnus-article-buffer
9803                    (prog1
9804                        gnus-article-mime-handles
9805                      (setq gnus-article-mime-handles nil))))))
9806      (t
9807       (setq force t)))
9808     (when (and raw (not force)
9809                (member gnus-newsgroup-name '("nndraft:delayed"
9810                                              "nndraft:drafts"
9811                                              "nndraft:queue")))
9812       (error "Can't edit the raw article in group %s"
9813              gnus-newsgroup-name))
9814     (save-excursion
9815       (set-buffer gnus-summary-buffer)
9816       (let ((mail-parse-charset gnus-newsgroup-charset)
9817             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9818         (gnus-set-global-variables)
9819         (when (and (not force)
9820                    (gnus-group-read-only-p))
9821           (error "The current newsgroup does not support article editing"))
9822         (gnus-summary-show-article t)
9823         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9824           (with-current-buffer gnus-article-buffer
9825             (mm-enable-multibyte)))
9826         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9827             (setq raw t))
9828         (gnus-article-edit-article
9829          (if raw 'ignore
9830            `(lambda ()
9831               (let ((mbl mml-buffer-list))
9832                 (setq mml-buffer-list nil)
9833                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9834                   (mime-to-mml ,'current-handles))
9835                 (let ((mbl1 mml-buffer-list))
9836                   (setq mml-buffer-list mbl)
9837                   (set (make-local-variable 'mml-buffer-list) mbl1))
9838                 (gnus-make-local-hook 'kill-buffer-hook)
9839                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9840          `(lambda (no-highlight)
9841             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9842                   (message-options message-options)
9843                   (message-options-set-recipient)
9844                   (mail-parse-ignored-charsets
9845                    ',gnus-newsgroup-ignored-charsets))
9846               ,(if (not raw) '(progn
9847                                 (mml-to-mime)
9848                                 (mml-destroy-buffers)
9849                                 (remove-hook 'kill-buffer-hook
9850                                              'mml-destroy-buffers t)
9851                                 (kill-local-variable 'mml-buffer-list)))
9852               (gnus-summary-edit-article-done
9853                ,(or (mail-header-references gnus-current-headers) "")
9854                ,(gnus-group-read-only-p)
9855                ,gnus-summary-buffer no-highlight))))))))
9856
9857 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9858
9859 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9860                                                  no-highlight)
9861   "Make edits to the current article permanent."
9862   (interactive)
9863   (save-excursion
9864    ;; The buffer restriction contains the entire article if it exists.
9865     (when (article-goto-body)
9866       (let ((lines (count-lines (point) (point-max)))
9867             (length (- (point-max) (point)))
9868             (case-fold-search t)
9869             (body (copy-marker (point))))
9870         (goto-char (point-min))
9871         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9872           (delete-region (match-beginning 1) (match-end 1))
9873           (insert (number-to-string length)))
9874         (goto-char (point-min))
9875         (when (re-search-forward
9876                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9877           (delete-region (match-beginning 1) (match-end 1))
9878           (insert (number-to-string length)))
9879         (goto-char (point-min))
9880         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9881           (delete-region (match-beginning 1) (match-end 1))
9882           (insert (number-to-string lines))))))
9883   ;; Replace the article.
9884   (let ((buf (current-buffer)))
9885     (with-temp-buffer
9886       (insert-buffer-substring buf)
9887
9888       (if (and (not read-only)
9889                (not (gnus-request-replace-article
9890                      (cdr gnus-article-current) (car gnus-article-current)
9891                      (current-buffer) t)))
9892           (error "Couldn't replace article")
9893         ;; Update the summary buffer.
9894         (if (and references
9895                  (equal (message-tokenize-header references " ")
9896                         (message-tokenize-header
9897                          (or (message-fetch-field "references") "") " ")))
9898             ;; We only have to update this line.
9899             (save-excursion
9900               (save-restriction
9901                 (message-narrow-to-head)
9902                 (let ((head (buffer-substring-no-properties
9903                              (point-min) (point-max)))
9904                       header)
9905                   (with-temp-buffer
9906                     (insert (format "211 %d Article retrieved.\n"
9907                                     (cdr gnus-article-current)))
9908                     (insert head)
9909                     (insert ".\n")
9910                     (let ((nntp-server-buffer (current-buffer)))
9911                       (setq header (car (gnus-get-newsgroup-headers
9912                                          nil t))))
9913                     (save-excursion
9914                       (set-buffer gnus-summary-buffer)
9915                       (gnus-data-set-header
9916                        (gnus-data-find (cdr gnus-article-current))
9917                        header)
9918                       (gnus-summary-update-article-line
9919                        (cdr gnus-article-current) header)
9920                       (if (gnus-summary-goto-subject
9921                            (cdr gnus-article-current) nil t)
9922                           (gnus-summary-update-secondary-mark
9923                            (cdr gnus-article-current))))))))
9924           ;; Update threads.
9925           (set-buffer (or buffer gnus-summary-buffer))
9926           (gnus-summary-update-article (cdr gnus-article-current))
9927           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9928               (gnus-summary-update-secondary-mark
9929                (cdr gnus-article-current))))
9930         ;; Prettify the article buffer again.
9931         (unless no-highlight
9932           (save-excursion
9933             (set-buffer gnus-article-buffer)
9934             ;;;!!! Fix this -- article should be rehighlighted.
9935             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9936             (set-buffer gnus-original-article-buffer)
9937             (gnus-request-article
9938              (cdr gnus-article-current)
9939              (car gnus-article-current) (current-buffer))))
9940         ;; Prettify the summary buffer line.
9941         (when (gnus-visual-p 'summary-highlight 'highlight)
9942           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9943
9944 (defun gnus-summary-edit-wash (key)
9945   "Perform editing command KEY in the article buffer."
9946   (interactive
9947    (list
9948     (progn
9949       (message "%s" (concat (this-command-keys) "- "))
9950       (read-char))))
9951   (message "")
9952   (gnus-summary-edit-article)
9953   (execute-kbd-macro (concat (this-command-keys) key))
9954   (gnus-article-edit-done))
9955
9956 ;;; Respooling
9957
9958 (defun gnus-summary-respool-query (&optional silent trace)
9959   "Query where the respool algorithm would put this article."
9960   (interactive)
9961   (let (gnus-mark-article-hook)
9962     (gnus-summary-select-article)
9963     (save-excursion
9964       (set-buffer gnus-original-article-buffer)
9965       (let ((groups (nnmail-article-group 'identity trace)))
9966         (unless silent
9967           (if groups
9968               (message "This message would go to %s"
9969                        (mapconcat 'car groups ", "))
9970             (message "This message would go to no groups"))
9971           groups)))))
9972
9973 (defun gnus-summary-respool-trace ()
9974   "Trace where the respool algorithm would put this article.
9975 Display a buffer showing all fancy splitting patterns which matched."
9976   (interactive)
9977   (gnus-summary-respool-query nil t))
9978
9979 ;; Summary marking commands.
9980
9981 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9982   "Mark articles which has the same subject as read, and then select the next.
9983 If UNMARK is positive, remove any kind of mark.
9984 If UNMARK is negative, tick articles."
9985   (interactive "P")
9986   (when unmark
9987     (setq unmark (prefix-numeric-value unmark)))
9988   (let ((count
9989          (gnus-summary-mark-same-subject
9990           (gnus-summary-article-subject) unmark)))
9991     ;; Select next unread article.  If auto-select-same mode, should
9992     ;; select the first unread article.
9993     (gnus-summary-next-article t (and gnus-auto-select-same
9994                                       (gnus-summary-article-subject)))
9995     (gnus-message 7 "%d article%s marked as %s"
9996                   count (if (= count 1) " is" "s are")
9997                   (if unmark "unread" "read"))))
9998
9999 (defun gnus-summary-kill-same-subject (&optional unmark)
10000   "Mark articles which has the same subject as read.
10001 If UNMARK is positive, remove any kind of mark.
10002 If UNMARK is negative, tick articles."
10003   (interactive "P")
10004   (when unmark
10005     (setq unmark (prefix-numeric-value unmark)))
10006   (let ((count
10007          (gnus-summary-mark-same-subject
10008           (gnus-summary-article-subject) unmark)))
10009     ;; If marked as read, go to next unread subject.
10010     (when (null unmark)
10011       ;; Go to next unread subject.
10012       (gnus-summary-next-subject 1 t))
10013     (gnus-message 7 "%d articles are marked as %s"
10014                   count (if unmark "unread" "read"))))
10015
10016 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10017   "Mark articles with same SUBJECT as read, and return marked number.
10018 If optional argument UNMARK is positive, remove any kinds of marks.
10019 If optional argument UNMARK is negative, mark articles as unread instead."
10020   (let ((count 1))
10021     (save-excursion
10022       (cond
10023        ((null unmark)                   ; Mark as read.
10024         (while (and
10025                 (progn
10026                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10027                   (gnus-summary-show-thread) t)
10028                 (gnus-summary-find-subject subject))
10029           (setq count (1+ count))))
10030        ((> unmark 0)                    ; Tick.
10031         (while (and
10032                 (progn
10033                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10034                   (gnus-summary-show-thread) t)
10035                 (gnus-summary-find-subject subject))
10036           (setq count (1+ count))))
10037        (t                               ; Mark as unread.
10038         (while (and
10039                 (progn
10040                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10041                   (gnus-summary-show-thread) t)
10042                 (gnus-summary-find-subject subject))
10043           (setq count (1+ count)))))
10044       (gnus-set-mode-line 'summary)
10045       ;; Return the number of marked articles.
10046       count)))
10047
10048 (defun gnus-summary-mark-as-processable (n &optional unmark)
10049   "Set the process mark on the next N articles.
10050 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10051 the process mark instead.  The difference between N and the actual
10052 number of articles marked is returned."
10053   (interactive "P")
10054   (if (and (null n) (gnus-region-active-p))
10055       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10056     (setq n (prefix-numeric-value n))
10057     (let ((backward (< n 0))
10058           (n (abs n)))
10059       (while (and
10060               (> n 0)
10061               (if unmark
10062                   (gnus-summary-remove-process-mark
10063                    (gnus-summary-article-number))
10064                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10065               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10066         (setq n (1- n)))
10067       (when (/= 0 n)
10068         (gnus-message 7 "No more articles"))
10069       (gnus-summary-recenter)
10070       (gnus-summary-position-point)
10071       n)))
10072
10073 (defun gnus-summary-unmark-as-processable (n)
10074   "Remove the process mark from the next N articles.
10075 If N is negative, unmark backward instead.  The difference between N and
10076 the actual number of articles unmarked is returned."
10077   (interactive "P")
10078   (gnus-summary-mark-as-processable n t))
10079
10080 (defun gnus-summary-unmark-all-processable ()
10081   "Remove the process mark from all articles."
10082   (interactive)
10083   (save-excursion
10084     (while gnus-newsgroup-processable
10085       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10086   (gnus-summary-position-point))
10087
10088 (defun gnus-summary-add-mark (article type)
10089   "Mark ARTICLE with a mark of TYPE."
10090   (let ((vtype (car (assq type gnus-article-mark-lists)))
10091         var)
10092     (if (not vtype)
10093         (error "No such mark type: %s" type)
10094       (setq var (intern (format "gnus-newsgroup-%s" type)))
10095       (set var (cons article (symbol-value var)))
10096       (if (memq type '(processable cached replied forwarded recent saved))
10097           (gnus-summary-update-secondary-mark article)
10098         ;;; !!! This is bogus.  We should find out what primary
10099         ;;; !!! mark we want to set.
10100         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10101
10102 (defun gnus-summary-mark-as-expirable (n)
10103   "Mark N articles forward as expirable.
10104 If N is negative, mark backward instead.  The difference between N and
10105 the actual number of articles marked is returned."
10106   (interactive "p")
10107   (gnus-summary-mark-forward n gnus-expirable-mark))
10108
10109 (defun gnus-summary-mark-as-spam (n)
10110   "Mark N articles forward as spam.
10111 If N is negative, mark backward instead.  The difference between N and
10112 the actual number of articles marked is returned."
10113   (interactive "p")
10114   (gnus-summary-mark-forward n gnus-spam-mark))
10115
10116 (defun gnus-summary-mark-article-as-replied (article)
10117   "Mark ARTICLE as replied to and update the summary line.
10118 ARTICLE can also be a list of articles."
10119   (interactive (list (gnus-summary-article-number)))
10120   (let ((articles (if (listp article) article (list article))))
10121     (dolist (article articles)
10122       (unless (numberp article)
10123         (error "%s is not a number" article))
10124       (push article gnus-newsgroup-replied)
10125       (let ((buffer-read-only nil))
10126         (when (gnus-summary-goto-subject article nil t)
10127           (gnus-summary-update-secondary-mark article))))))
10128
10129 (defun gnus-summary-mark-article-as-forwarded (article)
10130   "Mark ARTICLE as forwarded and update the summary line.
10131 ARTICLE can also be a list of articles."
10132   (let ((articles (if (listp article) article (list article))))
10133     (dolist (article articles)
10134       (push article gnus-newsgroup-forwarded)
10135       (let ((buffer-read-only nil))
10136         (when (gnus-summary-goto-subject article nil t)
10137           (gnus-summary-update-secondary-mark article))))))
10138
10139 (defun gnus-summary-set-bookmark (article)
10140   "Set a bookmark in current article."
10141   (interactive (list (gnus-summary-article-number)))
10142   (when (or (not (get-buffer gnus-article-buffer))
10143             (not gnus-current-article)
10144             (not gnus-article-current)
10145             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10146     (error "No current article selected"))
10147   ;; Remove old bookmark, if one exists.
10148   (gnus-pull article gnus-newsgroup-bookmarks)
10149   ;; Set the new bookmark, which is on the form
10150   ;; (article-number . line-number-in-body).
10151   (push
10152    (cons article
10153          (with-current-buffer gnus-article-buffer
10154            (count-lines
10155             (min (point)
10156                  (save-excursion
10157                    (article-goto-body)
10158                    (point)))
10159             (point))))
10160    gnus-newsgroup-bookmarks)
10161   (gnus-message 6 "A bookmark has been added to the current article."))
10162
10163 (defun gnus-summary-remove-bookmark (article)
10164   "Remove the bookmark from the current article."
10165   (interactive (list (gnus-summary-article-number)))
10166   ;; Remove old bookmark, if one exists.
10167   (if (not (assq article gnus-newsgroup-bookmarks))
10168       (gnus-message 6 "No bookmark in current article.")
10169     (gnus-pull article gnus-newsgroup-bookmarks)
10170     (gnus-message 6 "Removed bookmark.")))
10171
10172 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10173 (defun gnus-summary-mark-as-dormant (n)
10174   "Mark N articles forward as dormant.
10175 If N is negative, mark backward instead.  The difference between N and
10176 the actual number of articles marked is returned."
10177   (interactive "p")
10178   (gnus-summary-mark-forward n gnus-dormant-mark))
10179
10180 (defun gnus-summary-set-process-mark (article)
10181   "Set the process mark on ARTICLE and update the summary line."
10182   (setq gnus-newsgroup-processable
10183         (cons article
10184               (delq article gnus-newsgroup-processable)))
10185   (when (gnus-summary-goto-subject article)
10186     (gnus-summary-show-thread)
10187     (gnus-summary-goto-subject article)
10188     (gnus-summary-update-secondary-mark article)))
10189
10190 (defun gnus-summary-remove-process-mark (&rest articles)
10191   "Remove the process mark from ARTICLES and update the summary line."
10192   (dolist (article articles)
10193     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10194     (when (gnus-summary-goto-subject article)
10195       (gnus-summary-show-thread)
10196       (gnus-summary-goto-subject article)
10197       (gnus-summary-update-secondary-mark article)))
10198   t)
10199
10200 (defun gnus-summary-set-saved-mark (article)
10201   "Set the process mark on ARTICLE and update the summary line."
10202   (push article gnus-newsgroup-saved)
10203   (when (gnus-summary-goto-subject article)
10204     (gnus-summary-update-secondary-mark article)))
10205
10206 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10207   "Mark N articles as read forwards.
10208 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10209 The difference between N and the actual number of articles marked is
10210 returned.
10211 If NO-EXPIRE, auto-expiry will be inhibited."
10212   (interactive "p")
10213   (gnus-summary-show-thread)
10214   (let ((backward (< n 0))
10215         (gnus-summary-goto-unread
10216          (and gnus-summary-goto-unread
10217               (not (eq gnus-summary-goto-unread 'never))
10218               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10219                                     gnus-ticked-mark gnus-dormant-mark)))))
10220         (n (abs n))
10221         (mark (or mark gnus-del-mark)))
10222     (while (and (> n 0)
10223                 (gnus-summary-mark-article nil mark no-expire)
10224                 (zerop (gnus-summary-next-subject
10225                         (if backward -1 1)
10226                         (and gnus-summary-goto-unread
10227                              (not (eq gnus-summary-goto-unread 'never)))
10228                         t)))
10229       (setq n (1- n)))
10230     (when (/= 0 n)
10231       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10232     (gnus-summary-recenter)
10233     (gnus-summary-position-point)
10234     (gnus-set-mode-line 'summary)
10235     n))
10236
10237 (defun gnus-summary-mark-article-as-read (mark)
10238   "Mark the current article quickly as read with MARK."
10239   (let ((article (gnus-summary-article-number)))
10240     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10241     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10242     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10243     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10244     (push (cons article mark) gnus-newsgroup-reads)
10245     ;; Possibly remove from cache, if that is used.
10246     (when gnus-use-cache
10247       (gnus-cache-enter-remove-article article))
10248     ;; Allow the backend to change the mark.
10249     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10250     ;; Check for auto-expiry.
10251     (when (and gnus-newsgroup-auto-expire
10252                (memq mark gnus-auto-expirable-marks))
10253       (setq mark gnus-expirable-mark)
10254       ;; Let the backend know about the mark change.
10255       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10256       (push article gnus-newsgroup-expirable))
10257     ;; Set the mark in the buffer.
10258     (gnus-summary-update-mark mark 'unread)
10259     t))
10260
10261 (defun gnus-summary-mark-article-as-unread (mark)
10262   "Mark the current article quickly as unread with MARK."
10263   (let* ((article (gnus-summary-article-number))
10264          (old-mark (gnus-summary-article-mark article)))
10265     ;; Allow the backend to change the mark.
10266     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10267     (if (eq mark old-mark)
10268         t
10269       (if (<= article 0)
10270           (progn
10271             (gnus-error 1 "Can't mark negative article numbers")
10272             nil)
10273         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10274         (setq gnus-newsgroup-spam-marked
10275               (delq article gnus-newsgroup-spam-marked))
10276         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10277         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10278         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10279         (cond ((= mark gnus-ticked-mark)
10280                (setq gnus-newsgroup-marked
10281                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10282                                               article)))
10283               ((= mark gnus-spam-mark)
10284                (setq gnus-newsgroup-spam-marked
10285                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10286                                               article)))
10287               ((= mark gnus-dormant-mark)
10288                (setq gnus-newsgroup-dormant
10289                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10290                                               article)))
10291               (t
10292                (setq gnus-newsgroup-unreads
10293                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10294                                               article))))
10295         (gnus-pull article gnus-newsgroup-reads)
10296
10297         ;; See whether the article is to be put in the cache.
10298         (and gnus-use-cache
10299              (vectorp (gnus-summary-article-header article))
10300              (save-excursion
10301                (gnus-cache-possibly-enter-article
10302                 gnus-newsgroup-name article
10303                 (= mark gnus-ticked-mark)
10304                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10305
10306         ;; Fix the mark.
10307         (gnus-summary-update-mark mark 'unread)
10308         t))))
10309
10310 (defun gnus-summary-mark-article (&optional article mark no-expire)
10311   "Mark ARTICLE with MARK.  MARK can be any character.
10312 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10313 `??' (dormant) and `?E' (expirable).
10314 If MARK is nil, then the default character `?r' is used.
10315 If ARTICLE is nil, then the article on the current line will be
10316 marked.
10317 If NO-EXPIRE, auto-expiry will be inhibited."
10318   ;; The mark might be a string.
10319   (when (stringp mark)
10320     (setq mark (aref mark 0)))
10321   ;; If no mark is given, then we check auto-expiring.
10322   (when (null mark)
10323     (setq mark gnus-del-mark))
10324   (when (and (not no-expire)
10325              gnus-newsgroup-auto-expire
10326              (memq mark gnus-auto-expirable-marks))
10327     (setq mark gnus-expirable-mark))
10328   (let ((article (or article (gnus-summary-article-number)))
10329         (old-mark (gnus-summary-article-mark article)))
10330     ;; Allow the backend to change the mark.
10331     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10332     (if (eq mark old-mark)
10333         t
10334       (unless article
10335         (error "No article on current line"))
10336       (if (not (if (or (= mark gnus-unread-mark)
10337                        (= mark gnus-ticked-mark)
10338                        (= mark gnus-spam-mark)
10339                        (= mark gnus-dormant-mark))
10340                    (gnus-mark-article-as-unread article mark)
10341                  (gnus-mark-article-as-read article mark)))
10342           t
10343         ;; See whether the article is to be put in the cache.
10344         (and gnus-use-cache
10345              (not (= mark gnus-canceled-mark))
10346              (vectorp (gnus-summary-article-header article))
10347              (save-excursion
10348                (gnus-cache-possibly-enter-article
10349                 gnus-newsgroup-name article
10350                 (= mark gnus-ticked-mark)
10351                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10352
10353         (when (gnus-summary-goto-subject article nil t)
10354           (let ((buffer-read-only nil))
10355             (gnus-summary-show-thread)
10356             ;; Fix the mark.
10357             (gnus-summary-update-mark mark 'unread)
10358             t))))))
10359
10360 (defun gnus-summary-update-secondary-mark (article)
10361   "Update the secondary (read, process, cache) mark."
10362   (gnus-summary-update-mark
10363    (cond ((memq article gnus-newsgroup-processable)
10364           gnus-process-mark)
10365          ((memq article gnus-newsgroup-cached)
10366           gnus-cached-mark)
10367          ((memq article gnus-newsgroup-replied)
10368           gnus-replied-mark)
10369          ((memq article gnus-newsgroup-forwarded)
10370           gnus-forwarded-mark)
10371          ((memq article gnus-newsgroup-saved)
10372           gnus-saved-mark)
10373          ((memq article gnus-newsgroup-recent)
10374           gnus-recent-mark)
10375          ((memq article gnus-newsgroup-unseen)
10376           gnus-unseen-mark)
10377          (t gnus-no-mark))
10378    'replied)
10379   (when (gnus-visual-p 'summary-highlight 'highlight)
10380     (gnus-run-hooks 'gnus-summary-update-hook))
10381   t)
10382
10383 (defun gnus-summary-update-download-mark (article)
10384   "Update the download mark."
10385   (gnus-summary-update-mark
10386    (cond ((memq article gnus-newsgroup-undownloaded)
10387           gnus-undownloaded-mark)
10388          (gnus-newsgroup-agentized
10389           gnus-downloaded-mark)
10390          (t
10391           gnus-no-mark))
10392    'download)
10393   (gnus-summary-update-line t)
10394   t)
10395
10396 (defun gnus-summary-update-mark (mark type)
10397   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10398         (buffer-read-only nil))
10399     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10400     (when forward
10401       (when (looking-at "\r")
10402         (incf forward))
10403       (when (<= (+ forward (point)) (point-max))
10404         ;; Go to the right position on the line.
10405         (goto-char (+ forward (point)))
10406         ;; Replace the old mark with the new mark.
10407         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10408         ;; Optionally update the marks by some user rule.
10409         (when (eq type 'unread)
10410           (gnus-data-set-mark
10411            (gnus-data-find (gnus-summary-article-number)) mark)
10412           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10413
10414 (defun gnus-mark-article-as-read (article &optional mark)
10415   "Enter ARTICLE in the pertinent lists and remove it from others."
10416   ;; Make the article expirable.
10417   (let ((mark (or mark gnus-del-mark)))
10418     (setq gnus-newsgroup-expirable
10419           (if (= mark gnus-expirable-mark)
10420               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10421             (delq article gnus-newsgroup-expirable)))
10422     ;; Remove from unread and marked lists.
10423     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10424     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10425     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10426     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10427     (push (cons article mark) gnus-newsgroup-reads)
10428     ;; Possibly remove from cache, if that is used.
10429     (when gnus-use-cache
10430       (gnus-cache-enter-remove-article article))
10431     t))
10432
10433 (defun gnus-mark-article-as-unread (article &optional mark)
10434   "Enter ARTICLE in the pertinent lists and remove it from others."
10435   (let ((mark (or mark gnus-ticked-mark)))
10436     (if (<= article 0)
10437         (progn
10438           (gnus-error 1 "Can't mark negative article numbers")
10439           nil)
10440       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10441             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10442             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10443             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10444             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10445
10446       ;; Unsuppress duplicates?
10447       (when gnus-suppress-duplicates
10448         (gnus-dup-unsuppress-article article))
10449
10450       (cond ((= mark gnus-ticked-mark)
10451              (setq gnus-newsgroup-marked
10452                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10453             ((= mark gnus-spam-mark)
10454              (setq gnus-newsgroup-spam-marked
10455                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10456                                             article)))
10457             ((= mark gnus-dormant-mark)
10458              (setq gnus-newsgroup-dormant
10459                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10460             (t
10461              (setq gnus-newsgroup-unreads
10462                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10463       (gnus-pull article gnus-newsgroup-reads)
10464       t)))
10465
10466 (defalias 'gnus-summary-mark-as-unread-forward
10467   'gnus-summary-tick-article-forward)
10468 (make-obsolete 'gnus-summary-mark-as-unread-forward
10469                'gnus-summary-tick-article-forward)
10470 (defun gnus-summary-tick-article-forward (n)
10471   "Tick N articles forwards.
10472 If N is negative, tick backwards instead.
10473 The difference between N and the number of articles ticked is returned."
10474   (interactive "p")
10475   (gnus-summary-mark-forward n gnus-ticked-mark))
10476
10477 (defalias 'gnus-summary-mark-as-unread-backward
10478   'gnus-summary-tick-article-backward)
10479 (make-obsolete 'gnus-summary-mark-as-unread-backward
10480                'gnus-summary-tick-article-backward)
10481 (defun gnus-summary-tick-article-backward (n)
10482   "Tick N articles backwards.
10483 The difference between N and the number of articles ticked is returned."
10484   (interactive "p")
10485   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10486
10487 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10488 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10489 (defun gnus-summary-tick-article (&optional article clear-mark)
10490   "Mark current article as unread.
10491 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10492 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10493   (interactive)
10494   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10495                                        gnus-ticked-mark)))
10496
10497 (defun gnus-summary-mark-as-read-forward (n)
10498   "Mark N articles as read forwards.
10499 If N is negative, mark backwards instead.
10500 The difference between N and the actual number of articles marked is
10501 returned."
10502   (interactive "p")
10503   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10504
10505 (defun gnus-summary-mark-as-read-backward (n)
10506   "Mark the N articles as read backwards.
10507 The difference between N and the actual number of articles marked is
10508 returned."
10509   (interactive "p")
10510   (gnus-summary-mark-forward
10511    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10512
10513 (defun gnus-summary-mark-as-read (&optional article mark)
10514   "Mark current article as read.
10515 ARTICLE specifies the article to be marked as read.
10516 MARK specifies a string to be inserted at the beginning of the line."
10517   (gnus-summary-mark-article article mark))
10518
10519 (defun gnus-summary-clear-mark-forward (n)
10520   "Clear marks from N articles forward.
10521 If N is negative, clear backward instead.
10522 The difference between N and the number of marks cleared is returned."
10523   (interactive "p")
10524   (gnus-summary-mark-forward n gnus-unread-mark))
10525
10526 (defun gnus-summary-clear-mark-backward (n)
10527   "Clear marks from N articles backward.
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-mark-unread-as-read ()
10533   "Intended to be used by `gnus-summary-mark-article-hook'."
10534   (when (memq gnus-current-article gnus-newsgroup-unreads)
10535     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10536
10537 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10538   "Intended to be used by `gnus-summary-mark-article-hook'."
10539   (let ((mark (gnus-summary-article-mark)))
10540     (when (or (gnus-unread-mark-p mark)
10541               (gnus-read-mark-p mark))
10542       (gnus-summary-mark-article gnus-current-article
10543                                  (or new-mark gnus-read-mark)))))
10544
10545 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10546   "Intended to be used by `gnus-summary-mark-article-hook'."
10547   (let ((mark (gnus-summary-article-mark)))
10548     (when (or (gnus-unread-mark-p mark)
10549               (gnus-read-mark-p mark))
10550       (gnus-summary-mark-article (gnus-summary-article-number)
10551                                  (or new-mark gnus-read-mark)))))
10552
10553 (defun gnus-summary-mark-unread-as-ticked ()
10554   "Intended to be used by `gnus-summary-mark-article-hook'."
10555   (when (memq gnus-current-article gnus-newsgroup-unreads)
10556     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10557
10558 (defun gnus-summary-mark-region-as-read (point mark all)
10559   "Mark all unread articles between point and mark as read.
10560 If given a prefix, mark all articles between point and mark as read,
10561 even ticked and dormant ones."
10562   (interactive "r\nP")
10563   (save-excursion
10564     (let (article)
10565       (goto-char point)
10566       (beginning-of-line)
10567       (while (and
10568               (< (point) mark)
10569               (progn
10570                 (when (or all
10571                           (memq (setq article (gnus-summary-article-number))
10572                                 gnus-newsgroup-unreads))
10573                   (gnus-summary-mark-article article gnus-del-mark))
10574                 t)
10575               (gnus-summary-find-next))))))
10576
10577 (defun gnus-summary-mark-below (score mark)
10578   "Mark articles with score less than SCORE with MARK."
10579   (interactive "P\ncMark: ")
10580   (setq score (if score
10581                   (prefix-numeric-value score)
10582                 (or gnus-summary-default-score 0)))
10583   (save-excursion
10584     (set-buffer gnus-summary-buffer)
10585     (goto-char (point-min))
10586     (while
10587         (progn
10588           (and (< (gnus-summary-article-score) score)
10589                (gnus-summary-mark-article nil mark))
10590           (gnus-summary-find-next)))))
10591
10592 (defun gnus-summary-kill-below (&optional score)
10593   "Mark articles with score below SCORE as read."
10594   (interactive "P")
10595   (gnus-summary-mark-below score gnus-killed-mark))
10596
10597 (defun gnus-summary-clear-above (&optional score)
10598   "Clear all marks from articles with score above SCORE."
10599   (interactive "P")
10600   (gnus-summary-mark-above score gnus-unread-mark))
10601
10602 (defun gnus-summary-tick-above (&optional score)
10603   "Tick all articles with score above SCORE."
10604   (interactive "P")
10605   (gnus-summary-mark-above score gnus-ticked-mark))
10606
10607 (defun gnus-summary-mark-above (score mark)
10608   "Mark articles with score over SCORE with MARK."
10609   (interactive "P\ncMark: ")
10610   (setq score (if score
10611                   (prefix-numeric-value score)
10612                 (or gnus-summary-default-score 0)))
10613   (save-excursion
10614     (set-buffer gnus-summary-buffer)
10615     (goto-char (point-min))
10616     (while (and (progn
10617                   (when (> (gnus-summary-article-score) score)
10618                     (gnus-summary-mark-article nil mark))
10619                   t)
10620                 (gnus-summary-find-next)))))
10621
10622 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10623 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10624 (defun gnus-summary-limit-include-expunged (&optional no-error)
10625   "Display all the hidden articles that were expunged for low scores."
10626   (interactive)
10627   (let ((buffer-read-only nil))
10628     (let ((scored gnus-newsgroup-scored)
10629           headers h)
10630       (while scored
10631         (unless (gnus-summary-article-header (caar scored))
10632           (and (setq h (gnus-number-to-header (caar scored)))
10633                (< (cdar scored) gnus-summary-expunge-below)
10634                (push h headers)))
10635         (setq scored (cdr scored)))
10636       (if (not headers)
10637           (when (not no-error)
10638             (error "No expunged articles hidden"))
10639         (goto-char (point-min))
10640         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10641         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10642         (mapcar (lambda (x) (push (mail-header-number x)
10643                                   gnus-newsgroup-limit))
10644                 headers)
10645         (gnus-summary-prepare-unthreaded (nreverse headers))
10646         (goto-char (point-min))
10647         (gnus-summary-position-point)
10648         t))))
10649
10650 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10651   "Mark all unread articles in this newsgroup as read.
10652 If prefix argument ALL is non-nil, ticked and dormant articles will
10653 also be marked as read.
10654 If QUIETLY is non-nil, no questions will be asked.
10655
10656 If TO-HERE is non-nil, it should be a point in the buffer.  All
10657 articles before (after, if REVERSE is set) this point will be marked
10658 as read.
10659
10660 Note that this function will only catch up the unread article
10661 in the current summary buffer limitation.
10662
10663 The number of articles marked as read is returned."
10664   (interactive "P")
10665   (prog1
10666       (save-excursion
10667         (when (or quietly
10668                   (not gnus-interactive-catchup) ;Without confirmation?
10669                   gnus-expert-user
10670                   (gnus-y-or-n-p
10671                    (if all
10672                        "Mark absolutely all articles as read? "
10673                      "Mark all unread articles as read? ")))
10674           (if (and not-mark
10675                    (not gnus-newsgroup-adaptive)
10676                    (not gnus-newsgroup-auto-expire)
10677                    (not gnus-suppress-duplicates)
10678                    (or (not gnus-use-cache)
10679                        (eq gnus-use-cache 'passive)))
10680               (progn
10681                 (when all
10682                   (setq gnus-newsgroup-marked nil
10683                         gnus-newsgroup-spam-marked nil
10684                         gnus-newsgroup-dormant nil))
10685                 (setq gnus-newsgroup-unreads
10686                       (gnus-sorted-nunion
10687                        (gnus-intersection gnus-newsgroup-unreads
10688                                           gnus-newsgroup-downloadable)
10689                        gnus-newsgroup-unfetched)))
10690             ;; We actually mark all articles as canceled, which we
10691             ;; have to do when using auto-expiry or adaptive scoring.
10692             (gnus-summary-show-all-threads)
10693             (if (and to-here reverse)
10694                 (progn
10695                   (goto-char to-here)
10696                   (gnus-summary-mark-current-read-and-unread-as-read
10697                    gnus-catchup-mark)
10698                   (while (gnus-summary-find-next (not all))
10699                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10700               (when (gnus-summary-first-subject (not all))
10701                 (while (and
10702                         (if to-here (< (point) to-here) t)
10703                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10704                         (gnus-summary-find-next (not all))))))
10705             (gnus-set-mode-line 'summary))
10706           t))
10707     (gnus-summary-position-point)))
10708
10709 (defun gnus-summary-catchup-to-here (&optional all)
10710   "Mark all unticked articles before the current one as read.
10711 If ALL is non-nil, also mark ticked and dormant articles as read."
10712   (interactive "P")
10713   (save-excursion
10714     (gnus-save-hidden-threads
10715       (let ((beg (point)))
10716         ;; We check that there are unread articles.
10717         (when (or all (gnus-summary-find-prev))
10718           (gnus-summary-catchup all t beg)))))
10719   (gnus-summary-position-point))
10720
10721 (defun gnus-summary-catchup-from-here (&optional all)
10722   "Mark all unticked articles after (and including) the current one as read.
10723 If ALL is non-nil, also mark ticked and dormant articles as read."
10724   (interactive "P")
10725   (save-excursion
10726     (gnus-save-hidden-threads
10727       (let ((beg (point)))
10728         ;; We check that there are unread articles.
10729         (when (or all (gnus-summary-find-next))
10730           (gnus-summary-catchup all t beg nil t)))))
10731   (gnus-summary-position-point))
10732
10733 (defun gnus-summary-catchup-all (&optional quietly)
10734   "Mark all articles in this newsgroup as read.
10735 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10736 instead, which marks only unread articles as read."
10737   (interactive "P")
10738   (gnus-summary-catchup t quietly))
10739
10740 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10741   "Mark all unread articles in this group as read, then exit.
10742 If prefix argument ALL is non-nil, all articles are marked as read.
10743 If QUIETLY is non-nil, no questions will be asked."
10744   (interactive "P")
10745   (when (gnus-summary-catchup all quietly nil 'fast)
10746     ;; Select next newsgroup or exit.
10747     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10748              (eq gnus-auto-select-next 'quietly))
10749         (gnus-summary-next-group nil)
10750       (gnus-summary-exit))))
10751
10752 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10753   "Mark all articles in this newsgroup as read, and then exit.
10754 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10755 instead, which marks only unread articles as read."
10756   (interactive "P")
10757   (gnus-summary-catchup-and-exit t quietly))
10758
10759 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10760   "Mark all articles in this group as read and select the next group.
10761 If given a prefix, mark all articles, unread as well as ticked, as
10762 read."
10763   (interactive "P")
10764   (save-excursion
10765     (gnus-summary-catchup all))
10766   (gnus-summary-next-group))
10767
10768 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10769   "Mark all articles in this group as read and select the previous group.
10770 If given a prefix, mark all articles, unread as well as ticked, as
10771 read."
10772   (interactive "P")
10773   (save-excursion
10774     (gnus-summary-catchup all))
10775   (gnus-summary-next-group nil nil t))
10776
10777 ;;;
10778 ;;; with article
10779 ;;;
10780
10781 (defmacro gnus-with-article (article &rest forms)
10782   "Select ARTICLE and perform FORMS in the original article buffer.
10783 Then replace the article with the result."
10784   `(progn
10785      ;; We don't want the article to be marked as read.
10786      (let (gnus-mark-article-hook)
10787        (gnus-summary-select-article t t nil ,article))
10788      (set-buffer gnus-original-article-buffer)
10789      ,@forms
10790      (if (not (gnus-check-backend-function
10791                'request-replace-article (car gnus-article-current)))
10792          (gnus-message 5 "Read-only group; not replacing")
10793        (unless (gnus-request-replace-article
10794                 ,article (car gnus-article-current)
10795                 (current-buffer) t)
10796          (error "Couldn't replace article")))
10797      ;; The cache and backlog have to be flushed somewhat.
10798      (when gnus-keep-backlog
10799        (gnus-backlog-remove-article
10800         (car gnus-article-current) (cdr gnus-article-current)))
10801      (when gnus-use-cache
10802        (gnus-cache-update-article
10803         (car gnus-article-current) (cdr gnus-article-current)))))
10804
10805 (put 'gnus-with-article 'lisp-indent-function 1)
10806 (put 'gnus-with-article 'edebug-form-spec '(form body))
10807
10808 ;; Thread-based commands.
10809
10810 (defun gnus-summary-articles-in-thread (&optional article)
10811   "Return a list of all articles in the current thread.
10812 If ARTICLE is non-nil, return all articles in the thread that starts
10813 with that article."
10814   (let* ((article (or article (gnus-summary-article-number)))
10815          (data (gnus-data-find-list article))
10816          (top-level (gnus-data-level (car data)))
10817          (top-subject
10818           (cond ((null gnus-thread-operation-ignore-subject)
10819                  (gnus-simplify-subject-re
10820                   (mail-header-subject (gnus-data-header (car data)))))
10821                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10822                  (gnus-simplify-subject-fuzzy
10823                   (mail-header-subject (gnus-data-header (car data)))))
10824                 (t nil)))
10825          (end-point (save-excursion
10826                       (if (gnus-summary-go-to-next-thread)
10827                           (point) (point-max))))
10828          articles)
10829     (while (and data
10830                 (< (gnus-data-pos (car data)) end-point))
10831       (when (or (not top-subject)
10832                 (string= top-subject
10833                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10834                              (gnus-simplify-subject-fuzzy
10835                               (mail-header-subject
10836                                (gnus-data-header (car data))))
10837                            (gnus-simplify-subject-re
10838                             (mail-header-subject
10839                              (gnus-data-header (car data)))))))
10840         (push (gnus-data-number (car data)) articles))
10841       (unless (and (setq data (cdr data))
10842                    (> (gnus-data-level (car data)) top-level))
10843         (setq data nil)))
10844     ;; Return the list of articles.
10845     (nreverse articles)))
10846
10847 (defun gnus-summary-rethread-current ()
10848   "Rethread the thread the current article is part of."
10849   (interactive)
10850   (let* ((gnus-show-threads t)
10851          (article (gnus-summary-article-number))
10852          (id (mail-header-id (gnus-summary-article-header)))
10853          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10854     (unless id
10855       (error "No article on the current line"))
10856     (gnus-rebuild-thread id)
10857     (gnus-summary-goto-subject article)))
10858
10859 (defun gnus-summary-reparent-thread ()
10860   "Make the current article child of the marked (or previous) article.
10861
10862 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10863 is non-nil or the Subject: of both articles are the same."
10864   (interactive)
10865   (unless (not (gnus-group-read-only-p))
10866     (error "The current newsgroup does not support article editing"))
10867   (unless (<= (length gnus-newsgroup-processable) 1)
10868     (error "No more than one article may be marked"))
10869   (let ((child (gnus-summary-article-number))
10870         ;; First grab the marked article, otherwise one line up.
10871         (parent (if (not (null gnus-newsgroup-processable))
10872                     (car gnus-newsgroup-processable)
10873                   (save-excursion
10874                     (if (eq (forward-line -1) 0)
10875                         (gnus-summary-article-number)
10876                       (error "Beginning of summary buffer"))))))
10877     (gnus-summary-reparent-children parent (list child))))
10878
10879 (defun gnus-summary-reparent-children (parent children)
10880   "Make PARENT the parent of CHILDREN.
10881 When called interactively, PARENT is is current article and
10882 CHILDREN are the process-marked articles."
10883   (interactive
10884    (list (gnus-summary-article-number)
10885          (gnus-summary-work-articles nil)))
10886   (dolist (child children)
10887     (save-window-excursion
10888       (let ((gnus-article-buffer " *reparent*"))
10889         (unless (not (eq parent child))
10890           (error "An article may not be self-referential"))
10891         (let ((message-id (mail-header-id
10892                            (gnus-summary-article-header parent))))
10893           (unless (and message-id (not (equal message-id "")))
10894             (error "No message-id in desired parent"))
10895           (gnus-with-article child
10896             (save-restriction
10897               (goto-char (point-min))
10898               (message-narrow-to-head)
10899               (if (re-search-forward "^References: " nil t)
10900                   (progn
10901                     (re-search-forward "^[^ \t]" nil t)
10902                     (forward-line -1)
10903                     (end-of-line)
10904                     (insert " " message-id))
10905                 (insert "References: " message-id "\n"))))
10906           (set-buffer gnus-summary-buffer)
10907           (gnus-summary-unmark-all-processable)
10908           (gnus-summary-update-article child)
10909           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10910             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10911           (gnus-summary-rethread-current)
10912           (gnus-message 3 "Article %d is now the child of article %d"
10913                         child parent))))))
10914
10915 (defun gnus-summary-toggle-threads (&optional arg)
10916   "Toggle showing conversation threads.
10917 If ARG is positive number, turn showing conversation threads on."
10918   (interactive "P")
10919   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10920     (setq gnus-show-threads
10921           (if (null arg) (not gnus-show-threads)
10922             (> (prefix-numeric-value arg) 0)))
10923     (gnus-summary-prepare)
10924     (gnus-summary-goto-subject current)
10925     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10926     (gnus-summary-position-point)))
10927
10928 (defun gnus-summary-show-all-threads ()
10929   "Show all threads."
10930   (interactive)
10931   (save-excursion
10932     (let ((buffer-read-only nil))
10933       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10934   (gnus-summary-position-point))
10935
10936 (defun gnus-summary-show-thread ()
10937   "Show thread subtrees.
10938 Returns nil if no thread was there to be shown."
10939   (interactive)
10940   (let ((buffer-read-only nil)
10941         (orig (point))
10942         (end (point-at-eol))
10943         ;; Leave point at bol
10944         (beg (progn (beginning-of-line) (point))))
10945     (prog1
10946         ;; Any hidden lines here?
10947         (search-forward "\r" end t)
10948       (subst-char-in-region beg end ?\^M ?\n t)
10949       (goto-char orig)
10950       (gnus-summary-position-point))))
10951
10952 (defun gnus-summary-maybe-hide-threads ()
10953   "If requested, hide the threads that should be hidden."
10954   (when (and gnus-show-threads
10955              gnus-thread-hide-subtree)
10956     (gnus-summary-hide-all-threads
10957      (if (or (consp gnus-thread-hide-subtree)
10958              (functionp gnus-thread-hide-subtree))
10959          (gnus-make-predicate gnus-thread-hide-subtree)
10960        nil))))
10961
10962 ;;; Hiding predicates.
10963
10964 (defun gnus-article-unread-p (header)
10965   (memq (mail-header-number header) gnus-newsgroup-unreads))
10966
10967 (defun gnus-article-unseen-p (header)
10968   (memq (mail-header-number header) gnus-newsgroup-unseen))
10969
10970 (defun gnus-map-articles (predicate articles)
10971   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10972   (apply 'gnus-or (mapcar predicate
10973                           (mapcar (lambda (number)
10974                                     (gnus-summary-article-header number))
10975                                   articles))))
10976
10977 (defun gnus-summary-hide-all-threads (&optional predicate)
10978   "Hide all thread subtrees.
10979 If PREDICATE is supplied, threads that satisfy this predicate
10980 will not be hidden."
10981   (interactive)
10982   (save-excursion
10983     (goto-char (point-min))
10984     (let ((end nil))
10985       (while (not end)
10986         (when (or (not predicate)
10987                   (gnus-map-articles
10988                    predicate (gnus-summary-article-children)))
10989             (gnus-summary-hide-thread))
10990         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10991   (gnus-summary-position-point))
10992
10993 (defun gnus-summary-hide-thread ()
10994   "Hide thread subtrees.
10995 If PREDICATE is supplied, threads that satisfy this predicate
10996 will not be hidden.
10997 Returns nil if no threads were there to be hidden."
10998   (interactive)
10999   (let ((buffer-read-only nil)
11000         (start (point))
11001         (article (gnus-summary-article-number)))
11002     (goto-char start)
11003     ;; Go forward until either the buffer ends or the subthread
11004     ;; ends.
11005     (when (and (not (eobp))
11006                (or (zerop (gnus-summary-next-thread 1 t))
11007                    (goto-char (point-max))))
11008       (prog1
11009           (if (and (> (point) start)
11010                    (search-backward "\n" start t))
11011               (progn
11012                 (subst-char-in-region start (point) ?\n ?\^M)
11013                 (gnus-summary-goto-subject article))
11014             (goto-char start)
11015             nil)))))
11016
11017 (defun gnus-summary-go-to-next-thread (&optional previous)
11018   "Go to the same level (or less) next thread.
11019 If PREVIOUS is non-nil, go to previous thread instead.
11020 Return the article number moved to, or nil if moving was impossible."
11021   (let ((level (gnus-summary-thread-level))
11022         (way (if previous -1 1))
11023         (beg (point)))
11024     (forward-line way)
11025     (while (and (not (eobp))
11026                 (< level (gnus-summary-thread-level)))
11027       (forward-line way))
11028     (if (eobp)
11029         (progn
11030           (goto-char beg)
11031           nil)
11032       (setq beg (point))
11033       (prog1
11034           (gnus-summary-article-number)
11035         (goto-char beg)))))
11036
11037 (defun gnus-summary-next-thread (n &optional silent)
11038   "Go to the same level next N'th thread.
11039 If N is negative, search backward instead.
11040 Returns the difference between N and the number of skips actually
11041 done.
11042
11043 If SILENT, don't output messages."
11044   (interactive "p")
11045   (let ((backward (< n 0))
11046         (n (abs n)))
11047     (while (and (> n 0)
11048                 (gnus-summary-go-to-next-thread backward))
11049       (decf n))
11050     (unless silent
11051       (gnus-summary-position-point))
11052     (when (and (not silent) (/= 0 n))
11053       (gnus-message 7 "No more threads"))
11054     n))
11055
11056 (defun gnus-summary-prev-thread (n)
11057   "Go to the same level previous N'th thread.
11058 Returns the difference between N and the number of skips actually
11059 done."
11060   (interactive "p")
11061   (gnus-summary-next-thread (- n)))
11062
11063 (defun gnus-summary-go-down-thread ()
11064   "Go down one level in the current thread."
11065   (let ((children (gnus-summary-article-children)))
11066     (when children
11067       (gnus-summary-goto-subject (car children)))))
11068
11069 (defun gnus-summary-go-up-thread ()
11070   "Go up one level in the current thread."
11071   (let ((parent (gnus-summary-article-parent)))
11072     (when parent
11073       (gnus-summary-goto-subject parent))))
11074
11075 (defun gnus-summary-down-thread (n)
11076   "Go down thread N steps.
11077 If N is negative, go up instead.
11078 Returns the difference between N and how many steps down that were
11079 taken."
11080   (interactive "p")
11081   (let ((up (< n 0))
11082         (n (abs n)))
11083     (while (and (> n 0)
11084                 (if up (gnus-summary-go-up-thread)
11085                   (gnus-summary-go-down-thread)))
11086       (setq n (1- n)))
11087     (gnus-summary-position-point)
11088     (when (/= 0 n)
11089       (gnus-message 7 "Can't go further"))
11090     n))
11091
11092 (defun gnus-summary-up-thread (n)
11093   "Go up thread N steps.
11094 If N is negative, go down instead.
11095 Returns the difference between N and how many steps down that were
11096 taken."
11097   (interactive "p")
11098   (gnus-summary-down-thread (- n)))
11099
11100 (defun gnus-summary-top-thread ()
11101   "Go to the top of the thread."
11102   (interactive)
11103   (while (gnus-summary-go-up-thread))
11104   (gnus-summary-article-number))
11105
11106 (defun gnus-summary-kill-thread (&optional unmark)
11107   "Mark articles under current thread as read.
11108 If the prefix argument is positive, remove any kinds of marks.
11109 If the prefix argument is negative, tick articles instead."
11110   (interactive "P")
11111   (when unmark
11112     (setq unmark (prefix-numeric-value unmark)))
11113   (let ((articles (gnus-summary-articles-in-thread)))
11114     (save-excursion
11115       ;; Expand the thread.
11116       (gnus-summary-show-thread)
11117       ;; Mark all the articles.
11118       (while articles
11119         (gnus-summary-goto-subject (car articles))
11120         (cond ((null unmark)
11121                (gnus-summary-mark-article-as-read gnus-killed-mark))
11122               ((> unmark 0)
11123                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11124               (t
11125                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11126         (setq articles (cdr articles))))
11127     ;; Hide killed subtrees.
11128     (and (null unmark)
11129          gnus-thread-hide-killed
11130          (gnus-summary-hide-thread))
11131     ;; If marked as read, go to next unread subject.
11132     (when (null unmark)
11133       ;; Go to next unread subject.
11134       (gnus-summary-next-subject 1 t)))
11135   (gnus-set-mode-line 'summary))
11136
11137 ;; Summary sorting commands
11138
11139 (defun gnus-summary-sort-by-number (&optional reverse)
11140   "Sort the summary buffer by article number.
11141 Argument REVERSE means reverse order."
11142   (interactive "P")
11143   (gnus-summary-sort 'number reverse))
11144
11145 (defun gnus-summary-sort-by-random (&optional reverse)
11146   "Randomize the order in the summary buffer.
11147 Argument REVERSE means to randomize in reverse order."
11148   (interactive "P")
11149   (gnus-summary-sort 'random reverse))
11150
11151 (defun gnus-summary-sort-by-author (&optional reverse)
11152   "Sort the summary buffer by author name alphabetically.
11153 If `case-fold-search' is non-nil, case of letters is ignored.
11154 Argument REVERSE means reverse order."
11155   (interactive "P")
11156   (gnus-summary-sort 'author reverse))
11157
11158 (defun gnus-summary-sort-by-recipient (&optional reverse)
11159   "Sort the summary buffer by recipient name alphabetically.
11160 If `case-fold-search' is non-nil, case of letters is ignored.
11161 Argument REVERSE means reverse order."
11162   (interactive "P")
11163   (gnus-summary-sort 'recipient reverse))
11164
11165 (defun gnus-summary-sort-by-subject (&optional reverse)
11166   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11167 If `case-fold-search' is non-nil, case of letters is ignored.
11168 Argument REVERSE means reverse order."
11169   (interactive "P")
11170   (gnus-summary-sort 'subject reverse))
11171
11172 (defun gnus-summary-sort-by-date (&optional reverse)
11173   "Sort the summary buffer by date.
11174 Argument REVERSE means reverse order."
11175   (interactive "P")
11176   (gnus-summary-sort 'date reverse))
11177
11178 (defun gnus-summary-sort-by-score (&optional reverse)
11179   "Sort the summary buffer by score.
11180 Argument REVERSE means reverse order."
11181   (interactive "P")
11182   (gnus-summary-sort 'score reverse))
11183
11184 (defun gnus-summary-sort-by-lines (&optional reverse)
11185   "Sort the summary buffer by the number of lines.
11186 Argument REVERSE means reverse order."
11187   (interactive "P")
11188   (gnus-summary-sort 'lines reverse))
11189
11190 (defun gnus-summary-sort-by-chars (&optional reverse)
11191   "Sort the summary buffer by article length.
11192 Argument REVERSE means reverse order."
11193   (interactive "P")
11194   (gnus-summary-sort 'chars reverse))
11195
11196 (defun gnus-summary-sort-by-original (&optional reverse)
11197   "Sort the summary buffer using the default sorting method.
11198 Argument REVERSE means reverse order."
11199   (interactive "P")
11200   (let* ((buffer-read-only)
11201          (gnus-summary-prepare-hook nil))
11202     ;; We do the sorting by regenerating the threads.
11203     (gnus-summary-prepare)
11204     ;; Hide subthreads if needed.
11205     (gnus-summary-maybe-hide-threads)))
11206
11207 (defun gnus-summary-sort (predicate reverse)
11208   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11209   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11210          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11211          (gnus-thread-sort-functions
11212           (if (not reverse)
11213               thread
11214             `(lambda (t1 t2)
11215                (,thread t2 t1))))
11216          (gnus-sort-gathered-threads-function
11217           gnus-thread-sort-functions)
11218          (gnus-article-sort-functions
11219           (if (not reverse)
11220               article
11221             `(lambda (t1 t2)
11222                (,article t2 t1))))
11223          (buffer-read-only)
11224          (gnus-summary-prepare-hook nil))
11225     ;; We do the sorting by regenerating the threads.
11226     (gnus-summary-prepare)
11227     ;; Hide subthreads if needed.
11228     (gnus-summary-maybe-hide-threads)))
11229
11230 ;; Summary saving commands.
11231
11232 (defun gnus-summary-save-article (&optional n not-saved decode)
11233   "Save the current article using the default saver function.
11234 If N is a positive number, save the N next articles.
11235 If N is a negative number, save the N previous articles.
11236 If N is nil and any articles have been marked with the process mark,
11237 save those articles instead.
11238 The variable `gnus-default-article-saver' specifies the saver function.
11239
11240 If the optional second argument NOT-SAVED is non-nil, articles saved
11241 will not be marked as saved.  If the optional third argument DECODE is
11242 non-nil, articles will be decoded before saving."
11243   (interactive "P")
11244   (require 'gnus-art)
11245   (unless gnus-article-save-coding-system
11246     (setq decode nil))
11247   (let* ((articles (gnus-summary-work-articles n))
11248          (save-buffer (save-excursion
11249                         (nnheader-set-temp-buffer " *Gnus Save*")))
11250          (num (length articles))
11251          header file)
11252     (dolist (article articles)
11253       (setq header (gnus-summary-article-header article))
11254       (if (not (vectorp header))
11255           ;; This is a pseudo-article.
11256           (if (assq 'name header)
11257               (gnus-copy-file (cdr (assq 'name header)))
11258             (gnus-message 1 "Article %d is unsaveable" article))
11259         ;; This is a real article.
11260         (save-window-excursion
11261           (let ((gnus-display-mime-function (when decode
11262                                               gnus-display-mime-function))
11263                 (gnus-article-prepare-hook (when decode
11264                                              gnus-article-prepare-hook)))
11265             (gnus-summary-select-article (not decode) nil nil article)))
11266         (save-excursion
11267           (set-buffer save-buffer)
11268           (erase-buffer)
11269           (insert-buffer-substring (if decode
11270                                        gnus-article-buffer
11271                                      gnus-original-article-buffer)))
11272         (setq file (gnus-article-save save-buffer file num))
11273         (gnus-summary-remove-process-mark article)
11274         (unless not-saved
11275           (gnus-summary-set-saved-mark article))))
11276     (gnus-kill-buffer save-buffer)
11277     (gnus-summary-position-point)
11278     (gnus-set-mode-line 'summary)
11279     n))
11280
11281 (defun gnus-summary-pipe-output (&optional arg headers)
11282   "Pipe the current article to a subprocess.
11283 If N is a positive number, pipe the N next articles.
11284 If N is a negative number, pipe the N previous articles.
11285 If N is nil and any articles have been marked with the process mark,
11286 pipe those articles instead.
11287 If HEADERS (the symbolic prefix), include the headers, too."
11288   (interactive (gnus-interactive "P\ny"))
11289   (require 'gnus-art)
11290   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11291         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11292     (gnus-summary-save-article arg t))
11293   (let ((buffer (get-buffer "*Shell Command Output*")))
11294     (when (and buffer
11295                (not (zerop (buffer-size buffer))))
11296       (gnus-configure-windows 'pipe))))
11297
11298 (defun gnus-summary-save-article-mail (&optional arg)
11299   "Append the current article to a Unix mail box file.
11300 If N is a positive number, save the N next articles.
11301 If N is a negative number, save the N previous articles.
11302 If N is nil and any articles have been marked with the process mark,
11303 save those articles instead."
11304   (interactive "P")
11305   (require 'gnus-art)
11306   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11307     (gnus-summary-save-article arg)))
11308
11309 (defun gnus-summary-save-article-rmail (&optional arg)
11310   "Append the current article to an rmail file.
11311 If N is a positive number, save the N next articles.
11312 If N is a negative number, save the N previous articles.
11313 If N is nil and any articles have been marked with the process mark,
11314 save those articles instead."
11315   (interactive "P")
11316   (require 'gnus-art)
11317   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11318     (gnus-summary-save-article arg)))
11319
11320 (defun gnus-summary-save-article-file (&optional arg)
11321   "Append the current article to a file.
11322 If N is a positive number, save the N next articles.
11323 If N is a negative number, save the N previous articles.
11324 If N is nil and any articles have been marked with the process mark,
11325 save those articles instead."
11326   (interactive "P")
11327   (require 'gnus-art)
11328   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11329     (gnus-summary-save-article arg nil t)))
11330
11331 (defun gnus-summary-write-article-file (&optional arg)
11332   "Write the current article to a file, deleting the previous file.
11333 If N is a positive number, save the N next articles.
11334 If N is a negative number, save the N previous articles.
11335 If N is nil and any articles have been marked with the process mark,
11336 save those articles instead."
11337   (interactive "P")
11338   (require 'gnus-art)
11339   ;; When saving many files, use `gnus-summary-write-to-file' first
11340   ;; and `gnus-summary-save-in-file' thereafter unless
11341   ;; `gnus-prompt-before-saving' is `always'.
11342   (let ((gnus-default-article-saver
11343          (if (eq gnus-prompt-before-saving 'always)
11344              'gnus-summary-write-to-file
11345            (lambda (&rest args)
11346              (prog1
11347                  (apply 'gnus-summary-write-to-file args)
11348                (setq gnus-default-article-saver
11349                      'gnus-summary-save-in-file))))))
11350     (gnus-summary-save-article arg nil t)))
11351
11352 (defun gnus-summary-save-article-body-file (&optional arg)
11353   "Append the current article body to a file.
11354 If N is a positive number, save the N next articles.
11355 If N is a negative number, save the N previous articles.
11356 If N is nil and any articles have been marked with the process mark,
11357 save those articles instead."
11358   (interactive "P")
11359   (require 'gnus-art)
11360   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11361     (gnus-summary-save-article arg nil t)))
11362
11363 (defun gnus-summary-muttprint (&optional arg)
11364   "Print the current article using Muttprint.
11365 If N is a positive number, save the N next articles.
11366 If N is a negative number, save the N previous articles.
11367 If N is nil and any articles have been marked with the process mark,
11368 save those articles instead."
11369   (interactive "P")
11370   (require 'gnus-art)
11371   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11372     (gnus-summary-save-article arg t)))
11373
11374 (defun gnus-summary-pipe-message (program)
11375   "Pipe the current article through PROGRAM."
11376   (interactive "sProgram: ")
11377   (gnus-summary-select-article)
11378   (let ((mail-header-separator ""))
11379     (gnus-eval-in-buffer-window gnus-article-buffer
11380       (save-restriction
11381         (widen)
11382         (let ((start (window-start))
11383               buffer-read-only)
11384           (message-pipe-buffer-body program)
11385           (set-window-start (get-buffer-window (current-buffer)) start))))))
11386
11387 (defun gnus-get-split-value (methods)
11388   "Return a value based on the split METHODS."
11389   (let (split-name method result match)
11390     (when methods
11391       (save-excursion
11392         (set-buffer gnus-original-article-buffer)
11393         (save-restriction
11394           (nnheader-narrow-to-headers)
11395           (while (and methods (not split-name))
11396             (goto-char (point-min))
11397             (setq method (pop methods))
11398             (setq match (car method))
11399             (when (cond
11400                    ((stringp match)
11401                     ;; Regular expression.
11402                     (ignore-errors
11403                       (re-search-forward match nil t)))
11404                    ((functionp match)
11405                     ;; Function.
11406                     (save-restriction
11407                       (widen)
11408                       (setq result (funcall match gnus-newsgroup-name))))
11409                    ((consp match)
11410                     ;; Form.
11411                     (save-restriction
11412                       (widen)
11413                       (setq result (eval match)))))
11414               (setq split-name (cdr method))
11415               (cond ((stringp result)
11416                      (push (expand-file-name
11417                             result gnus-article-save-directory)
11418                            split-name))
11419                     ((consp result)
11420                      (setq split-name (append result split-name)))))))))
11421     (nreverse split-name)))
11422
11423 (defun gnus-valid-move-group-p (group)
11424   (and (boundp group)
11425        (symbol-name group)
11426        (symbol-value group)
11427        (gnus-get-function (gnus-find-method-for-group
11428                            (symbol-name group)) 'request-accept-article t)))
11429
11430 (defun gnus-read-move-group-name (prompt default articles prefix)
11431   "Read a group name."
11432   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11433          (minibuffer-confirm-incomplete nil) ; XEmacs
11434          (prom
11435           (format "%s %s to"
11436                   prompt
11437                   (if (> (length articles) 1)
11438                       (format "these %d articles" (length articles))
11439                     "this article")))
11440          (to-newsgroup
11441           (cond
11442            ((null split-name)
11443             (gnus-completing-read-with-default
11444              default prom
11445              gnus-active-hashtb
11446              'gnus-valid-move-group-p
11447              nil prefix
11448              'gnus-group-history))
11449            ((= 1 (length split-name))
11450             (gnus-completing-read-with-default
11451              (car split-name) prom
11452              gnus-active-hashtb
11453              'gnus-valid-move-group-p
11454              nil nil
11455              'gnus-group-history))
11456            (t
11457             (gnus-completing-read-with-default
11458              nil prom
11459              (mapcar 'list (nreverse split-name))
11460              nil nil nil
11461              'gnus-group-history))))
11462          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11463     (when to-newsgroup
11464       (if (or (string= to-newsgroup "")
11465               (string= to-newsgroup prefix))
11466           (setq to-newsgroup default))
11467       (unless to-newsgroup
11468         (error "No group name entered"))
11469       (or (gnus-active to-newsgroup)
11470           (gnus-activate-group to-newsgroup nil nil to-method)
11471           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11472                                      to-newsgroup))
11473               (or (and (gnus-request-create-group to-newsgroup to-method)
11474                        (gnus-activate-group
11475                         to-newsgroup nil nil to-method)
11476                        (gnus-subscribe-group to-newsgroup))
11477                   (error "Couldn't create group %s" to-newsgroup)))
11478           (error "No such group: %s" to-newsgroup)))
11479     to-newsgroup))
11480
11481 (defvar gnus-summary-save-parts-counter)
11482
11483 (defun gnus-summary-save-parts (type dir n &optional reverse)
11484   "Save parts matching TYPE to DIR.
11485 If REVERSE, save parts that do not match TYPE."
11486   (interactive
11487    (list (read-string "Save parts of type: "
11488                       (or (car gnus-summary-save-parts-type-history)
11489                           gnus-summary-save-parts-default-mime)
11490                       'gnus-summary-save-parts-type-history)
11491          (setq gnus-summary-save-parts-last-directory
11492                (read-file-name "Save to directory: "
11493                                gnus-summary-save-parts-last-directory
11494                                nil t))
11495          current-prefix-arg))
11496   (gnus-summary-iterate n
11497     (let ((gnus-display-mime-function nil)
11498           (gnus-inhibit-treatment t))
11499       (gnus-summary-select-article))
11500     (save-excursion
11501       (set-buffer gnus-article-buffer)
11502       (let ((handles (or gnus-article-mime-handles
11503                          (mm-dissect-buffer nil gnus-article-loose-mime)
11504                          (and gnus-article-emulate-mime
11505                               (mm-uu-dissect))))
11506             (gnus-summary-save-parts-counter 1))
11507         (when handles
11508           (gnus-summary-save-parts-1 type dir handles reverse)
11509           (unless gnus-article-mime-handles ;; Don't destroy this case.
11510             (mm-destroy-parts handles)))))))
11511
11512 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11513   (if (stringp (car handle))
11514       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11515               (cdr handle))
11516     (when (if reverse
11517               (not (string-match type (mm-handle-media-type handle)))
11518             (string-match type (mm-handle-media-type handle)))
11519       (let ((file (expand-file-name
11520                    (gnus-map-function
11521                     mm-file-name-rewrite-functions
11522                     (file-name-nondirectory
11523                      (or
11524                       (mail-content-type-get
11525                        (mm-handle-disposition handle) 'filename)
11526                       (mail-content-type-get
11527                        (mm-handle-type handle) 'name)
11528                       (format "%s.%d.%d" gnus-newsgroup-name
11529                               (cdr gnus-article-current)
11530                               gnus-summary-save-parts-counter))))
11531                    dir)))
11532         (incf gnus-summary-save-parts-counter)
11533         (unless (file-exists-p file)
11534           (mm-save-part-to-file handle file))))))
11535
11536 ;; Summary extract commands
11537
11538 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11539   (let ((buffer-read-only nil)
11540         (article (gnus-summary-article-number))
11541         after-article b e)
11542     (unless (gnus-summary-goto-subject article)
11543       (error "No such article: %d" article))
11544     (gnus-summary-position-point)
11545     ;; If all commands are to be bunched up on one line, we collect
11546     ;; them here.
11547     (unless gnus-view-pseudos-separately
11548       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11549             files action)
11550         (while ps
11551           (setq action (cdr (assq 'action (car ps))))
11552           (setq files (list (cdr (assq 'name (car ps)))))
11553           (while (and ps (cdr ps)
11554                       (string= (or action "1")
11555                                (or (cdr (assq 'action (cadr ps))) "2")))
11556             (push (cdr (assq 'name (cadr ps))) files)
11557             (setcdr ps (cddr ps)))
11558           (when files
11559             (when (not (string-match "%s" action))
11560               (push " " files))
11561             (push " " files)
11562             (when (assq 'execute (car ps))
11563               (setcdr (assq 'execute (car ps))
11564                       (funcall (if (string-match "%s" action)
11565                                    'format 'concat)
11566                                action
11567                                (mapconcat
11568                                 (lambda (f)
11569                                   (if (equal f " ")
11570                                       f
11571                                     (shell-quote-argument f)))
11572                                 files " ")))))
11573           (setq ps (cdr ps)))))
11574     (if (and gnus-view-pseudos (not not-view))
11575         (while pslist
11576           (when (assq 'execute (car pslist))
11577             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11578                                   (eq gnus-view-pseudos 'not-confirm)))
11579           (setq pslist (cdr pslist)))
11580       (save-excursion
11581         (while pslist
11582           (setq after-article (or (cdr (assq 'article (car pslist)))
11583                                   (gnus-summary-article-number)))
11584           (gnus-summary-goto-subject after-article)
11585           (forward-line 1)
11586           (setq b (point))
11587           (insert "    " (file-name-nondirectory
11588                           (cdr (assq 'name (car pslist))))
11589                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11590           (setq e (point))
11591           (forward-line -1)             ; back to `b'
11592           (gnus-add-text-properties
11593            b (1- e) (list 'gnus-number gnus-reffed-article-number
11594                           gnus-mouse-face-prop gnus-mouse-face))
11595           (gnus-data-enter
11596            after-article gnus-reffed-article-number
11597            gnus-unread-mark b (car pslist) 0 (- e b))
11598           (setq gnus-newsgroup-unreads
11599                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11600                                          gnus-reffed-article-number))
11601           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11602           (setq pslist (cdr pslist)))))))
11603
11604 (defun gnus-pseudos< (p1 p2)
11605   (let ((c1 (cdr (assq 'action p1)))
11606         (c2 (cdr (assq 'action p2))))
11607     (and c1 c2 (string< c1 c2))))
11608
11609 (defun gnus-request-pseudo-article (props)
11610   (cond ((assq 'execute props)
11611          (gnus-execute-command (cdr (assq 'execute props)))))
11612   (let ((gnus-current-article (gnus-summary-article-number)))
11613     (gnus-run-hooks 'gnus-mark-article-hook)))
11614
11615 (defun gnus-execute-command (command &optional automatic)
11616   (save-excursion
11617     (gnus-article-setup-buffer)
11618     (set-buffer gnus-article-buffer)
11619     (setq buffer-read-only nil)
11620     (let ((command (if automatic command
11621                      (read-string "Command: " (cons command 0)))))
11622       (erase-buffer)
11623       (insert "$ " command "\n\n")
11624       (if gnus-view-pseudo-asynchronously
11625           (start-process "gnus-execute" (current-buffer) shell-file-name
11626                          shell-command-switch command)
11627         (call-process shell-file-name nil t nil
11628                       shell-command-switch command)))))
11629
11630 ;; Summary kill commands.
11631
11632 (defun gnus-summary-edit-global-kill (article)
11633   "Edit the \"global\" kill file."
11634   (interactive (list (gnus-summary-article-number)))
11635   (gnus-group-edit-global-kill article))
11636
11637 (defun gnus-summary-edit-local-kill ()
11638   "Edit a local kill file applied to the current newsgroup."
11639   (interactive)
11640   (setq gnus-current-headers (gnus-summary-article-header))
11641   (gnus-group-edit-local-kill
11642    (gnus-summary-article-number) gnus-newsgroup-name))
11643
11644 ;;; Header reading.
11645
11646 (defun gnus-read-header (id &optional header)
11647   "Read the headers of article ID and enter them into the Gnus system."
11648   (let ((group gnus-newsgroup-name)
11649         (gnus-override-method
11650          (or
11651           gnus-override-method
11652           (and (gnus-news-group-p gnus-newsgroup-name)
11653                (car (gnus-refer-article-methods)))))
11654         where)
11655     ;; First we check to see whether the header in question is already
11656     ;; fetched.
11657     (if (stringp id)
11658         ;; This is a Message-ID.
11659         (setq header (or header (gnus-id-to-header id)))
11660       ;; This is an article number.
11661       (setq header (or header (gnus-summary-article-header id))))
11662     (if (and header
11663              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11664         ;; We have found the header.
11665         header
11666       ;; We have to really fetch the header to this article.
11667       (save-excursion
11668         (set-buffer nntp-server-buffer)
11669         (when (setq where (gnus-request-head id group))
11670           (nnheader-fold-continuation-lines)
11671           (goto-char (point-max))
11672           (insert ".\n")
11673           (goto-char (point-min))
11674           (insert "211 ")
11675           (princ (cond
11676                   ((numberp id) id)
11677                   ((cdr where) (cdr where))
11678                   (header (mail-header-number header))
11679                   (t gnus-reffed-article-number))
11680                  (current-buffer))
11681           (insert " Article retrieved.\n"))
11682         (if (or (not where)
11683                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11684             ()                          ; Malformed head.
11685           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11686             (when (and (stringp id)
11687                        (or
11688                         (not (string= (gnus-group-real-name group)
11689                                       (car where)))
11690                         (not (gnus-server-equal gnus-override-method
11691                                                 (gnus-group-method group)))))
11692               ;; If we fetched by Message-ID and the article came from
11693               ;; a different group (or server), we fudge some bogus
11694               ;; article numbers for this article.
11695               (mail-header-set-number header gnus-reffed-article-number))
11696             (save-excursion
11697               (set-buffer gnus-summary-buffer)
11698               (decf gnus-reffed-article-number)
11699               (gnus-remove-header (mail-header-number header))
11700               (push header gnus-newsgroup-headers)
11701               (setq gnus-current-headers header)
11702               (push (mail-header-number header) gnus-newsgroup-limit)))
11703           header)))))
11704
11705 (defun gnus-remove-header (number)
11706   "Remove header NUMBER from `gnus-newsgroup-headers'."
11707   (if (and gnus-newsgroup-headers
11708            (= number (mail-header-number (car gnus-newsgroup-headers))))
11709       (pop gnus-newsgroup-headers)
11710     (let ((headers gnus-newsgroup-headers))
11711       (while (and (cdr headers)
11712                   (not (= number (mail-header-number (cadr headers)))))
11713         (pop headers))
11714       (when (cdr headers)
11715         (setcdr headers (cddr headers))))))
11716
11717 ;;;
11718 ;;; summary highlights
11719 ;;;
11720
11721 (defun gnus-highlight-selected-summary ()
11722   "Highlight selected article in summary buffer."
11723   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11724   (when gnus-summary-selected-face
11725     (save-excursion
11726       (let* ((beg (point-at-bol))
11727              (end (point-at-eol))
11728              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11729              (from (if (get-text-property beg gnus-mouse-face-prop)
11730                        beg
11731                      (or (next-single-property-change
11732                           beg gnus-mouse-face-prop nil end)
11733                          beg)))
11734              (to
11735               (if (= from end)
11736                   (- from 2)
11737                 (or (next-single-property-change
11738                      from gnus-mouse-face-prop nil end)
11739                     end))))
11740         ;; If no mouse-face prop on line we will have to = from = end,
11741         ;; so we highlight the entire line instead.
11742         (when (= (+ to 2) from)
11743           (setq from beg)
11744           (setq to end))
11745         (if gnus-newsgroup-selected-overlay
11746             ;; Move old overlay.
11747             (gnus-move-overlay
11748              gnus-newsgroup-selected-overlay from to (current-buffer))
11749           ;; Create new overlay.
11750           (gnus-overlay-put
11751            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11752            'face gnus-summary-selected-face))))))
11753
11754 (defvar gnus-summary-highlight-line-cached nil)
11755 (defvar gnus-summary-highlight-line-trigger nil)
11756
11757 (defun gnus-summary-highlight-line-0 ()
11758   (if (and (eq gnus-summary-highlight-line-trigger
11759                gnus-summary-highlight)
11760            gnus-summary-highlight-line-cached)
11761       gnus-summary-highlight-line-cached
11762     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11763           gnus-summary-highlight-line-cached
11764           (let* ((cond (list 'cond))
11765                  (c cond)
11766                  (list gnus-summary-highlight))
11767             (while list
11768               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11769                               nil))
11770               (setq c (cdr c)
11771                     list (cdr list)))
11772             (gnus-byte-compile (list 'lambda nil cond))))))
11773
11774 (defun gnus-summary-highlight-line ()
11775   "Highlight current line according to `gnus-summary-highlight'."
11776   (let* ((beg (point-at-bol))
11777          (article (or (gnus-summary-article-number) gnus-current-article))
11778          (score (or (cdr (assq article
11779                                gnus-newsgroup-scored))
11780                     gnus-summary-default-score 0))
11781          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11782          (inhibit-read-only t)
11783          (default gnus-summary-default-score)
11784          (default-high gnus-summary-default-high-score)
11785          (default-low gnus-summary-default-low-score)
11786          (uncached (and gnus-summary-use-undownloaded-faces
11787                         (memq article gnus-newsgroup-undownloaded)
11788                         (not (memq article gnus-newsgroup-cached)))))
11789     (let ((face (funcall (gnus-summary-highlight-line-0))))
11790       (unless (eq face (get-text-property beg 'face))
11791         (gnus-put-text-property-excluding-characters-with-faces
11792          beg (point-at-eol) 'face
11793          (setq face (if (boundp face) (symbol-value face) face)))
11794         (when gnus-summary-highlight-line-function
11795           (funcall gnus-summary-highlight-line-function article face))))))
11796
11797 (defun gnus-update-read-articles (group unread &optional compute)
11798   "Update the list of read articles in GROUP.
11799 UNREAD is a sorted list."
11800   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11801         (info (gnus-get-info group))
11802         (prev 1)
11803         read)
11804     (if (or (not info) (not active))
11805         ;; There is no info on this group if it was, in fact,
11806         ;; killed.  Gnus stores no information on killed groups, so
11807         ;; there's nothing to be done.
11808         ;; One could store the information somewhere temporarily,
11809         ;; perhaps...  Hmmm...
11810         ()
11811       ;; Remove any negative articles numbers.
11812       (while (and unread (< (car unread) 0))
11813         (setq unread (cdr unread)))
11814       ;; Remove any expired article numbers
11815       (while (and unread (< (car unread) (car active)))
11816         (setq unread (cdr unread)))
11817       ;; Compute the ranges of read articles by looking at the list of
11818       ;; unread articles.
11819       (while unread
11820         (when (/= (car unread) prev)
11821           (push (if (= prev (1- (car unread))) prev
11822                   (cons prev (1- (car unread))))
11823                 read))
11824         (setq prev (1+ (car unread)))
11825         (setq unread (cdr unread)))
11826       (when (<= prev (cdr active))
11827         (push (cons prev (cdr active)) read))
11828       (setq read (if (> (length read) 1) (nreverse read) read))
11829       (if compute
11830           read
11831         (save-excursion
11832           (let (setmarkundo)
11833             ;; Propagate the read marks to the backend.
11834             (when (gnus-check-backend-function 'request-set-mark group)
11835               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11836                     (add (gnus-remove-from-range read (gnus-info-read info))))
11837                 (when (or add del)
11838                   (unless (gnus-check-group group)
11839                     (error "Can't open server for %s" group))
11840                   (gnus-request-set-mark
11841                    group (delq nil (list (if add (list add 'add '(read)))
11842                                          (if del (list del 'del '(read))))))
11843                   (setq setmarkundo
11844                         `(gnus-request-set-mark
11845                           ,group
11846                           ',(delq nil (list
11847                                        (if del (list del 'add '(read)))
11848                                        (if add (list add 'del '(read))))))))))
11849             (set-buffer gnus-group-buffer)
11850             (gnus-undo-register
11851               `(progn
11852                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11853                  (gnus-info-set-read ',info ',(gnus-info-read info))
11854                  (gnus-get-unread-articles-in-group ',info
11855                                                     (gnus-active ,group))
11856                  (gnus-group-update-group ,group t)
11857                  ,setmarkundo))))
11858         ;; Enter this list into the group info.
11859         (gnus-info-set-read info read)
11860         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11861         (gnus-get-unread-articles-in-group info (gnus-active group))
11862         t))))
11863
11864 (defun gnus-offer-save-summaries ()
11865   "Offer to save all active summary buffers."
11866   (let (buffers)
11867     ;; Go through all buffers and find all summaries.
11868     (dolist (buffer (buffer-list))
11869       (when (and (setq buffer (buffer-name buffer))
11870                  (string-match "Summary" buffer)
11871                  (with-current-buffer buffer
11872                    ;; We check that this is, indeed, a summary buffer.
11873                    (and (eq major-mode 'gnus-summary-mode)
11874                         ;; Also make sure this isn't bogus.
11875                         gnus-newsgroup-prepared
11876                         ;; Also make sure that this isn't a
11877                         ;; dead summary buffer.
11878                         (not gnus-dead-summary-mode))))
11879         (push buffer buffers)))
11880     ;; Go through all these summary buffers and offer to save them.
11881     (when buffers
11882       (save-excursion
11883         (map-y-or-n-p
11884          "Update summary buffer %s? "
11885          (lambda (buf)
11886            (switch-to-buffer buf)
11887            (gnus-summary-exit))
11888          buffers)))))
11889
11890 (defun gnus-summary-setup-default-charset ()
11891   "Setup newsgroup default charset."
11892   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11893       (setq gnus-newsgroup-charset nil)
11894     (let* ((ignored-charsets
11895             (or gnus-newsgroup-ephemeral-ignored-charsets
11896                 (append
11897                  (and gnus-newsgroup-name
11898                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11899                  gnus-newsgroup-ignored-charsets))))
11900       (setq gnus-newsgroup-charset
11901             (or gnus-newsgroup-ephemeral-charset
11902                 (and gnus-newsgroup-name
11903                      (gnus-parameter-charset gnus-newsgroup-name))
11904                 gnus-default-charset))
11905       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11906            ignored-charsets))))
11907
11908 ;;;
11909 ;;; Mime Commands
11910 ;;;
11911
11912 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11913   "Display the current article buffer fully MIME-buttonized.
11914 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11915 treated as multipart/mixed."
11916   (interactive "P")
11917   (require 'gnus-art)
11918   (let ((gnus-unbuttonized-mime-types nil)
11919         (gnus-mime-display-multipart-as-mixed show-all-parts))
11920     (gnus-summary-show-article)))
11921
11922 (defun gnus-summary-repair-multipart (article)
11923   "Add a Content-Type header to a multipart article without one."
11924   (interactive (list (gnus-summary-article-number)))
11925   (gnus-with-article article
11926     (message-narrow-to-head)
11927     (message-remove-header "Mime-Version")
11928     (goto-char (point-max))
11929     (insert "Mime-Version: 1.0\n")
11930     (widen)
11931     (when (search-forward "\n--" nil t)
11932       (let ((separator (buffer-substring (point) (point-at-eol))))
11933         (message-narrow-to-head)
11934         (message-remove-header "Content-Type")
11935         (goto-char (point-max))
11936         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11937                         separator))
11938         (widen))))
11939   (let (gnus-mark-article-hook)
11940     (gnus-summary-select-article t t nil article)))
11941
11942 (defun gnus-summary-toggle-display-buttonized ()
11943   "Toggle the buttonizing of the article buffer."
11944   (interactive)
11945   (require 'gnus-art)
11946   (if (setq gnus-inhibit-mime-unbuttonizing
11947             (not gnus-inhibit-mime-unbuttonizing))
11948       (let ((gnus-unbuttonized-mime-types nil))
11949         (gnus-summary-show-article))
11950     (gnus-summary-show-article)))
11951
11952 ;;;
11953 ;;; Generic summary marking commands
11954 ;;;
11955
11956 (defvar gnus-summary-marking-alist
11957   '((read gnus-del-mark "d")
11958     (unread gnus-unread-mark "u")
11959     (ticked gnus-ticked-mark "!")
11960     (dormant gnus-dormant-mark "?")
11961     (expirable gnus-expirable-mark "e"))
11962   "An alist of names/marks/keystrokes.")
11963
11964 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11965 (defvar gnus-summary-mark-map)
11966
11967 (defun gnus-summary-make-all-marking-commands ()
11968   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11969   (dolist (elem gnus-summary-marking-alist)
11970     (apply 'gnus-summary-make-marking-command elem)))
11971
11972 (defun gnus-summary-make-marking-command (name mark keystroke)
11973   (let ((map (make-sparse-keymap)))
11974     (define-key gnus-summary-generic-mark-map keystroke map)
11975     (dolist (lway `((next "next" next nil "n")
11976                     (next-unread "next unread" next t "N")
11977                     (prev "previous" prev nil "p")
11978                     (prev-unread "previous unread" prev t "P")
11979                     (nomove "" nil nil ,keystroke)))
11980       (let ((func (gnus-summary-make-marking-command-1
11981                    mark (car lway) lway name)))
11982         (setq func (eval func))
11983         (define-key map (nth 4 lway) func)))))
11984
11985 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11986   `(defun ,(intern
11987             (format "gnus-summary-put-mark-as-%s%s"
11988                     name (if (eq way 'nomove)
11989                              ""
11990                            (concat "-" (symbol-name way)))))
11991      (n)
11992      ,(format
11993        "Mark the current article as %s%s.
11994 If N, the prefix, then repeat N times.
11995 If N is negative, move in reverse order.
11996 The difference between N and the actual number of articles marked is
11997 returned."
11998        name (cadr lway))
11999      (interactive "p")
12000      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12001
12002 (defun gnus-summary-generic-mark (n mark move unread)
12003   "Mark N articles with MARK."
12004   (unless (eq major-mode 'gnus-summary-mode)
12005     (error "This command can only be used in the summary buffer"))
12006   (gnus-summary-show-thread)
12007   (let ((nummove
12008          (cond
12009           ((eq move 'next) 1)
12010           ((eq move 'prev) -1)
12011           (t 0))))
12012     (if (zerop nummove)
12013         (setq n 1)
12014       (when (< n 0)
12015         (setq n (abs n)
12016               nummove (* -1 nummove))))
12017     (while (and (> n 0)
12018                 (gnus-summary-mark-article nil mark)
12019                 (zerop (gnus-summary-next-subject nummove unread t)))
12020       (setq n (1- n)))
12021     (when (/= 0 n)
12022       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12023     (gnus-summary-recenter)
12024     (gnus-summary-position-point)
12025     (gnus-set-mode-line 'summary)
12026     n))
12027
12028 (defun gnus-summary-insert-articles (articles)
12029   (when (setq articles
12030               (gnus-sorted-difference articles
12031                                       (mapcar (lambda (h)
12032                                                 (mail-header-number h))
12033                                               gnus-newsgroup-headers)))
12034     (setq gnus-newsgroup-headers
12035           (gnus-merge 'list
12036                       gnus-newsgroup-headers
12037                       (gnus-fetch-headers articles)
12038                       'gnus-article-sort-by-number))
12039     ;; Suppress duplicates?
12040     (when gnus-suppress-duplicates
12041       (gnus-dup-suppress-articles))
12042
12043     ;; We might want to build some more threads first.
12044     (when (and gnus-fetch-old-headers
12045                (eq gnus-headers-retrieved-by 'nov))
12046       (if (eq gnus-fetch-old-headers 'invisible)
12047           (gnus-build-all-threads)
12048         (gnus-build-old-threads)))
12049     ;; Let the Gnus agent mark articles as read.
12050     (when gnus-agent
12051       (gnus-agent-get-undownloaded-list))
12052     ;; Remove list identifiers from subject
12053     (when gnus-list-identifiers
12054       (gnus-summary-remove-list-identifiers))
12055     ;; First and last article in this newsgroup.
12056     (when gnus-newsgroup-headers
12057       (setq gnus-newsgroup-begin
12058             (mail-header-number (car gnus-newsgroup-headers))
12059             gnus-newsgroup-end
12060             (mail-header-number
12061              (gnus-last-element gnus-newsgroup-headers))))
12062     (when gnus-use-scoring
12063       (gnus-possibly-score-headers))))
12064
12065 (defun gnus-summary-insert-old-articles (&optional all)
12066   "Insert all old articles in this group.
12067 If ALL is non-nil, already read articles become readable.
12068 If ALL is a number, fetch this number of articles."
12069   (interactive "P")
12070   (prog1
12071       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12072             older len)
12073         (setq older
12074               ;; Some nntp servers lie about their active range.  When
12075               ;; this happens, the active range can be in the millions.
12076               ;; Use a compressed range to avoid creating a huge list.
12077               (gnus-range-difference (list gnus-newsgroup-active) old))
12078         (setq len (gnus-range-length older))
12079         (cond
12080          ((null older) nil)
12081          ((numberp all)
12082           (if (< all len)
12083               (let ((older-range (nreverse older)))
12084                 (setq older nil)
12085
12086                 (while (> all 0)
12087                   (let* ((r (pop older-range))
12088                          (min (if (numberp r) r (car r)))
12089                          (max (if (numberp r) r (cdr r))))
12090                     (while (and (<= min max)
12091                                 (> all 0))
12092                       (push max older)
12093                       (setq all (1- all)
12094                             max (1- max))))))
12095             (setq older (gnus-uncompress-range older))))
12096          (all
12097           (setq older (gnus-uncompress-range older)))
12098          (t
12099           (when (and (numberp gnus-large-newsgroup)
12100                    (> len gnus-large-newsgroup))
12101               (let* ((cursor-in-echo-area nil)
12102                      (initial (gnus-parameter-large-newsgroup-initial
12103                                gnus-newsgroup-name))
12104                      (input
12105                       (read-string
12106                        (format
12107                         "How many articles from %s (%s %d): "
12108                         (gnus-limit-string
12109                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12110                         (if initial "max" "default")
12111                         len)
12112                        (if initial
12113                            (cons (number-to-string initial)
12114                                  0)))))
12115                 (unless (string-match "^[ \t]*$" input)
12116                   (setq all (string-to-number input))
12117                   (if (< all len)
12118                       (let ((older-range (nreverse older)))
12119                         (setq older nil)
12120
12121                         (while (> all 0)
12122                           (let* ((r (pop older-range))
12123                                  (min (if (numberp r) r (car r)))
12124                                  (max (if (numberp r) r (cdr r))))
12125                             (while (and (<= min max)
12126                                         (> all 0))
12127                               (push max older)
12128                               (setq all (1- all)
12129                                     max (1- max))))))))))
12130           (setq older (gnus-uncompress-range older))))
12131         (if (not older)
12132             (message "No old news.")
12133           (gnus-summary-insert-articles older)
12134           (gnus-summary-limit (gnus-sorted-nunion old older))))
12135     (gnus-summary-position-point)))
12136
12137 (defun gnus-summary-insert-new-articles ()
12138   "Insert all new articles in this group."
12139   (interactive)
12140   (prog1
12141       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12142             (old-active gnus-newsgroup-active)
12143             (nnmail-fetched-sources (list t))
12144             i new)
12145         (setq gnus-newsgroup-active
12146               (gnus-activate-group gnus-newsgroup-name 'scan))
12147         (setq i (cdr gnus-newsgroup-active))
12148         (while (> i (cdr old-active))
12149           (push i new)
12150           (decf i))
12151         (if (not new)
12152             (message "No gnus is bad news")
12153           (gnus-summary-insert-articles new)
12154           (setq gnus-newsgroup-unreads
12155                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12156           (gnus-summary-limit (gnus-sorted-nunion old new))))
12157     (gnus-summary-position-point)))
12158
12159 (gnus-summary-make-all-marking-commands)
12160
12161 (gnus-ems-redefine)
12162
12163 (provide 'gnus-sum)
12164
12165 (run-hooks 'gnus-sum-load-hook)
12166
12167 ;; Local Variables:
12168 ;; coding: iso-8859-1
12169 ;; End:
12170
12171 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12172 ;;; gnus-sum.el ends here