2006-05-23 Hynek Schlawack <hynek@ularx.de>
[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 part with charset..." gnus-article-view-part-as-charset t]
2246                ["Copy part" gnus-article-copy-part t]
2247                ["Save part..." gnus-article-save-part t]
2248                ["View part" gnus-article-view-part t]))
2249              ("Date"
2250               ["Local" gnus-article-date-local t]
2251               ["ISO8601" gnus-article-date-iso8601 t]
2252               ["UT" gnus-article-date-ut t]
2253               ["Original" gnus-article-date-original t]
2254               ["Lapsed" gnus-article-date-lapsed t]
2255               ["User-defined" gnus-article-date-user t])
2256              ("Display"
2257               ["Remove images" gnus-article-remove-images t]
2258               ["Toggle smiley" gnus-treat-smiley t]
2259               ["Show X-Face" gnus-article-display-x-face t]
2260               ["Show picons in From" gnus-treat-from-picon t]
2261               ["Show picons in mail headers" gnus-treat-mail-picon t]
2262               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2263               ("View as different encoding"
2264                ,@(gnus-summary-menu-split
2265                   (mapcar
2266                    (lambda (cs)
2267                      ;; Since easymenu under Emacs doesn't allow
2268                      ;; lambda forms for menu commands, we should
2269                      ;; provide intern'ed function symbols.
2270                      (let ((command (intern (format "\
2271 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2272                        (fset command
2273                              `(lambda ()
2274                                 (interactive)
2275                                 (let ((gnus-summary-show-article-charset-alist
2276                                        '((1 . ,cs))))
2277                                   (gnus-summary-show-article 1))))
2278                        `[,(symbol-name cs) ,command t]))
2279                    (sort (if (fboundp 'coding-system-list)
2280                              (coding-system-list)
2281                            (mapcar 'car mm-mime-mule-charset-alist))
2282                          'string<)))))
2283              ("Washing"
2284               ("Remove Blanks"
2285                ["Leading" gnus-article-strip-leading-blank-lines t]
2286                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2287                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2288                ["All of the above" gnus-article-strip-blank-lines t]
2289                ["All" gnus-article-strip-all-blank-lines t]
2290                ["Leading space" gnus-article-strip-leading-space t]
2291                ["Trailing space" gnus-article-strip-trailing-space t]
2292                ["Leading space in headers"
2293                 gnus-article-remove-leading-whitespace t])
2294               ["Overstrike" gnus-article-treat-overstrike t]
2295               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2296               ["Emphasis" gnus-article-emphasize t]
2297               ["Word wrap" gnus-article-fill-cited-article t]
2298               ["Fill long lines" gnus-article-fill-long-lines t]
2299               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2300               ["Remove CR" gnus-article-remove-cr t]
2301               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2302               ["Base64" gnus-article-de-base64-unreadable t]
2303               ["Rot 13" gnus-summary-caesar-message
2304                ,@(if (featurep 'xemacs) '(t)
2305                    '(:help "\"Caesar rotate\" article by 13"))]
2306               ["De-IDNA" gnus-summary-idna-message t]
2307               ["Morse decode" gnus-summary-morse-message t]
2308               ["Unix pipe..." gnus-summary-pipe-message t]
2309               ["Add buttons" gnus-article-add-buttons t]
2310               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2311               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2312               ["Verbose header" gnus-summary-verbose-headers t]
2313               ["Toggle header" gnus-summary-toggle-header t]
2314               ["Unfold headers" gnus-article-treat-unfold-headers t]
2315               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2316               ["Html" gnus-article-wash-html t]
2317               ["Unsplit URLs" gnus-article-unsplit-urls t]
2318               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2319               ["Decode HZ" gnus-article-decode-HZ t]
2320               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2321               ("(Outlook) Deuglify"
2322                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2323                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2324                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2325                ["Full (Outlook) deuglify"
2326                 gnus-article-outlook-deuglify-article t])
2327               )
2328              ("Output"
2329               ["Save in default format..." gnus-summary-save-article
2330                ,@(if (featurep 'xemacs) '(t)
2331                    '(:help "Save article using default method"))]
2332               ["Save in file..." gnus-summary-save-article-file
2333                ,@(if (featurep 'xemacs) '(t)
2334                    '(:help "Save article in file"))]
2335               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2336               ["Save in MH folder..." gnus-summary-save-article-folder t]
2337               ["Save in VM folder..." gnus-summary-save-article-vm t]
2338               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2339               ["Save body in file..." gnus-summary-save-article-body-file t]
2340               ["Pipe through a filter..." gnus-summary-pipe-output t]
2341               ["Add to SOUP packet" gnus-soup-add-article t]
2342               ["Print with Muttprint..." gnus-summary-muttprint t]
2343               ["Print" gnus-summary-print-article
2344                ,@(if (featurep 'xemacs) '(t)
2345                    '(:help "Generate and print a PostScript image"))])
2346              ("Copy, move,... (Backend)"
2347               ,@(if (featurep 'xemacs) nil
2348                   '(:help "Copying, moving, expiring articles..."))
2349               ["Respool article..." gnus-summary-respool-article t]
2350               ["Move article..." gnus-summary-move-article
2351                (gnus-check-backend-function
2352                 'request-move-article gnus-newsgroup-name)]
2353               ["Copy article..." gnus-summary-copy-article t]
2354               ["Crosspost article..." gnus-summary-crosspost-article
2355                (gnus-check-backend-function
2356                 'request-replace-article gnus-newsgroup-name)]
2357               ["Import file..." gnus-summary-import-article
2358                (gnus-check-backend-function
2359                 'request-accept-article gnus-newsgroup-name)]
2360               ["Create article..." gnus-summary-create-article
2361                (gnus-check-backend-function
2362                 'request-accept-article gnus-newsgroup-name)]
2363               ["Check if posted" gnus-summary-article-posted-p t]
2364               ["Edit article" gnus-summary-edit-article
2365                (not (gnus-group-read-only-p))]
2366               ["Delete article" gnus-summary-delete-article
2367                (gnus-check-backend-function
2368                 'request-expire-articles gnus-newsgroup-name)]
2369               ["Query respool" gnus-summary-respool-query t]
2370               ["Trace respool" gnus-summary-respool-trace t]
2371               ["Delete expirable articles" gnus-summary-expire-articles-now
2372                (gnus-check-backend-function
2373                 'request-expire-articles gnus-newsgroup-name)])
2374              ("Extract"
2375               ["Uudecode" gnus-uu-decode-uu
2376                ,@(if (featurep 'xemacs) '(t)
2377                    '(:help "Decode uuencoded article(s)"))]
2378               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2379               ["Unshar" gnus-uu-decode-unshar t]
2380               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2381               ["Save" gnus-uu-decode-save t]
2382               ["Binhex" gnus-uu-decode-binhex t]
2383               ["Postscript" gnus-uu-decode-postscript t]
2384               ["All MIME parts" gnus-summary-save-parts t])
2385              ("Cache"
2386               ["Enter article" gnus-cache-enter-article t]
2387               ["Remove article" gnus-cache-remove-article t])
2388              ["Translate" gnus-article-babel t]
2389              ["Select article buffer" gnus-summary-select-article-buffer t]
2390              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2391              ["Isearch article..." gnus-summary-isearch-article t]
2392              ["Beginning of the article" gnus-summary-beginning-of-article t]
2393              ["End of the article" gnus-summary-end-of-article t]
2394              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2395              ["Fetch referenced articles" gnus-summary-refer-references t]
2396              ["Fetch current thread" gnus-summary-refer-thread t]
2397              ["Fetch article with id..." gnus-summary-refer-article t]
2398              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2399              ["Redisplay" gnus-summary-show-article t]
2400              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2401       (easy-menu-define
2402         gnus-summary-article-menu gnus-summary-mode-map ""
2403         (cons "Article" innards))
2404
2405       (if (not (keymapp gnus-summary-article-menu))
2406           (easy-menu-define
2407             gnus-article-commands-menu gnus-article-mode-map ""
2408             (cons "Commands" innards))
2409         ;; in Emacs, don't share menu.
2410         (setq gnus-article-commands-menu
2411               (copy-keymap gnus-summary-article-menu))
2412         (define-key gnus-article-mode-map [menu-bar commands]
2413           (cons "Commands" gnus-article-commands-menu))))
2414
2415     (easy-menu-define
2416       gnus-summary-thread-menu gnus-summary-mode-map ""
2417       '("Threads"
2418         ["Find all messages in thread" gnus-summary-refer-thread t]
2419         ["Toggle threading" gnus-summary-toggle-threads t]
2420         ["Hide threads" gnus-summary-hide-all-threads t]
2421         ["Show threads" gnus-summary-show-all-threads t]
2422         ["Hide thread" gnus-summary-hide-thread t]
2423         ["Show thread" gnus-summary-show-thread t]
2424         ["Go to next thread" gnus-summary-next-thread t]
2425         ["Go to previous thread" gnus-summary-prev-thread t]
2426         ["Go down thread" gnus-summary-down-thread t]
2427         ["Go up thread" gnus-summary-up-thread t]
2428         ["Top of thread" gnus-summary-top-thread t]
2429         ["Mark thread as read" gnus-summary-kill-thread t]
2430         ["Lower thread score" gnus-summary-lower-thread t]
2431         ["Raise thread score" gnus-summary-raise-thread t]
2432         ["Rethread current" gnus-summary-rethread-current t]))
2433
2434     (easy-menu-define
2435       gnus-summary-post-menu gnus-summary-mode-map ""
2436       `("Post"
2437         ["Send a message (mail or news)" gnus-summary-post-news
2438          ,@(if (featurep 'xemacs) '(t)
2439              '(:help "Compose a new message (mail or news)"))]
2440         ["Followup" gnus-summary-followup
2441          ,@(if (featurep 'xemacs) '(t)
2442              '(:help "Post followup to this article"))]
2443         ["Followup and yank" gnus-summary-followup-with-original
2444          ,@(if (featurep 'xemacs) '(t)
2445              '(:help "Post followup to this article, quoting its contents"))]
2446         ["Supersede article" gnus-summary-supersede-article t]
2447         ["Cancel article" gnus-summary-cancel-article
2448          ,@(if (featurep 'xemacs) '(t)
2449              '(:help "Cancel an article you posted"))]
2450         ["Reply" gnus-summary-reply t]
2451         ["Reply and yank" gnus-summary-reply-with-original t]
2452         ["Wide reply" gnus-summary-wide-reply t]
2453         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2454          ,@(if (featurep 'xemacs) '(t)
2455              '(:help "Mail a reply, quoting this article"))]
2456         ["Very wide reply" gnus-summary-very-wide-reply t]
2457         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2458          ,@(if (featurep 'xemacs) '(t)
2459              '(:help "Mail a very wide reply, quoting this article"))]
2460         ["Mail forward" gnus-summary-mail-forward t]
2461         ["Post forward" gnus-summary-post-forward t]
2462         ["Digest and mail" gnus-uu-digest-mail-forward t]
2463         ["Digest and post" gnus-uu-digest-post-forward t]
2464         ["Resend message" gnus-summary-resend-message t]
2465         ["Resend message edit" gnus-summary-resend-message-edit t]
2466         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2467         ["Send a mail" gnus-summary-mail-other-window t]
2468         ["Create a local message" gnus-summary-news-other-window t]
2469         ["Uuencode and post" gnus-uu-post-news
2470          ,@(if (featurep 'xemacs) '(t)
2471              '(:help "Post a uuencoded article"))]
2472         ["Followup via news" gnus-summary-followup-to-mail t]
2473         ["Followup via news and yank"
2474          gnus-summary-followup-to-mail-with-original t]
2475         ;;("Draft"
2476         ;;["Send" gnus-summary-send-draft t]
2477         ;;["Send bounced" gnus-resend-bounced-mail t])
2478         ))
2479
2480     (cond
2481      ((not (keymapp gnus-summary-post-menu))
2482       (setq gnus-article-post-menu gnus-summary-post-menu))
2483      ((not gnus-article-post-menu)
2484       ;; Don't share post menu.
2485       (setq gnus-article-post-menu
2486             (copy-keymap gnus-summary-post-menu))))
2487     (define-key gnus-article-mode-map [menu-bar post]
2488       (cons "Post" gnus-article-post-menu))
2489
2490     (easy-menu-define
2491       gnus-summary-misc-menu gnus-summary-mode-map ""
2492       `("Gnus"
2493         ("Mark Read"
2494          ["Mark as read" gnus-summary-mark-as-read-forward t]
2495          ["Mark same subject and select"
2496           gnus-summary-kill-same-subject-and-select t]
2497          ["Mark same subject" gnus-summary-kill-same-subject t]
2498          ["Catchup" gnus-summary-catchup
2499           ,@(if (featurep 'xemacs) '(t)
2500               '(:help "Mark unread articles in this group as read"))]
2501          ["Catchup all" gnus-summary-catchup-all t]
2502          ["Catchup to here" gnus-summary-catchup-to-here t]
2503          ["Catchup from here" gnus-summary-catchup-from-here t]
2504          ["Catchup region" gnus-summary-mark-region-as-read
2505           (gnus-mark-active-p)]
2506          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2507         ("Mark Various"
2508          ["Tick" gnus-summary-tick-article-forward t]
2509          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2510          ["Remove marks" gnus-summary-clear-mark-forward t]
2511          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2512          ["Set bookmark" gnus-summary-set-bookmark t]
2513          ["Remove bookmark" gnus-summary-remove-bookmark t])
2514         ("Limit to"
2515          ["Marks..." gnus-summary-limit-to-marks t]
2516          ["Subject..." gnus-summary-limit-to-subject t]
2517          ["Author..." gnus-summary-limit-to-author t]
2518          ["Recipient..." gnus-summary-limit-to-recipient t]
2519          ["Age..." gnus-summary-limit-to-age t]
2520          ["Extra..." gnus-summary-limit-to-extra t]
2521          ["Score..." gnus-summary-limit-to-score t]
2522          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2523          ["Unread" gnus-summary-limit-to-unread t]
2524          ["Unseen" gnus-summary-limit-to-unseen t]
2525          ["Replied" gnus-summary-limit-to-replied t]
2526          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2527          ["Next articles" gnus-summary-limit-to-articles t]
2528          ["Pop limit" gnus-summary-pop-limit t]
2529          ["Show dormant" gnus-summary-limit-include-dormant t]
2530          ["Hide childless dormant"
2531           gnus-summary-limit-exclude-childless-dormant t]
2532          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2533          ["Hide marked" gnus-summary-limit-exclude-marks t]
2534          ["Show expunged" gnus-summary-limit-include-expunged t])
2535         ("Process Mark"
2536          ["Set mark" gnus-summary-mark-as-processable t]
2537          ["Remove mark" gnus-summary-unmark-as-processable t]
2538          ["Remove all marks" gnus-summary-unmark-all-processable t]
2539          ["Invert marks" gnus-uu-invert-processable t]
2540          ["Mark above" gnus-uu-mark-over t]
2541          ["Mark series" gnus-uu-mark-series t]
2542          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2543          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2544          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2545          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2546          ["Mark all" gnus-uu-mark-all t]
2547          ["Mark buffer" gnus-uu-mark-buffer t]
2548          ["Mark sparse" gnus-uu-mark-sparse t]
2549          ["Mark thread" gnus-uu-mark-thread t]
2550          ["Unmark thread" gnus-uu-unmark-thread t]
2551          ("Process Mark Sets"
2552           ["Kill" gnus-summary-kill-process-mark t]
2553           ["Yank" gnus-summary-yank-process-mark
2554            gnus-newsgroup-process-stack]
2555           ["Save" gnus-summary-save-process-mark t]
2556           ["Run command on marked..." gnus-summary-universal-argument t]))
2557         ("Scroll article"
2558          ["Page forward" gnus-summary-next-page
2559           ,@(if (featurep 'xemacs) '(t)
2560               '(:help "Show next page of article"))]
2561          ["Page backward" gnus-summary-prev-page
2562           ,@(if (featurep 'xemacs) '(t)
2563               '(:help "Show previous page of article"))]
2564          ["Line forward" gnus-summary-scroll-up t])
2565         ("Move"
2566          ["Next unread article" gnus-summary-next-unread-article t]
2567          ["Previous unread article" gnus-summary-prev-unread-article t]
2568          ["Next article" gnus-summary-next-article t]
2569          ["Previous article" gnus-summary-prev-article t]
2570          ["Next unread subject" gnus-summary-next-unread-subject t]
2571          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2572          ["Next article same subject" gnus-summary-next-same-subject t]
2573          ["Previous article same subject" gnus-summary-prev-same-subject t]
2574          ["First unread article" gnus-summary-first-unread-article t]
2575          ["Best unread article" gnus-summary-best-unread-article t]
2576          ["Go to subject number..." gnus-summary-goto-subject t]
2577          ["Go to article number..." gnus-summary-goto-article t]
2578          ["Go to the last article" gnus-summary-goto-last-article t]
2579          ["Pop article off history" gnus-summary-pop-article t])
2580         ("Sort"
2581          ["Sort by number" gnus-summary-sort-by-number t]
2582          ["Sort by author" gnus-summary-sort-by-author t]
2583          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2584          ["Sort by subject" gnus-summary-sort-by-subject t]
2585          ["Sort by date" gnus-summary-sort-by-date t]
2586          ["Sort by score" gnus-summary-sort-by-score t]
2587          ["Sort by lines" gnus-summary-sort-by-lines t]
2588          ["Sort by characters" gnus-summary-sort-by-chars t]
2589          ["Randomize" gnus-summary-sort-by-random t]
2590          ["Original sort" gnus-summary-sort-by-original t])
2591         ("Help"
2592          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2593          ["Describe group" gnus-summary-describe-group t]
2594          ["Fetch charter" gnus-group-fetch-charter
2595           ,@(if (featurep 'xemacs) nil
2596               '(:help "Display the charter of the current group"))]
2597          ["Fetch control message" gnus-group-fetch-control
2598           ,@(if (featurep 'xemacs) nil
2599               '(:help "Display the archived control message for the current group"))]
2600          ["Read manual" gnus-info-find-node t])
2601         ("Modes"
2602          ["Pick and read" gnus-pick-mode t]
2603          ["Binary" gnus-binary-mode t])
2604         ("Regeneration"
2605          ["Regenerate" gnus-summary-prepare t]
2606          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2607          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2608          ["Toggle threading" gnus-summary-toggle-threads t])
2609         ["See old articles" gnus-summary-insert-old-articles t]
2610         ["See new articles" gnus-summary-insert-new-articles t]
2611         ["Filter articles..." gnus-summary-execute-command t]
2612         ["Run command on articles..." gnus-summary-universal-argument t]
2613         ["Search articles forward..." gnus-summary-search-article-forward t]
2614         ["Search articles backward..." gnus-summary-search-article-backward t]
2615         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2616         ["Expand window" gnus-summary-expand-window t]
2617         ["Expire expirable articles" gnus-summary-expire-articles
2618          (gnus-check-backend-function
2619           'request-expire-articles gnus-newsgroup-name)]
2620         ["Edit local kill file" gnus-summary-edit-local-kill t]
2621         ["Edit main kill file" gnus-summary-edit-global-kill t]
2622         ["Edit group parameters" gnus-summary-edit-parameters t]
2623         ["Customize group parameters" gnus-summary-customize-parameters t]
2624         ["Send a bug report" gnus-bug t]
2625         ("Exit"
2626          ["Catchup and exit" gnus-summary-catchup-and-exit
2627           ,@(if (featurep 'xemacs) '(t)
2628               '(:help "Mark unread articles in this group as read, then exit"))]
2629          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2630          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2631          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2632          ["Exit group" gnus-summary-exit
2633           ,@(if (featurep 'xemacs) '(t)
2634               '(:help "Exit current group, return to group selection mode"))]
2635          ["Exit group without updating" gnus-summary-exit-no-update t]
2636          ["Exit and goto next group" gnus-summary-next-group t]
2637          ["Exit and goto prev group" gnus-summary-prev-group t]
2638          ["Reselect group" gnus-summary-reselect-current-group t]
2639          ["Rescan group" gnus-summary-rescan-group t]
2640          ["Update dribble" gnus-summary-save-newsrc t])))
2641
2642     (gnus-run-hooks 'gnus-summary-menu-hook)))
2643
2644 (defvar gnus-summary-tool-bar-map nil)
2645
2646 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2647 ;; affect _new_ message buffers.  We might add a function that walks thru all
2648 ;; summary-mode buffers and force the update.
2649 (defun gnus-summary-tool-bar-update (&optional symbol value)
2650   "Update summary mode toolbar.
2651 Setter function for custom variables."
2652   (setq-default gnus-summary-tool-bar-map nil)
2653   (when symbol
2654     ;; When used as ":set" function:
2655     (set-default symbol value))
2656   (when (gnus-buffer-live-p gnus-summary-buffer)
2657     (with-current-buffer gnus-summary-buffer
2658       (gnus-summary-make-tool-bar))))
2659
2660 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2661                                      'gnus-summary-tool-bar-gnome
2662                                    'gnus-summary-tool-bar-retro)
2663   "Specifies the Gnus summary tool bar.
2664
2665 It can be either a list or a symbol refering to a list.  See
2666 `gmm-tool-bar-from-list' for the format of the list.  The
2667 default key map is `gnus-summary-mode-map'.
2668
2669 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2670 `gnus-summary-tool-bar-retro'."
2671   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2672                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2673                  (repeat :tag "User defined list" gmm-tool-bar-item)
2674                  (symbol))
2675   :version "23.0" ;; No Gnus
2676   :initialize 'custom-initialize-default
2677   :set 'gnus-summary-tool-bar-update
2678   :group 'gnus-summary)
2679
2680 (defcustom gnus-summary-tool-bar-gnome
2681   '((gnus-summary-post-news "mail/compose" nil)
2682     (gnus-summary-insert-new-articles "mail/inbox" nil
2683                                       :visible (or (not gnus-agent)
2684                                                    gnus-plugged))
2685     (gnus-summary-reply-with-original "mail/reply")
2686     (gnus-summary-reply "mail/reply" nil :visible nil)
2687     (gnus-summary-followup-with-original "mail/reply-all")
2688     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2689     (gnus-summary-mail-forward "mail/forward")
2690     (gnus-summary-save-article "mail/save")
2691     (gnus-summary-search-article-forward "search" nil :visible nil)
2692     (gnus-summary-print-article "print")
2693     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2694     ;; Some new commands that may need more suitable icons:
2695     (gnus-summary-save-newsrc "save" nil :visible nil)
2696     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2697     (gnus-summary-prev-article "left-arrow")
2698     (gnus-summary-next-article "right-arrow")
2699     (gnus-summary-next-page "next-page")
2700     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2701     ;;
2702     ;; Maybe some sort-by-... could be added:
2703     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2704     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2705     (gnus-summary-mark-as-expirable
2706      "delete" nil
2707      :visible (gnus-check-backend-function 'request-expire-articles
2708                                            gnus-newsgroup-name))
2709     (gnus-summary-mark-as-spam
2710      "mail/spam" t
2711      :visible (and (fboundp 'spam-group-ham-contents-p)
2712                    (spam-group-ham-contents-p gnus-newsgroup-name))
2713      :help "Mark as spam")
2714     (gnus-summary-mark-as-read-forward
2715      "mail/not-spam" nil
2716      :visible (and (fboundp 'spam-group-spam-contents-p)
2717                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2718     ;;
2719     (gnus-summary-exit "exit")
2720     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2721     (gnus-info-find-node "help"))
2722   "List of functions for the summary tool bar (GNOME style).
2723
2724 See `gmm-tool-bar-from-list' for the format of the list."
2725   :type '(repeat gmm-tool-bar-item)
2726   :version "23.0" ;; No Gnus
2727   :initialize 'custom-initialize-default
2728   :set 'gnus-summary-tool-bar-update
2729   :group 'gnus-summary)
2730
2731 (defcustom gnus-summary-tool-bar-retro
2732   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2733     (gnus-summary-next-unread-article "gnus/next-ur")
2734     (gnus-summary-post-news "gnus/post")
2735     (gnus-summary-followup-with-original "gnus/fuwo")
2736     (gnus-summary-followup "gnus/followup")
2737     (gnus-summary-reply-with-original "gnus/reply-wo")
2738     (gnus-summary-reply "gnus/reply")
2739     (gnus-summary-caesar-message "gnus/rot13")
2740     (gnus-uu-decode-uu "gnus/uu-decode")
2741     (gnus-summary-save-article-file "gnus/save-aif")
2742     (gnus-summary-save-article "gnus/save-art")
2743     (gnus-uu-post-news "gnus/uu-post")
2744     (gnus-summary-catchup "gnus/catchup")
2745     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2746     (gnus-summary-exit "gnus/exit-summ")
2747     ;; Some new command that may need more suitable icons:
2748     (gnus-summary-print-article "gnus/print" nil :visible nil)
2749     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2750     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2751     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2752     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2753     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2754     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2755     ;;
2756     (gnus-info-find-node "gnus/help" nil :visible nil))
2757   "List of functions for the summary tool bar (retro look).
2758
2759 See `gmm-tool-bar-from-list' for the format of the list."
2760   :type '(repeat gmm-tool-bar-item)
2761   :version "23.0" ;; No Gnus
2762   :initialize 'custom-initialize-default
2763   :set 'gnus-summary-tool-bar-update
2764   :group 'gnus-summary)
2765
2766 (defcustom gnus-summary-tool-bar-zap-list t
2767   "List of icon items from the global tool bar.
2768 These items are not displayed in the Gnus summary mode tool bar.
2769
2770 See `gmm-tool-bar-from-list' for the format of the list."
2771   :type 'gmm-tool-bar-zap-list
2772   :version "23.0" ;; No Gnus
2773   :initialize 'custom-initialize-default
2774   :set 'gnus-summary-tool-bar-update
2775   :group 'gnus-summary)
2776
2777 (defvar image-load-path)
2778
2779 (defun gnus-summary-make-tool-bar (&optional force)
2780   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2781 When FORCE, rebuild the tool bar."
2782   (when (and (not (featurep 'xemacs))
2783              (boundp 'tool-bar-mode)
2784              tool-bar-mode
2785              (or (not gnus-summary-tool-bar-map) force))
2786     (let* ((load-path
2787             (gmm-image-load-path-for-library "gnus"
2788                                              "mail/save.xpm"
2789                                              nil t))
2790            (image-load-path (cons (car load-path)
2791                                   (when (boundp 'image-load-path)
2792                                     image-load-path)))
2793            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2794                                         gnus-summary-tool-bar-zap-list
2795                                         'gnus-summary-mode-map)))
2796       (when map
2797         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2798         ;; uses it's value.
2799         (setq gnus-summary-tool-bar-map map))))
2800   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2801
2802 (defun gnus-score-set-default (var value)
2803   "A version of set that updates the GNU Emacs menu-bar."
2804   (set var value)
2805   ;; It is the message that forces the active status to be updated.
2806   (message ""))
2807
2808 (defun gnus-make-score-map (type)
2809   "Make a summary score map of type TYPE."
2810   (if t
2811       nil
2812     (let ((headers '(("author" "from" string)
2813                      ("subject" "subject" string)
2814                      ("article body" "body" string)
2815                      ("article head" "head" string)
2816                      ("xref" "xref" string)
2817                      ("extra header" "extra" string)
2818                      ("lines" "lines" number)
2819                      ("followups to author" "followup" string)))
2820           (types '((number ("less than" <)
2821                            ("greater than" >)
2822                            ("equal" =))
2823                    (string ("substring" s)
2824                            ("exact string" e)
2825                            ("fuzzy string" f)
2826                            ("regexp" r))))
2827           (perms '(("temporary" (current-time-string))
2828                    ("permanent" nil)
2829                    ("immediate" now)))
2830           header)
2831       (list
2832        (apply
2833         'nconc
2834         (list
2835          (if (eq type 'lower)
2836              "Lower score"
2837            "Increase score"))
2838         (let (outh)
2839           (while headers
2840             (setq header (car headers))
2841             (setq outh
2842                   (cons
2843                    (apply
2844                     'nconc
2845                     (list (car header))
2846                     (let ((ts (cdr (assoc (nth 2 header) types)))
2847                           outt)
2848                       (while ts
2849                         (setq outt
2850                               (cons
2851                                (apply
2852                                 'nconc
2853                                 (list (caar ts))
2854                                 (let ((ps perms)
2855                                       outp)
2856                                   (while ps
2857                                     (setq outp
2858                                           (cons
2859                                            (vector
2860                                             (caar ps)
2861                                             (list
2862                                              'gnus-summary-score-entry
2863                                              (nth 1 header)
2864                                              (if (or (string= (nth 1 header)
2865                                                               "head")
2866                                                      (string= (nth 1 header)
2867                                                               "body"))
2868                                                  ""
2869                                                (list 'gnus-summary-header
2870                                                      (nth 1 header)))
2871                                              (list 'quote (nth 1 (car ts)))
2872                                              (list 'gnus-score-delta-default
2873                                                    nil)
2874                                              (nth 1 (car ps))
2875                                              t)
2876                                             t)
2877                                            outp))
2878                                     (setq ps (cdr ps)))
2879                                   (list (nreverse outp))))
2880                                outt))
2881                         (setq ts (cdr ts)))
2882                       (list (nreverse outt))))
2883                    outh))
2884             (setq headers (cdr headers)))
2885           (list (nreverse outh))))))))
2886
2887 \f
2888
2889 (defun gnus-summary-mode (&optional group)
2890   "Major mode for reading articles.
2891
2892 All normal editing commands are switched off.
2893 \\<gnus-summary-mode-map>
2894 Each line in this buffer represents one article.  To read an
2895 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2896 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2897 respectively.
2898
2899 You can also post articles and send mail from this buffer.  To
2900 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2901 of an article, type `\\[gnus-summary-reply]'.
2902
2903 There are approx. one gazillion commands you can execute in this
2904 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2905
2906 The following commands are available:
2907
2908 \\{gnus-summary-mode-map}"
2909   (interactive)
2910   (kill-all-local-variables)
2911   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2912     (gnus-summary-make-local-variables))
2913   (gnus-summary-make-local-variables)
2914   (setq gnus-newsgroup-name group)
2915   (when (gnus-visual-p 'summary-menu 'menu)
2916     (gnus-summary-make-menu-bar)
2917     (gnus-summary-make-tool-bar))
2918   (gnus-make-thread-indent-array)
2919   (gnus-simplify-mode-line)
2920   (setq major-mode 'gnus-summary-mode)
2921   (setq mode-name "Summary")
2922   (make-local-variable 'minor-mode-alist)
2923   (use-local-map gnus-summary-mode-map)
2924   (buffer-disable-undo)
2925   (setq buffer-read-only t              ;Disable modification
2926         show-trailing-whitespace nil)
2927   (setq truncate-lines t)
2928   (setq selective-display t)
2929   (setq selective-display-ellipses t)   ;Display `...'
2930   (gnus-summary-set-display-table)
2931   (gnus-set-default-directory)
2932   (make-local-variable 'gnus-summary-line-format)
2933   (make-local-variable 'gnus-summary-line-format-spec)
2934   (make-local-variable 'gnus-summary-dummy-line-format)
2935   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2936   (make-local-variable 'gnus-summary-mark-positions)
2937   (gnus-make-local-hook 'pre-command-hook)
2938   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2939   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2940   (turn-on-gnus-mailing-list-mode)
2941   (mm-enable-multibyte)
2942   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2943   (gnus-update-summary-mark-positions))
2944
2945 (defun gnus-summary-make-local-variables ()
2946   "Make all the local summary buffer variables."
2947   (let (global)
2948     (dolist (local gnus-summary-local-variables)
2949       (if (consp local)
2950           (progn
2951             (if (eq (cdr local) 'global)
2952                 ;; Copy the global value of the variable.
2953                 (setq global (symbol-value (car local)))
2954               ;; Use the value from the list.
2955               (setq global (eval (cdr local))))
2956             (set (make-local-variable (car local)) global))
2957         ;; Simple nil-valued local variable.
2958         (set (make-local-variable local) nil)))))
2959
2960 (defun gnus-summary-clear-local-variables ()
2961   (let ((locals gnus-summary-local-variables))
2962     (while locals
2963       (if (consp (car locals))
2964           (and (symbolp (caar locals))
2965                (set (caar locals) nil))
2966         (and (symbolp (car locals))
2967              (set (car locals) nil)))
2968       (setq locals (cdr locals)))))
2969
2970 ;; Summary data functions.
2971
2972 (defmacro gnus-data-number (data)
2973   `(car ,data))
2974
2975 (defmacro gnus-data-set-number (data number)
2976   `(setcar ,data ,number))
2977
2978 (defmacro gnus-data-mark (data)
2979   `(nth 1 ,data))
2980
2981 (defmacro gnus-data-set-mark (data mark)
2982   `(setcar (nthcdr 1 ,data) ,mark))
2983
2984 (defmacro gnus-data-pos (data)
2985   `(nth 2 ,data))
2986
2987 (defmacro gnus-data-set-pos (data pos)
2988   `(setcar (nthcdr 2 ,data) ,pos))
2989
2990 (defmacro gnus-data-header (data)
2991   `(nth 3 ,data))
2992
2993 (defmacro gnus-data-set-header (data header)
2994   `(setf (nth 3 ,data) ,header))
2995
2996 (defmacro gnus-data-level (data)
2997   `(nth 4 ,data))
2998
2999 (defmacro gnus-data-unread-p (data)
3000   `(= (nth 1 ,data) gnus-unread-mark))
3001
3002 (defmacro gnus-data-read-p (data)
3003   `(/= (nth 1 ,data) gnus-unread-mark))
3004
3005 (defmacro gnus-data-pseudo-p (data)
3006   `(consp (nth 3 ,data)))
3007
3008 (defmacro gnus-data-find (number)
3009   `(assq ,number gnus-newsgroup-data))
3010
3011 (defmacro gnus-data-find-list (number &optional data)
3012   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3013      (memq (assq ,number bdata)
3014            bdata)))
3015
3016 (defmacro gnus-data-make (number mark pos header level)
3017   `(list ,number ,mark ,pos ,header ,level))
3018
3019 (defun gnus-data-enter (after-article number mark pos header level offset)
3020   (let ((data (gnus-data-find-list after-article)))
3021     (unless data
3022       (error "No such article: %d" after-article))
3023     (setcdr data (cons (gnus-data-make number mark pos header level)
3024                        (cdr data)))
3025     (setq gnus-newsgroup-data-reverse nil)
3026     (gnus-data-update-list (cddr data) offset)))
3027
3028 (defun gnus-data-enter-list (after-article list &optional offset)
3029   (when list
3030     (let ((data (and after-article (gnus-data-find-list after-article)))
3031           (ilist list))
3032       (if (not (or data
3033                    after-article))
3034           (let ((odata gnus-newsgroup-data))
3035             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3036             (when offset
3037               (gnus-data-update-list odata offset)))
3038         ;; Find the last element in the list to be spliced into the main
3039         ;; list.
3040         (setq list (last list))
3041         (if (not data)
3042             (progn
3043               (setcdr list gnus-newsgroup-data)
3044               (setq gnus-newsgroup-data ilist)
3045               (when offset
3046                 (gnus-data-update-list (cdr list) offset)))
3047           (setcdr list (cdr data))
3048           (setcdr data ilist)
3049           (when offset
3050             (gnus-data-update-list (cdr list) offset))))
3051       (setq gnus-newsgroup-data-reverse nil))))
3052
3053 (defun gnus-data-remove (article &optional offset)
3054   (let ((data gnus-newsgroup-data))
3055     (if (= (gnus-data-number (car data)) article)
3056         (progn
3057           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3058                 gnus-newsgroup-data-reverse nil)
3059           (when offset
3060             (gnus-data-update-list gnus-newsgroup-data offset)))
3061       (while (cdr data)
3062         (when (= (gnus-data-number (cadr data)) article)
3063           (setcdr data (cddr data))
3064           (when offset
3065             (gnus-data-update-list (cdr data) offset))
3066           (setq data nil
3067                 gnus-newsgroup-data-reverse nil))
3068         (setq data (cdr data))))))
3069
3070 (defmacro gnus-data-list (backward)
3071   `(if ,backward
3072        (or gnus-newsgroup-data-reverse
3073            (setq gnus-newsgroup-data-reverse
3074                  (reverse gnus-newsgroup-data)))
3075      gnus-newsgroup-data))
3076
3077 (defun gnus-data-update-list (data offset)
3078   "Add OFFSET to the POS of all data entries in DATA."
3079   (setq gnus-newsgroup-data-reverse nil)
3080   (while data
3081     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3082     (setq data (cdr data))))
3083
3084 (defun gnus-summary-article-pseudo-p (article)
3085   "Say whether this article is a pseudo article or not."
3086   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3087
3088 (defmacro gnus-summary-article-sparse-p (article)
3089   "Say whether this article is a sparse article or not."
3090   `(memq ,article gnus-newsgroup-sparse))
3091
3092 (defmacro gnus-summary-article-ancient-p (article)
3093   "Say whether this article is a sparse article or not."
3094   `(memq ,article gnus-newsgroup-ancient))
3095
3096 (defun gnus-article-parent-p (number)
3097   "Say whether this article is a parent or not."
3098   (let ((data (gnus-data-find-list number)))
3099     (and (cdr data)              ; There has to be an article after...
3100          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3101             (gnus-data-level (nth 1 data))))))
3102
3103 (defun gnus-article-children (number)
3104   "Return a list of all children to NUMBER."
3105   (let* ((data (gnus-data-find-list number))
3106          (level (gnus-data-level (car data)))
3107          children)
3108     (setq data (cdr data))
3109     (while (and data
3110                 (= (gnus-data-level (car data)) (1+ level)))
3111       (push (gnus-data-number (car data)) children)
3112       (setq data (cdr data)))
3113     children))
3114
3115 (defmacro gnus-summary-skip-intangible ()
3116   "If the current article is intangible, then jump to a different article."
3117   '(let ((to (get-text-property (point) 'gnus-intangible)))
3118      (and to (gnus-summary-goto-subject to))))
3119
3120 (defmacro gnus-summary-article-intangible-p ()
3121   "Say whether this article is intangible or not."
3122   '(get-text-property (point) 'gnus-intangible))
3123
3124 (defun gnus-article-read-p (article)
3125   "Say whether ARTICLE is read or not."
3126   (not (or (memq article gnus-newsgroup-marked)
3127            (memq article gnus-newsgroup-spam-marked)
3128            (memq article gnus-newsgroup-unreads)
3129            (memq article gnus-newsgroup-unselected)
3130            (memq article gnus-newsgroup-dormant))))
3131
3132 ;; Some summary mode macros.
3133
3134 (defmacro gnus-summary-article-number ()
3135   "The article number of the article on the current line.
3136 If there isn't an article number here, then we return the current
3137 article number."
3138   '(progn
3139      (gnus-summary-skip-intangible)
3140      (or (get-text-property (point) 'gnus-number)
3141          (gnus-summary-last-subject))))
3142
3143 (defmacro gnus-summary-article-header (&optional number)
3144   "Return the header of article NUMBER."
3145   `(gnus-data-header (gnus-data-find
3146                       ,(or number '(gnus-summary-article-number)))))
3147
3148 (defmacro gnus-summary-thread-level (&optional number)
3149   "Return the level of thread that starts with article NUMBER."
3150   `(if (and (eq gnus-summary-make-false-root 'dummy)
3151             (get-text-property (point) 'gnus-intangible))
3152        0
3153      (gnus-data-level (gnus-data-find
3154                        ,(or number '(gnus-summary-article-number))))))
3155
3156 (defmacro gnus-summary-article-mark (&optional number)
3157   "Return the mark of article NUMBER."
3158   `(gnus-data-mark (gnus-data-find
3159                     ,(or number '(gnus-summary-article-number)))))
3160
3161 (defmacro gnus-summary-article-pos (&optional number)
3162   "Return the position of the line of article NUMBER."
3163   `(gnus-data-pos (gnus-data-find
3164                    ,(or number '(gnus-summary-article-number)))))
3165
3166 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3167 (defmacro gnus-summary-article-subject (&optional number)
3168   "Return current subject string or nil if nothing."
3169   `(let ((headers
3170           ,(if number
3171                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3172              '(gnus-data-header (assq (gnus-summary-article-number)
3173                                       gnus-newsgroup-data)))))
3174      (and headers
3175           (vectorp headers)
3176           (mail-header-subject headers))))
3177
3178 (defmacro gnus-summary-article-score (&optional number)
3179   "Return current article score."
3180   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3181                   gnus-newsgroup-scored))
3182        gnus-summary-default-score 0))
3183
3184 (defun gnus-summary-article-children (&optional number)
3185   "Return a list of article numbers that are children of article NUMBER."
3186   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3187          (level (gnus-data-level (car data)))
3188          l children)
3189     (while (and (setq data (cdr data))
3190                 (> (setq l (gnus-data-level (car data))) level))
3191       (and (= (1+ level) l)
3192            (push (gnus-data-number (car data))
3193                  children)))
3194     (nreverse children)))
3195
3196 (defun gnus-summary-article-parent (&optional number)
3197   "Return the article number of the parent of article NUMBER."
3198   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3199                                     (gnus-data-list t)))
3200          (level (gnus-data-level (car data))))
3201     (if (zerop level)
3202         ()                              ; This is a root.
3203       ;; We search until we find an article with a level less than
3204       ;; this one.  That function has to be the parent.
3205       (while (and (setq data (cdr data))
3206                   (not (< (gnus-data-level (car data)) level))))
3207       (and data (gnus-data-number (car data))))))
3208
3209 (defun gnus-unread-mark-p (mark)
3210   "Say whether MARK is the unread mark."
3211   (= mark gnus-unread-mark))
3212
3213 (defun gnus-read-mark-p (mark)
3214   "Say whether MARK is one of the marks that mark as read.
3215 This is all marks except unread, ticked, dormant, and expirable."
3216   (not (or (= mark gnus-unread-mark)
3217            (= mark gnus-ticked-mark)
3218            (= mark gnus-spam-mark)
3219            (= mark gnus-dormant-mark)
3220            (= mark gnus-expirable-mark))))
3221
3222 (defmacro gnus-article-mark (number)
3223   "Return the MARK of article NUMBER.
3224 This macro should only be used when computing the mark the \"first\"
3225 time; i.e., when generating the summary lines.  After that,
3226 `gnus-summary-article-mark' should be used to examine the
3227 marks of articles."
3228   `(cond
3229     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3230     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3231     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3232     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3233     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3234     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3235     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3236     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3237            gnus-ancient-mark))))
3238
3239 ;; Saving hidden threads.
3240
3241 (defmacro gnus-save-hidden-threads (&rest forms)
3242   "Save hidden threads, eval FORMS, and restore the hidden threads."
3243   (let ((config (make-symbol "config")))
3244     `(let ((,config (gnus-hidden-threads-configuration)))
3245        (unwind-protect
3246            (save-excursion
3247              ,@forms)
3248          (gnus-restore-hidden-threads-configuration ,config)))))
3249 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3250 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3251
3252 (defun gnus-data-compute-positions ()
3253   "Compute the positions of all articles."
3254   (setq gnus-newsgroup-data-reverse nil)
3255   (let ((data gnus-newsgroup-data))
3256     (save-excursion
3257       (gnus-save-hidden-threads
3258         (gnus-summary-show-all-threads)
3259         (goto-char (point-min))
3260         (while data
3261           (while (get-text-property (point) 'gnus-intangible)
3262             (forward-line 1))
3263           (gnus-data-set-pos (car data) (+ (point) 3))
3264           (setq data (cdr data))
3265           (forward-line 1))))))
3266
3267 (defun gnus-hidden-threads-configuration ()
3268   "Return the current hidden threads configuration."
3269   (save-excursion
3270     (let (config)
3271       (goto-char (point-min))
3272       (while (search-forward "\r" nil t)
3273         (push (1- (point)) config))
3274       config)))
3275
3276 (defun gnus-restore-hidden-threads-configuration (config)
3277   "Restore hidden threads configuration from CONFIG."
3278   (save-excursion
3279     (let (point buffer-read-only)
3280       (while (setq point (pop config))
3281         (when (and (< point (point-max))
3282                    (goto-char point)
3283                    (eq (char-after) ?\n))
3284           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3285
3286 ;; Various summary mode internalish functions.
3287
3288 (defun gnus-mouse-pick-article (e)
3289   (interactive "e")
3290   (mouse-set-point e)
3291   (gnus-summary-next-page nil t))
3292
3293 (defun gnus-summary-set-display-table ()
3294   "Change the display table.
3295 Odd characters have a tendency to mess
3296 up nicely formatted displays - we make all possible glyphs
3297 display only a single character."
3298
3299   ;; We start from the standard display table, if any.
3300   (let ((table (or (copy-sequence standard-display-table)
3301                    (make-display-table)))
3302         (i 32))
3303     ;; Nix out all the control chars...
3304     (while (>= (setq i (1- i)) 0)
3305       (aset table i [??]))
3306    ;; ... but not newline and cr, of course.  (cr is necessary for the
3307     ;; selective display).
3308     (aset table ?\n nil)
3309     (aset table ?\r nil)
3310     ;; We keep TAB as well.
3311     (aset table ?\t nil)
3312     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3313     ;; Emacs 23 (unicode), that are not set already.
3314     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3315                  160
3316                256)))
3317       (while (>= (setq i (1- i)) 127)
3318         ;; Only modify if the entry is nil.
3319         (unless (aref table i)
3320           (aset table i [??]))))
3321     (setq buffer-display-table table)))
3322
3323 (defun gnus-summary-set-article-display-arrow (pos)
3324   "Update the overlay arrow to point to line at position POS."
3325   (when (and gnus-summary-display-arrow
3326              (boundp 'overlay-arrow-position)
3327              (boundp 'overlay-arrow-string))
3328     (save-excursion
3329       (goto-char pos)
3330       (beginning-of-line)
3331       (unless overlay-arrow-position
3332         (setq overlay-arrow-position (make-marker)))
3333       (setq overlay-arrow-string "=>"
3334             overlay-arrow-position (set-marker overlay-arrow-position
3335                                                (point)
3336                                                (current-buffer))))))
3337
3338 (defun gnus-summary-setup-buffer (group)
3339   "Initialize summary buffer."
3340   (let ((buffer (gnus-summary-buffer-name group))
3341         (dead-name (concat "*Dead Summary "
3342                            (gnus-group-decoded-name group) "*")))
3343     ;; If a dead summary buffer exists, we kill it.
3344     (when (gnus-buffer-live-p dead-name)
3345       (gnus-kill-buffer dead-name))
3346     (if (get-buffer buffer)
3347         (progn
3348           (set-buffer buffer)
3349           (setq gnus-summary-buffer (current-buffer))
3350           (not gnus-newsgroup-prepared))
3351       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3352       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3353       (gnus-summary-mode group)
3354       (when gnus-carpal
3355         (gnus-carpal-setup-buffer 'summary))
3356       (when (gnus-group-quit-config group)
3357         (set (make-local-variable 'gnus-single-article-buffer) nil))
3358       (make-local-variable 'gnus-article-buffer)
3359       (make-local-variable 'gnus-article-current)
3360       (make-local-variable 'gnus-original-article-buffer)
3361       (setq gnus-newsgroup-name group)
3362       ;; Set any local variables in the group parameters.
3363       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3364       t)))
3365
3366 (defun gnus-set-global-variables ()
3367   "Set the global equivalents of the buffer-local variables.
3368 They are set to the latest values they had.  These reflect the summary
3369 buffer that was in action when the last article was fetched."
3370   (when (eq major-mode 'gnus-summary-mode)
3371     (setq gnus-summary-buffer (current-buffer))
3372     (let ((name gnus-newsgroup-name)
3373           (marked gnus-newsgroup-marked)
3374           (spam gnus-newsgroup-spam-marked)
3375           (unread gnus-newsgroup-unreads)
3376           (headers gnus-current-headers)
3377           (data gnus-newsgroup-data)
3378           (summary gnus-summary-buffer)
3379           (article-buffer gnus-article-buffer)
3380           (original gnus-original-article-buffer)
3381           (gac gnus-article-current)
3382           (reffed gnus-reffed-article-number)
3383           (score-file gnus-current-score-file)
3384           (default-charset gnus-newsgroup-charset)
3385           vlist)
3386       (let ((locals gnus-newsgroup-variables))
3387         (while locals
3388           (if (consp (car locals))
3389               (push (eval (caar locals)) vlist)
3390             (push (eval (car locals)) vlist))
3391           (setq locals (cdr locals)))
3392         (setq vlist (nreverse vlist)))
3393       (with-current-buffer gnus-group-buffer
3394         (setq gnus-newsgroup-name name
3395               gnus-newsgroup-marked marked
3396               gnus-newsgroup-spam-marked spam
3397               gnus-newsgroup-unreads unread
3398               gnus-current-headers headers
3399               gnus-newsgroup-data data
3400               gnus-article-current gac
3401               gnus-summary-buffer summary
3402               gnus-article-buffer article-buffer
3403               gnus-original-article-buffer original
3404               gnus-reffed-article-number reffed
3405               gnus-current-score-file score-file
3406               gnus-newsgroup-charset default-charset)
3407         (let ((locals gnus-newsgroup-variables))
3408           (while locals
3409             (if (consp (car locals))
3410                 (set (caar locals) (pop vlist))
3411               (set (car locals) (pop vlist)))
3412             (setq locals (cdr locals))))
3413         ;; The article buffer also has local variables.
3414         (when (gnus-buffer-live-p gnus-article-buffer)
3415           (set-buffer gnus-article-buffer)
3416           (setq gnus-summary-buffer summary))))))
3417
3418 (defun gnus-summary-article-unread-p (article)
3419   "Say whether ARTICLE is unread or not."
3420   (memq article gnus-newsgroup-unreads))
3421
3422 (defun gnus-summary-first-article-p (&optional article)
3423   "Return whether ARTICLE is the first article in the buffer."
3424   (if (not (setq article (or article (gnus-summary-article-number))))
3425       nil
3426     (eq article (caar gnus-newsgroup-data))))
3427
3428 (defun gnus-summary-last-article-p (&optional article)
3429   "Return whether ARTICLE is the last article in the buffer."
3430   (if (not (setq article (or article (gnus-summary-article-number))))
3431       ;; All non-existent numbers are the last article.  :-)
3432       t
3433     (not (cdr (gnus-data-find-list article)))))
3434
3435 (defun gnus-make-thread-indent-array ()
3436   (let ((n 200))
3437     (unless (and gnus-thread-indent-array
3438                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3439       (setq gnus-thread-indent-array (make-vector 201 "")
3440             gnus-thread-indent-array-level gnus-thread-indent-level)
3441       (while (>= n 0)
3442         (aset gnus-thread-indent-array n
3443               (make-string (* n gnus-thread-indent-level) ? ))
3444         (setq n (1- n))))))
3445
3446 (defun gnus-update-summary-mark-positions ()
3447   "Compute where the summary marks are to go."
3448   (save-excursion
3449     (when (gnus-buffer-exists-p gnus-summary-buffer)
3450       (set-buffer gnus-summary-buffer))
3451     (let ((spec gnus-summary-line-format-spec)
3452           pos)
3453       (save-excursion
3454         (gnus-set-work-buffer)
3455         (let ((gnus-tmp-unread ?Z)
3456               (gnus-replied-mark ?Z)
3457               (gnus-score-below-mark ?Z)
3458               (gnus-score-over-mark ?Z)
3459               (gnus-undownloaded-mark ?Z)
3460               (gnus-summary-line-format-spec spec)
3461               (gnus-newsgroup-downloadable '(0))
3462               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3463               case-fold-search ignores)
3464           ;; Here, all marks are bound to Z.
3465           (gnus-summary-insert-line header
3466                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3467           (goto-char (point-min))
3468           ;; Memorize the positions of the same characters as dummy marks.
3469           (while (re-search-forward "[A-D]" nil t)
3470             (push (point) ignores))
3471           (erase-buffer)
3472           ;; We use A-D as dummy marks in order to know column positions
3473           ;; where marks should be inserted.
3474           (setq gnus-tmp-unread ?A
3475                 gnus-replied-mark ?B
3476                 gnus-score-below-mark ?C
3477                 gnus-score-over-mark ?C
3478                 gnus-undownloaded-mark ?D)
3479           (gnus-summary-insert-line header
3480                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3481           ;; Ignore characters which aren't dummy marks.
3482           (dolist (p ignores)
3483             (delete-region (goto-char (1- p)) p)
3484             (insert ?Z))
3485           (goto-char (point-min))
3486           (setq pos (list (cons 'unread
3487                                 (and (search-forward "A" nil t)
3488                                      (- (point) (point-min) 1)))))
3489           (goto-char (point-min))
3490           (push (cons 'replied (and (search-forward "B" nil t)
3491                                     (- (point) (point-min) 1)))
3492                 pos)
3493           (goto-char (point-min))
3494           (push (cons 'score (and (search-forward "C" nil t)
3495                                   (- (point) (point-min) 1)))
3496                 pos)
3497           (goto-char (point-min))
3498           (push (cons 'download (and (search-forward "D" nil t)
3499                                      (- (point) (point-min) 1)))
3500                 pos)))
3501       (setq gnus-summary-mark-positions pos))))
3502
3503 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3504   "Insert a dummy root in the summary buffer."
3505   (beginning-of-line)
3506   (gnus-add-text-properties
3507    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3508    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3509
3510 (defun gnus-summary-extract-address-component (from)
3511   (or (car (funcall gnus-extract-address-components from))
3512       from))
3513
3514 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3515   (let ((mail-parse-charset gnus-newsgroup-charset)
3516         ; Is it really necessary to do this next part for each summary line?
3517         ; Luckily, doesn't seem to slow things down much.
3518         (mail-parse-ignored-charsets
3519          (with-current-buffer gnus-summary-buffer
3520            gnus-newsgroup-ignored-charsets)))
3521     (or
3522      (and gnus-ignored-from-addresses
3523           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3524           (let ((extra-headers (mail-header-extra header))
3525                 to
3526                 newsgroups)
3527             (cond
3528              ((setq to (cdr (assq 'To extra-headers)))
3529               (concat gnus-summary-to-prefix
3530                       (inline
3531                         (gnus-summary-extract-address-component
3532                          (funcall gnus-decode-encoded-word-function to)))))
3533              ((setq newsgroups
3534                     (or
3535                      (cdr (assq 'Newsgroups extra-headers))
3536                      (and
3537                       (memq 'Newsgroups gnus-extra-headers)
3538                       (eq (car (gnus-find-method-for-group
3539                                 gnus-newsgroup-name)) 'nntp)
3540                       (gnus-group-real-name gnus-newsgroup-name))))
3541               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3542      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3543
3544 (defun gnus-summary-insert-line (gnus-tmp-header
3545                                  gnus-tmp-level gnus-tmp-current
3546                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3547                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3548                                  &optional gnus-tmp-dummy gnus-tmp-score
3549                                  gnus-tmp-process)
3550   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3551          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3552          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3553          (gnus-tmp-score-char
3554           (if (or (null gnus-summary-default-score)
3555                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3556                       gnus-summary-zcore-fuzz))
3557               ?                         ;Whitespace
3558             (if (< gnus-tmp-score gnus-summary-default-score)
3559                 gnus-score-below-mark gnus-score-over-mark)))
3560          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3561          (gnus-tmp-replied
3562           (cond (gnus-tmp-process gnus-process-mark)
3563                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3564                  gnus-cached-mark)
3565                 (gnus-tmp-replied gnus-replied-mark)
3566                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3567                  gnus-forwarded-mark)
3568                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3569                  gnus-saved-mark)
3570                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3571                  gnus-recent-mark)
3572                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3573                  gnus-unseen-mark)
3574                 (t gnus-no-mark)))
3575          (gnus-tmp-downloaded
3576           (cond (undownloaded
3577                  gnus-undownloaded-mark)
3578                 (gnus-newsgroup-agentized
3579                  gnus-downloaded-mark)
3580                 (t
3581                  gnus-no-mark)))
3582          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3583          (gnus-tmp-name
3584           (cond
3585            ((string-match "<[^>]+> *$" gnus-tmp-from)
3586             (let ((beg (match-beginning 0)))
3587               (or (and (string-match "^\".+\"" gnus-tmp-from)
3588                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3589                   (substring gnus-tmp-from 0 beg))))
3590            ((string-match "(.+)" gnus-tmp-from)
3591             (substring gnus-tmp-from
3592                        (1+ (match-beginning 0)) (1- (match-end 0))))
3593            (t gnus-tmp-from)))
3594          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3595          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3596          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3597          (buffer-read-only nil))
3598     (when (string= gnus-tmp-name "")
3599       (setq gnus-tmp-name gnus-tmp-from))
3600     (unless (numberp gnus-tmp-lines)
3601       (setq gnus-tmp-lines -1))
3602     (if (= gnus-tmp-lines -1)
3603         (setq gnus-tmp-lines "?")
3604       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3605       (gnus-put-text-property
3606      (point)
3607      (progn (eval gnus-summary-line-format-spec) (point))
3608        'gnus-number gnus-tmp-number)
3609     (when (gnus-visual-p 'summary-highlight 'highlight)
3610       (forward-line -1)
3611       (gnus-run-hooks 'gnus-summary-update-hook)
3612       (forward-line 1))))
3613
3614 (defun gnus-summary-update-line (&optional dont-update)
3615   "Update summary line after change."
3616   (when (and gnus-summary-default-score
3617              (not gnus-summary-inhibit-highlight))
3618     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3619            (article (gnus-summary-article-number))
3620            (score (gnus-summary-article-score article)))
3621       (unless dont-update
3622         (if (and gnus-summary-mark-below
3623                  (< (gnus-summary-article-score)
3624                     gnus-summary-mark-below))
3625             ;; This article has a low score, so we mark it as read.
3626             (when (memq article gnus-newsgroup-unreads)
3627               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3628           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3629             ;; This article was previously marked as read on account
3630             ;; of a low score, but now it has risen, so we mark it as
3631             ;; unread.
3632             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3633         (gnus-summary-update-mark
3634          (if (or (null gnus-summary-default-score)
3635                  (<= (abs (- score gnus-summary-default-score))
3636                      gnus-summary-zcore-fuzz))
3637              ?                          ;Whitespace
3638            (if (< score gnus-summary-default-score)
3639                gnus-score-below-mark gnus-score-over-mark))
3640          'score))
3641       ;; Do visual highlighting.
3642       (when (gnus-visual-p 'summary-highlight 'highlight)
3643         (gnus-run-hooks 'gnus-summary-update-hook)))))
3644
3645 (defvar gnus-tmp-new-adopts nil)
3646
3647 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3648   "Return the number of articles in THREAD.
3649 This may be 0 in some cases -- if none of the articles in
3650 the thread are to be displayed."
3651   (let* ((number
3652          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3653           (cond
3654            ((not (listp thread))
3655             1)
3656            ((and (consp thread) (cdr thread))
3657             (apply
3658              '+ 1 (mapcar
3659                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3660            ((null thread)
3661             1)
3662            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3663             1)
3664            (t 0))))
3665     (when (and level (zerop level) gnus-tmp-new-adopts)
3666       (incf number
3667             (apply '+ (mapcar
3668                        'gnus-summary-number-of-articles-in-thread
3669                        gnus-tmp-new-adopts))))
3670     (if char
3671         (if (> number 1) gnus-not-empty-thread-mark
3672           gnus-empty-thread-mark)
3673       number)))
3674
3675 (defsubst gnus-summary-line-message-size (head)
3676   "Return pretty-printed version of message size.
3677 This function is intended to be used in
3678 `gnus-summary-line-format-alist'."
3679   (let ((c (or (mail-header-chars head) -1)))
3680     (cond ((< c 0) "n/a")               ; chars not available
3681           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3682           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3683           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3684           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3685
3686
3687 (defun gnus-summary-set-local-parameters (group)
3688   "Go through the local params of GROUP and set all variable specs in that list."
3689   (let ((vars '(quit-config)))          ; Ignore quit-config.
3690     (dolist (elem (gnus-group-find-parameter group))
3691       (and (consp elem)                 ; Has to be a cons.
3692            (consp (cdr elem))           ; The cdr has to be a list.
3693            (symbolp (car elem))         ; Has to be a symbol in there.
3694            (not (memq (car elem) vars))
3695            (ignore-errors               ; So we set it.
3696              (push (car elem) vars)
3697              (make-local-variable (car elem))
3698              (set (car elem) (eval (nth 1 elem))))))))
3699
3700 (defun gnus-summary-read-group (group &optional show-all no-article
3701                                       kill-buffer no-display backward
3702                                       select-articles)
3703   "Start reading news in newsgroup GROUP.
3704 If SHOW-ALL is non-nil, already read articles are also listed.
3705 If NO-ARTICLE is non-nil, no article is selected initially.
3706 If NO-DISPLAY, don't generate a summary buffer."
3707   (let (result)
3708     (while (and group
3709                 (null (setq result
3710                             (let ((gnus-auto-select-next nil))
3711                               (or (gnus-summary-read-group-1
3712                                    group show-all no-article
3713                                    kill-buffer no-display
3714                                    select-articles)
3715                                   (setq show-all nil
3716                                         select-articles nil)))))
3717                 (eq gnus-auto-select-next 'quietly))
3718       (set-buffer gnus-group-buffer)
3719       ;; The entry function called above goes to the next
3720       ;; group automatically, so we go two groups back
3721       ;; if we are searching for the previous group.
3722       (when backward
3723         (gnus-group-prev-unread-group 2))
3724       (if (not (equal group (gnus-group-group-name)))
3725           (setq group (gnus-group-group-name))
3726         (setq group nil)))
3727     result))
3728
3729 (defun gnus-summary-read-group-1 (group show-all no-article
3730                                         kill-buffer no-display
3731                                         &optional select-articles)
3732   ;; Killed foreign groups can't be entered.
3733   ;;  (when (and (not (gnus-group-native-p group))
3734   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3735   ;;    (error "Dead non-native groups can't be entered"))
3736   (gnus-message 5 "Retrieving newsgroup: %s..."
3737                 (gnus-group-decoded-name group))
3738   (let* ((new-group (gnus-summary-setup-buffer group))
3739          (quit-config (gnus-group-quit-config group))
3740          (did-select (and new-group (gnus-select-newsgroup
3741                                      group show-all select-articles))))
3742     (cond
3743      ;; This summary buffer exists already, so we just select it.
3744      ((not new-group)
3745       (gnus-set-global-variables)
3746       (when kill-buffer
3747         (gnus-kill-or-deaden-summary kill-buffer))
3748       (gnus-configure-windows 'summary 'force)
3749       (gnus-set-mode-line 'summary)
3750       (gnus-summary-position-point)
3751       (message "")
3752       t)
3753      ;; We couldn't select this group.
3754      ((null did-select)
3755       (when (and (eq major-mode 'gnus-summary-mode)
3756                  (not (equal (current-buffer) kill-buffer)))
3757         (kill-buffer (current-buffer))
3758         (if (not quit-config)
3759             (progn
3760               ;; Update the info -- marks might need to be removed,
3761               ;; for instance.
3762               (gnus-summary-update-info)
3763               (set-buffer gnus-group-buffer)
3764               (gnus-group-jump-to-group group)
3765               (gnus-group-next-unread-group 1))
3766           (gnus-handle-ephemeral-exit quit-config)))
3767       (let ((grpinfo (gnus-get-info group)))
3768         (if (null (gnus-info-read grpinfo))
3769             (gnus-message 3 "Group %s contains no messages"
3770                           (gnus-group-decoded-name group))
3771           (gnus-message 3 "Can't select group")))
3772       nil)
3773      ;; The user did a `C-g' while prompting for number of articles,
3774      ;; so we exit this group.
3775      ((eq did-select 'quit)
3776       (and (eq major-mode 'gnus-summary-mode)
3777            (not (equal (current-buffer) kill-buffer))
3778            (kill-buffer (current-buffer)))
3779       (when kill-buffer
3780         (gnus-kill-or-deaden-summary kill-buffer))
3781       (if (not quit-config)
3782           (progn
3783             (set-buffer gnus-group-buffer)
3784             (gnus-group-jump-to-group group)
3785             (gnus-group-next-unread-group 1)
3786             (gnus-configure-windows 'group 'force))
3787         (gnus-handle-ephemeral-exit quit-config))
3788       ;; Finally signal the quit.
3789       (signal 'quit nil))
3790      ;; The group was successfully selected.
3791      (t
3792       (gnus-set-global-variables)
3793       ;; Save the active value in effect when the group was entered.
3794       (setq gnus-newsgroup-active
3795             (gnus-copy-sequence
3796              (gnus-active gnus-newsgroup-name)))
3797       ;; You can change the summary buffer in some way with this hook.
3798       (gnus-run-hooks 'gnus-select-group-hook)
3799       (when (memq 'summary (gnus-update-format-specifications
3800                             nil 'summary 'summary-mode 'summary-dummy))
3801         ;; The format specification for the summary line was updated,
3802         ;; so we need to update the mark positions as well.
3803         (gnus-update-summary-mark-positions))
3804       ;; Do score processing.
3805       (when gnus-use-scoring
3806         (gnus-possibly-score-headers))
3807       ;; Check whether to fill in the gaps in the threads.
3808       (when gnus-build-sparse-threads
3809         (gnus-build-sparse-threads))
3810       ;; Find the initial limit.
3811       (if show-all
3812           (let ((gnus-newsgroup-dormant nil))
3813             (gnus-summary-initial-limit show-all))
3814         (gnus-summary-initial-limit show-all))
3815       ;; Generate the summary buffer.
3816       (unless no-display
3817         (gnus-summary-prepare))
3818       (when gnus-use-trees
3819         (gnus-tree-open group)
3820         (setq gnus-summary-highlight-line-function
3821               'gnus-tree-highlight-article))
3822       ;; If the summary buffer is empty, but there are some low-scored
3823       ;; articles or some excluded dormants, we include these in the
3824       ;; buffer.
3825       (when (and (zerop (buffer-size))
3826                  (not no-display))
3827         (cond (gnus-newsgroup-dormant
3828                (gnus-summary-limit-include-dormant))
3829               ((and gnus-newsgroup-scored show-all)
3830                (gnus-summary-limit-include-expunged t))))
3831       ;; Function `gnus-apply-kill-file' must be called in this hook.
3832       (gnus-run-hooks 'gnus-apply-kill-hook)
3833       (if (and (zerop (buffer-size))
3834                (not no-display))
3835           (progn
3836             ;; This newsgroup is empty.
3837             (gnus-summary-catchup-and-exit nil t)
3838             (gnus-message 6 "No unread news")
3839             (when kill-buffer
3840               (gnus-kill-or-deaden-summary kill-buffer))
3841             ;; Return nil from this function.
3842             nil)
3843         ;; Hide conversation thread subtrees.  We cannot do this in
3844         ;; gnus-summary-prepare-hook since kill processing may not
3845         ;; work with hidden articles.
3846         (gnus-summary-maybe-hide-threads)
3847         (when kill-buffer
3848           (gnus-kill-or-deaden-summary kill-buffer))
3849         (gnus-summary-auto-select-subject)
3850         ;; Show first unread article if requested.
3851         (if (and (not no-article)
3852                  (not no-display)
3853                  gnus-newsgroup-unreads
3854                  gnus-auto-select-first)
3855             (progn
3856               (gnus-configure-windows 'summary)
3857               (let ((art (gnus-summary-article-number)))
3858                 (unless (and (not gnus-plugged)
3859                              (or (memq art gnus-newsgroup-undownloaded)
3860                                  (memq art gnus-newsgroup-downloadable)))
3861                   (gnus-summary-goto-article art))))
3862           ;; Don't select any articles.
3863           (gnus-summary-position-point)
3864           (gnus-configure-windows 'summary 'force)
3865           (gnus-set-mode-line 'summary))
3866         (when (and gnus-auto-center-group
3867                    (get-buffer-window gnus-group-buffer t))
3868           ;; Gotta use windows, because recenter does weird stuff if
3869           ;; the current buffer ain't the displayed window.
3870           (let ((owin (selected-window)))
3871             (select-window (get-buffer-window gnus-group-buffer t))
3872             (when (gnus-group-goto-group group)
3873               (recenter))
3874             (select-window owin)))
3875         ;; Mark this buffer as "prepared".
3876         (setq gnus-newsgroup-prepared t)
3877         (gnus-run-hooks 'gnus-summary-prepared-hook)
3878         (unless (gnus-ephemeral-group-p group)
3879           (gnus-group-update-group group))
3880         t)))))
3881
3882 (defun gnus-summary-auto-select-subject ()
3883   "Select the subject line on initial group entry."
3884   (goto-char (point-min))
3885   (cond
3886    ((eq gnus-auto-select-subject 'best)
3887     (gnus-summary-best-unread-subject))
3888    ((eq gnus-auto-select-subject 'unread)
3889     (gnus-summary-first-unread-subject))
3890    ((eq gnus-auto-select-subject 'unseen)
3891     (gnus-summary-first-unseen-subject))
3892    ((eq gnus-auto-select-subject 'unseen-or-unread)
3893     (gnus-summary-first-unseen-or-unread-subject))
3894    ((eq gnus-auto-select-subject 'first)
3895     ;; Do nothing.
3896     )
3897    ((functionp gnus-auto-select-subject)
3898     (funcall gnus-auto-select-subject))))
3899
3900 (defun gnus-summary-prepare ()
3901   "Generate the summary buffer."
3902   (interactive)
3903   (let ((buffer-read-only nil))
3904     (erase-buffer)
3905     (setq gnus-newsgroup-data nil
3906           gnus-newsgroup-data-reverse nil)
3907     (gnus-run-hooks 'gnus-summary-generate-hook)
3908     ;; Generate the buffer, either with threads or without.
3909     (when gnus-newsgroup-headers
3910       (gnus-summary-prepare-threads
3911        (if gnus-show-threads
3912            (gnus-sort-gathered-threads
3913             (funcall gnus-summary-thread-gathering-function
3914                      (gnus-sort-threads
3915                       (gnus-cut-threads (gnus-make-threads)))))
3916          ;; Unthreaded display.
3917          (gnus-sort-articles gnus-newsgroup-headers))))
3918     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3919     ;; Call hooks for modifying summary buffer.
3920     (goto-char (point-min))
3921     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3922
3923 (defsubst gnus-general-simplify-subject (subject)
3924   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3925   (setq subject
3926         (cond
3927          ;; Truncate the subject.
3928          (gnus-simplify-subject-functions
3929           (gnus-map-function gnus-simplify-subject-functions subject))
3930          ((numberp gnus-summary-gather-subject-limit)
3931           (setq subject (gnus-simplify-subject-re subject))
3932           (if (> (length subject) gnus-summary-gather-subject-limit)
3933               (substring subject 0 gnus-summary-gather-subject-limit)
3934             subject))
3935          ;; Fuzzily simplify it.
3936          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3937           (gnus-simplify-subject-fuzzy subject))
3938          ;; Just remove the leading "Re:".
3939          (t
3940           (gnus-simplify-subject-re subject))))
3941
3942   (if (and gnus-summary-gather-exclude-subject
3943            (string-match gnus-summary-gather-exclude-subject subject))
3944       nil                         ; This article shouldn't be gathered
3945     subject))
3946
3947 (defun gnus-summary-simplify-subject-query ()
3948   "Query where the respool algorithm would put this article."
3949   (interactive)
3950   (gnus-summary-select-article)
3951   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3952
3953 (defun gnus-gather-threads-by-subject (threads)
3954   "Gather threads by looking at Subject headers."
3955   (if (not gnus-summary-make-false-root)
3956       threads
3957     (let ((hashtb (gnus-make-hashtable 1024))
3958           (prev threads)
3959           (result threads)
3960           subject hthread whole-subject)
3961       (while threads
3962         (setq subject (gnus-general-simplify-subject
3963                        (setq whole-subject (mail-header-subject
3964                                             (caar threads)))))
3965         (when subject
3966           (if (setq hthread (gnus-gethash subject hashtb))
3967               (progn
3968                 ;; We enter a dummy root into the thread, if we
3969                 ;; haven't done that already.
3970                 (unless (stringp (caar hthread))
3971                   (setcar hthread (list whole-subject (car hthread))))
3972                 ;; We add this new gathered thread to this gathered
3973                 ;; thread.
3974                 (setcdr (car hthread)
3975                         (nconc (cdar hthread) (list (car threads))))
3976                 ;; Remove it from the list of threads.
3977                 (setcdr prev (cdr threads))
3978                 (setq threads prev))
3979             ;; Enter this thread into the hash table.
3980             (gnus-sethash subject
3981                           (if gnus-summary-make-false-root-always
3982                               (progn
3983                                 ;; If you want a dummy root above all
3984                                 ;; threads...
3985                                 (setcar threads (list whole-subject
3986                                                       (car threads)))
3987                                 threads)
3988                             threads)
3989                           hashtb)))
3990         (setq prev threads)
3991         (setq threads (cdr threads)))
3992       result)))
3993
3994 (defun gnus-gather-threads-by-references (threads)
3995   "Gather threads by looking at References headers."
3996   (let ((idhashtb (gnus-make-hashtable 1024))
3997         (thhashtb (gnus-make-hashtable 1024))
3998         (prev threads)
3999         (result threads)
4000         ids references id gthread gid entered ref)
4001     (while threads
4002       (when (setq references (mail-header-references (caar threads)))
4003         (setq id (mail-header-id (caar threads))
4004               ids (inline (gnus-split-references references))
4005               entered nil)
4006         (while (setq ref (pop ids))
4007           (setq ids (delete ref ids))
4008           (if (not (setq gid (gnus-gethash ref idhashtb)))
4009               (progn
4010                 (gnus-sethash ref id idhashtb)
4011                 (gnus-sethash id threads thhashtb))
4012             (setq gthread (gnus-gethash gid thhashtb))
4013             (unless entered
4014               ;; We enter a dummy root into the thread, if we
4015               ;; haven't done that already.
4016               (unless (stringp (caar gthread))
4017                 (setcar gthread (list (mail-header-subject (caar gthread))
4018                                       (car gthread))))
4019               ;; We add this new gathered thread to this gathered
4020               ;; thread.
4021               (setcdr (car gthread)
4022                       (nconc (cdar gthread) (list (car threads)))))
4023             ;; Add it into the thread hash table.
4024             (gnus-sethash id gthread thhashtb)
4025             (setq entered t)
4026             ;; Remove it from the list of threads.
4027             (setcdr prev (cdr threads))
4028             (setq threads prev))))
4029       (setq prev threads)
4030       (setq threads (cdr threads)))
4031     result))
4032
4033 (defun gnus-sort-gathered-threads (threads)
4034   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4035   (let ((result threads))
4036     (while threads
4037       (when (stringp (caar threads))
4038         (setcdr (car threads)
4039                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4040       (setq threads (cdr threads)))
4041     result))
4042
4043 (defun gnus-thread-loop-p (root thread)
4044   "Say whether ROOT is in THREAD."
4045   (let ((stack (list thread))
4046         (infloop 0)
4047         th)
4048     (while (setq thread (pop stack))
4049       (setq th (cdr thread))
4050       (while (and th
4051                   (not (eq (caar th) root)))
4052         (pop th))
4053       (if th
4054           ;; We have found a loop.
4055           (let (ref-dep)
4056             (setcdr thread (delq (car th) (cdr thread)))
4057             (if (boundp (setq ref-dep (intern "none"
4058                                               gnus-newsgroup-dependencies)))
4059                 (setcdr (symbol-value ref-dep)
4060                         (nconc (cdr (symbol-value ref-dep))
4061                                (list (car th))))
4062               (set ref-dep (list nil (car th))))
4063             (setq infloop 1
4064                   stack nil))
4065         ;; Push all the subthreads onto the stack.
4066         (push (cdr thread) stack)))
4067     infloop))
4068
4069 (defun gnus-make-threads ()
4070   "Go through the dependency hashtb and find the roots.  Return all threads."
4071   (let (threads)
4072     (while (catch 'infloop
4073              (mapatoms
4074               (lambda (refs)
4075                 ;; Deal with self-referencing References loops.
4076                 (when (and (car (symbol-value refs))
4077                            (not (zerop
4078                                  (apply
4079                                   '+
4080                                   (mapcar
4081                                    (lambda (thread)
4082                                      (gnus-thread-loop-p
4083                                       (car (symbol-value refs)) thread))
4084                                    (cdr (symbol-value refs)))))))
4085                   (setq threads nil)
4086                   (throw 'infloop t))
4087                 (unless (car (symbol-value refs))
4088                   ;; These threads do not refer back to any other
4089                   ;; articles, so they're roots.
4090                   (setq threads (append (cdr (symbol-value refs)) threads))))
4091               gnus-newsgroup-dependencies)))
4092     threads))
4093
4094 ;; Build the thread tree.
4095 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4096   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4097
4098 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4099 if it was already present.
4100
4101 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4102 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4103 Message-IDs will be renamed to a unique Message-ID before being
4104 entered.
4105
4106 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4107   (let* ((id (mail-header-id header))
4108          (id-dep (and id (intern id dependencies)))
4109          parent-id ref ref-dep ref-header replaced)
4110     ;; Enter this `header' in the `dependencies' table.
4111     (cond
4112      ((not id-dep)
4113       (setq header nil))
4114      ;; The first two cases do the normal part: enter a new `header'
4115      ;; in the `dependencies' table.
4116      ((not (boundp id-dep))
4117       (set id-dep (list header)))
4118      ((null (car (symbol-value id-dep)))
4119       (setcar (symbol-value id-dep) header))
4120
4121      ;; From here the `header' was already present in the
4122      ;; `dependencies' table.
4123      (force-new
4124       ;; Overrides an existing entry;
4125       ;; just set the header part of the entry.
4126       (setcar (symbol-value id-dep) header)
4127       (setq replaced t))
4128
4129      ;; Renames the existing `header' to a unique Message-ID.
4130      ((not gnus-summary-ignore-duplicates)
4131       ;; An article with this Message-ID has already been seen.
4132       ;; We rename the Message-ID.
4133       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4134            (list header))
4135       (mail-header-set-id header id))
4136
4137      ;; The last case ignores an existing entry, except it adds any
4138      ;; additional Xrefs (in case the two articles came from different
4139      ;; servers.
4140      ;; Also sets `header' to `nil' meaning that the `dependencies'
4141      ;; table was *not* modified.
4142      (t
4143       (mail-header-set-xref
4144        (car (symbol-value id-dep))
4145        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4146                    "")
4147                (or (mail-header-xref header) "")))
4148       (setq header nil)))
4149
4150     (when (and header (not replaced))
4151       ;; First check that we are not creating a References loop.
4152       (setq parent-id (gnus-parent-id (mail-header-references header)))
4153       (setq ref parent-id)
4154       (while (and ref
4155                   (setq ref-dep (intern-soft ref dependencies))
4156                   (boundp ref-dep)
4157                   (setq ref-header (car (symbol-value ref-dep))))
4158         (if (string= id ref)
4159             ;; Yuk!  This is a reference loop.  Make the article be a
4160             ;; root article.
4161             (progn
4162               (mail-header-set-references (car (symbol-value id-dep)) "none")
4163               (setq ref nil)
4164               (setq parent-id nil))
4165           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4166       (setq ref-dep (intern (or parent-id "none") dependencies))
4167       (if (boundp ref-dep)
4168           (setcdr (symbol-value ref-dep)
4169                   (nconc (cdr (symbol-value ref-dep))
4170                          (list (symbol-value id-dep))))
4171         (set ref-dep (list nil (symbol-value id-dep)))))
4172     header))
4173
4174 (defun gnus-extract-message-id-from-in-reply-to (string)
4175   (if (string-match "<[^>]+>" string)
4176       (substring string (match-beginning 0) (match-end 0))
4177     nil))
4178
4179 (defun gnus-build-sparse-threads ()
4180   (let ((headers gnus-newsgroup-headers)
4181         (mail-parse-charset gnus-newsgroup-charset)
4182         (gnus-summary-ignore-duplicates t)
4183         header references generation relations
4184         subject child end new-child date)
4185     ;; First we create an alist of generations/relations, where
4186     ;; generations is how much we trust the relation, and the relation
4187     ;; is parent/child.
4188     (gnus-message 7 "Making sparse threads...")
4189     (save-excursion
4190       (nnheader-set-temp-buffer " *gnus sparse threads*")
4191       (while (setq header (pop headers))
4192         (when (and (setq references (mail-header-references header))
4193                    (not (string= references "")))
4194           (insert references)
4195           (setq child (mail-header-id header)
4196                 subject (mail-header-subject header)
4197                 date (mail-header-date header)
4198                 generation 0)
4199           (while (search-backward ">" nil t)
4200             (setq end (1+ (point)))
4201             (when (search-backward "<" nil t)
4202               (setq new-child (buffer-substring (point) end))
4203               (push (list (incf generation)
4204                           child (setq child new-child)
4205                           subject date)
4206                     relations)))
4207           (when child
4208             (push (list (1+ generation) child nil subject) relations))
4209           (erase-buffer)))
4210       (kill-buffer (current-buffer)))
4211     ;; Sort over trustworthiness.
4212     (mapcar
4213      (lambda (relation)
4214        (when (gnus-dependencies-add-header
4215               (make-full-mail-header
4216                gnus-reffed-article-number
4217                (nth 3 relation) "" (or (nth 4 relation) "")
4218                (nth 1 relation)
4219                (or (nth 2 relation) "") 0 0 "")
4220               gnus-newsgroup-dependencies nil)
4221          (push gnus-reffed-article-number gnus-newsgroup-limit)
4222          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4223          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4224                gnus-newsgroup-reads)
4225          (decf gnus-reffed-article-number)))
4226      (sort relations 'car-less-than-car))
4227     (gnus-message 7 "Making sparse threads...done")))
4228
4229 (defun gnus-build-old-threads ()
4230   ;; Look at all the articles that refer back to old articles, and
4231   ;; fetch the headers for the articles that aren't there.  This will
4232   ;; build complete threads - if the roots haven't been expired by the
4233   ;; server, that is.
4234   (let ((mail-parse-charset gnus-newsgroup-charset)
4235         id heads)
4236     (mapatoms
4237      (lambda (refs)
4238        (when (not (car (symbol-value refs)))
4239          (setq heads (cdr (symbol-value refs)))
4240          (while heads
4241            (if (memq (mail-header-number (caar heads))
4242                      gnus-newsgroup-dormant)
4243                (setq heads (cdr heads))
4244              (setq id (symbol-name refs))
4245              (while (and (setq id (gnus-build-get-header id))
4246                          (not (car (gnus-id-to-thread id)))))
4247              (setq heads nil)))))
4248      gnus-newsgroup-dependencies)))
4249
4250 (defsubst gnus-remove-odd-characters (string)
4251   "Translate STRING into something that doesn't contain weird characters."
4252   (mm-subst-char-in-string
4253    ?\r ?\-
4254    (mm-subst-char-in-string ?\n ?\- string t) t))
4255
4256 ;; This function has to be called with point after the article number
4257 ;; on the beginning of the line.
4258 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4259   (let ((eol (point-at-eol))
4260         (buffer (current-buffer))
4261         header references in-reply-to)
4262
4263     ;; overview: [num subject from date id refs chars lines misc]
4264     (unwind-protect
4265         (let (x)
4266           (narrow-to-region (point) eol)
4267           (unless (eobp)
4268             (forward-char))
4269
4270           (setq header
4271                 (make-full-mail-header
4272                  number                 ; number
4273                  (condition-case ()     ; subject
4274                      (gnus-remove-odd-characters
4275                       (funcall gnus-decode-encoded-word-function
4276                                (setq x (nnheader-nov-field))))
4277                    (error x))
4278                  (condition-case ()     ; from
4279                      (gnus-remove-odd-characters
4280                       (funcall gnus-decode-encoded-word-function
4281                                (setq x (nnheader-nov-field))))
4282                    (error x))
4283                  (nnheader-nov-field)   ; date
4284                  (nnheader-nov-read-message-id number)  ; id
4285                  (setq references (nnheader-nov-field)) ; refs
4286                  (nnheader-nov-read-integer) ; chars
4287                  (nnheader-nov-read-integer) ; lines
4288                  (unless (eobp)
4289                    (if (looking-at "Xref: ")
4290                        (goto-char (match-end 0)))
4291                    (nnheader-nov-field)) ; Xref
4292                  (nnheader-nov-parse-extra)))) ; extra
4293
4294       (widen))
4295
4296     (when (and (string= references "")
4297                (setq in-reply-to (mail-header-extra header))
4298                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4299       (mail-header-set-references
4300        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4301
4302     (when gnus-alter-header-function
4303       (funcall gnus-alter-header-function header))
4304     (gnus-dependencies-add-header header dependencies force-new)))
4305
4306 (defun gnus-build-get-header (id)
4307   "Look through the buffer of NOV lines and find the header to ID.
4308 Enter this line into the dependencies hash table, and return
4309 the id of the parent article (if any)."
4310   (let ((deps gnus-newsgroup-dependencies)
4311         found header)
4312     (prog1
4313         (save-excursion
4314           (set-buffer nntp-server-buffer)
4315           (let ((case-fold-search nil))
4316             (goto-char (point-min))
4317             (while (and (not found)
4318                         (search-forward id nil t))
4319               (beginning-of-line)
4320               (setq found (looking-at
4321                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4322                                    (regexp-quote id))))
4323               (or found (beginning-of-line 2)))
4324             (when found
4325               (beginning-of-line)
4326               (and
4327                (setq header (gnus-nov-parse-line
4328                              (read (current-buffer)) deps))
4329                (gnus-parent-id (mail-header-references header))))))
4330       (when header
4331         (let ((number (mail-header-number header)))
4332           (push number gnus-newsgroup-limit)
4333           (push header gnus-newsgroup-headers)
4334           (if (memq number gnus-newsgroup-unselected)
4335               (progn
4336                 (setq gnus-newsgroup-unreads
4337                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4338                                                number))
4339                 (setq gnus-newsgroup-unselected
4340                       (delq number gnus-newsgroup-unselected)))
4341             (push number gnus-newsgroup-ancient)))))))
4342
4343 (defun gnus-build-all-threads ()
4344   "Read all the headers."
4345   (let ((gnus-summary-ignore-duplicates t)
4346         (mail-parse-charset gnus-newsgroup-charset)
4347         (dependencies gnus-newsgroup-dependencies)
4348         header article)
4349     (save-excursion
4350       (set-buffer nntp-server-buffer)
4351       (let ((case-fold-search nil))
4352         (goto-char (point-min))
4353         (while (not (eobp))
4354           (ignore-errors
4355             (setq article (read (current-buffer))
4356                   header (gnus-nov-parse-line article dependencies)))
4357           (when header
4358             (with-current-buffer gnus-summary-buffer
4359               (push header gnus-newsgroup-headers)
4360               (if (memq (setq article (mail-header-number header))
4361                         gnus-newsgroup-unselected)
4362                   (progn
4363                     (setq gnus-newsgroup-unreads
4364                           (gnus-add-to-sorted-list
4365                            gnus-newsgroup-unreads article))
4366                     (setq gnus-newsgroup-unselected
4367                           (delq article gnus-newsgroup-unselected)))
4368                 (push article gnus-newsgroup-ancient)))
4369             (forward-line 1)))))))
4370
4371 (defun gnus-summary-update-article-line (article header)
4372   "Update the line for ARTICLE using HEADER."
4373   (let* ((id (mail-header-id header))
4374          (thread (gnus-id-to-thread id)))
4375     (unless thread
4376       (error "Article in no thread"))
4377     ;; Update the thread.
4378     (setcar thread header)
4379     (gnus-summary-goto-subject article)
4380     (let* ((datal (gnus-data-find-list article))
4381            (data (car datal))
4382            (buffer-read-only nil)
4383            (level (gnus-summary-thread-level)))
4384       (gnus-delete-line)
4385       (let ((inserted (- (point)
4386                          (progn
4387                            (gnus-summary-insert-line
4388                             header level nil
4389                             (memq article gnus-newsgroup-undownloaded)
4390                             (gnus-article-mark article)
4391                             (memq article gnus-newsgroup-replied)
4392                             (memq article gnus-newsgroup-expirable)
4393                             ;; Only insert the Subject string when it's different
4394                             ;; from the previous Subject string.
4395                             (if (and
4396                                  gnus-show-threads
4397                                  (gnus-subject-equal
4398                                   (condition-case ()
4399                                       (mail-header-subject
4400                                        (gnus-data-header
4401                                         (cadr
4402                                          (gnus-data-find-list
4403                                           article
4404                                           (gnus-data-list t)))))
4405                                     ;; Error on the side of excessive subjects.
4406                                     (error ""))
4407                                   (mail-header-subject header)))
4408                                 ""
4409                               (mail-header-subject header))
4410                             nil (cdr (assq article gnus-newsgroup-scored))
4411                             (memq article gnus-newsgroup-processable))
4412                            (point)))))
4413         (when (cdr datal)
4414           (gnus-data-update-list
4415            (cdr datal)
4416            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4417
4418 (defun gnus-summary-update-article (article &optional iheader)
4419   "Update ARTICLE in the summary buffer."
4420   (set-buffer gnus-summary-buffer)
4421   (let* ((header (gnus-summary-article-header article))
4422          (id (mail-header-id header))
4423          (data (gnus-data-find article))
4424          (thread (gnus-id-to-thread id))
4425          (references (mail-header-references header))
4426          (parent
4427           (gnus-id-to-thread
4428            (or (gnus-parent-id
4429                 (when (and references
4430                            (not (equal "" references)))
4431                   references))
4432                "none")))
4433          (buffer-read-only nil)
4434          (old (car thread)))
4435     (when thread
4436       (unless iheader
4437         (setcar thread nil)
4438         (when parent
4439           (delq thread parent)))
4440       (if (gnus-summary-insert-subject id header)
4441           ;; Set the (possibly) new article number in the data structure.
4442           (gnus-data-set-number data (gnus-id-to-article id))
4443         (setcar thread old)
4444         nil))))
4445
4446 (defun gnus-rebuild-thread (id &optional line)
4447   "Rebuild the thread containing ID.
4448 If LINE, insert the rebuilt thread starting on line LINE."
4449   (let ((buffer-read-only nil)
4450         old-pos current thread data)
4451     (if (not gnus-show-threads)
4452         (setq thread (list (car (gnus-id-to-thread id))))
4453       ;; Get the thread this article is part of.
4454       (setq thread (gnus-remove-thread id)))
4455     (setq old-pos (point-at-bol))
4456     (setq current (save-excursion
4457                     (and (re-search-backward "[\r\n]" nil t)
4458                          (gnus-summary-article-number))))
4459     ;; If this is a gathered thread, we have to go some re-gathering.
4460     (when (stringp (car thread))
4461       (let ((subject (car thread))
4462             roots thr)
4463         (setq thread (cdr thread))
4464         (while thread
4465           (unless (memq (setq thr (gnus-id-to-thread
4466                                    (gnus-root-id
4467                                     (mail-header-id (caar thread)))))
4468                         roots)
4469             (push thr roots))
4470           (setq thread (cdr thread)))
4471         ;; We now have all (unique) roots.
4472         (if (= (length roots) 1)
4473             ;; All the loose roots are now one solid root.
4474             (setq thread (car roots))
4475           (setq thread (cons subject (gnus-sort-threads roots))))))
4476     (let (threads)
4477       ;; We then insert this thread into the summary buffer.
4478       (when line
4479         (goto-char (point-min))
4480         (forward-line (1- line)))
4481       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4482         (if gnus-show-threads
4483             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4484           (gnus-summary-prepare-unthreaded thread))
4485         (setq data (nreverse gnus-newsgroup-data))
4486         (setq threads gnus-newsgroup-threads))
4487       ;; We splice the new data into the data structure.
4488       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4489       ;;!!! then we want to insert at the beginning of the buffer.
4490       ;;!!! That happens to be true with Gnus now, but that may
4491       ;;!!! change in the future.  Perhaps.
4492       (gnus-data-enter-list
4493        (if line nil current) data (- (point) old-pos))
4494       (setq gnus-newsgroup-threads
4495             (nconc threads gnus-newsgroup-threads))
4496       (gnus-data-compute-positions))))
4497
4498 (defun gnus-number-to-header (number)
4499   "Return the header for article NUMBER."
4500   (let ((headers gnus-newsgroup-headers))
4501     (while (and headers
4502                 (not (= number (mail-header-number (car headers)))))
4503       (pop headers))
4504     (when headers
4505       (car headers))))
4506
4507 (defun gnus-parent-headers (in-headers &optional generation)
4508   "Return the headers of the GENERATIONeth parent of HEADERS."
4509   (unless generation
4510     (setq generation 1))
4511   (let ((parent t)
4512         (headers in-headers)
4513         references)
4514     (while (and parent
4515                 (not (zerop generation))
4516                 (setq references (mail-header-references headers)))
4517       (setq headers (if (and references
4518                              (setq parent (gnus-parent-id references)))
4519                         (car (gnus-id-to-thread parent))
4520                       nil))
4521       (decf generation))
4522     (and (not (eq headers in-headers))
4523          headers)))
4524
4525 (defun gnus-id-to-thread (id)
4526   "Return the (sub-)thread where ID appears."
4527   (gnus-gethash id gnus-newsgroup-dependencies))
4528
4529 (defun gnus-id-to-article (id)
4530   "Return the article number of ID."
4531   (let ((thread (gnus-id-to-thread id)))
4532     (when (and thread
4533                (car thread))
4534       (mail-header-number (car thread)))))
4535
4536 (defun gnus-id-to-header (id)
4537   "Return the article headers of ID."
4538   (car (gnus-id-to-thread id)))
4539
4540 (defun gnus-article-displayed-root-p (article)
4541   "Say whether ARTICLE is a root(ish) article."
4542   (let ((level (gnus-summary-thread-level article))
4543         (refs (mail-header-references  (gnus-summary-article-header article)))
4544         particle)
4545     (cond
4546      ((null level) nil)
4547      ((zerop level) t)
4548      ((null refs) t)
4549      ((null (gnus-parent-id refs)) t)
4550      ((and (= 1 level)
4551            (null (setq particle (gnus-id-to-article
4552                                  (gnus-parent-id refs))))
4553            (null (gnus-summary-thread-level particle)))))))
4554
4555 (defun gnus-root-id (id)
4556   "Return the id of the root of the thread where ID appears."
4557   (let (last-id prev)
4558     (while (and id (setq prev (car (gnus-id-to-thread id))))
4559       (setq last-id id
4560             id (gnus-parent-id (mail-header-references prev))))
4561     last-id))
4562
4563 (defun gnus-articles-in-thread (thread)
4564   "Return the list of articles in THREAD."
4565   (cons (mail-header-number (car thread))
4566         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4567
4568 (defun gnus-remove-thread (id &optional dont-remove)
4569   "Remove the thread that has ID in it."
4570   (let (headers thread last-id)
4571     ;; First go up in this thread until we find the root.
4572     (setq last-id (gnus-root-id id)
4573           headers (message-flatten-list (gnus-id-to-thread last-id)))
4574     ;; We have now found the real root of this thread.  It might have
4575     ;; been gathered into some loose thread, so we have to search
4576     ;; through the threads to find the thread we wanted.
4577     (let ((threads gnus-newsgroup-threads)
4578           sub)
4579       (while threads
4580         (setq sub (car threads))
4581         (if (stringp (car sub))
4582             ;; This is a gathered thread, so we look at the roots
4583             ;; below it to find whether this article is in this
4584             ;; gathered root.
4585             (progn
4586               (setq sub (cdr sub))
4587               (while sub
4588                 (when (member (caar sub) headers)
4589                   (setq thread (car threads)
4590                         threads nil
4591                         sub nil))
4592                 (setq sub (cdr sub))))
4593           ;; It's an ordinary thread, so we check it.
4594           (when (eq (car sub) (car headers))
4595             (setq thread sub
4596                   threads nil)))
4597         (setq threads (cdr threads)))
4598       ;; If this article is in no thread, then it's a root.
4599       (if thread
4600           (unless dont-remove
4601             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4602         (setq thread (gnus-id-to-thread last-id)))
4603       (when thread
4604         (prog1
4605             thread                      ; We return this thread.
4606           (unless dont-remove
4607             (if (stringp (car thread))
4608                 (progn
4609                   ;; If we use dummy roots, then we have to remove the
4610                   ;; dummy root as well.
4611                   (when (eq gnus-summary-make-false-root 'dummy)
4612                     ;; We go to the dummy root by going to
4613                     ;; the first sub-"thread", and then one line up.
4614                     (gnus-summary-goto-article
4615                      (mail-header-number (caadr thread)))
4616                     (forward-line -1)
4617                     (gnus-delete-line)
4618                     (gnus-data-compute-positions))
4619                   (setq thread (cdr thread))
4620                   (while thread
4621                     (gnus-remove-thread-1 (car thread))
4622                     (setq thread (cdr thread))))
4623               (gnus-remove-thread-1 thread))))))))
4624
4625 (defun gnus-remove-thread-1 (thread)
4626   "Remove the thread THREAD recursively."
4627   (let ((number (mail-header-number (pop thread)))
4628         d)
4629     (setq thread (reverse thread))
4630     (while thread
4631       (gnus-remove-thread-1 (pop thread)))
4632     (when (setq d (gnus-data-find number))
4633       (goto-char (gnus-data-pos d))
4634       (gnus-summary-show-thread)
4635       (gnus-data-remove
4636        number
4637        (- (point-at-bol)
4638           (prog1
4639               (1+ (point-at-eol))
4640             (gnus-delete-line)))))))
4641
4642 (defun gnus-sort-threads-1 (threads func)
4643   (sort (mapcar (lambda (thread)
4644                   (cons (car thread)
4645                         (and (cdr thread)
4646                              (gnus-sort-threads-1 (cdr thread) func))))
4647                 threads) func))
4648
4649 (defun gnus-sort-threads (threads)
4650   "Sort THREADS."
4651   (if (not gnus-thread-sort-functions)
4652       threads
4653     (gnus-message 8 "Sorting threads...")
4654     (let ((max-lisp-eval-depth 5000))
4655       (prog1 (gnus-sort-threads-1
4656          threads
4657          (gnus-make-sort-function gnus-thread-sort-functions))
4658         (gnus-message 8 "Sorting threads...done")))))
4659
4660 (defun gnus-sort-articles (articles)
4661   "Sort ARTICLES."
4662   (when gnus-article-sort-functions
4663     (gnus-message 7 "Sorting articles...")
4664     (prog1
4665         (setq gnus-newsgroup-headers
4666               (sort articles (gnus-make-sort-function
4667                               gnus-article-sort-functions)))
4668       (gnus-message 7 "Sorting articles...done"))))
4669
4670 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4671 (defmacro gnus-thread-header (thread)
4672   "Return header of first article in THREAD.
4673 Note that THREAD must never, ever be anything else than a variable -
4674 using some other form will lead to serious barfage."
4675   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4676   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4677   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4678         (vector thread) 2))
4679
4680 (defsubst gnus-article-sort-by-number (h1 h2)
4681   "Sort articles by article number."
4682   (< (mail-header-number h1)
4683      (mail-header-number h2)))
4684
4685 (defun gnus-thread-sort-by-number (h1 h2)
4686   "Sort threads by root article number."
4687   (gnus-article-sort-by-number
4688    (gnus-thread-header h1) (gnus-thread-header h2)))
4689
4690 (defsubst gnus-article-sort-by-random (h1 h2)
4691   "Sort articles by article number."
4692   (zerop (random 2)))
4693
4694 (defun gnus-thread-sort-by-random (h1 h2)
4695   "Sort threads by root article number."
4696   (gnus-article-sort-by-random
4697    (gnus-thread-header h1) (gnus-thread-header h2)))
4698
4699 (defsubst gnus-article-sort-by-lines (h1 h2)
4700   "Sort articles by article Lines header."
4701   (< (mail-header-lines h1)
4702      (mail-header-lines h2)))
4703
4704 (defun gnus-thread-sort-by-lines (h1 h2)
4705   "Sort threads by root article Lines header."
4706   (gnus-article-sort-by-lines
4707    (gnus-thread-header h1) (gnus-thread-header h2)))
4708
4709 (defsubst gnus-article-sort-by-chars (h1 h2)
4710   "Sort articles by octet length."
4711   (< (mail-header-chars h1)
4712      (mail-header-chars h2)))
4713
4714 (defun gnus-thread-sort-by-chars (h1 h2)
4715   "Sort threads by root article octet length."
4716   (gnus-article-sort-by-chars
4717    (gnus-thread-header h1) (gnus-thread-header h2)))
4718
4719 (defsubst gnus-article-sort-by-author (h1 h2)
4720   "Sort articles by root author."
4721   (string-lessp
4722    (let ((extract (funcall
4723                    gnus-extract-address-components
4724                    (mail-header-from h1))))
4725      (or (car extract) (cadr extract) ""))
4726    (let ((extract (funcall
4727                    gnus-extract-address-components
4728                    (mail-header-from h2))))
4729      (or (car extract) (cadr extract) ""))))
4730
4731 (defun gnus-thread-sort-by-author (h1 h2)
4732   "Sort threads by root author."
4733   (gnus-article-sort-by-author
4734    (gnus-thread-header h1)  (gnus-thread-header h2)))
4735
4736 (defsubst gnus-article-sort-by-recipient (h1 h2)
4737   "Sort articles by recipient."
4738   (string-lessp
4739    (let ((extract (funcall
4740                    gnus-extract-address-components
4741                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4742      (or (car extract) (cadr extract)))
4743    (let ((extract (funcall
4744                    gnus-extract-address-components
4745                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4746      (or (car extract) (cadr extract)))))
4747
4748 (defun gnus-thread-sort-by-recipient (h1 h2)
4749   "Sort threads by root recipient."
4750   (gnus-article-sort-by-recipient
4751    (gnus-thread-header h1) (gnus-thread-header h2)))
4752
4753 (defsubst gnus-article-sort-by-subject (h1 h2)
4754   "Sort articles by root subject."
4755   (string-lessp
4756    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4757    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4758
4759 (defun gnus-thread-sort-by-subject (h1 h2)
4760   "Sort threads by root subject."
4761   (gnus-article-sort-by-subject
4762    (gnus-thread-header h1) (gnus-thread-header h2)))
4763
4764 (defsubst gnus-article-sort-by-date (h1 h2)
4765   "Sort articles by root article date."
4766   (time-less-p
4767    (gnus-date-get-time (mail-header-date h1))
4768    (gnus-date-get-time (mail-header-date h2))))
4769
4770 (defun gnus-thread-sort-by-date (h1 h2)
4771   "Sort threads by root article date."
4772   (gnus-article-sort-by-date
4773    (gnus-thread-header h1) (gnus-thread-header h2)))
4774
4775 (defsubst gnus-article-sort-by-score (h1 h2)
4776   "Sort articles by root article score.
4777 Unscored articles will be counted as having a score of zero."
4778   (> (or (cdr (assq (mail-header-number h1)
4779                     gnus-newsgroup-scored))
4780          gnus-summary-default-score 0)
4781      (or (cdr (assq (mail-header-number h2)
4782                     gnus-newsgroup-scored))
4783          gnus-summary-default-score 0)))
4784
4785 (defun gnus-thread-sort-by-score (h1 h2)
4786   "Sort threads by root article score."
4787   (gnus-article-sort-by-score
4788    (gnus-thread-header h1) (gnus-thread-header h2)))
4789
4790 (defun gnus-thread-sort-by-total-score (h1 h2)
4791   "Sort threads by the sum of all scores in the thread.
4792 Unscored articles will be counted as having a score of zero."
4793   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4794
4795 (defun gnus-thread-total-score (thread)
4796   ;; This function find the total score of THREAD.
4797   (cond
4798    ((null thread)
4799     0)
4800    ((consp thread)
4801     (if (stringp (car thread))
4802         (apply gnus-thread-score-function 0
4803                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4804       (gnus-thread-total-score-1 thread)))
4805    (t
4806     (gnus-thread-total-score-1 (list thread)))))
4807
4808 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4809   "Sort threads such that the thread with the most recently arrived article comes first."
4810   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4811
4812 (defun gnus-thread-highest-number (thread)
4813   "Return the highest article number in THREAD."
4814   (apply 'max (mapcar (lambda (header)
4815                         (mail-header-number header))
4816                       (message-flatten-list thread))))
4817
4818 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4819   "Sort threads such that the thread with the most recently dated article comes first."
4820   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4821
4822 (defun gnus-thread-latest-date (thread)
4823   "Return the highest article date in THREAD."
4824   (let ((previous-time 0))
4825     (apply 'max
4826            (mapcar
4827             (lambda (header)
4828               (setq previous-time
4829                     (condition-case ()
4830                         (time-to-seconds (mail-header-parse-date
4831                                           (mail-header-date header)))
4832                       (error previous-time))))
4833             (sort
4834              (message-flatten-list thread)
4835              (lambda (h1 h2)
4836                (< (mail-header-number h1)
4837                   (mail-header-number h2))))))))
4838
4839 (defun gnus-thread-total-score-1 (root)
4840   ;; This function find the total score of the thread below ROOT.
4841   (setq root (car root))
4842   (apply gnus-thread-score-function
4843          (or (append
4844               (mapcar 'gnus-thread-total-score
4845                       (cdr (gnus-id-to-thread (mail-header-id root))))
4846               (when (> (mail-header-number root) 0)
4847                 (list (or (cdr (assq (mail-header-number root)
4848                                      gnus-newsgroup-scored))
4849                           gnus-summary-default-score 0))))
4850              (list gnus-summary-default-score)
4851              '(0))))
4852
4853 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4854 (defvar gnus-tmp-prev-subject nil)
4855 (defvar gnus-tmp-false-parent nil)
4856 (defvar gnus-tmp-root-expunged nil)
4857 (defvar gnus-tmp-dummy-line nil)
4858
4859 (eval-when-compile (defvar gnus-tmp-header))
4860 (defun gnus-extra-header (type &optional header)
4861   "Return the extra header of TYPE."
4862   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4863       ""))
4864
4865 (defvar gnus-tmp-thread-tree-header-string "")
4866
4867 (defcustom gnus-sum-thread-tree-root "> "
4868   "With %B spec, used for the root of a thread.
4869 If nil, use subject instead."
4870   :version "22.1"
4871   :type '(radio (const :format "%v  " nil) string)
4872   :group 'gnus-thread)
4873
4874 (defcustom gnus-sum-thread-tree-false-root "> "
4875   "With %B spec, used for a false root of a thread.
4876 If nil, use subject instead."
4877   :version "22.1"
4878   :type '(radio (const :format "%v  " nil) string)
4879   :group 'gnus-thread)
4880
4881 (defcustom gnus-sum-thread-tree-single-indent ""
4882   "With %B spec, used for a thread with just one message.
4883 If nil, use subject instead."
4884   :version "22.1"
4885   :type '(radio (const :format "%v  " nil) string)
4886   :group 'gnus-thread)
4887
4888 (defcustom gnus-sum-thread-tree-vertical "| "
4889   "With %B spec, used for drawing a vertical line."
4890   :version "22.1"
4891   :type 'string
4892   :group 'gnus-thread)
4893
4894 (defcustom gnus-sum-thread-tree-indent "  "
4895   "With %B spec, used for indenting."
4896   :version "22.1"
4897   :type 'string
4898   :group 'gnus-thread)
4899
4900 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4901   "With %B spec, used for a leaf with brothers."
4902   :version "22.1"
4903   :type 'string
4904   :group 'gnus-thread)
4905
4906 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4907   "With %B spec, used for a leaf without brothers."
4908   :version "22.1"
4909   :type 'string
4910   :group 'gnus-thread)
4911
4912 (defun gnus-summary-prepare-threads (threads)
4913   "Prepare summary buffer from THREADS and indentation LEVEL.
4914 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4915 or a straight list of headers."
4916   (gnus-message 7 "Generating summary...")
4917
4918   (setq gnus-newsgroup-threads threads)
4919   (beginning-of-line)
4920
4921   (let ((gnus-tmp-level 0)
4922         (default-score (or gnus-summary-default-score 0))
4923         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4924         (building-line-count gnus-summary-display-while-building)
4925         (building-count (integerp gnus-summary-display-while-building))
4926         thread number subject stack state gnus-tmp-gathered beg-match
4927         new-roots gnus-tmp-new-adopts thread-end simp-subject
4928         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4929         gnus-tmp-replied gnus-tmp-subject-or-nil
4930         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4931         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4932         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4933         tree-stack)
4934
4935     (setq gnus-tmp-prev-subject nil
4936           gnus-tmp-thread-tree-header-string "")
4937
4938     (if (vectorp (car threads))
4939         ;; If this is a straight (sic) list of headers, then a
4940         ;; threaded summary display isn't required, so we just create
4941         ;; an unthreaded one.
4942         (gnus-summary-prepare-unthreaded threads)
4943
4944       ;; Do the threaded display.
4945
4946       (if gnus-summary-display-while-building
4947           (switch-to-buffer (buffer-name)))
4948       (while (or threads stack gnus-tmp-new-adopts new-roots)
4949
4950         (if (and (= gnus-tmp-level 0)
4951                  (or (not stack)
4952                      (= (caar stack) 0))
4953                  (not gnus-tmp-false-parent)
4954                  (or gnus-tmp-new-adopts new-roots))
4955             (if gnus-tmp-new-adopts
4956                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4957                       thread (list (car gnus-tmp-new-adopts))
4958                       gnus-tmp-header (caar thread)
4959                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4960               (when new-roots
4961                 (setq thread (list (car new-roots))
4962                       gnus-tmp-header (caar thread)
4963                       new-roots (cdr new-roots))))
4964
4965           (if threads
4966               ;; If there are some threads, we do them before the
4967               ;; threads on the stack.
4968               (setq thread threads
4969                     gnus-tmp-header (caar thread))
4970             ;; There were no current threads, so we pop something off
4971             ;; the stack.
4972             (setq state (car stack)
4973                   gnus-tmp-level (car state)
4974                   tree-stack (cadr state)
4975                   thread (caddr state)
4976                   stack (cdr stack)
4977                   gnus-tmp-header (caar thread))))
4978
4979         (setq gnus-tmp-false-parent nil)
4980         (setq gnus-tmp-root-expunged nil)
4981         (setq thread-end nil)
4982
4983         (if (stringp gnus-tmp-header)
4984             ;; The header is a dummy root.
4985             (cond
4986              ((eq gnus-summary-make-false-root 'adopt)
4987               ;; We let the first article adopt the rest.
4988               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4989                                                (cddar thread)))
4990               (setq gnus-tmp-gathered
4991                     (nconc (mapcar
4992                             (lambda (h) (mail-header-number (car h)))
4993                             (cddar thread))
4994                            gnus-tmp-gathered))
4995               (setq thread (cons (list (caar thread)
4996                                        (cadar thread))
4997                                  (cdr thread)))
4998               (setq gnus-tmp-level -1
4999                     gnus-tmp-false-parent t))
5000              ((eq gnus-summary-make-false-root 'empty)
5001               ;; We print adopted articles with empty subject fields.
5002               (setq gnus-tmp-gathered
5003                     (nconc (mapcar
5004                             (lambda (h) (mail-header-number (car h)))
5005                             (cddar thread))
5006                            gnus-tmp-gathered))
5007               (setq gnus-tmp-level -1))
5008              ((eq gnus-summary-make-false-root 'dummy)
5009               ;; We remember that we probably want to output a dummy
5010               ;; root.
5011               (setq gnus-tmp-dummy-line gnus-tmp-header)
5012               (setq gnus-tmp-prev-subject gnus-tmp-header))
5013              (t
5014               ;; We do not make a root for the gathered
5015               ;; sub-threads at all.
5016               (setq gnus-tmp-level -1)))
5017
5018           (setq number (mail-header-number gnus-tmp-header)
5019                 subject (mail-header-subject gnus-tmp-header)
5020                 simp-subject (gnus-simplify-subject-fully subject))
5021
5022           (cond
5023            ;; If the thread has changed subject, we might want to make
5024            ;; this subthread into a root.
5025            ((and (null gnus-thread-ignore-subject)
5026                  (not (zerop gnus-tmp-level))
5027                  gnus-tmp-prev-subject
5028                  (not (string= gnus-tmp-prev-subject simp-subject)))
5029             (setq new-roots (nconc new-roots (list (car thread)))
5030                   thread-end t
5031                   gnus-tmp-header nil))
5032            ;; If the article lies outside the current limit,
5033            ;; then we do not display it.
5034            ((not (memq number gnus-newsgroup-limit))
5035             (setq gnus-tmp-gathered
5036                   (nconc (mapcar
5037                           (lambda (h) (mail-header-number (car h)))
5038                           (cdar thread))
5039                          gnus-tmp-gathered))
5040             (setq gnus-tmp-new-adopts (if (cdar thread)
5041                                           (append gnus-tmp-new-adopts
5042                                                   (cdar thread))
5043                                         gnus-tmp-new-adopts)
5044                   thread-end t
5045                   gnus-tmp-header nil)
5046             (when (zerop gnus-tmp-level)
5047               (setq gnus-tmp-root-expunged t)))
5048            ;; Perhaps this article is to be marked as read?
5049            ((and gnus-summary-mark-below
5050                  (< (or (cdr (assq number gnus-newsgroup-scored))
5051                         default-score)
5052                     gnus-summary-mark-below)
5053                  ;; Don't touch sparse articles.
5054                  (not (gnus-summary-article-sparse-p number))
5055                  (not (gnus-summary-article-ancient-p number)))
5056             (setq gnus-newsgroup-unreads
5057                   (delq number gnus-newsgroup-unreads))
5058             (if gnus-newsgroup-auto-expire
5059                 (setq gnus-newsgroup-expirable
5060                       (gnus-add-to-sorted-list
5061                        gnus-newsgroup-expirable number))
5062               (push (cons number gnus-low-score-mark)
5063                     gnus-newsgroup-reads))))
5064
5065           (when gnus-tmp-header
5066             ;; We may have an old dummy line to output before this
5067             ;; article.
5068             (when (and gnus-tmp-dummy-line
5069                        (gnus-subject-equal
5070                         gnus-tmp-dummy-line
5071                         (mail-header-subject gnus-tmp-header)))
5072               (gnus-summary-insert-dummy-line
5073                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5074               (setq gnus-tmp-dummy-line nil))
5075
5076             ;; Compute the mark.
5077             (setq gnus-tmp-unread (gnus-article-mark number))
5078
5079             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5080                                   gnus-tmp-header gnus-tmp-level)
5081                   gnus-newsgroup-data)
5082
5083             ;; Actually insert the line.
5084             (setq
5085              gnus-tmp-subject-or-nil
5086              (cond
5087               ((and gnus-thread-ignore-subject
5088                     gnus-tmp-prev-subject
5089                     (not (string= gnus-tmp-prev-subject simp-subject)))
5090                subject)
5091               ((zerop gnus-tmp-level)
5092                (if (and (eq gnus-summary-make-false-root 'empty)
5093                         (memq number gnus-tmp-gathered)
5094                         gnus-tmp-prev-subject
5095                         (string= gnus-tmp-prev-subject simp-subject))
5096                    gnus-summary-same-subject
5097                  subject))
5098               (t gnus-summary-same-subject)))
5099             (if (and (eq gnus-summary-make-false-root 'adopt)
5100                      (= gnus-tmp-level 1)
5101                      (memq number gnus-tmp-gathered))
5102                 (setq gnus-tmp-opening-bracket ?\<
5103                       gnus-tmp-closing-bracket ?\>)
5104               (setq gnus-tmp-opening-bracket ?\[
5105                     gnus-tmp-closing-bracket ?\]))
5106             (setq
5107              gnus-tmp-indentation
5108              (aref gnus-thread-indent-array gnus-tmp-level)
5109              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5110              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5111                                 gnus-summary-default-score 0)
5112              gnus-tmp-score-char
5113              (if (or (null gnus-summary-default-score)
5114                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5115                          gnus-summary-zcore-fuzz))
5116                  ?                      ;Whitespace
5117                (if (< gnus-tmp-score gnus-summary-default-score)
5118                    gnus-score-below-mark gnus-score-over-mark))
5119              gnus-tmp-replied
5120              (cond ((memq number gnus-newsgroup-processable)
5121                     gnus-process-mark)
5122                    ((memq number gnus-newsgroup-cached)
5123                     gnus-cached-mark)
5124                    ((memq number gnus-newsgroup-replied)
5125                     gnus-replied-mark)
5126                    ((memq number gnus-newsgroup-forwarded)
5127                     gnus-forwarded-mark)
5128                    ((memq number gnus-newsgroup-saved)
5129                     gnus-saved-mark)
5130                    ((memq number gnus-newsgroup-recent)
5131                     gnus-recent-mark)
5132                    ((memq number gnus-newsgroup-unseen)
5133                     gnus-unseen-mark)
5134                    (t gnus-no-mark))
5135              gnus-tmp-downloaded
5136              (cond ((memq number gnus-newsgroup-undownloaded)
5137                     gnus-undownloaded-mark)
5138                    (gnus-newsgroup-agentized
5139                     gnus-downloaded-mark)
5140                    (t
5141                     gnus-no-mark))
5142              gnus-tmp-from (mail-header-from gnus-tmp-header)
5143              gnus-tmp-name
5144              (cond
5145               ((string-match "<[^>]+> *$" gnus-tmp-from)
5146                (setq beg-match (match-beginning 0))
5147                (or (and (string-match "^\".+\"" gnus-tmp-from)
5148                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5149                    (substring gnus-tmp-from 0 beg-match)))
5150               ((string-match "(.+)" gnus-tmp-from)
5151                (substring gnus-tmp-from
5152                           (1+ (match-beginning 0)) (1- (match-end 0))))
5153               (t gnus-tmp-from))
5154
5155              ;; Do the %B string
5156              gnus-tmp-thread-tree-header-string
5157              (cond
5158               ((not gnus-show-threads) "")
5159               ((zerop gnus-tmp-level)
5160                (cond ((cdar thread)
5161                       (or gnus-sum-thread-tree-root subject))
5162                      (gnus-tmp-new-adopts
5163                       (or gnus-sum-thread-tree-false-root subject))
5164                      (t
5165                       (or gnus-sum-thread-tree-single-indent subject))))
5166               (t
5167                (concat (apply 'concat
5168                               (mapcar (lambda (item)
5169                                         (if (= item 1)
5170                                             gnus-sum-thread-tree-vertical
5171                                           gnus-sum-thread-tree-indent))
5172                                       (cdr (reverse tree-stack))))
5173                        (if (nth 1 thread)
5174                            gnus-sum-thread-tree-leaf-with-other
5175                          gnus-sum-thread-tree-single-leaf)))))
5176             (when (string= gnus-tmp-name "")
5177               (setq gnus-tmp-name gnus-tmp-from))
5178             (unless (numberp gnus-tmp-lines)
5179               (setq gnus-tmp-lines -1))
5180             (if (= gnus-tmp-lines -1)
5181                 (setq gnus-tmp-lines "?")
5182               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5183               (gnus-put-text-property
5184              (point)
5185              (progn (eval gnus-summary-line-format-spec) (point))
5186                'gnus-number number)
5187             (when gnus-visual-p
5188               (forward-line -1)
5189               (gnus-run-hooks 'gnus-summary-update-hook)
5190               (forward-line 1))
5191
5192             (setq gnus-tmp-prev-subject simp-subject)))
5193
5194         (when (nth 1 thread)
5195           (push (list (max 0 gnus-tmp-level)
5196                       (copy-sequence tree-stack)
5197                       (nthcdr 1 thread))
5198                 stack))
5199         (push (if (nth 1 thread) 1 0) tree-stack)
5200         (incf gnus-tmp-level)
5201         (setq threads (if thread-end nil (cdar thread)))
5202         (if gnus-summary-display-while-building
5203             (if building-count
5204                 (progn
5205                   ;; use a set frequency
5206                   (setq building-line-count (1- building-line-count))
5207                   (when (= building-line-count 0)
5208                     (sit-for 0)
5209                     (setq building-line-count
5210                           gnus-summary-display-while-building)))
5211               ;; always
5212               (sit-for 0)))
5213         (unless threads
5214           (setq gnus-tmp-level 0)))))
5215   (gnus-message 7 "Generating summary...done"))
5216
5217 (defun gnus-summary-prepare-unthreaded (headers)
5218   "Generate an unthreaded summary buffer based on HEADERS."
5219   (let (header number mark)
5220
5221     (beginning-of-line)
5222
5223     (while headers
5224       ;; We may have to root out some bad articles...
5225       (when (memq (setq number (mail-header-number
5226                                 (setq header (pop headers))))
5227                   gnus-newsgroup-limit)
5228         ;; Mark article as read when it has a low score.
5229         (when (and gnus-summary-mark-below
5230                    (< (or (cdr (assq number gnus-newsgroup-scored))
5231                           gnus-summary-default-score 0)
5232                       gnus-summary-mark-below)
5233                    (not (gnus-summary-article-ancient-p number)))
5234           (setq gnus-newsgroup-unreads
5235                 (delq number gnus-newsgroup-unreads))
5236           (if gnus-newsgroup-auto-expire
5237               (push number gnus-newsgroup-expirable)
5238             (push (cons number gnus-low-score-mark)
5239                   gnus-newsgroup-reads)))
5240
5241         (setq mark (gnus-article-mark number))
5242         (push (gnus-data-make number mark (1+ (point)) header 0)
5243               gnus-newsgroup-data)
5244         (gnus-summary-insert-line
5245          header 0 number
5246          (memq number gnus-newsgroup-undownloaded)
5247          mark (memq number gnus-newsgroup-replied)
5248          (memq number gnus-newsgroup-expirable)
5249          (mail-header-subject header) nil
5250          (cdr (assq number gnus-newsgroup-scored))
5251          (memq number gnus-newsgroup-processable))))))
5252
5253 (defun gnus-summary-remove-list-identifiers ()
5254   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5255   (let ((regexp (if (consp gnus-list-identifiers)
5256                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5257                   gnus-list-identifiers))
5258         changed subject)
5259     (when regexp
5260       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5261       (dolist (header gnus-newsgroup-headers)
5262         (setq subject (mail-header-subject header)
5263               changed nil)
5264         (while (string-match regexp subject)
5265           (setq subject
5266                 (concat (substring subject 0 (match-beginning 1))
5267                         (substring subject (match-end 0)))
5268                 changed t))
5269         (when changed
5270           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5271             (setq subject
5272                   (concat (substring subject 0 (match-beginning 1))
5273                           (substring subject (match-end 1)))))
5274           (mail-header-set-subject header subject))))))
5275
5276 (defun gnus-fetch-headers (articles)
5277   "Fetch headers of ARTICLES."
5278   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5279     (gnus-message 5 "Fetching headers for %s..." name)
5280     (prog1
5281         (if (eq 'nov
5282                 (setq gnus-headers-retrieved-by
5283                       (gnus-retrieve-headers
5284                        articles gnus-newsgroup-name
5285                        ;; We might want to fetch old headers, but
5286                        ;; not if there is only 1 article.
5287                        (and (or (and
5288                                  (not (eq gnus-fetch-old-headers 'some))
5289                                  (not (numberp gnus-fetch-old-headers)))
5290                                 (> (length articles) 1))
5291                             gnus-fetch-old-headers))))
5292             (gnus-get-newsgroup-headers-xover
5293              articles nil nil gnus-newsgroup-name t)
5294           (gnus-get-newsgroup-headers))
5295       (gnus-message 5 "Fetching headers for %s...done" name))))
5296
5297 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5298   "Select newsgroup GROUP.
5299 If READ-ALL is non-nil, all articles in the group are selected.
5300 If SELECT-ARTICLES, only select those articles from GROUP."
5301   (let* ((entry (gnus-group-entry group))
5302          ;;!!! Dirty hack; should be removed.
5303          (gnus-summary-ignore-duplicates
5304           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5305               t
5306             gnus-summary-ignore-duplicates))
5307          (info (nth 2 entry))
5308          articles fetched-articles cached)
5309
5310     (unless (gnus-check-server
5311              (set (make-local-variable 'gnus-current-select-method)
5312                   (gnus-find-method-for-group group)))
5313       (error "Couldn't open server"))
5314
5315     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5316         (gnus-activate-group group)     ; Or we can activate it...
5317         (progn                          ; Or we bug out.
5318           (when (equal major-mode 'gnus-summary-mode)
5319             (gnus-kill-buffer (current-buffer)))
5320           (error "Couldn't activate group %s: %s"
5321                  group (gnus-status-message group))))
5322
5323     (unless (gnus-request-group group t)
5324       (when (equal major-mode 'gnus-summary-mode)
5325         (gnus-kill-buffer (current-buffer)))
5326       (error "Couldn't request group %s: %s"
5327              group (gnus-status-message group)))
5328
5329     (when gnus-agent
5330       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5331
5332       (setq gnus-summary-use-undownloaded-faces
5333             (gnus-agent-find-parameter
5334              group
5335              'agent-enable-undownloaded-faces)))
5336
5337     (setq gnus-newsgroup-name group
5338           gnus-newsgroup-unselected nil
5339           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5340
5341     (let ((display (gnus-group-find-parameter group 'display)))
5342       (setq gnus-newsgroup-display
5343             (cond
5344              ((not (zerop (or (car-safe read-all) 0)))
5345               ;; The user entered the group with C-u SPC/RET, let's show
5346               ;; all articles.
5347               'gnus-not-ignore)
5348              ((eq display 'all)
5349               'gnus-not-ignore)
5350              ((arrayp display)
5351               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5352              ((numberp display)
5353               ;; The following is probably the "correct" solution, but
5354               ;; it makes Gnus fetch all headers and then limit the
5355               ;; articles (which is slow), so instead we hack the
5356               ;; select-articles parameter instead. -- Simon Josefsson
5357               ;; <jas@kth.se>
5358               ;;
5359               ;; (gnus-byte-compile
5360               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5361               ;;                         display)))))
5362               (setq select-articles
5363                     (gnus-uncompress-range
5364                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5365                              (if (> tmp 0)
5366                                  tmp
5367                                1))
5368                            (cdr (gnus-active group)))))
5369               nil)
5370              (t
5371               nil))))
5372
5373     (gnus-summary-setup-default-charset)
5374
5375     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5376     (when (gnus-virtual-group-p group)
5377       (setq cached gnus-newsgroup-cached))
5378
5379     (setq gnus-newsgroup-unreads
5380           (gnus-sorted-ndifference
5381            (gnus-sorted-ndifference gnus-newsgroup-unreads
5382                                     gnus-newsgroup-marked)
5383            gnus-newsgroup-dormant))
5384
5385     (setq gnus-newsgroup-processable nil)
5386
5387     (gnus-update-read-articles group gnus-newsgroup-unreads)
5388
5389     ;; Adjust and set lists of article marks.
5390     (when info
5391       (gnus-adjust-marked-articles info))
5392     (if (setq articles select-articles)
5393         (setq gnus-newsgroup-unselected
5394               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5395       (setq articles (gnus-articles-to-read group read-all)))
5396
5397     (cond
5398      ((null articles)
5399       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5400       'quit)
5401      ((eq articles 0) nil)
5402      (t
5403       ;; Init the dependencies hash table.
5404       (setq gnus-newsgroup-dependencies
5405             (gnus-make-hashtable (length articles)))
5406       (gnus-set-global-variables)
5407       ;; Retrieve the headers and read them in.
5408
5409       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5410
5411       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5412       (when cached
5413         (setq gnus-newsgroup-cached cached))
5414
5415       ;; Suppress duplicates?
5416       (when gnus-suppress-duplicates
5417         (gnus-dup-suppress-articles))
5418
5419       ;; Set the initial limit.
5420       (setq gnus-newsgroup-limit (copy-sequence articles))
5421       ;; Remove canceled articles from the list of unread articles.
5422       (setq fetched-articles
5423             (mapcar (lambda (headers) (mail-header-number headers))
5424                     gnus-newsgroup-headers))
5425       (setq gnus-newsgroup-articles fetched-articles)
5426       (setq gnus-newsgroup-unreads
5427             (gnus-sorted-nintersection
5428              gnus-newsgroup-unreads fetched-articles))
5429       (gnus-compute-unseen-list)
5430
5431       ;; Removed marked articles that do not exist.
5432       (gnus-update-missing-marks
5433        (gnus-sorted-difference articles fetched-articles))
5434       ;; We might want to build some more threads first.
5435       (when (and gnus-fetch-old-headers
5436                  (eq gnus-headers-retrieved-by 'nov))
5437         (if (eq gnus-fetch-old-headers 'invisible)
5438             (gnus-build-all-threads)
5439           (gnus-build-old-threads)))
5440       ;; Let the Gnus agent mark articles as read.
5441       (when gnus-agent
5442         (gnus-agent-get-undownloaded-list))
5443       ;; Remove list identifiers from subject
5444       (when gnus-list-identifiers
5445         (gnus-summary-remove-list-identifiers))
5446       ;; Check whether auto-expire is to be done in this group.
5447       (setq gnus-newsgroup-auto-expire
5448             (gnus-group-auto-expirable-p group))
5449       ;; Set up the article buffer now, if necessary.
5450       (unless gnus-single-article-buffer
5451         (gnus-article-setup-buffer))
5452       ;; First and last article in this newsgroup.
5453       (when gnus-newsgroup-headers
5454         (setq gnus-newsgroup-begin
5455               (mail-header-number (car gnus-newsgroup-headers))
5456               gnus-newsgroup-end
5457               (mail-header-number
5458                (gnus-last-element gnus-newsgroup-headers))))
5459       ;; GROUP is successfully selected.
5460       (or gnus-newsgroup-headers t)))))
5461
5462 (defun gnus-compute-unseen-list ()
5463   ;; The `seen' marks are treated specially.
5464   (if (not gnus-newsgroup-seen)
5465       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5466     (setq gnus-newsgroup-unseen
5467           (gnus-inverse-list-range-intersection
5468            gnus-newsgroup-articles gnus-newsgroup-seen))))
5469
5470 (defun gnus-summary-display-make-predicate (display)
5471   (require 'gnus-agent)
5472   (when (= (length display) 1)
5473     (setq display (car display)))
5474   (unless gnus-summary-display-cache
5475     (dolist (elem (append '((unread . unread)
5476                             (read . read)
5477                             (unseen . unseen))
5478                           gnus-article-mark-lists))
5479       (push (cons (cdr elem)
5480                   (gnus-byte-compile
5481                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5482             gnus-summary-display-cache)))
5483   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5484         (gnus-category-predicate-cache gnus-summary-display-cache))
5485     (gnus-get-predicate display)))
5486
5487 ;; Uses the dynamically bound `number' variable.
5488 (eval-when-compile
5489   (defvar number))
5490 (defun gnus-article-marked-p (type &optional article)
5491   (let ((article (or article number)))
5492     (cond
5493      ((eq type 'tick)
5494       (memq article gnus-newsgroup-marked))
5495      ((eq type 'spam)
5496       (memq article gnus-newsgroup-spam-marked))
5497      ((eq type 'unsend)
5498       (memq article gnus-newsgroup-unsendable))
5499      ((eq type 'undownload)
5500       (memq article gnus-newsgroup-undownloaded))
5501      ((eq type 'download)
5502       (memq article gnus-newsgroup-downloadable))
5503      ((eq type 'unread)
5504       (memq article gnus-newsgroup-unreads))
5505      ((eq type 'read)
5506       (memq article gnus-newsgroup-reads))
5507      ((eq type 'dormant)
5508       (memq article gnus-newsgroup-dormant) )
5509      ((eq type 'expire)
5510       (memq article gnus-newsgroup-expirable))
5511      ((eq type 'reply)
5512       (memq article gnus-newsgroup-replied))
5513      ((eq type 'killed)
5514       (memq article gnus-newsgroup-killed))
5515      ((eq type 'bookmark)
5516       (assq article gnus-newsgroup-bookmarks))
5517      ((eq type 'score)
5518       (assq article gnus-newsgroup-scored))
5519      ((eq type 'save)
5520       (memq article gnus-newsgroup-saved))
5521      ((eq type 'cache)
5522       (memq article gnus-newsgroup-cached))
5523      ((eq type 'forward)
5524       (memq article gnus-newsgroup-forwarded))
5525      ((eq type 'seen)
5526       (not (memq article gnus-newsgroup-unseen)))
5527      ((eq type 'recent)
5528       (memq article gnus-newsgroup-recent))
5529      (t t))))
5530
5531 (defun gnus-articles-to-read (group &optional read-all)
5532   "Find out what articles the user wants to read."
5533   (let* ((articles
5534           ;; Select all articles if `read-all' is non-nil, or if there
5535           ;; are no unread articles.
5536           (if (or read-all
5537                   (and (zerop (length gnus-newsgroup-marked))
5538                        (zerop (length gnus-newsgroup-unreads)))
5539                   ;; Fetch all if the predicate is non-nil.
5540                   gnus-newsgroup-display)
5541               ;; We want to select the headers for all the articles in
5542               ;; the group, so we select either all the active
5543               ;; articles in the group, or (if that's nil), the
5544               ;; articles in the cache.
5545               (or
5546                (gnus-uncompress-range (gnus-active group))
5547                (gnus-cache-articles-in-group group))
5548             ;; Select only the "normal" subset of articles.
5549             (gnus-sorted-nunion
5550              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5551              gnus-newsgroup-unreads)))
5552          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5553          (scored (length scored-list))
5554          (number (length articles))
5555          (marked (+ (length gnus-newsgroup-marked)
5556                     (length gnus-newsgroup-dormant)))
5557          (select
5558           (cond
5559            ((numberp read-all)
5560             read-all)
5561            ((numberp gnus-newsgroup-display)
5562             gnus-newsgroup-display)
5563            (t
5564             (condition-case ()
5565                 (cond
5566                  ((and (or (<= scored marked) (= scored number))
5567                        (numberp gnus-large-newsgroup)
5568                        (> number gnus-large-newsgroup))
5569                   (let* ((cursor-in-echo-area nil)
5570                          (initial (gnus-parameter-large-newsgroup-initial
5571                                    gnus-newsgroup-name))
5572                          (input
5573                           (read-string
5574                            (format
5575                             "How many articles from %s (%s %d): "
5576                             (gnus-limit-string
5577                              (gnus-group-decoded-name gnus-newsgroup-name)
5578                              35)
5579                             (if initial "max" "default")
5580                             number)
5581                            (if initial
5582                                (cons (number-to-string initial)
5583                                      0)))))
5584                     (if (string-match "^[ \t]*$" input) number input)))
5585                  ((and (> scored marked) (< scored number)
5586                        (> (- scored number) 20))
5587                   (let ((input
5588                          (read-string
5589                           (format "%s %s (%d scored, %d total): "
5590                                   "How many articles from"
5591                                   (gnus-group-decoded-name group)
5592                                   scored number))))
5593                     (if (string-match "^[ \t]*$" input)
5594                         number input)))
5595                  (t number))
5596               (quit
5597                (message "Quit getting the articles to read")
5598                nil))))))
5599     (setq select (if (stringp select) (string-to-number select) select))
5600     (if (or (null select) (zerop select))
5601         select
5602       (if (and (not (zerop scored)) (<= (abs select) scored))
5603           (progn
5604             (setq articles (sort scored-list '<))
5605             (setq number (length articles)))
5606         (setq articles (copy-sequence articles)))
5607
5608       (when (< (abs select) number)
5609         (if (< select 0)
5610             ;; Select the N oldest articles.
5611             (setcdr (nthcdr (1- (abs select)) articles) nil)
5612           ;; Select the N most recent articles.
5613           (setq articles (nthcdr (- number select) articles))))
5614       (setq gnus-newsgroup-unselected
5615             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5616       (when gnus-alter-articles-to-read-function
5617         (setq articles
5618               (sort
5619                (funcall gnus-alter-articles-to-read-function
5620                         gnus-newsgroup-name articles)
5621                '<)))
5622       articles)))
5623
5624 (defun gnus-killed-articles (killed articles)
5625   (let (out)
5626     (while articles
5627       (when (inline (gnus-member-of-range (car articles) killed))
5628         (push (car articles) out))
5629       (setq articles (cdr articles)))
5630     out))
5631
5632 (defun gnus-uncompress-marks (marks)
5633   "Uncompress the mark ranges in MARKS."
5634   (let ((uncompressed '(score bookmark))
5635         out)
5636     (while marks
5637       (if (memq (caar marks) uncompressed)
5638           (push (car marks) out)
5639         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5640       (setq marks (cdr marks)))
5641     out))
5642
5643 (defun gnus-article-mark-to-type (mark)
5644   "Return the type of MARK."
5645   (or (cadr (assq mark gnus-article-special-mark-lists))
5646       'list))
5647
5648 (defun gnus-article-unpropagatable-p (mark)
5649   "Return whether MARK should be propagated to back end."
5650   (memq mark gnus-article-unpropagated-mark-lists))
5651
5652 (defun gnus-adjust-marked-articles (info)
5653   "Set all article lists and remove all marks that are no longer valid."
5654   (let* ((marked-lists (gnus-info-marks info))
5655          (active (gnus-active (gnus-info-group info)))
5656          (min (car active))
5657          (max (cdr active))
5658          (types gnus-article-mark-lists)
5659          marks var articles article mark mark-type
5660          bgn end)
5661
5662     (dolist (marks marked-lists)
5663       (setq mark (car marks)
5664             mark-type (gnus-article-mark-to-type mark)
5665             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5666
5667       ;; We set the variable according to the type of the marks list,
5668       ;; and then adjust the marks to a subset of the active articles.
5669       (cond
5670        ;; Adjust "simple" lists - compressed yet unsorted
5671        ((eq mark-type 'list)
5672         ;; Simultaneously uncompress and clip to active range
5673         ;; See gnus-uncompress-range for a description of possible marks
5674         (let (l lh)
5675           (if (not (cadr marks))
5676               (set var nil)
5677             (setq articles (if (numberp (cddr marks))
5678                                (list (cdr marks))
5679                              (cdr marks))
5680                   lh (cons nil nil)
5681                   l lh)
5682
5683             (while (setq article (pop articles))
5684               (cond ((consp article)
5685                      (setq bgn (max (car article) min)
5686                            end (min (cdr article) max))
5687                      (while (<= bgn end)
5688                        (setq l (setcdr l (cons bgn nil))
5689                              bgn (1+ bgn))))
5690                     ((and (<= min article)
5691                           (>= max article))
5692                      (setq l (setcdr l (cons article nil))))))
5693             (set var (cdr lh)))))
5694        ;; Adjust assocs.
5695        ((eq mark-type 'tuple)
5696         (set var (setq articles (cdr marks)))
5697         (when (not (listp (cdr (symbol-value var))))
5698           (set var (list (symbol-value var))))
5699         (when (not (listp (cdr articles)))
5700           (setq articles (list articles)))
5701         (while articles
5702           (when (or (not (consp (setq article (pop articles))))
5703                     (< (car article) min)
5704                     (> (car article) max))
5705             (set var (delq article (symbol-value var))))))
5706        ;; Adjust ranges (sloppily).
5707        ((eq mark-type 'range)
5708         (cond
5709          ((eq mark 'seen)
5710           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5711           ;; It should be (seen (NUM1 . NUM2)).
5712           (when (numberp (cddr marks))
5713             (setcdr marks (list (cdr marks))))
5714           (setq articles (cdr marks))
5715           (while (and articles
5716                       (or (and (consp (car articles))
5717                                (> min (cdar articles)))
5718                           (and (numberp (car articles))
5719                                (> min (car articles)))))
5720             (pop articles))
5721           (set var articles))))))))
5722
5723 (defun gnus-update-missing-marks (missing)
5724   "Go through the list of MISSING articles and remove them from the mark lists."
5725   (when missing
5726     (let (var m)
5727       ;; Go through all types.
5728       (dolist (elem gnus-article-mark-lists)
5729         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5730           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5731           (when (symbol-value var)
5732             ;; This list has articles.  So we delete all missing
5733             ;; articles from it.
5734             (setq m missing)
5735             (while m
5736               (set var (delq (pop m) (symbol-value var))))))))))
5737
5738 (defun gnus-update-marks ()
5739   "Enter the various lists of marked articles into the newsgroup info list."
5740   (let ((types gnus-article-mark-lists)
5741         (info (gnus-get-info gnus-newsgroup-name))
5742         type list newmarked symbol delta-marks)
5743     (when info
5744       ;; Add all marks lists to the list of marks lists.
5745       (while (setq type (pop types))
5746         (setq list (symbol-value
5747                     (setq symbol
5748                           (intern (format "gnus-newsgroup-%s" (car type))))))
5749
5750         (when list
5751           ;; Get rid of the entries of the articles that have the
5752           ;; default score.
5753           (when (and (eq (cdr type) 'score)
5754                      gnus-save-score
5755                      list)
5756             (let* ((arts list)
5757                    (prev (cons nil list))
5758                    (all prev))
5759               (while arts
5760                 (if (or (not (consp (car arts)))
5761                         (= (cdar arts) gnus-summary-default-score))
5762                     (setcdr prev (cdr arts))
5763                   (setq prev arts))
5764                 (setq arts (cdr arts)))
5765               (setq list (cdr all)))))
5766
5767         (when (eq (cdr type) 'seen)
5768           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5769
5770         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5771           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5772
5773         (when (and (gnus-check-backend-function
5774                     'request-set-mark gnus-newsgroup-name)
5775                    (not (gnus-article-unpropagatable-p (cdr type))))
5776           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5777                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5778                  (add (gnus-remove-from-range
5779                        (gnus-copy-sequence list) old)))
5780             (when add
5781               (push (list add 'add (list (cdr type))) delta-marks))
5782             (when del
5783               (push (list del 'del (list (cdr type))) delta-marks))))
5784
5785         (when list
5786           (push (cons (cdr type) list) newmarked)))
5787
5788       (when delta-marks
5789         (unless (gnus-check-group gnus-newsgroup-name)
5790           (error "Can't open server for %s" gnus-newsgroup-name))
5791         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5792
5793       ;; Enter these new marks into the info of the group.
5794       (if (nthcdr 3 info)
5795           (setcar (nthcdr 3 info) newmarked)
5796         ;; Add the marks lists to the end of the info.
5797         (when newmarked
5798           (setcdr (nthcdr 2 info) (list newmarked))))
5799
5800       ;; Cut off the end of the info if there's nothing else there.
5801       (let ((i 5))
5802         (while (and (> i 2)
5803                     (not (nth i info)))
5804           (when (nthcdr (decf i) info)
5805             (setcdr (nthcdr i info) nil)))))))
5806
5807 (defun gnus-set-mode-line (where)
5808   "Set the mode line of the article or summary buffers.
5809 If WHERE is `summary', the summary mode line format will be used."
5810   ;; Is this mode line one we keep updated?
5811   (when (and (memq where gnus-updated-mode-lines)
5812              (symbol-value
5813               (intern (format "gnus-%s-mode-line-format-spec" where))))
5814     (let (mode-string)
5815       (save-excursion
5816         ;; We evaluate this in the summary buffer since these
5817         ;; variables are buffer-local to that buffer.
5818         (set-buffer gnus-summary-buffer)
5819        ;; We bind all these variables that are used in the `eval' form
5820         ;; below.
5821         (let* ((mformat (symbol-value
5822                          (intern
5823                           (format "gnus-%s-mode-line-format-spec" where))))
5824                (gnus-tmp-group-name (gnus-group-decoded-name
5825                                      gnus-newsgroup-name))
5826                (gnus-tmp-article-number (or gnus-current-article 0))
5827                (gnus-tmp-unread gnus-newsgroup-unreads)
5828                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5829                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5830                (gnus-tmp-unread-and-unselected
5831                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5832                             (zerop gnus-tmp-unselected))
5833                        "")
5834                       ((zerop gnus-tmp-unselected)
5835                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5836                       (t (format "{%d(+%d) more}"
5837                                  gnus-tmp-unread-and-unticked
5838                                  gnus-tmp-unselected))))
5839                (gnus-tmp-subject
5840                 (if (and gnus-current-headers
5841                          (vectorp gnus-current-headers))
5842                     (gnus-mode-string-quote
5843                      (mail-header-subject gnus-current-headers))
5844                   ""))
5845                bufname-length max-len
5846                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5847           (setq mode-string (eval mformat))
5848           (setq bufname-length (if (string-match "%b" mode-string)
5849                                    (- (length
5850                                        (buffer-name
5851                                         (if (eq where 'summary)
5852                                             nil
5853                                           (get-buffer gnus-article-buffer))))
5854                                       2)
5855                                  0))
5856           (setq max-len (max 4 (if gnus-mode-non-string-length
5857                                    (- (window-width)
5858                                       gnus-mode-non-string-length
5859                                       bufname-length)
5860                                  (length mode-string))))
5861           ;; We might have to chop a bit of the string off...
5862           (when (> (length mode-string) max-len)
5863             (setq mode-string
5864                   (concat (truncate-string-to-width mode-string (- max-len 3))
5865                           "...")))
5866           ;; Pad the mode string a bit.
5867           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5868       ;; Update the mode line.
5869       (setq mode-line-buffer-identification
5870             (gnus-mode-line-buffer-identification (list mode-string)))
5871       (set-buffer-modified-p t))))
5872
5873 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5874   "Go through the HEADERS list and add all Xrefs to a hash table.
5875 The resulting hash table is returned, or nil if no Xrefs were found."
5876   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5877          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5878          (xref-hashtb (gnus-make-hashtable))
5879          start group entry number xrefs header)
5880     (while headers
5881       (setq header (pop headers))
5882       (when (and (setq xrefs (mail-header-xref header))
5883                  (not (memq (setq number (mail-header-number header))
5884                             unreads)))
5885         (setq start 0)
5886         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5887           (setq start (match-end 0))
5888           (setq group (if prefix
5889                           (concat prefix (substring xrefs (match-beginning 1)
5890                                                     (match-end 1)))
5891                         (substring xrefs (match-beginning 1) (match-end 1))))
5892           (setq number
5893                 (string-to-number (substring xrefs (match-beginning 2)
5894                                           (match-end 2))))
5895           (if (setq entry (gnus-gethash group xref-hashtb))
5896               (setcdr entry (cons number (cdr entry)))
5897             (gnus-sethash group (cons number nil) xref-hashtb)))))
5898     (and start xref-hashtb)))
5899
5900 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5901   "Look through all the headers and mark the Xrefs as read."
5902   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5903         name info xref-hashtb idlist method nth4)
5904     (save-excursion
5905       (set-buffer gnus-group-buffer)
5906       (when (setq xref-hashtb
5907                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5908         (mapatoms
5909          (lambda (group)
5910            (unless (string= from-newsgroup (setq name (symbol-name group)))
5911              (setq idlist (symbol-value group))
5912              ;; Dead groups are not updated.
5913              (and (prog1
5914                       (setq info (gnus-get-info name))
5915                     (when (stringp (setq nth4 (gnus-info-method info)))
5916                       (setq nth4 (gnus-server-to-method nth4))))
5917                   ;; Only do the xrefs if the group has the same
5918                   ;; select method as the group we have just read.
5919                   (or (gnus-methods-equal-p
5920                        nth4 (gnus-find-method-for-group from-newsgroup))
5921                       virtual
5922                       (equal nth4 (setq method (gnus-find-method-for-group
5923                                                 from-newsgroup)))
5924                       (and (equal (car nth4) (car method))
5925                            (equal (nth 1 nth4) (nth 1 method))))
5926                   gnus-use-cross-reference
5927                   (or (not (eq gnus-use-cross-reference t))
5928                       virtual
5929                       ;; Only do cross-references on subscribed
5930                       ;; groups, if that is what is wanted.
5931                       (<= (gnus-info-level info) gnus-level-subscribed))
5932                   (gnus-group-make-articles-read name idlist))))
5933          xref-hashtb)))))
5934
5935 (defun gnus-compute-read-articles (group articles)
5936   (let* ((entry (gnus-group-entry group))
5937          (info (nth 2 entry))
5938          (active (gnus-active group))
5939          ninfo)
5940     (when entry
5941       ;; First peel off all invalid article numbers.
5942       (when active
5943         (let ((ids articles)
5944               id first)
5945           (while (setq id (pop ids))
5946             (when (and first (> id (cdr active)))
5947               ;; We'll end up in this situation in one particular
5948               ;; obscure situation.  If you re-scan a group and get
5949               ;; a new article that is cross-posted to a different
5950               ;; group that has not been re-scanned, you might get
5951               ;; crossposted article that has a higher number than
5952               ;; Gnus believes possible.  So we re-activate this
5953               ;; group as well.  This might mean doing the
5954               ;; crossposting thingy will *increase* the number
5955               ;; of articles in some groups.  Tsk, tsk.
5956               (setq active (or (gnus-activate-group group) active)))
5957             (when (or (> id (cdr active))
5958                       (< id (car active)))
5959               (setq articles (delq id articles))))))
5960       ;; If the read list is nil, we init it.
5961       (if (and active
5962                (null (gnus-info-read info))
5963                (> (car active) 1))
5964           (setq ninfo (cons 1 (1- (car active))))
5965         (setq ninfo (gnus-info-read info)))
5966       ;; Then we add the read articles to the range.
5967       (gnus-add-to-range
5968        ninfo (setq articles (sort articles '<))))))
5969
5970 (defun gnus-group-make-articles-read (group articles)
5971   "Update the info of GROUP to say that ARTICLES are read."
5972   (let* ((num 0)
5973          (entry (gnus-group-entry group))
5974          (info (nth 2 entry))
5975          (active (gnus-active group))
5976          range)
5977     (when entry
5978       (setq range (gnus-compute-read-articles group articles))
5979       (with-current-buffer gnus-group-buffer
5980         (gnus-undo-register
5981           `(progn
5982              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5983              (gnus-info-set-read ',info ',(gnus-info-read info))
5984              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5985              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5986              (gnus-group-update-group ,group t))))
5987       ;; Add the read articles to the range.
5988       (gnus-info-set-read info range)
5989       (gnus-request-set-mark group (list (list range 'add '(read))))
5990       ;; Then we have to re-compute how many unread
5991       ;; articles there are in this group.
5992       (when active
5993         (cond
5994          ((not range)
5995           (setq num (- (1+ (cdr active)) (car active))))
5996          ((not (listp (cdr range)))
5997           (setq num (- (cdr active) (- (1+ (cdr range))
5998                                        (car range)))))
5999          (t
6000           (while range
6001             (if (numberp (car range))
6002                 (setq num (1+ num))
6003               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6004             (setq range (cdr range)))
6005           (setq num (- (cdr active) num))))
6006         ;; Update the number of unread articles.
6007         (setcar entry num)
6008         ;; Update the group buffer.
6009         (unless (gnus-ephemeral-group-p group)
6010           (gnus-group-update-group group t))))))
6011
6012 (defvar gnus-newsgroup-none-id 0)
6013
6014 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6015   (let ((cur nntp-server-buffer)
6016         (dependencies
6017          (or dependencies
6018              (with-current-buffer gnus-summary-buffer
6019                gnus-newsgroup-dependencies)))
6020         headers id end ref number
6021         (mail-parse-charset gnus-newsgroup-charset)
6022         (mail-parse-ignored-charsets
6023          (save-excursion (condition-case nil
6024                              (set-buffer gnus-summary-buffer)
6025                            (error))
6026                          gnus-newsgroup-ignored-charsets)))
6027     (save-excursion
6028       (set-buffer nntp-server-buffer)
6029       ;; Translate all TAB characters into SPACE characters.
6030       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6031       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6032       (ietf-drums-unfold-fws)
6033       (gnus-run-hooks 'gnus-parse-headers-hook)
6034       (let ((case-fold-search t)
6035             in-reply-to header p lines chars)
6036         (goto-char (point-min))
6037         ;; Search to the beginning of the next header.  Error messages
6038         ;; do not begin with 2 or 3.
6039         (while (re-search-forward "^[23][0-9]+ " nil t)
6040           (setq id nil
6041                 ref nil)
6042           ;; This implementation of this function, with nine
6043           ;; search-forwards instead of the one re-search-forward and
6044           ;; a case (which basically was the old function) is actually
6045           ;; about twice as fast, even though it looks messier.  You
6046           ;; can't have everything, I guess.  Speed and elegance
6047           ;; doesn't always go hand in hand.
6048           (setq
6049            header
6050            (vector
6051             ;; Number.
6052             (prog1
6053                 (setq number (read cur))
6054               (end-of-line)
6055               (setq p (point))
6056               (narrow-to-region (point)
6057                                 (or (and (search-forward "\n.\n" nil t)
6058                                          (- (point) 2))
6059                                     (point))))
6060             ;; Subject.
6061             (progn
6062               (goto-char p)
6063               (if (search-forward "\nsubject:" nil t)
6064                   (funcall gnus-decode-encoded-word-function
6065                            (nnheader-header-value))
6066                 "(none)"))
6067             ;; From.
6068             (progn
6069               (goto-char p)
6070               (if (search-forward "\nfrom:" nil t)
6071                   (funcall gnus-decode-encoded-word-function
6072                            (nnheader-header-value))
6073                 "(nobody)"))
6074             ;; Date.
6075             (progn
6076               (goto-char p)
6077               (if (search-forward "\ndate:" nil t)
6078                   (nnheader-header-value) ""))
6079             ;; Message-ID.
6080             (progn
6081               (goto-char p)
6082               (setq id (if (re-search-forward
6083                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6084                            ;; We do it this way to make sure the Message-ID
6085                            ;; is (somewhat) syntactically valid.
6086                            (buffer-substring (match-beginning 1)
6087                                              (match-end 1))
6088                          ;; If there was no message-id, we just fake one
6089                          ;; to make subsequent routines simpler.
6090                          (nnheader-generate-fake-message-id number))))
6091             ;; References.
6092             (progn
6093               (goto-char p)
6094               (if (search-forward "\nreferences:" nil t)
6095                   (progn
6096                     (setq end (point))
6097                     (prog1
6098                         (nnheader-header-value)
6099                       (setq ref
6100                             (buffer-substring
6101                              (progn
6102                                (end-of-line)
6103                                (search-backward ">" end t)
6104                                (1+ (point)))
6105                              (progn
6106                                (search-backward "<" end t)
6107                                (point))))))
6108                 ;; Get the references from the in-reply-to header if there
6109                 ;; were no references and the in-reply-to header looks
6110                 ;; promising.
6111                 (if (and (search-forward "\nin-reply-to:" nil t)
6112                          (setq in-reply-to (nnheader-header-value))
6113                          (string-match "<[^>]+>" in-reply-to))
6114                     (let (ref2)
6115                       (setq ref (substring in-reply-to (match-beginning 0)
6116                                            (match-end 0)))
6117                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6118                         (setq ref2 (substring in-reply-to (match-beginning 0)
6119                                               (match-end 0)))
6120                         (when (> (length ref2) (length ref))
6121                           (setq ref ref2)))
6122                       ref)
6123                   (setq ref nil))))
6124             ;; Chars.
6125             (progn
6126               (goto-char p)
6127               (if (search-forward "\nchars: " nil t)
6128                   (if (numberp (setq chars (ignore-errors (read cur))))
6129                       chars -1)
6130                 -1))
6131             ;; Lines.
6132             (progn
6133               (goto-char p)
6134               (if (search-forward "\nlines: " nil t)
6135                   (if (numberp (setq lines (ignore-errors (read cur))))
6136                       lines -1)
6137                 -1))
6138             ;; Xref.
6139             (progn
6140               (goto-char p)
6141               (and (search-forward "\nxref:" nil t)
6142                    (nnheader-header-value)))
6143             ;; Extra.
6144             (when gnus-extra-headers
6145               (let ((extra gnus-extra-headers)
6146                     out)
6147                 (while extra
6148                   (goto-char p)
6149                   (when (search-forward
6150                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6151                     (push (cons (car extra) (nnheader-header-value))
6152                           out))
6153                   (pop extra))
6154                 out))))
6155           (when (equal id ref)
6156             (setq ref nil))
6157
6158           (when gnus-alter-header-function
6159             (funcall gnus-alter-header-function header)
6160             (setq id (mail-header-id header)
6161                   ref (gnus-parent-id (mail-header-references header))))
6162
6163           (when (setq header
6164                       (gnus-dependencies-add-header
6165                        header dependencies force-new))
6166             (push header headers))
6167           (goto-char (point-max))
6168           (widen))
6169         (nreverse headers)))))
6170
6171 ;; Goes through the xover lines and returns a list of vectors
6172 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6173                                                   force-new dependencies
6174                                                   group also-fetch-heads)
6175   "Parse the news overview data in the server buffer.
6176 Return a list of headers that match SEQUENCE (see
6177 `nntp-retrieve-headers')."
6178   ;; Get the Xref when the users reads the articles since most/some
6179   ;; NNTP servers do not include Xrefs when using XOVER.
6180   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6181   (let ((mail-parse-charset gnus-newsgroup-charset)
6182         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6183         (cur nntp-server-buffer)
6184         (dependencies (or dependencies gnus-newsgroup-dependencies))
6185         (allp (cond
6186                ((eq gnus-read-all-available-headers t)
6187                 t)
6188                ((and (stringp gnus-read-all-available-headers)
6189                      group)
6190                 (string-match gnus-read-all-available-headers group))
6191                (t
6192                 nil)))
6193         number headers header)
6194     (save-excursion
6195       (set-buffer nntp-server-buffer)
6196       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6197       ;; Allow the user to mangle the headers before parsing them.
6198       (gnus-run-hooks 'gnus-parse-headers-hook)
6199       (goto-char (point-min))
6200       (gnus-parse-without-error
6201         (while (and (or sequence allp)
6202                     (not (eobp)))
6203           (setq number (read cur))
6204           (when (not allp)
6205             (while (and sequence
6206                         (< (car sequence) number))
6207               (setq sequence (cdr sequence))))
6208           (when (and (or allp
6209                          (and sequence
6210                               (eq number (car sequence))))
6211                      (progn
6212                        (setq sequence (cdr sequence))
6213                        (setq header (inline
6214                                       (gnus-nov-parse-line
6215                                        number dependencies force-new)))))
6216             (push header headers))
6217           (forward-line 1)))
6218       ;; A common bug in inn is that if you have posted an article and
6219       ;; then retrieves the active file, it will answer correctly --
6220       ;; the new article is included.  However, a NOV entry for the
6221       ;; article may not have been generated yet, so this may fail.
6222       ;; We work around this problem by retrieving the last few
6223       ;; headers using HEAD.
6224       (if (or (not also-fetch-heads)
6225               (not sequence))
6226           ;; We (probably) got all the headers.
6227           (nreverse headers)
6228         (let ((gnus-nov-is-evil t))
6229           (nconc
6230            (nreverse headers)
6231            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6232              (gnus-get-newsgroup-headers))))))))
6233
6234 (defun gnus-article-get-xrefs ()
6235   "Fill in the Xref value in `gnus-current-headers', if necessary.
6236 This is meant to be called in `gnus-article-internal-prepare-hook'."
6237   (let ((headers (with-current-buffer gnus-summary-buffer
6238                    gnus-current-headers)))
6239     (or (not gnus-use-cross-reference)
6240         (not headers)
6241         (and (mail-header-xref headers)
6242              (not (string= (mail-header-xref headers) "")))
6243         (let ((case-fold-search t)
6244               xref)
6245           (save-restriction
6246             (nnheader-narrow-to-headers)
6247             (goto-char (point-min))
6248             (when (or (and (not (eobp))
6249                            (eq (downcase (char-after)) ?x)
6250                            (looking-at "Xref:"))
6251                       (search-forward "\nXref:" nil t))
6252               (goto-char (1+ (match-end 0)))
6253               (setq xref (buffer-substring (point) (point-at-eol)))
6254               (mail-header-set-xref headers xref)))))))
6255
6256 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6257   "Find article ID and insert the summary line for that article.
6258 OLD-HEADER can either be a header or a line number to insert
6259 the subject line on."
6260   (let* ((line (and (numberp old-header) old-header))
6261          (old-header (and (vectorp old-header) old-header))
6262          (header (cond ((and old-header use-old-header)
6263                         old-header)
6264                        ((and (numberp id)
6265                              (gnus-number-to-header id))
6266                         (gnus-number-to-header id))
6267                        (t
6268                         (gnus-read-header id))))
6269          (number (and (numberp id) id))
6270          d)
6271     (when header
6272       ;; Rebuild the thread that this article is part of and go to the
6273       ;; article we have fetched.
6274       (when (and (not gnus-show-threads)
6275                  old-header)
6276         (when (and number
6277                    (setq d (gnus-data-find (mail-header-number old-header))))
6278           (goto-char (gnus-data-pos d))
6279           (gnus-data-remove
6280            number
6281            (- (point-at-bol)
6282               (prog1
6283                   (1+ (point-at-eol))
6284                 (gnus-delete-line))))))
6285       ;; Remove list identifiers from subject.
6286       (when gnus-list-identifiers
6287         (let ((gnus-newsgroup-headers (list header)))
6288           (gnus-summary-remove-list-identifiers)))
6289       (when old-header
6290         (mail-header-set-number header (mail-header-number old-header)))
6291       (setq gnus-newsgroup-sparse
6292             (delq (setq number (mail-header-number header))
6293                   gnus-newsgroup-sparse))
6294       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6295       (push number gnus-newsgroup-limit)
6296       (gnus-rebuild-thread (mail-header-id header) line)
6297       (gnus-summary-goto-subject number nil t))
6298     (when (and (numberp number)
6299                (> number 0))
6300       ;; We have to update the boundaries even if we can't fetch the
6301       ;; article if ID is a number -- so that the next `P' or `N'
6302       ;; command will fetch the previous (or next) article even
6303       ;; if the one we tried to fetch this time has been canceled.
6304       (when (> number gnus-newsgroup-end)
6305         (setq gnus-newsgroup-end number))
6306       (when (< number gnus-newsgroup-begin)
6307         (setq gnus-newsgroup-begin number))
6308       (setq gnus-newsgroup-unselected
6309             (delq number gnus-newsgroup-unselected)))
6310     ;; Report back a success?
6311     (and header (mail-header-number header))))
6312
6313 ;;; Process/prefix in the summary buffer
6314
6315 (defun gnus-summary-work-articles (n)
6316   "Return a list of articles to be worked upon.
6317 The prefix argument, the list of process marked articles, and the
6318 current article will be taken into consideration."
6319   (save-excursion
6320     (set-buffer gnus-summary-buffer)
6321     (cond
6322      (n
6323       ;; A numerical prefix has been given.
6324       (setq n (prefix-numeric-value n))
6325       (let ((backward (< n 0))
6326             (n (abs (prefix-numeric-value n)))
6327             articles article)
6328         (save-excursion
6329           (while
6330               (and (> n 0)
6331                    (push (setq article (gnus-summary-article-number))
6332                          articles)
6333                    (if backward
6334                        (gnus-summary-find-prev nil article)
6335                      (gnus-summary-find-next nil article)))
6336             (decf n)))
6337         (nreverse articles)))
6338      ((and (gnus-region-active-p) (mark))
6339       (message "region active")
6340       ;; Work on the region between point and mark.
6341       (let ((max (max (point) (mark)))
6342             articles article)
6343         (save-excursion
6344           (goto-char (min (point) (mark)))
6345           (while
6346               (and
6347                (push (setq article (gnus-summary-article-number)) articles)
6348                (gnus-summary-find-next nil article)
6349                (< (point) max)))
6350           (nreverse articles))))
6351      (gnus-newsgroup-processable
6352       ;; There are process-marked articles present.
6353       ;; Save current state.
6354       (gnus-summary-save-process-mark)
6355       ;; Return the list.
6356       (reverse gnus-newsgroup-processable))
6357      (t
6358       ;; Just return the current article.
6359       (list (gnus-summary-article-number))))))
6360
6361 (defmacro gnus-summary-iterate (arg &rest forms)
6362   "Iterate over the process/prefixed articles and do FORMS.
6363 ARG is the interactive prefix given to the command.  FORMS will be
6364 executed with point over the summary line of the articles."
6365   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6366     `(let ((,articles (gnus-summary-work-articles ,arg)))
6367        (while ,articles
6368          (gnus-summary-goto-subject (car ,articles))
6369          ,@forms
6370          (pop ,articles)))))
6371
6372 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6373 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6374
6375 (defun gnus-summary-save-process-mark ()
6376   "Push the current set of process marked articles on the stack."
6377   (interactive)
6378   (push (copy-sequence gnus-newsgroup-processable)
6379         gnus-newsgroup-process-stack))
6380
6381 (defun gnus-summary-kill-process-mark ()
6382   "Push the current set of process marked articles on the stack and unmark."
6383   (interactive)
6384   (gnus-summary-save-process-mark)
6385   (gnus-summary-unmark-all-processable))
6386
6387 (defun gnus-summary-yank-process-mark ()
6388   "Pop the last process mark state off the stack and restore it."
6389   (interactive)
6390   (unless gnus-newsgroup-process-stack
6391     (error "Empty mark stack"))
6392   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6393
6394 (defun gnus-summary-process-mark-set (set)
6395   "Make SET into the current process marked articles."
6396   (gnus-summary-unmark-all-processable)
6397   (mapc 'gnus-summary-set-process-mark set))
6398
6399 ;;; Searching and stuff
6400
6401 (defun gnus-summary-search-group (&optional backward use-level)
6402   "Search for next unread newsgroup.
6403 If optional argument BACKWARD is non-nil, search backward instead."
6404   (save-excursion
6405     (set-buffer gnus-group-buffer)
6406     (when (gnus-group-search-forward
6407            backward nil (if use-level (gnus-group-group-level) nil))
6408       (gnus-group-group-name))))
6409
6410 (defun gnus-summary-best-group (&optional exclude-group)
6411   "Find the name of the best unread group.
6412 If EXCLUDE-GROUP, do not go to this group."
6413   (with-current-buffer gnus-group-buffer
6414     (save-excursion
6415       (gnus-group-best-unread-group exclude-group))))
6416
6417 (defun gnus-summary-find-next (&optional unread article backward)
6418   (if backward
6419       (gnus-summary-find-prev unread article)
6420     (let* ((dummy (gnus-summary-article-intangible-p))
6421            (article (or article (gnus-summary-article-number)))
6422            (data (gnus-data-find-list article))
6423            result)
6424       (when (and (not dummy)
6425                  (or (not gnus-summary-check-current)
6426                      (not unread)
6427                      (not (gnus-data-unread-p (car data)))))
6428         (setq data (cdr data)))
6429       (when (setq result
6430                   (if unread
6431                       (progn
6432                         (while data
6433                           (unless (memq (gnus-data-number (car data))
6434                                         (cond
6435                                          ((eq gnus-auto-goto-ignores
6436                                               'always-undownloaded)
6437                                           gnus-newsgroup-undownloaded)
6438                                          (gnus-plugged
6439                                           nil)
6440                                          ((eq gnus-auto-goto-ignores
6441                                               'unfetched)
6442                                           gnus-newsgroup-unfetched)
6443                                          ((eq gnus-auto-goto-ignores
6444                                               'undownloaded)
6445                                           gnus-newsgroup-undownloaded)))
6446                             (when (gnus-data-unread-p (car data))
6447                               (setq result (car data)
6448                                     data nil)))
6449                           (setq data (cdr data)))
6450                         result)
6451                     (car data)))
6452         (goto-char (gnus-data-pos result))
6453         (gnus-data-number result)))))
6454
6455 (defun gnus-summary-find-prev (&optional unread article)
6456   (let* ((eobp (eobp))
6457          (article (or article (gnus-summary-article-number)))
6458          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6459          result)
6460     (when (and (not eobp)
6461                (or (not gnus-summary-check-current)
6462                    (not unread)
6463                    (not (gnus-data-unread-p (car data)))))
6464       (setq data (cdr data)))
6465     (when (setq result
6466                 (if unread
6467                     (progn
6468                       (while data
6469                         (unless (memq (gnus-data-number (car data))
6470                                       (cond
6471                                        ((eq gnus-auto-goto-ignores
6472                                             'always-undownloaded)
6473                                         gnus-newsgroup-undownloaded)
6474                                        (gnus-plugged
6475                                         nil)
6476                                        ((eq gnus-auto-goto-ignores
6477                                             'unfetched)
6478                                         gnus-newsgroup-unfetched)
6479                                        ((eq gnus-auto-goto-ignores
6480                                             'undownloaded)
6481                                         gnus-newsgroup-undownloaded)))
6482                           (when (gnus-data-unread-p (car data))
6483                             (setq result (car data)
6484                                   data nil)))
6485                         (setq data (cdr data)))
6486                       result)
6487                   (car data)))
6488       (goto-char (gnus-data-pos result))
6489       (gnus-data-number result))))
6490
6491 (defun gnus-summary-find-subject (subject &optional unread backward article)
6492   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6493          (article (or article (gnus-summary-article-number)))
6494          (articles (gnus-data-list backward))
6495          (arts (gnus-data-find-list article articles))
6496          result)
6497     (when (or (not gnus-summary-check-current)
6498               (not unread)
6499               (not (gnus-data-unread-p (car arts))))
6500       (setq arts (cdr arts)))
6501     (while arts
6502       (and (or (not unread)
6503                (gnus-data-unread-p (car arts)))
6504            (vectorp (gnus-data-header (car arts)))
6505            (gnus-subject-equal
6506             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6507            (setq result (car arts)
6508                  arts nil))
6509       (setq arts (cdr arts)))
6510     (and result
6511          (goto-char (gnus-data-pos result))
6512          (gnus-data-number result))))
6513
6514 (defun gnus-summary-search-forward (&optional unread subject backward)
6515   "Search forward for an article.
6516 If UNREAD, look for unread articles.  If SUBJECT, look for
6517 articles with that subject.  If BACKWARD, search backward instead."
6518   (cond (subject (gnus-summary-find-subject subject unread backward))
6519         (backward (gnus-summary-find-prev unread))
6520         (t (gnus-summary-find-next unread))))
6521
6522 (defun gnus-recenter (&optional n)
6523   "Center point in window and redisplay frame.
6524 Also do horizontal recentering."
6525   (interactive "P")
6526   (when (and gnus-auto-center-summary
6527              (not (eq gnus-auto-center-summary 'vertical)))
6528     (gnus-horizontal-recenter))
6529   (recenter n))
6530
6531 (defun gnus-summary-recenter ()
6532   "Center point in the summary window.
6533 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6534 displayed, no centering will be performed."
6535   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6536   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6537   (interactive)
6538   ;; The user has to want it.
6539   (when gnus-auto-center-summary
6540     (let* ((top (cond ((< (window-height) 4) 0)
6541                       ((< (window-height) 7) 1)
6542                       (t (if (numberp gnus-auto-center-summary)
6543                              gnus-auto-center-summary
6544                            (/ (1- (window-height)) 2)))))
6545            (height (1- (window-height)))
6546            (bottom (save-excursion (goto-char (point-max))
6547                                    (forward-line (- height))
6548                                    (point)))
6549            (window (get-buffer-window (current-buffer))))
6550       (when (get-buffer-window gnus-article-buffer)
6551         ;; Only do recentering when the article buffer is displayed,
6552         ;; Set the window start to either `bottom', which is the biggest
6553         ;; possible valid number, or the second line from the top,
6554         ;; whichever is the least.
6555         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6556           (if (> bottom top-pos)
6557               ;; Keep the second line from the top visible
6558               (set-window-start window top-pos t)
6559             ;; Try to keep the bottom line visible; if it's partially
6560             ;; obscured, either scroll one more line to make it fully
6561             ;; visible, or revert to using TOP-POS.
6562             (save-excursion
6563               (goto-char (point-max))
6564               (forward-line -1)
6565               (let ((last-line-start (point)))
6566                 (goto-char bottom)
6567                 (set-window-start window (point) t)
6568                 (when (not (pos-visible-in-window-p last-line-start window))
6569                   (forward-line 1)
6570                   (set-window-start window (min (point) top-pos) t)))))))
6571       ;; Do horizontal recentering while we're at it.
6572       (when (and (get-buffer-window (current-buffer) t)
6573                  (not (eq gnus-auto-center-summary 'vertical)))
6574         (let ((selected (selected-window)))
6575           (select-window (get-buffer-window (current-buffer) t))
6576           (gnus-summary-position-point)
6577           (gnus-horizontal-recenter)
6578           (select-window selected))))))
6579
6580 (defun gnus-summary-jump-to-group (newsgroup)
6581   "Move point to NEWSGROUP in group mode buffer."
6582   ;; Keep update point of group mode buffer if visible.
6583   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6584       (save-window-excursion
6585         ;; Take care of tree window mode.
6586         (when (get-buffer-window gnus-group-buffer)
6587           (pop-to-buffer gnus-group-buffer))
6588         (gnus-group-jump-to-group newsgroup))
6589     (save-excursion
6590       ;; Take care of tree window mode.
6591       (if (get-buffer-window gnus-group-buffer)
6592           (pop-to-buffer gnus-group-buffer)
6593         (set-buffer gnus-group-buffer))
6594       (gnus-group-jump-to-group newsgroup))))
6595
6596 ;; This function returns a list of article numbers based on the
6597 ;; difference between the ranges of read articles in this group and
6598 ;; the range of active articles.
6599 (defun gnus-list-of-unread-articles (group)
6600   (let* ((read (gnus-info-read (gnus-get-info group)))
6601          (active (or (gnus-active group) (gnus-activate-group group)))
6602          (last (or (cdr active)
6603                    (error "Group %s couldn't be activated " group)))
6604          first nlast unread)
6605     ;; If none are read, then all are unread.
6606     (if (not read)
6607         (setq first (car active))
6608       ;; If the range of read articles is a single range, then the
6609       ;; first unread article is the article after the last read
6610       ;; article.  Sounds logical, doesn't it?
6611       (if (and (not (listp (cdr read)))
6612                (or (< (car read) (car active))
6613                    (progn (setq read (list read))
6614                           nil)))
6615           (setq first (max (car active) (1+ (cdr read))))
6616         ;; `read' is a list of ranges.
6617         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6618                                   (caar read)))
6619                   1)
6620           (setq first (car active)))
6621         (while read
6622           (when first
6623             (while (< first nlast)
6624               (setq unread (cons first unread)
6625                     first (1+ first))))
6626           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6627           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6628           (setq read (cdr read)))))
6629     ;; And add the last unread articles.
6630     (while (<= first last)
6631       (setq unread (cons first unread)
6632             first (1+ first)))
6633     ;; Return the list of unread articles.
6634     (delq 0 (nreverse unread))))
6635
6636 (defun gnus-list-of-read-articles (group)
6637   "Return a list of unread, unticked and non-dormant articles."
6638   (let* ((info (gnus-get-info group))
6639          (marked (gnus-info-marks info))
6640          (active (gnus-active group)))
6641     (and info active
6642          (gnus-list-range-difference
6643           (gnus-list-range-difference
6644            (gnus-sorted-complement
6645             (gnus-uncompress-range active)
6646             (gnus-list-of-unread-articles group))
6647            (cdr (assq 'dormant marked)))
6648           (cdr (assq 'tick marked))))))
6649
6650 ;; This function returns a sequence of article numbers based on the
6651 ;; difference between the ranges of read articles in this group and
6652 ;; the range of active articles.
6653 (defun gnus-sequence-of-unread-articles (group)
6654   (let* ((read (gnus-info-read (gnus-get-info group)))
6655          (active (or (gnus-active group) (gnus-activate-group group)))
6656          (last (cdr active))
6657          first nlast unread)
6658     ;; If none are read, then all are unread.
6659     (if (not read)
6660         (setq first (car active))
6661       ;; If the range of read articles is a single range, then the
6662       ;; first unread article is the article after the last read
6663       ;; article.  Sounds logical, doesn't it?
6664       (if (and (not (listp (cdr read)))
6665                (or (< (car read) (car active))
6666                    (progn (setq read (list read))
6667                           nil)))
6668           (setq first (max (car active) (1+ (cdr read))))
6669         ;; `read' is a list of ranges.
6670         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6671                                   (caar read)))
6672                   1)
6673           (setq first (car active)))
6674         (while read
6675           (when first
6676             (push (cons first nlast) unread))
6677           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6678           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6679           (setq read (cdr read)))))
6680     ;; And add the last unread articles.
6681     (cond ((not (and first last))
6682            nil)
6683           ((< first last)
6684            (push (cons first last) unread))
6685           ((= first last)
6686            (push first unread)))
6687     ;; Return the sequence of unread articles.
6688     (delq 0 (nreverse unread))))
6689
6690 ;; Various summary commands
6691
6692 (defun gnus-summary-select-article-buffer ()
6693   "Reconfigure windows to show article buffer."
6694   (interactive)
6695   (if (not (gnus-buffer-live-p gnus-article-buffer))
6696       (error "There is no article buffer for this summary buffer")
6697     (gnus-configure-windows 'article)
6698     (select-window (get-buffer-window gnus-article-buffer))))
6699
6700 (defun gnus-summary-universal-argument (arg)
6701   "Perform any operation on all articles that are process/prefixed."
6702   (interactive "P")
6703   (let ((articles (gnus-summary-work-articles arg))
6704         func article)
6705     (if (eq
6706          (setq
6707           func
6708           (key-binding
6709            (read-key-sequence
6710             (substitute-command-keys
6711              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6712          'undefined)
6713         (gnus-error 1 "Undefined key")
6714       (save-excursion
6715         (while articles
6716           (gnus-summary-goto-subject (setq article (pop articles)))
6717           (let (gnus-newsgroup-processable)
6718             (command-execute func))
6719           (gnus-summary-remove-process-mark article)))))
6720   (gnus-summary-position-point))
6721
6722 (defun gnus-summary-toggle-truncation (&optional arg)
6723   "Toggle truncation of summary lines.
6724 With ARG, turn line truncation on if ARG is positive."
6725   (interactive "P")
6726   (setq truncate-lines
6727         (if (null arg) (not truncate-lines)
6728           (> (prefix-numeric-value arg) 0)))
6729   (redraw-display))
6730
6731 (defun gnus-summary-find-for-reselect ()
6732   "Return the number of an article to stay on across a reselect.
6733 The current article is considered, then following articles, then previous
6734 articles.  An article is sought which is not cancelled and isn't a temporary
6735 insertion from another group.  If there's no such then return a dummy 0."
6736   (let (found)
6737     (dolist (rev '(nil t))
6738       (unless found      ; don't demand the reverse list if we don't need it
6739         (let ((data (gnus-data-find-list
6740                      (gnus-summary-article-number) (gnus-data-list rev))))
6741           (while (and data (not found))
6742             (if (and (< 0 (gnus-data-number (car data)))
6743                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6744                 (setq found (gnus-data-number (car data))))
6745             (setq data (cdr data))))))
6746     (or found 0)))
6747
6748 (defun gnus-summary-reselect-current-group (&optional all rescan)
6749   "Exit and then reselect the current newsgroup.
6750 The prefix argument ALL means to select all articles."
6751   (interactive "P")
6752   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6753     (error "Ephemeral groups can't be reselected"))
6754   (let ((current-subject (gnus-summary-find-for-reselect))
6755         (group gnus-newsgroup-name))
6756     (setq gnus-newsgroup-begin nil)
6757     (gnus-summary-exit nil 'leave-hidden)
6758     ;; We have to adjust the point of group mode buffer because
6759     ;; point was moved to the next unread newsgroup by exiting.
6760     (gnus-summary-jump-to-group group)
6761     (when rescan
6762       (save-excursion
6763         (gnus-group-get-new-news-this-group 1)))
6764     (gnus-group-read-group all t)
6765     (gnus-summary-goto-subject current-subject nil t)))
6766
6767 (defun gnus-summary-rescan-group (&optional all)
6768   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6769   (interactive "P")
6770   (gnus-summary-reselect-current-group all t))
6771
6772 (defun gnus-summary-update-info (&optional non-destructive)
6773   (save-excursion
6774     (let ((group gnus-newsgroup-name))
6775       (when group
6776         (when gnus-newsgroup-kill-headers
6777           (setq gnus-newsgroup-killed
6778                 (gnus-compress-sequence
6779                  (gnus-sorted-union
6780                   (gnus-list-range-intersection
6781                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6782                   gnus-newsgroup-unreads)
6783                  t)))
6784         (unless (listp (cdr gnus-newsgroup-killed))
6785           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6786         (let ((headers gnus-newsgroup-headers))
6787           ;; Set the new ranges of read articles.
6788           (with-current-buffer gnus-group-buffer
6789             (gnus-undo-force-boundary))
6790           (gnus-update-read-articles
6791            group (gnus-sorted-union
6792                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6793           ;; Set the current article marks.
6794           (let ((gnus-newsgroup-scored
6795                  (if (and (not gnus-save-score)
6796                           (not non-destructive))
6797                      nil
6798                    gnus-newsgroup-scored)))
6799             (save-excursion
6800               (gnus-update-marks)))
6801           ;; Do the cross-ref thing.
6802           (when gnus-use-cross-reference
6803             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6804           ;; Do not switch windows but change the buffer to work.
6805           (set-buffer gnus-group-buffer)
6806           (unless (gnus-ephemeral-group-p group)
6807             (gnus-group-update-group group)))))))
6808
6809 (defun gnus-summary-save-newsrc (&optional force)
6810   "Save the current number of read/marked articles in the dribble buffer.
6811 The dribble buffer will then be saved.
6812 If FORCE (the prefix), also save the .newsrc file(s)."
6813   (interactive "P")
6814   (gnus-summary-update-info t)
6815   (if force
6816       (gnus-save-newsrc-file)
6817     (gnus-dribble-save)))
6818
6819 (defun gnus-summary-exit (&optional temporary leave-hidden)
6820   "Exit reading current newsgroup, and then return to group selection mode.
6821 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6822   (interactive)
6823   (gnus-set-global-variables)
6824   (when (gnus-buffer-live-p gnus-article-buffer)
6825     (save-excursion
6826       (set-buffer gnus-article-buffer)
6827       (mm-destroy-parts gnus-article-mime-handles)
6828       ;; Set it to nil for safety reason.
6829       (setq gnus-article-mime-handle-alist nil)
6830       (setq gnus-article-mime-handles nil)))
6831   (gnus-kill-save-kill-buffer)
6832   (gnus-async-halt-prefetch)
6833   (let* ((group gnus-newsgroup-name)
6834          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6835          (gnus-group-is-exiting-p t)
6836          (mode major-mode)
6837          (group-point nil)
6838          (buf (current-buffer)))
6839     (unless quit-config
6840       ;; Do adaptive scoring, and possibly save score files.
6841       (when gnus-newsgroup-adaptive
6842         (gnus-score-adaptive))
6843       (when gnus-use-scoring
6844         (gnus-score-save)))
6845     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6846     ;; If we have several article buffers, we kill them at exit.
6847     (unless gnus-single-article-buffer
6848       (gnus-kill-buffer gnus-article-buffer)
6849       (gnus-kill-buffer gnus-original-article-buffer)
6850       (setq gnus-article-current nil))
6851     (when gnus-use-cache
6852       (gnus-cache-possibly-remove-articles)
6853       (gnus-cache-save-buffers))
6854     (gnus-async-prefetch-remove-group group)
6855     (when gnus-suppress-duplicates
6856       (gnus-dup-enter-articles))
6857     (when gnus-use-trees
6858       (gnus-tree-close group))
6859     (when gnus-use-cache
6860       (gnus-cache-write-active))
6861     ;; Remove entries for this group.
6862     (nnmail-purge-split-history (gnus-group-real-name group))
6863     ;; Make all changes in this group permanent.
6864     (unless quit-config
6865       (gnus-run-hooks 'gnus-exit-group-hook)
6866       (gnus-summary-update-info))
6867     (gnus-close-group group)
6868     ;; Make sure where we were, and go to next newsgroup.
6869     (set-buffer gnus-group-buffer)
6870     (unless quit-config
6871       (gnus-group-jump-to-group group))
6872     (gnus-run-hooks 'gnus-summary-exit-hook)
6873     (unless (or quit-config
6874                 ;; If this group has disappeared from the summary
6875                 ;; buffer, don't skip forwards.
6876                 (not (string= group (gnus-group-group-name))))
6877       (gnus-group-next-unread-group 1))
6878     (setq group-point (point))
6879     (if temporary
6880         nil                             ;Nothing to do.
6881       ;; If we have several article buffers, we kill them at exit.
6882       (unless gnus-single-article-buffer
6883         (gnus-kill-buffer gnus-article-buffer)
6884         (gnus-kill-buffer gnus-original-article-buffer)
6885         (setq gnus-article-current nil))
6886       (set-buffer buf)
6887       (if (not gnus-kill-summary-on-exit)
6888           (progn
6889             (gnus-deaden-summary)
6890             (setq mode nil))
6891         ;; We set all buffer-local variables to nil.  It is unclear why
6892         ;; this is needed, but if we don't, buffer-local variables are
6893         ;; not garbage-collected, it seems.  This would the lead to en
6894         ;; ever-growing Emacs.
6895         (gnus-summary-clear-local-variables)
6896         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6897           (gnus-summary-clear-local-variables))
6898         (when (get-buffer gnus-article-buffer)
6899           (bury-buffer gnus-article-buffer))
6900         ;; Return to group mode buffer.
6901         (when (eq mode 'gnus-summary-mode)
6902           (gnus-kill-buffer buf)))
6903       (setq gnus-current-select-method gnus-select-method)
6904       (set-buffer gnus-group-buffer)
6905       (if quit-config
6906           (gnus-handle-ephemeral-exit quit-config)
6907         (goto-char group-point)
6908         ;; If gnus-group-buffer is already displayed, make sure we also move
6909         ;; the cursor in the window that displays it.
6910         (let ((win (get-buffer-window (current-buffer) 0)))
6911           (if win (set-window-point win (point))))
6912         (unless leave-hidden
6913           (gnus-configure-windows 'group 'force)))
6914       ;; Clear the current group name.
6915       (unless quit-config
6916         (setq gnus-newsgroup-name nil)))))
6917
6918 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6919 (defun gnus-summary-exit-no-update (&optional no-questions)
6920   "Quit reading current newsgroup without updating read article info."
6921   (interactive)
6922   (let* ((group gnus-newsgroup-name)
6923          (gnus-group-is-exiting-p t)
6924          (gnus-group-is-exiting-without-update-p t)
6925          (quit-config (gnus-group-quit-config group)))
6926     (when (or no-questions
6927               gnus-expert-user
6928               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6929       (gnus-async-halt-prefetch)
6930       (run-hooks 'gnus-summary-prepare-exit-hook)
6931       (when (gnus-buffer-live-p gnus-article-buffer)
6932         (save-excursion
6933           (set-buffer gnus-article-buffer)
6934           (mm-destroy-parts gnus-article-mime-handles)
6935           ;; Set it to nil for safety reason.
6936           (setq gnus-article-mime-handle-alist nil)
6937           (setq gnus-article-mime-handles nil)))
6938       ;; If we have several article buffers, we kill them at exit.
6939       (unless gnus-single-article-buffer
6940         (gnus-kill-buffer gnus-article-buffer)
6941         (gnus-kill-buffer gnus-original-article-buffer)
6942         (setq gnus-article-current nil))
6943       (if (not gnus-kill-summary-on-exit)
6944           (gnus-deaden-summary)
6945         (gnus-close-group group)
6946         (gnus-summary-clear-local-variables)
6947         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6948           (gnus-summary-clear-local-variables))
6949         (gnus-kill-buffer gnus-summary-buffer))
6950       (unless gnus-single-article-buffer
6951         (setq gnus-article-current nil))
6952       (when gnus-use-trees
6953         (gnus-tree-close group))
6954       (gnus-async-prefetch-remove-group group)
6955       (when (get-buffer gnus-article-buffer)
6956         (bury-buffer gnus-article-buffer))
6957       ;; Return to the group buffer.
6958       (gnus-configure-windows 'group 'force)
6959       ;; Clear the current group name.
6960       (setq gnus-newsgroup-name nil)
6961       (unless (gnus-ephemeral-group-p group)
6962         (gnus-group-update-group group))
6963       (when (equal (gnus-group-group-name) group)
6964         (gnus-group-next-unread-group 1))
6965       (when quit-config
6966         (gnus-handle-ephemeral-exit quit-config)))))
6967
6968 (defun gnus-handle-ephemeral-exit (quit-config)
6969   "Handle movement when leaving an ephemeral group.
6970 The state which existed when entering the ephemeral is reset."
6971   (if (not (buffer-name (car quit-config)))
6972       (gnus-configure-windows 'group 'force)
6973     (set-buffer (car quit-config))
6974     (cond ((eq major-mode 'gnus-summary-mode)
6975            (gnus-set-global-variables))
6976           ((eq major-mode 'gnus-article-mode)
6977            (save-excursion
6978              ;; The `gnus-summary-buffer' variable may point
6979              ;; to the old summary buffer when using a single
6980              ;; article buffer.
6981              (unless (gnus-buffer-live-p gnus-summary-buffer)
6982                (set-buffer gnus-group-buffer))
6983              (set-buffer gnus-summary-buffer)
6984              (gnus-set-global-variables))))
6985     (if (or (eq (cdr quit-config) 'article)
6986             (eq (cdr quit-config) 'pick))
6987         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6988             (gnus-configure-windows 'pick 'force)
6989           (gnus-configure-windows (cdr quit-config) 'force))
6990       (gnus-configure-windows (cdr quit-config) 'force))
6991     (when (eq major-mode 'gnus-summary-mode)
6992       (gnus-summary-recenter)
6993       (gnus-summary-position-point))))
6994
6995 ;;; Dead summaries.
6996
6997 (defvar gnus-dead-summary-mode-map nil)
6998
6999 (unless gnus-dead-summary-mode-map
7000   (setq gnus-dead-summary-mode-map (make-keymap))
7001   (suppress-keymap gnus-dead-summary-mode-map)
7002   (substitute-key-definition
7003    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7004   (dolist (key '("\C-d" "\r" "\177" [delete]))
7005     (define-key gnus-dead-summary-mode-map
7006       key 'gnus-summary-wake-up-the-dead))
7007   (dolist (key '("q" "Q"))
7008     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7009
7010 (defvar gnus-dead-summary-mode nil
7011   "Minor mode for Gnus summary buffers.")
7012
7013 (defun gnus-dead-summary-mode (&optional arg)
7014   "Minor mode for Gnus summary buffers."
7015   (interactive "P")
7016   (when (eq major-mode 'gnus-summary-mode)
7017     (make-local-variable 'gnus-dead-summary-mode)
7018     (setq gnus-dead-summary-mode
7019           (if (null arg) (not gnus-dead-summary-mode)
7020             (> (prefix-numeric-value arg) 0)))
7021     (when gnus-dead-summary-mode
7022       (add-minor-mode
7023        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7024
7025 (defun gnus-deaden-summary ()
7026   "Make the current summary buffer into a dead summary buffer."
7027   ;; Kill any previous dead summary buffer.
7028   (when (and gnus-dead-summary
7029              (buffer-name gnus-dead-summary))
7030     (with-current-buffer gnus-dead-summary
7031       (when gnus-dead-summary-mode
7032         (kill-buffer (current-buffer)))))
7033   ;; Make this the current dead summary.
7034   (setq gnus-dead-summary (current-buffer))
7035   (gnus-dead-summary-mode 1)
7036   (let ((name (buffer-name)))
7037     (when (string-match "Summary" name)
7038       (rename-buffer
7039        (concat (substring name 0 (match-beginning 0)) "Dead "
7040                (substring name (match-beginning 0)))
7041        t)
7042       (bury-buffer))))
7043
7044 (defun gnus-kill-or-deaden-summary (buffer)
7045   "Kill or deaden the summary BUFFER."
7046   (save-excursion
7047     (when (and (buffer-name buffer)
7048                (not gnus-single-article-buffer))
7049       (with-current-buffer buffer
7050         (gnus-kill-buffer gnus-article-buffer)
7051         (gnus-kill-buffer gnus-original-article-buffer)))
7052     (cond
7053      ;; Kill the buffer.
7054      (gnus-kill-summary-on-exit
7055       (when (and gnus-use-trees
7056                  (gnus-buffer-exists-p buffer))
7057         (save-excursion
7058           (set-buffer buffer)
7059           (gnus-tree-close gnus-newsgroup-name)))
7060       (gnus-kill-buffer buffer))
7061      ;; Deaden the buffer.
7062      ((gnus-buffer-exists-p buffer)
7063       (save-excursion
7064         (set-buffer buffer)
7065         (gnus-deaden-summary))))))
7066
7067 (defun gnus-summary-wake-up-the-dead (&rest args)
7068   "Wake up the dead summary buffer."
7069   (interactive)
7070   (gnus-dead-summary-mode -1)
7071   (let ((name (buffer-name)))
7072     (when (string-match "Dead " name)
7073       (rename-buffer
7074        (concat (substring name 0 (match-beginning 0))
7075                (substring name (match-end 0)))
7076        t)))
7077   (gnus-message 3 "This dead summary is now alive again"))
7078
7079 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7080 (defun gnus-summary-fetch-faq (&optional faq-dir)
7081   "Fetch the FAQ for the current group.
7082 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7083 in."
7084   (interactive
7085    (list
7086     (when current-prefix-arg
7087       (completing-read
7088        "FAQ dir: " (and (listp gnus-group-faq-directory)
7089                         (mapcar 'list
7090                                 gnus-group-faq-directory))))))
7091   (let (gnus-faq-buffer)
7092     (when (setq gnus-faq-buffer
7093                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7094       (gnus-configure-windows 'summary-faq))))
7095
7096 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7097 (defun gnus-summary-describe-group (&optional force)
7098   "Describe the current newsgroup."
7099   (interactive "P")
7100   (gnus-group-describe-group force gnus-newsgroup-name))
7101
7102 (defun gnus-summary-describe-briefly ()
7103   "Describe summary mode commands briefly."
7104   (interactive)
7105   (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")))
7106
7107 ;; Walking around group mode buffer from summary mode.
7108
7109 (defun gnus-summary-next-group (&optional no-article target-group backward)
7110   "Exit current newsgroup and then select next unread newsgroup.
7111 If prefix argument NO-ARTICLE is non-nil, no article is selected
7112 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7113 previous group instead."
7114   (interactive "P")
7115   ;; Stop pre-fetching.
7116   (gnus-async-halt-prefetch)
7117   (let ((current-group gnus-newsgroup-name)
7118         (current-buffer (current-buffer))
7119         entered)
7120     ;; First we semi-exit this group to update Xrefs and all variables.
7121     ;; We can't do a real exit, because the window conf must remain
7122     ;; the same in case the user is prompted for info, and we don't
7123     ;; want the window conf to change before that...
7124     (gnus-summary-exit t)
7125     (while (not entered)
7126       ;; Then we find what group we are supposed to enter.
7127       (set-buffer gnus-group-buffer)
7128       (gnus-group-jump-to-group current-group)
7129       (setq target-group
7130             (or target-group
7131                 (if (eq gnus-keep-same-level 'best)
7132                     (gnus-summary-best-group gnus-newsgroup-name)
7133                   (gnus-summary-search-group backward gnus-keep-same-level))))
7134       (if (not target-group)
7135           ;; There are no further groups, so we return to the group
7136           ;; buffer.
7137           (progn
7138             (gnus-message 5 "Returning to the group buffer")
7139             (setq entered t)
7140             (when (gnus-buffer-live-p current-buffer)
7141               (set-buffer current-buffer)
7142               (gnus-summary-exit))
7143             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7144         ;; We try to enter the target group.
7145         (gnus-group-jump-to-group target-group)
7146         (let ((unreads (gnus-group-group-unread)))
7147           (if (and (or (eq t unreads)
7148                        (and unreads (not (zerop unreads))))
7149                    (gnus-summary-read-group
7150                     target-group nil no-article
7151                     (and (buffer-name current-buffer) current-buffer)
7152                     nil backward))
7153               (setq entered t)
7154             (setq current-group target-group
7155                   target-group nil)))))))
7156
7157 (defun gnus-summary-prev-group (&optional no-article)
7158   "Exit current newsgroup and then select previous unread newsgroup.
7159 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7160   (interactive "P")
7161   (gnus-summary-next-group no-article nil t))
7162
7163 ;; Walking around summary lines.
7164
7165 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7166   "Go to the first subject satisfying any non-nil constraint.
7167 If UNREAD is non-nil, the article should be unread.
7168 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7169 If UNSEEN is non-nil, the article should be unseen.
7170 Returns the article selected or nil if there are no matching articles."
7171   (interactive "P")
7172   (cond
7173    ;; Empty summary.
7174    ((null gnus-newsgroup-data)
7175     (gnus-message 3 "No articles in the group")
7176     nil)
7177    ;; Pick the first article.
7178    ((not (or unread undownloaded unseen))
7179     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7180     (gnus-data-number (car gnus-newsgroup-data)))
7181    ;; Find the first unread article.
7182    (t
7183     (let ((data gnus-newsgroup-data))
7184       (while (and data
7185                   (let ((num (gnus-data-number (car data))))
7186                     (or (memq num gnus-newsgroup-unfetched)
7187                         (not (or (and unread
7188                                       (memq num gnus-newsgroup-unreads))
7189                                  (and undownloaded
7190                                       (memq num gnus-newsgroup-undownloaded))
7191                                  (and unseen
7192                                       (memq num gnus-newsgroup-unseen)))))))
7193         (setq data (cdr data)))
7194       (prog1
7195           (if data
7196               (progn
7197                 (goto-char (gnus-data-pos (car data)))
7198                 (gnus-data-number (car data)))
7199             (gnus-message 3 "No more%s articles"
7200                           (let* ((r (when unread " unread"))
7201                                  (d (when undownloaded " undownloaded"))
7202                                  (s (when unseen " unseen"))
7203                                  (l (delq nil (list r d s))))
7204                             (cond ((= 3 (length l))
7205                                    (concat r "," d ", or" s))
7206                                   ((= 2 (length l))
7207                                    (concat (car l) ", or" (cadr l)))
7208                                   ((= 1 (length l))
7209                                    (car l))
7210                                   (t
7211                                    ""))))
7212             nil
7213             )
7214         (gnus-summary-position-point))))))
7215
7216 (defun gnus-summary-next-subject (n &optional unread dont-display)
7217   "Go to next N'th summary line.
7218 If N is negative, go to the previous N'th subject line.
7219 If UNREAD is non-nil, only unread articles are selected.
7220 The difference between N and the actual number of steps taken is
7221 returned."
7222   (interactive "p")
7223   (let ((backward (< n 0))
7224         (n (abs n)))
7225     (while (and (> n 0)
7226                 (if backward
7227                     (gnus-summary-find-prev unread)
7228                   (gnus-summary-find-next unread)))
7229       (unless (zerop (setq n (1- n)))
7230         (gnus-summary-show-thread)))
7231     (when (/= 0 n)
7232       (gnus-message 7 "No more%s articles"
7233                     (if unread " unread" "")))
7234     (unless dont-display
7235       (gnus-summary-recenter)
7236       (gnus-summary-position-point))
7237     n))
7238
7239 (defun gnus-summary-next-unread-subject (n)
7240   "Go to next N'th unread summary line."
7241   (interactive "p")
7242   (gnus-summary-next-subject n t))
7243
7244 (defun gnus-summary-prev-subject (n &optional unread)
7245   "Go to previous N'th summary line.
7246 If optional argument UNREAD is non-nil, only unread article is selected."
7247   (interactive "p")
7248   (gnus-summary-next-subject (- n) unread))
7249
7250 (defun gnus-summary-prev-unread-subject (n)
7251   "Go to previous N'th unread summary line."
7252   (interactive "p")
7253   (gnus-summary-next-subject (- n) t))
7254
7255 (defun gnus-summary-goto-subjects (articles)
7256   "Insert the subject header for ARTICLES in the current buffer."
7257   (save-excursion
7258     (dolist (article articles)
7259       (gnus-summary-goto-subject article t)))
7260   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7261   (gnus-summary-position-point))
7262
7263 (defun gnus-summary-goto-subject (article &optional force silent)
7264   "Go the subject line of ARTICLE.
7265 If FORCE, also allow jumping to articles not currently shown."
7266   (interactive "nArticle number: ")
7267   (unless (numberp article)
7268     (error "Article %s is not a number" article))
7269   (let ((b (point))
7270         (data (gnus-data-find article)))
7271     ;; We read in the article if we have to.
7272     (and (not data)
7273          force
7274          (gnus-summary-insert-subject
7275           article
7276           (if (or (numberp force) (vectorp force)) force)
7277           t)
7278          (setq data (gnus-data-find article)))
7279     (goto-char b)
7280     (if (not data)
7281         (progn
7282           (unless silent
7283             (gnus-message 3 "Can't find article %d" article))
7284           nil)
7285       (let ((pt (gnus-data-pos data)))
7286         (goto-char pt)
7287         (gnus-summary-set-article-display-arrow pt))
7288       (gnus-summary-position-point)
7289       article)))
7290
7291 ;; Walking around summary lines with displaying articles.
7292
7293 (defun gnus-summary-expand-window (&optional arg)
7294   "Make the summary buffer take up the entire Emacs frame.
7295 Given a prefix, will force an `article' buffer configuration."
7296   (interactive "P")
7297   (if arg
7298       (gnus-configure-windows 'article 'force)
7299     (gnus-configure-windows 'summary 'force)))
7300
7301 (defun gnus-summary-display-article (article &optional all-header)
7302   "Display ARTICLE in article buffer."
7303   (when (gnus-buffer-live-p gnus-article-buffer)
7304     (with-current-buffer gnus-article-buffer
7305       (mm-enable-multibyte)))
7306   (gnus-set-global-variables)
7307   (when (gnus-buffer-live-p gnus-article-buffer)
7308     (with-current-buffer gnus-article-buffer
7309       (setq gnus-article-charset gnus-newsgroup-charset)
7310       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7311       (mm-enable-multibyte)))
7312   (if (null article)
7313       nil
7314     (prog1
7315         (if gnus-summary-display-article-function
7316             (funcall gnus-summary-display-article-function article all-header)
7317           (gnus-article-prepare article all-header))
7318       (gnus-run-hooks 'gnus-select-article-hook)
7319       (when (and gnus-current-article
7320                  (not (zerop gnus-current-article)))
7321         (gnus-summary-goto-subject gnus-current-article))
7322       (gnus-summary-recenter)
7323       (when (and gnus-use-trees gnus-show-threads)
7324         (gnus-possibly-generate-tree article)
7325         (gnus-highlight-selected-tree article))
7326       ;; Successfully display article.
7327       (gnus-article-set-window-start
7328        (cdr (assq article gnus-newsgroup-bookmarks))))))
7329
7330 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7331   "Select the current article.
7332 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7333 non-nil, the article will be re-fetched even if it already present in
7334 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7335 be displayed."
7336   ;; Make sure we are in the summary buffer to work around bbdb bug.
7337   (unless (eq major-mode 'gnus-summary-mode)
7338     (set-buffer gnus-summary-buffer))
7339   (let ((article (or article (gnus-summary-article-number)))
7340         (all-headers (not (not all-headers))) ;Must be t or nil.
7341         gnus-summary-display-article-function)
7342     (and (not pseudo)
7343          (gnus-summary-article-pseudo-p article)
7344          (error "This is a pseudo-article"))
7345     (save-excursion
7346       (set-buffer gnus-summary-buffer)
7347       (if (or (and gnus-single-article-buffer
7348                    (or (null gnus-current-article)
7349                        (null gnus-article-current)
7350                        (null (get-buffer gnus-article-buffer))
7351                        (not (eq article (cdr gnus-article-current)))
7352                        (not (equal (car gnus-article-current)
7353                                    gnus-newsgroup-name))))
7354               (and (not gnus-single-article-buffer)
7355                    (or (null gnus-current-article)
7356                        (not (eq gnus-current-article article))))
7357               force)
7358           ;; The requested article is different from the current article.
7359           (progn
7360             (gnus-summary-display-article article all-headers)
7361             (when (gnus-buffer-live-p gnus-article-buffer)
7362               (with-current-buffer gnus-article-buffer
7363                 (if (not gnus-article-decoded-p) ;; a local variable
7364                     (mm-disable-multibyte))))
7365             (gnus-article-set-window-start
7366              (cdr (assq article gnus-newsgroup-bookmarks)))
7367             article)
7368         'old))))
7369
7370 (defun gnus-summary-force-verify-and-decrypt ()
7371   "Display buttons for signed/encrypted parts and verify/decrypt them."
7372   (interactive)
7373   (let ((mm-verify-option 'known)
7374         (mm-decrypt-option 'known)
7375         (gnus-article-emulate-mime t)
7376         (gnus-buttonized-mime-types (append (list "multipart/signed"
7377                                                   "multipart/encrypted")
7378                                             gnus-buttonized-mime-types)))
7379     (gnus-summary-select-article nil 'force)))
7380
7381 (defun gnus-summary-set-current-mark (&optional current-mark)
7382   "Obsolete function."
7383   nil)
7384
7385 (defun gnus-summary-next-article (&optional unread subject backward push)
7386   "Select the next article.
7387 If UNREAD, only unread articles are selected.
7388 If SUBJECT, only articles with SUBJECT are selected.
7389 If BACKWARD, the previous article is selected instead of the next."
7390   (interactive "P")
7391   (cond
7392    ;; Is there such an article?
7393    ((and (gnus-summary-search-forward unread subject backward)
7394          (or (gnus-summary-display-article (gnus-summary-article-number))
7395              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7396     (gnus-summary-position-point))
7397    ;; If not, we try the first unread, if that is wanted.
7398    ((and subject
7399          gnus-auto-select-same
7400          (gnus-summary-first-unread-article))
7401     (gnus-summary-position-point)
7402     (gnus-message 6 "Wrapped"))
7403    ;; Try to get next/previous article not displayed in this group.
7404    ((and gnus-auto-extend-newsgroup
7405          (not unread) (not subject))
7406     (gnus-summary-goto-article
7407      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7408      nil (count-lines (point-min) (point))))
7409    ;; Go to next/previous group.
7410    (t
7411     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7412       (gnus-summary-jump-to-group gnus-newsgroup-name))
7413     (let ((cmd last-command-char)
7414           (point
7415            (with-current-buffer gnus-group-buffer
7416              (point)))
7417           (group
7418            (if (eq gnus-keep-same-level 'best)
7419                (gnus-summary-best-group gnus-newsgroup-name)
7420              (gnus-summary-search-group backward gnus-keep-same-level))))
7421       ;; For some reason, the group window gets selected.  We change
7422       ;; it back.
7423       (select-window (get-buffer-window (current-buffer)))
7424       ;; Select next unread newsgroup automagically.
7425       (cond
7426        ((or (not gnus-auto-select-next)
7427             (not cmd))
7428         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7429        ((or (eq gnus-auto-select-next 'quietly)
7430             (and (eq gnus-auto-select-next 'slightly-quietly)
7431                  push)
7432             (and (eq gnus-auto-select-next 'almost-quietly)
7433                  (gnus-summary-last-article-p)))
7434         ;; Select quietly.
7435         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7436             (gnus-summary-exit)
7437           (gnus-message 7 "No more%s articles (%s)..."
7438                         (if unread " unread" "")
7439                         (if group (concat "selecting " group)
7440                           "exiting"))
7441           (gnus-summary-next-group nil group backward)))
7442        (t
7443         (when (gnus-key-press-event-p last-input-event)
7444           (gnus-summary-walk-group-buffer
7445            gnus-newsgroup-name cmd unread backward point))))))))
7446
7447 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7448   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7449                       (?\C-p (gnus-group-prev-unread-group 1))))
7450         (cursor-in-echo-area t)
7451         keve key group ended prompt)
7452     (save-excursion
7453       (set-buffer gnus-group-buffer)
7454       (goto-char start)
7455       (setq group
7456             (if (eq gnus-keep-same-level 'best)
7457                 (gnus-summary-best-group gnus-newsgroup-name)
7458               (gnus-summary-search-group backward gnus-keep-same-level))))
7459     (while (not ended)
7460       (setq prompt
7461             (format
7462              "No more%s articles%s " (if unread " unread" "")
7463              (if (and group
7464                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7465                  (format " (Type %s for %s [%s])"
7466                          (single-key-description cmd)
7467                          (gnus-group-decoded-name group)
7468                          (gnus-group-unread group))
7469                (format " (Type %s to exit %s)"
7470                        (single-key-description cmd)
7471                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7472       ;; Confirm auto selection.
7473       (setq key (car (setq keve (gnus-read-event-char prompt)))
7474             ended t)
7475       (cond
7476        ((assq key keystrokes)
7477         (let ((obuf (current-buffer)))
7478           (switch-to-buffer gnus-group-buffer)
7479           (when group
7480             (gnus-group-jump-to-group group))
7481           (eval (cadr (assq key keystrokes)))
7482           (setq group (gnus-group-group-name))
7483           (switch-to-buffer obuf))
7484         (setq ended nil))
7485        ((equal key cmd)
7486         (if (or (not group)
7487                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7488             (gnus-summary-exit)
7489           (gnus-summary-next-group nil group backward)))
7490        (t
7491         (push (cdr keve) unread-command-events))))))
7492
7493 (defun gnus-summary-next-unread-article ()
7494   "Select unread article after current one."
7495   (interactive)
7496   (gnus-summary-next-article
7497    (or (not (eq gnus-summary-goto-unread 'never))
7498        (gnus-summary-last-article-p (gnus-summary-article-number)))
7499    (and gnus-auto-select-same
7500         (gnus-summary-article-subject))))
7501
7502 (defun gnus-summary-prev-article (&optional unread subject)
7503   "Select the article after the current one.
7504 If UNREAD is non-nil, only unread articles are selected."
7505   (interactive "P")
7506   (gnus-summary-next-article unread subject t))
7507
7508 (defun gnus-summary-prev-unread-article ()
7509   "Select unread article before current one."
7510   (interactive)
7511   (gnus-summary-prev-article
7512    (or (not (eq gnus-summary-goto-unread 'never))
7513        (gnus-summary-first-article-p (gnus-summary-article-number)))
7514    (and gnus-auto-select-same
7515         (gnus-summary-article-subject))))
7516
7517 (defun gnus-summary-next-page (&optional lines circular stop)
7518   "Show next page of the selected article.
7519 If at the end of the current article, select the next article.
7520 LINES says how many lines should be scrolled up.
7521
7522 If CIRCULAR is non-nil, go to the start of the article instead of
7523 selecting the next article when reaching the end of the current
7524 article.
7525
7526 If STOP is non-nil, just stop when reaching the end of the message.
7527
7528 Also see the variable `gnus-article-skip-boring'."
7529   (interactive "P")
7530   (setq gnus-summary-buffer (current-buffer))
7531   (gnus-set-global-variables)
7532   (let ((article (gnus-summary-article-number))
7533         (article-window (get-buffer-window gnus-article-buffer t))
7534         endp)
7535     ;; If the buffer is empty, we have no article.
7536     (unless article
7537       (error "No article to select"))
7538     (gnus-configure-windows 'article)
7539     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7540         (if (and (eq gnus-summary-goto-unread 'never)
7541                  (not (gnus-summary-last-article-p article)))
7542             (gnus-summary-next-article)
7543           (gnus-summary-next-unread-article))
7544       (if (or (null gnus-current-article)
7545               (null gnus-article-current)
7546               (/= article (cdr gnus-article-current))
7547               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7548           ;; Selected subject is different from current article's.
7549           (gnus-summary-display-article article)
7550         (when article-window
7551           (gnus-eval-in-buffer-window gnus-article-buffer
7552             (setq endp (or (gnus-article-next-page lines)
7553                            (gnus-article-only-boring-p))))
7554           (when endp
7555             (cond (stop
7556                    (gnus-message 3 "End of message"))
7557                   (circular
7558                    (gnus-summary-beginning-of-article))
7559                   (lines
7560                    (gnus-message 3 "End of message"))
7561                   ((null lines)
7562                    (if (and (eq gnus-summary-goto-unread 'never)
7563                             (not (gnus-summary-last-article-p article)))
7564                        (gnus-summary-next-article)
7565                      (gnus-summary-next-unread-article))))))))
7566     (gnus-summary-recenter)
7567     (gnus-summary-position-point)))
7568
7569 (defun gnus-summary-prev-page (&optional lines move)
7570   "Show previous page of selected article.
7571 Argument LINES specifies lines to be scrolled down.
7572 If MOVE, move to the previous unread article if point is at
7573 the beginning of the buffer."
7574   (interactive "P")
7575   (let ((article (gnus-summary-article-number))
7576         (article-window (get-buffer-window gnus-article-buffer t))
7577         endp)
7578     (gnus-configure-windows 'article)
7579     (if (or (null gnus-current-article)
7580             (null gnus-article-current)
7581             (/= article (cdr gnus-article-current))
7582             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7583         ;; Selected subject is different from current article's.
7584         (gnus-summary-display-article article)
7585       (gnus-summary-recenter)
7586       (when article-window
7587         (gnus-eval-in-buffer-window gnus-article-buffer
7588           (setq endp (gnus-article-prev-page lines)))
7589         (when (and move endp)
7590           (cond (lines
7591                  (gnus-message 3 "Beginning of message"))
7592                 ((null lines)
7593                  (if (and (eq gnus-summary-goto-unread 'never)
7594                           (not (gnus-summary-first-article-p article)))
7595                      (gnus-summary-prev-article)
7596                    (gnus-summary-prev-unread-article))))))))
7597   (gnus-summary-position-point))
7598
7599 (defun gnus-summary-prev-page-or-article (&optional lines)
7600   "Show previous page of selected article.
7601 Argument LINES specifies lines to be scrolled down.
7602 If at the beginning of the article, go to the next article."
7603   (interactive "P")
7604   (gnus-summary-prev-page lines t))
7605
7606 (defun gnus-summary-scroll-up (lines)
7607   "Scroll up (or down) one line current article.
7608 Argument LINES specifies lines to be scrolled up (or down if negative)."
7609   (interactive "p")
7610   (gnus-configure-windows 'article)
7611   (gnus-summary-show-thread)
7612   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7613     (gnus-eval-in-buffer-window gnus-article-buffer
7614       (cond ((> lines 0)
7615              (when (gnus-article-next-page lines)
7616                (gnus-message 3 "End of message")))
7617             ((< lines 0)
7618              (gnus-article-prev-page (- lines))))))
7619   (gnus-summary-recenter)
7620   (gnus-summary-position-point))
7621
7622 (defun gnus-summary-scroll-down (lines)
7623   "Scroll down (or up) one line current article.
7624 Argument LINES specifies lines to be scrolled down (or up if negative)."
7625   (interactive "p")
7626   (gnus-summary-scroll-up (- lines)))
7627
7628 (defun gnus-summary-next-same-subject ()
7629   "Select next article which has the same subject as current one."
7630   (interactive)
7631   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7632
7633 (defun gnus-summary-prev-same-subject ()
7634   "Select previous article which has the same subject as current one."
7635   (interactive)
7636   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7637
7638 (defun gnus-summary-next-unread-same-subject ()
7639   "Select next unread article which has the same subject as current one."
7640   (interactive)
7641   (gnus-summary-next-article t (gnus-summary-article-subject)))
7642
7643 (defun gnus-summary-prev-unread-same-subject ()
7644   "Select previous unread article which has the same subject as current one."
7645   (interactive)
7646   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7647
7648 (defun gnus-summary-first-unread-article ()
7649   "Select the first unread article.
7650 Return nil if there are no unread articles."
7651   (interactive)
7652   (prog1
7653       (when (gnus-summary-first-subject t)
7654         (gnus-summary-show-thread)
7655         (gnus-summary-first-subject t)
7656         (gnus-summary-display-article (gnus-summary-article-number)))
7657     (gnus-summary-position-point)))
7658
7659 (defun gnus-summary-first-unread-subject ()
7660   "Place the point on the subject line of the first unread article.
7661 Return nil if there are no unread articles."
7662   (interactive)
7663   (prog1
7664       (when (gnus-summary-first-subject t)
7665         (gnus-summary-show-thread)
7666         (gnus-summary-first-subject t))
7667     (gnus-summary-position-point)))
7668
7669 (defun gnus-summary-first-unseen-subject ()
7670   "Place the point on the subject line of the first unseen article.
7671 Return nil if there are no unseen articles."
7672   (interactive)
7673   (prog1
7674       (when (gnus-summary-first-subject nil nil t)
7675         (gnus-summary-show-thread)
7676         (gnus-summary-first-subject nil nil t))
7677     (gnus-summary-position-point)))
7678
7679 (defun gnus-summary-first-unseen-or-unread-subject ()
7680   "Place the point on the subject line of the first unseen article or,
7681 if all article have been seen, on the subject line of the first unread
7682 article."
7683   (interactive)
7684   (prog1
7685       (unless (when (gnus-summary-first-subject nil nil t)
7686                 (gnus-summary-show-thread)
7687                 (gnus-summary-first-subject nil nil t))
7688         (when (gnus-summary-first-subject t)
7689           (gnus-summary-show-thread)
7690           (gnus-summary-first-subject t)))
7691     (gnus-summary-position-point)))
7692
7693 (defun gnus-summary-first-article ()
7694   "Select the first article.
7695 Return nil if there are no articles."
7696   (interactive)
7697   (prog1
7698       (when (gnus-summary-first-subject)
7699         (gnus-summary-show-thread)
7700         (gnus-summary-first-subject)
7701         (gnus-summary-display-article (gnus-summary-article-number)))
7702     (gnus-summary-position-point)))
7703
7704 (defun gnus-summary-best-unread-article (&optional arg)
7705   "Select the unread article with the highest score.
7706 If given a prefix argument, select the next unread article that has a
7707 score higher than the default score."
7708   (interactive "P")
7709   (let ((article (if arg
7710                      (gnus-summary-better-unread-subject)
7711                    (gnus-summary-best-unread-subject))))
7712     (if article
7713         (gnus-summary-goto-article article)
7714       (error "No unread articles"))))
7715
7716 (defun gnus-summary-best-unread-subject ()
7717   "Select the unread subject with the highest score."
7718   (interactive)
7719   (let ((best -1000000)
7720         (data gnus-newsgroup-data)
7721         article score)
7722     (while data
7723       (and (gnus-data-unread-p (car data))
7724            (> (setq score
7725                     (gnus-summary-article-score (gnus-data-number (car data))))
7726               best)
7727            (setq best score
7728                  article (gnus-data-number (car data))))
7729       (setq data (cdr data)))
7730     (when article
7731       (gnus-summary-goto-subject article))
7732     (gnus-summary-position-point)
7733     article))
7734
7735 (defun gnus-summary-better-unread-subject ()
7736   "Select the first unread subject that has a score over the default score."
7737   (interactive)
7738   (let ((data gnus-newsgroup-data)
7739         article score)
7740     (while (and (setq article (gnus-data-number (car data)))
7741                 (or (gnus-data-read-p (car data))
7742                     (not (> (gnus-summary-article-score article)
7743                             gnus-summary-default-score))))
7744       (setq data (cdr data)))
7745     (when article
7746       (gnus-summary-goto-subject article))
7747     (gnus-summary-position-point)
7748     article))
7749
7750 (defun gnus-summary-last-subject ()
7751   "Go to the last displayed subject line in the group."
7752   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7753     (when article
7754       (gnus-summary-goto-subject article))))
7755
7756 (defun gnus-summary-goto-article (article &optional all-headers force)
7757   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7758 If ALL-HEADERS is non-nil, no header lines are hidden.
7759 If FORCE, go to the article even if it isn't displayed.  If FORCE
7760 is a number, it is the line the article is to be displayed on."
7761   (interactive
7762    (list
7763     (completing-read
7764      "Article number or Message-ID: "
7765      (mapcar (lambda (number) (list (int-to-string number)))
7766              gnus-newsgroup-limit))
7767     current-prefix-arg
7768     t))
7769   (prog1
7770       (if (and (stringp article)
7771                (string-match "@\\|%40" article))
7772           (gnus-summary-refer-article article)
7773         (when (stringp article)
7774           (setq article (string-to-number article)))
7775         (if (gnus-summary-goto-subject article force)
7776             (gnus-summary-display-article article all-headers)
7777           (gnus-message 4 "Couldn't go to article %s" article) nil))
7778     (gnus-summary-position-point)))
7779
7780 (defun gnus-summary-goto-last-article ()
7781   "Go to the previously read article."
7782   (interactive)
7783   (prog1
7784       (when gnus-last-article
7785         (gnus-summary-goto-article gnus-last-article nil t))
7786     (gnus-summary-position-point)))
7787
7788 (defun gnus-summary-pop-article (number)
7789   "Pop one article off the history and go to the previous.
7790 NUMBER articles will be popped off."
7791   (interactive "p")
7792   (let (to)
7793     (setq gnus-newsgroup-history
7794           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7795     (if to
7796         (gnus-summary-goto-article (car to) nil t)
7797       (error "Article history empty")))
7798   (gnus-summary-position-point))
7799
7800 ;; Summary commands and functions for limiting the summary buffer.
7801
7802 (defun gnus-summary-limit-to-articles (n)
7803   "Limit the summary buffer to the next N articles.
7804 If not given a prefix, use the process marked articles instead."
7805   (interactive "P")
7806   (prog1
7807       (let ((articles (gnus-summary-work-articles n)))
7808         (setq gnus-newsgroup-processable nil)
7809         (gnus-summary-limit articles))
7810     (gnus-summary-position-point)))
7811
7812 (defun gnus-summary-pop-limit (&optional total)
7813   "Restore the previous limit.
7814 If given a prefix, remove all limits."
7815   (interactive "P")
7816   (when total
7817     (setq gnus-newsgroup-limits
7818           (list (mapcar (lambda (h) (mail-header-number h))
7819                         gnus-newsgroup-headers))))
7820   (unless gnus-newsgroup-limits
7821     (error "No limit to pop"))
7822   (prog1
7823       (gnus-summary-limit nil 'pop)
7824     (gnus-summary-position-point)))
7825
7826 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7827   "Limit the summary buffer to articles that have subjects that match a regexp.
7828 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7829   (interactive
7830    (list (read-string (if current-prefix-arg
7831                           "Exclude subject (regexp): "
7832                         "Limit to subject (regexp): "))
7833          nil current-prefix-arg))
7834   (unless header
7835     (setq header "subject"))
7836   (when (not (equal "" subject))
7837     (prog1
7838         (let ((articles (gnus-summary-find-matching
7839                          (or header "subject") subject 'all nil nil
7840                          not-matching)))
7841           (unless articles
7842             (error "Found no matches for \"%s\"" subject))
7843           (gnus-summary-limit articles))
7844       (gnus-summary-position-point))))
7845
7846 (defun gnus-summary-limit-to-author (from &optional not-matching)
7847   "Limit the summary buffer to articles that have authors that match a regexp.
7848 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7849   (interactive
7850    (list (read-string (if current-prefix-arg
7851                           "Exclude author (regexp): "
7852                         "Limit to author (regexp): "))
7853          current-prefix-arg))
7854   (gnus-summary-limit-to-subject from "from" not-matching))
7855
7856 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7857   "Limit the summary buffer to articles with the given RECIPIENT.
7858
7859 If NOT-MATCHING, exclude RECIPIENT.
7860
7861 To and Cc headers are checked.  You need to include them in
7862 `nnmail-extra-headers'."
7863   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7864   (interactive
7865    (list (read-string (format "%s recipient (regexp): "
7866                               (if current-prefix-arg "Exclude" "Limit to")))
7867          current-prefix-arg))
7868   (when (not (equal "" recipient))
7869     (prog1 (let* ((to
7870                    (if (memq 'To nnmail-extra-headers)
7871                        (gnus-summary-find-matching
7872                         (cons 'extra 'To) recipient 'all nil nil
7873                         not-matching)
7874                      (gnus-message
7875                       1 "`To' isn't present in `nnmail-extra-headers'")
7876                      (sit-for 1)
7877                      nil))
7878                   (cc
7879                    (if (memq 'Cc nnmail-extra-headers)
7880                        (gnus-summary-find-matching
7881                         (cons 'extra 'Cc) recipient 'all nil nil
7882                         not-matching)
7883                      (gnus-message
7884                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7885                      (sit-for 1)
7886                      nil))
7887                   (articles
7888                    (if not-matching
7889                        ;; We need the numbers that are in both lists:
7890                        (mapcar (lambda (a)
7891                                  (and (memq a to) a))
7892                                cc)
7893                      (nconc to cc))))
7894              (unless articles
7895                (error "Found no matches for \"%s\"" recipient))
7896              (gnus-summary-limit articles))
7897       (gnus-summary-position-point))))
7898
7899 (defun gnus-summary-limit-to-age (age &optional younger-p)
7900   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7901 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7902 articles that are younger than AGE days."
7903   (interactive
7904    (let ((younger current-prefix-arg)
7905          (days-got nil)
7906          days)
7907      (while (not days-got)
7908        (setq days (if younger
7909                       (read-string "Limit to articles younger than (in days, older when negative): ")
7910                     (read-string
7911                      "Limit to articles older than (in days, younger when negative): ")))
7912        (when (> (length days) 0)
7913          (setq days (read days)))
7914        (if (numberp days)
7915            (progn
7916              (setq days-got t)
7917              (when (< days 0)
7918                (setq younger (not younger))
7919                (setq days (* days -1))))
7920          (message "Please enter a number.")
7921          (sleep-for 1)))
7922      (list days younger)))
7923   (prog1
7924       (let ((data gnus-newsgroup-data)
7925             (cutoff (days-to-time age))
7926             articles d date is-younger)
7927         (while (setq d (pop data))
7928           (when (and (vectorp (gnus-data-header d))
7929                      (setq date (mail-header-date (gnus-data-header d))))
7930             (setq is-younger (time-less-p
7931                               (time-since (condition-case ()
7932                                               (date-to-time date)
7933                                             (error '(0 0))))
7934                               cutoff))
7935             (when (if younger-p
7936                       is-younger
7937                     (not is-younger))
7938               (push (gnus-data-number d) articles))))
7939         (gnus-summary-limit (nreverse articles)))
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7943   "Limit the summary buffer to articles that match an 'extra' header."
7944   (interactive
7945    (let ((header
7946           (intern
7947            (gnus-completing-read-with-default
7948             (symbol-name (car gnus-extra-headers))
7949             (if current-prefix-arg
7950                 "Exclude extra header"
7951               "Limit extra header")
7952             (mapcar (lambda (x)
7953                       (cons (symbol-name x) x))
7954                     gnus-extra-headers)
7955             nil
7956             t))))
7957      (list header
7958            (read-string (format "%s header %s (regexp): "
7959                                 (if current-prefix-arg "Exclude" "Limit to")
7960                                 header))
7961            current-prefix-arg)))
7962   (when (not (equal "" regexp))
7963     (prog1
7964         (let ((articles (gnus-summary-find-matching
7965                          (cons 'extra header) regexp 'all nil nil
7966                          not-matching)))
7967           (unless articles
7968             (error "Found no matches for \"%s\"" regexp))
7969           (gnus-summary-limit articles))
7970       (gnus-summary-position-point))))
7971
7972 (defun gnus-summary-limit-to-display-predicate ()
7973   "Limit the summary buffer to the predicated in the `display' group parameter."
7974   (interactive)
7975   (unless gnus-newsgroup-display
7976     (error "There is no `display' group parameter"))
7977   (let (articles)
7978     (dolist (number gnus-newsgroup-articles)
7979       (when (funcall gnus-newsgroup-display)
7980         (push number articles)))
7981     (gnus-summary-limit articles))
7982   (gnus-summary-position-point))
7983
7984 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7985 (make-obsolete
7986  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7987
7988 (defun gnus-summary-limit-to-unread (&optional all)
7989   "Limit the summary buffer to articles that are not marked as read.
7990 If ALL is non-nil, limit strictly to unread articles."
7991   (interactive "P")
7992   (if all
7993       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7994     (gnus-summary-limit-to-marks
7995      ;; Concat all the marks that say that an article is read and have
7996      ;; those removed.
7997      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7998            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7999            gnus-low-score-mark gnus-expirable-mark
8000            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8001            gnus-duplicate-mark gnus-souped-mark)
8002      'reverse)))
8003
8004 (defun gnus-summary-limit-to-bodies (match &optional reverse)
8005   "Limit the summary buffer to articles that have bodies that match MATCH.
8006 If REVERSE (the prefix), limit to articles that don't match."
8007   (interactive "sMatch body (regexp): \nP")
8008   (let ((articles nil)
8009         (gnus-select-article-hook nil)  ;Disable hook.
8010         (gnus-article-prepare-hook nil)
8011         (gnus-use-article-prefetch nil)
8012         (gnus-keep-backlog nil)
8013         (gnus-break-pages nil)
8014         (gnus-summary-display-arrow nil)
8015         (gnus-updated-mode-lines nil)
8016         (gnus-auto-center-summary nil)
8017         (gnus-display-mime-function nil))
8018     (dolist (data gnus-newsgroup-data)
8019       (let (gnus-mark-article-hook)
8020         (gnus-summary-select-article t t nil (gnus-data-number data)))
8021       (save-excursion
8022         (set-buffer gnus-article-buffer)
8023         (article-goto-body)
8024         (let* ((case-fold-search t)
8025                (found (re-search-forward match nil t)))
8026           (when (or (and found
8027                          (not reverse))
8028                     (and (not found)
8029                          reverse))
8030             (push (gnus-data-number data) articles)))))
8031     (if (not articles)
8032         (message "No messages matched")
8033       (gnus-summary-limit articles)))
8034   (gnus-summary-position-point))
8035
8036 (defun gnus-summary-limit-to-replied (&optional unreplied)
8037   "Limit the summary buffer to replied articles.
8038 If UNREPLIED (the prefix), limit to unreplied articles."
8039   (interactive "P")
8040   (if unreplied
8041       (gnus-summary-limit
8042        (gnus-set-difference gnus-newsgroup-articles
8043         gnus-newsgroup-replied))
8044     (gnus-summary-limit gnus-newsgroup-replied))
8045   (gnus-summary-position-point))
8046
8047 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8048 (make-obsolete 'gnus-summary-delete-marked-with
8049                'gnus-summary-limit-exclude-marks)
8050
8051 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8052   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8053 If REVERSE, limit the summary buffer to articles that are marked
8054 with MARKS.  MARKS can either be a string of marks or a list of marks.
8055 Returns how many articles were removed."
8056   (interactive "sMarks: ")
8057   (gnus-summary-limit-to-marks marks t))
8058
8059 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8060   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8061 If REVERSE (the prefix), limit the summary buffer to articles that are
8062 not marked with MARKS.  MARKS can either be a string of marks or a
8063 list of marks.
8064 Returns how many articles were removed."
8065   (interactive "sMarks: \nP")
8066   (prog1
8067       (let ((data gnus-newsgroup-data)
8068             (marks (if (listp marks) marks
8069                      (append marks nil))) ; Transform to list.
8070             articles)
8071         (while data
8072           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8073                   (memq (gnus-data-mark (car data)) marks))
8074             (push (gnus-data-number (car data)) articles))
8075           (setq data (cdr data)))
8076         (gnus-summary-limit articles))
8077     (gnus-summary-position-point)))
8078
8079 (defun gnus-summary-limit-to-score (score)
8080   "Limit to articles with score at or above SCORE."
8081   (interactive "NLimit to articles with score of at least: ")
8082   (let ((data gnus-newsgroup-data)
8083         articles)
8084     (while data
8085       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8086                 score)
8087         (push (gnus-data-number (car data)) articles))
8088       (setq data (cdr data)))
8089     (prog1
8090         (gnus-summary-limit articles)
8091       (gnus-summary-position-point))))
8092
8093 (defun gnus-summary-limit-to-unseen ()
8094   "Limit to unseen articles."
8095   (interactive)
8096   (prog1
8097       (gnus-summary-limit gnus-newsgroup-unseen)
8098     (gnus-summary-position-point)))
8099
8100 (defun gnus-summary-limit-include-thread (id)
8101   "Display all the hidden articles that is in the thread with ID in it.
8102 When called interactively, ID is the Message-ID of the current
8103 article."
8104   (interactive (list (mail-header-id (gnus-summary-article-header))))
8105   (let ((articles (gnus-articles-in-thread
8106                    (gnus-id-to-thread (gnus-root-id id)))))
8107     (prog1
8108         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8109       (gnus-summary-limit-include-matching-articles
8110        "subject"
8111        (regexp-quote (gnus-simplify-subject-re
8112                       (mail-header-subject (gnus-id-to-header id)))))
8113       (gnus-summary-position-point))))
8114
8115 (defun gnus-summary-limit-include-matching-articles (header regexp)
8116   "Display all the hidden articles that have HEADERs that match REGEXP."
8117   (interactive (list (read-string "Match on header: ")
8118                      (read-string "Regexp: ")))
8119   (let ((articles (gnus-find-matching-articles header regexp)))
8120     (prog1
8121         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8122       (gnus-summary-position-point))))
8123
8124 (defun gnus-summary-insert-dormant-articles ()
8125   "Insert all the dormant articles for this group into the current buffer."
8126   (interactive)
8127   (let ((gnus-verbose (max 6 gnus-verbose)))
8128     (if (not gnus-newsgroup-dormant)
8129         (gnus-message 3 "No cached articles for this group")
8130       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8131
8132 (defun gnus-summary-limit-include-dormant ()
8133   "Display all the hidden articles that are marked as dormant.
8134 Note that this command only works on a subset of the articles currently
8135 fetched for this group."
8136   (interactive)
8137   (unless gnus-newsgroup-dormant
8138     (error "There are no dormant articles in this group"))
8139   (prog1
8140       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8141     (gnus-summary-position-point)))
8142
8143 (defun gnus-summary-limit-exclude-dormant ()
8144   "Hide all dormant articles."
8145   (interactive)
8146   (prog1
8147       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8148     (gnus-summary-position-point)))
8149
8150 (defun gnus-summary-limit-exclude-childless-dormant ()
8151   "Hide all dormant articles that have no children."
8152   (interactive)
8153   (let ((data (gnus-data-list t))
8154         articles d children)
8155     ;; Find all articles that are either not dormant or have
8156     ;; children.
8157     (while (setq d (pop data))
8158       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8159                 (and (setq children
8160                            (gnus-article-children (gnus-data-number d)))
8161                      (let (found)
8162                        (while children
8163                          (when (memq (car children) articles)
8164                            (setq children nil
8165                                  found t))
8166                          (pop children))
8167                        found)))
8168         (push (gnus-data-number d) articles)))
8169     ;; Do the limiting.
8170     (prog1
8171         (gnus-summary-limit articles)
8172       (gnus-summary-position-point))))
8173
8174 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8175   "Mark all unread excluded articles as read.
8176 If ALL, mark even excluded ticked and dormants as read."
8177   (interactive "P")
8178   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8179   (let ((articles (gnus-sorted-ndifference
8180                    (sort
8181                     (mapcar (lambda (h) (mail-header-number h))
8182                             gnus-newsgroup-headers)
8183                     '<)
8184                    gnus-newsgroup-limit))
8185         article)
8186     (setq gnus-newsgroup-unreads
8187           (gnus-sorted-intersection gnus-newsgroup-unreads
8188                                     gnus-newsgroup-limit))
8189     (if all
8190         (setq gnus-newsgroup-dormant nil
8191               gnus-newsgroup-marked nil
8192               gnus-newsgroup-reads
8193               (nconc
8194                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8195                gnus-newsgroup-reads))
8196       (while (setq article (pop articles))
8197         (unless (or (memq article gnus-newsgroup-dormant)
8198                     (memq article gnus-newsgroup-marked))
8199           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8200
8201 (defun gnus-summary-limit (articles &optional pop)
8202   (if pop
8203       ;; We pop the previous limit off the stack and use that.
8204       (setq articles (car gnus-newsgroup-limits)
8205             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8206     ;; We use the new limit, so we push the old limit on the stack.
8207     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8208   ;; Set the limit.
8209   (setq gnus-newsgroup-limit articles)
8210   (let ((total (length gnus-newsgroup-data))
8211         (data (gnus-data-find-list (gnus-summary-article-number)))
8212         (gnus-summary-mark-below nil)   ; Inhibit this.
8213         found)
8214     ;; This will do all the work of generating the new summary buffer
8215     ;; according to the new limit.
8216     (gnus-summary-prepare)
8217     ;; Hide any threads, possibly.
8218     (gnus-summary-maybe-hide-threads)
8219     ;; Try to return to the article you were at, or one in the
8220     ;; neighborhood.
8221     (when data
8222       ;; We try to find some article after the current one.
8223       (while data
8224         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8225           (setq data nil
8226                 found t))
8227         (setq data (cdr data))))
8228     (unless found
8229       ;; If there is no data, that means that we were after the last
8230       ;; article.  The same goes when we can't find any articles
8231       ;; after the current one.
8232       (goto-char (point-max))
8233       (gnus-summary-find-prev))
8234     (gnus-set-mode-line 'summary)
8235     ;; We return how many articles were removed from the summary
8236     ;; buffer as a result of the new limit.
8237     (- total (length gnus-newsgroup-data))))
8238
8239 (defsubst gnus-invisible-cut-children (threads)
8240   (let ((num 0))
8241     (while threads
8242       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8243         (incf num))
8244       (pop threads))
8245     (< num 2)))
8246
8247 (defsubst gnus-cut-thread (thread)
8248   "Go forwards in the thread until we find an article that we want to display."
8249   (when (or (eq gnus-fetch-old-headers 'some)
8250             (eq gnus-fetch-old-headers 'invisible)
8251             (numberp gnus-fetch-old-headers)
8252             (eq gnus-build-sparse-threads 'some)
8253             (eq gnus-build-sparse-threads 'more))
8254     ;; Deal with old-fetched headers and sparse threads.
8255     (while (and
8256             thread
8257             (or
8258              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8259              (gnus-summary-article-ancient-p
8260               (mail-header-number (car thread))))
8261             (if (or (<= (length (cdr thread)) 1)
8262                     (eq gnus-fetch-old-headers 'invisible))
8263                 (setq gnus-newsgroup-limit
8264                       (delq (mail-header-number (car thread))
8265                             gnus-newsgroup-limit)
8266                       thread (cadr thread))
8267               (when (gnus-invisible-cut-children (cdr thread))
8268                 (let ((th (cdr thread)))
8269                   (while th
8270                     (if (memq (mail-header-number (caar th))
8271                               gnus-newsgroup-limit)
8272                         (setq thread (car th)
8273                               th nil)
8274                       (setq th (cdr th))))))))))
8275   thread)
8276
8277 (defun gnus-cut-threads (threads)
8278   "Cut off all uninteresting articles from the beginning of THREADS."
8279   (when (or (eq gnus-fetch-old-headers 'some)
8280             (eq gnus-fetch-old-headers 'invisible)
8281             (numberp gnus-fetch-old-headers)
8282             (eq gnus-build-sparse-threads 'some)
8283             (eq gnus-build-sparse-threads 'more))
8284     (let ((th threads))
8285       (while th
8286         (setcar th (gnus-cut-thread (car th)))
8287         (setq th (cdr th)))))
8288   ;; Remove nixed out threads.
8289   (delq nil threads))
8290
8291 (defun gnus-summary-initial-limit (&optional show-if-empty)
8292   "Figure out what the initial limit is supposed to be on group entry.
8293 This entails weeding out unwanted dormants, low-scored articles,
8294 fetch-old-headers verbiage, and so on."
8295   ;; Most groups have nothing to remove.
8296   (if (or gnus-inhibit-limiting
8297           (and (null gnus-newsgroup-dormant)
8298                (eq gnus-newsgroup-display 'gnus-not-ignore)
8299                (not (eq gnus-fetch-old-headers 'some))
8300                (not (numberp gnus-fetch-old-headers))
8301                (not (eq gnus-fetch-old-headers 'invisible))
8302                (null gnus-summary-expunge-below)
8303                (not (eq gnus-build-sparse-threads 'some))
8304                (not (eq gnus-build-sparse-threads 'more))
8305                (null gnus-thread-expunge-below)
8306                (not gnus-use-nocem)))
8307       ()                                ; Do nothing.
8308     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8309     (setq gnus-newsgroup-limit nil)
8310     (mapatoms
8311      (lambda (node)
8312        (unless (car (symbol-value node))
8313          ;; These threads have no parents -- they are roots.
8314          (let ((nodes (cdr (symbol-value node)))
8315                thread)
8316            (while nodes
8317              (if (and gnus-thread-expunge-below
8318                       (< (gnus-thread-total-score (car nodes))
8319                          gnus-thread-expunge-below))
8320                  (gnus-expunge-thread (pop nodes))
8321                (setq thread (pop nodes))
8322                (gnus-summary-limit-children thread))))))
8323      gnus-newsgroup-dependencies)
8324     ;; If this limitation resulted in an empty group, we might
8325     ;; pop the previous limit and use it instead.
8326     (when (and (not gnus-newsgroup-limit)
8327                show-if-empty)
8328       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8329     gnus-newsgroup-limit))
8330
8331 (defun gnus-summary-limit-children (thread)
8332   "Return 1 if this subthread is visible and 0 if it is not."
8333   ;; First we get the number of visible children to this thread.  This
8334   ;; is done by recursing down the thread using this function, so this
8335   ;; will really go down to a leaf article first, before slowly
8336   ;; working its way up towards the root.
8337   (when thread
8338     (let* ((max-lisp-eval-depth 5000)
8339            (children
8340            (if (cdr thread)
8341                (apply '+ (mapcar 'gnus-summary-limit-children
8342                                  (cdr thread)))
8343              0))
8344           (number (mail-header-number (car thread)))
8345           score)
8346       (if (and
8347            (not (memq number gnus-newsgroup-marked))
8348            (or
8349             ;; If this article is dormant and has absolutely no visible
8350             ;; children, then this article isn't visible.
8351             (and (memq number gnus-newsgroup-dormant)
8352                  (zerop children))
8353             ;; If this is "fetch-old-headered" and there is no
8354             ;; visible children, then we don't want this article.
8355             (and (or (eq gnus-fetch-old-headers 'some)
8356                      (numberp gnus-fetch-old-headers))
8357                  (gnus-summary-article-ancient-p number)
8358                  (zerop children))
8359             ;; If this is "fetch-old-headered" and `invisible', then
8360             ;; we don't want this article.
8361             (and (eq gnus-fetch-old-headers 'invisible)
8362                  (gnus-summary-article-ancient-p number))
8363             ;; If this is a sparsely inserted article with no children,
8364             ;; we don't want it.
8365             (and (eq gnus-build-sparse-threads 'some)
8366                  (gnus-summary-article-sparse-p number)
8367                  (zerop children))
8368             ;; If we use expunging, and this article is really
8369             ;; low-scored, then we don't want this article.
8370             (when (and gnus-summary-expunge-below
8371                        (< (setq score
8372                                 (or (cdr (assq number gnus-newsgroup-scored))
8373                                     gnus-summary-default-score))
8374                           gnus-summary-expunge-below))
8375               ;; We increase the expunge-tally here, but that has
8376               ;; nothing to do with the limits, really.
8377               (incf gnus-newsgroup-expunged-tally)
8378               ;; We also mark as read here, if that's wanted.
8379               (when (and gnus-summary-mark-below
8380                          (< score gnus-summary-mark-below))
8381                 (setq gnus-newsgroup-unreads
8382                       (delq number gnus-newsgroup-unreads))
8383                 (if gnus-newsgroup-auto-expire
8384                     (push number gnus-newsgroup-expirable)
8385                   (push (cons number gnus-low-score-mark)
8386                         gnus-newsgroup-reads)))
8387               t)
8388             ;; Do the `display' group parameter.
8389             (and gnus-newsgroup-display
8390                  (not (funcall gnus-newsgroup-display)))
8391             ;; Check NoCeM things.
8392             (when (and gnus-use-nocem
8393                        (gnus-nocem-unwanted-article-p
8394                         (mail-header-id (car thread))))
8395               (setq gnus-newsgroup-unreads
8396                     (delq number gnus-newsgroup-unreads))
8397               t)))
8398           ;; Nope, invisible article.
8399           0
8400         ;; Ok, this article is to be visible, so we add it to the limit
8401         ;; and return 1.
8402         (push number gnus-newsgroup-limit)
8403         1))))
8404
8405 (defun gnus-expunge-thread (thread)
8406   "Mark all articles in THREAD as read."
8407   (let* ((number (mail-header-number (car thread))))
8408     (incf gnus-newsgroup-expunged-tally)
8409     ;; We also mark as read here, if that's wanted.
8410     (setq gnus-newsgroup-unreads
8411           (delq number gnus-newsgroup-unreads))
8412     (if gnus-newsgroup-auto-expire
8413         (push number gnus-newsgroup-expirable)
8414       (push (cons number gnus-low-score-mark)
8415             gnus-newsgroup-reads)))
8416   ;; Go recursively through all subthreads.
8417   (mapcar 'gnus-expunge-thread (cdr thread)))
8418
8419 ;; Summary article oriented commands
8420
8421 (defun gnus-summary-refer-parent-article (n)
8422   "Refer parent article N times.
8423 If N is negative, go to ancestor -N instead.
8424 The difference between N and the number of articles fetched is returned."
8425   (interactive "p")
8426   (let ((skip 1)
8427         error header ref)
8428     (when (not (natnump n))
8429       (setq skip (abs n)
8430             n 1))
8431     (while (and (> n 0)
8432                 (not error))
8433       (setq header (gnus-summary-article-header))
8434       (if (and (eq (mail-header-number header)
8435                    (cdr gnus-article-current))
8436                (equal gnus-newsgroup-name
8437                       (car gnus-article-current)))
8438           ;; If we try to find the parent of the currently
8439           ;; displayed article, then we take a look at the actual
8440           ;; References header, since this is slightly more
8441           ;; reliable than the References field we got from the
8442           ;; server.
8443           (save-excursion
8444             (set-buffer gnus-original-article-buffer)
8445             (nnheader-narrow-to-headers)
8446             (unless (setq ref (message-fetch-field "references"))
8447               (when (setq ref (message-fetch-field "in-reply-to"))
8448                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8449             (widen))
8450         (setq ref
8451               ;; It's not the current article, so we take a bet on
8452               ;; the value we got from the server.
8453               (mail-header-references header)))
8454       (if (and ref
8455                (not (equal ref "")))
8456           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8457             (gnus-message 1 "Couldn't find parent"))
8458         (gnus-message 1 "No references in article %d"
8459                       (gnus-summary-article-number))
8460         (setq error t))
8461       (decf n))
8462     (gnus-summary-position-point)
8463     n))
8464
8465 (defun gnus-summary-refer-references ()
8466   "Fetch all articles mentioned in the References header.
8467 Return the number of articles fetched."
8468   (interactive)
8469   (let ((ref (mail-header-references (gnus-summary-article-header)))
8470         (current (gnus-summary-article-number))
8471         (n 0))
8472     (if (or (not ref)
8473             (equal ref ""))
8474         (error "No References in the current article")
8475       ;; For each Message-ID in the References header...
8476       (while (string-match "<[^>]*>" ref)
8477         (incf n)
8478         ;; ... fetch that article.
8479         (gnus-summary-refer-article
8480          (prog1 (match-string 0 ref)
8481            (setq ref (substring ref (match-end 0))))))
8482       (gnus-summary-goto-subject current)
8483       (gnus-summary-position-point)
8484       n)))
8485
8486 (defun gnus-summary-refer-thread (&optional limit)
8487   "Fetch all articles in the current thread.
8488 If LIMIT (the numerical prefix), fetch that many old headers instead
8489 of what's specified by the `gnus-refer-thread-limit' variable."
8490   (interactive "P")
8491   (let ((id (mail-header-id (gnus-summary-article-header)))
8492         (limit (if limit (prefix-numeric-value limit)
8493                  gnus-refer-thread-limit)))
8494     (unless (eq gnus-fetch-old-headers 'invisible)
8495       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8496       ;; Retrieve the headers and read them in.
8497       (if (eq (if (numberp limit)
8498                   (gnus-retrieve-headers
8499                    (list (min
8500                           (+ (mail-header-number
8501                               (gnus-summary-article-header))
8502                              limit)
8503                           gnus-newsgroup-end))
8504                    gnus-newsgroup-name (* limit 2))
8505                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8506                 ;; headers.
8507                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8508                                        gnus-newsgroup-name limit))
8509               'nov)
8510           (gnus-build-all-threads)
8511         (error "Can't fetch thread from back ends that don't support NOV"))
8512       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8513     (gnus-summary-limit-include-thread id)))
8514
8515 (defun gnus-summary-refer-article (message-id)
8516   "Fetch an article specified by MESSAGE-ID."
8517   (interactive "sMessage-ID: ")
8518   (when (and (stringp message-id)
8519              (not (zerop (length message-id))))
8520     (setq message-id (gnus-replace-in-string message-id " " ""))
8521     ;; Construct the correct Message-ID if necessary.
8522     ;; Suggested by tale@pawl.rpi.edu.
8523     (unless (string-match "^<" message-id)
8524       (setq message-id (concat "<" message-id)))
8525     (unless (string-match ">$" message-id)
8526       (setq message-id (concat message-id ">")))
8527     ;; People often post MIDs from URLs, so unhex it:
8528     (unless (string-match "@" message-id)
8529       (setq message-id (gnus-url-unhex-string message-id)))
8530     (let* ((header (gnus-id-to-header message-id))
8531            (sparse (and header
8532                         (gnus-summary-article-sparse-p
8533                          (mail-header-number header))
8534                         (memq (mail-header-number header)
8535                               gnus-newsgroup-limit)))
8536            number)
8537       (cond
8538        ;; If the article is present in the buffer we just go to it.
8539        ((and header
8540              (or (not (gnus-summary-article-sparse-p
8541                        (mail-header-number header)))
8542                  sparse))
8543         (prog1
8544             (gnus-summary-goto-article
8545              (mail-header-number header) nil t)
8546           (when sparse
8547             (gnus-summary-update-article (mail-header-number header)))))
8548        (t
8549         ;; We fetch the article.
8550         (catch 'found
8551           (dolist (gnus-override-method (gnus-refer-article-methods))
8552             (when (and (gnus-check-server gnus-override-method)
8553                        ;; Fetch the header,
8554                        (setq number (gnus-summary-insert-subject message-id)))
8555               ;; and display the article.
8556               (gnus-summary-select-article nil nil nil number)
8557               (throw 'found t)))
8558           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8559
8560 (defun gnus-refer-article-methods ()
8561   "Return a list of referable methods."
8562   (cond
8563    ;; No method, so we default to current and native.
8564    ((null gnus-refer-article-method)
8565     (list gnus-current-select-method gnus-select-method))
8566    ;; Current.
8567    ((eq 'current gnus-refer-article-method)
8568     (list gnus-current-select-method))
8569    ;; List of select methods.
8570    ((not (and (symbolp (car gnus-refer-article-method))
8571               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8572     (let (out)
8573       (dolist (method gnus-refer-article-method)
8574         (push (if (eq 'current method)
8575                   gnus-current-select-method
8576                 method)
8577               out))
8578       (nreverse out)))
8579    ;; One single select method.
8580    (t
8581     (list gnus-refer-article-method))))
8582
8583 (defun gnus-summary-edit-parameters ()
8584   "Edit the group parameters of the current group."
8585   (interactive)
8586   (gnus-group-edit-group gnus-newsgroup-name 'params))
8587
8588 (defun gnus-summary-customize-parameters ()
8589   "Customize the group parameters of the current group."
8590   (interactive)
8591   (gnus-group-customize gnus-newsgroup-name))
8592
8593 (defun gnus-summary-enter-digest-group (&optional force)
8594   "Enter an nndoc group based on the current article.
8595 If FORCE, force a digest interpretation.  If not, try
8596 to guess what the document format is."
8597   (interactive "P")
8598   (let ((conf gnus-current-window-configuration))
8599     (save-window-excursion
8600       (save-excursion
8601         (let (gnus-article-prepare-hook
8602               gnus-display-mime-function
8603               gnus-break-pages)
8604           (gnus-summary-select-article))))
8605     (setq gnus-current-window-configuration conf)
8606     (let* ((name (format "%s-%d"
8607                          (gnus-group-prefixed-name
8608                           gnus-newsgroup-name (list 'nndoc ""))
8609                          (with-current-buffer gnus-summary-buffer
8610                            gnus-current-article)))
8611            (ogroup gnus-newsgroup-name)
8612            (params (append (gnus-info-params (gnus-get-info ogroup))
8613                            (list (cons 'to-group ogroup))
8614                            (list (cons 'parent-group ogroup))
8615                            (list (cons 'save-article-group ogroup))))
8616            (case-fold-search t)
8617            (buf (current-buffer))
8618            dig to-address)
8619       (save-excursion
8620         (set-buffer gnus-original-article-buffer)
8621         ;; Have the digest group inherit the main mail address of
8622         ;; the parent article.
8623         (when (setq to-address (or (gnus-fetch-field "reply-to")
8624                                    (gnus-fetch-field "from")))
8625           (setq params (append
8626                         (list (cons 'to-address
8627                                     (funcall gnus-decode-encoded-word-function
8628                                              to-address))))))
8629         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8630         (insert-buffer-substring gnus-original-article-buffer)
8631         ;; Remove lines that may lead nndoc to misinterpret the
8632         ;; document type.
8633         (narrow-to-region
8634          (goto-char (point-min))
8635          (or (search-forward "\n\n" nil t) (point)))
8636         (goto-char (point-min))
8637         (delete-matching-lines "^Path:\\|^From ")
8638         (widen))
8639       (unwind-protect
8640           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8641                     (gnus-newsgroup-ephemeral-ignored-charsets
8642                      gnus-newsgroup-ignored-charsets))
8643                 (gnus-group-read-ephemeral-group
8644                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8645                               (nndoc-article-type
8646                                ,(if force 'mbox 'guess)))
8647                  t nil nil nil
8648                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8649                                                         "ADAPT")))))
8650               ;; Make all postings to this group go to the parent group.
8651               (nconc (gnus-info-params (gnus-get-info name))
8652                      params)
8653             ;; Couldn't select this doc group.
8654             (switch-to-buffer buf)
8655             (gnus-set-global-variables)
8656             (gnus-configure-windows 'summary)
8657             (gnus-message 3 "Article couldn't be entered?"))
8658         (kill-buffer dig)))))
8659
8660 (defun gnus-summary-read-document (n)
8661   "Open a new group based on the current article(s).
8662 This will allow you to read digests and other similar
8663 documents as newsgroups.
8664 Obeys the standard process/prefix convention."
8665   (interactive "P")
8666   (let* ((ogroup gnus-newsgroup-name)
8667          (params (append (gnus-info-params (gnus-get-info ogroup))
8668                          (list (cons 'to-group ogroup))))
8669          group egroup groups vgroup)
8670     (dolist (article (gnus-summary-work-articles n))
8671       (setq group (format "%s-%d" gnus-newsgroup-name article))
8672       (gnus-summary-remove-process-mark article)
8673       (when (gnus-summary-display-article article)
8674         (save-excursion
8675           (with-temp-buffer
8676             (insert-buffer-substring gnus-original-article-buffer)
8677             ;; Remove some headers that may lead nndoc to make
8678             ;; the wrong guess.
8679             (message-narrow-to-head)
8680             (goto-char (point-min))
8681             (delete-matching-lines "^Path:\\|^From ")
8682             (widen)
8683             (if (setq egroup
8684                       (gnus-group-read-ephemeral-group
8685                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8686                                      (nndoc-article-type guess))
8687                        t nil t))
8688                 (progn
8689             ;; Make all postings to this group go to the parent group.
8690                   (nconc (gnus-info-params (gnus-get-info egroup))
8691                          params)
8692                   (push egroup groups))
8693               ;; Couldn't select this doc group.
8694               (gnus-error 3 "Article couldn't be entered"))))))
8695     ;; Now we have selected all the documents.
8696     (cond
8697      ((not groups)
8698       (error "None of the articles could be interpreted as documents"))
8699      ((gnus-group-read-ephemeral-group
8700        (setq vgroup (format
8701                      "nnvirtual:%s-%s" gnus-newsgroup-name
8702                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8703        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8704        t
8705        (cons (current-buffer) 'summary)))
8706      (t
8707       (error "Couldn't select virtual nndoc group")))))
8708
8709 (defun gnus-summary-isearch-article (&optional regexp-p)
8710   "Do incremental search forward on the current article.
8711 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8712   (interactive "P")
8713   (gnus-summary-select-article)
8714   (gnus-configure-windows 'article)
8715   (gnus-eval-in-buffer-window gnus-article-buffer
8716     (save-restriction
8717       (widen)
8718       (isearch-forward regexp-p))))
8719
8720 (defun gnus-summary-repeat-search-article-forward ()
8721   "Repeat the previous search forwards."
8722   (interactive)
8723   (unless gnus-last-search-regexp
8724     (error "No previous search"))
8725   (gnus-summary-search-article-forward gnus-last-search-regexp))
8726
8727 (defun gnus-summary-repeat-search-article-backward ()
8728   "Repeat the previous search backwards."
8729   (interactive)
8730   (unless gnus-last-search-regexp
8731     (error "No previous search"))
8732   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8733
8734 (defun gnus-summary-search-article-forward (regexp &optional backward)
8735   "Search for an article containing REGEXP forward.
8736 If BACKWARD, search backward instead."
8737   (interactive
8738    (list (read-string
8739           (format "Search article %s (regexp%s): "
8740                   (if current-prefix-arg "backward" "forward")
8741                   (if gnus-last-search-regexp
8742                       (concat ", default " gnus-last-search-regexp)
8743                     "")))
8744          current-prefix-arg))
8745   (if (string-equal regexp "")
8746       (setq regexp (or gnus-last-search-regexp ""))
8747     (setq gnus-last-search-regexp regexp)
8748     (setq gnus-article-before-search gnus-current-article))
8749   ;; Intentionally set gnus-last-article.
8750   (setq gnus-last-article gnus-article-before-search)
8751   (let ((gnus-last-article gnus-last-article))
8752     (if (gnus-summary-search-article regexp backward)
8753         (gnus-summary-show-thread)
8754       (signal 'search-failed (list regexp)))))
8755
8756 (defun gnus-summary-search-article-backward (regexp)
8757   "Search for an article containing REGEXP backward."
8758   (interactive
8759    (list (read-string
8760           (format "Search article backward (regexp%s): "
8761                   (if gnus-last-search-regexp
8762                       (concat ", default " gnus-last-search-regexp)
8763                     "")))))
8764   (gnus-summary-search-article-forward regexp 'backward))
8765
8766 (defun gnus-summary-search-article (regexp &optional backward)
8767   "Search for an article containing REGEXP.
8768 Optional argument BACKWARD means do search for backward.
8769 `gnus-select-article-hook' is not called during the search."
8770   ;; We have to require this here to make sure that the following
8771   ;; dynamic binding isn't shadowed by autoloading.
8772   (require 'gnus-async)
8773   (require 'gnus-art)
8774   (let ((gnus-select-article-hook nil)  ;Disable hook.
8775         (gnus-article-prepare-hook nil)
8776         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8777         (gnus-use-article-prefetch nil)
8778         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8779         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8780         (gnus-visual nil)
8781         (gnus-keep-backlog nil)
8782         (gnus-break-pages nil)
8783         (gnus-summary-display-arrow nil)
8784         (gnus-updated-mode-lines nil)
8785         (gnus-auto-center-summary nil)
8786         (sum (current-buffer))
8787         (gnus-display-mime-function nil)
8788         (found nil)
8789         point)
8790     (gnus-save-hidden-threads
8791       (gnus-summary-select-article)
8792       (set-buffer gnus-article-buffer)
8793       (goto-char (window-point (get-buffer-window (current-buffer))))
8794       (when backward
8795         (forward-line -1))
8796       (while (not found)
8797         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8798         (if (if backward
8799                 (re-search-backward regexp nil t)
8800               (re-search-forward regexp nil t))
8801             ;; We found the regexp.
8802             (progn
8803               (setq found 'found)
8804               (beginning-of-line)
8805               (set-window-start
8806                (get-buffer-window (current-buffer))
8807                (point))
8808               (forward-line 1)
8809               (set-window-point
8810                (get-buffer-window (current-buffer))
8811                (point))
8812               (set-buffer sum)
8813               (setq point (point)))
8814           ;; We didn't find it, so we go to the next article.
8815           (set-buffer sum)
8816           (setq found 'not)
8817           (while (eq found 'not)
8818             (if (not (if backward (gnus-summary-find-prev)
8819                        (gnus-summary-find-next)))
8820                 ;; No more articles.
8821                 (setq found t)
8822               ;; Select the next article and adjust point.
8823               (unless (gnus-summary-article-sparse-p
8824                        (gnus-summary-article-number))
8825                 (setq found nil)
8826                 (gnus-summary-select-article)
8827                 (set-buffer gnus-article-buffer)
8828                 (widen)
8829                 (goto-char (if backward (point-max) (point-min))))))))
8830       (gnus-message 7 ""))
8831     ;; Return whether we found the regexp.
8832     (when (eq found 'found)
8833       (goto-char point)
8834       (gnus-summary-show-thread)
8835       (gnus-summary-goto-subject gnus-current-article)
8836       (gnus-summary-position-point)
8837       t)))
8838
8839 (defun gnus-find-matching-articles (header regexp)
8840   "Return a list of all articles that match REGEXP on HEADER.
8841 This search includes all articles in the current group that Gnus has
8842 fetched headers for, whether they are displayed or not."
8843   (let ((articles nil)
8844         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8845         (case-fold-search t))
8846     (dolist (header gnus-newsgroup-headers)
8847       (when (string-match regexp (funcall func header))
8848         (push (mail-header-number header) articles)))
8849     (nreverse articles)))
8850
8851 (defun gnus-summary-find-matching (header regexp &optional backward unread
8852                                           not-case-fold not-matching)
8853   "Return a list of all articles that match REGEXP on HEADER.
8854 The search stars on the current article and goes forwards unless
8855 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8856 If UNREAD is non-nil, only unread articles will
8857 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8858 in the comparisons. If NOT-MATCHING, return a list of all articles that
8859 not match REGEXP on HEADER."
8860   (let ((case-fold-search (not not-case-fold))
8861         articles d func)
8862     (if (consp header)
8863         (if (eq (car header) 'extra)
8864             (setq func
8865                   `(lambda (h)
8866                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8867                          "")))
8868           (error "%s is an invalid header" header))
8869       (unless (fboundp (intern (concat "mail-header-" header)))
8870         (error "%s is not a valid header" header))
8871       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8872     (dolist (d (if (eq backward 'all)
8873                    gnus-newsgroup-data
8874                  (gnus-data-find-list
8875                   (gnus-summary-article-number)
8876                   (gnus-data-list backward))))
8877       (when (and (or (not unread)       ; We want all articles...
8878                      (gnus-data-unread-p d)) ; Or just unreads.
8879                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8880                  (if not-matching
8881                      (not (string-match
8882                            regexp
8883                            (funcall func (gnus-data-header d))))
8884                    (string-match regexp
8885                                  (funcall func (gnus-data-header d)))))
8886         (push (gnus-data-number d) articles))) ; Success!
8887     (nreverse articles)))
8888
8889 (defun gnus-summary-execute-command (header regexp command &optional backward)
8890   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8891 If HEADER is an empty string (or nil), the match is done on the entire
8892 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8893   (interactive
8894    (list (let ((completion-ignore-case t))
8895            (completing-read
8896             "Header name: "
8897             (mapcar (lambda (header) (list (format "%s" header)))
8898                     (append
8899                      '("Number" "Subject" "From" "Lines" "Date"
8900                        "Message-ID" "Xref" "References" "Body")
8901                      gnus-extra-headers))
8902             nil 'require-match))
8903          (read-string "Regexp: ")
8904          (read-key-sequence "Command: ")
8905          current-prefix-arg))
8906   (when (equal header "Body")
8907     (setq header ""))
8908   ;; Hidden thread subtrees must be searched as well.
8909   (gnus-summary-show-all-threads)
8910   ;; We don't want to change current point nor window configuration.
8911   (save-excursion
8912     (save-window-excursion
8913       (let (gnus-visual
8914             gnus-treat-strip-trailing-blank-lines
8915             gnus-treat-strip-leading-blank-lines
8916             gnus-treat-strip-multiple-blank-lines
8917             gnus-treat-hide-boring-headers
8918             gnus-treat-fold-newsgroups
8919             gnus-article-prepare-hook)
8920         (gnus-message 6 "Executing %s..." (key-description command))
8921         ;; We'd like to execute COMMAND interactively so as to give arguments.
8922         (gnus-execute header regexp
8923                       `(call-interactively ',(key-binding command))
8924                       backward)
8925         (gnus-message 6 "Executing %s...done" (key-description command))))))
8926
8927 (defun gnus-summary-beginning-of-article ()
8928   "Scroll the article back to the beginning."
8929   (interactive)
8930   (gnus-summary-select-article)
8931   (gnus-configure-windows 'article)
8932   (gnus-eval-in-buffer-window gnus-article-buffer
8933     (widen)
8934     (goto-char (point-min))
8935     (when gnus-break-pages
8936       (gnus-narrow-to-page))))
8937
8938 (defun gnus-summary-end-of-article ()
8939   "Scroll to the end of the article."
8940   (interactive)
8941   (gnus-summary-select-article)
8942   (gnus-configure-windows 'article)
8943   (gnus-eval-in-buffer-window gnus-article-buffer
8944     (widen)
8945     (goto-char (point-max))
8946     (recenter -3)
8947     (when gnus-break-pages
8948       (when (re-search-backward page-delimiter nil t)
8949         (narrow-to-region (match-end 0) (point-max)))
8950       (gnus-narrow-to-page))))
8951
8952 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8953   "Truncate to LEN and quote all \"(\"'s in STRING."
8954   (gnus-replace-in-string (if (and len (> (length string) len))
8955                               (substring string 0 len)
8956                             string)
8957                           "[()]" "\\\\\\&"))
8958
8959 (defun gnus-summary-print-article (&optional filename n)
8960   "Generate and print a PostScript image of the process-marked (mail) articles.
8961
8962 If used interactively, print the current article if none are
8963 process-marked.  With prefix arg, prompt the user for the name of the
8964 file to save in.
8965
8966 When used from Lisp, accept two optional args FILENAME and N.  N means
8967 to print the next N articles.  If N is negative, print the N previous
8968 articles.  If N is nil and articles have been marked with the process
8969 mark, print these instead.
8970
8971 If the optional first argument FILENAME is nil, send the image to the
8972 printer.  If FILENAME is a string, save the PostScript image in a file with
8973 that name.  If FILENAME is a number, prompt the user for the name of the file
8974 to save in."
8975   (interactive (list (ps-print-preprint current-prefix-arg)))
8976   (dolist (article (gnus-summary-work-articles n))
8977     (gnus-summary-select-article nil nil 'pseudo article)
8978     (gnus-eval-in-buffer-window gnus-article-buffer
8979       (gnus-print-buffer))
8980     (gnus-summary-remove-process-mark article))
8981   (ps-despool filename))
8982
8983 (defun gnus-print-buffer ()
8984   (let ((buffer (generate-new-buffer " *print*")))
8985     (unwind-protect
8986         (progn
8987           (copy-to-buffer buffer (point-min) (point-max))
8988           (set-buffer buffer)
8989           (gnus-remove-text-with-property 'gnus-decoration)
8990           (when (gnus-visual-p 'article-highlight 'highlight)
8991             ;; Copy-to-buffer doesn't copy overlay.  So redo
8992             ;; highlight.
8993             (let ((gnus-article-buffer buffer))
8994               (gnus-article-highlight-citation t)
8995               (gnus-article-highlight-signature)
8996               (gnus-article-emphasize)
8997               (gnus-article-delete-invisible-text)))
8998           (let ((ps-left-header
8999                  (list
9000                   (concat "("
9001                           (gnus-summary-print-truncate-and-quote
9002                            (mail-header-subject gnus-current-headers)
9003                            66) ")")
9004                   (concat "("
9005                           (gnus-summary-print-truncate-and-quote
9006                            (mail-header-from gnus-current-headers)
9007                            45) ")")))
9008                 (ps-right-header
9009                  (list
9010                   "/pagenumberstring load"
9011                   (concat "("
9012                           (mail-header-date gnus-current-headers) ")"))))
9013             (gnus-run-hooks 'gnus-ps-print-hook)
9014             (save-excursion
9015               (if window-system
9016                   (ps-spool-buffer-with-faces)
9017                 (ps-spool-buffer)))))
9018       (kill-buffer buffer))))
9019
9020 (defun gnus-summary-show-article (&optional arg)
9021   "Force redisplaying of the current article.
9022 If ARG (the prefix) is a number, show the article with the charset
9023 defined in `gnus-summary-show-article-charset-alist', or the charset
9024 input.
9025 If ARG (the prefix) is non-nil and not a number, show the raw article
9026 without any article massaging functions being run.  Normally, the key
9027 strokes are `C-u g'."
9028   (interactive "P")
9029   (cond
9030    ((numberp arg)
9031     (gnus-summary-show-article t)
9032     (let ((gnus-newsgroup-charset
9033            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9034                (mm-read-coding-system
9035                 "View as charset: " ;; actually it is coding system.
9036                 (with-current-buffer gnus-article-buffer
9037                   (mm-detect-coding-region (point) (point-max))))))
9038           (gnus-newsgroup-ignored-charsets 'gnus-all))
9039       (gnus-summary-select-article nil 'force)
9040       (let ((deps gnus-newsgroup-dependencies)
9041             head header lines)
9042         (save-excursion
9043           (set-buffer gnus-original-article-buffer)
9044           (save-restriction
9045             (message-narrow-to-head)
9046             (setq head (buffer-string))
9047             (goto-char (point-min))
9048             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9049               (goto-char (point-max))
9050               (widen)
9051               (setq lines (1- (count-lines (point) (point-max))))))
9052           (with-temp-buffer
9053             (insert (format "211 %d Article retrieved.\n"
9054                             (cdr gnus-article-current)))
9055             (insert head)
9056             (if lines (insert (format "Lines: %d\n" lines)))
9057             (insert ".\n")
9058             (let ((nntp-server-buffer (current-buffer)))
9059               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9060         (gnus-data-set-header
9061          (gnus-data-find (cdr gnus-article-current))
9062          header)
9063         (gnus-summary-update-article-line
9064          (cdr gnus-article-current) header)
9065         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9066           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9067    ((not arg)
9068     ;; Select the article the normal way.
9069     (gnus-summary-select-article nil 'force))
9070    (t
9071     ;; We have to require this here to make sure that the following
9072     ;; dynamic binding isn't shadowed by autoloading.
9073     (require 'gnus-async)
9074     (require 'gnus-art)
9075     ;; Bind the article treatment functions to nil.
9076     (let ((gnus-have-all-headers t)
9077           gnus-article-prepare-hook
9078           gnus-article-decode-hook
9079           gnus-display-mime-function
9080           gnus-break-pages)
9081       ;; Destroy any MIME parts.
9082       (when (gnus-buffer-live-p gnus-article-buffer)
9083         (save-excursion
9084           (set-buffer gnus-article-buffer)
9085           (mm-destroy-parts gnus-article-mime-handles)
9086           ;; Set it to nil for safety reason.
9087           (setq gnus-article-mime-handle-alist nil)
9088           (setq gnus-article-mime-handles nil)))
9089       (gnus-summary-select-article nil 'force))))
9090   (gnus-summary-goto-subject gnus-current-article)
9091   (gnus-summary-position-point))
9092
9093 (defun gnus-summary-show-raw-article ()
9094   "Show the raw article without any article massaging functions being run."
9095   (interactive)
9096   (gnus-summary-show-article t))
9097
9098 (defun gnus-summary-verbose-headers (&optional arg)
9099   "Toggle permanent full header display.
9100 If ARG is a positive number, turn header display on.
9101 If ARG is a negative number, turn header display off."
9102   (interactive "P")
9103   (setq gnus-show-all-headers
9104         (cond ((or (not (numberp arg))
9105                    (zerop arg))
9106                (not gnus-show-all-headers))
9107               ((natnump arg)
9108                t)))
9109   (gnus-summary-show-article))
9110
9111 (defun gnus-summary-toggle-header (&optional arg)
9112   "Show the headers if they are hidden, or hide them if they are shown.
9113 If ARG is a positive number, show the entire header.
9114 If ARG is a negative number, hide the unwanted header lines."
9115   (interactive "P")
9116   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9117                      (get-buffer-window gnus-article-buffer t))))
9118     (with-current-buffer gnus-article-buffer
9119       (widen)
9120       (article-narrow-to-head)
9121       (let* ((buffer-read-only nil)
9122              (inhibit-point-motion-hooks t)
9123              (hidden (if (numberp arg)
9124                          (>= arg 0)
9125                        (or (not (looking-at "[^ \t\n]+:"))
9126                            (gnus-article-hidden-text-p 'headers))))
9127              s e)
9128         (delete-region (point-min) (point-max))
9129         (with-current-buffer gnus-original-article-buffer
9130           (goto-char (setq s (point-min)))
9131           (setq e (if (search-forward "\n\n" nil t)
9132                       (1- (point))
9133                     (point-max))))
9134         (insert-buffer-substring gnus-original-article-buffer s e)
9135         (run-hooks 'gnus-article-decode-hook)
9136         (if hidden
9137             (let ((gnus-treat-hide-headers nil)
9138                   (gnus-treat-hide-boring-headers nil))
9139               (gnus-delete-wash-type 'headers)
9140               (gnus-treat-article 'head))
9141           (gnus-treat-article 'head))
9142         (widen)
9143         (if window
9144             (set-window-start window (goto-char (point-min))))
9145         (if gnus-break-pages
9146             (gnus-narrow-to-page)
9147           (when (gnus-visual-p 'page-marker)
9148             (let ((buffer-read-only nil))
9149               (gnus-remove-text-with-property 'gnus-prev)
9150               (gnus-remove-text-with-property 'gnus-next))))
9151         (gnus-set-mode-line 'article)))))
9152
9153 (defun gnus-summary-show-all-headers ()
9154   "Make all header lines visible."
9155   (interactive)
9156   (gnus-summary-toggle-header 1))
9157
9158 (defun gnus-summary-caesar-message (&optional arg)
9159   "Caesar rotate the current article by 13.
9160 The numerical prefix specifies how many places to rotate each letter
9161 forward."
9162   (interactive "P")
9163   (gnus-summary-select-article)
9164   (let ((mail-header-separator ""))
9165     (gnus-eval-in-buffer-window gnus-article-buffer
9166       (save-restriction
9167         (widen)
9168         (let ((start (window-start))
9169               buffer-read-only)
9170           (message-caesar-buffer-body arg)
9171           (set-window-start (get-buffer-window (current-buffer)) start)))))
9172   ;; Create buttons and stuff...
9173   (gnus-treat-article nil))
9174
9175 (defun gnus-summary-idna-message (&optional arg)
9176   "Decode IDNA encoded domain names in the current articles.
9177 IDNA encoded domain names looks like `xn--bar'.  If a string
9178 remain unencoded after running this function, it is likely an
9179 invalid IDNA string (`xn--bar' is invalid).
9180
9181 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9182 installed for this command to work."
9183   (interactive "P")
9184   (if (not (and (condition-case nil (require 'idna)
9185                   (file-error))
9186                 (mm-coding-system-p 'utf-8)
9187                 (executable-find (symbol-value 'idna-program))))
9188       (gnus-message
9189        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9190     (gnus-summary-select-article)
9191     (let ((mail-header-separator ""))
9192       (gnus-eval-in-buffer-window gnus-article-buffer
9193         (save-restriction
9194           (widen)
9195           (let ((start (window-start))
9196                 buffer-read-only)
9197             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9198               (replace-match (idna-to-unicode (match-string 1))))
9199             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9200
9201 (defun gnus-summary-morse-message (&optional arg)
9202   "Morse decode the current article."
9203   (interactive "P")
9204   (gnus-summary-select-article)
9205   (let ((mail-header-separator ""))
9206     (gnus-eval-in-buffer-window gnus-article-buffer
9207       (save-excursion
9208         (save-restriction
9209           (widen)
9210           (let ((pos (window-start))
9211                 buffer-read-only)
9212             (goto-char (point-min))
9213             (when (message-goto-body)
9214               (gnus-narrow-to-body))
9215             (goto-char (point-min))
9216             (while (search-forward "·" (point-max) t)
9217               (replace-match "."))
9218             (unmorse-region (point-min) (point-max))
9219             (widen)
9220             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9221
9222 (defun gnus-summary-stop-page-breaking ()
9223   "Stop page breaking in the current article."
9224   (interactive)
9225   (gnus-summary-select-article)
9226   (gnus-eval-in-buffer-window gnus-article-buffer
9227     (widen)
9228     (when (gnus-visual-p 'page-marker)
9229       (let ((buffer-read-only nil))
9230         (gnus-remove-text-with-property 'gnus-prev)
9231         (gnus-remove-text-with-property 'gnus-next))
9232       (setq gnus-page-broken nil))))
9233
9234 (defun gnus-summary-move-article (&optional n to-newsgroup
9235                                             select-method action)
9236   "Move the current article to a different newsgroup.
9237 If N is a positive number, move the N next articles.
9238 If N is a negative number, move the N previous articles.
9239 If N is nil and any articles have been marked with the process mark,
9240 move those articles instead.
9241 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9242 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9243 re-spool using this method.
9244
9245 When called interactively with TO-NEWSGROUP being nil, the value of
9246 the variable `gnus-move-split-methods' is used for finding a default
9247 for the target newsgroup.
9248
9249 For this function to work, both the current newsgroup and the
9250 newsgroup that you want to move to have to support the `request-move'
9251 and `request-accept' functions.
9252
9253 ACTION can be either `move' (the default), `crosspost' or `copy'."
9254   (interactive "P")
9255   (unless action
9256     (setq action 'move))
9257   ;; Check whether the source group supports the required functions.
9258   (cond ((and (eq action 'move)
9259               (not (gnus-check-backend-function
9260                     'request-move-article gnus-newsgroup-name)))
9261          (error "The current group does not support article moving"))
9262         ((and (eq action 'crosspost)
9263               (not (gnus-check-backend-function
9264                     'request-replace-article gnus-newsgroup-name)))
9265          (error "The current group does not support article editing")))
9266   (let ((articles (gnus-summary-work-articles n))
9267         (prefix (if (gnus-check-backend-function
9268                      'request-move-article gnus-newsgroup-name)
9269                     (funcall gnus-move-group-prefix-function
9270                              gnus-newsgroup-name)
9271                   ""))
9272         (names '((move "Move" "Moving")
9273                  (copy "Copy" "Copying")
9274                  (crosspost "Crosspost" "Crossposting")))
9275         (copy-buf (save-excursion
9276                     (nnheader-set-temp-buffer " *copy article*")))
9277         art-group to-method new-xref article to-groups articles-to-update-marks)
9278     (unless (assq action names)
9279       (error "Unknown action %s" action))
9280     ;; Read the newsgroup name.
9281     (when (and (not to-newsgroup)
9282                (not select-method))
9283       (if (and gnus-move-split-methods
9284                (not
9285                 (and (memq gnus-current-article articles)
9286                      (gnus-buffer-live-p gnus-original-article-buffer))))
9287           ;; When `gnus-move-split-methods' is non-nil, we have to
9288           ;; select an article to give `gnus-read-move-group-name' an
9289           ;; opportunity to suggest an appropriate default.  However,
9290           ;; we needn't render or mark the article.
9291           (let ((gnus-display-mime-function nil)
9292                 (gnus-article-prepare-hook nil)
9293                 (gnus-mark-article-hook nil))
9294             (gnus-summary-select-article nil nil nil (car articles))))
9295       (setq to-newsgroup
9296             (gnus-read-move-group-name
9297              (cadr (assq action names))
9298              (symbol-value (intern (format "gnus-current-%s-group" action)))
9299              articles prefix))
9300       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9301     (setq to-method (or select-method
9302                         (gnus-server-to-method
9303                          (gnus-group-method to-newsgroup))))
9304     ;; Check the method we are to move this article to...
9305     (unless (gnus-check-backend-function
9306              'request-accept-article (car to-method))
9307       (error "%s does not support article copying" (car to-method)))
9308     (unless (gnus-check-server to-method)
9309       (error "Can't open server %s" (car to-method)))
9310     (gnus-message 6 "%s to %s: %s..."
9311                   (caddr (assq action names))
9312                   (or (car select-method) to-newsgroup) articles)
9313     (while articles
9314       (setq article (pop articles))
9315       (setq
9316        art-group
9317        (cond
9318         ;; Move the article.
9319         ((eq action 'move)
9320          ;; Remove this article from future suppression.
9321          (gnus-dup-unsuppress-article article)
9322          (let* ((from-method (gnus-find-method-for-group
9323                               gnus-newsgroup-name))
9324                 (to-method (gnus-find-method-for-group
9325                             to-newsgroup))
9326                 (move-is-internal (gnus-method-equal from-method to-method)))
9327          (gnus-request-move-article
9328           article                       ; Article to move
9329           gnus-newsgroup-name           ; From newsgroup
9330           (nth 1 (gnus-find-method-for-group
9331                   gnus-newsgroup-name)) ; Server
9332           (list 'gnus-request-accept-article
9333                 to-newsgroup (list 'quote select-method)
9334                 (not articles) t)       ; Accept form
9335           (not articles)                ; Only save nov last time
9336           move-is-internal)))           ; is this move internal?
9337         ;; Copy the article.
9338         ((eq action 'copy)
9339          (save-excursion
9340            (set-buffer copy-buf)
9341            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9342              (save-restriction
9343                (nnheader-narrow-to-headers)
9344                (dolist (hdr gnus-copy-article-ignored-headers)
9345                  (message-remove-header hdr t)))
9346              (gnus-request-accept-article
9347               to-newsgroup select-method (not articles) t))))
9348         ;; Crosspost the article.
9349         ((eq action 'crosspost)
9350          (let ((xref (message-tokenize-header
9351                       (mail-header-xref (gnus-summary-article-header article))
9352                       " ")))
9353            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9354                                   ":" (number-to-string article)))
9355            (unless xref
9356              (setq xref (list (system-name))))
9357            (setq new-xref
9358                  (concat
9359                   (mapconcat 'identity
9360                              (delete "Xref:" (delete new-xref xref))
9361                              " ")
9362                   " " new-xref))
9363            (save-excursion
9364              (set-buffer copy-buf)
9365              ;; First put the article in the destination group.
9366              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9367              (when (consp (setq art-group
9368                                 (gnus-request-accept-article
9369                                  to-newsgroup select-method (not articles))))
9370                (setq new-xref (concat new-xref " " (car art-group)
9371                                       ":"
9372                                       (number-to-string (cdr art-group))))
9373                ;; Now we have the new Xrefs header, so we insert
9374                ;; it and replace the new article.
9375                (nnheader-replace-header "Xref" new-xref)
9376                (gnus-request-replace-article
9377                 (cdr art-group) to-newsgroup (current-buffer))
9378                art-group))))))
9379       (cond
9380        ((not art-group)
9381         (gnus-message 1 "Couldn't %s article %s: %s"
9382                       (cadr (assq action names)) article
9383                       (nnheader-get-report (car to-method))))
9384        ((eq art-group 'junk)
9385         (when (eq action 'move)
9386           (gnus-summary-mark-article article gnus-canceled-mark)
9387           (gnus-message 4 "Deleted article %s" article)
9388           ;; run the delete hook
9389           (run-hook-with-args 'gnus-summary-article-delete-hook
9390                               action
9391                               (gnus-data-header
9392                                (assoc article (gnus-data-list nil)))
9393                               gnus-newsgroup-name nil
9394                               select-method)))
9395        (t
9396         (let* ((pto-group (gnus-group-prefixed-name
9397                            (car art-group) to-method))
9398                (info (gnus-get-info pto-group))
9399                (to-group (gnus-info-group info))
9400                to-marks)
9401           ;; Update the group that has been moved to.
9402           (when (and info
9403                      (memq action '(move copy)))
9404             (unless (member to-group to-groups)
9405               (push to-group to-groups))
9406
9407             (unless (memq article gnus-newsgroup-unreads)
9408               (push 'read to-marks)
9409               (gnus-info-set-read
9410                info (gnus-add-to-range (gnus-info-read info)
9411                                        (list (cdr art-group)))))
9412
9413             ;; See whether the article is to be put in the cache.
9414             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9415                              gnus-article-mark-lists
9416                            (delete '(expirable . expire)
9417                                    (copy-sequence gnus-article-mark-lists))))
9418                   (to-article (cdr art-group)))
9419
9420               ;; Enter the article into the cache in the new group,
9421               ;; if that is required.
9422               (when gnus-use-cache
9423                 (gnus-cache-possibly-enter-article
9424                  to-group to-article
9425                  (memq article gnus-newsgroup-marked)
9426                  (memq article gnus-newsgroup-dormant)
9427                  (memq article gnus-newsgroup-unreads)))
9428
9429               (when gnus-preserve-marks
9430                 ;; Copy any marks over to the new group.
9431                 (when (and (equal to-group gnus-newsgroup-name)
9432                            (not (memq article gnus-newsgroup-unreads)))
9433                   ;; Mark this article as read in this group.
9434                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9435                   (setcdr (gnus-active to-group) to-article)
9436                   (setcdr gnus-newsgroup-active to-article))
9437
9438                 (while marks
9439                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9440                     (when (memq article (symbol-value
9441                                          (intern (format "gnus-newsgroup-%s"
9442                                                          (caar marks)))))
9443                       (push (cdar marks) to-marks)
9444                       ;; If the other group is the same as this group,
9445                       ;; then we have to add the mark to the list.
9446                       (when (equal to-group gnus-newsgroup-name)
9447                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9448                              (cons to-article
9449                                    (symbol-value
9450                                     (intern (format "gnus-newsgroup-%s"
9451                                                     (caar marks)))))))
9452                       ;; Copy the marks to other group.
9453                       (gnus-add-marked-articles
9454                        to-group (cdar marks) (list to-article) info)))
9455                   (setq marks (cdr marks)))
9456
9457                 (gnus-request-set-mark
9458                  to-group (list (list (list to-article) 'add to-marks))))
9459
9460               (gnus-dribble-enter
9461                (concat "(gnus-group-set-info '"
9462                        (gnus-prin1-to-string (gnus-get-info to-group))
9463                        ")"))))
9464
9465           ;; Update the Xref header in this article to point to
9466           ;; the new crossposted article we have just created.
9467           (when (eq action 'crosspost)
9468             (save-excursion
9469               (set-buffer copy-buf)
9470               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9471               (nnheader-replace-header "Xref" new-xref)
9472               (gnus-request-replace-article
9473                article gnus-newsgroup-name (current-buffer))))
9474
9475           ;; run the move/copy/crosspost/respool hook
9476           (run-hook-with-args 'gnus-summary-article-move-hook
9477                               action
9478                               (gnus-data-header
9479                                (assoc article (gnus-data-list nil)))
9480                               gnus-newsgroup-name
9481                               to-newsgroup
9482                               select-method))
9483
9484         ;;;!!!Why is this necessary?
9485         (set-buffer gnus-summary-buffer)
9486         
9487         (gnus-summary-goto-subject article)
9488         (when (eq action 'move)
9489           (gnus-summary-mark-article article gnus-canceled-mark))))
9490       (push article articles-to-update-marks))
9491
9492     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9493     ;; Re-activate all groups that have been moved to.
9494     (save-excursion
9495       (set-buffer gnus-group-buffer)
9496       (let ((gnus-group-marked to-groups))
9497         (gnus-group-get-new-news-this-group nil t)))
9498     
9499     (gnus-kill-buffer copy-buf)
9500     (gnus-summary-position-point)
9501     (gnus-set-mode-line 'summary)))
9502
9503 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9504   "Copy the current article to some other group.
9505 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9506 When called interactively, if TO-NEWSGROUP is nil, use the value of
9507 the variable `gnus-move-split-methods' for finding a default target
9508 newsgroup.
9509 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9510 re-spool using this method."
9511   (interactive "P")
9512   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9513
9514 (defun gnus-summary-crosspost-article (&optional n)
9515   "Crosspost the current article to some other group."
9516   (interactive "P")
9517   (gnus-summary-move-article n nil nil 'crosspost))
9518
9519 (defcustom gnus-summary-respool-default-method nil
9520   "Default method type for respooling an article.
9521 If nil, use to the current newsgroup method."
9522   :type 'symbol
9523   :group 'gnus-summary-mail)
9524
9525 (defcustom gnus-summary-display-while-building nil
9526   "If non-nil, show and update the summary buffer as it's being built.
9527 If the value is t, update the buffer after every line is inserted.  If
9528 the value is an integer (N), update the display every N lines."
9529   :version "22.1"
9530   :group 'gnus-thread
9531   :type '(choice (const :tag "off" nil)
9532                  number
9533                  (const :tag "frequently" t)))
9534
9535 (defun gnus-summary-respool-article (&optional n method)
9536   "Respool the current article.
9537 The article will be squeezed through the mail spooling process again,
9538 which means that it will be put in some mail newsgroup or other
9539 depending on `nnmail-split-methods'.
9540 If N is a positive number, respool the N next articles.
9541 If N is a negative number, respool the N previous articles.
9542 If N is nil and any articles have been marked with the process mark,
9543 respool those articles instead.
9544
9545 Respooling can be done both from mail groups and \"real\" newsgroups.
9546 In the former case, the articles in question will be moved from the
9547 current group into whatever groups they are destined to.  In the
9548 latter case, they will be copied into the relevant groups."
9549   (interactive
9550    (list current-prefix-arg
9551          (let* ((methods (gnus-methods-using 'respool))
9552                 (methname
9553                  (symbol-name (or gnus-summary-respool-default-method
9554                                   (car (gnus-find-method-for-group
9555                                         gnus-newsgroup-name)))))
9556                 (method
9557                  (gnus-completing-read-with-default
9558                   methname "Backend to use when respooling"
9559                   methods nil t nil 'gnus-mail-method-history))
9560                 ms)
9561            (cond
9562             ((zerop (length (setq ms (gnus-servers-using-backend
9563                                       (intern method)))))
9564              (list (intern method) ""))
9565             ((= 1 (length ms))
9566              (car ms))
9567             (t
9568              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9569                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9570                            ms-alist))))))))
9571   (unless method
9572     (error "No method given for respooling"))
9573   (if (assoc (symbol-name
9574               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9575              (gnus-methods-using 'respool))
9576       (gnus-summary-move-article n nil method)
9577     (gnus-summary-copy-article n nil method)))
9578
9579 (defun gnus-summary-import-article (file &optional edit)
9580   "Import an arbitrary file into a mail newsgroup."
9581   (interactive "fImport file: \nP")
9582   (let ((group gnus-newsgroup-name)
9583         (now (current-time))
9584         atts lines group-art)
9585     (unless (gnus-check-backend-function 'request-accept-article group)
9586       (error "%s does not support article importing" group))
9587     (or (file-readable-p file)
9588         (not (file-regular-p file))
9589         (error "Can't read %s" file))
9590     (save-excursion
9591       (set-buffer (gnus-get-buffer-create " *import file*"))
9592       (erase-buffer)
9593       (nnheader-insert-file-contents file)
9594       (goto-char (point-min))
9595       (if (nnheader-article-p)
9596           (save-restriction
9597             (goto-char (point-min))
9598             (search-forward "\n\n" nil t)
9599             (narrow-to-region (point-min) (1- (point)))
9600             (goto-char (point-min))
9601             (unless (re-search-forward "^date:" nil t)
9602               (goto-char (point-max))
9603               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9604        ;; This doesn't look like an article, so we fudge some headers.
9605         (setq atts (file-attributes file)
9606               lines (count-lines (point-min) (point-max)))
9607         (insert "From: " (read-string "From: ") "\n"
9608                 "Subject: " (read-string "Subject: ") "\n"
9609                 "Date: " (message-make-date (nth 5 atts)) "\n"
9610                 "Message-ID: " (message-make-message-id) "\n"
9611                 "Lines: " (int-to-string lines) "\n"
9612                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9613       (setq group-art (gnus-request-accept-article group nil t))
9614       (kill-buffer (current-buffer)))
9615     (setq gnus-newsgroup-active (gnus-activate-group group))
9616     (forward-line 1)
9617     (gnus-summary-goto-article (cdr group-art) nil t)
9618     (when edit
9619       (gnus-summary-edit-article))))
9620
9621 (defun gnus-summary-create-article ()
9622   "Create an article in a mail newsgroup."
9623   (interactive)
9624   (let ((group gnus-newsgroup-name)
9625         (now (current-time))
9626         group-art)
9627     (unless (gnus-check-backend-function 'request-accept-article group)
9628       (error "%s does not support article importing" group))
9629     (save-excursion
9630       (set-buffer (gnus-get-buffer-create " *import file*"))
9631       (erase-buffer)
9632       (goto-char (point-min))
9633       ;; This doesn't look like an article, so we fudge some headers.
9634       (insert "From: " (read-string "From: ") "\n"
9635               "Subject: " (read-string "Subject: ") "\n"
9636               "Date: " (message-make-date now) "\n"
9637               "Message-ID: " (message-make-message-id) "\n")
9638       (setq group-art (gnus-request-accept-article group nil t))
9639       (kill-buffer (current-buffer)))
9640     (setq gnus-newsgroup-active (gnus-activate-group group))
9641     (forward-line 1)
9642     (gnus-summary-goto-article (cdr group-art) nil t)
9643     (gnus-summary-edit-article)))
9644
9645 (defun gnus-summary-article-posted-p ()
9646   "Say whether the current (mail) article is available from news as well.
9647 This will be the case if the article has both been mailed and posted."
9648   (interactive)
9649   (let ((id (mail-header-references (gnus-summary-article-header)))
9650         (gnus-override-method (car (gnus-refer-article-methods))))
9651     (if (gnus-request-head id "")
9652         (gnus-message 2 "The current message was found on %s"
9653                       gnus-override-method)
9654       (gnus-message 2 "The current message couldn't be found on %s"
9655                     gnus-override-method)
9656       nil)))
9657
9658 (defun gnus-summary-expire-articles (&optional now)
9659   "Expire all articles that are marked as expirable in the current group."
9660   (interactive)
9661   (when (and (not gnus-group-is-exiting-without-update-p)
9662              (gnus-check-backend-function
9663               'request-expire-articles gnus-newsgroup-name))
9664     ;; This backend supports expiry.
9665     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9666            (expirable (if total
9667                           (progn
9668                             ;; We need to update the info for
9669                             ;; this group for `gnus-list-of-read-articles'
9670                             ;; to give us the right answer.
9671                             (gnus-run-hooks 'gnus-exit-group-hook)
9672                             (gnus-summary-update-info)
9673                             (gnus-list-of-read-articles gnus-newsgroup-name))
9674                         (setq gnus-newsgroup-expirable
9675                               (sort gnus-newsgroup-expirable '<))))
9676            (expiry-wait (if now 'immediate
9677                           (gnus-group-find-parameter
9678                            gnus-newsgroup-name 'expiry-wait)))
9679            (nnmail-expiry-target
9680             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9681                 nnmail-expiry-target))
9682            es)
9683       (when expirable
9684         ;; There are expirable articles in this group, so we run them
9685         ;; through the expiry process.
9686         (gnus-message 6 "Expiring articles...")
9687         (unless (gnus-check-group gnus-newsgroup-name)
9688           (error "Can't open server for %s" gnus-newsgroup-name))
9689         ;; The list of articles that weren't expired is returned.
9690         (save-excursion
9691           (if expiry-wait
9692               (let ((nnmail-expiry-wait-function nil)
9693                     (nnmail-expiry-wait expiry-wait))
9694                 (setq es (gnus-request-expire-articles
9695                           expirable gnus-newsgroup-name)))
9696             (setq es (gnus-request-expire-articles
9697                       expirable gnus-newsgroup-name)))
9698           (unless total
9699             (setq gnus-newsgroup-expirable es))
9700           ;; We go through the old list of expirable, and mark all
9701           ;; really expired articles as nonexistent.
9702           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9703             (let ((gnus-use-cache nil))
9704               (dolist (article expirable)
9705                 (when (and (not (memq article es))
9706                            (gnus-data-find article))
9707                   (gnus-summary-mark-article article gnus-canceled-mark)
9708                   (run-hook-with-args 'gnus-summary-article-expire-hook
9709                                       'delete
9710                                       (gnus-data-header
9711                                        (assoc article (gnus-data-list nil)))
9712                                       gnus-newsgroup-name
9713                                       nil
9714                                       nil))))))
9715         (gnus-message 6 "Expiring articles...done")))))
9716
9717 (defun gnus-summary-expire-articles-now ()
9718   "Expunge all expirable articles in the current group.
9719 This means that *all* articles that are marked as expirable will be
9720 deleted forever, right now."
9721   (interactive)
9722   (or gnus-expert-user
9723       (gnus-yes-or-no-p
9724        "Are you really, really sure you want to delete all expirable messages? ")
9725       (error "Phew!"))
9726   (gnus-summary-expire-articles t))
9727
9728 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9729 (defun gnus-summary-delete-article (&optional n)
9730   "Delete the N next (mail) articles.
9731 This command actually deletes articles.  This is not a marking
9732 command.  The article will disappear forever from your life, never to
9733 return.
9734
9735 If N is negative, delete backwards.
9736 If N is nil and articles have been marked with the process mark,
9737 delete these instead.
9738
9739 If `gnus-novice-user' is non-nil you will be asked for
9740 confirmation before the articles are deleted."
9741   (interactive "P")
9742   (unless (gnus-check-backend-function 'request-expire-articles
9743                                        gnus-newsgroup-name)
9744     (error "The current newsgroup does not support article deletion"))
9745   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9746     (error "Couldn't open server"))
9747   ;; Compute the list of articles to delete.
9748   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9749         (nnmail-expiry-target 'delete)
9750         not-deleted)
9751     (if (and gnus-novice-user
9752              (not (gnus-yes-or-no-p
9753                    (format "Do you really want to delete %s forever? "
9754                            (if (> (length articles) 1)
9755                                (format "these %s articles" (length articles))
9756                              "this article")))))
9757         ()
9758       ;; Delete the articles.
9759       (setq not-deleted (gnus-request-expire-articles
9760                          articles gnus-newsgroup-name 'force))
9761       (while articles
9762         (gnus-summary-remove-process-mark (car articles))
9763         ;; The backend might not have been able to delete the article
9764         ;; after all.
9765         (unless (memq (car articles) not-deleted)
9766           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9767         (let* ((article (car articles))
9768                (ghead  (gnus-data-header
9769                                     (assoc article (gnus-data-list nil)))))
9770           (run-hook-with-args 'gnus-summary-article-delete-hook
9771                               'delete ghead gnus-newsgroup-name nil
9772                               nil))
9773         (setq articles (cdr articles)))
9774       (when not-deleted
9775         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9776     (gnus-summary-position-point)
9777     (gnus-set-mode-line 'summary)
9778     not-deleted))
9779
9780 (defun gnus-summary-edit-article (&optional arg)
9781   "Edit the current article.
9782 This will have permanent effect only in mail groups.
9783 If ARG is nil, edit the decoded articles.
9784 If ARG is 1, edit the raw articles.
9785 If ARG is 2, edit the raw articles even in read-only groups.
9786 If ARG is 3, edit the articles with the current handles.
9787 Otherwise, allow editing of articles even in read-only
9788 groups."
9789   (interactive "P")
9790   (let (force raw current-handles)
9791     (cond
9792      ((null arg))
9793      ((eq arg 1)
9794       (setq raw t))
9795      ((eq arg 2)
9796       (setq raw t
9797             force t))
9798      ((eq arg 3)
9799       (setq current-handles
9800             (and (gnus-buffer-live-p gnus-article-buffer)
9801                  (with-current-buffer gnus-article-buffer
9802                    (prog1
9803                        gnus-article-mime-handles
9804                      (setq gnus-article-mime-handles nil))))))
9805      (t
9806       (setq force t)))
9807     (when (and raw (not force)
9808                (member gnus-newsgroup-name '("nndraft:delayed"
9809                                              "nndraft:drafts"
9810                                              "nndraft:queue")))
9811       (error "Can't edit the raw article in group %s"
9812              gnus-newsgroup-name))
9813     (save-excursion
9814       (set-buffer gnus-summary-buffer)
9815       (let ((mail-parse-charset gnus-newsgroup-charset)
9816             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9817         (gnus-set-global-variables)
9818         (when (and (not force)
9819                    (gnus-group-read-only-p))
9820           (error "The current newsgroup does not support article editing"))
9821         (gnus-summary-show-article t)
9822         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9823           (with-current-buffer gnus-article-buffer
9824             (mm-enable-multibyte)))
9825         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9826             (setq raw t))
9827         (gnus-article-edit-article
9828          (if raw 'ignore
9829            `(lambda ()
9830               (let ((mbl mml-buffer-list))
9831                 (setq mml-buffer-list nil)
9832                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9833                   (mime-to-mml ,'current-handles))
9834                 (let ((mbl1 mml-buffer-list))
9835                   (setq mml-buffer-list mbl)
9836                   (set (make-local-variable 'mml-buffer-list) mbl1))
9837                 (gnus-make-local-hook 'kill-buffer-hook)
9838                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9839          `(lambda (no-highlight)
9840             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9841                   (message-options message-options)
9842                   (message-options-set-recipient)
9843                   (mail-parse-ignored-charsets
9844                    ',gnus-newsgroup-ignored-charsets))
9845               ,(if (not raw) '(progn
9846                                 (mml-to-mime)
9847                                 (mml-destroy-buffers)
9848                                 (remove-hook 'kill-buffer-hook
9849                                              'mml-destroy-buffers t)
9850                                 (kill-local-variable 'mml-buffer-list)))
9851               (gnus-summary-edit-article-done
9852                ,(or (mail-header-references gnus-current-headers) "")
9853                ,(gnus-group-read-only-p)
9854                ,gnus-summary-buffer no-highlight))))))))
9855
9856 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9857
9858 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9859                                                  no-highlight)
9860   "Make edits to the current article permanent."
9861   (interactive)
9862   (save-excursion
9863    ;; The buffer restriction contains the entire article if it exists.
9864     (when (article-goto-body)
9865       (let ((lines (count-lines (point) (point-max)))
9866             (length (- (point-max) (point)))
9867             (case-fold-search t)
9868             (body (copy-marker (point))))
9869         (goto-char (point-min))
9870         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9871           (delete-region (match-beginning 1) (match-end 1))
9872           (insert (number-to-string length)))
9873         (goto-char (point-min))
9874         (when (re-search-forward
9875                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9876           (delete-region (match-beginning 1) (match-end 1))
9877           (insert (number-to-string length)))
9878         (goto-char (point-min))
9879         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9880           (delete-region (match-beginning 1) (match-end 1))
9881           (insert (number-to-string lines))))))
9882   ;; Replace the article.
9883   (let ((buf (current-buffer)))
9884     (with-temp-buffer
9885       (insert-buffer-substring buf)
9886
9887       (if (and (not read-only)
9888                (not (gnus-request-replace-article
9889                      (cdr gnus-article-current) (car gnus-article-current)
9890                      (current-buffer) t)))
9891           (error "Couldn't replace article")
9892         ;; Update the summary buffer.
9893         (if (and references
9894                  (equal (message-tokenize-header references " ")
9895                         (message-tokenize-header
9896                          (or (message-fetch-field "references") "") " ")))
9897             ;; We only have to update this line.
9898             (save-excursion
9899               (save-restriction
9900                 (message-narrow-to-head)
9901                 (let ((head (buffer-substring-no-properties
9902                              (point-min) (point-max)))
9903                       header)
9904                   (with-temp-buffer
9905                     (insert (format "211 %d Article retrieved.\n"
9906                                     (cdr gnus-article-current)))
9907                     (insert head)
9908                     (insert ".\n")
9909                     (let ((nntp-server-buffer (current-buffer)))
9910                       (setq header (car (gnus-get-newsgroup-headers
9911                                          nil t))))
9912                     (save-excursion
9913                       (set-buffer gnus-summary-buffer)
9914                       (gnus-data-set-header
9915                        (gnus-data-find (cdr gnus-article-current))
9916                        header)
9917                       (gnus-summary-update-article-line
9918                        (cdr gnus-article-current) header)
9919                       (if (gnus-summary-goto-subject
9920                            (cdr gnus-article-current) nil t)
9921                           (gnus-summary-update-secondary-mark
9922                            (cdr gnus-article-current))))))))
9923           ;; Update threads.
9924           (set-buffer (or buffer gnus-summary-buffer))
9925           (gnus-summary-update-article (cdr gnus-article-current))
9926           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9927               (gnus-summary-update-secondary-mark
9928                (cdr gnus-article-current))))
9929         ;; Prettify the article buffer again.
9930         (unless no-highlight
9931           (save-excursion
9932             (set-buffer gnus-article-buffer)
9933             ;;;!!! Fix this -- article should be rehighlighted.
9934             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9935             (set-buffer gnus-original-article-buffer)
9936             (gnus-request-article
9937              (cdr gnus-article-current)
9938              (car gnus-article-current) (current-buffer))))
9939         ;; Prettify the summary buffer line.
9940         (when (gnus-visual-p 'summary-highlight 'highlight)
9941           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9942
9943 (defun gnus-summary-edit-wash (key)
9944   "Perform editing command KEY in the article buffer."
9945   (interactive
9946    (list
9947     (progn
9948       (message "%s" (concat (this-command-keys) "- "))
9949       (read-char))))
9950   (message "")
9951   (gnus-summary-edit-article)
9952   (execute-kbd-macro (concat (this-command-keys) key))
9953   (gnus-article-edit-done))
9954
9955 ;;; Respooling
9956
9957 (defun gnus-summary-respool-query (&optional silent trace)
9958   "Query where the respool algorithm would put this article."
9959   (interactive)
9960   (let (gnus-mark-article-hook)
9961     (gnus-summary-select-article)
9962     (save-excursion
9963       (set-buffer gnus-original-article-buffer)
9964       (let ((groups (nnmail-article-group 'identity trace)))
9965         (unless silent
9966           (if groups
9967               (message "This message would go to %s"
9968                        (mapconcat 'car groups ", "))
9969             (message "This message would go to no groups"))
9970           groups)))))
9971
9972 (defun gnus-summary-respool-trace ()
9973   "Trace where the respool algorithm would put this article.
9974 Display a buffer showing all fancy splitting patterns which matched."
9975   (interactive)
9976   (gnus-summary-respool-query nil t))
9977
9978 ;; Summary marking commands.
9979
9980 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9981   "Mark articles which has the same subject as read, and then select the next.
9982 If UNMARK is positive, remove any kind of mark.
9983 If UNMARK is negative, tick articles."
9984   (interactive "P")
9985   (when unmark
9986     (setq unmark (prefix-numeric-value unmark)))
9987   (let ((count
9988          (gnus-summary-mark-same-subject
9989           (gnus-summary-article-subject) unmark)))
9990     ;; Select next unread article.  If auto-select-same mode, should
9991     ;; select the first unread article.
9992     (gnus-summary-next-article t (and gnus-auto-select-same
9993                                       (gnus-summary-article-subject)))
9994     (gnus-message 7 "%d article%s marked as %s"
9995                   count (if (= count 1) " is" "s are")
9996                   (if unmark "unread" "read"))))
9997
9998 (defun gnus-summary-kill-same-subject (&optional unmark)
9999   "Mark articles which has the same subject as read.
10000 If UNMARK is positive, remove any kind of mark.
10001 If UNMARK is negative, tick articles."
10002   (interactive "P")
10003   (when unmark
10004     (setq unmark (prefix-numeric-value unmark)))
10005   (let ((count
10006          (gnus-summary-mark-same-subject
10007           (gnus-summary-article-subject) unmark)))
10008     ;; If marked as read, go to next unread subject.
10009     (when (null unmark)
10010       ;; Go to next unread subject.
10011       (gnus-summary-next-subject 1 t))
10012     (gnus-message 7 "%d articles are marked as %s"
10013                   count (if unmark "unread" "read"))))
10014
10015 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10016   "Mark articles with same SUBJECT as read, and return marked number.
10017 If optional argument UNMARK is positive, remove any kinds of marks.
10018 If optional argument UNMARK is negative, mark articles as unread instead."
10019   (let ((count 1))
10020     (save-excursion
10021       (cond
10022        ((null unmark)                   ; Mark as read.
10023         (while (and
10024                 (progn
10025                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10026                   (gnus-summary-show-thread) t)
10027                 (gnus-summary-find-subject subject))
10028           (setq count (1+ count))))
10029        ((> unmark 0)                    ; Tick.
10030         (while (and
10031                 (progn
10032                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10033                   (gnus-summary-show-thread) t)
10034                 (gnus-summary-find-subject subject))
10035           (setq count (1+ count))))
10036        (t                               ; Mark as unread.
10037         (while (and
10038                 (progn
10039                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10040                   (gnus-summary-show-thread) t)
10041                 (gnus-summary-find-subject subject))
10042           (setq count (1+ count)))))
10043       (gnus-set-mode-line 'summary)
10044       ;; Return the number of marked articles.
10045       count)))
10046
10047 (defun gnus-summary-mark-as-processable (n &optional unmark)
10048   "Set the process mark on the next N articles.
10049 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10050 the process mark instead.  The difference between N and the actual
10051 number of articles marked is returned."
10052   (interactive "P")
10053   (if (and (null n) (gnus-region-active-p))
10054       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10055     (setq n (prefix-numeric-value n))
10056     (let ((backward (< n 0))
10057           (n (abs n)))
10058       (while (and
10059               (> n 0)
10060               (if unmark
10061                   (gnus-summary-remove-process-mark
10062                    (gnus-summary-article-number))
10063                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10064               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10065         (setq n (1- n)))
10066       (when (/= 0 n)
10067         (gnus-message 7 "No more articles"))
10068       (gnus-summary-recenter)
10069       (gnus-summary-position-point)
10070       n)))
10071
10072 (defun gnus-summary-unmark-as-processable (n)
10073   "Remove the process mark from the next N articles.
10074 If N is negative, unmark backward instead.  The difference between N and
10075 the actual number of articles unmarked is returned."
10076   (interactive "P")
10077   (gnus-summary-mark-as-processable n t))
10078
10079 (defun gnus-summary-unmark-all-processable ()
10080   "Remove the process mark from all articles."
10081   (interactive)
10082   (save-excursion
10083     (while gnus-newsgroup-processable
10084       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10085   (gnus-summary-position-point))
10086
10087 (defun gnus-summary-add-mark (article type)
10088   "Mark ARTICLE with a mark of TYPE."
10089   (let ((vtype (car (assq type gnus-article-mark-lists)))
10090         var)
10091     (if (not vtype)
10092         (error "No such mark type: %s" type)
10093       (setq var (intern (format "gnus-newsgroup-%s" type)))
10094       (set var (cons article (symbol-value var)))
10095       (if (memq type '(processable cached replied forwarded recent saved))
10096           (gnus-summary-update-secondary-mark article)
10097         ;;; !!! This is bogus.  We should find out what primary
10098         ;;; !!! mark we want to set.
10099         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10100
10101 (defun gnus-summary-mark-as-expirable (n)
10102   "Mark N articles forward as expirable.
10103 If N is negative, mark backward instead.  The difference between N and
10104 the actual number of articles marked is returned."
10105   (interactive "p")
10106   (gnus-summary-mark-forward n gnus-expirable-mark))
10107
10108 (defun gnus-summary-mark-as-spam (n)
10109   "Mark N articles forward as spam.
10110 If N is negative, mark backward instead.  The difference between N and
10111 the actual number of articles marked is returned."
10112   (interactive "p")
10113   (gnus-summary-mark-forward n gnus-spam-mark))
10114
10115 (defun gnus-summary-mark-article-as-replied (article)
10116   "Mark ARTICLE as replied to and update the summary line.
10117 ARTICLE can also be a list of articles."
10118   (interactive (list (gnus-summary-article-number)))
10119   (let ((articles (if (listp article) article (list article))))
10120     (dolist (article articles)
10121       (unless (numberp article)
10122         (error "%s is not a number" article))
10123       (push article gnus-newsgroup-replied)
10124       (let ((buffer-read-only nil))
10125         (when (gnus-summary-goto-subject article nil t)
10126           (gnus-summary-update-secondary-mark article))))))
10127
10128 (defun gnus-summary-mark-article-as-forwarded (article)
10129   "Mark ARTICLE as forwarded and update the summary line.
10130 ARTICLE can also be a list of articles."
10131   (let ((articles (if (listp article) article (list article))))
10132     (dolist (article articles)
10133       (push article gnus-newsgroup-forwarded)
10134       (let ((buffer-read-only nil))
10135         (when (gnus-summary-goto-subject article nil t)
10136           (gnus-summary-update-secondary-mark article))))))
10137
10138 (defun gnus-summary-set-bookmark (article)
10139   "Set a bookmark in current article."
10140   (interactive (list (gnus-summary-article-number)))
10141   (when (or (not (get-buffer gnus-article-buffer))
10142             (not gnus-current-article)
10143             (not gnus-article-current)
10144             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10145     (error "No current article selected"))
10146   ;; Remove old bookmark, if one exists.
10147   (gnus-pull article gnus-newsgroup-bookmarks)
10148   ;; Set the new bookmark, which is on the form
10149   ;; (article-number . line-number-in-body).
10150   (push
10151    (cons article
10152          (with-current-buffer gnus-article-buffer
10153            (count-lines
10154             (min (point)
10155                  (save-excursion
10156                    (article-goto-body)
10157                    (point)))
10158             (point))))
10159    gnus-newsgroup-bookmarks)
10160   (gnus-message 6 "A bookmark has been added to the current article."))
10161
10162 (defun gnus-summary-remove-bookmark (article)
10163   "Remove the bookmark from the current article."
10164   (interactive (list (gnus-summary-article-number)))
10165   ;; Remove old bookmark, if one exists.
10166   (if (not (assq article gnus-newsgroup-bookmarks))
10167       (gnus-message 6 "No bookmark in current article.")
10168     (gnus-pull article gnus-newsgroup-bookmarks)
10169     (gnus-message 6 "Removed bookmark.")))
10170
10171 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10172 (defun gnus-summary-mark-as-dormant (n)
10173   "Mark N articles forward as dormant.
10174 If N is negative, mark backward instead.  The difference between N and
10175 the actual number of articles marked is returned."
10176   (interactive "p")
10177   (gnus-summary-mark-forward n gnus-dormant-mark))
10178
10179 (defun gnus-summary-set-process-mark (article)
10180   "Set the process mark on ARTICLE and update the summary line."
10181   (setq gnus-newsgroup-processable
10182         (cons article
10183               (delq article gnus-newsgroup-processable)))
10184   (when (gnus-summary-goto-subject article)
10185     (gnus-summary-show-thread)
10186     (gnus-summary-goto-subject article)
10187     (gnus-summary-update-secondary-mark article)))
10188
10189 (defun gnus-summary-remove-process-mark (&rest articles)
10190   "Remove the process mark from ARTICLES and update the summary line."
10191   (dolist (article articles)
10192     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10193     (when (gnus-summary-goto-subject article)
10194       (gnus-summary-show-thread)
10195       (gnus-summary-goto-subject article)
10196       (gnus-summary-update-secondary-mark article)))
10197   t)
10198
10199 (defun gnus-summary-set-saved-mark (article)
10200   "Set the process mark on ARTICLE and update the summary line."
10201   (push article gnus-newsgroup-saved)
10202   (when (gnus-summary-goto-subject article)
10203     (gnus-summary-update-secondary-mark article)))
10204
10205 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10206   "Mark N articles as read forwards.
10207 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10208 The difference between N and the actual number of articles marked is
10209 returned.
10210 If NO-EXPIRE, auto-expiry will be inhibited."
10211   (interactive "p")
10212   (gnus-summary-show-thread)
10213   (let ((backward (< n 0))
10214         (gnus-summary-goto-unread
10215          (and gnus-summary-goto-unread
10216               (not (eq gnus-summary-goto-unread 'never))
10217               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10218                                     gnus-ticked-mark gnus-dormant-mark)))))
10219         (n (abs n))
10220         (mark (or mark gnus-del-mark)))
10221     (while (and (> n 0)
10222                 (gnus-summary-mark-article nil mark no-expire)
10223                 (zerop (gnus-summary-next-subject
10224                         (if backward -1 1)
10225                         (and gnus-summary-goto-unread
10226                              (not (eq gnus-summary-goto-unread 'never)))
10227                         t)))
10228       (setq n (1- n)))
10229     (when (/= 0 n)
10230       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10231     (gnus-summary-recenter)
10232     (gnus-summary-position-point)
10233     (gnus-set-mode-line 'summary)
10234     n))
10235
10236 (defun gnus-summary-mark-article-as-read (mark)
10237   "Mark the current article quickly as read with MARK."
10238   (let ((article (gnus-summary-article-number)))
10239     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10240     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10241     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10242     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10243     (push (cons article mark) gnus-newsgroup-reads)
10244     ;; Possibly remove from cache, if that is used.
10245     (when gnus-use-cache
10246       (gnus-cache-enter-remove-article article))
10247     ;; Allow the backend to change the mark.
10248     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10249     ;; Check for auto-expiry.
10250     (when (and gnus-newsgroup-auto-expire
10251                (memq mark gnus-auto-expirable-marks))
10252       (setq mark gnus-expirable-mark)
10253       ;; Let the backend know about the mark change.
10254       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10255       (push article gnus-newsgroup-expirable))
10256     ;; Set the mark in the buffer.
10257     (gnus-summary-update-mark mark 'unread)
10258     t))
10259
10260 (defun gnus-summary-mark-article-as-unread (mark)
10261   "Mark the current article quickly as unread with MARK."
10262   (let* ((article (gnus-summary-article-number))
10263          (old-mark (gnus-summary-article-mark article)))
10264     ;; Allow the backend to change the mark.
10265     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10266     (if (eq mark old-mark)
10267         t
10268       (if (<= article 0)
10269           (progn
10270             (gnus-error 1 "Can't mark negative article numbers")
10271             nil)
10272         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10273         (setq gnus-newsgroup-spam-marked
10274               (delq article gnus-newsgroup-spam-marked))
10275         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10276         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10277         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10278         (cond ((= mark gnus-ticked-mark)
10279                (setq gnus-newsgroup-marked
10280                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10281                                               article)))
10282               ((= mark gnus-spam-mark)
10283                (setq gnus-newsgroup-spam-marked
10284                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10285                                               article)))
10286               ((= mark gnus-dormant-mark)
10287                (setq gnus-newsgroup-dormant
10288                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10289                                               article)))
10290               (t
10291                (setq gnus-newsgroup-unreads
10292                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10293                                               article))))
10294         (gnus-pull article gnus-newsgroup-reads)
10295
10296         ;; See whether the article is to be put in the cache.
10297         (and gnus-use-cache
10298              (vectorp (gnus-summary-article-header article))
10299              (save-excursion
10300                (gnus-cache-possibly-enter-article
10301                 gnus-newsgroup-name article
10302                 (= mark gnus-ticked-mark)
10303                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10304
10305         ;; Fix the mark.
10306         (gnus-summary-update-mark mark 'unread)
10307         t))))
10308
10309 (defun gnus-summary-mark-article (&optional article mark no-expire)
10310   "Mark ARTICLE with MARK.  MARK can be any character.
10311 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10312 `??' (dormant) and `?E' (expirable).
10313 If MARK is nil, then the default character `?r' is used.
10314 If ARTICLE is nil, then the article on the current line will be
10315 marked.
10316 If NO-EXPIRE, auto-expiry will be inhibited."
10317   ;; The mark might be a string.
10318   (when (stringp mark)
10319     (setq mark (aref mark 0)))
10320   ;; If no mark is given, then we check auto-expiring.
10321   (when (null mark)
10322     (setq mark gnus-del-mark))
10323   (when (and (not no-expire)
10324              gnus-newsgroup-auto-expire
10325              (memq mark gnus-auto-expirable-marks))
10326     (setq mark gnus-expirable-mark))
10327   (let ((article (or article (gnus-summary-article-number)))
10328         (old-mark (gnus-summary-article-mark article)))
10329     ;; Allow the backend to change the mark.
10330     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10331     (if (eq mark old-mark)
10332         t
10333       (unless article
10334         (error "No article on current line"))
10335       (if (not (if (or (= mark gnus-unread-mark)
10336                        (= mark gnus-ticked-mark)
10337                        (= mark gnus-spam-mark)
10338                        (= mark gnus-dormant-mark))
10339                    (gnus-mark-article-as-unread article mark)
10340                  (gnus-mark-article-as-read article mark)))
10341           t
10342         ;; See whether the article is to be put in the cache.
10343         (and gnus-use-cache
10344              (not (= mark gnus-canceled-mark))
10345              (vectorp (gnus-summary-article-header article))
10346              (save-excursion
10347                (gnus-cache-possibly-enter-article
10348                 gnus-newsgroup-name article
10349                 (= mark gnus-ticked-mark)
10350                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10351
10352         (when (gnus-summary-goto-subject article nil t)
10353           (let ((buffer-read-only nil))
10354             (gnus-summary-show-thread)
10355             ;; Fix the mark.
10356             (gnus-summary-update-mark mark 'unread)
10357             t))))))
10358
10359 (defun gnus-summary-update-secondary-mark (article)
10360   "Update the secondary (read, process, cache) mark."
10361   (gnus-summary-update-mark
10362    (cond ((memq article gnus-newsgroup-processable)
10363           gnus-process-mark)
10364          ((memq article gnus-newsgroup-cached)
10365           gnus-cached-mark)
10366          ((memq article gnus-newsgroup-replied)
10367           gnus-replied-mark)
10368          ((memq article gnus-newsgroup-forwarded)
10369           gnus-forwarded-mark)
10370          ((memq article gnus-newsgroup-saved)
10371           gnus-saved-mark)
10372          ((memq article gnus-newsgroup-recent)
10373           gnus-recent-mark)
10374          ((memq article gnus-newsgroup-unseen)
10375           gnus-unseen-mark)
10376          (t gnus-no-mark))
10377    'replied)
10378   (when (gnus-visual-p 'summary-highlight 'highlight)
10379     (gnus-run-hooks 'gnus-summary-update-hook))
10380   t)
10381
10382 (defun gnus-summary-update-download-mark (article)
10383   "Update the download mark."
10384   (gnus-summary-update-mark
10385    (cond ((memq article gnus-newsgroup-undownloaded)
10386           gnus-undownloaded-mark)
10387          (gnus-newsgroup-agentized
10388           gnus-downloaded-mark)
10389          (t
10390           gnus-no-mark))
10391    'download)
10392   (gnus-summary-update-line t)
10393   t)
10394
10395 (defun gnus-summary-update-mark (mark type)
10396   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10397         (buffer-read-only nil))
10398     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10399     (when forward
10400       (when (looking-at "\r")
10401         (incf forward))
10402       (when (<= (+ forward (point)) (point-max))
10403         ;; Go to the right position on the line.
10404         (goto-char (+ forward (point)))
10405         ;; Replace the old mark with the new mark.
10406         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10407         ;; Optionally update the marks by some user rule.
10408         (when (eq type 'unread)
10409           (gnus-data-set-mark
10410            (gnus-data-find (gnus-summary-article-number)) mark)
10411           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10412
10413 (defun gnus-mark-article-as-read (article &optional mark)
10414   "Enter ARTICLE in the pertinent lists and remove it from others."
10415   ;; Make the article expirable.
10416   (let ((mark (or mark gnus-del-mark)))
10417     (setq gnus-newsgroup-expirable
10418           (if (= mark gnus-expirable-mark)
10419               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10420             (delq article gnus-newsgroup-expirable)))
10421     ;; Remove from unread and marked lists.
10422     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10423     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10424     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10425     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10426     (push (cons article mark) gnus-newsgroup-reads)
10427     ;; Possibly remove from cache, if that is used.
10428     (when gnus-use-cache
10429       (gnus-cache-enter-remove-article article))
10430     t))
10431
10432 (defun gnus-mark-article-as-unread (article &optional mark)
10433   "Enter ARTICLE in the pertinent lists and remove it from others."
10434   (let ((mark (or mark gnus-ticked-mark)))
10435     (if (<= article 0)
10436         (progn
10437           (gnus-error 1 "Can't mark negative article numbers")
10438           nil)
10439       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10440             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10441             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10442             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10443             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10444
10445       ;; Unsuppress duplicates?
10446       (when gnus-suppress-duplicates
10447         (gnus-dup-unsuppress-article article))
10448
10449       (cond ((= mark gnus-ticked-mark)
10450              (setq gnus-newsgroup-marked
10451                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10452             ((= mark gnus-spam-mark)
10453              (setq gnus-newsgroup-spam-marked
10454                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10455                                             article)))
10456             ((= mark gnus-dormant-mark)
10457              (setq gnus-newsgroup-dormant
10458                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10459             (t
10460              (setq gnus-newsgroup-unreads
10461                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10462       (gnus-pull article gnus-newsgroup-reads)
10463       t)))
10464
10465 (defalias 'gnus-summary-mark-as-unread-forward
10466   'gnus-summary-tick-article-forward)
10467 (make-obsolete 'gnus-summary-mark-as-unread-forward
10468                'gnus-summary-tick-article-forward)
10469 (defun gnus-summary-tick-article-forward (n)
10470   "Tick N articles forwards.
10471 If N is negative, tick backwards instead.
10472 The difference between N and the number of articles ticked is returned."
10473   (interactive "p")
10474   (gnus-summary-mark-forward n gnus-ticked-mark))
10475
10476 (defalias 'gnus-summary-mark-as-unread-backward
10477   'gnus-summary-tick-article-backward)
10478 (make-obsolete 'gnus-summary-mark-as-unread-backward
10479                'gnus-summary-tick-article-backward)
10480 (defun gnus-summary-tick-article-backward (n)
10481   "Tick N articles backwards.
10482 The difference between N and the number of articles ticked is returned."
10483   (interactive "p")
10484   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10485
10486 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10487 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10488 (defun gnus-summary-tick-article (&optional article clear-mark)
10489   "Mark current article as unread.
10490 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10491 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10492   (interactive)
10493   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10494                                        gnus-ticked-mark)))
10495
10496 (defun gnus-summary-mark-as-read-forward (n)
10497   "Mark N articles as read forwards.
10498 If N is negative, mark backwards instead.
10499 The difference between N and the actual number of articles marked is
10500 returned."
10501   (interactive "p")
10502   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10503
10504 (defun gnus-summary-mark-as-read-backward (n)
10505   "Mark the N articles as read backwards.
10506 The difference between N and the actual number of articles marked is
10507 returned."
10508   (interactive "p")
10509   (gnus-summary-mark-forward
10510    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10511
10512 (defun gnus-summary-mark-as-read (&optional article mark)
10513   "Mark current article as read.
10514 ARTICLE specifies the article to be marked as read.
10515 MARK specifies a string to be inserted at the beginning of the line."
10516   (gnus-summary-mark-article article mark))
10517
10518 (defun gnus-summary-clear-mark-forward (n)
10519   "Clear marks from N articles forward.
10520 If N is negative, clear backward instead.
10521 The difference between N and the number of marks cleared is returned."
10522   (interactive "p")
10523   (gnus-summary-mark-forward n gnus-unread-mark))
10524
10525 (defun gnus-summary-clear-mark-backward (n)
10526   "Clear marks from N articles backward.
10527 The difference between N and the number of marks cleared is returned."
10528   (interactive "p")
10529   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10530
10531 (defun gnus-summary-mark-unread-as-read ()
10532   "Intended to be used by `gnus-summary-mark-article-hook'."
10533   (when (memq gnus-current-article gnus-newsgroup-unreads)
10534     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10535
10536 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10537   "Intended to be used by `gnus-summary-mark-article-hook'."
10538   (let ((mark (gnus-summary-article-mark)))
10539     (when (or (gnus-unread-mark-p mark)
10540               (gnus-read-mark-p mark))
10541       (gnus-summary-mark-article gnus-current-article
10542                                  (or new-mark gnus-read-mark)))))
10543
10544 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10545   "Intended to be used by `gnus-summary-mark-article-hook'."
10546   (let ((mark (gnus-summary-article-mark)))
10547     (when (or (gnus-unread-mark-p mark)
10548               (gnus-read-mark-p mark))
10549       (gnus-summary-mark-article (gnus-summary-article-number)
10550                                  (or new-mark gnus-read-mark)))))
10551
10552 (defun gnus-summary-mark-unread-as-ticked ()
10553   "Intended to be used by `gnus-summary-mark-article-hook'."
10554   (when (memq gnus-current-article gnus-newsgroup-unreads)
10555     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10556
10557 (defun gnus-summary-mark-region-as-read (point mark all)
10558   "Mark all unread articles between point and mark as read.
10559 If given a prefix, mark all articles between point and mark as read,
10560 even ticked and dormant ones."
10561   (interactive "r\nP")
10562   (save-excursion
10563     (let (article)
10564       (goto-char point)
10565       (beginning-of-line)
10566       (while (and
10567               (< (point) mark)
10568               (progn
10569                 (when (or all
10570                           (memq (setq article (gnus-summary-article-number))
10571                                 gnus-newsgroup-unreads))
10572                   (gnus-summary-mark-article article gnus-del-mark))
10573                 t)
10574               (gnus-summary-find-next))))))
10575
10576 (defun gnus-summary-mark-below (score mark)
10577   "Mark articles with score less than SCORE with MARK."
10578   (interactive "P\ncMark: ")
10579   (setq score (if score
10580                   (prefix-numeric-value score)
10581                 (or gnus-summary-default-score 0)))
10582   (save-excursion
10583     (set-buffer gnus-summary-buffer)
10584     (goto-char (point-min))
10585     (while
10586         (progn
10587           (and (< (gnus-summary-article-score) score)
10588                (gnus-summary-mark-article nil mark))
10589           (gnus-summary-find-next)))))
10590
10591 (defun gnus-summary-kill-below (&optional score)
10592   "Mark articles with score below SCORE as read."
10593   (interactive "P")
10594   (gnus-summary-mark-below score gnus-killed-mark))
10595
10596 (defun gnus-summary-clear-above (&optional score)
10597   "Clear all marks from articles with score above SCORE."
10598   (interactive "P")
10599   (gnus-summary-mark-above score gnus-unread-mark))
10600
10601 (defun gnus-summary-tick-above (&optional score)
10602   "Tick all articles with score above SCORE."
10603   (interactive "P")
10604   (gnus-summary-mark-above score gnus-ticked-mark))
10605
10606 (defun gnus-summary-mark-above (score mark)
10607   "Mark articles with score over SCORE with MARK."
10608   (interactive "P\ncMark: ")
10609   (setq score (if score
10610                   (prefix-numeric-value score)
10611                 (or gnus-summary-default-score 0)))
10612   (save-excursion
10613     (set-buffer gnus-summary-buffer)
10614     (goto-char (point-min))
10615     (while (and (progn
10616                   (when (> (gnus-summary-article-score) score)
10617                     (gnus-summary-mark-article nil mark))
10618                   t)
10619                 (gnus-summary-find-next)))))
10620
10621 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10622 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10623 (defun gnus-summary-limit-include-expunged (&optional no-error)
10624   "Display all the hidden articles that were expunged for low scores."
10625   (interactive)
10626   (let ((buffer-read-only nil))
10627     (let ((scored gnus-newsgroup-scored)
10628           headers h)
10629       (while scored
10630         (unless (gnus-summary-article-header (caar scored))
10631           (and (setq h (gnus-number-to-header (caar scored)))
10632                (< (cdar scored) gnus-summary-expunge-below)
10633                (push h headers)))
10634         (setq scored (cdr scored)))
10635       (if (not headers)
10636           (when (not no-error)
10637             (error "No expunged articles hidden"))
10638         (goto-char (point-min))
10639         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10640         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10641         (mapcar (lambda (x) (push (mail-header-number x)
10642                                   gnus-newsgroup-limit))
10643                 headers)
10644         (gnus-summary-prepare-unthreaded (nreverse headers))
10645         (goto-char (point-min))
10646         (gnus-summary-position-point)
10647         t))))
10648
10649 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10650   "Mark all unread articles in this newsgroup as read.
10651 If prefix argument ALL is non-nil, ticked and dormant articles will
10652 also be marked as read.
10653 If QUIETLY is non-nil, no questions will be asked.
10654
10655 If TO-HERE is non-nil, it should be a point in the buffer.  All
10656 articles before (after, if REVERSE is set) this point will be marked
10657 as read.
10658
10659 Note that this function will only catch up the unread article
10660 in the current summary buffer limitation.
10661
10662 The number of articles marked as read is returned."
10663   (interactive "P")
10664   (prog1
10665       (save-excursion
10666         (when (or quietly
10667                   (not gnus-interactive-catchup) ;Without confirmation?
10668                   gnus-expert-user
10669                   (gnus-y-or-n-p
10670                    (if all
10671                        "Mark absolutely all articles as read? "
10672                      "Mark all unread articles as read? ")))
10673           (if (and not-mark
10674                    (not gnus-newsgroup-adaptive)
10675                    (not gnus-newsgroup-auto-expire)
10676                    (not gnus-suppress-duplicates)
10677                    (or (not gnus-use-cache)
10678                        (eq gnus-use-cache 'passive)))
10679               (progn
10680                 (when all
10681                   (setq gnus-newsgroup-marked nil
10682                         gnus-newsgroup-spam-marked nil
10683                         gnus-newsgroup-dormant nil))
10684                 (setq gnus-newsgroup-unreads
10685                       (gnus-sorted-nunion
10686                        (gnus-intersection gnus-newsgroup-unreads
10687                                           gnus-newsgroup-downloadable)
10688                        gnus-newsgroup-unfetched)))
10689             ;; We actually mark all articles as canceled, which we
10690             ;; have to do when using auto-expiry or adaptive scoring.
10691             (gnus-summary-show-all-threads)
10692             (if (and to-here reverse)
10693                 (progn
10694                   (goto-char to-here)
10695                   (gnus-summary-mark-current-read-and-unread-as-read
10696                    gnus-catchup-mark)
10697                   (while (gnus-summary-find-next (not all))
10698                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10699               (when (gnus-summary-first-subject (not all))
10700                 (while (and
10701                         (if to-here (< (point) to-here) t)
10702                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10703                         (gnus-summary-find-next (not all))))))
10704             (gnus-set-mode-line 'summary))
10705           t))
10706     (gnus-summary-position-point)))
10707
10708 (defun gnus-summary-catchup-to-here (&optional all)
10709   "Mark all unticked articles before the current one as read.
10710 If ALL is non-nil, also mark ticked and dormant articles as read."
10711   (interactive "P")
10712   (save-excursion
10713     (gnus-save-hidden-threads
10714       (let ((beg (point)))
10715         ;; We check that there are unread articles.
10716         (when (or all (gnus-summary-find-prev))
10717           (gnus-summary-catchup all t beg)))))
10718   (gnus-summary-position-point))
10719
10720 (defun gnus-summary-catchup-from-here (&optional all)
10721   "Mark all unticked articles after (and including) the current one as read.
10722 If ALL is non-nil, also mark ticked and dormant articles as read."
10723   (interactive "P")
10724   (save-excursion
10725     (gnus-save-hidden-threads
10726       (let ((beg (point)))
10727         ;; We check that there are unread articles.
10728         (when (or all (gnus-summary-find-next))
10729           (gnus-summary-catchup all t beg nil t)))))
10730   (gnus-summary-position-point))
10731
10732 (defun gnus-summary-catchup-all (&optional quietly)
10733   "Mark all articles in this newsgroup as read.
10734 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10735 instead, which marks only unread articles as read."
10736   (interactive "P")
10737   (gnus-summary-catchup t quietly))
10738
10739 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10740   "Mark all unread articles in this group as read, then exit.
10741 If prefix argument ALL is non-nil, all articles are marked as read.
10742 If QUIETLY is non-nil, no questions will be asked."
10743   (interactive "P")
10744   (when (gnus-summary-catchup all quietly nil 'fast)
10745     ;; Select next newsgroup or exit.
10746     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10747              (eq gnus-auto-select-next 'quietly))
10748         (gnus-summary-next-group nil)
10749       (gnus-summary-exit))))
10750
10751 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10752   "Mark all articles in this newsgroup as read, and then exit.
10753 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10754 instead, which marks only unread articles as read."
10755   (interactive "P")
10756   (gnus-summary-catchup-and-exit t quietly))
10757
10758 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10759   "Mark all articles in this group as read and select the next group.
10760 If given a prefix, mark all articles, unread as well as ticked, as
10761 read."
10762   (interactive "P")
10763   (save-excursion
10764     (gnus-summary-catchup all))
10765   (gnus-summary-next-group))
10766
10767 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10768   "Mark all articles in this group as read and select the previous group.
10769 If given a prefix, mark all articles, unread as well as ticked, as
10770 read."
10771   (interactive "P")
10772   (save-excursion
10773     (gnus-summary-catchup all))
10774   (gnus-summary-next-group nil nil t))
10775
10776 ;;;
10777 ;;; with article
10778 ;;;
10779
10780 (defmacro gnus-with-article (article &rest forms)
10781   "Select ARTICLE and perform FORMS in the original article buffer.
10782 Then replace the article with the result."
10783   `(progn
10784      ;; We don't want the article to be marked as read.
10785      (let (gnus-mark-article-hook)
10786        (gnus-summary-select-article t t nil ,article))
10787      (set-buffer gnus-original-article-buffer)
10788      ,@forms
10789      (if (not (gnus-check-backend-function
10790                'request-replace-article (car gnus-article-current)))
10791          (gnus-message 5 "Read-only group; not replacing")
10792        (unless (gnus-request-replace-article
10793                 ,article (car gnus-article-current)
10794                 (current-buffer) t)
10795          (error "Couldn't replace article")))
10796      ;; The cache and backlog have to be flushed somewhat.
10797      (when gnus-keep-backlog
10798        (gnus-backlog-remove-article
10799         (car gnus-article-current) (cdr gnus-article-current)))
10800      (when gnus-use-cache
10801        (gnus-cache-update-article
10802         (car gnus-article-current) (cdr gnus-article-current)))))
10803
10804 (put 'gnus-with-article 'lisp-indent-function 1)
10805 (put 'gnus-with-article 'edebug-form-spec '(form body))
10806
10807 ;; Thread-based commands.
10808
10809 (defun gnus-summary-articles-in-thread (&optional article)
10810   "Return a list of all articles in the current thread.
10811 If ARTICLE is non-nil, return all articles in the thread that starts
10812 with that article."
10813   (let* ((article (or article (gnus-summary-article-number)))
10814          (data (gnus-data-find-list article))
10815          (top-level (gnus-data-level (car data)))
10816          (top-subject
10817           (cond ((null gnus-thread-operation-ignore-subject)
10818                  (gnus-simplify-subject-re
10819                   (mail-header-subject (gnus-data-header (car data)))))
10820                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10821                  (gnus-simplify-subject-fuzzy
10822                   (mail-header-subject (gnus-data-header (car data)))))
10823                 (t nil)))
10824          (end-point (save-excursion
10825                       (if (gnus-summary-go-to-next-thread)
10826                           (point) (point-max))))
10827          articles)
10828     (while (and data
10829                 (< (gnus-data-pos (car data)) end-point))
10830       (when (or (not top-subject)
10831                 (string= top-subject
10832                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10833                              (gnus-simplify-subject-fuzzy
10834                               (mail-header-subject
10835                                (gnus-data-header (car data))))
10836                            (gnus-simplify-subject-re
10837                             (mail-header-subject
10838                              (gnus-data-header (car data)))))))
10839         (push (gnus-data-number (car data)) articles))
10840       (unless (and (setq data (cdr data))
10841                    (> (gnus-data-level (car data)) top-level))
10842         (setq data nil)))
10843     ;; Return the list of articles.
10844     (nreverse articles)))
10845
10846 (defun gnus-summary-rethread-current ()
10847   "Rethread the thread the current article is part of."
10848   (interactive)
10849   (let* ((gnus-show-threads t)
10850          (article (gnus-summary-article-number))
10851          (id (mail-header-id (gnus-summary-article-header)))
10852          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10853     (unless id
10854       (error "No article on the current line"))
10855     (gnus-rebuild-thread id)
10856     (gnus-summary-goto-subject article)))
10857
10858 (defun gnus-summary-reparent-thread ()
10859   "Make the current article child of the marked (or previous) article.
10860
10861 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10862 is non-nil or the Subject: of both articles are the same."
10863   (interactive)
10864   (unless (not (gnus-group-read-only-p))
10865     (error "The current newsgroup does not support article editing"))
10866   (unless (<= (length gnus-newsgroup-processable) 1)
10867     (error "No more than one article may be marked"))
10868   (let ((child (gnus-summary-article-number))
10869         ;; First grab the marked article, otherwise one line up.
10870         (parent (if (not (null gnus-newsgroup-processable))
10871                     (car gnus-newsgroup-processable)
10872                   (save-excursion
10873                     (if (eq (forward-line -1) 0)
10874                         (gnus-summary-article-number)
10875                       (error "Beginning of summary buffer"))))))
10876     (gnus-summary-reparent-children parent (list child))))
10877
10878 (defun gnus-summary-reparent-children (parent children)
10879   "Make PARENT the parent of CHILDREN.
10880 When called interactively, PARENT is is current article and
10881 CHILDREN are the process-marked articles."
10882   (interactive
10883    (list (gnus-summary-article-number)
10884          (gnus-summary-work-articles nil)))
10885   (dolist (child children)
10886     (save-window-excursion
10887       (let ((gnus-article-buffer " *reparent*"))
10888         (unless (not (eq parent child))
10889           (error "An article may not be self-referential"))
10890         (let ((message-id (mail-header-id
10891                            (gnus-summary-article-header parent))))
10892           (unless (and message-id (not (equal message-id "")))
10893             (error "No message-id in desired parent"))
10894           (gnus-with-article child
10895             (save-restriction
10896               (goto-char (point-min))
10897               (message-narrow-to-head)
10898               (if (re-search-forward "^References: " nil t)
10899                   (progn
10900                     (re-search-forward "^[^ \t]" nil t)
10901                     (forward-line -1)
10902                     (end-of-line)
10903                     (insert " " message-id))
10904                 (insert "References: " message-id "\n"))))
10905           (set-buffer gnus-summary-buffer)
10906           (gnus-summary-unmark-all-processable)
10907           (gnus-summary-update-article child)
10908           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10909             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10910           (gnus-summary-rethread-current)
10911           (gnus-message 3 "Article %d is now the child of article %d"
10912                         child parent))))))
10913
10914 (defun gnus-summary-toggle-threads (&optional arg)
10915   "Toggle showing conversation threads.
10916 If ARG is positive number, turn showing conversation threads on."
10917   (interactive "P")
10918   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10919     (setq gnus-show-threads
10920           (if (null arg) (not gnus-show-threads)
10921             (> (prefix-numeric-value arg) 0)))
10922     (gnus-summary-prepare)
10923     (gnus-summary-goto-subject current)
10924     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10925     (gnus-summary-position-point)))
10926
10927 (defun gnus-summary-show-all-threads ()
10928   "Show all threads."
10929   (interactive)
10930   (save-excursion
10931     (let ((buffer-read-only nil))
10932       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10933   (gnus-summary-position-point))
10934
10935 (defun gnus-summary-show-thread ()
10936   "Show thread subtrees.
10937 Returns nil if no thread was there to be shown."
10938   (interactive)
10939   (let ((buffer-read-only nil)
10940         (orig (point))
10941         (end (point-at-eol))
10942         ;; Leave point at bol
10943         (beg (progn (beginning-of-line) (point))))
10944     (prog1
10945         ;; Any hidden lines here?
10946         (search-forward "\r" end t)
10947       (subst-char-in-region beg end ?\^M ?\n t)
10948       (goto-char orig)
10949       (gnus-summary-position-point))))
10950
10951 (defun gnus-summary-maybe-hide-threads ()
10952   "If requested, hide the threads that should be hidden."
10953   (when (and gnus-show-threads
10954              gnus-thread-hide-subtree)
10955     (gnus-summary-hide-all-threads
10956      (if (or (consp gnus-thread-hide-subtree)
10957              (functionp gnus-thread-hide-subtree))
10958          (gnus-make-predicate gnus-thread-hide-subtree)
10959        nil))))
10960
10961 ;;; Hiding predicates.
10962
10963 (defun gnus-article-unread-p (header)
10964   (memq (mail-header-number header) gnus-newsgroup-unreads))
10965
10966 (defun gnus-article-unseen-p (header)
10967   (memq (mail-header-number header) gnus-newsgroup-unseen))
10968
10969 (defun gnus-map-articles (predicate articles)
10970   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10971   (apply 'gnus-or (mapcar predicate
10972                           (mapcar (lambda (number)
10973                                     (gnus-summary-article-header number))
10974                                   articles))))
10975
10976 (defun gnus-summary-hide-all-threads (&optional predicate)
10977   "Hide all thread subtrees.
10978 If PREDICATE is supplied, threads that satisfy this predicate
10979 will not be hidden."
10980   (interactive)
10981   (save-excursion
10982     (goto-char (point-min))
10983     (let ((end nil))
10984       (while (not end)
10985         (when (or (not predicate)
10986                   (gnus-map-articles
10987                    predicate (gnus-summary-article-children)))
10988             (gnus-summary-hide-thread))
10989         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10990   (gnus-summary-position-point))
10991
10992 (defun gnus-summary-hide-thread ()
10993   "Hide thread subtrees.
10994 If PREDICATE is supplied, threads that satisfy this predicate
10995 will not be hidden.
10996 Returns nil if no threads were there to be hidden."
10997   (interactive)
10998   (let ((buffer-read-only nil)
10999         (start (point))
11000         (article (gnus-summary-article-number)))
11001     (goto-char start)
11002     ;; Go forward until either the buffer ends or the subthread
11003     ;; ends.
11004     (when (and (not (eobp))
11005                (or (zerop (gnus-summary-next-thread 1 t))
11006                    (goto-char (point-max))))
11007       (prog1
11008           (if (and (> (point) start)
11009                    (search-backward "\n" start t))
11010               (progn
11011                 (subst-char-in-region start (point) ?\n ?\^M)
11012                 (gnus-summary-goto-subject article))
11013             (goto-char start)
11014             nil)))))
11015
11016 (defun gnus-summary-go-to-next-thread (&optional previous)
11017   "Go to the same level (or less) next thread.
11018 If PREVIOUS is non-nil, go to previous thread instead.
11019 Return the article number moved to, or nil if moving was impossible."
11020   (let ((level (gnus-summary-thread-level))
11021         (way (if previous -1 1))
11022         (beg (point)))
11023     (forward-line way)
11024     (while (and (not (eobp))
11025                 (< level (gnus-summary-thread-level)))
11026       (forward-line way))
11027     (if (eobp)
11028         (progn
11029           (goto-char beg)
11030           nil)
11031       (setq beg (point))
11032       (prog1
11033           (gnus-summary-article-number)
11034         (goto-char beg)))))
11035
11036 (defun gnus-summary-next-thread (n &optional silent)
11037   "Go to the same level next N'th thread.
11038 If N is negative, search backward instead.
11039 Returns the difference between N and the number of skips actually
11040 done.
11041
11042 If SILENT, don't output messages."
11043   (interactive "p")
11044   (let ((backward (< n 0))
11045         (n (abs n)))
11046     (while (and (> n 0)
11047                 (gnus-summary-go-to-next-thread backward))
11048       (decf n))
11049     (unless silent
11050       (gnus-summary-position-point))
11051     (when (and (not silent) (/= 0 n))
11052       (gnus-message 7 "No more threads"))
11053     n))
11054
11055 (defun gnus-summary-prev-thread (n)
11056   "Go to the same level previous N'th thread.
11057 Returns the difference between N and the number of skips actually
11058 done."
11059   (interactive "p")
11060   (gnus-summary-next-thread (- n)))
11061
11062 (defun gnus-summary-go-down-thread ()
11063   "Go down one level in the current thread."
11064   (let ((children (gnus-summary-article-children)))
11065     (when children
11066       (gnus-summary-goto-subject (car children)))))
11067
11068 (defun gnus-summary-go-up-thread ()
11069   "Go up one level in the current thread."
11070   (let ((parent (gnus-summary-article-parent)))
11071     (when parent
11072       (gnus-summary-goto-subject parent))))
11073
11074 (defun gnus-summary-down-thread (n)
11075   "Go down thread N steps.
11076 If N is negative, go up instead.
11077 Returns the difference between N and how many steps down that were
11078 taken."
11079   (interactive "p")
11080   (let ((up (< n 0))
11081         (n (abs n)))
11082     (while (and (> n 0)
11083                 (if up (gnus-summary-go-up-thread)
11084                   (gnus-summary-go-down-thread)))
11085       (setq n (1- n)))
11086     (gnus-summary-position-point)
11087     (when (/= 0 n)
11088       (gnus-message 7 "Can't go further"))
11089     n))
11090
11091 (defun gnus-summary-up-thread (n)
11092   "Go up thread N steps.
11093 If N is negative, go down instead.
11094 Returns the difference between N and how many steps down that were
11095 taken."
11096   (interactive "p")
11097   (gnus-summary-down-thread (- n)))
11098
11099 (defun gnus-summary-top-thread ()
11100   "Go to the top of the thread."
11101   (interactive)
11102   (while (gnus-summary-go-up-thread))
11103   (gnus-summary-article-number))
11104
11105 (defun gnus-summary-kill-thread (&optional unmark)
11106   "Mark articles under current thread as read.
11107 If the prefix argument is positive, remove any kinds of marks.
11108 If the prefix argument is negative, tick articles instead."
11109   (interactive "P")
11110   (when unmark
11111     (setq unmark (prefix-numeric-value unmark)))
11112   (let ((articles (gnus-summary-articles-in-thread)))
11113     (save-excursion
11114       ;; Expand the thread.
11115       (gnus-summary-show-thread)
11116       ;; Mark all the articles.
11117       (while articles
11118         (gnus-summary-goto-subject (car articles))
11119         (cond ((null unmark)
11120                (gnus-summary-mark-article-as-read gnus-killed-mark))
11121               ((> unmark 0)
11122                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11123               (t
11124                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11125         (setq articles (cdr articles))))
11126     ;; Hide killed subtrees.
11127     (and (null unmark)
11128          gnus-thread-hide-killed
11129          (gnus-summary-hide-thread))
11130     ;; If marked as read, go to next unread subject.
11131     (when (null unmark)
11132       ;; Go to next unread subject.
11133       (gnus-summary-next-subject 1 t)))
11134   (gnus-set-mode-line 'summary))
11135
11136 ;; Summary sorting commands
11137
11138 (defun gnus-summary-sort-by-number (&optional reverse)
11139   "Sort the summary buffer by article number.
11140 Argument REVERSE means reverse order."
11141   (interactive "P")
11142   (gnus-summary-sort 'number reverse))
11143
11144 (defun gnus-summary-sort-by-random (&optional reverse)
11145   "Randomize the order in the summary buffer.
11146 Argument REVERSE means to randomize in reverse order."
11147   (interactive "P")
11148   (gnus-summary-sort 'random reverse))
11149
11150 (defun gnus-summary-sort-by-author (&optional reverse)
11151   "Sort the summary buffer by author name alphabetically.
11152 If `case-fold-search' is non-nil, case of letters is ignored.
11153 Argument REVERSE means reverse order."
11154   (interactive "P")
11155   (gnus-summary-sort 'author reverse))
11156
11157 (defun gnus-summary-sort-by-recipient (&optional reverse)
11158   "Sort the summary buffer by recipient name alphabetically.
11159 If `case-fold-search' is non-nil, case of letters is ignored.
11160 Argument REVERSE means reverse order."
11161   (interactive "P")
11162   (gnus-summary-sort 'recipient reverse))
11163
11164 (defun gnus-summary-sort-by-subject (&optional reverse)
11165   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11166 If `case-fold-search' is non-nil, case of letters is ignored.
11167 Argument REVERSE means reverse order."
11168   (interactive "P")
11169   (gnus-summary-sort 'subject reverse))
11170
11171 (defun gnus-summary-sort-by-date (&optional reverse)
11172   "Sort the summary buffer by date.
11173 Argument REVERSE means reverse order."
11174   (interactive "P")
11175   (gnus-summary-sort 'date reverse))
11176
11177 (defun gnus-summary-sort-by-score (&optional reverse)
11178   "Sort the summary buffer by score.
11179 Argument REVERSE means reverse order."
11180   (interactive "P")
11181   (gnus-summary-sort 'score reverse))
11182
11183 (defun gnus-summary-sort-by-lines (&optional reverse)
11184   "Sort the summary buffer by the number of lines.
11185 Argument REVERSE means reverse order."
11186   (interactive "P")
11187   (gnus-summary-sort 'lines reverse))
11188
11189 (defun gnus-summary-sort-by-chars (&optional reverse)
11190   "Sort the summary buffer by article length.
11191 Argument REVERSE means reverse order."
11192   (interactive "P")
11193   (gnus-summary-sort 'chars reverse))
11194
11195 (defun gnus-summary-sort-by-original (&optional reverse)
11196   "Sort the summary buffer using the default sorting method.
11197 Argument REVERSE means reverse order."
11198   (interactive "P")
11199   (let* ((buffer-read-only)
11200          (gnus-summary-prepare-hook nil))
11201     ;; We do the sorting by regenerating the threads.
11202     (gnus-summary-prepare)
11203     ;; Hide subthreads if needed.
11204     (gnus-summary-maybe-hide-threads)))
11205
11206 (defun gnus-summary-sort (predicate reverse)
11207   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11208   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11209          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11210          (gnus-thread-sort-functions
11211           (if (not reverse)
11212               thread
11213             `(lambda (t1 t2)
11214                (,thread t2 t1))))
11215          (gnus-sort-gathered-threads-function
11216           gnus-thread-sort-functions)
11217          (gnus-article-sort-functions
11218           (if (not reverse)
11219               article
11220             `(lambda (t1 t2)
11221                (,article t2 t1))))
11222          (buffer-read-only)
11223          (gnus-summary-prepare-hook nil))
11224     ;; We do the sorting by regenerating the threads.
11225     (gnus-summary-prepare)
11226     ;; Hide subthreads if needed.
11227     (gnus-summary-maybe-hide-threads)))
11228
11229 ;; Summary saving commands.
11230
11231 (defcustom gnus-summary-save-article-coding-system nil
11232   "Coding system used to save a decoded article to a file.
11233 This is used when the `gnus-summary-write-article-file' command is run.
11234 The recommended coding systems include `utf-8', `iso-2022-7bit', and so
11235 forth.  Note that buttonized MIME parts will be lost in a saved file.
11236 If it is nil, raw articles will be saved."
11237   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
11238                  (const :tag "Save raw articles" nil)
11239                  (const :tag "UTF-8" utf-8)
11240                  (const :tag "iso-2022-7bit" iso-2022-7bit)
11241                  (const :tag "Emacs internal" emacs-mule)
11242                  (symbol :tag "Coding system"))
11243   :group 'gnus-article-saving)
11244
11245 (defun gnus-summary-save-article (&optional n not-saved decode)
11246   "Save the current article using the default saver function.
11247 If N is a positive number, save the N next articles.
11248 If N is a negative number, save the N previous articles.
11249 If N is nil and any articles have been marked with the process mark,
11250 save those articles instead.
11251 The variable `gnus-default-article-saver' specifies the saver function."
11252   (interactive "P")
11253   (unless gnus-summary-save-article-coding-system
11254     (setq decode nil))
11255   (let* ((articles (gnus-summary-work-articles n))
11256          (save-buffer (save-excursion
11257                         (nnheader-set-temp-buffer " *Gnus Save*")))
11258          (num (length articles))
11259          header file)
11260     (dolist (article articles)
11261       (setq header (gnus-summary-article-header article))
11262       (if (not (vectorp header))
11263           ;; This is a pseudo-article.
11264           (if (assq 'name header)
11265               (gnus-copy-file (cdr (assq 'name header)))
11266             (gnus-message 1 "Article %d is unsaveable" article))
11267         ;; This is a real article.
11268         (save-window-excursion
11269           (let ((gnus-display-mime-function (when decode
11270                                               gnus-display-mime-function))
11271                 (gnus-article-prepare-hook (when decode
11272                                              gnus-article-prepare-hook)))
11273             (gnus-summary-select-article t nil nil article)))
11274         (save-excursion
11275           (set-buffer save-buffer)
11276           (erase-buffer)
11277           (if decode
11278               (progn
11279                 (insert "X-Coding-System: -*- coding: "
11280                         (symbol-name gnus-summary-save-article-coding-system)
11281                         "; -*-\n")
11282                 (insert-buffer-substring gnus-article-buffer))
11283             (insert-buffer-substring gnus-original-article-buffer)))
11284         (let ((mm-text-coding-system-for-write
11285                (if decode
11286                    gnus-summary-save-article-coding-system
11287                  mm-text-coding-system-for-write)))
11288           (setq file (gnus-article-save save-buffer file num)))
11289         (gnus-summary-remove-process-mark article)
11290         (unless not-saved
11291           (gnus-summary-set-saved-mark article))))
11292     (gnus-kill-buffer save-buffer)
11293     (gnus-summary-position-point)
11294     (gnus-set-mode-line 'summary)
11295     n))
11296
11297 (defun gnus-summary-pipe-output (&optional arg headers)
11298   "Pipe the current article to a subprocess.
11299 If N is a positive number, pipe the N next articles.
11300 If N is a negative number, pipe the N previous articles.
11301 If N is nil and any articles have been marked with the process mark,
11302 pipe those articles instead.
11303 If HEADERS (the symbolic prefix), include the headers, too."
11304   (interactive (gnus-interactive "P\ny"))
11305   (require 'gnus-art)
11306   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11307         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11308     (gnus-summary-save-article arg t))
11309   (let ((buffer (get-buffer "*Shell Command Output*")))
11310     (when (and buffer
11311                (not (zerop (buffer-size buffer))))
11312       (gnus-configure-windows 'pipe))))
11313
11314 (defun gnus-summary-save-article-mail (&optional arg)
11315   "Append the current article to a Unix mail box file.
11316 If N is a positive number, save the N next articles.
11317 If N is a negative number, save the N previous articles.
11318 If N is nil and any articles have been marked with the process mark,
11319 save those articles instead."
11320   (interactive "P")
11321   (require 'gnus-art)
11322   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11323     (gnus-summary-save-article arg)))
11324
11325 (defun gnus-summary-save-article-rmail (&optional arg)
11326   "Append the current article to an rmail file.
11327 If N is a positive number, save the N next articles.
11328 If N is a negative number, save the N previous articles.
11329 If N is nil and any articles have been marked with the process mark,
11330 save those articles instead."
11331   (interactive "P")
11332   (require 'gnus-art)
11333   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11334     (gnus-summary-save-article arg)))
11335
11336 (defun gnus-summary-save-article-file (&optional arg)
11337   "Append the current article to a file.
11338 If N is a positive number, save the N next articles.
11339 If N is a negative number, save the N previous articles.
11340 If N is nil and any articles have been marked with the process mark,
11341 save those articles instead."
11342   (interactive "P")
11343   (require 'gnus-art)
11344   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11345     (gnus-summary-save-article arg)))
11346
11347 (defun gnus-summary-write-article-file (&optional arg)
11348   "Write the current article to a file, deleting the previous file.
11349 If N is a positive number, save the N next articles.
11350 If N is a negative number, save the N previous articles.
11351 If N is nil and any articles have been marked with the process mark,
11352 save those articles instead."
11353   (interactive "P")
11354   (require 'gnus-art)
11355   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11356     (gnus-summary-save-article arg nil t)))
11357
11358 (defun gnus-summary-save-article-body-file (&optional arg)
11359   "Append the current article body to a file.
11360 If N is a positive number, save the N next articles.
11361 If N is a negative number, save the N previous articles.
11362 If N is nil and any articles have been marked with the process mark,
11363 save those articles instead."
11364   (interactive "P")
11365   (require 'gnus-art)
11366   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11367     (gnus-summary-save-article arg)))
11368
11369 (defun gnus-summary-muttprint (&optional arg)
11370   "Print the current article using Muttprint.
11371 If N is a positive number, save the N next articles.
11372 If N is a negative number, save the N previous articles.
11373 If N is nil and any articles have been marked with the process mark,
11374 save those articles instead."
11375   (interactive "P")
11376   (require 'gnus-art)
11377   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11378     (gnus-summary-save-article arg t)))
11379
11380 (defun gnus-summary-pipe-message (program)
11381   "Pipe the current article through PROGRAM."
11382   (interactive "sProgram: ")
11383   (gnus-summary-select-article)
11384   (let ((mail-header-separator ""))
11385     (gnus-eval-in-buffer-window gnus-article-buffer
11386       (save-restriction
11387         (widen)
11388         (let ((start (window-start))
11389               buffer-read-only)
11390           (message-pipe-buffer-body program)
11391           (set-window-start (get-buffer-window (current-buffer)) start))))))
11392
11393 (defun gnus-get-split-value (methods)
11394   "Return a value based on the split METHODS."
11395   (let (split-name method result match)
11396     (when methods
11397       (save-excursion
11398         (set-buffer gnus-original-article-buffer)
11399         (save-restriction
11400           (nnheader-narrow-to-headers)
11401           (while (and methods (not split-name))
11402             (goto-char (point-min))
11403             (setq method (pop methods))
11404             (setq match (car method))
11405             (when (cond
11406                    ((stringp match)
11407                     ;; Regular expression.
11408                     (ignore-errors
11409                       (re-search-forward match nil t)))
11410                    ((functionp match)
11411                     ;; Function.
11412                     (save-restriction
11413                       (widen)
11414                       (setq result (funcall match gnus-newsgroup-name))))
11415                    ((consp match)
11416                     ;; Form.
11417                     (save-restriction
11418                       (widen)
11419                       (setq result (eval match)))))
11420               (setq split-name (cdr method))
11421               (cond ((stringp result)
11422                      (push (expand-file-name
11423                             result gnus-article-save-directory)
11424                            split-name))
11425                     ((consp result)
11426                      (setq split-name (append result split-name)))))))))
11427     (nreverse split-name)))
11428
11429 (defun gnus-valid-move-group-p (group)
11430   (and (boundp group)
11431        (symbol-name group)
11432        (symbol-value group)
11433        (gnus-get-function (gnus-find-method-for-group
11434                            (symbol-name group)) 'request-accept-article t)))
11435
11436 (defun gnus-read-move-group-name (prompt default articles prefix)
11437   "Read a group name."
11438   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11439          (minibuffer-confirm-incomplete nil) ; XEmacs
11440          (prom
11441           (format "%s %s to"
11442                   prompt
11443                   (if (> (length articles) 1)
11444                       (format "these %d articles" (length articles))
11445                     "this article")))
11446          (to-newsgroup
11447           (cond
11448            ((null split-name)
11449             (gnus-completing-read-with-default
11450              default prom
11451              gnus-active-hashtb
11452              'gnus-valid-move-group-p
11453              nil prefix
11454              'gnus-group-history))
11455            ((= 1 (length split-name))
11456             (gnus-completing-read-with-default
11457              (car split-name) prom
11458              gnus-active-hashtb
11459              'gnus-valid-move-group-p
11460              nil nil
11461              'gnus-group-history))
11462            (t
11463             (gnus-completing-read-with-default
11464              nil prom
11465              (mapcar 'list (nreverse split-name))
11466              nil nil nil
11467              'gnus-group-history))))
11468          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11469     (when to-newsgroup
11470       (if (or (string= to-newsgroup "")
11471               (string= to-newsgroup prefix))
11472           (setq to-newsgroup default))
11473       (unless to-newsgroup
11474         (error "No group name entered"))
11475       (or (gnus-active to-newsgroup)
11476           (gnus-activate-group to-newsgroup nil nil to-method)
11477           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11478                                      to-newsgroup))
11479               (or (and (gnus-request-create-group to-newsgroup to-method)
11480                        (gnus-activate-group
11481                         to-newsgroup nil nil to-method)
11482                        (gnus-subscribe-group to-newsgroup))
11483                   (error "Couldn't create group %s" to-newsgroup)))
11484           (error "No such group: %s" to-newsgroup)))
11485     to-newsgroup))
11486
11487 (defvar gnus-summary-save-parts-counter)
11488
11489 (defun gnus-summary-save-parts (type dir n &optional reverse)
11490   "Save parts matching TYPE to DIR.
11491 If REVERSE, save parts that do not match TYPE."
11492   (interactive
11493    (list (read-string "Save parts of type: "
11494                       (or (car gnus-summary-save-parts-type-history)
11495                           gnus-summary-save-parts-default-mime)
11496                       'gnus-summary-save-parts-type-history)
11497          (setq gnus-summary-save-parts-last-directory
11498                (read-file-name "Save to directory: "
11499                                gnus-summary-save-parts-last-directory
11500                                nil t))
11501          current-prefix-arg))
11502   (gnus-summary-iterate n
11503     (let ((gnus-display-mime-function nil)
11504           (gnus-inhibit-treatment t))
11505       (gnus-summary-select-article))
11506     (save-excursion
11507       (set-buffer gnus-article-buffer)
11508       (let ((handles (or gnus-article-mime-handles
11509                          (mm-dissect-buffer nil gnus-article-loose-mime)
11510                          (and gnus-article-emulate-mime
11511                               (mm-uu-dissect))))
11512             (gnus-summary-save-parts-counter 1))
11513         (when handles
11514           (gnus-summary-save-parts-1 type dir handles reverse)
11515           (unless gnus-article-mime-handles ;; Don't destroy this case.
11516             (mm-destroy-parts handles)))))))
11517
11518 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11519   (if (stringp (car handle))
11520       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11521               (cdr handle))
11522     (when (if reverse
11523               (not (string-match type (mm-handle-media-type handle)))
11524             (string-match type (mm-handle-media-type handle)))
11525       (let ((file (expand-file-name
11526                    (gnus-map-function
11527                     mm-file-name-rewrite-functions
11528                     (file-name-nondirectory
11529                      (or
11530                       (mail-content-type-get
11531                        (mm-handle-disposition handle) 'filename)
11532                       (mail-content-type-get
11533                        (mm-handle-type handle) 'name)
11534                       (format "%s.%d.%d" gnus-newsgroup-name
11535                               (cdr gnus-article-current)
11536                               gnus-summary-save-parts-counter))))
11537                    dir)))
11538         (incf gnus-summary-save-parts-counter)
11539         (unless (file-exists-p file)
11540           (mm-save-part-to-file handle file))))))
11541
11542 ;; Summary extract commands
11543
11544 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11545   (let ((buffer-read-only nil)
11546         (article (gnus-summary-article-number))
11547         after-article b e)
11548     (unless (gnus-summary-goto-subject article)
11549       (error "No such article: %d" article))
11550     (gnus-summary-position-point)
11551     ;; If all commands are to be bunched up on one line, we collect
11552     ;; them here.
11553     (unless gnus-view-pseudos-separately
11554       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11555             files action)
11556         (while ps
11557           (setq action (cdr (assq 'action (car ps))))
11558           (setq files (list (cdr (assq 'name (car ps)))))
11559           (while (and ps (cdr ps)
11560                       (string= (or action "1")
11561                                (or (cdr (assq 'action (cadr ps))) "2")))
11562             (push (cdr (assq 'name (cadr ps))) files)
11563             (setcdr ps (cddr ps)))
11564           (when files
11565             (when (not (string-match "%s" action))
11566               (push " " files))
11567             (push " " files)
11568             (when (assq 'execute (car ps))
11569               (setcdr (assq 'execute (car ps))
11570                       (funcall (if (string-match "%s" action)
11571                                    'format 'concat)
11572                                action
11573                                (mapconcat
11574                                 (lambda (f)
11575                                   (if (equal f " ")
11576                                       f
11577                                     (shell-quote-argument f)))
11578                                 files " ")))))
11579           (setq ps (cdr ps)))))
11580     (if (and gnus-view-pseudos (not not-view))
11581         (while pslist
11582           (when (assq 'execute (car pslist))
11583             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11584                                   (eq gnus-view-pseudos 'not-confirm)))
11585           (setq pslist (cdr pslist)))
11586       (save-excursion
11587         (while pslist
11588           (setq after-article (or (cdr (assq 'article (car pslist)))
11589                                   (gnus-summary-article-number)))
11590           (gnus-summary-goto-subject after-article)
11591           (forward-line 1)
11592           (setq b (point))
11593           (insert "    " (file-name-nondirectory
11594                           (cdr (assq 'name (car pslist))))
11595                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11596           (setq e (point))
11597           (forward-line -1)             ; back to `b'
11598           (gnus-add-text-properties
11599            b (1- e) (list 'gnus-number gnus-reffed-article-number
11600                           gnus-mouse-face-prop gnus-mouse-face))
11601           (gnus-data-enter
11602            after-article gnus-reffed-article-number
11603            gnus-unread-mark b (car pslist) 0 (- e b))
11604           (setq gnus-newsgroup-unreads
11605                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11606                                          gnus-reffed-article-number))
11607           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11608           (setq pslist (cdr pslist)))))))
11609
11610 (defun gnus-pseudos< (p1 p2)
11611   (let ((c1 (cdr (assq 'action p1)))
11612         (c2 (cdr (assq 'action p2))))
11613     (and c1 c2 (string< c1 c2))))
11614
11615 (defun gnus-request-pseudo-article (props)
11616   (cond ((assq 'execute props)
11617          (gnus-execute-command (cdr (assq 'execute props)))))
11618   (let ((gnus-current-article (gnus-summary-article-number)))
11619     (gnus-run-hooks 'gnus-mark-article-hook)))
11620
11621 (defun gnus-execute-command (command &optional automatic)
11622   (save-excursion
11623     (gnus-article-setup-buffer)
11624     (set-buffer gnus-article-buffer)
11625     (setq buffer-read-only nil)
11626     (let ((command (if automatic command
11627                      (read-string "Command: " (cons command 0)))))
11628       (erase-buffer)
11629       (insert "$ " command "\n\n")
11630       (if gnus-view-pseudo-asynchronously
11631           (start-process "gnus-execute" (current-buffer) shell-file-name
11632                          shell-command-switch command)
11633         (call-process shell-file-name nil t nil
11634                       shell-command-switch command)))))
11635
11636 ;; Summary kill commands.
11637
11638 (defun gnus-summary-edit-global-kill (article)
11639   "Edit the \"global\" kill file."
11640   (interactive (list (gnus-summary-article-number)))
11641   (gnus-group-edit-global-kill article))
11642
11643 (defun gnus-summary-edit-local-kill ()
11644   "Edit a local kill file applied to the current newsgroup."
11645   (interactive)
11646   (setq gnus-current-headers (gnus-summary-article-header))
11647   (gnus-group-edit-local-kill
11648    (gnus-summary-article-number) gnus-newsgroup-name))
11649
11650 ;;; Header reading.
11651
11652 (defun gnus-read-header (id &optional header)
11653   "Read the headers of article ID and enter them into the Gnus system."
11654   (let ((group gnus-newsgroup-name)
11655         (gnus-override-method
11656          (or
11657           gnus-override-method
11658           (and (gnus-news-group-p gnus-newsgroup-name)
11659                (car (gnus-refer-article-methods)))))
11660         where)
11661     ;; First we check to see whether the header in question is already
11662     ;; fetched.
11663     (if (stringp id)
11664         ;; This is a Message-ID.
11665         (setq header (or header (gnus-id-to-header id)))
11666       ;; This is an article number.
11667       (setq header (or header (gnus-summary-article-header id))))
11668     (if (and header
11669              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11670         ;; We have found the header.
11671         header
11672       ;; We have to really fetch the header to this article.
11673       (save-excursion
11674         (set-buffer nntp-server-buffer)
11675         (when (setq where (gnus-request-head id group))
11676           (nnheader-fold-continuation-lines)
11677           (goto-char (point-max))
11678           (insert ".\n")
11679           (goto-char (point-min))
11680           (insert "211 ")
11681           (princ (cond
11682                   ((numberp id) id)
11683                   ((cdr where) (cdr where))
11684                   (header (mail-header-number header))
11685                   (t gnus-reffed-article-number))
11686                  (current-buffer))
11687           (insert " Article retrieved.\n"))
11688         (if (or (not where)
11689                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11690             ()                          ; Malformed head.
11691           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11692             (when (and (stringp id)
11693                        (or
11694                         (not (string= (gnus-group-real-name group)
11695                                       (car where)))
11696                         (not (gnus-server-equal gnus-override-method
11697                                                 (gnus-group-method group)))))
11698               ;; If we fetched by Message-ID and the article came from
11699               ;; a different group (or server), we fudge some bogus
11700               ;; article numbers for this article.
11701               (mail-header-set-number header gnus-reffed-article-number))
11702             (save-excursion
11703               (set-buffer gnus-summary-buffer)
11704               (decf gnus-reffed-article-number)
11705               (gnus-remove-header (mail-header-number header))
11706               (push header gnus-newsgroup-headers)
11707               (setq gnus-current-headers header)
11708               (push (mail-header-number header) gnus-newsgroup-limit)))
11709           header)))))
11710
11711 (defun gnus-remove-header (number)
11712   "Remove header NUMBER from `gnus-newsgroup-headers'."
11713   (if (and gnus-newsgroup-headers
11714            (= number (mail-header-number (car gnus-newsgroup-headers))))
11715       (pop gnus-newsgroup-headers)
11716     (let ((headers gnus-newsgroup-headers))
11717       (while (and (cdr headers)
11718                   (not (= number (mail-header-number (cadr headers)))))
11719         (pop headers))
11720       (when (cdr headers)
11721         (setcdr headers (cddr headers))))))
11722
11723 ;;;
11724 ;;; summary highlights
11725 ;;;
11726
11727 (defun gnus-highlight-selected-summary ()
11728   "Highlight selected article in summary buffer."
11729   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11730   (when gnus-summary-selected-face
11731     (save-excursion
11732       (let* ((beg (point-at-bol))
11733              (end (point-at-eol))
11734              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11735              (from (if (get-text-property beg gnus-mouse-face-prop)
11736                        beg
11737                      (or (next-single-property-change
11738                           beg gnus-mouse-face-prop nil end)
11739                          beg)))
11740              (to
11741               (if (= from end)
11742                   (- from 2)
11743                 (or (next-single-property-change
11744                      from gnus-mouse-face-prop nil end)
11745                     end))))
11746         ;; If no mouse-face prop on line we will have to = from = end,
11747         ;; so we highlight the entire line instead.
11748         (when (= (+ to 2) from)
11749           (setq from beg)
11750           (setq to end))
11751         (if gnus-newsgroup-selected-overlay
11752             ;; Move old overlay.
11753             (gnus-move-overlay
11754              gnus-newsgroup-selected-overlay from to (current-buffer))
11755           ;; Create new overlay.
11756           (gnus-overlay-put
11757            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11758            'face gnus-summary-selected-face))))))
11759
11760 (defvar gnus-summary-highlight-line-cached nil)
11761 (defvar gnus-summary-highlight-line-trigger nil)
11762
11763 (defun gnus-summary-highlight-line-0 ()
11764   (if (and (eq gnus-summary-highlight-line-trigger
11765                gnus-summary-highlight)
11766            gnus-summary-highlight-line-cached)
11767       gnus-summary-highlight-line-cached
11768     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11769           gnus-summary-highlight-line-cached
11770           (let* ((cond (list 'cond))
11771                  (c cond)
11772                  (list gnus-summary-highlight))
11773             (while list
11774               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11775                               nil))
11776               (setq c (cdr c)
11777                     list (cdr list)))
11778             (gnus-byte-compile (list 'lambda nil cond))))))
11779
11780 (defun gnus-summary-highlight-line ()
11781   "Highlight current line according to `gnus-summary-highlight'."
11782   (let* ((beg (point-at-bol))
11783          (article (or (gnus-summary-article-number) gnus-current-article))
11784          (score (or (cdr (assq article
11785                                gnus-newsgroup-scored))
11786                     gnus-summary-default-score 0))
11787          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11788          (inhibit-read-only t)
11789          (default gnus-summary-default-score)
11790          (default-high gnus-summary-default-high-score)
11791          (default-low gnus-summary-default-low-score)
11792          (uncached (and gnus-summary-use-undownloaded-faces
11793                         (memq article gnus-newsgroup-undownloaded)
11794                         (not (memq article gnus-newsgroup-cached)))))
11795     (let ((face (funcall (gnus-summary-highlight-line-0))))
11796       (unless (eq face (get-text-property beg 'face))
11797         (gnus-put-text-property-excluding-characters-with-faces
11798          beg (point-at-eol) 'face
11799          (setq face (if (boundp face) (symbol-value face) face)))
11800         (when gnus-summary-highlight-line-function
11801           (funcall gnus-summary-highlight-line-function article face))))))
11802
11803 (defun gnus-update-read-articles (group unread &optional compute)
11804   "Update the list of read articles in GROUP.
11805 UNREAD is a sorted list."
11806   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11807         (info (gnus-get-info group))
11808         (prev 1)
11809         read)
11810     (if (or (not info) (not active))
11811         ;; There is no info on this group if it was, in fact,
11812         ;; killed.  Gnus stores no information on killed groups, so
11813         ;; there's nothing to be done.
11814         ;; One could store the information somewhere temporarily,
11815         ;; perhaps...  Hmmm...
11816         ()
11817       ;; Remove any negative articles numbers.
11818       (while (and unread (< (car unread) 0))
11819         (setq unread (cdr unread)))
11820       ;; Remove any expired article numbers
11821       (while (and unread (< (car unread) (car active)))
11822         (setq unread (cdr unread)))
11823       ;; Compute the ranges of read articles by looking at the list of
11824       ;; unread articles.
11825       (while unread
11826         (when (/= (car unread) prev)
11827           (push (if (= prev (1- (car unread))) prev
11828                   (cons prev (1- (car unread))))
11829                 read))
11830         (setq prev (1+ (car unread)))
11831         (setq unread (cdr unread)))
11832       (when (<= prev (cdr active))
11833         (push (cons prev (cdr active)) read))
11834       (setq read (if (> (length read) 1) (nreverse read) read))
11835       (if compute
11836           read
11837         (save-excursion
11838           (let (setmarkundo)
11839             ;; Propagate the read marks to the backend.
11840             (when (gnus-check-backend-function 'request-set-mark group)
11841               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11842                     (add (gnus-remove-from-range read (gnus-info-read info))))
11843                 (when (or add del)
11844                   (unless (gnus-check-group group)
11845                     (error "Can't open server for %s" group))
11846                   (gnus-request-set-mark
11847                    group (delq nil (list (if add (list add 'add '(read)))
11848                                          (if del (list del 'del '(read))))))
11849                   (setq setmarkundo
11850                         `(gnus-request-set-mark
11851                           ,group
11852                           ',(delq nil (list
11853                                        (if del (list del 'add '(read)))
11854                                        (if add (list add 'del '(read))))))))))
11855             (set-buffer gnus-group-buffer)
11856             (gnus-undo-register
11857               `(progn
11858                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11859                  (gnus-info-set-read ',info ',(gnus-info-read info))
11860                  (gnus-get-unread-articles-in-group ',info
11861                                                     (gnus-active ,group))
11862                  (gnus-group-update-group ,group t)
11863                  ,setmarkundo))))
11864         ;; Enter this list into the group info.
11865         (gnus-info-set-read info read)
11866         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11867         (gnus-get-unread-articles-in-group info (gnus-active group))
11868         t))))
11869
11870 (defun gnus-offer-save-summaries ()
11871   "Offer to save all active summary buffers."
11872   (let (buffers)
11873     ;; Go through all buffers and find all summaries.
11874     (dolist (buffer (buffer-list))
11875       (when (and (setq buffer (buffer-name buffer))
11876                  (string-match "Summary" buffer)
11877                  (with-current-buffer buffer
11878                    ;; We check that this is, indeed, a summary buffer.
11879                    (and (eq major-mode 'gnus-summary-mode)
11880                         ;; Also make sure this isn't bogus.
11881                         gnus-newsgroup-prepared
11882                         ;; Also make sure that this isn't a
11883                         ;; dead summary buffer.
11884                         (not gnus-dead-summary-mode))))
11885         (push buffer buffers)))
11886     ;; Go through all these summary buffers and offer to save them.
11887     (when buffers
11888       (save-excursion
11889         (map-y-or-n-p
11890          "Update summary buffer %s? "
11891          (lambda (buf)
11892            (switch-to-buffer buf)
11893            (gnus-summary-exit))
11894          buffers)))))
11895
11896 (defun gnus-summary-setup-default-charset ()
11897   "Setup newsgroup default charset."
11898   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11899       (setq gnus-newsgroup-charset nil)
11900     (let* ((ignored-charsets
11901             (or gnus-newsgroup-ephemeral-ignored-charsets
11902                 (append
11903                  (and gnus-newsgroup-name
11904                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11905                  gnus-newsgroup-ignored-charsets))))
11906       (setq gnus-newsgroup-charset
11907             (or gnus-newsgroup-ephemeral-charset
11908                 (and gnus-newsgroup-name
11909                      (gnus-parameter-charset gnus-newsgroup-name))
11910                 gnus-default-charset))
11911       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11912            ignored-charsets))))
11913
11914 ;;;
11915 ;;; Mime Commands
11916 ;;;
11917
11918 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11919   "Display the current article buffer fully MIME-buttonized.
11920 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11921 treated as multipart/mixed."
11922   (interactive "P")
11923   (require 'gnus-art)
11924   (let ((gnus-unbuttonized-mime-types nil)
11925         (gnus-mime-display-multipart-as-mixed show-all-parts))
11926     (gnus-summary-show-article)))
11927
11928 (defun gnus-summary-repair-multipart (article)
11929   "Add a Content-Type header to a multipart article without one."
11930   (interactive (list (gnus-summary-article-number)))
11931   (gnus-with-article article
11932     (message-narrow-to-head)
11933     (message-remove-header "Mime-Version")
11934     (goto-char (point-max))
11935     (insert "Mime-Version: 1.0\n")
11936     (widen)
11937     (when (search-forward "\n--" nil t)
11938       (let ((separator (buffer-substring (point) (point-at-eol))))
11939         (message-narrow-to-head)
11940         (message-remove-header "Content-Type")
11941         (goto-char (point-max))
11942         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11943                         separator))
11944         (widen))))
11945   (let (gnus-mark-article-hook)
11946     (gnus-summary-select-article t t nil article)))
11947
11948 (defun gnus-summary-toggle-display-buttonized ()
11949   "Toggle the buttonizing of the article buffer."
11950   (interactive)
11951   (require 'gnus-art)
11952   (if (setq gnus-inhibit-mime-unbuttonizing
11953             (not gnus-inhibit-mime-unbuttonizing))
11954       (let ((gnus-unbuttonized-mime-types nil))
11955         (gnus-summary-show-article))
11956     (gnus-summary-show-article)))
11957
11958 ;;;
11959 ;;; Generic summary marking commands
11960 ;;;
11961
11962 (defvar gnus-summary-marking-alist
11963   '((read gnus-del-mark "d")
11964     (unread gnus-unread-mark "u")
11965     (ticked gnus-ticked-mark "!")
11966     (dormant gnus-dormant-mark "?")
11967     (expirable gnus-expirable-mark "e"))
11968   "An alist of names/marks/keystrokes.")
11969
11970 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11971 (defvar gnus-summary-mark-map)
11972
11973 (defun gnus-summary-make-all-marking-commands ()
11974   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11975   (dolist (elem gnus-summary-marking-alist)
11976     (apply 'gnus-summary-make-marking-command elem)))
11977
11978 (defun gnus-summary-make-marking-command (name mark keystroke)
11979   (let ((map (make-sparse-keymap)))
11980     (define-key gnus-summary-generic-mark-map keystroke map)
11981     (dolist (lway `((next "next" next nil "n")
11982                     (next-unread "next unread" next t "N")
11983                     (prev "previous" prev nil "p")
11984                     (prev-unread "previous unread" prev t "P")
11985                     (nomove "" nil nil ,keystroke)))
11986       (let ((func (gnus-summary-make-marking-command-1
11987                    mark (car lway) lway name)))
11988         (setq func (eval func))
11989         (define-key map (nth 4 lway) func)))))
11990
11991 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11992   `(defun ,(intern
11993             (format "gnus-summary-put-mark-as-%s%s"
11994                     name (if (eq way 'nomove)
11995                              ""
11996                            (concat "-" (symbol-name way)))))
11997      (n)
11998      ,(format
11999        "Mark the current article as %s%s.
12000 If N, the prefix, then repeat N times.
12001 If N is negative, move in reverse order.
12002 The difference between N and the actual number of articles marked is
12003 returned."
12004        name (cadr lway))
12005      (interactive "p")
12006      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12007
12008 (defun gnus-summary-generic-mark (n mark move unread)
12009   "Mark N articles with MARK."
12010   (unless (eq major-mode 'gnus-summary-mode)
12011     (error "This command can only be used in the summary buffer"))
12012   (gnus-summary-show-thread)
12013   (let ((nummove
12014          (cond
12015           ((eq move 'next) 1)
12016           ((eq move 'prev) -1)
12017           (t 0))))
12018     (if (zerop nummove)
12019         (setq n 1)
12020       (when (< n 0)
12021         (setq n (abs n)
12022               nummove (* -1 nummove))))
12023     (while (and (> n 0)
12024                 (gnus-summary-mark-article nil mark)
12025                 (zerop (gnus-summary-next-subject nummove unread t)))
12026       (setq n (1- n)))
12027     (when (/= 0 n)
12028       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12029     (gnus-summary-recenter)
12030     (gnus-summary-position-point)
12031     (gnus-set-mode-line 'summary)
12032     n))
12033
12034 (defun gnus-summary-insert-articles (articles)
12035   (when (setq articles
12036               (gnus-sorted-difference articles
12037                                       (mapcar (lambda (h)
12038                                                 (mail-header-number h))
12039                                               gnus-newsgroup-headers)))
12040     (setq gnus-newsgroup-headers
12041           (gnus-merge 'list
12042                       gnus-newsgroup-headers
12043                       (gnus-fetch-headers articles)
12044                       'gnus-article-sort-by-number))
12045     ;; Suppress duplicates?
12046     (when gnus-suppress-duplicates
12047       (gnus-dup-suppress-articles))
12048
12049     ;; We might want to build some more threads first.
12050     (when (and gnus-fetch-old-headers
12051                (eq gnus-headers-retrieved-by 'nov))
12052       (if (eq gnus-fetch-old-headers 'invisible)
12053           (gnus-build-all-threads)
12054         (gnus-build-old-threads)))
12055     ;; Let the Gnus agent mark articles as read.
12056     (when gnus-agent
12057       (gnus-agent-get-undownloaded-list))
12058     ;; Remove list identifiers from subject
12059     (when gnus-list-identifiers
12060       (gnus-summary-remove-list-identifiers))
12061     ;; First and last article in this newsgroup.
12062     (when gnus-newsgroup-headers
12063       (setq gnus-newsgroup-begin
12064             (mail-header-number (car gnus-newsgroup-headers))
12065             gnus-newsgroup-end
12066             (mail-header-number
12067              (gnus-last-element gnus-newsgroup-headers))))
12068     (when gnus-use-scoring
12069       (gnus-possibly-score-headers))))
12070
12071 (defun gnus-summary-insert-old-articles (&optional all)
12072   "Insert all old articles in this group.
12073 If ALL is non-nil, already read articles become readable.
12074 If ALL is a number, fetch this number of articles."
12075   (interactive "P")
12076   (prog1
12077       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12078             older len)
12079         (setq older
12080               ;; Some nntp servers lie about their active range.  When
12081               ;; this happens, the active range can be in the millions.
12082               ;; Use a compressed range to avoid creating a huge list.
12083               (gnus-range-difference (list gnus-newsgroup-active) old))
12084         (setq len (gnus-range-length older))
12085         (cond
12086          ((null older) nil)
12087          ((numberp all)
12088           (if (< all len)
12089               (let ((older-range (nreverse older)))
12090                 (setq older nil)
12091
12092                 (while (> all 0)
12093                   (let* ((r (pop older-range))
12094                          (min (if (numberp r) r (car r)))
12095                          (max (if (numberp r) r (cdr r))))
12096                     (while (and (<= min max)
12097                                 (> all 0))
12098                       (push max older)
12099                       (setq all (1- all)
12100                             max (1- max))))))
12101             (setq older (gnus-uncompress-range older))))
12102          (all
12103           (setq older (gnus-uncompress-range older)))
12104          (t
12105           (when (and (numberp gnus-large-newsgroup)
12106                    (> len gnus-large-newsgroup))
12107               (let* ((cursor-in-echo-area nil)
12108                      (initial (gnus-parameter-large-newsgroup-initial
12109                                gnus-newsgroup-name))
12110                      (input
12111                       (read-string
12112                        (format
12113                         "How many articles from %s (%s %d): "
12114                         (gnus-limit-string
12115                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12116                         (if initial "max" "default")
12117                         len)
12118                        (if initial
12119                            (cons (number-to-string initial)
12120                                  0)))))
12121                 (unless (string-match "^[ \t]*$" input)
12122                   (setq all (string-to-number input))
12123                   (if (< all len)
12124                       (let ((older-range (nreverse older)))
12125                         (setq older nil)
12126
12127                         (while (> all 0)
12128                           (let* ((r (pop older-range))
12129                                  (min (if (numberp r) r (car r)))
12130                                  (max (if (numberp r) r (cdr r))))
12131                             (while (and (<= min max)
12132                                         (> all 0))
12133                               (push max older)
12134                               (setq all (1- all)
12135                                     max (1- max))))))))))
12136           (setq older (gnus-uncompress-range older))))
12137         (if (not older)
12138             (message "No old news.")
12139           (gnus-summary-insert-articles older)
12140           (gnus-summary-limit (gnus-sorted-nunion old older))))
12141     (gnus-summary-position-point)))
12142
12143 (defun gnus-summary-insert-new-articles ()
12144   "Insert all new articles in this group."
12145   (interactive)
12146   (prog1
12147       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12148             (old-active gnus-newsgroup-active)
12149             (nnmail-fetched-sources (list t))
12150             i new)
12151         (setq gnus-newsgroup-active
12152               (gnus-activate-group gnus-newsgroup-name 'scan))
12153         (setq i (cdr gnus-newsgroup-active))
12154         (while (> i (cdr old-active))
12155           (push i new)
12156           (decf i))
12157         (if (not new)
12158             (message "No gnus is bad news")
12159           (gnus-summary-insert-articles new)
12160           (setq gnus-newsgroup-unreads
12161                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12162           (gnus-summary-limit (gnus-sorted-nunion old new))))
12163     (gnus-summary-position-point)))
12164
12165 (gnus-summary-make-all-marking-commands)
12166
12167 (gnus-ems-redefine)
12168
12169 (provide 'gnus-sum)
12170
12171 (run-hooks 'gnus-sum-load-hook)
12172
12173 ;; Local Variables:
12174 ;; coding: iso-8859-1
12175 ;; End:
12176
12177 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12178 ;;; gnus-sum.el ends here