* nnweb.el (nnweb-gmane-search): Placeholder TOPDOC setting.
[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   "Function used to decode a string with encoded words.")
1056
1057 (defvar gnus-decode-encoded-address-function
1058   'mail-decode-encoded-address-string
1059   "Function used to decode addresses with encoded words.")
1060
1061 (defcustom gnus-extra-headers '(To Newsgroups)
1062   "*Extra headers to parse."
1063   :version "21.1"
1064   :group 'gnus-summary
1065   :type '(repeat symbol))
1066
1067 (defcustom gnus-ignored-from-addresses
1068   (and user-mail-address
1069        (not (string= user-mail-address ""))
1070        (regexp-quote user-mail-address))
1071   "*Regexp of From headers that may be suppressed in favor of To headers."
1072   :version "21.1"
1073   :group 'gnus-summary
1074   :type 'regexp)
1075
1076 (defcustom gnus-summary-to-prefix "-> "
1077   "*String prefixed to the To field in the summary line when
1078 using `gnus-ignored-from-addresses'."
1079   :version "22.1"
1080   :group 'gnus-summary
1081   :type 'string)
1082
1083 (defcustom gnus-summary-newsgroup-prefix "=> "
1084   "*String prefixed to the Newsgroup field in the summary
1085 line when using `gnus-ignored-from-addresses'."
1086   :version "22.1"
1087   :group 'gnus-summary
1088   :type 'string)
1089
1090 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1091   "List of charsets that should be ignored.
1092 When these charsets are used in the \"charset\" parameter, the
1093 default charset will be used instead."
1094   :version "21.1"
1095   :type '(repeat symbol)
1096   :group 'gnus-charset)
1097
1098 (gnus-define-group-parameter
1099  ignored-charsets
1100  :type list
1101  :function-document
1102  "Return the ignored charsets of GROUP."
1103  :variable gnus-group-ignored-charsets-alist
1104  :variable-default
1105  '(("alt\\.chinese\\.text" iso-8859-1))
1106  :variable-document
1107  "Alist of regexps (to match group names) and charsets that should be ignored.
1108 When these charsets are used in the \"charset\" parameter, the
1109 default charset will be used instead."
1110  :variable-group gnus-charset
1111  :variable-type '(repeat (cons (regexp :tag "Group")
1112                                (repeat symbol)))
1113  :parameter-type '(choice :tag "Ignored charsets"
1114                           :value nil
1115                           (repeat (symbol)))
1116  :parameter-document       "\
1117 List of charsets that should be ignored.
1118
1119 When these charsets are used in the \"charset\" parameter, the
1120 default charset will be used instead.")
1121
1122 (defcustom gnus-group-highlight-words-alist nil
1123   "Alist of group regexps and highlight regexps.
1124 This variable uses the same syntax as `gnus-emphasis-alist'."
1125   :version "21.1"
1126   :type '(repeat (cons (regexp :tag "Group")
1127                        (repeat (list (regexp :tag "Highlight regexp")
1128                                      (number :tag "Group for entire word" 0)
1129                                      (number :tag "Group for displayed part" 0)
1130                                      (symbol :tag "Face"
1131                                              gnus-emphasis-highlight-words)))))
1132   :group 'gnus-summary-visual)
1133
1134 (defcustom gnus-summary-show-article-charset-alist
1135   nil
1136   "Alist of number and charset.
1137 The article will be shown with the charset corresponding to the
1138 numbered argument.
1139 For example: ((1 . cn-gb-2312) (2 . big5))."
1140   :version "21.1"
1141   :type '(repeat (cons (number :tag "Argument" 1)
1142                        (symbol :tag "Charset")))
1143   :group 'gnus-charset)
1144
1145 (defcustom gnus-preserve-marks t
1146   "Whether marks are preserved when moving, copying and respooling messages."
1147   :version "21.1"
1148   :type 'boolean
1149   :group 'gnus-summary-marks)
1150
1151 (defcustom gnus-alter-articles-to-read-function nil
1152   "Function to be called to alter the list of articles to be selected."
1153   :type '(choice (const nil) function)
1154   :group 'gnus-summary)
1155
1156 (defcustom gnus-orphan-score nil
1157   "*All orphans get this score added.  Set in the score file."
1158   :group 'gnus-score-default
1159   :type '(choice (const nil)
1160                  integer))
1161
1162 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1163   "*A regexp to match MIME parts when saving multiple parts of a
1164 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1165 This regexp will be used by default when prompting the user for which
1166 type of files to save."
1167   :group 'gnus-summary
1168   :type 'regexp)
1169
1170 (defcustom gnus-read-all-available-headers nil
1171   "Whether Gnus should parse all headers made available to it.
1172 This is mostly relevant for slow back ends where the user may
1173 wish to widen the summary buffer to include all headers
1174 that were fetched.  Say, for nnultimate groups."
1175   :version "22.1"
1176   :group 'gnus-summary
1177   :type '(choice boolean regexp))
1178
1179 (defcustom gnus-summary-muttprint-program "muttprint"
1180   "Command (and optional arguments) used to run Muttprint."
1181   :version "22.1"
1182   :group 'gnus-summary
1183   :type 'string)
1184
1185 (defcustom gnus-article-loose-mime t
1186   "If non-nil, don't require MIME-Version header.
1187 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1188 supply the MIME-Version header or deliberately strip it from the mail.
1189 If non-nil (the default), Gnus will treat some articles as MIME
1190 even if the MIME-Version header is missing."
1191   :version "22.1"
1192   :type 'boolean
1193   :group 'gnus-article-mime)
1194
1195 (defcustom gnus-article-emulate-mime t
1196   "If non-nil, use MIME emulation for uuencode and the like.
1197 This means that Gnus will search message bodies for text that look
1198 like uuencoded bits, yEncoded bits, and so on, and present that using
1199 the normal Gnus MIME machinery."
1200   :version "22.1"
1201   :type 'boolean
1202   :group 'gnus-article-mime)
1203
1204 ;;; Internal variables
1205
1206 (defvar gnus-summary-display-cache nil)
1207 (defvar gnus-article-mime-handles nil)
1208 (defvar gnus-article-decoded-p nil)
1209 (defvar gnus-article-charset nil)
1210 (defvar gnus-article-ignored-charsets nil)
1211 (defvar gnus-scores-exclude-files nil)
1212 (defvar gnus-page-broken nil)
1213
1214 (defvar gnus-original-article nil)
1215 (defvar gnus-article-internal-prepare-hook nil)
1216 (defvar gnus-newsgroup-process-stack nil)
1217
1218 (defvar gnus-thread-indent-array nil)
1219 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1220 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1221   "Function called to sort the articles within a thread after it has been gathered together.")
1222
1223 (defvar gnus-summary-save-parts-type-history nil)
1224 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1225
1226 ;; Avoid highlighting in kill files.
1227 (defvar gnus-summary-inhibit-highlight nil)
1228 (defvar gnus-newsgroup-selected-overlay nil)
1229 (defvar gnus-inhibit-limiting nil)
1230 (defvar gnus-newsgroup-adaptive-score-file nil)
1231 (defvar gnus-current-score-file nil)
1232 (defvar gnus-current-move-group nil)
1233 (defvar gnus-current-copy-group nil)
1234 (defvar gnus-current-crosspost-group nil)
1235 (defvar gnus-newsgroup-display nil)
1236
1237 (defvar gnus-newsgroup-dependencies nil)
1238 (defvar gnus-newsgroup-adaptive nil)
1239 (defvar gnus-summary-display-article-function nil)
1240 (defvar gnus-summary-highlight-line-function nil
1241   "Function called after highlighting a summary line.")
1242
1243 (defvar gnus-summary-line-format-alist
1244   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1245     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1246     (?s gnus-tmp-subject-or-nil ?s)
1247     (?n gnus-tmp-name ?s)
1248     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1249         ?s)
1250     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1251             gnus-tmp-from) ?s)
1252     (?F gnus-tmp-from ?s)
1253     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1254     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1255     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1256     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1257     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1258     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1259     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1260     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1261     (?L gnus-tmp-lines ?s)
1262     (?O gnus-tmp-downloaded ?c)
1263     (?I gnus-tmp-indentation ?s)
1264     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1265     (?R gnus-tmp-replied ?c)
1266     (?\[ gnus-tmp-opening-bracket ?c)
1267     (?\] gnus-tmp-closing-bracket ?c)
1268     (?\> (make-string gnus-tmp-level ? ) ?s)
1269     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1270     (?i gnus-tmp-score ?d)
1271     (?z gnus-tmp-score-char ?c)
1272     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1273     (?U gnus-tmp-unread ?c)
1274     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1275         ?s)
1276     (?t (gnus-summary-number-of-articles-in-thread
1277          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1278         ?d)
1279     (?e (gnus-summary-number-of-articles-in-thread
1280          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1281         ?c)
1282     (?u gnus-tmp-user-defined ?s)
1283     (?P (gnus-pick-line-number) ?d)
1284     (?B gnus-tmp-thread-tree-header-string ?s)
1285     (user-date (gnus-user-date
1286                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1287   "An alist of format specifications that can appear in summary lines.
1288 These are paired with what variables they correspond with, along with
1289 the type of the variable (string, integer, character, etc).")
1290
1291 (defvar gnus-summary-dummy-line-format-alist
1292   `((?S gnus-tmp-subject ?s)
1293     (?N gnus-tmp-number ?d)
1294     (?u gnus-tmp-user-defined ?s)))
1295
1296 (defvar gnus-summary-mode-line-format-alist
1297   `((?G gnus-tmp-group-name ?s)
1298     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1299     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1300     (?A gnus-tmp-article-number ?d)
1301     (?Z gnus-tmp-unread-and-unselected ?s)
1302     (?V gnus-version ?s)
1303     (?U gnus-tmp-unread-and-unticked ?d)
1304     (?S gnus-tmp-subject ?s)
1305     (?e gnus-tmp-unselected ?d)
1306     (?u gnus-tmp-user-defined ?s)
1307     (?d (length gnus-newsgroup-dormant) ?d)
1308     (?t (length gnus-newsgroup-marked) ?d)
1309     (?h (length gnus-newsgroup-spam-marked) ?d)
1310     (?r (length gnus-newsgroup-reads) ?d)
1311     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1312     (?E gnus-newsgroup-expunged-tally ?d)
1313     (?s (gnus-current-score-file-nondirectory) ?s)))
1314
1315 (defvar gnus-last-search-regexp nil
1316   "Default regexp for article search command.")
1317
1318 (defvar gnus-last-shell-command nil
1319   "Default shell command on article.")
1320
1321 (defvar gnus-newsgroup-agentized nil
1322   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1323 (defvar gnus-newsgroup-begin nil)
1324 (defvar gnus-newsgroup-end nil)
1325 (defvar gnus-newsgroup-last-rmail nil)
1326 (defvar gnus-newsgroup-last-mail nil)
1327 (defvar gnus-newsgroup-last-folder nil)
1328 (defvar gnus-newsgroup-last-file nil)
1329 (defvar gnus-newsgroup-last-directory nil)
1330 (defvar gnus-newsgroup-auto-expire nil)
1331 (defvar gnus-newsgroup-active nil)
1332
1333 (defvar gnus-newsgroup-data nil)
1334 (defvar gnus-newsgroup-data-reverse nil)
1335 (defvar gnus-newsgroup-limit nil)
1336 (defvar gnus-newsgroup-limits nil)
1337 (defvar gnus-summary-use-undownloaded-faces nil)
1338
1339 (defvar gnus-newsgroup-unreads nil
1340   "Sorted list of unread articles in the current newsgroup.")
1341
1342 (defvar gnus-newsgroup-unselected nil
1343   "Sorted list of unselected unread articles in the current newsgroup.")
1344
1345 (defvar gnus-newsgroup-reads nil
1346   "Alist of read articles and article marks in the current newsgroup.")
1347
1348 (defvar gnus-newsgroup-expunged-tally nil)
1349
1350 (defvar gnus-newsgroup-marked nil
1351   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1352
1353 (defvar gnus-newsgroup-spam-marked nil
1354   "List of ranges of articles that have been marked as spam.")
1355
1356 (defvar gnus-newsgroup-killed nil
1357   "List of ranges of articles that have been through the scoring process.")
1358
1359 (defvar gnus-newsgroup-cached nil
1360   "Sorted list of articles that come from the article cache.")
1361
1362 (defvar gnus-newsgroup-saved nil
1363   "List of articles that have been saved.")
1364
1365 (defvar gnus-newsgroup-kill-headers nil)
1366
1367 (defvar gnus-newsgroup-replied nil
1368   "List of articles that have been replied to in the current newsgroup.")
1369
1370 (defvar gnus-newsgroup-forwarded nil
1371   "List of articles that have been forwarded in the current newsgroup.")
1372
1373 (defvar gnus-newsgroup-recent nil
1374   "List of articles that have are recent in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-expirable nil
1377   "Sorted list of articles in the current newsgroup that can be expired.")
1378
1379 (defvar gnus-newsgroup-processable nil
1380   "List of articles in the current newsgroup that can be processed.")
1381
1382 (defvar gnus-newsgroup-downloadable nil
1383   "Sorted list of articles in the current newsgroup that can be processed.")
1384
1385 (defvar gnus-newsgroup-unfetched nil
1386   "Sorted list of articles in the current newsgroup whose headers have
1387 not been fetched into the agent.
1388
1389 This list will always be a subset of gnus-newsgroup-undownloaded.")
1390
1391 (defvar gnus-newsgroup-undownloaded nil
1392   "List of articles in the current newsgroup that haven't been downloaded.")
1393
1394 (defvar gnus-newsgroup-unsendable nil
1395   "List of articles in the current newsgroup that won't be sent.")
1396
1397 (defvar gnus-newsgroup-bookmarks nil
1398   "List of articles in the current newsgroup that have bookmarks.")
1399
1400 (defvar gnus-newsgroup-dormant nil
1401   "Sorted list of dormant articles in the current newsgroup.")
1402
1403 (defvar gnus-newsgroup-unseen nil
1404   "List of unseen articles in the current newsgroup.")
1405
1406 (defvar gnus-newsgroup-seen nil
1407   "Range of seen articles in the current newsgroup.")
1408
1409 (defvar gnus-newsgroup-articles nil
1410   "List of articles in the current newsgroup.")
1411
1412 (defvar gnus-newsgroup-scored nil
1413   "List of scored articles in the current newsgroup.")
1414
1415 (defvar gnus-newsgroup-headers nil
1416   "List of article headers in the current newsgroup.")
1417
1418 (defvar gnus-newsgroup-threads nil)
1419
1420 (defvar gnus-newsgroup-prepared nil
1421   "Whether the current group has been prepared properly.")
1422
1423 (defvar gnus-newsgroup-ancient nil
1424   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-sparse nil)
1427
1428 (defvar gnus-current-article nil)
1429 (defvar gnus-article-current nil)
1430 (defvar gnus-current-headers nil)
1431 (defvar gnus-have-all-headers nil)
1432 (defvar gnus-last-article nil)
1433 (defvar gnus-newsgroup-history nil)
1434 (defvar gnus-newsgroup-charset nil)
1435 (defvar gnus-newsgroup-ephemeral-charset nil)
1436 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1437
1438 (defvar gnus-article-before-search nil)
1439
1440 (defvar gnus-summary-local-variables
1441   '(gnus-newsgroup-name
1442     gnus-newsgroup-begin gnus-newsgroup-end
1443     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1444     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1445     gnus-newsgroup-last-directory
1446     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1447     gnus-newsgroup-unselected gnus-newsgroup-marked
1448     gnus-newsgroup-spam-marked
1449     gnus-newsgroup-reads gnus-newsgroup-saved
1450     gnus-newsgroup-replied gnus-newsgroup-forwarded
1451     gnus-newsgroup-recent
1452     gnus-newsgroup-expirable
1453     gnus-newsgroup-processable gnus-newsgroup-killed
1454     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1455     gnus-newsgroup-unfetched
1456     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1457     gnus-newsgroup-seen gnus-newsgroup-articles
1458     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1459     gnus-newsgroup-headers gnus-newsgroup-threads
1460     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1461     gnus-current-article gnus-current-headers gnus-have-all-headers
1462     gnus-last-article gnus-article-internal-prepare-hook
1463     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1464     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1465     gnus-thread-expunge-below
1466     gnus-score-alist gnus-current-score-file
1467     (gnus-summary-expunge-below . global)
1468     (gnus-summary-mark-below . global)
1469     (gnus-orphan-score . global)
1470     gnus-newsgroup-active gnus-scores-exclude-files
1471     gnus-newsgroup-history gnus-newsgroup-ancient
1472     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1473     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1474     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1475     (gnus-newsgroup-expunged-tally . 0)
1476     gnus-cache-removable-articles gnus-newsgroup-cached
1477     gnus-newsgroup-data gnus-newsgroup-data-reverse
1478     gnus-newsgroup-limit gnus-newsgroup-limits
1479     gnus-newsgroup-charset gnus-newsgroup-display
1480     gnus-summary-use-undownloaded-faces)
1481   "Variables that are buffer-local to the summary buffers.")
1482
1483 (defvar gnus-newsgroup-variables nil
1484   "A list of variables that have separate values in different newsgroups.
1485 A list of newsgroup (summary buffer) local variables, or cons of
1486 variables and their default expressions to be evalled (when the default
1487 values are not nil), that should be made global while the summary buffer
1488 is active.
1489
1490 Note: The default expressions will be evaluated (using function `eval')
1491 before assignment to the local variable rather than just assigned to it.
1492 If the default expression is the symbol `global', that symbol will not
1493 be evaluated but the global value of the local variable will be used
1494 instead.
1495
1496 These variables can be used to set variables in the group parameters
1497 while still allowing them to affect operations done in other buffers.
1498 For example:
1499
1500 \(setq gnus-newsgroup-variables
1501      '(message-use-followup-to
1502        (gnus-visible-headers .
1503          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1504 ")
1505
1506 ;; Byte-compiler warning.
1507 (eval-when-compile
1508   ;; Bind features so that require will believe that gnus-sum has
1509   ;; already been loaded (avoids infinite recursion)
1510   (let ((features (cons 'gnus-sum features)))
1511     ;; Several of the declarations in gnus-sum are needed to load the
1512     ;; following files. Right now, these definitions have been
1513     ;; compiled but not defined (evaluated).  We could either do a
1514     ;; eval-and-compile about all of the declarations or evaluate the
1515     ;; source file.
1516     (if (boundp 'gnus-newsgroup-variables)
1517         nil
1518       (load "gnus-sum.el" t t t))
1519     (require 'gnus)
1520     (require 'gnus-art)))
1521
1522 ;; MIME stuff.
1523
1524 (defvar gnus-decode-encoded-word-methods
1525   '(mail-decode-encoded-word-string)
1526   "List of methods used to decode encoded words.
1527
1528 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1529 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1530 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1531 whose names match REGEXP.
1532
1533 For example:
1534 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1535  mail-decode-encoded-word-string
1536  (\"chinese\" . rfc1843-decode-string))")
1537
1538 (defvar gnus-decode-encoded-word-methods-cache nil)
1539
1540 (defun gnus-multi-decode-encoded-word-string (string)
1541   "Apply the functions from `gnus-encoded-word-methods' that match."
1542   (unless (and gnus-decode-encoded-word-methods-cache
1543                (eq gnus-newsgroup-name
1544                    (car gnus-decode-encoded-word-methods-cache)))
1545     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1546     (mapcar (lambda (x)
1547               (if (symbolp x)
1548                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1549                 (if (and gnus-newsgroup-name
1550                          (string-match (car x) gnus-newsgroup-name))
1551                     (nconc gnus-decode-encoded-word-methods-cache
1552                            (list (cdr x))))))
1553             gnus-decode-encoded-word-methods))
1554   (let ((xlist gnus-decode-encoded-word-methods-cache))
1555     (pop xlist)
1556     (while xlist
1557       (setq string (funcall (pop xlist) string))))
1558   string)
1559
1560 ;; Subject simplification.
1561
1562 (defun gnus-simplify-whitespace (str)
1563   "Remove excessive whitespace from STR."
1564   ;; Multiple spaces.
1565   (while (string-match "[ \t][ \t]+" str)
1566     (setq str (concat (substring str 0 (match-beginning 0))
1567                         " "
1568                         (substring str (match-end 0)))))
1569   ;; Leading spaces.
1570   (when (string-match "^[ \t]+" str)
1571     (setq str (substring str (match-end 0))))
1572   ;; Trailing spaces.
1573   (when (string-match "[ \t]+$" str)
1574     (setq str (substring str 0 (match-beginning 0))))
1575   str)
1576
1577 (defun gnus-simplify-all-whitespace (str)
1578   "Remove all whitespace from STR."
1579   (while (string-match "[ \t\n]+" str)
1580     (setq str (replace-match "" nil nil str)))
1581   str)
1582
1583 (defsubst gnus-simplify-subject-re (subject)
1584   "Remove \"Re:\" from subject lines."
1585   (if (string-match message-subject-re-regexp subject)
1586       (substring subject (match-end 0))
1587     subject))
1588
1589 (defun gnus-simplify-subject (subject &optional re-only)
1590   "Remove `Re:' and words in parentheses.
1591 If RE-ONLY is non-nil, strip leading `Re:'s only."
1592   (let ((case-fold-search t))           ;Ignore case.
1593     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1594     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1595       (setq subject (substring subject (match-end 0))))
1596     ;; Remove uninteresting prefixes.
1597     (when (and (not re-only)
1598                gnus-simplify-ignored-prefixes
1599                (string-match gnus-simplify-ignored-prefixes subject))
1600       (setq subject (substring subject (match-end 0))))
1601     ;; Remove words in parentheses from end.
1602     (unless re-only
1603       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1604         (setq subject (substring subject 0 (match-beginning 0)))))
1605     ;; Return subject string.
1606     subject))
1607
1608 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1609 ;; all whitespace.
1610 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1611   (goto-char (point-min))
1612   (while (re-search-forward regexp nil t)
1613     (replace-match (or newtext ""))))
1614
1615 (defun gnus-simplify-buffer-fuzzy ()
1616   "Simplify string in the buffer fuzzily.
1617 The string in the accessible portion of the current buffer is simplified.
1618 It is assumed to be a single-line subject.
1619 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1620 matter is removed.  Additional things can be deleted by setting
1621 `gnus-simplify-subject-fuzzy-regexp'."
1622   (let ((case-fold-search t)
1623         (modified-tick))
1624     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1625
1626     (while (not (eq modified-tick (buffer-modified-tick)))
1627       (setq modified-tick (buffer-modified-tick))
1628       (cond
1629        ((listp gnus-simplify-subject-fuzzy-regexp)
1630         (mapcar 'gnus-simplify-buffer-fuzzy-step
1631                 gnus-simplify-subject-fuzzy-regexp))
1632        (gnus-simplify-subject-fuzzy-regexp
1633         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1634       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1635       (gnus-simplify-buffer-fuzzy-step
1636        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1637       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1638
1639     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1640     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1641     (gnus-simplify-buffer-fuzzy-step " $")
1642     (gnus-simplify-buffer-fuzzy-step "^ +")))
1643
1644 (defun gnus-simplify-subject-fuzzy (subject)
1645   "Simplify a subject string fuzzily.
1646 See `gnus-simplify-buffer-fuzzy' for details."
1647   (save-excursion
1648     (gnus-set-work-buffer)
1649     (let ((case-fold-search t))
1650       ;; Remove uninteresting prefixes.
1651       (when (and gnus-simplify-ignored-prefixes
1652                  (string-match gnus-simplify-ignored-prefixes subject))
1653         (setq subject (substring subject (match-end 0))))
1654       (insert subject)
1655       (inline (gnus-simplify-buffer-fuzzy))
1656       (buffer-string))))
1657
1658 (defsubst gnus-simplify-subject-fully (subject)
1659   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1660   (cond
1661    (gnus-simplify-subject-functions
1662     (gnus-map-function gnus-simplify-subject-functions subject))
1663    ((null gnus-summary-gather-subject-limit)
1664     (gnus-simplify-subject-re subject))
1665    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1666     (gnus-simplify-subject-fuzzy subject))
1667    ((numberp gnus-summary-gather-subject-limit)
1668     (gnus-limit-string (gnus-simplify-subject-re subject)
1669                        gnus-summary-gather-subject-limit))
1670    (t
1671     subject)))
1672
1673 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1674   "Check whether two subjects are equal.
1675 If optional argument SIMPLE-FIRST is t, first argument is already
1676 simplified."
1677   (cond
1678    ((null simple-first)
1679     (equal (gnus-simplify-subject-fully s1)
1680            (gnus-simplify-subject-fully s2)))
1681    (t
1682     (equal s1
1683            (gnus-simplify-subject-fully s2)))))
1684
1685 (defun gnus-summary-bubble-group ()
1686   "Increase the score of the current group.
1687 This is a handy function to add to `gnus-summary-exit-hook' to
1688 increase the score of each group you read."
1689   (gnus-group-add-score gnus-newsgroup-name))
1690
1691 \f
1692 ;;;
1693 ;;; Gnus summary mode
1694 ;;;
1695
1696 (put 'gnus-summary-mode 'mode-class 'special)
1697
1698 (defvar gnus-article-commands-menu)
1699
1700 ;; Non-orthogonal keys
1701
1702 (gnus-define-keys gnus-summary-mode-map
1703   " " gnus-summary-next-page
1704   "\177" gnus-summary-prev-page
1705   [delete] gnus-summary-prev-page
1706   [backspace] gnus-summary-prev-page
1707   "\r" gnus-summary-scroll-up
1708   "\M-\r" gnus-summary-scroll-down
1709   "n" gnus-summary-next-unread-article
1710   "p" gnus-summary-prev-unread-article
1711   "N" gnus-summary-next-article
1712   "P" gnus-summary-prev-article
1713   "\M-\C-n" gnus-summary-next-same-subject
1714   "\M-\C-p" gnus-summary-prev-same-subject
1715   "\M-n" gnus-summary-next-unread-subject
1716   "\M-p" gnus-summary-prev-unread-subject
1717   "." gnus-summary-first-unread-article
1718   "," gnus-summary-best-unread-article
1719   "\M-s" gnus-summary-search-article-forward
1720   "\M-r" gnus-summary-search-article-backward
1721   "\M-S" gnus-summary-repeat-search-article-forward
1722   "\M-R" gnus-summary-repeat-search-article-backward
1723   "<" gnus-summary-beginning-of-article
1724   ">" gnus-summary-end-of-article
1725   "j" gnus-summary-goto-article
1726   "^" gnus-summary-refer-parent-article
1727   "\M-^" gnus-summary-refer-article
1728   "u" gnus-summary-tick-article-forward
1729   "!" gnus-summary-tick-article-forward
1730   "U" gnus-summary-tick-article-backward
1731   "d" gnus-summary-mark-as-read-forward
1732   "D" gnus-summary-mark-as-read-backward
1733   "E" gnus-summary-mark-as-expirable
1734   "\M-u" gnus-summary-clear-mark-forward
1735   "\M-U" gnus-summary-clear-mark-backward
1736   "k" gnus-summary-kill-same-subject-and-select
1737   "\C-k" gnus-summary-kill-same-subject
1738   "\M-\C-k" gnus-summary-kill-thread
1739   "\M-\C-l" gnus-summary-lower-thread
1740   "e" gnus-summary-edit-article
1741   "#" gnus-summary-mark-as-processable
1742   "\M-#" gnus-summary-unmark-as-processable
1743   "\M-\C-t" gnus-summary-toggle-threads
1744   "\M-\C-s" gnus-summary-show-thread
1745   "\M-\C-h" gnus-summary-hide-thread
1746   "\M-\C-f" gnus-summary-next-thread
1747   "\M-\C-b" gnus-summary-prev-thread
1748   [(meta down)] gnus-summary-next-thread
1749   [(meta up)] gnus-summary-prev-thread
1750   "\M-\C-u" gnus-summary-up-thread
1751   "\M-\C-d" gnus-summary-down-thread
1752   "&" gnus-summary-execute-command
1753   "c" gnus-summary-catchup-and-exit
1754   "\C-w" gnus-summary-mark-region-as-read
1755   "\C-t" gnus-summary-toggle-truncation
1756   "?" gnus-summary-mark-as-dormant
1757   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1758   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1759   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1760   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1761   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1762   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1763   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1764   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1765   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1766   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1767   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1768   "=" gnus-summary-expand-window
1769   "\C-x\C-s" gnus-summary-reselect-current-group
1770   "\M-g" gnus-summary-rescan-group
1771   "w" gnus-summary-stop-page-breaking
1772   "\C-c\C-r" gnus-summary-caesar-message
1773   "f" gnus-summary-followup
1774   "F" gnus-summary-followup-with-original
1775   "C" gnus-summary-cancel-article
1776   "r" gnus-summary-reply
1777   "R" gnus-summary-reply-with-original
1778   "\C-c\C-f" gnus-summary-mail-forward
1779   "o" gnus-summary-save-article
1780   "\C-o" gnus-summary-save-article-mail
1781   "|" gnus-summary-pipe-output
1782   "\M-k" gnus-summary-edit-local-kill
1783   "\M-K" gnus-summary-edit-global-kill
1784   ;; "V" gnus-version
1785   "\C-c\C-d" gnus-summary-describe-group
1786   "q" gnus-summary-exit
1787   "Q" gnus-summary-exit-no-update
1788   "\C-c\C-i" gnus-info-find-node
1789   gnus-mouse-2 gnus-mouse-pick-article
1790   [follow-link] mouse-face
1791   "m" gnus-summary-mail-other-window
1792   "a" gnus-summary-post-news
1793   "i" gnus-summary-news-other-window
1794   "x" gnus-summary-limit-to-unread
1795   "s" gnus-summary-isearch-article
1796   "t" gnus-summary-toggle-header
1797   "g" gnus-summary-show-article
1798   "l" gnus-summary-goto-last-article
1799   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1800   "\C-d" gnus-summary-enter-digest-group
1801   "\M-\C-d" gnus-summary-read-document
1802   "\M-\C-e" gnus-summary-edit-parameters
1803   "\M-\C-a" gnus-summary-customize-parameters
1804   "\C-c\C-b" gnus-bug
1805   "*" gnus-cache-enter-article
1806   "\M-*" gnus-cache-remove-article
1807   "\M-&" gnus-summary-universal-argument
1808   "\C-l" gnus-recenter
1809   "I" gnus-summary-increase-score
1810   "L" gnus-summary-lower-score
1811   "\M-i" gnus-symbolic-argument
1812   "h" gnus-summary-select-article-buffer
1813
1814   "b" gnus-article-view-part
1815   "\M-t" gnus-summary-toggle-display-buttonized
1816
1817   "V" gnus-summary-score-map
1818   "X" gnus-uu-extract-map
1819   "S" gnus-summary-send-map)
1820
1821 ;; Sort of orthogonal keymap
1822 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1823   "t" gnus-summary-tick-article-forward
1824   "!" gnus-summary-tick-article-forward
1825   "d" gnus-summary-mark-as-read-forward
1826   "r" gnus-summary-mark-as-read-forward
1827   "c" gnus-summary-clear-mark-forward
1828   " " gnus-summary-clear-mark-forward
1829   "e" gnus-summary-mark-as-expirable
1830   "x" gnus-summary-mark-as-expirable
1831   "?" gnus-summary-mark-as-dormant
1832   "b" gnus-summary-set-bookmark
1833   "B" gnus-summary-remove-bookmark
1834   "#" gnus-summary-mark-as-processable
1835   "\M-#" gnus-summary-unmark-as-processable
1836   "S" gnus-summary-limit-include-expunged
1837   "C" gnus-summary-catchup
1838   "H" gnus-summary-catchup-to-here
1839   "h" gnus-summary-catchup-from-here
1840   "\C-c" gnus-summary-catchup-all
1841   "k" gnus-summary-kill-same-subject-and-select
1842   "K" gnus-summary-kill-same-subject
1843   "P" gnus-uu-mark-map)
1844
1845 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1846   "c" gnus-summary-clear-above
1847   "u" gnus-summary-tick-above
1848   "m" gnus-summary-mark-above
1849   "k" gnus-summary-kill-below)
1850
1851 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1852   "/" gnus-summary-limit-to-subject
1853   "n" gnus-summary-limit-to-articles
1854   "b" gnus-summary-limit-to-bodies
1855   "h" gnus-summary-limit-to-headers
1856   "w" gnus-summary-pop-limit
1857   "s" gnus-summary-limit-to-subject
1858   "a" gnus-summary-limit-to-author
1859   "u" gnus-summary-limit-to-unread
1860   "m" gnus-summary-limit-to-marks
1861   "M" gnus-summary-limit-exclude-marks
1862   "v" gnus-summary-limit-to-score
1863   "*" gnus-summary-limit-include-cached
1864   "D" gnus-summary-limit-include-dormant
1865   "T" gnus-summary-limit-include-thread
1866   "d" gnus-summary-limit-exclude-dormant
1867   "t" gnus-summary-limit-to-age
1868   "." gnus-summary-limit-to-unseen
1869   "x" gnus-summary-limit-to-extra
1870   "p" gnus-summary-limit-to-display-predicate
1871   "E" gnus-summary-limit-include-expunged
1872   "c" gnus-summary-limit-exclude-childless-dormant
1873   "C" gnus-summary-limit-mark-excluded-as-read
1874   "o" gnus-summary-insert-old-articles
1875   "N" gnus-summary-insert-new-articles
1876   "r" gnus-summary-limit-to-replied
1877   "R" gnus-summary-limit-to-recipient)
1878
1879 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1880   "n" gnus-summary-next-unread-article
1881   "p" gnus-summary-prev-unread-article
1882   "N" gnus-summary-next-article
1883   "P" gnus-summary-prev-article
1884   "\C-n" gnus-summary-next-same-subject
1885   "\C-p" gnus-summary-prev-same-subject
1886   "\M-n" gnus-summary-next-unread-subject
1887   "\M-p" gnus-summary-prev-unread-subject
1888   "f" gnus-summary-first-unread-article
1889   "b" gnus-summary-best-unread-article
1890   "j" gnus-summary-goto-article
1891   "g" gnus-summary-goto-subject
1892   "l" gnus-summary-goto-last-article
1893   "o" gnus-summary-pop-article)
1894
1895 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1896   "k" gnus-summary-kill-thread
1897   "l" gnus-summary-lower-thread
1898   "i" gnus-summary-raise-thread
1899   "T" gnus-summary-toggle-threads
1900   "t" gnus-summary-rethread-current
1901   "^" gnus-summary-reparent-thread
1902   "\M-^" gnus-summary-reparent-children
1903   "s" gnus-summary-show-thread
1904   "S" gnus-summary-show-all-threads
1905   "h" gnus-summary-hide-thread
1906   "H" gnus-summary-hide-all-threads
1907   "n" gnus-summary-next-thread
1908   "p" gnus-summary-prev-thread
1909   "u" gnus-summary-up-thread
1910   "o" gnus-summary-top-thread
1911   "d" gnus-summary-down-thread
1912   "#" gnus-uu-mark-thread
1913   "\M-#" gnus-uu-unmark-thread)
1914
1915 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1916   "g" gnus-summary-prepare
1917   "c" gnus-summary-insert-cached-articles
1918   "d" gnus-summary-insert-dormant-articles)
1919
1920 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1921   "c" gnus-summary-catchup-and-exit
1922   "C" gnus-summary-catchup-all-and-exit
1923   "E" gnus-summary-exit-no-update
1924   "Q" gnus-summary-exit
1925   "Z" gnus-summary-exit
1926   "n" gnus-summary-catchup-and-goto-next-group
1927   "p" gnus-summary-catchup-and-goto-prev-group
1928   "R" gnus-summary-reselect-current-group
1929   "G" gnus-summary-rescan-group
1930   "N" gnus-summary-next-group
1931   "s" gnus-summary-save-newsrc
1932   "P" gnus-summary-prev-group)
1933
1934 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1935   " " gnus-summary-next-page
1936   "n" gnus-summary-next-page
1937   "\177" gnus-summary-prev-page
1938   [delete] gnus-summary-prev-page
1939   "p" gnus-summary-prev-page
1940   "\r" gnus-summary-scroll-up
1941   "\M-\r" gnus-summary-scroll-down
1942   "<" gnus-summary-beginning-of-article
1943   ">" gnus-summary-end-of-article
1944   "b" gnus-summary-beginning-of-article
1945   "e" gnus-summary-end-of-article
1946   "^" gnus-summary-refer-parent-article
1947   "r" gnus-summary-refer-parent-article
1948   "D" gnus-summary-enter-digest-group
1949   "R" gnus-summary-refer-references
1950   "T" gnus-summary-refer-thread
1951   "g" gnus-summary-show-article
1952   "s" gnus-summary-isearch-article
1953   "P" gnus-summary-print-article
1954   "M" gnus-mailing-list-insinuate
1955   "t" gnus-article-babel)
1956
1957 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1958   "b" gnus-article-add-buttons
1959   "B" gnus-article-add-buttons-to-head
1960   "o" gnus-article-treat-overstrike
1961   "e" gnus-article-emphasize
1962   "w" gnus-article-fill-cited-article
1963   "Q" gnus-article-fill-long-lines
1964   "L" gnus-article-toggle-truncate-lines
1965   "C" gnus-article-capitalize-sentences
1966   "c" gnus-article-remove-cr
1967   "q" gnus-article-de-quoted-unreadable
1968   "6" gnus-article-de-base64-unreadable
1969   "Z" gnus-article-decode-HZ
1970   "A" gnus-article-treat-ansi-sequences
1971   "h" gnus-article-wash-html
1972   "u" gnus-article-unsplit-urls
1973   "s" gnus-summary-force-verify-and-decrypt
1974   "f" gnus-article-display-x-face
1975   "l" gnus-summary-stop-page-breaking
1976   "r" gnus-summary-caesar-message
1977   "m" gnus-summary-morse-message
1978   "t" gnus-summary-toggle-header
1979   "g" gnus-treat-smiley
1980   "v" gnus-summary-verbose-headers
1981   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1982   "p" gnus-article-verify-x-pgp-sig
1983   "d" gnus-article-treat-dumbquotes
1984   "i" gnus-summary-idna-message)
1985
1986 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1987   ;; mnemonic: deuglif*Y*
1988   "u" gnus-article-outlook-unwrap-lines
1989   "a" gnus-article-outlook-repair-attribution
1990   "c" gnus-article-outlook-rearrange-citation
1991   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1992
1993 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1994   "a" gnus-article-hide
1995   "h" gnus-article-hide-headers
1996   "b" gnus-article-hide-boring-headers
1997   "s" gnus-article-hide-signature
1998   "c" gnus-article-hide-citation
1999   "C" gnus-article-hide-citation-in-followups
2000   "l" gnus-article-hide-list-identifiers
2001   "B" gnus-article-strip-banner
2002   "P" gnus-article-hide-pem
2003   "\C-c" gnus-article-hide-citation-maybe)
2004
2005 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2006   "a" gnus-article-highlight
2007   "h" gnus-article-highlight-headers
2008   "c" gnus-article-highlight-citation
2009   "s" gnus-article-highlight-signature)
2010
2011 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2012   "f" gnus-article-treat-fold-headers
2013   "u" gnus-article-treat-unfold-headers
2014   "n" gnus-article-treat-fold-newsgroups)
2015
2016 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2017   "x" gnus-article-display-x-face
2018   "d" gnus-article-display-face
2019   "s" gnus-treat-smiley
2020   "D" gnus-article-remove-images
2021   "f" gnus-treat-from-picon
2022   "m" gnus-treat-mail-picon
2023   "n" gnus-treat-newsgroups-picon)
2024
2025 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2026   "w" gnus-article-decode-mime-words
2027   "c" gnus-article-decode-charset
2028   "v" gnus-mime-view-all-parts
2029   "b" gnus-article-view-part)
2030
2031 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2032   "z" gnus-article-date-ut
2033   "u" gnus-article-date-ut
2034   "l" gnus-article-date-local
2035   "p" gnus-article-date-english
2036   "e" gnus-article-date-lapsed
2037   "o" gnus-article-date-original
2038   "i" gnus-article-date-iso8601
2039   "s" gnus-article-date-user)
2040
2041 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2042   "t" gnus-article-remove-trailing-blank-lines
2043   "l" gnus-article-strip-leading-blank-lines
2044   "m" gnus-article-strip-multiple-blank-lines
2045   "a" gnus-article-strip-blank-lines
2046   "A" gnus-article-strip-all-blank-lines
2047   "s" gnus-article-strip-leading-space
2048   "e" gnus-article-strip-trailing-space
2049   "w" gnus-article-remove-leading-whitespace)
2050
2051 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2052   "v" gnus-version
2053   "f" gnus-summary-fetch-faq
2054   "d" gnus-summary-describe-group
2055   "h" gnus-summary-describe-briefly
2056   "i" gnus-info-find-node
2057   "c" gnus-group-fetch-charter
2058   "C" gnus-group-fetch-control)
2059
2060 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2061   "e" gnus-summary-expire-articles
2062   "\M-\C-e" gnus-summary-expire-articles-now
2063   "\177" gnus-summary-delete-article
2064   [delete] gnus-summary-delete-article
2065   [backspace] gnus-summary-delete-article
2066   "m" gnus-summary-move-article
2067   "r" gnus-summary-respool-article
2068   "w" gnus-summary-edit-article
2069   "c" gnus-summary-copy-article
2070   "B" gnus-summary-crosspost-article
2071   "q" gnus-summary-respool-query
2072   "t" gnus-summary-respool-trace
2073   "i" gnus-summary-import-article
2074   "I" gnus-summary-create-article
2075   "p" gnus-summary-article-posted-p)
2076
2077 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2078   "o" gnus-summary-save-article
2079   "m" gnus-summary-save-article-mail
2080   "F" gnus-summary-write-article-file
2081   "r" gnus-summary-save-article-rmail
2082   "f" gnus-summary-save-article-file
2083   "b" gnus-summary-save-article-body-file
2084   "B" gnus-summary-write-article-body-file
2085   "h" gnus-summary-save-article-folder
2086   "v" gnus-summary-save-article-vm
2087   "p" gnus-summary-pipe-output
2088   "P" gnus-summary-muttprint
2089   "s" gnus-soup-add-article)
2090
2091 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2092   "b" gnus-summary-display-buttonized
2093   "m" gnus-summary-repair-multipart
2094   "v" gnus-article-view-part
2095   "o" gnus-article-save-part
2096   "O" gnus-article-save-part-and-strip
2097   "r" gnus-article-replace-part
2098   "d" gnus-article-delete-part
2099   "t" gnus-article-view-part-as-type
2100   "j" gnus-article-jump-to-part
2101   "c" gnus-article-copy-part
2102   "C" gnus-article-view-part-as-charset
2103   "e" gnus-article-view-part-externally
2104   "H" gnus-article-browse-html-article
2105   "E" gnus-article-encrypt-body
2106   "i" gnus-article-inline-part
2107   "|" gnus-article-pipe-part)
2108
2109 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2110   "p" gnus-summary-mark-as-processable
2111   "u" gnus-summary-unmark-as-processable
2112   "U" gnus-summary-unmark-all-processable
2113   "v" gnus-uu-mark-over
2114   "s" gnus-uu-mark-series
2115   "r" gnus-uu-mark-region
2116   "g" gnus-uu-unmark-region
2117   "R" gnus-uu-mark-by-regexp
2118   "G" gnus-uu-unmark-by-regexp
2119   "t" gnus-uu-mark-thread
2120   "T" gnus-uu-unmark-thread
2121   "a" gnus-uu-mark-all
2122   "b" gnus-uu-mark-buffer
2123   "S" gnus-uu-mark-sparse
2124   "k" gnus-summary-kill-process-mark
2125   "y" gnus-summary-yank-process-mark
2126   "w" gnus-summary-save-process-mark
2127   "i" gnus-uu-invert-processable)
2128
2129 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2130   ;;"x" gnus-uu-extract-any
2131   "m" gnus-summary-save-parts
2132   "u" gnus-uu-decode-uu
2133   "U" gnus-uu-decode-uu-and-save
2134   "s" gnus-uu-decode-unshar
2135   "S" gnus-uu-decode-unshar-and-save
2136   "o" gnus-uu-decode-save
2137   "O" gnus-uu-decode-save
2138   "b" gnus-uu-decode-binhex
2139   "B" gnus-uu-decode-binhex
2140   "p" gnus-uu-decode-postscript
2141   "P" gnus-uu-decode-postscript-and-save)
2142
2143 (gnus-define-keys
2144     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2145   "u" gnus-uu-decode-uu-view
2146   "U" gnus-uu-decode-uu-and-save-view
2147   "s" gnus-uu-decode-unshar-view
2148   "S" gnus-uu-decode-unshar-and-save-view
2149   "o" gnus-uu-decode-save-view
2150   "O" gnus-uu-decode-save-view
2151   "b" gnus-uu-decode-binhex-view
2152   "B" gnus-uu-decode-binhex-view
2153   "p" gnus-uu-decode-postscript-view
2154   "P" gnus-uu-decode-postscript-and-save-view)
2155
2156 (defvar gnus-article-post-menu nil)
2157
2158 (defconst gnus-summary-menu-maxlen 20)
2159
2160 (defun gnus-summary-menu-split (menu)
2161   ;; If we have lots of elements, divide them into groups of 20
2162   ;; and make a pane (or submenu) for each one.
2163   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2164       (let ((menu menu) sublists next
2165             (i 1))
2166         (while menu
2167           ;; Pull off the next gnus-summary-menu-maxlen elements
2168           ;; and make them the next element of sublist.
2169           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2170           (if next
2171               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2172                       nil))
2173           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2174                                              (aref (car (last menu)) 0)) menu)
2175                                sublists))
2176           (setq i (1+ i))
2177           (setq menu next))
2178         (nreverse sublists))
2179     ;; Few elements--put them all in one pane.
2180     menu))
2181
2182 (defun gnus-summary-make-menu-bar ()
2183   (gnus-turn-off-edit-menu 'summary)
2184
2185   (unless (boundp 'gnus-summary-misc-menu)
2186
2187     (easy-menu-define
2188       gnus-summary-kill-menu gnus-summary-mode-map ""
2189       (cons
2190        "Score"
2191        (nconc
2192         (list
2193          ["Customize" gnus-score-customize t])
2194         (gnus-make-score-map 'increase)
2195         (gnus-make-score-map 'lower)
2196         '(("Mark"
2197            ["Kill below" gnus-summary-kill-below t]
2198            ["Mark above" gnus-summary-mark-above t]
2199            ["Tick above" gnus-summary-tick-above t]
2200            ["Clear above" gnus-summary-clear-above t])
2201           ["Current score" gnus-summary-current-score t]
2202           ["Set score" gnus-summary-set-score t]
2203           ["Switch current score file..." gnus-score-change-score-file t]
2204           ["Set mark below..." gnus-score-set-mark-below t]
2205           ["Set expunge below..." gnus-score-set-expunge-below t]
2206           ["Edit current score file" gnus-score-edit-current-scores t]
2207           ["Edit score file" gnus-score-edit-file t]
2208           ["Trace score" gnus-score-find-trace t]
2209           ["Find words" gnus-score-find-favourite-words t]
2210           ["Rescore buffer" gnus-summary-rescore t]
2211           ["Increase score..." gnus-summary-increase-score t]
2212           ["Lower score..." gnus-summary-lower-score t]))))
2213
2214     ;; Define both the Article menu in the summary buffer and the
2215     ;; equivalent Commands menu in the article buffer here for
2216     ;; consistency.
2217     (let ((innards
2218            `(("Hide"
2219               ["All" gnus-article-hide t]
2220               ["Headers" gnus-article-hide-headers t]
2221               ["Signature" gnus-article-hide-signature t]
2222               ["Citation" gnus-article-hide-citation t]
2223               ["List identifiers" gnus-article-hide-list-identifiers t]
2224               ["Banner" gnus-article-strip-banner t]
2225               ["Boring headers" gnus-article-hide-boring-headers t])
2226              ("Highlight"
2227               ["All" gnus-article-highlight t]
2228               ["Headers" gnus-article-highlight-headers t]
2229               ["Signature" gnus-article-highlight-signature t]
2230               ["Citation" gnus-article-highlight-citation t])
2231              ("MIME"
2232               ["Words" gnus-article-decode-mime-words t]
2233               ["Charset" gnus-article-decode-charset t]
2234               ["QP" gnus-article-de-quoted-unreadable t]
2235               ["Base64" gnus-article-de-base64-unreadable t]
2236               ["View MIME buttons" gnus-summary-display-buttonized t]
2237               ["View all" gnus-mime-view-all-parts t]
2238               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2239               ["Encrypt body" gnus-article-encrypt-body
2240                :active (not (gnus-group-read-only-p))
2241                ,@(if (featurep 'xemacs) nil
2242                    '(:help "Encrypt the message body on disk"))]
2243               ["Extract all parts..." gnus-summary-save-parts t]
2244               ("Multipart"
2245                ["Repair multipart" gnus-summary-repair-multipart t]
2246                ["Pipe part..." gnus-article-pipe-part t]
2247                ["Inline part" gnus-article-inline-part t]
2248                ["View part as type..." gnus-article-view-part-as-type t]
2249                ["Encrypt body" gnus-article-encrypt-body
2250                 :active (not (gnus-group-read-only-p))
2251                ,@(if (featurep 'xemacs) nil
2252                    '(:help "Encrypt the message body on disk"))]
2253                ["View part externally" gnus-article-view-part-externally t]
2254                ["View HTML parts in browser" gnus-article-browse-html-article t]
2255                ["View part with charset..." gnus-article-view-part-as-charset t]
2256                ["Copy part" gnus-article-copy-part t]
2257                ["Save part..." gnus-article-save-part t]
2258                ["View part" gnus-article-view-part t]))
2259              ("Date"
2260               ["Local" gnus-article-date-local t]
2261               ["ISO8601" gnus-article-date-iso8601 t]
2262               ["UT" gnus-article-date-ut t]
2263               ["Original" gnus-article-date-original t]
2264               ["Lapsed" gnus-article-date-lapsed t]
2265               ["User-defined" gnus-article-date-user t])
2266              ("Display"
2267               ["Remove images" gnus-article-remove-images t]
2268               ["Toggle smiley" gnus-treat-smiley t]
2269               ["Show X-Face" gnus-article-display-x-face t]
2270               ["Show picons in From" gnus-treat-from-picon t]
2271               ["Show picons in mail headers" gnus-treat-mail-picon t]
2272               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2273               ("View as different encoding"
2274                ,@(gnus-summary-menu-split
2275                   (mapcar
2276                    (lambda (cs)
2277                      ;; Since easymenu under Emacs doesn't allow
2278                      ;; lambda forms for menu commands, we should
2279                      ;; provide intern'ed function symbols.
2280                      (let ((command (intern (format "\
2281 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2282                        (fset command
2283                              `(lambda ()
2284                                 (interactive)
2285                                 (let ((gnus-summary-show-article-charset-alist
2286                                        '((1 . ,cs))))
2287                                   (gnus-summary-show-article 1))))
2288                        `[,(symbol-name cs) ,command t]))
2289                    (sort (if (fboundp 'coding-system-list)
2290                              (coding-system-list)
2291                            (mapcar 'car mm-mime-mule-charset-alist))
2292                          'string<)))))
2293              ("Washing"
2294               ("Remove Blanks"
2295                ["Leading" gnus-article-strip-leading-blank-lines t]
2296                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2297                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2298                ["All of the above" gnus-article-strip-blank-lines t]
2299                ["All" gnus-article-strip-all-blank-lines t]
2300                ["Leading space" gnus-article-strip-leading-space t]
2301                ["Trailing space" gnus-article-strip-trailing-space t]
2302                ["Leading space in headers"
2303                 gnus-article-remove-leading-whitespace t])
2304               ["Overstrike" gnus-article-treat-overstrike t]
2305               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2306               ["Emphasis" gnus-article-emphasize t]
2307               ["Word wrap" gnus-article-fill-cited-article t]
2308               ["Fill long lines" gnus-article-fill-long-lines t]
2309               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2310               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2311               ["Remove CR" gnus-article-remove-cr t]
2312               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2313               ["Base64" gnus-article-de-base64-unreadable t]
2314               ["Rot 13" gnus-summary-caesar-message
2315                ,@(if (featurep 'xemacs) '(t)
2316                    '(:help "\"Caesar rotate\" article by 13"))]
2317               ["De-IDNA" gnus-summary-idna-message t]
2318               ["Morse decode" gnus-summary-morse-message t]
2319               ["Unix pipe..." gnus-summary-pipe-message t]
2320               ["Add buttons" gnus-article-add-buttons t]
2321               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2322               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2323               ["Verbose header" gnus-summary-verbose-headers t]
2324               ["Toggle header" gnus-summary-toggle-header t]
2325               ["Unfold headers" gnus-article-treat-unfold-headers t]
2326               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2327               ["Html" gnus-article-wash-html t]
2328               ["Unsplit URLs" gnus-article-unsplit-urls t]
2329               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2330               ["Decode HZ" gnus-article-decode-HZ t]
2331               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2332               ("(Outlook) Deuglify"
2333                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2334                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2335                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2336                ["Full (Outlook) deuglify"
2337                 gnus-article-outlook-deuglify-article t])
2338               )
2339              ("Output"
2340               ["Save in default format..." gnus-summary-save-article
2341                ,@(if (featurep 'xemacs) '(t)
2342                    '(:help "Save article using default method"))]
2343               ["Save in file..." gnus-summary-save-article-file
2344                ,@(if (featurep 'xemacs) '(t)
2345                    '(:help "Save article in file"))]
2346               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2347               ["Save in MH folder..." gnus-summary-save-article-folder t]
2348               ["Save in VM folder..." gnus-summary-save-article-vm t]
2349               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2350               ["Save body in file..." gnus-summary-save-article-body-file t]
2351               ["Pipe through a filter..." gnus-summary-pipe-output t]
2352               ["Add to SOUP packet" gnus-soup-add-article t]
2353               ["Print with Muttprint..." gnus-summary-muttprint t]
2354               ["Print" gnus-summary-print-article
2355                ,@(if (featurep 'xemacs) '(t)
2356                    '(:help "Generate and print a PostScript image"))])
2357              ("Copy, move,... (Backend)"
2358               ,@(if (featurep 'xemacs) nil
2359                   '(:help "Copying, moving, expiring articles..."))
2360               ["Respool article..." gnus-summary-respool-article t]
2361               ["Move article..." gnus-summary-move-article
2362                (gnus-check-backend-function
2363                 'request-move-article gnus-newsgroup-name)]
2364               ["Copy article..." gnus-summary-copy-article t]
2365               ["Crosspost article..." gnus-summary-crosspost-article
2366                (gnus-check-backend-function
2367                 'request-replace-article gnus-newsgroup-name)]
2368               ["Import file..." gnus-summary-import-article
2369                (gnus-check-backend-function
2370                 'request-accept-article gnus-newsgroup-name)]
2371               ["Create article..." gnus-summary-create-article
2372                (gnus-check-backend-function
2373                 'request-accept-article gnus-newsgroup-name)]
2374               ["Check if posted" gnus-summary-article-posted-p t]
2375               ["Edit article" gnus-summary-edit-article
2376                (not (gnus-group-read-only-p))]
2377               ["Delete article" gnus-summary-delete-article
2378                (gnus-check-backend-function
2379                 'request-expire-articles gnus-newsgroup-name)]
2380               ["Query respool" gnus-summary-respool-query t]
2381               ["Trace respool" gnus-summary-respool-trace t]
2382               ["Delete expirable articles" gnus-summary-expire-articles-now
2383                (gnus-check-backend-function
2384                 'request-expire-articles gnus-newsgroup-name)])
2385              ("Extract"
2386               ["Uudecode" gnus-uu-decode-uu
2387                ,@(if (featurep 'xemacs) '(t)
2388                    '(:help "Decode uuencoded article(s)"))]
2389               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2390               ["Unshar" gnus-uu-decode-unshar t]
2391               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2392               ["Save" gnus-uu-decode-save t]
2393               ["Binhex" gnus-uu-decode-binhex t]
2394               ["Postscript" gnus-uu-decode-postscript t]
2395               ["All MIME parts" gnus-summary-save-parts t])
2396              ("Cache"
2397               ["Enter article" gnus-cache-enter-article t]
2398               ["Remove article" gnus-cache-remove-article t])
2399              ["Translate" gnus-article-babel t]
2400              ["Select article buffer" gnus-summary-select-article-buffer t]
2401              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2402              ["Isearch article..." gnus-summary-isearch-article t]
2403              ["Beginning of the article" gnus-summary-beginning-of-article t]
2404              ["End of the article" gnus-summary-end-of-article t]
2405              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2406              ["Fetch referenced articles" gnus-summary-refer-references t]
2407              ["Fetch current thread" gnus-summary-refer-thread t]
2408              ["Fetch article with id..." gnus-summary-refer-article t]
2409              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2410              ["Redisplay" gnus-summary-show-article t]
2411              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2412       (easy-menu-define
2413         gnus-summary-article-menu gnus-summary-mode-map ""
2414         (cons "Article" innards))
2415
2416       (if (not (keymapp gnus-summary-article-menu))
2417           (easy-menu-define
2418             gnus-article-commands-menu gnus-article-mode-map ""
2419             (cons "Commands" innards))
2420         ;; in Emacs, don't share menu.
2421         (setq gnus-article-commands-menu
2422               (copy-keymap gnus-summary-article-menu))
2423         (define-key gnus-article-mode-map [menu-bar commands]
2424           (cons "Commands" gnus-article-commands-menu))))
2425
2426     (easy-menu-define
2427       gnus-summary-thread-menu gnus-summary-mode-map ""
2428       '("Threads"
2429         ["Find all messages in thread" gnus-summary-refer-thread t]
2430         ["Toggle threading" gnus-summary-toggle-threads t]
2431         ["Hide threads" gnus-summary-hide-all-threads t]
2432         ["Show threads" gnus-summary-show-all-threads t]
2433         ["Hide thread" gnus-summary-hide-thread t]
2434         ["Show thread" gnus-summary-show-thread t]
2435         ["Go to next thread" gnus-summary-next-thread t]
2436         ["Go to previous thread" gnus-summary-prev-thread t]
2437         ["Go down thread" gnus-summary-down-thread t]
2438         ["Go up thread" gnus-summary-up-thread t]
2439         ["Top of thread" gnus-summary-top-thread t]
2440         ["Mark thread as read" gnus-summary-kill-thread t]
2441         ["Lower thread score" gnus-summary-lower-thread t]
2442         ["Raise thread score" gnus-summary-raise-thread t]
2443         ["Rethread current" gnus-summary-rethread-current t]))
2444
2445     (easy-menu-define
2446       gnus-summary-post-menu gnus-summary-mode-map ""
2447       `("Post"
2448         ["Send a message (mail or news)" gnus-summary-post-news
2449          ,@(if (featurep 'xemacs) '(t)
2450              '(:help "Compose a new message (mail or news)"))]
2451         ["Followup" gnus-summary-followup
2452          ,@(if (featurep 'xemacs) '(t)
2453              '(:help "Post followup to this article"))]
2454         ["Followup and yank" gnus-summary-followup-with-original
2455          ,@(if (featurep 'xemacs) '(t)
2456              '(:help "Post followup to this article, quoting its contents"))]
2457         ["Supersede article" gnus-summary-supersede-article t]
2458         ["Cancel article" gnus-summary-cancel-article
2459          ,@(if (featurep 'xemacs) '(t)
2460              '(:help "Cancel an article you posted"))]
2461         ["Reply" gnus-summary-reply t]
2462         ["Reply and yank" gnus-summary-reply-with-original t]
2463         ["Wide reply" gnus-summary-wide-reply t]
2464         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2465          ,@(if (featurep 'xemacs) '(t)
2466              '(:help "Mail a reply, quoting this article"))]
2467         ["Very wide reply" gnus-summary-very-wide-reply t]
2468         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2469          ,@(if (featurep 'xemacs) '(t)
2470              '(:help "Mail a very wide reply, quoting this article"))]
2471         ["Mail forward" gnus-summary-mail-forward t]
2472         ["Post forward" gnus-summary-post-forward t]
2473         ["Digest and mail" gnus-uu-digest-mail-forward t]
2474         ["Digest and post" gnus-uu-digest-post-forward t]
2475         ["Resend message" gnus-summary-resend-message t]
2476         ["Resend message edit" gnus-summary-resend-message-edit t]
2477         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2478         ["Send a mail" gnus-summary-mail-other-window t]
2479         ["Create a local message" gnus-summary-news-other-window t]
2480         ["Uuencode and post" gnus-uu-post-news
2481          ,@(if (featurep 'xemacs) '(t)
2482              '(:help "Post a uuencoded article"))]
2483         ["Followup via news" gnus-summary-followup-to-mail t]
2484         ["Followup via news and yank"
2485          gnus-summary-followup-to-mail-with-original t]
2486         ;;("Draft"
2487         ;;["Send" gnus-summary-send-draft t]
2488         ;;["Send bounced" gnus-resend-bounced-mail t])
2489         ))
2490
2491     (cond
2492      ((not (keymapp gnus-summary-post-menu))
2493       (setq gnus-article-post-menu gnus-summary-post-menu))
2494      ((not gnus-article-post-menu)
2495       ;; Don't share post menu.
2496       (setq gnus-article-post-menu
2497             (copy-keymap gnus-summary-post-menu))))
2498     (define-key gnus-article-mode-map [menu-bar post]
2499       (cons "Post" gnus-article-post-menu))
2500
2501     (easy-menu-define
2502       gnus-summary-misc-menu gnus-summary-mode-map ""
2503       `("Gnus"
2504         ("Mark Read"
2505          ["Mark as read" gnus-summary-mark-as-read-forward t]
2506          ["Mark same subject and select"
2507           gnus-summary-kill-same-subject-and-select t]
2508          ["Mark same subject" gnus-summary-kill-same-subject t]
2509          ["Catchup" gnus-summary-catchup
2510           ,@(if (featurep 'xemacs) '(t)
2511               '(:help "Mark unread articles in this group as read"))]
2512          ["Catchup all" gnus-summary-catchup-all t]
2513          ["Catchup to here" gnus-summary-catchup-to-here t]
2514          ["Catchup from here" gnus-summary-catchup-from-here t]
2515          ["Catchup region" gnus-summary-mark-region-as-read
2516           (gnus-mark-active-p)]
2517          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2518         ("Mark Various"
2519          ["Tick" gnus-summary-tick-article-forward t]
2520          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2521          ["Remove marks" gnus-summary-clear-mark-forward t]
2522          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2523          ["Set bookmark" gnus-summary-set-bookmark t]
2524          ["Remove bookmark" gnus-summary-remove-bookmark t])
2525         ("Limit to"
2526          ["Marks..." gnus-summary-limit-to-marks t]
2527          ["Subject..." gnus-summary-limit-to-subject t]
2528          ["Author..." gnus-summary-limit-to-author t]
2529          ["Recipient..." gnus-summary-limit-to-recipient t]
2530          ["Age..." gnus-summary-limit-to-age t]
2531          ["Extra..." gnus-summary-limit-to-extra t]
2532          ["Score..." gnus-summary-limit-to-score t]
2533          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2534          ["Unread" gnus-summary-limit-to-unread t]
2535          ["Unseen" gnus-summary-limit-to-unseen t]
2536          ["Replied" gnus-summary-limit-to-replied t]
2537          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2538          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2539          ["Pop limit" gnus-summary-pop-limit t]
2540          ["Show dormant" gnus-summary-limit-include-dormant t]
2541          ["Hide childless dormant"
2542           gnus-summary-limit-exclude-childless-dormant t]
2543          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2544          ["Hide marked" gnus-summary-limit-exclude-marks t]
2545          ["Show expunged" gnus-summary-limit-include-expunged t])
2546         ("Process Mark"
2547          ["Set mark" gnus-summary-mark-as-processable t]
2548          ["Remove mark" gnus-summary-unmark-as-processable t]
2549          ["Remove all marks" gnus-summary-unmark-all-processable t]
2550          ["Invert marks" gnus-uu-invert-processable t]
2551          ["Mark above" gnus-uu-mark-over t]
2552          ["Mark series" gnus-uu-mark-series t]
2553          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2554          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2555          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2556          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2557          ["Mark all" gnus-uu-mark-all t]
2558          ["Mark buffer" gnus-uu-mark-buffer t]
2559          ["Mark sparse" gnus-uu-mark-sparse t]
2560          ["Mark thread" gnus-uu-mark-thread t]
2561          ["Unmark thread" gnus-uu-unmark-thread t]
2562          ("Process Mark Sets"
2563           ["Kill" gnus-summary-kill-process-mark t]
2564           ["Yank" gnus-summary-yank-process-mark
2565            gnus-newsgroup-process-stack]
2566           ["Save" gnus-summary-save-process-mark t]
2567           ["Run command on marked..." gnus-summary-universal-argument t]))
2568         ("Scroll article"
2569          ["Page forward" gnus-summary-next-page
2570           ,@(if (featurep 'xemacs) '(t)
2571               '(:help "Show next page of article"))]
2572          ["Page backward" gnus-summary-prev-page
2573           ,@(if (featurep 'xemacs) '(t)
2574               '(:help "Show previous page of article"))]
2575          ["Line forward" gnus-summary-scroll-up t])
2576         ("Move"
2577          ["Next unread article" gnus-summary-next-unread-article t]
2578          ["Previous unread article" gnus-summary-prev-unread-article t]
2579          ["Next article" gnus-summary-next-article t]
2580          ["Previous article" gnus-summary-prev-article t]
2581          ["Next unread subject" gnus-summary-next-unread-subject t]
2582          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2583          ["Next article same subject" gnus-summary-next-same-subject t]
2584          ["Previous article same subject" gnus-summary-prev-same-subject t]
2585          ["First unread article" gnus-summary-first-unread-article t]
2586          ["Best unread article" gnus-summary-best-unread-article t]
2587          ["Go to subject number..." gnus-summary-goto-subject t]
2588          ["Go to article number..." gnus-summary-goto-article t]
2589          ["Go to the last article" gnus-summary-goto-last-article t]
2590          ["Pop article off history" gnus-summary-pop-article t])
2591         ("Sort"
2592          ["Sort by number" gnus-summary-sort-by-number t]
2593          ["Sort by author" gnus-summary-sort-by-author t]
2594          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2595          ["Sort by subject" gnus-summary-sort-by-subject t]
2596          ["Sort by date" gnus-summary-sort-by-date t]
2597          ["Sort by score" gnus-summary-sort-by-score t]
2598          ["Sort by lines" gnus-summary-sort-by-lines t]
2599          ["Sort by characters" gnus-summary-sort-by-chars t]
2600          ["Randomize" gnus-summary-sort-by-random t]
2601          ["Original sort" gnus-summary-sort-by-original t])
2602         ("Help"
2603          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2604          ["Describe group" gnus-summary-describe-group t]
2605          ["Fetch charter" gnus-group-fetch-charter
2606           ,@(if (featurep 'xemacs) nil
2607               '(:help "Display the charter of the current group"))]
2608          ["Fetch control message" gnus-group-fetch-control
2609           ,@(if (featurep 'xemacs) nil
2610               '(:help "Display the archived control message for the current group"))]
2611          ["Read manual" gnus-info-find-node t])
2612         ("Modes"
2613          ["Pick and read" gnus-pick-mode t]
2614          ["Binary" gnus-binary-mode t])
2615         ("Regeneration"
2616          ["Regenerate" gnus-summary-prepare t]
2617          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2618          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2619          ["Toggle threading" gnus-summary-toggle-threads t])
2620         ["See old articles" gnus-summary-insert-old-articles t]
2621         ["See new articles" gnus-summary-insert-new-articles t]
2622         ["Filter articles..." gnus-summary-execute-command t]
2623         ["Run command on articles..." gnus-summary-universal-argument t]
2624         ["Search articles forward..." gnus-summary-search-article-forward t]
2625         ["Search articles backward..." gnus-summary-search-article-backward t]
2626         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2627         ["Expand window" gnus-summary-expand-window t]
2628         ["Expire expirable articles" gnus-summary-expire-articles
2629          (gnus-check-backend-function
2630           'request-expire-articles gnus-newsgroup-name)]
2631         ["Edit local kill file" gnus-summary-edit-local-kill t]
2632         ["Edit main kill file" gnus-summary-edit-global-kill t]
2633         ["Edit group parameters" gnus-summary-edit-parameters t]
2634         ["Customize group parameters" gnus-summary-customize-parameters t]
2635         ["Send a bug report" gnus-bug t]
2636         ("Exit"
2637          ["Catchup and exit" gnus-summary-catchup-and-exit
2638           ,@(if (featurep 'xemacs) '(t)
2639               '(:help "Mark unread articles in this group as read, then exit"))]
2640          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2641          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2642          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2643          ["Exit group" gnus-summary-exit
2644           ,@(if (featurep 'xemacs) '(t)
2645               '(:help "Exit current group, return to group selection mode"))]
2646          ["Exit group without updating" gnus-summary-exit-no-update t]
2647          ["Exit and goto next group" gnus-summary-next-group t]
2648          ["Exit and goto prev group" gnus-summary-prev-group t]
2649          ["Reselect group" gnus-summary-reselect-current-group t]
2650          ["Rescan group" gnus-summary-rescan-group t]
2651          ["Update dribble" gnus-summary-save-newsrc t])))
2652
2653     (gnus-run-hooks 'gnus-summary-menu-hook)))
2654
2655 (defvar gnus-summary-tool-bar-map nil)
2656
2657 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2658 ;; affect _new_ message buffers.  We might add a function that walks thru all
2659 ;; summary-mode buffers and force the update.
2660 (defun gnus-summary-tool-bar-update (&optional symbol value)
2661   "Update summary mode toolbar.
2662 Setter function for custom variables."
2663   (setq-default gnus-summary-tool-bar-map nil)
2664   (when symbol
2665     ;; When used as ":set" function:
2666     (set-default symbol value))
2667   (when (gnus-buffer-live-p gnus-summary-buffer)
2668     (with-current-buffer gnus-summary-buffer
2669       (gnus-summary-make-tool-bar))))
2670
2671 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2672                                      'gnus-summary-tool-bar-gnome
2673                                    'gnus-summary-tool-bar-retro)
2674   "Specifies the Gnus summary tool bar.
2675
2676 It can be either a list or a symbol refering to a list.  See
2677 `gmm-tool-bar-from-list' for the format of the list.  The
2678 default key map is `gnus-summary-mode-map'.
2679
2680 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2681 `gnus-summary-tool-bar-retro'."
2682   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2683                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2684                  (repeat :tag "User defined list" gmm-tool-bar-item)
2685                  (symbol))
2686   :version "23.0" ;; No Gnus
2687   :initialize 'custom-initialize-default
2688   :set 'gnus-summary-tool-bar-update
2689   :group 'gnus-summary)
2690
2691 (defcustom gnus-summary-tool-bar-gnome
2692   '((gnus-summary-post-news "mail/compose" nil)
2693     (gnus-summary-insert-new-articles "mail/inbox" nil
2694                                       :visible (or (not gnus-agent)
2695                                                    gnus-plugged))
2696     (gnus-summary-reply-with-original "mail/reply")
2697     (gnus-summary-reply "mail/reply" nil :visible nil)
2698     (gnus-summary-followup-with-original "mail/reply-all")
2699     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2700     (gnus-summary-mail-forward "mail/forward")
2701     (gnus-summary-save-article "mail/save")
2702     (gnus-summary-search-article-forward "search" nil :visible nil)
2703     (gnus-summary-print-article "print")
2704     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2705     ;; Some new commands that may need more suitable icons:
2706     (gnus-summary-save-newsrc "save" nil :visible nil)
2707     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2708     (gnus-summary-prev-article "left-arrow")
2709     (gnus-summary-next-article "right-arrow")
2710     (gnus-summary-next-page "next-page")
2711     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2712     ;;
2713     ;; Maybe some sort-by-... could be added:
2714     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2715     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2716     (gnus-summary-mark-as-expirable
2717      "delete" nil
2718      :visible (gnus-check-backend-function 'request-expire-articles
2719                                            gnus-newsgroup-name))
2720     (gnus-summary-mark-as-spam
2721      "mail/spam" t
2722      :visible (and (fboundp 'spam-group-ham-contents-p)
2723                    (spam-group-ham-contents-p gnus-newsgroup-name))
2724      :help "Mark as spam")
2725     (gnus-summary-mark-as-read-forward
2726      "mail/not-spam" nil
2727      :visible (and (fboundp 'spam-group-spam-contents-p)
2728                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2729     ;;
2730     (gnus-summary-exit "exit")
2731     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2732     (gnus-info-find-node "help"))
2733   "List of functions for the summary tool bar (GNOME style).
2734
2735 See `gmm-tool-bar-from-list' for the format of the list."
2736   :type '(repeat gmm-tool-bar-item)
2737   :version "23.0" ;; No Gnus
2738   :initialize 'custom-initialize-default
2739   :set 'gnus-summary-tool-bar-update
2740   :group 'gnus-summary)
2741
2742 (defcustom gnus-summary-tool-bar-retro
2743   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2744     (gnus-summary-next-unread-article "gnus/next-ur")
2745     (gnus-summary-post-news "gnus/post")
2746     (gnus-summary-followup-with-original "gnus/fuwo")
2747     (gnus-summary-followup "gnus/followup")
2748     (gnus-summary-reply-with-original "gnus/reply-wo")
2749     (gnus-summary-reply "gnus/reply")
2750     (gnus-summary-caesar-message "gnus/rot13")
2751     (gnus-uu-decode-uu "gnus/uu-decode")
2752     (gnus-summary-save-article-file "gnus/save-aif")
2753     (gnus-summary-save-article "gnus/save-art")
2754     (gnus-uu-post-news "gnus/uu-post")
2755     (gnus-summary-catchup "gnus/catchup")
2756     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2757     (gnus-summary-exit "gnus/exit-summ")
2758     ;; Some new command that may need more suitable icons:
2759     (gnus-summary-print-article "gnus/print" nil :visible nil)
2760     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2761     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2762     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2763     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2764     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2765     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2766     ;;
2767     (gnus-info-find-node "gnus/help" nil :visible nil))
2768   "List of functions for the summary tool bar (retro look).
2769
2770 See `gmm-tool-bar-from-list' for the format of the list."
2771   :type '(repeat gmm-tool-bar-item)
2772   :version "23.0" ;; No Gnus
2773   :initialize 'custom-initialize-default
2774   :set 'gnus-summary-tool-bar-update
2775   :group 'gnus-summary)
2776
2777 (defcustom gnus-summary-tool-bar-zap-list t
2778   "List of icon items from the global tool bar.
2779 These items are not displayed in the Gnus summary mode tool bar.
2780
2781 See `gmm-tool-bar-from-list' for the format of the list."
2782   :type 'gmm-tool-bar-zap-list
2783   :version "23.0" ;; No Gnus
2784   :initialize 'custom-initialize-default
2785   :set 'gnus-summary-tool-bar-update
2786   :group 'gnus-summary)
2787
2788 (defvar image-load-path)
2789
2790 (defun gnus-summary-make-tool-bar (&optional force)
2791   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2792 When FORCE, rebuild the tool bar."
2793   (when (and (not (featurep 'xemacs))
2794              (boundp 'tool-bar-mode)
2795              tool-bar-mode
2796              (or (not gnus-summary-tool-bar-map) force))
2797     (let* ((load-path
2798             (gmm-image-load-path-for-library "gnus"
2799                                              "mail/save.xpm"
2800                                              nil t))
2801            (image-load-path (cons (car load-path)
2802                                   (when (boundp 'image-load-path)
2803                                     image-load-path)))
2804            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2805                                         gnus-summary-tool-bar-zap-list
2806                                         'gnus-summary-mode-map)))
2807       (when map
2808         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2809         ;; uses it's value.
2810         (setq gnus-summary-tool-bar-map map))))
2811   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2812
2813 (defun gnus-score-set-default (var value)
2814   "A version of set that updates the GNU Emacs menu-bar."
2815   (set var value)
2816   ;; It is the message that forces the active status to be updated.
2817   (message ""))
2818
2819 (defun gnus-make-score-map (type)
2820   "Make a summary score map of type TYPE."
2821   (if t
2822       nil
2823     (let ((headers '(("author" "from" string)
2824                      ("subject" "subject" string)
2825                      ("article body" "body" string)
2826                      ("article head" "head" string)
2827                      ("xref" "xref" string)
2828                      ("extra header" "extra" string)
2829                      ("lines" "lines" number)
2830                      ("followups to author" "followup" string)))
2831           (types '((number ("less than" <)
2832                            ("greater than" >)
2833                            ("equal" =))
2834                    (string ("substring" s)
2835                            ("exact string" e)
2836                            ("fuzzy string" f)
2837                            ("regexp" r))))
2838           (perms '(("temporary" (current-time-string))
2839                    ("permanent" nil)
2840                    ("immediate" now)))
2841           header)
2842       (list
2843        (apply
2844         'nconc
2845         (list
2846          (if (eq type 'lower)
2847              "Lower score"
2848            "Increase score"))
2849         (let (outh)
2850           (while headers
2851             (setq header (car headers))
2852             (setq outh
2853                   (cons
2854                    (apply
2855                     'nconc
2856                     (list (car header))
2857                     (let ((ts (cdr (assoc (nth 2 header) types)))
2858                           outt)
2859                       (while ts
2860                         (setq outt
2861                               (cons
2862                                (apply
2863                                 'nconc
2864                                 (list (caar ts))
2865                                 (let ((ps perms)
2866                                       outp)
2867                                   (while ps
2868                                     (setq outp
2869                                           (cons
2870                                            (vector
2871                                             (caar ps)
2872                                             (list
2873                                              'gnus-summary-score-entry
2874                                              (nth 1 header)
2875                                              (if (or (string= (nth 1 header)
2876                                                               "head")
2877                                                      (string= (nth 1 header)
2878                                                               "body"))
2879                                                  ""
2880                                                (list 'gnus-summary-header
2881                                                      (nth 1 header)))
2882                                              (list 'quote (nth 1 (car ts)))
2883                                              (list 'gnus-score-delta-default
2884                                                    nil)
2885                                              (nth 1 (car ps))
2886                                              t)
2887                                             t)
2888                                            outp))
2889                                     (setq ps (cdr ps)))
2890                                   (list (nreverse outp))))
2891                                outt))
2892                         (setq ts (cdr ts)))
2893                       (list (nreverse outt))))
2894                    outh))
2895             (setq headers (cdr headers)))
2896           (list (nreverse outh))))))))
2897
2898 \f
2899
2900 (defun gnus-summary-mode (&optional group)
2901   "Major mode for reading articles.
2902
2903 All normal editing commands are switched off.
2904 \\<gnus-summary-mode-map>
2905 Each line in this buffer represents one article.  To read an
2906 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2907 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2908 respectively.
2909
2910 You can also post articles and send mail from this buffer.  To
2911 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2912 of an article, type `\\[gnus-summary-reply]'.
2913
2914 There are approx. one gazillion commands you can execute in this
2915 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2916
2917 The following commands are available:
2918
2919 \\{gnus-summary-mode-map}"
2920   (interactive)
2921   (kill-all-local-variables)
2922   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2923     (gnus-summary-make-local-variables))
2924   (gnus-summary-make-local-variables)
2925   (setq gnus-newsgroup-name group)
2926   (when (gnus-visual-p 'summary-menu 'menu)
2927     (gnus-summary-make-menu-bar)
2928     (gnus-summary-make-tool-bar))
2929   (gnus-make-thread-indent-array)
2930   (gnus-simplify-mode-line)
2931   (setq major-mode 'gnus-summary-mode)
2932   (setq mode-name "Summary")
2933   (make-local-variable 'minor-mode-alist)
2934   (use-local-map gnus-summary-mode-map)
2935   (buffer-disable-undo)
2936   (setq buffer-read-only t              ;Disable modification
2937         show-trailing-whitespace nil)
2938   (setq truncate-lines t)
2939   (setq selective-display t)
2940   (setq selective-display-ellipses t)   ;Display `...'
2941   (gnus-summary-set-display-table)
2942   (gnus-set-default-directory)
2943   (make-local-variable 'gnus-summary-line-format)
2944   (make-local-variable 'gnus-summary-line-format-spec)
2945   (make-local-variable 'gnus-summary-dummy-line-format)
2946   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2947   (make-local-variable 'gnus-summary-mark-positions)
2948   (gnus-make-local-hook 'pre-command-hook)
2949   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2950   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
2951   (turn-on-gnus-mailing-list-mode)
2952   (mm-enable-multibyte)
2953   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2954   (gnus-update-summary-mark-positions))
2955
2956 (defun gnus-summary-make-local-variables ()
2957   "Make all the local summary buffer variables."
2958   (let (global)
2959     (dolist (local gnus-summary-local-variables)
2960       (if (consp local)
2961           (progn
2962             (if (eq (cdr local) 'global)
2963                 ;; Copy the global value of the variable.
2964                 (setq global (symbol-value (car local)))
2965               ;; Use the value from the list.
2966               (setq global (eval (cdr local))))
2967             (set (make-local-variable (car local)) global))
2968         ;; Simple nil-valued local variable.
2969         (set (make-local-variable local) nil)))))
2970
2971 (defun gnus-summary-clear-local-variables ()
2972   (let ((locals gnus-summary-local-variables))
2973     (while locals
2974       (if (consp (car locals))
2975           (and (symbolp (caar locals))
2976                (set (caar locals) nil))
2977         (and (symbolp (car locals))
2978              (set (car locals) nil)))
2979       (setq locals (cdr locals)))))
2980
2981 ;; Summary data functions.
2982
2983 (defmacro gnus-data-number (data)
2984   `(car ,data))
2985
2986 (defmacro gnus-data-set-number (data number)
2987   `(setcar ,data ,number))
2988
2989 (defmacro gnus-data-mark (data)
2990   `(nth 1 ,data))
2991
2992 (defmacro gnus-data-set-mark (data mark)
2993   `(setcar (nthcdr 1 ,data) ,mark))
2994
2995 (defmacro gnus-data-pos (data)
2996   `(nth 2 ,data))
2997
2998 (defmacro gnus-data-set-pos (data pos)
2999   `(setcar (nthcdr 2 ,data) ,pos))
3000
3001 (defmacro gnus-data-header (data)
3002   `(nth 3 ,data))
3003
3004 (defmacro gnus-data-set-header (data header)
3005   `(setf (nth 3 ,data) ,header))
3006
3007 (defmacro gnus-data-level (data)
3008   `(nth 4 ,data))
3009
3010 (defmacro gnus-data-unread-p (data)
3011   `(= (nth 1 ,data) gnus-unread-mark))
3012
3013 (defmacro gnus-data-read-p (data)
3014   `(/= (nth 1 ,data) gnus-unread-mark))
3015
3016 (defmacro gnus-data-pseudo-p (data)
3017   `(consp (nth 3 ,data)))
3018
3019 (defmacro gnus-data-find (number)
3020   `(assq ,number gnus-newsgroup-data))
3021
3022 (defmacro gnus-data-find-list (number &optional data)
3023   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3024      (memq (assq ,number bdata)
3025            bdata)))
3026
3027 (defmacro gnus-data-make (number mark pos header level)
3028   `(list ,number ,mark ,pos ,header ,level))
3029
3030 (defun gnus-data-enter (after-article number mark pos header level offset)
3031   (let ((data (gnus-data-find-list after-article)))
3032     (unless data
3033       (error "No such article: %d" after-article))
3034     (setcdr data (cons (gnus-data-make number mark pos header level)
3035                        (cdr data)))
3036     (setq gnus-newsgroup-data-reverse nil)
3037     (gnus-data-update-list (cddr data) offset)))
3038
3039 (defun gnus-data-enter-list (after-article list &optional offset)
3040   (when list
3041     (let ((data (and after-article (gnus-data-find-list after-article)))
3042           (ilist list))
3043       (if (not (or data
3044                    after-article))
3045           (let ((odata gnus-newsgroup-data))
3046             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3047             (when offset
3048               (gnus-data-update-list odata offset)))
3049         ;; Find the last element in the list to be spliced into the main
3050         ;; list.
3051         (setq list (last list))
3052         (if (not data)
3053             (progn
3054               (setcdr list gnus-newsgroup-data)
3055               (setq gnus-newsgroup-data ilist)
3056               (when offset
3057                 (gnus-data-update-list (cdr list) offset)))
3058           (setcdr list (cdr data))
3059           (setcdr data ilist)
3060           (when offset
3061             (gnus-data-update-list (cdr list) offset))))
3062       (setq gnus-newsgroup-data-reverse nil))))
3063
3064 (defun gnus-data-remove (article &optional offset)
3065   (let ((data gnus-newsgroup-data))
3066     (if (= (gnus-data-number (car data)) article)
3067         (progn
3068           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3069                 gnus-newsgroup-data-reverse nil)
3070           (when offset
3071             (gnus-data-update-list gnus-newsgroup-data offset)))
3072       (while (cdr data)
3073         (when (= (gnus-data-number (cadr data)) article)
3074           (setcdr data (cddr data))
3075           (when offset
3076             (gnus-data-update-list (cdr data) offset))
3077           (setq data nil
3078                 gnus-newsgroup-data-reverse nil))
3079         (setq data (cdr data))))))
3080
3081 (defmacro gnus-data-list (backward)
3082   `(if ,backward
3083        (or gnus-newsgroup-data-reverse
3084            (setq gnus-newsgroup-data-reverse
3085                  (reverse gnus-newsgroup-data)))
3086      gnus-newsgroup-data))
3087
3088 (defun gnus-data-update-list (data offset)
3089   "Add OFFSET to the POS of all data entries in DATA."
3090   (setq gnus-newsgroup-data-reverse nil)
3091   (while data
3092     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3093     (setq data (cdr data))))
3094
3095 (defun gnus-summary-article-pseudo-p (article)
3096   "Say whether this article is a pseudo article or not."
3097   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3098
3099 (defmacro gnus-summary-article-sparse-p (article)
3100   "Say whether this article is a sparse article or not."
3101   `(memq ,article gnus-newsgroup-sparse))
3102
3103 (defmacro gnus-summary-article-ancient-p (article)
3104   "Say whether this article is a sparse article or not."
3105   `(memq ,article gnus-newsgroup-ancient))
3106
3107 (defun gnus-article-parent-p (number)
3108   "Say whether this article is a parent or not."
3109   (let ((data (gnus-data-find-list number)))
3110     (and (cdr data)              ; There has to be an article after...
3111          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3112             (gnus-data-level (nth 1 data))))))
3113
3114 (defun gnus-article-children (number)
3115   "Return a list of all children to NUMBER."
3116   (let* ((data (gnus-data-find-list number))
3117          (level (gnus-data-level (car data)))
3118          children)
3119     (setq data (cdr data))
3120     (while (and data
3121                 (= (gnus-data-level (car data)) (1+ level)))
3122       (push (gnus-data-number (car data)) children)
3123       (setq data (cdr data)))
3124     children))
3125
3126 (defmacro gnus-summary-skip-intangible ()
3127   "If the current article is intangible, then jump to a different article."
3128   '(let ((to (get-text-property (point) 'gnus-intangible)))
3129      (and to (gnus-summary-goto-subject to))))
3130
3131 (defmacro gnus-summary-article-intangible-p ()
3132   "Say whether this article is intangible or not."
3133   '(get-text-property (point) 'gnus-intangible))
3134
3135 (defun gnus-article-read-p (article)
3136   "Say whether ARTICLE is read or not."
3137   (not (or (memq article gnus-newsgroup-marked)
3138            (memq article gnus-newsgroup-spam-marked)
3139            (memq article gnus-newsgroup-unreads)
3140            (memq article gnus-newsgroup-unselected)
3141            (memq article gnus-newsgroup-dormant))))
3142
3143 ;; Some summary mode macros.
3144
3145 (defmacro gnus-summary-article-number ()
3146   "The article number of the article on the current line.
3147 If there isn't an article number here, then we return the current
3148 article number."
3149   '(progn
3150      (gnus-summary-skip-intangible)
3151      (or (get-text-property (point) 'gnus-number)
3152          (gnus-summary-last-subject))))
3153
3154 (defmacro gnus-summary-article-header (&optional number)
3155   "Return the header of article NUMBER."
3156   `(gnus-data-header (gnus-data-find
3157                       ,(or number '(gnus-summary-article-number)))))
3158
3159 (defmacro gnus-summary-thread-level (&optional number)
3160   "Return the level of thread that starts with article NUMBER."
3161   `(if (and (eq gnus-summary-make-false-root 'dummy)
3162             (get-text-property (point) 'gnus-intangible))
3163        0
3164      (gnus-data-level (gnus-data-find
3165                        ,(or number '(gnus-summary-article-number))))))
3166
3167 (defmacro gnus-summary-article-mark (&optional number)
3168   "Return the mark of article NUMBER."
3169   `(gnus-data-mark (gnus-data-find
3170                     ,(or number '(gnus-summary-article-number)))))
3171
3172 (defmacro gnus-summary-article-pos (&optional number)
3173   "Return the position of the line of article NUMBER."
3174   `(gnus-data-pos (gnus-data-find
3175                    ,(or number '(gnus-summary-article-number)))))
3176
3177 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3178 (defmacro gnus-summary-article-subject (&optional number)
3179   "Return current subject string or nil if nothing."
3180   `(let ((headers
3181           ,(if number
3182                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3183              '(gnus-data-header (assq (gnus-summary-article-number)
3184                                       gnus-newsgroup-data)))))
3185      (and headers
3186           (vectorp headers)
3187           (mail-header-subject headers))))
3188
3189 (defmacro gnus-summary-article-score (&optional number)
3190   "Return current article score."
3191   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3192                   gnus-newsgroup-scored))
3193        gnus-summary-default-score 0))
3194
3195 (defun gnus-summary-article-children (&optional number)
3196   "Return a list of article numbers that are children of article NUMBER."
3197   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3198          (level (gnus-data-level (car data)))
3199          l children)
3200     (while (and (setq data (cdr data))
3201                 (> (setq l (gnus-data-level (car data))) level))
3202       (and (= (1+ level) l)
3203            (push (gnus-data-number (car data))
3204                  children)))
3205     (nreverse children)))
3206
3207 (defun gnus-summary-article-parent (&optional number)
3208   "Return the article number of the parent of article NUMBER."
3209   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3210                                     (gnus-data-list t)))
3211          (level (gnus-data-level (car data))))
3212     (if (zerop level)
3213         ()                              ; This is a root.
3214       ;; We search until we find an article with a level less than
3215       ;; this one.  That function has to be the parent.
3216       (while (and (setq data (cdr data))
3217                   (not (< (gnus-data-level (car data)) level))))
3218       (and data (gnus-data-number (car data))))))
3219
3220 (defun gnus-unread-mark-p (mark)
3221   "Say whether MARK is the unread mark."
3222   (= mark gnus-unread-mark))
3223
3224 (defun gnus-read-mark-p (mark)
3225   "Say whether MARK is one of the marks that mark as read.
3226 This is all marks except unread, ticked, dormant, and expirable."
3227   (not (or (= mark gnus-unread-mark)
3228            (= mark gnus-ticked-mark)
3229            (= mark gnus-spam-mark)
3230            (= mark gnus-dormant-mark)
3231            (= mark gnus-expirable-mark))))
3232
3233 (defmacro gnus-article-mark (number)
3234   "Return the MARK of article NUMBER.
3235 This macro should only be used when computing the mark the \"first\"
3236 time; i.e., when generating the summary lines.  After that,
3237 `gnus-summary-article-mark' should be used to examine the
3238 marks of articles."
3239   `(cond
3240     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3241     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3242     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3243     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3244     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3245     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3246     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3247     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3248            gnus-ancient-mark))))
3249
3250 ;; Saving hidden threads.
3251
3252 (defmacro gnus-save-hidden-threads (&rest forms)
3253   "Save hidden threads, eval FORMS, and restore the hidden threads."
3254   (let ((config (make-symbol "config")))
3255     `(let ((,config (gnus-hidden-threads-configuration)))
3256        (unwind-protect
3257            (save-excursion
3258              ,@forms)
3259          (gnus-restore-hidden-threads-configuration ,config)))))
3260 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3261 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3262
3263 (defun gnus-data-compute-positions ()
3264   "Compute the positions of all articles."
3265   (setq gnus-newsgroup-data-reverse nil)
3266   (let ((data gnus-newsgroup-data))
3267     (save-excursion
3268       (gnus-save-hidden-threads
3269         (gnus-summary-show-all-threads)
3270         (goto-char (point-min))
3271         (while data
3272           (while (get-text-property (point) 'gnus-intangible)
3273             (forward-line 1))
3274           (gnus-data-set-pos (car data) (+ (point) 3))
3275           (setq data (cdr data))
3276           (forward-line 1))))))
3277
3278 (defun gnus-hidden-threads-configuration ()
3279   "Return the current hidden threads configuration."
3280   (save-excursion
3281     (let (config)
3282       (goto-char (point-min))
3283       (while (search-forward "\r" nil t)
3284         (push (1- (point)) config))
3285       config)))
3286
3287 (defun gnus-restore-hidden-threads-configuration (config)
3288   "Restore hidden threads configuration from CONFIG."
3289   (save-excursion
3290     (let (point buffer-read-only)
3291       (while (setq point (pop config))
3292         (when (and (< point (point-max))
3293                    (goto-char point)
3294                    (eq (char-after) ?\n))
3295           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3296
3297 ;; Various summary mode internalish functions.
3298
3299 (defun gnus-mouse-pick-article (e)
3300   (interactive "e")
3301   (mouse-set-point e)
3302   (gnus-summary-next-page nil t))
3303
3304 (defun gnus-summary-set-display-table ()
3305   "Change the display table.
3306 Odd characters have a tendency to mess
3307 up nicely formatted displays - we make all possible glyphs
3308 display only a single character."
3309
3310   ;; We start from the standard display table, if any.
3311   (let ((table (or (copy-sequence standard-display-table)
3312                    (make-display-table)))
3313         (i 32))
3314     ;; Nix out all the control chars...
3315     (while (>= (setq i (1- i)) 0)
3316       (aset table i [??]))
3317    ;; ... but not newline and cr, of course.  (cr is necessary for the
3318     ;; selective display).
3319     (aset table ?\n nil)
3320     (aset table ?\r nil)
3321     ;; We keep TAB as well.
3322     (aset table ?\t nil)
3323     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3324     ;; Emacs 23 (unicode), that are not set already.
3325     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3326                  160
3327                256)))
3328       (while (>= (setq i (1- i)) 127)
3329         ;; Only modify if the entry is nil.
3330         (unless (aref table i)
3331           (aset table i [??]))))
3332     (setq buffer-display-table table)))
3333
3334 (defun gnus-summary-set-article-display-arrow (pos)
3335   "Update the overlay arrow to point to line at position POS."
3336   (when (and gnus-summary-display-arrow
3337              (boundp 'overlay-arrow-position)
3338              (boundp 'overlay-arrow-string))
3339     (save-excursion
3340       (goto-char pos)
3341       (beginning-of-line)
3342       (unless overlay-arrow-position
3343         (setq overlay-arrow-position (make-marker)))
3344       (setq overlay-arrow-string "=>"
3345             overlay-arrow-position (set-marker overlay-arrow-position
3346                                                (point)
3347                                                (current-buffer))))))
3348
3349 (defun gnus-summary-setup-buffer (group)
3350   "Initialize summary buffer."
3351   (let ((buffer (gnus-summary-buffer-name group))
3352         (dead-name (concat "*Dead Summary "
3353                            (gnus-group-decoded-name group) "*")))
3354     ;; If a dead summary buffer exists, we kill it.
3355     (when (gnus-buffer-live-p dead-name)
3356       (gnus-kill-buffer dead-name))
3357     (if (get-buffer buffer)
3358         (progn
3359           (set-buffer buffer)
3360           (setq gnus-summary-buffer (current-buffer))
3361           (not gnus-newsgroup-prepared))
3362       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3363       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3364       (gnus-summary-mode group)
3365       (when gnus-carpal
3366         (gnus-carpal-setup-buffer 'summary))
3367       (when (gnus-group-quit-config group)
3368         (set (make-local-variable 'gnus-single-article-buffer) nil))
3369       (make-local-variable 'gnus-article-buffer)
3370       (make-local-variable 'gnus-article-current)
3371       (make-local-variable 'gnus-original-article-buffer)
3372       (setq gnus-newsgroup-name group)
3373       ;; Set any local variables in the group parameters.
3374       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3375       t)))
3376
3377 (defun gnus-set-global-variables ()
3378   "Set the global equivalents of the buffer-local variables.
3379 They are set to the latest values they had.  These reflect the summary
3380 buffer that was in action when the last article was fetched."
3381   (when (eq major-mode 'gnus-summary-mode)
3382     (setq gnus-summary-buffer (current-buffer))
3383     (let ((name gnus-newsgroup-name)
3384           (marked gnus-newsgroup-marked)
3385           (spam gnus-newsgroup-spam-marked)
3386           (unread gnus-newsgroup-unreads)
3387           (headers gnus-current-headers)
3388           (data gnus-newsgroup-data)
3389           (summary gnus-summary-buffer)
3390           (article-buffer gnus-article-buffer)
3391           (original gnus-original-article-buffer)
3392           (gac gnus-article-current)
3393           (reffed gnus-reffed-article-number)
3394           (score-file gnus-current-score-file)
3395           (default-charset gnus-newsgroup-charset)
3396           vlist)
3397       (let ((locals gnus-newsgroup-variables))
3398         (while locals
3399           (if (consp (car locals))
3400               (push (eval (caar locals)) vlist)
3401             (push (eval (car locals)) vlist))
3402           (setq locals (cdr locals)))
3403         (setq vlist (nreverse vlist)))
3404       (with-current-buffer gnus-group-buffer
3405         (setq gnus-newsgroup-name name
3406               gnus-newsgroup-marked marked
3407               gnus-newsgroup-spam-marked spam
3408               gnus-newsgroup-unreads unread
3409               gnus-current-headers headers
3410               gnus-newsgroup-data data
3411               gnus-article-current gac
3412               gnus-summary-buffer summary
3413               gnus-article-buffer article-buffer
3414               gnus-original-article-buffer original
3415               gnus-reffed-article-number reffed
3416               gnus-current-score-file score-file
3417               gnus-newsgroup-charset default-charset)
3418         (let ((locals gnus-newsgroup-variables))
3419           (while locals
3420             (if (consp (car locals))
3421                 (set (caar locals) (pop vlist))
3422               (set (car locals) (pop vlist)))
3423             (setq locals (cdr locals))))
3424         ;; The article buffer also has local variables.
3425         (when (gnus-buffer-live-p gnus-article-buffer)
3426           (set-buffer gnus-article-buffer)
3427           (setq gnus-summary-buffer summary))))))
3428
3429 (defun gnus-summary-article-unread-p (article)
3430   "Say whether ARTICLE is unread or not."
3431   (memq article gnus-newsgroup-unreads))
3432
3433 (defun gnus-summary-first-article-p (&optional article)
3434   "Return whether ARTICLE is the first article in the buffer."
3435   (if (not (setq article (or article (gnus-summary-article-number))))
3436       nil
3437     (eq article (caar gnus-newsgroup-data))))
3438
3439 (defun gnus-summary-last-article-p (&optional article)
3440   "Return whether ARTICLE is the last article in the buffer."
3441   (if (not (setq article (or article (gnus-summary-article-number))))
3442       ;; All non-existent numbers are the last article.  :-)
3443       t
3444     (not (cdr (gnus-data-find-list article)))))
3445
3446 (defun gnus-make-thread-indent-array ()
3447   (let ((n 200))
3448     (unless (and gnus-thread-indent-array
3449                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3450       (setq gnus-thread-indent-array (make-vector 201 "")
3451             gnus-thread-indent-array-level gnus-thread-indent-level)
3452       (while (>= n 0)
3453         (aset gnus-thread-indent-array n
3454               (make-string (* n gnus-thread-indent-level) ? ))
3455         (setq n (1- n))))))
3456
3457 (defun gnus-update-summary-mark-positions ()
3458   "Compute where the summary marks are to go."
3459   (save-excursion
3460     (when (gnus-buffer-exists-p gnus-summary-buffer)
3461       (set-buffer gnus-summary-buffer))
3462     (let ((spec gnus-summary-line-format-spec)
3463           pos)
3464       (save-excursion
3465         (gnus-set-work-buffer)
3466         (let ((gnus-tmp-unread ?Z)
3467               (gnus-replied-mark ?Z)
3468               (gnus-score-below-mark ?Z)
3469               (gnus-score-over-mark ?Z)
3470               (gnus-undownloaded-mark ?Z)
3471               (gnus-summary-line-format-spec spec)
3472               (gnus-newsgroup-downloadable '(0))
3473               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3474               case-fold-search ignores)
3475           ;; Here, all marks are bound to Z.
3476           (gnus-summary-insert-line header
3477                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3478           (goto-char (point-min))
3479           ;; Memorize the positions of the same characters as dummy marks.
3480           (while (re-search-forward "[A-D]" nil t)
3481             (push (point) ignores))
3482           (erase-buffer)
3483           ;; We use A-D as dummy marks in order to know column positions
3484           ;; where marks should be inserted.
3485           (setq gnus-tmp-unread ?A
3486                 gnus-replied-mark ?B
3487                 gnus-score-below-mark ?C
3488                 gnus-score-over-mark ?C
3489                 gnus-undownloaded-mark ?D)
3490           (gnus-summary-insert-line header
3491                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3492           ;; Ignore characters which aren't dummy marks.
3493           (dolist (p ignores)
3494             (delete-region (goto-char (1- p)) p)
3495             (insert ?Z))
3496           (goto-char (point-min))
3497           (setq pos (list (cons 'unread
3498                                 (and (search-forward "A" nil t)
3499                                      (- (point) (point-min) 1)))))
3500           (goto-char (point-min))
3501           (push (cons 'replied (and (search-forward "B" nil t)
3502                                     (- (point) (point-min) 1)))
3503                 pos)
3504           (goto-char (point-min))
3505           (push (cons 'score (and (search-forward "C" nil t)
3506                                   (- (point) (point-min) 1)))
3507                 pos)
3508           (goto-char (point-min))
3509           (push (cons 'download (and (search-forward "D" nil t)
3510                                      (- (point) (point-min) 1)))
3511                 pos)))
3512       (setq gnus-summary-mark-positions pos))))
3513
3514 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3515   "Insert a dummy root in the summary buffer."
3516   (beginning-of-line)
3517   (gnus-add-text-properties
3518    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3519    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3520
3521 (defun gnus-summary-extract-address-component (from)
3522   (or (car (funcall gnus-extract-address-components from))
3523       from))
3524
3525 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3526   (let ((mail-parse-charset gnus-newsgroup-charset)
3527         ; Is it really necessary to do this next part for each summary line?
3528         ; Luckily, doesn't seem to slow things down much.
3529         (mail-parse-ignored-charsets
3530          (with-current-buffer gnus-summary-buffer
3531            gnus-newsgroup-ignored-charsets)))
3532     (or
3533      (and gnus-ignored-from-addresses
3534           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3535           (let ((extra-headers (mail-header-extra header))
3536                 to
3537                 newsgroups)
3538             (cond
3539              ((setq to (cdr (assq 'To extra-headers)))
3540               (concat gnus-summary-to-prefix
3541                       (inline
3542                         (gnus-summary-extract-address-component
3543                          (funcall gnus-decode-encoded-address-function to)))))
3544              ((setq newsgroups
3545                     (or
3546                      (cdr (assq 'Newsgroups extra-headers))
3547                      (and
3548                       (memq 'Newsgroups gnus-extra-headers)
3549                       (eq (car (gnus-find-method-for-group
3550                                 gnus-newsgroup-name)) 'nntp)
3551                       (gnus-group-real-name gnus-newsgroup-name))))
3552               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3553      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3554
3555 (defun gnus-summary-insert-line (gnus-tmp-header
3556                                  gnus-tmp-level gnus-tmp-current
3557                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3558                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3559                                  &optional gnus-tmp-dummy gnus-tmp-score
3560                                  gnus-tmp-process)
3561   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3562          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3563          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3564          (gnus-tmp-score-char
3565           (if (or (null gnus-summary-default-score)
3566                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3567                       gnus-summary-zcore-fuzz))
3568               ?                         ;Whitespace
3569             (if (< gnus-tmp-score gnus-summary-default-score)
3570                 gnus-score-below-mark gnus-score-over-mark)))
3571          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3572          (gnus-tmp-replied
3573           (cond (gnus-tmp-process gnus-process-mark)
3574                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3575                  gnus-cached-mark)
3576                 (gnus-tmp-replied gnus-replied-mark)
3577                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3578                  gnus-forwarded-mark)
3579                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3580                  gnus-saved-mark)
3581                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3582                  gnus-recent-mark)
3583                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3584                  gnus-unseen-mark)
3585                 (t gnus-no-mark)))
3586          (gnus-tmp-downloaded
3587           (cond (undownloaded
3588                  gnus-undownloaded-mark)
3589                 (gnus-newsgroup-agentized
3590                  gnus-downloaded-mark)
3591                 (t
3592                  gnus-no-mark)))
3593          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3594          (gnus-tmp-name
3595           (cond
3596            ((string-match "<[^>]+> *$" gnus-tmp-from)
3597             (let ((beg (match-beginning 0)))
3598               (or (and (string-match "^\".+\"" gnus-tmp-from)
3599                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3600                   (substring gnus-tmp-from 0 beg))))
3601            ((string-match "(.+)" gnus-tmp-from)
3602             (substring gnus-tmp-from
3603                        (1+ (match-beginning 0)) (1- (match-end 0))))
3604            (t gnus-tmp-from)))
3605          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3606          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3607          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3608          (buffer-read-only nil))
3609     (when (string= gnus-tmp-name "")
3610       (setq gnus-tmp-name gnus-tmp-from))
3611     (unless (numberp gnus-tmp-lines)
3612       (setq gnus-tmp-lines -1))
3613     (if (= gnus-tmp-lines -1)
3614         (setq gnus-tmp-lines "?")
3615       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3616       (gnus-put-text-property
3617      (point)
3618      (progn (eval gnus-summary-line-format-spec) (point))
3619        'gnus-number gnus-tmp-number)
3620     (when (gnus-visual-p 'summary-highlight 'highlight)
3621       (forward-line -1)
3622       (gnus-run-hooks 'gnus-summary-update-hook)
3623       (forward-line 1))))
3624
3625 (defun gnus-summary-update-line (&optional dont-update)
3626   "Update summary line after change."
3627   (when (and gnus-summary-default-score
3628              (not gnus-summary-inhibit-highlight))
3629     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3630            (article (gnus-summary-article-number))
3631            (score (gnus-summary-article-score article)))
3632       (unless dont-update
3633         (if (and gnus-summary-mark-below
3634                  (< (gnus-summary-article-score)
3635                     gnus-summary-mark-below))
3636             ;; This article has a low score, so we mark it as read.
3637             (when (memq article gnus-newsgroup-unreads)
3638               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3639           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3640             ;; This article was previously marked as read on account
3641             ;; of a low score, but now it has risen, so we mark it as
3642             ;; unread.
3643             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3644         (gnus-summary-update-mark
3645          (if (or (null gnus-summary-default-score)
3646                  (<= (abs (- score gnus-summary-default-score))
3647                      gnus-summary-zcore-fuzz))
3648              ?                          ;Whitespace
3649            (if (< score gnus-summary-default-score)
3650                gnus-score-below-mark gnus-score-over-mark))
3651          'score))
3652       ;; Do visual highlighting.
3653       (when (gnus-visual-p 'summary-highlight 'highlight)
3654         (gnus-run-hooks 'gnus-summary-update-hook)))))
3655
3656 (defvar gnus-tmp-new-adopts nil)
3657
3658 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3659   "Return the number of articles in THREAD.
3660 This may be 0 in some cases -- if none of the articles in
3661 the thread are to be displayed."
3662   (let* ((number
3663          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3664           (cond
3665            ((not (listp thread))
3666             1)
3667            ((and (consp thread) (cdr thread))
3668             (apply
3669              '+ 1 (mapcar
3670                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3671            ((null thread)
3672             1)
3673            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3674             1)
3675            (t 0))))
3676     (when (and level (zerop level) gnus-tmp-new-adopts)
3677       (incf number
3678             (apply '+ (mapcar
3679                        'gnus-summary-number-of-articles-in-thread
3680                        gnus-tmp-new-adopts))))
3681     (if char
3682         (if (> number 1) gnus-not-empty-thread-mark
3683           gnus-empty-thread-mark)
3684       number)))
3685
3686 (defsubst gnus-summary-line-message-size (head)
3687   "Return pretty-printed version of message size.
3688 This function is intended to be used in
3689 `gnus-summary-line-format-alist'."
3690   (let ((c (or (mail-header-chars head) -1)))
3691     (cond ((< c 0) "n/a")               ; chars not available
3692           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3693           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3694           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3695           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3696
3697
3698 (defun gnus-summary-set-local-parameters (group)
3699   "Go through the local params of GROUP and set all variable specs in that list."
3700   (let ((vars '(quit-config)))          ; Ignore quit-config.
3701     (dolist (elem (gnus-group-find-parameter group))
3702       (and (consp elem)                 ; Has to be a cons.
3703            (consp (cdr elem))           ; The cdr has to be a list.
3704            (symbolp (car elem))         ; Has to be a symbol in there.
3705            (not (memq (car elem) vars))
3706            (ignore-errors               ; So we set it.
3707              (push (car elem) vars)
3708              (make-local-variable (car elem))
3709              (set (car elem) (eval (nth 1 elem))))))))
3710
3711 (defun gnus-summary-read-group (group &optional show-all no-article
3712                                       kill-buffer no-display backward
3713                                       select-articles)
3714   "Start reading news in newsgroup GROUP.
3715 If SHOW-ALL is non-nil, already read articles are also listed.
3716 If NO-ARTICLE is non-nil, no article is selected initially.
3717 If NO-DISPLAY, don't generate a summary buffer."
3718   (let (result)
3719     (while (and group
3720                 (null (setq result
3721                             (let ((gnus-auto-select-next nil))
3722                               (or (gnus-summary-read-group-1
3723                                    group show-all no-article
3724                                    kill-buffer no-display
3725                                    select-articles)
3726                                   (setq show-all nil
3727                                         select-articles nil)))))
3728                 (eq gnus-auto-select-next 'quietly))
3729       (set-buffer gnus-group-buffer)
3730       ;; The entry function called above goes to the next
3731       ;; group automatically, so we go two groups back
3732       ;; if we are searching for the previous group.
3733       (when backward
3734         (gnus-group-prev-unread-group 2))
3735       (if (not (equal group (gnus-group-group-name)))
3736           (setq group (gnus-group-group-name))
3737         (setq group nil)))
3738     result))
3739
3740 (defun gnus-summary-read-group-1 (group show-all no-article
3741                                         kill-buffer no-display
3742                                         &optional select-articles)
3743   ;; Killed foreign groups can't be entered.
3744   ;;  (when (and (not (gnus-group-native-p group))
3745   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3746   ;;    (error "Dead non-native groups can't be entered"))
3747   (gnus-message 5 "Retrieving newsgroup: %s..."
3748                 (gnus-group-decoded-name group))
3749   (let* ((new-group (gnus-summary-setup-buffer group))
3750          (quit-config (gnus-group-quit-config group))
3751          (did-select (and new-group (gnus-select-newsgroup
3752                                      group show-all select-articles))))
3753     (cond
3754      ;; This summary buffer exists already, so we just select it.
3755      ((not new-group)
3756       (gnus-set-global-variables)
3757       (when kill-buffer
3758         (gnus-kill-or-deaden-summary kill-buffer))
3759       (gnus-configure-windows 'summary 'force)
3760       (gnus-set-mode-line 'summary)
3761       (gnus-summary-position-point)
3762       (message "")
3763       t)
3764      ;; We couldn't select this group.
3765      ((null did-select)
3766       (when (and (eq major-mode 'gnus-summary-mode)
3767                  (not (equal (current-buffer) kill-buffer)))
3768         (kill-buffer (current-buffer))
3769         (if (not quit-config)
3770             (progn
3771               ;; Update the info -- marks might need to be removed,
3772               ;; for instance.
3773               (gnus-summary-update-info)
3774               (set-buffer gnus-group-buffer)
3775               (gnus-group-jump-to-group group)
3776               (gnus-group-next-unread-group 1))
3777           (gnus-handle-ephemeral-exit quit-config)))
3778       (let ((grpinfo (gnus-get-info group)))
3779         (if (null (gnus-info-read grpinfo))
3780             (gnus-message 3 "Group %s contains no messages"
3781                           (gnus-group-decoded-name group))
3782           (gnus-message 3 "Can't select group")))
3783       nil)
3784      ;; The user did a `C-g' while prompting for number of articles,
3785      ;; so we exit this group.
3786      ((eq did-select 'quit)
3787       (and (eq major-mode 'gnus-summary-mode)
3788            (not (equal (current-buffer) kill-buffer))
3789            (kill-buffer (current-buffer)))
3790       (when kill-buffer
3791         (gnus-kill-or-deaden-summary kill-buffer))
3792       (if (not quit-config)
3793           (progn
3794             (set-buffer gnus-group-buffer)
3795             (gnus-group-jump-to-group group)
3796             (gnus-group-next-unread-group 1)
3797             (gnus-configure-windows 'group 'force))
3798         (gnus-handle-ephemeral-exit quit-config))
3799       ;; Finally signal the quit.
3800       (signal 'quit nil))
3801      ;; The group was successfully selected.
3802      (t
3803       (gnus-set-global-variables)
3804       ;; Save the active value in effect when the group was entered.
3805       (setq gnus-newsgroup-active
3806             (gnus-copy-sequence
3807              (gnus-active gnus-newsgroup-name)))
3808       ;; You can change the summary buffer in some way with this hook.
3809       (gnus-run-hooks 'gnus-select-group-hook)
3810       (when (memq 'summary (gnus-update-format-specifications
3811                             nil 'summary 'summary-mode 'summary-dummy))
3812         ;; The format specification for the summary line was updated,
3813         ;; so we need to update the mark positions as well.
3814         (gnus-update-summary-mark-positions))
3815       ;; Do score processing.
3816       (when gnus-use-scoring
3817         (gnus-possibly-score-headers))
3818       ;; Check whether to fill in the gaps in the threads.
3819       (when gnus-build-sparse-threads
3820         (gnus-build-sparse-threads))
3821       ;; Find the initial limit.
3822       (if show-all
3823           (let ((gnus-newsgroup-dormant nil))
3824             (gnus-summary-initial-limit show-all))
3825         (gnus-summary-initial-limit show-all))
3826       ;; Generate the summary buffer.
3827       (unless no-display
3828         (gnus-summary-prepare))
3829       (when gnus-use-trees
3830         (gnus-tree-open group)
3831         (setq gnus-summary-highlight-line-function
3832               'gnus-tree-highlight-article))
3833       ;; If the summary buffer is empty, but there are some low-scored
3834       ;; articles or some excluded dormants, we include these in the
3835       ;; buffer.
3836       (when (and (zerop (buffer-size))
3837                  (not no-display))
3838         (cond (gnus-newsgroup-dormant
3839                (gnus-summary-limit-include-dormant))
3840               ((and gnus-newsgroup-scored show-all)
3841                (gnus-summary-limit-include-expunged t))))
3842       ;; Function `gnus-apply-kill-file' must be called in this hook.
3843       (gnus-run-hooks 'gnus-apply-kill-hook)
3844       (if (and (zerop (buffer-size))
3845                (not no-display))
3846           (progn
3847             ;; This newsgroup is empty.
3848             (gnus-summary-catchup-and-exit nil t)
3849             (gnus-message 6 "No unread news")
3850             (when kill-buffer
3851               (gnus-kill-or-deaden-summary kill-buffer))
3852             ;; Return nil from this function.
3853             nil)
3854         ;; Hide conversation thread subtrees.  We cannot do this in
3855         ;; gnus-summary-prepare-hook since kill processing may not
3856         ;; work with hidden articles.
3857         (gnus-summary-maybe-hide-threads)
3858         (when kill-buffer
3859           (gnus-kill-or-deaden-summary kill-buffer))
3860         (gnus-summary-auto-select-subject)
3861         ;; Show first unread article if requested.
3862         (if (and (not no-article)
3863                  (not no-display)
3864                  gnus-newsgroup-unreads
3865                  gnus-auto-select-first)
3866             (progn
3867               (gnus-configure-windows 'summary)
3868               (let ((art (gnus-summary-article-number)))
3869                 (unless (and (not gnus-plugged)
3870                              (or (memq art gnus-newsgroup-undownloaded)
3871                                  (memq art gnus-newsgroup-downloadable)))
3872                   (gnus-summary-goto-article art))))
3873           ;; Don't select any articles.
3874           (gnus-summary-position-point)
3875           (gnus-configure-windows 'summary 'force)
3876           (gnus-set-mode-line 'summary))
3877         (when (and gnus-auto-center-group
3878                    (get-buffer-window gnus-group-buffer t))
3879           ;; Gotta use windows, because recenter does weird stuff if
3880           ;; the current buffer ain't the displayed window.
3881           (let ((owin (selected-window)))
3882             (select-window (get-buffer-window gnus-group-buffer t))
3883             (when (gnus-group-goto-group group)
3884               (recenter))
3885             (select-window owin)))
3886         ;; Mark this buffer as "prepared".
3887         (setq gnus-newsgroup-prepared t)
3888         (gnus-run-hooks 'gnus-summary-prepared-hook)
3889         (unless (gnus-ephemeral-group-p group)
3890           (gnus-group-update-group group))
3891         t)))))
3892
3893 (defun gnus-summary-auto-select-subject ()
3894   "Select the subject line on initial group entry."
3895   (goto-char (point-min))
3896   (cond
3897    ((eq gnus-auto-select-subject 'best)
3898     (gnus-summary-best-unread-subject))
3899    ((eq gnus-auto-select-subject 'unread)
3900     (gnus-summary-first-unread-subject))
3901    ((eq gnus-auto-select-subject 'unseen)
3902     (gnus-summary-first-unseen-subject))
3903    ((eq gnus-auto-select-subject 'unseen-or-unread)
3904     (gnus-summary-first-unseen-or-unread-subject))
3905    ((eq gnus-auto-select-subject 'first)
3906     ;; Do nothing.
3907     )
3908    ((functionp gnus-auto-select-subject)
3909     (funcall gnus-auto-select-subject))))
3910
3911 (defun gnus-summary-prepare ()
3912   "Generate the summary buffer."
3913   (interactive)
3914   (let ((buffer-read-only nil))
3915     (erase-buffer)
3916     (setq gnus-newsgroup-data nil
3917           gnus-newsgroup-data-reverse nil)
3918     (gnus-run-hooks 'gnus-summary-generate-hook)
3919     ;; Generate the buffer, either with threads or without.
3920     (when gnus-newsgroup-headers
3921       (gnus-summary-prepare-threads
3922        (if gnus-show-threads
3923            (gnus-sort-gathered-threads
3924             (funcall gnus-summary-thread-gathering-function
3925                      (gnus-sort-threads
3926                       (gnus-cut-threads (gnus-make-threads)))))
3927          ;; Unthreaded display.
3928          (gnus-sort-articles gnus-newsgroup-headers))))
3929     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3930     ;; Call hooks for modifying summary buffer.
3931     (goto-char (point-min))
3932     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3933
3934 (defsubst gnus-general-simplify-subject (subject)
3935   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3936   (setq subject
3937         (cond
3938          ;; Truncate the subject.
3939          (gnus-simplify-subject-functions
3940           (gnus-map-function gnus-simplify-subject-functions subject))
3941          ((numberp gnus-summary-gather-subject-limit)
3942           (setq subject (gnus-simplify-subject-re subject))
3943           (if (> (length subject) gnus-summary-gather-subject-limit)
3944               (substring subject 0 gnus-summary-gather-subject-limit)
3945             subject))
3946          ;; Fuzzily simplify it.
3947          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3948           (gnus-simplify-subject-fuzzy subject))
3949          ;; Just remove the leading "Re:".
3950          (t
3951           (gnus-simplify-subject-re subject))))
3952
3953   (if (and gnus-summary-gather-exclude-subject
3954            (string-match gnus-summary-gather-exclude-subject subject))
3955       nil                         ; This article shouldn't be gathered
3956     subject))
3957
3958 (defun gnus-summary-simplify-subject-query ()
3959   "Query where the respool algorithm would put this article."
3960   (interactive)
3961   (gnus-summary-select-article)
3962   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3963
3964 (defun gnus-gather-threads-by-subject (threads)
3965   "Gather threads by looking at Subject headers."
3966   (if (not gnus-summary-make-false-root)
3967       threads
3968     (let ((hashtb (gnus-make-hashtable 1024))
3969           (prev threads)
3970           (result threads)
3971           subject hthread whole-subject)
3972       (while threads
3973         (setq subject (gnus-general-simplify-subject
3974                        (setq whole-subject (mail-header-subject
3975                                             (caar threads)))))
3976         (when subject
3977           (if (setq hthread (gnus-gethash subject hashtb))
3978               (progn
3979                 ;; We enter a dummy root into the thread, if we
3980                 ;; haven't done that already.
3981                 (unless (stringp (caar hthread))
3982                   (setcar hthread (list whole-subject (car hthread))))
3983                 ;; We add this new gathered thread to this gathered
3984                 ;; thread.
3985                 (setcdr (car hthread)
3986                         (nconc (cdar hthread) (list (car threads))))
3987                 ;; Remove it from the list of threads.
3988                 (setcdr prev (cdr threads))
3989                 (setq threads prev))
3990             ;; Enter this thread into the hash table.
3991             (gnus-sethash subject
3992                           (if gnus-summary-make-false-root-always
3993                               (progn
3994                                 ;; If you want a dummy root above all
3995                                 ;; threads...
3996                                 (setcar threads (list whole-subject
3997                                                       (car threads)))
3998                                 threads)
3999                             threads)
4000                           hashtb)))
4001         (setq prev threads)
4002         (setq threads (cdr threads)))
4003       result)))
4004
4005 (defun gnus-gather-threads-by-references (threads)
4006   "Gather threads by looking at References headers."
4007   (let ((idhashtb (gnus-make-hashtable 1024))
4008         (thhashtb (gnus-make-hashtable 1024))
4009         (prev threads)
4010         (result threads)
4011         ids references id gthread gid entered ref)
4012     (while threads
4013       (when (setq references (mail-header-references (caar threads)))
4014         (setq id (mail-header-id (caar threads))
4015               ids (inline (gnus-split-references references))
4016               entered nil)
4017         (while (setq ref (pop ids))
4018           (setq ids (delete ref ids))
4019           (if (not (setq gid (gnus-gethash ref idhashtb)))
4020               (progn
4021                 (gnus-sethash ref id idhashtb)
4022                 (gnus-sethash id threads thhashtb))
4023             (setq gthread (gnus-gethash gid thhashtb))
4024             (unless entered
4025               ;; We enter a dummy root into the thread, if we
4026               ;; haven't done that already.
4027               (unless (stringp (caar gthread))
4028                 (setcar gthread (list (mail-header-subject (caar gthread))
4029                                       (car gthread))))
4030               ;; We add this new gathered thread to this gathered
4031               ;; thread.
4032               (setcdr (car gthread)
4033                       (nconc (cdar gthread) (list (car threads)))))
4034             ;; Add it into the thread hash table.
4035             (gnus-sethash id gthread thhashtb)
4036             (setq entered t)
4037             ;; Remove it from the list of threads.
4038             (setcdr prev (cdr threads))
4039             (setq threads prev))))
4040       (setq prev threads)
4041       (setq threads (cdr threads)))
4042     result))
4043
4044 (defun gnus-sort-gathered-threads (threads)
4045   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4046   (let ((result threads))
4047     (while threads
4048       (when (stringp (caar threads))
4049         (setcdr (car threads)
4050                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4051       (setq threads (cdr threads)))
4052     result))
4053
4054 (defun gnus-thread-loop-p (root thread)
4055   "Say whether ROOT is in THREAD."
4056   (let ((stack (list thread))
4057         (infloop 0)
4058         th)
4059     (while (setq thread (pop stack))
4060       (setq th (cdr thread))
4061       (while (and th
4062                   (not (eq (caar th) root)))
4063         (pop th))
4064       (if th
4065           ;; We have found a loop.
4066           (let (ref-dep)
4067             (setcdr thread (delq (car th) (cdr thread)))
4068             (if (boundp (setq ref-dep (intern "none"
4069                                               gnus-newsgroup-dependencies)))
4070                 (setcdr (symbol-value ref-dep)
4071                         (nconc (cdr (symbol-value ref-dep))
4072                                (list (car th))))
4073               (set ref-dep (list nil (car th))))
4074             (setq infloop 1
4075                   stack nil))
4076         ;; Push all the subthreads onto the stack.
4077         (push (cdr thread) stack)))
4078     infloop))
4079
4080 (defun gnus-make-threads ()
4081   "Go through the dependency hashtb and find the roots.  Return all threads."
4082   (let (threads)
4083     (while (catch 'infloop
4084              (mapatoms
4085               (lambda (refs)
4086                 ;; Deal with self-referencing References loops.
4087                 (when (and (car (symbol-value refs))
4088                            (not (zerop
4089                                  (apply
4090                                   '+
4091                                   (mapcar
4092                                    (lambda (thread)
4093                                      (gnus-thread-loop-p
4094                                       (car (symbol-value refs)) thread))
4095                                    (cdr (symbol-value refs)))))))
4096                   (setq threads nil)
4097                   (throw 'infloop t))
4098                 (unless (car (symbol-value refs))
4099                   ;; These threads do not refer back to any other
4100                   ;; articles, so they're roots.
4101                   (setq threads (append (cdr (symbol-value refs)) threads))))
4102               gnus-newsgroup-dependencies)))
4103     threads))
4104
4105 ;; Build the thread tree.
4106 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4107   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4108
4109 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4110 if it was already present.
4111
4112 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4113 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4114 Message-IDs will be renamed to a unique Message-ID before being
4115 entered.
4116
4117 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4118   (let* ((id (mail-header-id header))
4119          (id-dep (and id (intern id dependencies)))
4120          parent-id ref ref-dep ref-header replaced)
4121     ;; Enter this `header' in the `dependencies' table.
4122     (cond
4123      ((not id-dep)
4124       (setq header nil))
4125      ;; The first two cases do the normal part: enter a new `header'
4126      ;; in the `dependencies' table.
4127      ((not (boundp id-dep))
4128       (set id-dep (list header)))
4129      ((null (car (symbol-value id-dep)))
4130       (setcar (symbol-value id-dep) header))
4131
4132      ;; From here the `header' was already present in the
4133      ;; `dependencies' table.
4134      (force-new
4135       ;; Overrides an existing entry;
4136       ;; just set the header part of the entry.
4137       (setcar (symbol-value id-dep) header)
4138       (setq replaced t))
4139
4140      ;; Renames the existing `header' to a unique Message-ID.
4141      ((not gnus-summary-ignore-duplicates)
4142       ;; An article with this Message-ID has already been seen.
4143       ;; We rename the Message-ID.
4144       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4145            (list header))
4146       (mail-header-set-id header id))
4147
4148      ;; The last case ignores an existing entry, except it adds any
4149      ;; additional Xrefs (in case the two articles came from different
4150      ;; servers.
4151      ;; Also sets `header' to `nil' meaning that the `dependencies'
4152      ;; table was *not* modified.
4153      (t
4154       (mail-header-set-xref
4155        (car (symbol-value id-dep))
4156        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4157                    "")
4158                (or (mail-header-xref header) "")))
4159       (setq header nil)))
4160
4161     (when (and header (not replaced))
4162       ;; First check that we are not creating a References loop.
4163       (setq parent-id (gnus-parent-id (mail-header-references header)))
4164       (setq ref parent-id)
4165       (while (and ref
4166                   (setq ref-dep (intern-soft ref dependencies))
4167                   (boundp ref-dep)
4168                   (setq ref-header (car (symbol-value ref-dep))))
4169         (if (string= id ref)
4170             ;; Yuk!  This is a reference loop.  Make the article be a
4171             ;; root article.
4172             (progn
4173               (mail-header-set-references (car (symbol-value id-dep)) "none")
4174               (setq ref nil)
4175               (setq parent-id nil))
4176           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4177       (setq ref-dep (intern (or parent-id "none") dependencies))
4178       (if (boundp ref-dep)
4179           (setcdr (symbol-value ref-dep)
4180                   (nconc (cdr (symbol-value ref-dep))
4181                          (list (symbol-value id-dep))))
4182         (set ref-dep (list nil (symbol-value id-dep)))))
4183     header))
4184
4185 (defun gnus-extract-message-id-from-in-reply-to (string)
4186   (if (string-match "<[^>]+>" string)
4187       (substring string (match-beginning 0) (match-end 0))
4188     nil))
4189
4190 (defun gnus-build-sparse-threads ()
4191   (let ((headers gnus-newsgroup-headers)
4192         (mail-parse-charset gnus-newsgroup-charset)
4193         (gnus-summary-ignore-duplicates t)
4194         header references generation relations
4195         subject child end new-child date)
4196     ;; First we create an alist of generations/relations, where
4197     ;; generations is how much we trust the relation, and the relation
4198     ;; is parent/child.
4199     (gnus-message 7 "Making sparse threads...")
4200     (save-excursion
4201       (nnheader-set-temp-buffer " *gnus sparse threads*")
4202       (while (setq header (pop headers))
4203         (when (and (setq references (mail-header-references header))
4204                    (not (string= references "")))
4205           (insert references)
4206           (setq child (mail-header-id header)
4207                 subject (mail-header-subject header)
4208                 date (mail-header-date header)
4209                 generation 0)
4210           (while (search-backward ">" nil t)
4211             (setq end (1+ (point)))
4212             (when (search-backward "<" nil t)
4213               (setq new-child (buffer-substring (point) end))
4214               (push (list (incf generation)
4215                           child (setq child new-child)
4216                           subject date)
4217                     relations)))
4218           (when child
4219             (push (list (1+ generation) child nil subject) relations))
4220           (erase-buffer)))
4221       (kill-buffer (current-buffer)))
4222     ;; Sort over trustworthiness.
4223     (mapcar
4224      (lambda (relation)
4225        (when (gnus-dependencies-add-header
4226               (make-full-mail-header
4227                gnus-reffed-article-number
4228                (nth 3 relation) "" (or (nth 4 relation) "")
4229                (nth 1 relation)
4230                (or (nth 2 relation) "") 0 0 "")
4231               gnus-newsgroup-dependencies nil)
4232          (push gnus-reffed-article-number gnus-newsgroup-limit)
4233          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4234          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4235                gnus-newsgroup-reads)
4236          (decf gnus-reffed-article-number)))
4237      (sort relations 'car-less-than-car))
4238     (gnus-message 7 "Making sparse threads...done")))
4239
4240 (defun gnus-build-old-threads ()
4241   ;; Look at all the articles that refer back to old articles, and
4242   ;; fetch the headers for the articles that aren't there.  This will
4243   ;; build complete threads - if the roots haven't been expired by the
4244   ;; server, that is.
4245   (let ((mail-parse-charset gnus-newsgroup-charset)
4246         id heads)
4247     (mapatoms
4248      (lambda (refs)
4249        (when (not (car (symbol-value refs)))
4250          (setq heads (cdr (symbol-value refs)))
4251          (while heads
4252            (if (memq (mail-header-number (caar heads))
4253                      gnus-newsgroup-dormant)
4254                (setq heads (cdr heads))
4255              (setq id (symbol-name refs))
4256              (while (and (setq id (gnus-build-get-header id))
4257                          (not (car (gnus-id-to-thread id)))))
4258              (setq heads nil)))))
4259      gnus-newsgroup-dependencies)))
4260
4261 (defsubst gnus-remove-odd-characters (string)
4262   "Translate STRING into something that doesn't contain weird characters."
4263   (mm-subst-char-in-string
4264    ?\r ?\-
4265    (mm-subst-char-in-string ?\n ?\- string t) t))
4266
4267 ;; This function has to be called with point after the article number
4268 ;; on the beginning of the line.
4269 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4270   (let ((eol (point-at-eol))
4271         (buffer (current-buffer))
4272         header references in-reply-to)
4273
4274     ;; overview: [num subject from date id refs chars lines misc]
4275     (unwind-protect
4276         (let (x)
4277           (narrow-to-region (point) eol)
4278           (unless (eobp)
4279             (forward-char))
4280
4281           (setq header
4282                 (make-full-mail-header
4283                  number                 ; number
4284                  (condition-case ()     ; subject
4285                      (gnus-remove-odd-characters
4286                       (funcall gnus-decode-encoded-word-function
4287                                (setq x (nnheader-nov-field))))
4288                    (error x))
4289                  (condition-case ()     ; from
4290                      (gnus-remove-odd-characters
4291                       (funcall gnus-decode-encoded-address-function
4292                                (setq x (nnheader-nov-field))))
4293                    (error x))
4294                  (nnheader-nov-field)   ; date
4295                  (nnheader-nov-read-message-id number)  ; id
4296                  (setq references (nnheader-nov-field)) ; refs
4297                  (nnheader-nov-read-integer) ; chars
4298                  (nnheader-nov-read-integer) ; lines
4299                  (unless (eobp)
4300                    (if (looking-at "Xref: ")
4301                        (goto-char (match-end 0)))
4302                    (nnheader-nov-field)) ; Xref
4303                  (nnheader-nov-parse-extra)))) ; extra
4304
4305       (widen))
4306
4307     (when (and (string= references "")
4308                (setq in-reply-to (mail-header-extra header))
4309                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4310       (mail-header-set-references
4311        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4312
4313     (when gnus-alter-header-function
4314       (funcall gnus-alter-header-function header))
4315     (gnus-dependencies-add-header header dependencies force-new)))
4316
4317 (defun gnus-build-get-header (id)
4318   "Look through the buffer of NOV lines and find the header to ID.
4319 Enter this line into the dependencies hash table, and return
4320 the id of the parent article (if any)."
4321   (let ((deps gnus-newsgroup-dependencies)
4322         found header)
4323     (prog1
4324         (save-excursion
4325           (set-buffer nntp-server-buffer)
4326           (let ((case-fold-search nil))
4327             (goto-char (point-min))
4328             (while (and (not found)
4329                         (search-forward id nil t))
4330               (beginning-of-line)
4331               (setq found (looking-at
4332                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4333                                    (regexp-quote id))))
4334               (or found (beginning-of-line 2)))
4335             (when found
4336               (beginning-of-line)
4337               (and
4338                (setq header (gnus-nov-parse-line
4339                              (read (current-buffer)) deps))
4340                (gnus-parent-id (mail-header-references header))))))
4341       (when header
4342         (let ((number (mail-header-number header)))
4343           (push number gnus-newsgroup-limit)
4344           (push header gnus-newsgroup-headers)
4345           (if (memq number gnus-newsgroup-unselected)
4346               (progn
4347                 (setq gnus-newsgroup-unreads
4348                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4349                                                number))
4350                 (setq gnus-newsgroup-unselected
4351                       (delq number gnus-newsgroup-unselected)))
4352             (push number gnus-newsgroup-ancient)))))))
4353
4354 (defun gnus-build-all-threads ()
4355   "Read all the headers."
4356   (let ((gnus-summary-ignore-duplicates t)
4357         (mail-parse-charset gnus-newsgroup-charset)
4358         (dependencies gnus-newsgroup-dependencies)
4359         header article)
4360     (save-excursion
4361       (set-buffer nntp-server-buffer)
4362       (let ((case-fold-search nil))
4363         (goto-char (point-min))
4364         (while (not (eobp))
4365           (ignore-errors
4366             (setq article (read (current-buffer))
4367                   header (gnus-nov-parse-line article dependencies)))
4368           (when header
4369             (with-current-buffer gnus-summary-buffer
4370               (push header gnus-newsgroup-headers)
4371               (if (memq (setq article (mail-header-number header))
4372                         gnus-newsgroup-unselected)
4373                   (progn
4374                     (setq gnus-newsgroup-unreads
4375                           (gnus-add-to-sorted-list
4376                            gnus-newsgroup-unreads article))
4377                     (setq gnus-newsgroup-unselected
4378                           (delq article gnus-newsgroup-unselected)))
4379                 (push article gnus-newsgroup-ancient)))
4380             (forward-line 1)))))))
4381
4382 (defun gnus-summary-update-article-line (article header)
4383   "Update the line for ARTICLE using HEADER."
4384   (let* ((id (mail-header-id header))
4385          (thread (gnus-id-to-thread id)))
4386     (unless thread
4387       (error "Article in no thread"))
4388     ;; Update the thread.
4389     (setcar thread header)
4390     (gnus-summary-goto-subject article)
4391     (let* ((datal (gnus-data-find-list article))
4392            (data (car datal))
4393            (buffer-read-only nil)
4394            (level (gnus-summary-thread-level)))
4395       (gnus-delete-line)
4396       (let ((inserted (- (point)
4397                          (progn
4398                            (gnus-summary-insert-line
4399                             header level nil
4400                             (memq article gnus-newsgroup-undownloaded)
4401                             (gnus-article-mark article)
4402                             (memq article gnus-newsgroup-replied)
4403                             (memq article gnus-newsgroup-expirable)
4404                             ;; Only insert the Subject string when it's different
4405                             ;; from the previous Subject string.
4406                             (if (and
4407                                  gnus-show-threads
4408                                  (gnus-subject-equal
4409                                   (condition-case ()
4410                                       (mail-header-subject
4411                                        (gnus-data-header
4412                                         (cadr
4413                                          (gnus-data-find-list
4414                                           article
4415                                           (gnus-data-list t)))))
4416                                     ;; Error on the side of excessive subjects.
4417                                     (error ""))
4418                                   (mail-header-subject header)))
4419                                 ""
4420                               (mail-header-subject header))
4421                             nil (cdr (assq article gnus-newsgroup-scored))
4422                             (memq article gnus-newsgroup-processable))
4423                            (point)))))
4424         (when (cdr datal)
4425           (gnus-data-update-list
4426            (cdr datal)
4427            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4428
4429 (defun gnus-summary-update-article (article &optional iheader)
4430   "Update ARTICLE in the summary buffer."
4431   (set-buffer gnus-summary-buffer)
4432   (let* ((header (gnus-summary-article-header article))
4433          (id (mail-header-id header))
4434          (data (gnus-data-find article))
4435          (thread (gnus-id-to-thread id))
4436          (references (mail-header-references header))
4437          (parent
4438           (gnus-id-to-thread
4439            (or (gnus-parent-id
4440                 (when (and references
4441                            (not (equal "" references)))
4442                   references))
4443                "none")))
4444          (buffer-read-only nil)
4445          (old (car thread)))
4446     (when thread
4447       (unless iheader
4448         (setcar thread nil)
4449         (when parent
4450           (delq thread parent)))
4451       (if (gnus-summary-insert-subject id header)
4452           ;; Set the (possibly) new article number in the data structure.
4453           (gnus-data-set-number data (gnus-id-to-article id))
4454         (setcar thread old)
4455         nil))))
4456
4457 (defun gnus-rebuild-thread (id &optional line)
4458   "Rebuild the thread containing ID.
4459 If LINE, insert the rebuilt thread starting on line LINE."
4460   (let ((buffer-read-only nil)
4461         old-pos current thread data)
4462     (if (not gnus-show-threads)
4463         (setq thread (list (car (gnus-id-to-thread id))))
4464       ;; Get the thread this article is part of.
4465       (setq thread (gnus-remove-thread id)))
4466     (setq old-pos (point-at-bol))
4467     (setq current (save-excursion
4468                     (and (re-search-backward "[\r\n]" nil t)
4469                          (gnus-summary-article-number))))
4470     ;; If this is a gathered thread, we have to go some re-gathering.
4471     (when (stringp (car thread))
4472       (let ((subject (car thread))
4473             roots thr)
4474         (setq thread (cdr thread))
4475         (while thread
4476           (unless (memq (setq thr (gnus-id-to-thread
4477                                    (gnus-root-id
4478                                     (mail-header-id (caar thread)))))
4479                         roots)
4480             (push thr roots))
4481           (setq thread (cdr thread)))
4482         ;; We now have all (unique) roots.
4483         (if (= (length roots) 1)
4484             ;; All the loose roots are now one solid root.
4485             (setq thread (car roots))
4486           (setq thread (cons subject (gnus-sort-threads roots))))))
4487     (let (threads)
4488       ;; We then insert this thread into the summary buffer.
4489       (when line
4490         (goto-char (point-min))
4491         (forward-line (1- line)))
4492       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4493         (if gnus-show-threads
4494             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4495           (gnus-summary-prepare-unthreaded thread))
4496         (setq data (nreverse gnus-newsgroup-data))
4497         (setq threads gnus-newsgroup-threads))
4498       ;; We splice the new data into the data structure.
4499       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4500       ;;!!! then we want to insert at the beginning of the buffer.
4501       ;;!!! That happens to be true with Gnus now, but that may
4502       ;;!!! change in the future.  Perhaps.
4503       (gnus-data-enter-list
4504        (if line nil current) data (- (point) old-pos))
4505       (setq gnus-newsgroup-threads
4506             (nconc threads gnus-newsgroup-threads))
4507       (gnus-data-compute-positions))))
4508
4509 (defun gnus-number-to-header (number)
4510   "Return the header for article NUMBER."
4511   (let ((headers gnus-newsgroup-headers))
4512     (while (and headers
4513                 (not (= number (mail-header-number (car headers)))))
4514       (pop headers))
4515     (when headers
4516       (car headers))))
4517
4518 (defun gnus-parent-headers (in-headers &optional generation)
4519   "Return the headers of the GENERATIONeth parent of HEADERS."
4520   (unless generation
4521     (setq generation 1))
4522   (let ((parent t)
4523         (headers in-headers)
4524         references)
4525     (while (and parent
4526                 (not (zerop generation))
4527                 (setq references (mail-header-references headers)))
4528       (setq headers (if (and references
4529                              (setq parent (gnus-parent-id references)))
4530                         (car (gnus-id-to-thread parent))
4531                       nil))
4532       (decf generation))
4533     (and (not (eq headers in-headers))
4534          headers)))
4535
4536 (defun gnus-id-to-thread (id)
4537   "Return the (sub-)thread where ID appears."
4538   (gnus-gethash id gnus-newsgroup-dependencies))
4539
4540 (defun gnus-id-to-article (id)
4541   "Return the article number of ID."
4542   (let ((thread (gnus-id-to-thread id)))
4543     (when (and thread
4544                (car thread))
4545       (mail-header-number (car thread)))))
4546
4547 (defun gnus-id-to-header (id)
4548   "Return the article headers of ID."
4549   (car (gnus-id-to-thread id)))
4550
4551 (defun gnus-article-displayed-root-p (article)
4552   "Say whether ARTICLE is a root(ish) article."
4553   (let ((level (gnus-summary-thread-level article))
4554         (refs (mail-header-references  (gnus-summary-article-header article)))
4555         particle)
4556     (cond
4557      ((null level) nil)
4558      ((zerop level) t)
4559      ((null refs) t)
4560      ((null (gnus-parent-id refs)) t)
4561      ((and (= 1 level)
4562            (null (setq particle (gnus-id-to-article
4563                                  (gnus-parent-id refs))))
4564            (null (gnus-summary-thread-level particle)))))))
4565
4566 (defun gnus-root-id (id)
4567   "Return the id of the root of the thread where ID appears."
4568   (let (last-id prev)
4569     (while (and id (setq prev (car (gnus-id-to-thread id))))
4570       (setq last-id id
4571             id (gnus-parent-id (mail-header-references prev))))
4572     last-id))
4573
4574 (defun gnus-articles-in-thread (thread)
4575   "Return the list of articles in THREAD."
4576   (cons (mail-header-number (car thread))
4577         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4578
4579 (defun gnus-remove-thread (id &optional dont-remove)
4580   "Remove the thread that has ID in it."
4581   (let (headers thread last-id)
4582     ;; First go up in this thread until we find the root.
4583     (setq last-id (gnus-root-id id)
4584           headers (message-flatten-list (gnus-id-to-thread last-id)))
4585     ;; We have now found the real root of this thread.  It might have
4586     ;; been gathered into some loose thread, so we have to search
4587     ;; through the threads to find the thread we wanted.
4588     (let ((threads gnus-newsgroup-threads)
4589           sub)
4590       (while threads
4591         (setq sub (car threads))
4592         (if (stringp (car sub))
4593             ;; This is a gathered thread, so we look at the roots
4594             ;; below it to find whether this article is in this
4595             ;; gathered root.
4596             (progn
4597               (setq sub (cdr sub))
4598               (while sub
4599                 (when (member (caar sub) headers)
4600                   (setq thread (car threads)
4601                         threads nil
4602                         sub nil))
4603                 (setq sub (cdr sub))))
4604           ;; It's an ordinary thread, so we check it.
4605           (when (eq (car sub) (car headers))
4606             (setq thread sub
4607                   threads nil)))
4608         (setq threads (cdr threads)))
4609       ;; If this article is in no thread, then it's a root.
4610       (if thread
4611           (unless dont-remove
4612             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4613         (setq thread (gnus-id-to-thread last-id)))
4614       (when thread
4615         (prog1
4616             thread                      ; We return this thread.
4617           (unless dont-remove
4618             (if (stringp (car thread))
4619                 (progn
4620                   ;; If we use dummy roots, then we have to remove the
4621                   ;; dummy root as well.
4622                   (when (eq gnus-summary-make-false-root 'dummy)
4623                     ;; We go to the dummy root by going to
4624                     ;; the first sub-"thread", and then one line up.
4625                     (gnus-summary-goto-article
4626                      (mail-header-number (caadr thread)))
4627                     (forward-line -1)
4628                     (gnus-delete-line)
4629                     (gnus-data-compute-positions))
4630                   (setq thread (cdr thread))
4631                   (while thread
4632                     (gnus-remove-thread-1 (car thread))
4633                     (setq thread (cdr thread))))
4634               (gnus-remove-thread-1 thread))))))))
4635
4636 (defun gnus-remove-thread-1 (thread)
4637   "Remove the thread THREAD recursively."
4638   (let ((number (mail-header-number (pop thread)))
4639         d)
4640     (setq thread (reverse thread))
4641     (while thread
4642       (gnus-remove-thread-1 (pop thread)))
4643     (when (setq d (gnus-data-find number))
4644       (goto-char (gnus-data-pos d))
4645       (gnus-summary-show-thread)
4646       (gnus-data-remove
4647        number
4648        (- (point-at-bol)
4649           (prog1
4650               (1+ (point-at-eol))
4651             (gnus-delete-line)))))))
4652
4653 (defun gnus-sort-threads-1 (threads func)
4654   (sort (mapcar (lambda (thread)
4655                   (cons (car thread)
4656                         (and (cdr thread)
4657                              (gnus-sort-threads-1 (cdr thread) func))))
4658                 threads) func))
4659
4660 (defun gnus-sort-threads (threads)
4661   "Sort THREADS."
4662   (if (not gnus-thread-sort-functions)
4663       threads
4664     (gnus-message 8 "Sorting threads...")
4665     (let ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth)))
4666       (prog1 (gnus-sort-threads-1
4667          threads
4668          (gnus-make-sort-function gnus-thread-sort-functions))
4669         (gnus-message 8 "Sorting threads...done")))))
4670
4671 (defun gnus-sort-articles (articles)
4672   "Sort ARTICLES."
4673   (when gnus-article-sort-functions
4674     (gnus-message 7 "Sorting articles...")
4675     (prog1
4676         (setq gnus-newsgroup-headers
4677               (sort articles (gnus-make-sort-function
4678                               gnus-article-sort-functions)))
4679       (gnus-message 7 "Sorting articles...done"))))
4680
4681 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4682 (defmacro gnus-thread-header (thread)
4683   "Return header of first article in THREAD.
4684 Note that THREAD must never, ever be anything else than a variable -
4685 using some other form will lead to serious barfage."
4686   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4687   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4688   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4689         (vector thread) 2))
4690
4691 (defsubst gnus-article-sort-by-number (h1 h2)
4692   "Sort articles by article number."
4693   (< (mail-header-number h1)
4694      (mail-header-number h2)))
4695
4696 (defun gnus-thread-sort-by-number (h1 h2)
4697   "Sort threads by root article number."
4698   (gnus-article-sort-by-number
4699    (gnus-thread-header h1) (gnus-thread-header h2)))
4700
4701 (defsubst gnus-article-sort-by-random (h1 h2)
4702   "Sort articles by article number."
4703   (zerop (random 2)))
4704
4705 (defun gnus-thread-sort-by-random (h1 h2)
4706   "Sort threads by root article number."
4707   (gnus-article-sort-by-random
4708    (gnus-thread-header h1) (gnus-thread-header h2)))
4709
4710 (defsubst gnus-article-sort-by-lines (h1 h2)
4711   "Sort articles by article Lines header."
4712   (< (mail-header-lines h1)
4713      (mail-header-lines h2)))
4714
4715 (defun gnus-thread-sort-by-lines (h1 h2)
4716   "Sort threads by root article Lines header."
4717   (gnus-article-sort-by-lines
4718    (gnus-thread-header h1) (gnus-thread-header h2)))
4719
4720 (defsubst gnus-article-sort-by-chars (h1 h2)
4721   "Sort articles by octet length."
4722   (< (mail-header-chars h1)
4723      (mail-header-chars h2)))
4724
4725 (defun gnus-thread-sort-by-chars (h1 h2)
4726   "Sort threads by root article octet length."
4727   (gnus-article-sort-by-chars
4728    (gnus-thread-header h1) (gnus-thread-header h2)))
4729
4730 (defsubst gnus-article-sort-by-author (h1 h2)
4731   "Sort articles by root author."
4732   (string-lessp
4733    (let ((extract (funcall
4734                    gnus-extract-address-components
4735                    (mail-header-from h1))))
4736      (or (car extract) (cadr extract) ""))
4737    (let ((extract (funcall
4738                    gnus-extract-address-components
4739                    (mail-header-from h2))))
4740      (or (car extract) (cadr extract) ""))))
4741
4742 (defun gnus-thread-sort-by-author (h1 h2)
4743   "Sort threads by root author."
4744   (gnus-article-sort-by-author
4745    (gnus-thread-header h1)  (gnus-thread-header h2)))
4746
4747 (defsubst gnus-article-sort-by-recipient (h1 h2)
4748   "Sort articles by recipient."
4749   (string-lessp
4750    (let ((extract (funcall
4751                    gnus-extract-address-components
4752                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4753      (or (car extract) (cadr extract)))
4754    (let ((extract (funcall
4755                    gnus-extract-address-components
4756                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4757      (or (car extract) (cadr extract)))))
4758
4759 (defun gnus-thread-sort-by-recipient (h1 h2)
4760   "Sort threads by root recipient."
4761   (gnus-article-sort-by-recipient
4762    (gnus-thread-header h1) (gnus-thread-header h2)))
4763
4764 (defsubst gnus-article-sort-by-subject (h1 h2)
4765   "Sort articles by root subject."
4766   (string-lessp
4767    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4768    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4769
4770 (defun gnus-thread-sort-by-subject (h1 h2)
4771   "Sort threads by root subject."
4772   (gnus-article-sort-by-subject
4773    (gnus-thread-header h1) (gnus-thread-header h2)))
4774
4775 (defsubst gnus-article-sort-by-date (h1 h2)
4776   "Sort articles by root article date."
4777   (time-less-p
4778    (gnus-date-get-time (mail-header-date h1))
4779    (gnus-date-get-time (mail-header-date h2))))
4780
4781 (defun gnus-thread-sort-by-date (h1 h2)
4782   "Sort threads by root article date."
4783   (gnus-article-sort-by-date
4784    (gnus-thread-header h1) (gnus-thread-header h2)))
4785
4786 (defsubst gnus-article-sort-by-score (h1 h2)
4787   "Sort articles by root article score.
4788 Unscored articles will be counted as having a score of zero."
4789   (> (or (cdr (assq (mail-header-number h1)
4790                     gnus-newsgroup-scored))
4791          gnus-summary-default-score 0)
4792      (or (cdr (assq (mail-header-number h2)
4793                     gnus-newsgroup-scored))
4794          gnus-summary-default-score 0)))
4795
4796 (defun gnus-thread-sort-by-score (h1 h2)
4797   "Sort threads by root article score."
4798   (gnus-article-sort-by-score
4799    (gnus-thread-header h1) (gnus-thread-header h2)))
4800
4801 (defun gnus-thread-sort-by-total-score (h1 h2)
4802   "Sort threads by the sum of all scores in the thread.
4803 Unscored articles will be counted as having a score of zero."
4804   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4805
4806 (defun gnus-thread-total-score (thread)
4807   ;; This function find the total score of THREAD.
4808   (cond
4809    ((null thread)
4810     0)
4811    ((consp thread)
4812     (if (stringp (car thread))
4813         (apply gnus-thread-score-function 0
4814                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4815       (gnus-thread-total-score-1 thread)))
4816    (t
4817     (gnus-thread-total-score-1 (list thread)))))
4818
4819 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4820   "Sort threads such that the thread with the most recently arrived article comes first."
4821   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4822
4823 (defun gnus-thread-highest-number (thread)
4824   "Return the highest article number in THREAD."
4825   (apply 'max (mapcar (lambda (header)
4826                         (mail-header-number header))
4827                       (message-flatten-list thread))))
4828
4829 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4830   "Sort threads such that the thread with the most recently dated article comes first."
4831   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4832
4833 (defun gnus-thread-latest-date (thread)
4834   "Return the highest article date in THREAD."
4835   (let ((previous-time 0))
4836     (apply 'max
4837            (mapcar
4838             (lambda (header)
4839               (setq previous-time
4840                     (condition-case ()
4841                         (time-to-seconds (mail-header-parse-date
4842                                           (mail-header-date header)))
4843                       (error previous-time))))
4844             (sort
4845              (message-flatten-list thread)
4846              (lambda (h1 h2)
4847                (< (mail-header-number h1)
4848                   (mail-header-number h2))))))))
4849
4850 (defun gnus-thread-total-score-1 (root)
4851   ;; This function find the total score of the thread below ROOT.
4852   (setq root (car root))
4853   (apply gnus-thread-score-function
4854          (or (append
4855               (mapcar 'gnus-thread-total-score
4856                       (cdr (gnus-id-to-thread (mail-header-id root))))
4857               (when (> (mail-header-number root) 0)
4858                 (list (or (cdr (assq (mail-header-number root)
4859                                      gnus-newsgroup-scored))
4860                           gnus-summary-default-score 0))))
4861              (list gnus-summary-default-score)
4862              '(0))))
4863
4864 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4865 (defvar gnus-tmp-prev-subject nil)
4866 (defvar gnus-tmp-false-parent nil)
4867 (defvar gnus-tmp-root-expunged nil)
4868 (defvar gnus-tmp-dummy-line nil)
4869
4870 (eval-when-compile (defvar gnus-tmp-header))
4871 (defun gnus-extra-header (type &optional header)
4872   "Return the extra header of TYPE."
4873   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4874       ""))
4875
4876 (defvar gnus-tmp-thread-tree-header-string "")
4877
4878 (defcustom gnus-sum-thread-tree-root "> "
4879   "With %B spec, used for the root of a thread.
4880 If nil, use subject instead."
4881   :version "22.1"
4882   :type '(radio (const :format "%v  " nil) string)
4883   :group 'gnus-thread)
4884
4885 (defcustom gnus-sum-thread-tree-false-root "> "
4886   "With %B spec, used for a false root of a thread.
4887 If nil, use subject instead."
4888   :version "22.1"
4889   :type '(radio (const :format "%v  " nil) string)
4890   :group 'gnus-thread)
4891
4892 (defcustom gnus-sum-thread-tree-single-indent ""
4893   "With %B spec, used for a thread with just one message.
4894 If nil, use subject instead."
4895   :version "22.1"
4896   :type '(radio (const :format "%v  " nil) string)
4897   :group 'gnus-thread)
4898
4899 (defcustom gnus-sum-thread-tree-vertical "| "
4900   "With %B spec, used for drawing a vertical line."
4901   :version "22.1"
4902   :type 'string
4903   :group 'gnus-thread)
4904
4905 (defcustom gnus-sum-thread-tree-indent "  "
4906   "With %B spec, used for indenting."
4907   :version "22.1"
4908   :type 'string
4909   :group 'gnus-thread)
4910
4911 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4912   "With %B spec, used for a leaf with brothers."
4913   :version "22.1"
4914   :type 'string
4915   :group 'gnus-thread)
4916
4917 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4918   "With %B spec, used for a leaf without brothers."
4919   :version "22.1"
4920   :type 'string
4921   :group 'gnus-thread)
4922
4923 (defun gnus-summary-prepare-threads (threads)
4924   "Prepare summary buffer from THREADS and indentation LEVEL.
4925 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4926 or a straight list of headers."
4927   (gnus-message 7 "Generating summary...")
4928
4929   (setq gnus-newsgroup-threads threads)
4930   (beginning-of-line)
4931
4932   (let ((gnus-tmp-level 0)
4933         (default-score (or gnus-summary-default-score 0))
4934         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4935         (building-line-count gnus-summary-display-while-building)
4936         (building-count (integerp gnus-summary-display-while-building))
4937         thread number subject stack state gnus-tmp-gathered beg-match
4938         new-roots gnus-tmp-new-adopts thread-end simp-subject
4939         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4940         gnus-tmp-replied gnus-tmp-subject-or-nil
4941         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4942         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4943         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4944         tree-stack)
4945
4946     (setq gnus-tmp-prev-subject nil
4947           gnus-tmp-thread-tree-header-string "")
4948
4949     (if (vectorp (car threads))
4950         ;; If this is a straight (sic) list of headers, then a
4951         ;; threaded summary display isn't required, so we just create
4952         ;; an unthreaded one.
4953         (gnus-summary-prepare-unthreaded threads)
4954
4955       ;; Do the threaded display.
4956
4957       (if gnus-summary-display-while-building
4958           (switch-to-buffer (buffer-name)))
4959       (while (or threads stack gnus-tmp-new-adopts new-roots)
4960
4961         (if (and (= gnus-tmp-level 0)
4962                  (or (not stack)
4963                      (= (caar stack) 0))
4964                  (not gnus-tmp-false-parent)
4965                  (or gnus-tmp-new-adopts new-roots))
4966             (if gnus-tmp-new-adopts
4967                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4968                       thread (list (car gnus-tmp-new-adopts))
4969                       gnus-tmp-header (caar thread)
4970                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4971               (when new-roots
4972                 (setq thread (list (car new-roots))
4973                       gnus-tmp-header (caar thread)
4974                       new-roots (cdr new-roots))))
4975
4976           (if threads
4977               ;; If there are some threads, we do them before the
4978               ;; threads on the stack.
4979               (setq thread threads
4980                     gnus-tmp-header (caar thread))
4981             ;; There were no current threads, so we pop something off
4982             ;; the stack.
4983             (setq state (car stack)
4984                   gnus-tmp-level (car state)
4985                   tree-stack (cadr state)
4986                   thread (caddr state)
4987                   stack (cdr stack)
4988                   gnus-tmp-header (caar thread))))
4989
4990         (setq gnus-tmp-false-parent nil)
4991         (setq gnus-tmp-root-expunged nil)
4992         (setq thread-end nil)
4993
4994         (if (stringp gnus-tmp-header)
4995             ;; The header is a dummy root.
4996             (cond
4997              ((eq gnus-summary-make-false-root 'adopt)
4998               ;; We let the first article adopt the rest.
4999               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5000                                                (cddar thread)))
5001               (setq gnus-tmp-gathered
5002                     (nconc (mapcar
5003                             (lambda (h) (mail-header-number (car h)))
5004                             (cddar thread))
5005                            gnus-tmp-gathered))
5006               (setq thread (cons (list (caar thread)
5007                                        (cadar thread))
5008                                  (cdr thread)))
5009               (setq gnus-tmp-level -1
5010                     gnus-tmp-false-parent t))
5011              ((eq gnus-summary-make-false-root 'empty)
5012               ;; We print adopted articles with empty subject fields.
5013               (setq gnus-tmp-gathered
5014                     (nconc (mapcar
5015                             (lambda (h) (mail-header-number (car h)))
5016                             (cddar thread))
5017                            gnus-tmp-gathered))
5018               (setq gnus-tmp-level -1))
5019              ((eq gnus-summary-make-false-root 'dummy)
5020               ;; We remember that we probably want to output a dummy
5021               ;; root.
5022               (setq gnus-tmp-dummy-line gnus-tmp-header)
5023               (setq gnus-tmp-prev-subject gnus-tmp-header))
5024              (t
5025               ;; We do not make a root for the gathered
5026               ;; sub-threads at all.
5027               (setq gnus-tmp-level -1)))
5028
5029           (setq number (mail-header-number gnus-tmp-header)
5030                 subject (mail-header-subject gnus-tmp-header)
5031                 simp-subject (gnus-simplify-subject-fully subject))
5032
5033           (cond
5034            ;; If the thread has changed subject, we might want to make
5035            ;; this subthread into a root.
5036            ((and (null gnus-thread-ignore-subject)
5037                  (not (zerop gnus-tmp-level))
5038                  gnus-tmp-prev-subject
5039                  (not (string= gnus-tmp-prev-subject simp-subject)))
5040             (setq new-roots (nconc new-roots (list (car thread)))
5041                   thread-end t
5042                   gnus-tmp-header nil))
5043            ;; If the article lies outside the current limit,
5044            ;; then we do not display it.
5045            ((not (memq number gnus-newsgroup-limit))
5046             (setq gnus-tmp-gathered
5047                   (nconc (mapcar
5048                           (lambda (h) (mail-header-number (car h)))
5049                           (cdar thread))
5050                          gnus-tmp-gathered))
5051             (setq gnus-tmp-new-adopts (if (cdar thread)
5052                                           (append gnus-tmp-new-adopts
5053                                                   (cdar thread))
5054                                         gnus-tmp-new-adopts)
5055                   thread-end t
5056                   gnus-tmp-header nil)
5057             (when (zerop gnus-tmp-level)
5058               (setq gnus-tmp-root-expunged t)))
5059            ;; Perhaps this article is to be marked as read?
5060            ((and gnus-summary-mark-below
5061                  (< (or (cdr (assq number gnus-newsgroup-scored))
5062                         default-score)
5063                     gnus-summary-mark-below)
5064                  ;; Don't touch sparse articles.
5065                  (not (gnus-summary-article-sparse-p number))
5066                  (not (gnus-summary-article-ancient-p number)))
5067             (setq gnus-newsgroup-unreads
5068                   (delq number gnus-newsgroup-unreads))
5069             (if gnus-newsgroup-auto-expire
5070                 (setq gnus-newsgroup-expirable
5071                       (gnus-add-to-sorted-list
5072                        gnus-newsgroup-expirable number))
5073               (push (cons number gnus-low-score-mark)
5074                     gnus-newsgroup-reads))))
5075
5076           (when gnus-tmp-header
5077             ;; We may have an old dummy line to output before this
5078             ;; article.
5079             (when (and gnus-tmp-dummy-line
5080                        (gnus-subject-equal
5081                         gnus-tmp-dummy-line
5082                         (mail-header-subject gnus-tmp-header)))
5083               (gnus-summary-insert-dummy-line
5084                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5085               (setq gnus-tmp-dummy-line nil))
5086
5087             ;; Compute the mark.
5088             (setq gnus-tmp-unread (gnus-article-mark number))
5089
5090             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5091                                   gnus-tmp-header gnus-tmp-level)
5092                   gnus-newsgroup-data)
5093
5094             ;; Actually insert the line.
5095             (setq
5096              gnus-tmp-subject-or-nil
5097              (cond
5098               ((and gnus-thread-ignore-subject
5099                     gnus-tmp-prev-subject
5100                     (not (string= gnus-tmp-prev-subject simp-subject)))
5101                subject)
5102               ((zerop gnus-tmp-level)
5103                (if (and (eq gnus-summary-make-false-root 'empty)
5104                         (memq number gnus-tmp-gathered)
5105                         gnus-tmp-prev-subject
5106                         (string= gnus-tmp-prev-subject simp-subject))
5107                    gnus-summary-same-subject
5108                  subject))
5109               (t gnus-summary-same-subject)))
5110             (if (and (eq gnus-summary-make-false-root 'adopt)
5111                      (= gnus-tmp-level 1)
5112                      (memq number gnus-tmp-gathered))
5113                 (setq gnus-tmp-opening-bracket ?\<
5114                       gnus-tmp-closing-bracket ?\>)
5115               (setq gnus-tmp-opening-bracket ?\[
5116                     gnus-tmp-closing-bracket ?\]))
5117             (setq
5118              gnus-tmp-indentation
5119              (aref gnus-thread-indent-array gnus-tmp-level)
5120              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5121              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5122                                 gnus-summary-default-score 0)
5123              gnus-tmp-score-char
5124              (if (or (null gnus-summary-default-score)
5125                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5126                          gnus-summary-zcore-fuzz))
5127                  ?                      ;Whitespace
5128                (if (< gnus-tmp-score gnus-summary-default-score)
5129                    gnus-score-below-mark gnus-score-over-mark))
5130              gnus-tmp-replied
5131              (cond ((memq number gnus-newsgroup-processable)
5132                     gnus-process-mark)
5133                    ((memq number gnus-newsgroup-cached)
5134                     gnus-cached-mark)
5135                    ((memq number gnus-newsgroup-replied)
5136                     gnus-replied-mark)
5137                    ((memq number gnus-newsgroup-forwarded)
5138                     gnus-forwarded-mark)
5139                    ((memq number gnus-newsgroup-saved)
5140                     gnus-saved-mark)
5141                    ((memq number gnus-newsgroup-recent)
5142                     gnus-recent-mark)
5143                    ((memq number gnus-newsgroup-unseen)
5144                     gnus-unseen-mark)
5145                    (t gnus-no-mark))
5146              gnus-tmp-downloaded
5147              (cond ((memq number gnus-newsgroup-undownloaded)
5148                     gnus-undownloaded-mark)
5149                    (gnus-newsgroup-agentized
5150                     gnus-downloaded-mark)
5151                    (t
5152                     gnus-no-mark))
5153              gnus-tmp-from (mail-header-from gnus-tmp-header)
5154              gnus-tmp-name
5155              (cond
5156               ((string-match "<[^>]+> *$" gnus-tmp-from)
5157                (setq beg-match (match-beginning 0))
5158                (or (and (string-match "^\".+\"" gnus-tmp-from)
5159                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5160                    (substring gnus-tmp-from 0 beg-match)))
5161               ((string-match "(.+)" gnus-tmp-from)
5162                (substring gnus-tmp-from
5163                           (1+ (match-beginning 0)) (1- (match-end 0))))
5164               (t gnus-tmp-from))
5165
5166              ;; Do the %B string
5167              gnus-tmp-thread-tree-header-string
5168              (cond
5169               ((not gnus-show-threads) "")
5170               ((zerop gnus-tmp-level)
5171                (cond ((cdar thread)
5172                       (or gnus-sum-thread-tree-root subject))
5173                      (gnus-tmp-new-adopts
5174                       (or gnus-sum-thread-tree-false-root subject))
5175                      (t
5176                       (or gnus-sum-thread-tree-single-indent subject))))
5177               (t
5178                (concat (apply 'concat
5179                               (mapcar (lambda (item)
5180                                         (if (= item 1)
5181                                             gnus-sum-thread-tree-vertical
5182                                           gnus-sum-thread-tree-indent))
5183                                       (cdr (reverse tree-stack))))
5184                        (if (nth 1 thread)
5185                            gnus-sum-thread-tree-leaf-with-other
5186                          gnus-sum-thread-tree-single-leaf)))))
5187             (when (string= gnus-tmp-name "")
5188               (setq gnus-tmp-name gnus-tmp-from))
5189             (unless (numberp gnus-tmp-lines)
5190               (setq gnus-tmp-lines -1))
5191             (if (= gnus-tmp-lines -1)
5192                 (setq gnus-tmp-lines "?")
5193               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5194               (gnus-put-text-property
5195              (point)
5196              (progn (eval gnus-summary-line-format-spec) (point))
5197                'gnus-number number)
5198             (when gnus-visual-p
5199               (forward-line -1)
5200               (gnus-run-hooks 'gnus-summary-update-hook)
5201               (forward-line 1))
5202
5203             (setq gnus-tmp-prev-subject simp-subject)))
5204
5205         (when (nth 1 thread)
5206           (push (list (max 0 gnus-tmp-level)
5207                       (copy-sequence tree-stack)
5208                       (nthcdr 1 thread))
5209                 stack))
5210         (push (if (nth 1 thread) 1 0) tree-stack)
5211         (incf gnus-tmp-level)
5212         (setq threads (if thread-end nil (cdar thread)))
5213         (if gnus-summary-display-while-building
5214             (if building-count
5215                 (progn
5216                   ;; use a set frequency
5217                   (setq building-line-count (1- building-line-count))
5218                   (when (= building-line-count 0)
5219                     (sit-for 0)
5220                     (setq building-line-count
5221                           gnus-summary-display-while-building)))
5222               ;; always
5223               (sit-for 0)))
5224         (unless threads
5225           (setq gnus-tmp-level 0)))))
5226   (gnus-message 7 "Generating summary...done"))
5227
5228 (defun gnus-summary-prepare-unthreaded (headers)
5229   "Generate an unthreaded summary buffer based on HEADERS."
5230   (let (header number mark)
5231
5232     (beginning-of-line)
5233
5234     (while headers
5235       ;; We may have to root out some bad articles...
5236       (when (memq (setq number (mail-header-number
5237                                 (setq header (pop headers))))
5238                   gnus-newsgroup-limit)
5239         ;; Mark article as read when it has a low score.
5240         (when (and gnus-summary-mark-below
5241                    (< (or (cdr (assq number gnus-newsgroup-scored))
5242                           gnus-summary-default-score 0)
5243                       gnus-summary-mark-below)
5244                    (not (gnus-summary-article-ancient-p number)))
5245           (setq gnus-newsgroup-unreads
5246                 (delq number gnus-newsgroup-unreads))
5247           (if gnus-newsgroup-auto-expire
5248               (push number gnus-newsgroup-expirable)
5249             (push (cons number gnus-low-score-mark)
5250                   gnus-newsgroup-reads)))
5251
5252         (setq mark (gnus-article-mark number))
5253         (push (gnus-data-make number mark (1+ (point)) header 0)
5254               gnus-newsgroup-data)
5255         (gnus-summary-insert-line
5256          header 0 number
5257          (memq number gnus-newsgroup-undownloaded)
5258          mark (memq number gnus-newsgroup-replied)
5259          (memq number gnus-newsgroup-expirable)
5260          (mail-header-subject header) nil
5261          (cdr (assq number gnus-newsgroup-scored))
5262          (memq number gnus-newsgroup-processable))))))
5263
5264 (defun gnus-summary-remove-list-identifiers ()
5265   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5266   (let ((regexp (if (consp gnus-list-identifiers)
5267                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5268                   gnus-list-identifiers))
5269         changed subject)
5270     (when regexp
5271       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5272       (dolist (header gnus-newsgroup-headers)
5273         (setq subject (mail-header-subject header)
5274               changed nil)
5275         (while (string-match regexp subject)
5276           (setq subject
5277                 (concat (substring subject 0 (match-beginning 1))
5278                         (substring subject (match-end 0)))
5279                 changed t))
5280         (when changed
5281           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5282             (setq subject
5283                   (concat (substring subject 0 (match-beginning 1))
5284                           (substring subject (match-end 1)))))
5285           (mail-header-set-subject header subject))))))
5286
5287 (defun gnus-fetch-headers (articles)
5288   "Fetch headers of ARTICLES."
5289   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5290     (gnus-message 5 "Fetching headers for %s..." name)
5291     (prog1
5292         (if (eq 'nov
5293                 (setq gnus-headers-retrieved-by
5294                       (gnus-retrieve-headers
5295                        articles gnus-newsgroup-name
5296                        ;; We might want to fetch old headers, but
5297                        ;; not if there is only 1 article.
5298                        (and (or (and
5299                                  (not (eq gnus-fetch-old-headers 'some))
5300                                  (not (numberp gnus-fetch-old-headers)))
5301                                 (> (length articles) 1))
5302                             gnus-fetch-old-headers))))
5303             (gnus-get-newsgroup-headers-xover
5304              articles nil nil gnus-newsgroup-name t)
5305           (gnus-get-newsgroup-headers))
5306       (gnus-message 5 "Fetching headers for %s...done" name))))
5307
5308 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5309   "Select newsgroup GROUP.
5310 If READ-ALL is non-nil, all articles in the group are selected.
5311 If SELECT-ARTICLES, only select those articles from GROUP."
5312   (let* ((entry (gnus-group-entry group))
5313          ;;!!! Dirty hack; should be removed.
5314          (gnus-summary-ignore-duplicates
5315           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5316               t
5317             gnus-summary-ignore-duplicates))
5318          (info (nth 2 entry))
5319          articles fetched-articles cached)
5320
5321     (unless (gnus-check-server
5322              (set (make-local-variable 'gnus-current-select-method)
5323                   (gnus-find-method-for-group group)))
5324       (error "Couldn't open server"))
5325
5326     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5327         (gnus-activate-group group)     ; Or we can activate it...
5328         (progn                          ; Or we bug out.
5329           (when (equal major-mode 'gnus-summary-mode)
5330             (gnus-kill-buffer (current-buffer)))
5331           (error "Couldn't activate group %s: %s"
5332                  (gnus-group-decoded-name group) (gnus-status-message group))))
5333
5334     (unless (gnus-request-group group t)
5335       (when (equal major-mode 'gnus-summary-mode)
5336         (gnus-kill-buffer (current-buffer)))
5337       (error "Couldn't request group %s: %s"
5338              (gnus-group-decoded-name group) (gnus-status-message group)))
5339
5340     (when gnus-agent
5341       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5342
5343       (setq gnus-summary-use-undownloaded-faces
5344             (gnus-agent-find-parameter
5345              group
5346              'agent-enable-undownloaded-faces)))
5347
5348     (setq gnus-newsgroup-name group
5349           gnus-newsgroup-unselected nil
5350           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5351
5352     (let ((display (gnus-group-find-parameter group 'display)))
5353       (setq gnus-newsgroup-display
5354             (cond
5355              ((not (zerop (or (car-safe read-all) 0)))
5356               ;; The user entered the group with C-u SPC/RET, let's show
5357               ;; all articles.
5358               'gnus-not-ignore)
5359              ((eq display 'all)
5360               'gnus-not-ignore)
5361              ((arrayp display)
5362               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5363              ((numberp display)
5364               ;; The following is probably the "correct" solution, but
5365               ;; it makes Gnus fetch all headers and then limit the
5366               ;; articles (which is slow), so instead we hack the
5367               ;; select-articles parameter instead. -- Simon Josefsson
5368               ;; <jas@kth.se>
5369               ;;
5370               ;; (gnus-byte-compile
5371               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5372               ;;                         display)))))
5373               (setq select-articles
5374                     (gnus-uncompress-range
5375                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5376                              (if (> tmp 0)
5377                                  tmp
5378                                1))
5379                            (cdr (gnus-active group)))))
5380               nil)
5381              (t
5382               nil))))
5383
5384     (gnus-summary-setup-default-charset)
5385
5386     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5387     (when (gnus-virtual-group-p group)
5388       (setq cached gnus-newsgroup-cached))
5389
5390     (setq gnus-newsgroup-unreads
5391           (gnus-sorted-ndifference
5392            (gnus-sorted-ndifference gnus-newsgroup-unreads
5393                                     gnus-newsgroup-marked)
5394            gnus-newsgroup-dormant))
5395
5396     (setq gnus-newsgroup-processable nil)
5397
5398     (gnus-update-read-articles group gnus-newsgroup-unreads)
5399
5400     ;; Adjust and set lists of article marks.
5401     (when info
5402       (gnus-adjust-marked-articles info))
5403     (if (setq articles select-articles)
5404         (setq gnus-newsgroup-unselected
5405               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5406       (setq articles (gnus-articles-to-read group read-all)))
5407
5408     (cond
5409      ((null articles)
5410       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5411       'quit)
5412      ((eq articles 0) nil)
5413      (t
5414       ;; Init the dependencies hash table.
5415       (setq gnus-newsgroup-dependencies
5416             (gnus-make-hashtable (length articles)))
5417       (gnus-set-global-variables)
5418       ;; Retrieve the headers and read them in.
5419
5420       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5421
5422       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5423       (when cached
5424         (setq gnus-newsgroup-cached cached))
5425
5426       ;; Suppress duplicates?
5427       (when gnus-suppress-duplicates
5428         (gnus-dup-suppress-articles))
5429
5430       ;; Set the initial limit.
5431       (setq gnus-newsgroup-limit (copy-sequence articles))
5432       ;; Remove canceled articles from the list of unread articles.
5433       (setq fetched-articles
5434             (mapcar (lambda (headers) (mail-header-number headers))
5435                     gnus-newsgroup-headers))
5436       (setq gnus-newsgroup-articles fetched-articles)
5437       (setq gnus-newsgroup-unreads
5438             (gnus-sorted-nintersection
5439              gnus-newsgroup-unreads fetched-articles))
5440       (gnus-compute-unseen-list)
5441
5442       ;; Removed marked articles that do not exist.
5443       (gnus-update-missing-marks
5444        (gnus-sorted-difference articles fetched-articles))
5445       ;; We might want to build some more threads first.
5446       (when (and gnus-fetch-old-headers
5447                  (eq gnus-headers-retrieved-by 'nov))
5448         (if (eq gnus-fetch-old-headers 'invisible)
5449             (gnus-build-all-threads)
5450           (gnus-build-old-threads)))
5451       ;; Let the Gnus agent mark articles as read.
5452       (when gnus-agent
5453         (gnus-agent-get-undownloaded-list))
5454       ;; Remove list identifiers from subject
5455       (when gnus-list-identifiers
5456         (gnus-summary-remove-list-identifiers))
5457       ;; Check whether auto-expire is to be done in this group.
5458       (setq gnus-newsgroup-auto-expire
5459             (gnus-group-auto-expirable-p group))
5460       ;; Set up the article buffer now, if necessary.
5461       (unless (and gnus-single-article-buffer
5462                    (equal gnus-article-buffer "*Article*"))
5463         (gnus-article-setup-buffer))
5464       ;; First and last article in this newsgroup.
5465       (when gnus-newsgroup-headers
5466         (setq gnus-newsgroup-begin
5467               (mail-header-number (car gnus-newsgroup-headers))
5468               gnus-newsgroup-end
5469               (mail-header-number
5470                (gnus-last-element gnus-newsgroup-headers))))
5471       ;; GROUP is successfully selected.
5472       (or gnus-newsgroup-headers t)))))
5473
5474 (defun gnus-compute-unseen-list ()
5475   ;; The `seen' marks are treated specially.
5476   (if (not gnus-newsgroup-seen)
5477       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5478     (setq gnus-newsgroup-unseen
5479           (gnus-inverse-list-range-intersection
5480            gnus-newsgroup-articles gnus-newsgroup-seen))))
5481
5482 (defun gnus-summary-display-make-predicate (display)
5483   (require 'gnus-agent)
5484   (when (= (length display) 1)
5485     (setq display (car display)))
5486   (unless gnus-summary-display-cache
5487     (dolist (elem (append '((unread . unread)
5488                             (read . read)
5489                             (unseen . unseen))
5490                           gnus-article-mark-lists))
5491       (push (cons (cdr elem)
5492                   (gnus-byte-compile
5493                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5494             gnus-summary-display-cache)))
5495   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5496         (gnus-category-predicate-cache gnus-summary-display-cache))
5497     (gnus-get-predicate display)))
5498
5499 ;; Uses the dynamically bound `number' variable.
5500 (eval-when-compile
5501   (defvar number))
5502 (defun gnus-article-marked-p (type &optional article)
5503   (let ((article (or article number)))
5504     (cond
5505      ((eq type 'tick)
5506       (memq article gnus-newsgroup-marked))
5507      ((eq type 'spam)
5508       (memq article gnus-newsgroup-spam-marked))
5509      ((eq type 'unsend)
5510       (memq article gnus-newsgroup-unsendable))
5511      ((eq type 'undownload)
5512       (memq article gnus-newsgroup-undownloaded))
5513      ((eq type 'download)
5514       (memq article gnus-newsgroup-downloadable))
5515      ((eq type 'unread)
5516       (memq article gnus-newsgroup-unreads))
5517      ((eq type 'read)
5518       (memq article gnus-newsgroup-reads))
5519      ((eq type 'dormant)
5520       (memq article gnus-newsgroup-dormant) )
5521      ((eq type 'expire)
5522       (memq article gnus-newsgroup-expirable))
5523      ((eq type 'reply)
5524       (memq article gnus-newsgroup-replied))
5525      ((eq type 'killed)
5526       (memq article gnus-newsgroup-killed))
5527      ((eq type 'bookmark)
5528       (assq article gnus-newsgroup-bookmarks))
5529      ((eq type 'score)
5530       (assq article gnus-newsgroup-scored))
5531      ((eq type 'save)
5532       (memq article gnus-newsgroup-saved))
5533      ((eq type 'cache)
5534       (memq article gnus-newsgroup-cached))
5535      ((eq type 'forward)
5536       (memq article gnus-newsgroup-forwarded))
5537      ((eq type 'seen)
5538       (not (memq article gnus-newsgroup-unseen)))
5539      ((eq type 'recent)
5540       (memq article gnus-newsgroup-recent))
5541      (t t))))
5542
5543 (defun gnus-articles-to-read (group &optional read-all)
5544   "Find out what articles the user wants to read."
5545   (let* ((articles
5546           ;; Select all articles if `read-all' is non-nil, or if there
5547           ;; are no unread articles.
5548           (if (or read-all
5549                   (and (zerop (length gnus-newsgroup-marked))
5550                        (zerop (length gnus-newsgroup-unreads)))
5551                   ;; Fetch all if the predicate is non-nil.
5552                   gnus-newsgroup-display)
5553               ;; We want to select the headers for all the articles in
5554               ;; the group, so we select either all the active
5555               ;; articles in the group, or (if that's nil), the
5556               ;; articles in the cache.
5557               (or
5558                (gnus-uncompress-range (gnus-active group))
5559                (gnus-cache-articles-in-group group))
5560             ;; Select only the "normal" subset of articles.
5561             (gnus-sorted-nunion
5562              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5563              gnus-newsgroup-unreads)))
5564          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5565          (scored (length scored-list))
5566          (number (length articles))
5567          (marked (+ (length gnus-newsgroup-marked)
5568                     (length gnus-newsgroup-dormant)))
5569          (select
5570           (cond
5571            ((numberp read-all)
5572             read-all)
5573            ((numberp gnus-newsgroup-display)
5574             gnus-newsgroup-display)
5575            (t
5576             (condition-case ()
5577                 (cond
5578                  ((and (or (<= scored marked) (= scored number))
5579                        (numberp gnus-large-newsgroup)
5580                        (> number gnus-large-newsgroup))
5581                   (let* ((cursor-in-echo-area nil)
5582                          (initial (gnus-parameter-large-newsgroup-initial
5583                                    gnus-newsgroup-name))
5584                          (input
5585                           (read-string
5586                            (format
5587                             "How many articles from %s (%s %d): "
5588                             (gnus-limit-string
5589                              (gnus-group-decoded-name gnus-newsgroup-name)
5590                              35)
5591                             (if initial "max" "default")
5592                             number)
5593                            (if initial
5594                                (cons (number-to-string initial)
5595                                      0)))))
5596                     (if (string-match "^[ \t]*$" input) number input)))
5597                  ((and (> scored marked) (< scored number)
5598                        (> (- scored number) 20))
5599                   (let ((input
5600                          (read-string
5601                           (format "%s %s (%d scored, %d total): "
5602                                   "How many articles from"
5603                                   (gnus-group-decoded-name group)
5604                                   scored number))))
5605                     (if (string-match "^[ \t]*$" input)
5606                         number input)))
5607                  (t number))
5608               (quit
5609                (message "Quit getting the articles to read")
5610                nil))))))
5611     (setq select (if (stringp select) (string-to-number select) select))
5612     (if (or (null select) (zerop select))
5613         select
5614       (if (and (not (zerop scored)) (<= (abs select) scored))
5615           (progn
5616             (setq articles (sort scored-list '<))
5617             (setq number (length articles)))
5618         (setq articles (copy-sequence articles)))
5619
5620       (when (< (abs select) number)
5621         (if (< select 0)
5622             ;; Select the N oldest articles.
5623             (setcdr (nthcdr (1- (abs select)) articles) nil)
5624           ;; Select the N most recent articles.
5625           (setq articles (nthcdr (- number select) articles))))
5626       (setq gnus-newsgroup-unselected
5627             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5628       (when gnus-alter-articles-to-read-function
5629         (setq articles
5630               (sort
5631                (funcall gnus-alter-articles-to-read-function
5632                         gnus-newsgroup-name articles)
5633                '<)))
5634       articles)))
5635
5636 (defun gnus-killed-articles (killed articles)
5637   (let (out)
5638     (while articles
5639       (when (inline (gnus-member-of-range (car articles) killed))
5640         (push (car articles) out))
5641       (setq articles (cdr articles)))
5642     out))
5643
5644 (defun gnus-uncompress-marks (marks)
5645   "Uncompress the mark ranges in MARKS."
5646   (let ((uncompressed '(score bookmark))
5647         out)
5648     (while marks
5649       (if (memq (caar marks) uncompressed)
5650           (push (car marks) out)
5651         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5652       (setq marks (cdr marks)))
5653     out))
5654
5655 (defun gnus-article-mark-to-type (mark)
5656   "Return the type of MARK."
5657   (or (cadr (assq mark gnus-article-special-mark-lists))
5658       'list))
5659
5660 (defun gnus-article-unpropagatable-p (mark)
5661   "Return whether MARK should be propagated to back end."
5662   (memq mark gnus-article-unpropagated-mark-lists))
5663
5664 (defun gnus-adjust-marked-articles (info)
5665   "Set all article lists and remove all marks that are no longer valid."
5666   (let* ((marked-lists (gnus-info-marks info))
5667          (active (gnus-active (gnus-info-group info)))
5668          (min (car active))
5669          (max (cdr active))
5670          (types gnus-article-mark-lists)
5671          marks var articles article mark mark-type
5672          bgn end)
5673
5674     (dolist (marks marked-lists)
5675       (setq mark (car marks)
5676             mark-type (gnus-article-mark-to-type mark)
5677             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5678
5679       ;; We set the variable according to the type of the marks list,
5680       ;; and then adjust the marks to a subset of the active articles.
5681       (cond
5682        ;; Adjust "simple" lists - compressed yet unsorted
5683        ((eq mark-type 'list)
5684         ;; Simultaneously uncompress and clip to active range
5685         ;; See gnus-uncompress-range for a description of possible marks
5686         (let (l lh)
5687           (if (not (cadr marks))
5688               (set var nil)
5689             (setq articles (if (numberp (cddr marks))
5690                                (list (cdr marks))
5691                              (cdr marks))
5692                   lh (cons nil nil)
5693                   l lh)
5694
5695             (while (setq article (pop articles))
5696               (cond ((consp article)
5697                      (setq bgn (max (car article) min)
5698                            end (min (cdr article) max))
5699                      (while (<= bgn end)
5700                        (setq l (setcdr l (cons bgn nil))
5701                              bgn (1+ bgn))))
5702                     ((and (<= min article)
5703                           (>= max article))
5704                      (setq l (setcdr l (cons article nil))))))
5705             (set var (cdr lh)))))
5706        ;; Adjust assocs.
5707        ((eq mark-type 'tuple)
5708         (set var (setq articles (cdr marks)))
5709         (when (not (listp (cdr (symbol-value var))))
5710           (set var (list (symbol-value var))))
5711         (when (not (listp (cdr articles)))
5712           (setq articles (list articles)))
5713         (while articles
5714           (when (or (not (consp (setq article (pop articles))))
5715                     (< (car article) min)
5716                     (> (car article) max))
5717             (set var (delq article (symbol-value var))))))
5718        ;; Adjust ranges (sloppily).
5719        ((eq mark-type 'range)
5720         (cond
5721          ((eq mark 'seen)
5722           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5723           ;; It should be (seen (NUM1 . NUM2)).
5724           (when (numberp (cddr marks))
5725             (setcdr marks (list (cdr marks))))
5726           (setq articles (cdr marks))
5727           (while (and articles
5728                       (or (and (consp (car articles))
5729                                (> min (cdar articles)))
5730                           (and (numberp (car articles))
5731                                (> min (car articles)))))
5732             (pop articles))
5733           (set var articles))))))))
5734
5735 (defun gnus-update-missing-marks (missing)
5736   "Go through the list of MISSING articles and remove them from the mark lists."
5737   (when missing
5738     (let (var m)
5739       ;; Go through all types.
5740       (dolist (elem gnus-article-mark-lists)
5741         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5742           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5743           (when (symbol-value var)
5744             ;; This list has articles.  So we delete all missing
5745             ;; articles from it.
5746             (setq m missing)
5747             (while m
5748               (set var (delq (pop m) (symbol-value var))))))))))
5749
5750 (defun gnus-update-marks ()
5751   "Enter the various lists of marked articles into the newsgroup info list."
5752   (let ((types gnus-article-mark-lists)
5753         (info (gnus-get-info gnus-newsgroup-name))
5754         type list newmarked symbol delta-marks)
5755     (when info
5756       ;; Add all marks lists to the list of marks lists.
5757       (while (setq type (pop types))
5758         (setq list (symbol-value
5759                     (setq symbol
5760                           (intern (format "gnus-newsgroup-%s" (car type))))))
5761
5762         (when list
5763           ;; Get rid of the entries of the articles that have the
5764           ;; default score.
5765           (when (and (eq (cdr type) 'score)
5766                      gnus-save-score
5767                      list)
5768             (let* ((arts list)
5769                    (prev (cons nil list))
5770                    (all prev))
5771               (while arts
5772                 (if (or (not (consp (car arts)))
5773                         (= (cdar arts) gnus-summary-default-score))
5774                     (setcdr prev (cdr arts))
5775                   (setq prev arts))
5776                 (setq arts (cdr arts)))
5777               (setq list (cdr all)))))
5778
5779         (when (eq (cdr type) 'seen)
5780           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5781
5782         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5783           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5784
5785         (when (and (gnus-check-backend-function
5786                     'request-set-mark gnus-newsgroup-name)
5787                    (not (gnus-article-unpropagatable-p (cdr type))))
5788           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5789                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5790                  (add (gnus-remove-from-range
5791                        (gnus-copy-sequence list) old)))
5792             (when add
5793               (push (list add 'add (list (cdr type))) delta-marks))
5794             (when del
5795               (push (list del 'del (list (cdr type))) delta-marks))))
5796
5797         (when list
5798           (push (cons (cdr type) list) newmarked)))
5799
5800       (when delta-marks
5801         (unless (gnus-check-group gnus-newsgroup-name)
5802           (error "Can't open server for %s" gnus-newsgroup-name))
5803         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5804
5805       ;; Enter these new marks into the info of the group.
5806       (if (nthcdr 3 info)
5807           (setcar (nthcdr 3 info) newmarked)
5808         ;; Add the marks lists to the end of the info.
5809         (when newmarked
5810           (setcdr (nthcdr 2 info) (list newmarked))))
5811
5812       ;; Cut off the end of the info if there's nothing else there.
5813       (let ((i 5))
5814         (while (and (> i 2)
5815                     (not (nth i info)))
5816           (when (nthcdr (decf i) info)
5817             (setcdr (nthcdr i info) nil)))))))
5818
5819 (defun gnus-set-mode-line (where)
5820   "Set the mode line of the article or summary buffers.
5821 If WHERE is `summary', the summary mode line format will be used."
5822   ;; Is this mode line one we keep updated?
5823   (when (and (memq where gnus-updated-mode-lines)
5824              (symbol-value
5825               (intern (format "gnus-%s-mode-line-format-spec" where))))
5826     (let (mode-string)
5827       (save-excursion
5828         ;; We evaluate this in the summary buffer since these
5829         ;; variables are buffer-local to that buffer.
5830         (set-buffer gnus-summary-buffer)
5831        ;; We bind all these variables that are used in the `eval' form
5832         ;; below.
5833         (let* ((mformat (symbol-value
5834                          (intern
5835                           (format "gnus-%s-mode-line-format-spec" where))))
5836                (gnus-tmp-group-name (gnus-mode-string-quote
5837                                      (gnus-group-decoded-name
5838                                       gnus-newsgroup-name)))
5839                (gnus-tmp-article-number (or gnus-current-article 0))
5840                (gnus-tmp-unread gnus-newsgroup-unreads)
5841                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5842                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5843                (gnus-tmp-unread-and-unselected
5844                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5845                             (zerop gnus-tmp-unselected))
5846                        "")
5847                       ((zerop gnus-tmp-unselected)
5848                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5849                       (t (format "{%d(+%d) more}"
5850                                  gnus-tmp-unread-and-unticked
5851                                  gnus-tmp-unselected))))
5852                (gnus-tmp-subject
5853                 (if (and gnus-current-headers
5854                          (vectorp gnus-current-headers))
5855                     (gnus-mode-string-quote
5856                      (mail-header-subject gnus-current-headers))
5857                   ""))
5858                bufname-length max-len
5859                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5860           (setq mode-string (eval mformat))
5861           (setq bufname-length (if (string-match "%b" mode-string)
5862                                    (- (length
5863                                        (buffer-name
5864                                         (if (eq where 'summary)
5865                                             nil
5866                                           (get-buffer gnus-article-buffer))))
5867                                       2)
5868                                  0))
5869           (setq max-len (max 4 (if gnus-mode-non-string-length
5870                                    (- (window-width)
5871                                       gnus-mode-non-string-length
5872                                       bufname-length)
5873                                  (length mode-string))))
5874           ;; We might have to chop a bit of the string off...
5875           (when (> (length mode-string) max-len)
5876             (setq mode-string
5877                   (concat (truncate-string-to-width mode-string (- max-len 3))
5878                           "...")))
5879           ;; Pad the mode string a bit.
5880           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5881       ;; Update the mode line.
5882       (setq mode-line-buffer-identification
5883             (gnus-mode-line-buffer-identification (list mode-string)))
5884       (set-buffer-modified-p t))))
5885
5886 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5887   "Go through the HEADERS list and add all Xrefs to a hash table.
5888 The resulting hash table is returned, or nil if no Xrefs were found."
5889   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5890          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5891          (xref-hashtb (gnus-make-hashtable))
5892          start group entry number xrefs header)
5893     (while headers
5894       (setq header (pop headers))
5895       (when (and (setq xrefs (mail-header-xref header))
5896                  (not (memq (setq number (mail-header-number header))
5897                             unreads)))
5898         (setq start 0)
5899         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5900           (setq start (match-end 0))
5901           (setq group (if prefix
5902                           (concat prefix (substring xrefs (match-beginning 1)
5903                                                     (match-end 1)))
5904                         (substring xrefs (match-beginning 1) (match-end 1))))
5905           (setq number
5906                 (string-to-number (substring xrefs (match-beginning 2)
5907                                           (match-end 2))))
5908           (if (setq entry (gnus-gethash group xref-hashtb))
5909               (setcdr entry (cons number (cdr entry)))
5910             (gnus-sethash group (cons number nil) xref-hashtb)))))
5911     (and start xref-hashtb)))
5912
5913 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5914   "Look through all the headers and mark the Xrefs as read."
5915   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5916         name info xref-hashtb idlist method nth4)
5917     (save-excursion
5918       (set-buffer gnus-group-buffer)
5919       (when (setq xref-hashtb
5920                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5921         (mapatoms
5922          (lambda (group)
5923            (unless (string= from-newsgroup (setq name (symbol-name group)))
5924              (setq idlist (symbol-value group))
5925              ;; Dead groups are not updated.
5926              (and (prog1
5927                       (setq info (gnus-get-info name))
5928                     (when (stringp (setq nth4 (gnus-info-method info)))
5929                       (setq nth4 (gnus-server-to-method nth4))))
5930                   ;; Only do the xrefs if the group has the same
5931                   ;; select method as the group we have just read.
5932                   (or (gnus-methods-equal-p
5933                        nth4 (gnus-find-method-for-group from-newsgroup))
5934                       virtual
5935                       (equal nth4 (setq method (gnus-find-method-for-group
5936                                                 from-newsgroup)))
5937                       (and (equal (car nth4) (car method))
5938                            (equal (nth 1 nth4) (nth 1 method))))
5939                   gnus-use-cross-reference
5940                   (or (not (eq gnus-use-cross-reference t))
5941                       virtual
5942                       ;; Only do cross-references on subscribed
5943                       ;; groups, if that is what is wanted.
5944                       (<= (gnus-info-level info) gnus-level-subscribed))
5945                   (gnus-group-make-articles-read name idlist))))
5946          xref-hashtb)))))
5947
5948 (defun gnus-compute-read-articles (group articles)
5949   (let* ((entry (gnus-group-entry group))
5950          (info (nth 2 entry))
5951          (active (gnus-active group))
5952          ninfo)
5953     (when entry
5954       ;; First peel off all invalid article numbers.
5955       (when active
5956         (let ((ids articles)
5957               id first)
5958           (while (setq id (pop ids))
5959             (when (and first (> id (cdr active)))
5960               ;; We'll end up in this situation in one particular
5961               ;; obscure situation.  If you re-scan a group and get
5962               ;; a new article that is cross-posted to a different
5963               ;; group that has not been re-scanned, you might get
5964               ;; crossposted article that has a higher number than
5965               ;; Gnus believes possible.  So we re-activate this
5966               ;; group as well.  This might mean doing the
5967               ;; crossposting thingy will *increase* the number
5968               ;; of articles in some groups.  Tsk, tsk.
5969               (setq active (or (gnus-activate-group group) active)))
5970             (when (or (> id (cdr active))
5971                       (< id (car active)))
5972               (setq articles (delq id articles))))))
5973       ;; If the read list is nil, we init it.
5974       (if (and active
5975                (null (gnus-info-read info))
5976                (> (car active) 1))
5977           (setq ninfo (cons 1 (1- (car active))))
5978         (setq ninfo (gnus-info-read info)))
5979       ;; Then we add the read articles to the range.
5980       (gnus-add-to-range
5981        ninfo (setq articles (sort articles '<))))))
5982
5983 (defun gnus-group-make-articles-read (group articles)
5984   "Update the info of GROUP to say that ARTICLES are read."
5985   (let* ((num 0)
5986          (entry (gnus-group-entry group))
5987          (info (nth 2 entry))
5988          (active (gnus-active group))
5989          range)
5990     (when entry
5991       (setq range (gnus-compute-read-articles group articles))
5992       (with-current-buffer gnus-group-buffer
5993         (gnus-undo-register
5994           `(progn
5995              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5996              (gnus-info-set-read ',info ',(gnus-info-read info))
5997              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5998              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5999              (gnus-group-update-group ,group t))))
6000       ;; Add the read articles to the range.
6001       (gnus-info-set-read info range)
6002       (gnus-request-set-mark group (list (list range 'add '(read))))
6003       ;; Then we have to re-compute how many unread
6004       ;; articles there are in this group.
6005       (when active
6006         (cond
6007          ((not range)
6008           (setq num (- (1+ (cdr active)) (car active))))
6009          ((not (listp (cdr range)))
6010           (setq num (- (cdr active) (- (1+ (cdr range))
6011                                        (car range)))))
6012          (t
6013           (while range
6014             (if (numberp (car range))
6015                 (setq num (1+ num))
6016               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6017             (setq range (cdr range)))
6018           (setq num (- (cdr active) num))))
6019         ;; Update the number of unread articles.
6020         (setcar entry num)
6021         ;; Update the group buffer.
6022         (unless (gnus-ephemeral-group-p group)
6023           (gnus-group-update-group group t))))))
6024
6025 (defvar gnus-newsgroup-none-id 0)
6026
6027 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6028   (let ((cur nntp-server-buffer)
6029         (dependencies
6030          (or dependencies
6031              (with-current-buffer gnus-summary-buffer
6032                gnus-newsgroup-dependencies)))
6033         headers id end ref number
6034         (mail-parse-charset gnus-newsgroup-charset)
6035         (mail-parse-ignored-charsets
6036          (save-excursion (condition-case nil
6037                              (set-buffer gnus-summary-buffer)
6038                            (error))
6039                          gnus-newsgroup-ignored-charsets)))
6040     (save-excursion
6041       (set-buffer nntp-server-buffer)
6042       ;; Translate all TAB characters into SPACE characters.
6043       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6044       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6045       (ietf-drums-unfold-fws)
6046       (gnus-run-hooks 'gnus-parse-headers-hook)
6047       (let ((case-fold-search t)
6048             in-reply-to header p lines chars)
6049         (goto-char (point-min))
6050         ;; Search to the beginning of the next header.  Error messages
6051         ;; do not begin with 2 or 3.
6052         (while (re-search-forward "^[23][0-9]+ " nil t)
6053           (setq id nil
6054                 ref nil)
6055           ;; This implementation of this function, with nine
6056           ;; search-forwards instead of the one re-search-forward and
6057           ;; a case (which basically was the old function) is actually
6058           ;; about twice as fast, even though it looks messier.  You
6059           ;; can't have everything, I guess.  Speed and elegance
6060           ;; doesn't always go hand in hand.
6061           (setq
6062            header
6063            (vector
6064             ;; Number.
6065             (prog1
6066                 (setq number (read cur))
6067               (end-of-line)
6068               (setq p (point))
6069               (narrow-to-region (point)
6070                                 (or (and (search-forward "\n.\n" nil t)
6071                                          (- (point) 2))
6072                                     (point))))
6073             ;; Subject.
6074             (progn
6075               (goto-char p)
6076               (if (search-forward "\nsubject:" nil t)
6077                   (funcall gnus-decode-encoded-word-function
6078                            (nnheader-header-value))
6079                 "(none)"))
6080             ;; From.
6081             (progn
6082               (goto-char p)
6083               (if (search-forward "\nfrom:" nil t)
6084                   (funcall gnus-decode-encoded-address-function
6085                            (nnheader-header-value))
6086                 "(nobody)"))
6087             ;; Date.
6088             (progn
6089               (goto-char p)
6090               (if (search-forward "\ndate:" nil t)
6091                   (nnheader-header-value) ""))
6092             ;; Message-ID.
6093             (progn
6094               (goto-char p)
6095               (setq id (if (re-search-forward
6096                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6097                            ;; We do it this way to make sure the Message-ID
6098                            ;; is (somewhat) syntactically valid.
6099                            (buffer-substring (match-beginning 1)
6100                                              (match-end 1))
6101                          ;; If there was no message-id, we just fake one
6102                          ;; to make subsequent routines simpler.
6103                          (nnheader-generate-fake-message-id number))))
6104             ;; References.
6105             (progn
6106               (goto-char p)
6107               (if (search-forward "\nreferences:" nil t)
6108                   (progn
6109                     (setq end (point))
6110                     (prog1
6111                         (nnheader-header-value)
6112                       (setq ref
6113                             (buffer-substring
6114                              (progn
6115                                (end-of-line)
6116                                (search-backward ">" end t)
6117                                (1+ (point)))
6118                              (progn
6119                                (search-backward "<" end t)
6120                                (point))))))
6121                 ;; Get the references from the in-reply-to header if there
6122                 ;; were no references and the in-reply-to header looks
6123                 ;; promising.
6124                 (if (and (search-forward "\nin-reply-to:" nil t)
6125                          (setq in-reply-to (nnheader-header-value))
6126                          (string-match "<[^>]+>" in-reply-to))
6127                     (let (ref2)
6128                       (setq ref (substring in-reply-to (match-beginning 0)
6129                                            (match-end 0)))
6130                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6131                         (setq ref2 (substring in-reply-to (match-beginning 0)
6132                                               (match-end 0)))
6133                         (when (> (length ref2) (length ref))
6134                           (setq ref ref2)))
6135                       ref)
6136                   (setq ref nil))))
6137             ;; Chars.
6138             (progn
6139               (goto-char p)
6140               (if (search-forward "\nchars: " nil t)
6141                   (if (numberp (setq chars (ignore-errors (read cur))))
6142                       chars -1)
6143                 -1))
6144             ;; Lines.
6145             (progn
6146               (goto-char p)
6147               (if (search-forward "\nlines: " nil t)
6148                   (if (numberp (setq lines (ignore-errors (read cur))))
6149                       lines -1)
6150                 -1))
6151             ;; Xref.
6152             (progn
6153               (goto-char p)
6154               (and (search-forward "\nxref:" nil t)
6155                    (nnheader-header-value)))
6156             ;; Extra.
6157             (when gnus-extra-headers
6158               (let ((extra gnus-extra-headers)
6159                     out)
6160                 (while extra
6161                   (goto-char p)
6162                   (when (search-forward
6163                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6164                     (push (cons (car extra) (nnheader-header-value))
6165                           out))
6166                   (pop extra))
6167                 out))))
6168           (when (equal id ref)
6169             (setq ref nil))
6170
6171           (when gnus-alter-header-function
6172             (funcall gnus-alter-header-function header)
6173             (setq id (mail-header-id header)
6174                   ref (gnus-parent-id (mail-header-references header))))
6175
6176           (when (setq header
6177                       (gnus-dependencies-add-header
6178                        header dependencies force-new))
6179             (push header headers))
6180           (goto-char (point-max))
6181           (widen))
6182         (nreverse headers)))))
6183
6184 ;; Goes through the xover lines and returns a list of vectors
6185 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6186                                                   force-new dependencies
6187                                                   group also-fetch-heads)
6188   "Parse the news overview data in the server buffer.
6189 Return a list of headers that match SEQUENCE (see
6190 `nntp-retrieve-headers')."
6191   ;; Get the Xref when the users reads the articles since most/some
6192   ;; NNTP servers do not include Xrefs when using XOVER.
6193   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6194   (let ((mail-parse-charset gnus-newsgroup-charset)
6195         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6196         (cur nntp-server-buffer)
6197         (dependencies (or dependencies gnus-newsgroup-dependencies))
6198         (allp (cond
6199                ((eq gnus-read-all-available-headers t)
6200                 t)
6201                ((and (stringp gnus-read-all-available-headers)
6202                      group)
6203                 (string-match gnus-read-all-available-headers group))
6204                (t
6205                 nil)))
6206         number headers header)
6207     (save-excursion
6208       (set-buffer nntp-server-buffer)
6209       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6210       ;; Allow the user to mangle the headers before parsing them.
6211       (gnus-run-hooks 'gnus-parse-headers-hook)
6212       (goto-char (point-min))
6213       (gnus-parse-without-error
6214         (while (and (or sequence allp)
6215                     (not (eobp)))
6216           (setq number (read cur))
6217           (when (not allp)
6218             (while (and sequence
6219                         (< (car sequence) number))
6220               (setq sequence (cdr sequence))))
6221           (when (and (or allp
6222                          (and sequence
6223                               (eq number (car sequence))))
6224                      (progn
6225                        (setq sequence (cdr sequence))
6226                        (setq header (inline
6227                                       (gnus-nov-parse-line
6228                                        number dependencies force-new)))))
6229             (push header headers))
6230           (forward-line 1)))
6231       ;; A common bug in inn is that if you have posted an article and
6232       ;; then retrieves the active file, it will answer correctly --
6233       ;; the new article is included.  However, a NOV entry for the
6234       ;; article may not have been generated yet, so this may fail.
6235       ;; We work around this problem by retrieving the last few
6236       ;; headers using HEAD.
6237       (if (or (not also-fetch-heads)
6238               (not sequence))
6239           ;; We (probably) got all the headers.
6240           (nreverse headers)
6241         (let ((gnus-nov-is-evil t))
6242           (nconc
6243            (nreverse headers)
6244            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6245              (gnus-get-newsgroup-headers))))))))
6246
6247 (defun gnus-article-get-xrefs ()
6248   "Fill in the Xref value in `gnus-current-headers', if necessary.
6249 This is meant to be called in `gnus-article-internal-prepare-hook'."
6250   (let ((headers (with-current-buffer gnus-summary-buffer
6251                    gnus-current-headers)))
6252     (or (not gnus-use-cross-reference)
6253         (not headers)
6254         (and (mail-header-xref headers)
6255              (not (string= (mail-header-xref headers) "")))
6256         (let ((case-fold-search t)
6257               xref)
6258           (save-restriction
6259             (nnheader-narrow-to-headers)
6260             (goto-char (point-min))
6261             (when (or (and (not (eobp))
6262                            (eq (downcase (char-after)) ?x)
6263                            (looking-at "Xref:"))
6264                       (search-forward "\nXref:" nil t))
6265               (goto-char (1+ (match-end 0)))
6266               (setq xref (buffer-substring (point) (point-at-eol)))
6267               (mail-header-set-xref headers xref)))))))
6268
6269 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6270   "Find article ID and insert the summary line for that article.
6271 OLD-HEADER can either be a header or a line number to insert
6272 the subject line on."
6273   (let* ((line (and (numberp old-header) old-header))
6274          (old-header (and (vectorp old-header) old-header))
6275          (header (cond ((and old-header use-old-header)
6276                         old-header)
6277                        ((and (numberp id)
6278                              (gnus-number-to-header id))
6279                         (gnus-number-to-header id))
6280                        (t
6281                         (gnus-read-header id))))
6282          (number (and (numberp id) id))
6283          d)
6284     (when header
6285       ;; Rebuild the thread that this article is part of and go to the
6286       ;; article we have fetched.
6287       (when (and (not gnus-show-threads)
6288                  old-header)
6289         (when (and number
6290                    (setq d (gnus-data-find (mail-header-number old-header))))
6291           (goto-char (gnus-data-pos d))
6292           (gnus-data-remove
6293            number
6294            (- (point-at-bol)
6295               (prog1
6296                   (1+ (point-at-eol))
6297                 (gnus-delete-line))))))
6298       ;; Remove list identifiers from subject.
6299       (when gnus-list-identifiers
6300         (let ((gnus-newsgroup-headers (list header)))
6301           (gnus-summary-remove-list-identifiers)))
6302       (when old-header
6303         (mail-header-set-number header (mail-header-number old-header)))
6304       (setq gnus-newsgroup-sparse
6305             (delq (setq number (mail-header-number header))
6306                   gnus-newsgroup-sparse))
6307       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6308       (push number gnus-newsgroup-limit)
6309       (gnus-rebuild-thread (mail-header-id header) line)
6310       (gnus-summary-goto-subject number nil t))
6311     (when (and (numberp number)
6312                (> number 0))
6313       ;; We have to update the boundaries even if we can't fetch the
6314       ;; article if ID is a number -- so that the next `P' or `N'
6315       ;; command will fetch the previous (or next) article even
6316       ;; if the one we tried to fetch this time has been canceled.
6317       (when (> number gnus-newsgroup-end)
6318         (setq gnus-newsgroup-end number))
6319       (when (< number gnus-newsgroup-begin)
6320         (setq gnus-newsgroup-begin number))
6321       (setq gnus-newsgroup-unselected
6322             (delq number gnus-newsgroup-unselected)))
6323     ;; Report back a success?
6324     (and header (mail-header-number header))))
6325
6326 ;;; Process/prefix in the summary buffer
6327
6328 (defun gnus-summary-work-articles (n)
6329   "Return a list of articles to be worked upon.
6330 The prefix argument, the list of process marked articles, and the
6331 current article will be taken into consideration."
6332   (save-excursion
6333     (set-buffer gnus-summary-buffer)
6334     (cond
6335      (n
6336       ;; A numerical prefix has been given.
6337       (setq n (prefix-numeric-value n))
6338       (let ((backward (< n 0))
6339             (n (abs (prefix-numeric-value n)))
6340             articles article)
6341         (save-excursion
6342           (while
6343               (and (> n 0)
6344                    (push (setq article (gnus-summary-article-number))
6345                          articles)
6346                    (if backward
6347                        (gnus-summary-find-prev nil article)
6348                      (gnus-summary-find-next nil article)))
6349             (decf n)))
6350         (nreverse articles)))
6351      ((and (gnus-region-active-p) (mark))
6352       (message "region active")
6353       ;; Work on the region between point and mark.
6354       (let ((max (max (point) (mark)))
6355             articles article)
6356         (save-excursion
6357           (goto-char (min (point) (mark)))
6358           (while
6359               (and
6360                (push (setq article (gnus-summary-article-number)) articles)
6361                (gnus-summary-find-next nil article)
6362                (< (point) max)))
6363           (nreverse articles))))
6364      (gnus-newsgroup-processable
6365       ;; There are process-marked articles present.
6366       ;; Save current state.
6367       (gnus-summary-save-process-mark)
6368       ;; Return the list.
6369       (reverse gnus-newsgroup-processable))
6370      (t
6371       ;; Just return the current article.
6372       (list (gnus-summary-article-number))))))
6373
6374 (defmacro gnus-summary-iterate (arg &rest forms)
6375   "Iterate over the process/prefixed articles and do FORMS.
6376 ARG is the interactive prefix given to the command.  FORMS will be
6377 executed with point over the summary line of the articles."
6378   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6379     `(let ((,articles (gnus-summary-work-articles ,arg)))
6380        (while ,articles
6381          (gnus-summary-goto-subject (car ,articles))
6382          ,@forms
6383          (pop ,articles)))))
6384
6385 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6386 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6387
6388 (defun gnus-summary-save-process-mark ()
6389   "Push the current set of process marked articles on the stack."
6390   (interactive)
6391   (push (copy-sequence gnus-newsgroup-processable)
6392         gnus-newsgroup-process-stack))
6393
6394 (defun gnus-summary-kill-process-mark ()
6395   "Push the current set of process marked articles on the stack and unmark."
6396   (interactive)
6397   (gnus-summary-save-process-mark)
6398   (gnus-summary-unmark-all-processable))
6399
6400 (defun gnus-summary-yank-process-mark ()
6401   "Pop the last process mark state off the stack and restore it."
6402   (interactive)
6403   (unless gnus-newsgroup-process-stack
6404     (error "Empty mark stack"))
6405   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6406
6407 (defun gnus-summary-process-mark-set (set)
6408   "Make SET into the current process marked articles."
6409   (gnus-summary-unmark-all-processable)
6410   (mapc 'gnus-summary-set-process-mark set))
6411
6412 ;;; Searching and stuff
6413
6414 (defun gnus-summary-search-group (&optional backward use-level)
6415   "Search for next unread newsgroup.
6416 If optional argument BACKWARD is non-nil, search backward instead."
6417   (save-excursion
6418     (set-buffer gnus-group-buffer)
6419     (when (gnus-group-search-forward
6420            backward nil (if use-level (gnus-group-group-level) nil))
6421       (gnus-group-group-name))))
6422
6423 (defun gnus-summary-best-group (&optional exclude-group)
6424   "Find the name of the best unread group.
6425 If EXCLUDE-GROUP, do not go to this group."
6426   (with-current-buffer gnus-group-buffer
6427     (save-excursion
6428       (gnus-group-best-unread-group exclude-group))))
6429
6430 (defun gnus-summary-find-next (&optional unread article backward)
6431   (if backward
6432       (gnus-summary-find-prev unread article)
6433     (let* ((dummy (gnus-summary-article-intangible-p))
6434            (article (or article (gnus-summary-article-number)))
6435            (data (gnus-data-find-list article))
6436            result)
6437       (when (and (not dummy)
6438                  (or (not gnus-summary-check-current)
6439                      (not unread)
6440                      (not (gnus-data-unread-p (car data)))))
6441         (setq data (cdr data)))
6442       (when (setq result
6443                   (if unread
6444                       (progn
6445                         (while data
6446                           (unless (memq (gnus-data-number (car data))
6447                                         (cond
6448                                          ((eq gnus-auto-goto-ignores
6449                                               'always-undownloaded)
6450                                           gnus-newsgroup-undownloaded)
6451                                          (gnus-plugged
6452                                           nil)
6453                                          ((eq gnus-auto-goto-ignores
6454                                               'unfetched)
6455                                           gnus-newsgroup-unfetched)
6456                                          ((eq gnus-auto-goto-ignores
6457                                               'undownloaded)
6458                                           gnus-newsgroup-undownloaded)))
6459                             (when (gnus-data-unread-p (car data))
6460                               (setq result (car data)
6461                                     data nil)))
6462                           (setq data (cdr data)))
6463                         result)
6464                     (car data)))
6465         (goto-char (gnus-data-pos result))
6466         (gnus-data-number result)))))
6467
6468 (defun gnus-summary-find-prev (&optional unread article)
6469   (let* ((eobp (eobp))
6470          (article (or article (gnus-summary-article-number)))
6471          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6472          result)
6473     (when (and (not eobp)
6474                (or (not gnus-summary-check-current)
6475                    (not unread)
6476                    (not (gnus-data-unread-p (car data)))))
6477       (setq data (cdr data)))
6478     (when (setq result
6479                 (if unread
6480                     (progn
6481                       (while data
6482                         (unless (memq (gnus-data-number (car data))
6483                                       (cond
6484                                        ((eq gnus-auto-goto-ignores
6485                                             'always-undownloaded)
6486                                         gnus-newsgroup-undownloaded)
6487                                        (gnus-plugged
6488                                         nil)
6489                                        ((eq gnus-auto-goto-ignores
6490                                             'unfetched)
6491                                         gnus-newsgroup-unfetched)
6492                                        ((eq gnus-auto-goto-ignores
6493                                             'undownloaded)
6494                                         gnus-newsgroup-undownloaded)))
6495                           (when (gnus-data-unread-p (car data))
6496                             (setq result (car data)
6497                                   data nil)))
6498                         (setq data (cdr data)))
6499                       result)
6500                   (car data)))
6501       (goto-char (gnus-data-pos result))
6502       (gnus-data-number result))))
6503
6504 (defun gnus-summary-find-subject (subject &optional unread backward article)
6505   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6506          (article (or article (gnus-summary-article-number)))
6507          (articles (gnus-data-list backward))
6508          (arts (gnus-data-find-list article articles))
6509          result)
6510     (when (or (not gnus-summary-check-current)
6511               (not unread)
6512               (not (gnus-data-unread-p (car arts))))
6513       (setq arts (cdr arts)))
6514     (while arts
6515       (and (or (not unread)
6516                (gnus-data-unread-p (car arts)))
6517            (vectorp (gnus-data-header (car arts)))
6518            (gnus-subject-equal
6519             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6520            (setq result (car arts)
6521                  arts nil))
6522       (setq arts (cdr arts)))
6523     (and result
6524          (goto-char (gnus-data-pos result))
6525          (gnus-data-number result))))
6526
6527 (defun gnus-summary-search-forward (&optional unread subject backward)
6528   "Search forward for an article.
6529 If UNREAD, look for unread articles.  If SUBJECT, look for
6530 articles with that subject.  If BACKWARD, search backward instead."
6531   (cond (subject (gnus-summary-find-subject subject unread backward))
6532         (backward (gnus-summary-find-prev unread))
6533         (t (gnus-summary-find-next unread))))
6534
6535 (defun gnus-recenter (&optional n)
6536   "Center point in window and redisplay frame.
6537 Also do horizontal recentering."
6538   (interactive "P")
6539   (when (and gnus-auto-center-summary
6540              (not (eq gnus-auto-center-summary 'vertical)))
6541     (gnus-horizontal-recenter))
6542   (recenter n))
6543
6544 (defun gnus-summary-recenter ()
6545   "Center point in the summary window.
6546 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6547 displayed, no centering will be performed."
6548   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6549   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6550   (interactive)
6551   ;; The user has to want it.
6552   (when gnus-auto-center-summary
6553     (let* ((top (cond ((< (window-height) 4) 0)
6554                       ((< (window-height) 7) 1)
6555                       (t (if (numberp gnus-auto-center-summary)
6556                              gnus-auto-center-summary
6557                            (/ (1- (window-height)) 2)))))
6558            (height (1- (window-height)))
6559            (bottom (save-excursion (goto-char (point-max))
6560                                    (forward-line (- height))
6561                                    (point)))
6562            (window (get-buffer-window (current-buffer))))
6563       (when (get-buffer-window gnus-article-buffer)
6564         ;; Only do recentering when the article buffer is displayed,
6565         ;; Set the window start to either `bottom', which is the biggest
6566         ;; possible valid number, or the second line from the top,
6567         ;; whichever is the least.
6568         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6569           (message "%s" top-pos)
6570           (if (> bottom top-pos)
6571               ;; Keep the second line from the top visible
6572               (set-window-start window top-pos)
6573             ;; Try to keep the bottom line visible; if it's partially
6574             ;; obscured, either scroll one more line to make it fully
6575             ;; visible, or revert to using TOP-POS.
6576             (save-excursion
6577               (goto-char (point-max))
6578               (forward-line -1)
6579               (let ((last-line-start (point)))
6580                 (goto-char bottom)
6581                 (set-window-start window (point) t)
6582                 (when (not (pos-visible-in-window-p last-line-start window))
6583                   (forward-line 1)
6584                   (set-window-start window (min (point) top-pos) t)))))))
6585       ;; Do horizontal recentering while we're at it.
6586       (when (and (get-buffer-window (current-buffer) t)
6587                  (not (eq gnus-auto-center-summary 'vertical)))
6588         (let ((selected (selected-window)))
6589           (select-window (get-buffer-window (current-buffer) t))
6590           (gnus-summary-position-point)
6591           (gnus-horizontal-recenter)
6592           (select-window selected))))))
6593
6594 (defun gnus-summary-jump-to-group (newsgroup)
6595   "Move point to NEWSGROUP in group mode buffer."
6596   ;; Keep update point of group mode buffer if visible.
6597   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6598       (save-window-excursion
6599         ;; Take care of tree window mode.
6600         (when (get-buffer-window gnus-group-buffer)
6601           (pop-to-buffer gnus-group-buffer))
6602         (gnus-group-jump-to-group newsgroup))
6603     (save-excursion
6604       ;; Take care of tree window mode.
6605       (if (get-buffer-window gnus-group-buffer)
6606           (pop-to-buffer gnus-group-buffer)
6607         (set-buffer gnus-group-buffer))
6608       (gnus-group-jump-to-group newsgroup))))
6609
6610 ;; This function returns a list of article numbers based on the
6611 ;; difference between the ranges of read articles in this group and
6612 ;; the range of active articles.
6613 (defun gnus-list-of-unread-articles (group)
6614   (let* ((read (gnus-info-read (gnus-get-info group)))
6615          (active (or (gnus-active group) (gnus-activate-group group)))
6616          (last (or (cdr active)
6617                    (error "Group %s couldn't be activated " group)))
6618          first nlast unread)
6619     ;; If none are read, then all are unread.
6620     (if (not read)
6621         (setq first (car active))
6622       ;; If the range of read articles is a single range, then the
6623       ;; first unread article is the article after the last read
6624       ;; article.  Sounds logical, doesn't it?
6625       (if (and (not (listp (cdr read)))
6626                (or (< (car read) (car active))
6627                    (progn (setq read (list read))
6628                           nil)))
6629           (setq first (max (car active) (1+ (cdr read))))
6630         ;; `read' is a list of ranges.
6631         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6632                                   (caar read)))
6633                   1)
6634           (setq first (car active)))
6635         (while read
6636           (when first
6637             (while (< first nlast)
6638               (setq unread (cons first unread)
6639                     first (1+ first))))
6640           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6641           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6642           (setq read (cdr read)))))
6643     ;; And add the last unread articles.
6644     (while (<= first last)
6645       (setq unread (cons first unread)
6646             first (1+ first)))
6647     ;; Return the list of unread articles.
6648     (delq 0 (nreverse unread))))
6649
6650 (defun gnus-list-of-read-articles (group)
6651   "Return a list of unread, unticked and non-dormant articles."
6652   (let* ((info (gnus-get-info group))
6653          (marked (gnus-info-marks info))
6654          (active (gnus-active group)))
6655     (and info active
6656          (gnus-list-range-difference
6657           (gnus-list-range-difference
6658            (gnus-sorted-complement
6659             (gnus-uncompress-range active)
6660             (gnus-list-of-unread-articles group))
6661            (cdr (assq 'dormant marked)))
6662           (cdr (assq 'tick marked))))))
6663
6664 ;; This function returns a sequence of article numbers based on the
6665 ;; difference between the ranges of read articles in this group and
6666 ;; the range of active articles.
6667 (defun gnus-sequence-of-unread-articles (group)
6668   (let* ((read (gnus-info-read (gnus-get-info group)))
6669          (active (or (gnus-active group) (gnus-activate-group group)))
6670          (last (cdr active))
6671          first nlast unread)
6672     ;; If none are read, then all are unread.
6673     (if (not read)
6674         (setq first (car active))
6675       ;; If the range of read articles is a single range, then the
6676       ;; first unread article is the article after the last read
6677       ;; article.  Sounds logical, doesn't it?
6678       (if (and (not (listp (cdr read)))
6679                (or (< (car read) (car active))
6680                    (progn (setq read (list read))
6681                           nil)))
6682           (setq first (max (car active) (1+ (cdr read))))
6683         ;; `read' is a list of ranges.
6684         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6685                                   (caar read)))
6686                   1)
6687           (setq first (car active)))
6688         (while read
6689           (when first
6690             (push (cons first nlast) unread))
6691           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6692           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6693           (setq read (cdr read)))))
6694     ;; And add the last unread articles.
6695     (cond ((not (and first last))
6696            nil)
6697           ((< first last)
6698            (push (cons first last) unread))
6699           ((= first last)
6700            (push first unread)))
6701     ;; Return the sequence of unread articles.
6702     (delq 0 (nreverse unread))))
6703
6704 ;; Various summary commands
6705
6706 (defun gnus-summary-select-article-buffer ()
6707   "Reconfigure windows to show article buffer."
6708   (interactive)
6709   (if (not (gnus-buffer-live-p gnus-article-buffer))
6710       (error "There is no article buffer for this summary buffer")
6711     (gnus-configure-windows 'article)
6712     (select-window (get-buffer-window gnus-article-buffer))))
6713
6714 (defun gnus-summary-universal-argument (arg)
6715   "Perform any operation on all articles that are process/prefixed."
6716   (interactive "P")
6717   (let ((articles (gnus-summary-work-articles arg))
6718         func article)
6719     (if (eq
6720          (setq
6721           func
6722           (key-binding
6723            (read-key-sequence
6724             (substitute-command-keys
6725              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6726          'undefined)
6727         (gnus-error 1 "Undefined key")
6728       (save-excursion
6729         (while articles
6730           (gnus-summary-goto-subject (setq article (pop articles)))
6731           (let (gnus-newsgroup-processable)
6732             (command-execute func))
6733           (gnus-summary-remove-process-mark article)))))
6734   (gnus-summary-position-point))
6735
6736 (defun gnus-summary-toggle-truncation (&optional arg)
6737   "Toggle truncation of summary lines.
6738 With ARG, turn line truncation on if ARG is positive."
6739   (interactive "P")
6740   (setq truncate-lines
6741         (if (null arg) (not truncate-lines)
6742           (> (prefix-numeric-value arg) 0)))
6743   (redraw-display))
6744
6745 (defun gnus-summary-find-for-reselect ()
6746   "Return the number of an article to stay on across a reselect.
6747 The current article is considered, then following articles, then previous
6748 articles.  An article is sought which is not cancelled and isn't a temporary
6749 insertion from another group.  If there's no such then return a dummy 0."
6750   (let (found)
6751     (dolist (rev '(nil t))
6752       (unless found      ; don't demand the reverse list if we don't need it
6753         (let ((data (gnus-data-find-list
6754                      (gnus-summary-article-number) (gnus-data-list rev))))
6755           (while (and data (not found))
6756             (if (and (< 0 (gnus-data-number (car data)))
6757                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6758                 (setq found (gnus-data-number (car data))))
6759             (setq data (cdr data))))))
6760     (or found 0)))
6761
6762 (defun gnus-summary-reselect-current-group (&optional all rescan)
6763   "Exit and then reselect the current newsgroup.
6764 The prefix argument ALL means to select all articles."
6765   (interactive "P")
6766   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6767     (error "Ephemeral groups can't be reselected"))
6768   (let ((current-subject (gnus-summary-find-for-reselect))
6769         (group gnus-newsgroup-name))
6770     (setq gnus-newsgroup-begin nil)
6771     (gnus-summary-exit nil 'leave-hidden)
6772     ;; We have to adjust the point of group mode buffer because
6773     ;; point was moved to the next unread newsgroup by exiting.
6774     (gnus-summary-jump-to-group group)
6775     (when rescan
6776       (save-excursion
6777         (gnus-group-get-new-news-this-group 1)))
6778     (gnus-group-read-group all t)
6779     (gnus-summary-goto-subject current-subject nil t)))
6780
6781 (defun gnus-summary-rescan-group (&optional all)
6782   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6783   (interactive "P")
6784   (gnus-summary-reselect-current-group all t))
6785
6786 (defun gnus-summary-update-info (&optional non-destructive)
6787   (save-excursion
6788     (let ((group gnus-newsgroup-name))
6789       (when group
6790         (when gnus-newsgroup-kill-headers
6791           (setq gnus-newsgroup-killed
6792                 (gnus-compress-sequence
6793                  (gnus-sorted-union
6794                   (gnus-list-range-intersection
6795                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6796                   gnus-newsgroup-unreads)
6797                  t)))
6798         (unless (listp (cdr gnus-newsgroup-killed))
6799           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6800         (let ((headers gnus-newsgroup-headers))
6801           ;; Set the new ranges of read articles.
6802           (with-current-buffer gnus-group-buffer
6803             (gnus-undo-force-boundary))
6804           (gnus-update-read-articles
6805            group (gnus-sorted-union
6806                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6807           ;; Set the current article marks.
6808           (let ((gnus-newsgroup-scored
6809                  (if (and (not gnus-save-score)
6810                           (not non-destructive))
6811                      nil
6812                    gnus-newsgroup-scored)))
6813             (save-excursion
6814               (gnus-update-marks)))
6815           ;; Do the cross-ref thing.
6816           (when gnus-use-cross-reference
6817             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6818           ;; Do not switch windows but change the buffer to work.
6819           (set-buffer gnus-group-buffer)
6820           (unless (gnus-ephemeral-group-p group)
6821             (gnus-group-update-group group)))))))
6822
6823 (defun gnus-summary-save-newsrc (&optional force)
6824   "Save the current number of read/marked articles in the dribble buffer.
6825 The dribble buffer will then be saved.
6826 If FORCE (the prefix), also save the .newsrc file(s)."
6827   (interactive "P")
6828   (gnus-summary-update-info t)
6829   (if force
6830       (gnus-save-newsrc-file)
6831     (gnus-dribble-save)))
6832
6833 (defun gnus-summary-exit (&optional temporary leave-hidden)
6834   "Exit reading current newsgroup, and then return to group selection mode.
6835 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6836   (interactive)
6837   (gnus-set-global-variables)
6838   (when (gnus-buffer-live-p gnus-article-buffer)
6839     (save-excursion
6840       (set-buffer gnus-article-buffer)
6841       (mm-destroy-parts gnus-article-mime-handles)
6842       ;; Set it to nil for safety reason.
6843       (setq gnus-article-mime-handle-alist nil)
6844       (setq gnus-article-mime-handles nil)))
6845   (gnus-kill-save-kill-buffer)
6846   (gnus-async-halt-prefetch)
6847   (let* ((group gnus-newsgroup-name)
6848          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6849          (gnus-group-is-exiting-p t)
6850          (mode major-mode)
6851          (group-point nil)
6852          (buf (current-buffer)))
6853     (unless quit-config
6854       ;; Do adaptive scoring, and possibly save score files.
6855       (when gnus-newsgroup-adaptive
6856         (gnus-score-adaptive))
6857       (when gnus-use-scoring
6858         (gnus-score-save)))
6859     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6860     ;; If we have several article buffers, we kill them at exit.
6861     (unless gnus-single-article-buffer
6862       (gnus-kill-buffer gnus-article-buffer)
6863       (gnus-kill-buffer gnus-original-article-buffer)
6864       (setq gnus-article-current nil))
6865     (when gnus-use-cache
6866       (gnus-cache-possibly-remove-articles)
6867       (gnus-cache-save-buffers))
6868     (gnus-async-prefetch-remove-group group)
6869     (when gnus-suppress-duplicates
6870       (gnus-dup-enter-articles))
6871     (when gnus-use-trees
6872       (gnus-tree-close group))
6873     (when gnus-use-cache
6874       (gnus-cache-write-active))
6875     ;; Remove entries for this group.
6876     (nnmail-purge-split-history (gnus-group-real-name group))
6877     ;; Make all changes in this group permanent.
6878     (unless quit-config
6879       (gnus-run-hooks 'gnus-exit-group-hook)
6880       (gnus-summary-update-info))
6881     (gnus-close-group group)
6882     ;; Make sure where we were, and go to next newsgroup.
6883     (set-buffer gnus-group-buffer)
6884     (unless quit-config
6885       (gnus-group-jump-to-group group))
6886     (gnus-run-hooks 'gnus-summary-exit-hook)
6887     (unless (or quit-config
6888                 ;; If this group has disappeared from the summary
6889                 ;; buffer, don't skip forwards.
6890                 (not (string= group (gnus-group-group-name))))
6891       (gnus-group-next-unread-group 1))
6892     (setq group-point (point))
6893     (if temporary
6894         nil                             ;Nothing to do.
6895       ;; If we have several article buffers, we kill them at exit.
6896       (unless gnus-single-article-buffer
6897         (gnus-kill-buffer gnus-article-buffer)
6898         (gnus-kill-buffer gnus-original-article-buffer)
6899         (setq gnus-article-current nil))
6900       (set-buffer buf)
6901       (if (not gnus-kill-summary-on-exit)
6902           (progn
6903             (gnus-deaden-summary)
6904             (setq mode nil))
6905         ;; We set all buffer-local variables to nil.  It is unclear why
6906         ;; this is needed, but if we don't, buffer-local variables are
6907         ;; not garbage-collected, it seems.  This would the lead to en
6908         ;; ever-growing Emacs.
6909         (gnus-summary-clear-local-variables)
6910         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6911           (gnus-summary-clear-local-variables))
6912         (when (get-buffer gnus-article-buffer)
6913           (bury-buffer gnus-article-buffer))
6914         ;; Return to group mode buffer.
6915         (when (eq mode 'gnus-summary-mode)
6916           (gnus-kill-buffer buf)))
6917       (setq gnus-current-select-method gnus-select-method)
6918       (set-buffer gnus-group-buffer)
6919       (if quit-config
6920           (gnus-handle-ephemeral-exit quit-config)
6921         (goto-char group-point)
6922         ;; If gnus-group-buffer is already displayed, make sure we also move
6923         ;; the cursor in the window that displays it.
6924         (let ((win (get-buffer-window (current-buffer) 0)))
6925           (if win (set-window-point win (point))))
6926         (unless leave-hidden
6927           (gnus-configure-windows 'group 'force)))
6928       ;; Clear the current group name.
6929       (unless quit-config
6930         (setq gnus-newsgroup-name nil)))))
6931
6932 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6933 (defun gnus-summary-exit-no-update (&optional no-questions)
6934   "Quit reading current newsgroup without updating read article info."
6935   (interactive)
6936   (let* ((group gnus-newsgroup-name)
6937          (gnus-group-is-exiting-p t)
6938          (gnus-group-is-exiting-without-update-p t)
6939          (quit-config (gnus-group-quit-config group)))
6940     (when (or no-questions
6941               gnus-expert-user
6942               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6943       (gnus-async-halt-prefetch)
6944       (run-hooks 'gnus-summary-prepare-exit-hook)
6945       (when (gnus-buffer-live-p gnus-article-buffer)
6946         (save-excursion
6947           (set-buffer gnus-article-buffer)
6948           (mm-destroy-parts gnus-article-mime-handles)
6949           ;; Set it to nil for safety reason.
6950           (setq gnus-article-mime-handle-alist nil)
6951           (setq gnus-article-mime-handles nil)))
6952       ;; If we have several article buffers, we kill them at exit.
6953       (unless gnus-single-article-buffer
6954         (gnus-kill-buffer gnus-article-buffer)
6955         (gnus-kill-buffer gnus-original-article-buffer)
6956         (setq gnus-article-current nil))
6957       (if (not gnus-kill-summary-on-exit)
6958           (gnus-deaden-summary)
6959         (gnus-close-group group)
6960         (gnus-summary-clear-local-variables)
6961         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6962           (gnus-summary-clear-local-variables))
6963         (gnus-kill-buffer gnus-summary-buffer))
6964       (unless gnus-single-article-buffer
6965         (setq gnus-article-current nil))
6966       (when gnus-use-trees
6967         (gnus-tree-close group))
6968       (gnus-async-prefetch-remove-group group)
6969       (when (get-buffer gnus-article-buffer)
6970         (bury-buffer gnus-article-buffer))
6971       ;; Return to the group buffer.
6972       (gnus-configure-windows 'group 'force)
6973       ;; Clear the current group name.
6974       (setq gnus-newsgroup-name nil)
6975       (unless (gnus-ephemeral-group-p group)
6976         (gnus-group-update-group group))
6977       (when (equal (gnus-group-group-name) group)
6978         (gnus-group-next-unread-group 1))
6979       (when quit-config
6980         (gnus-handle-ephemeral-exit quit-config)))))
6981
6982 (defun gnus-handle-ephemeral-exit (quit-config)
6983   "Handle movement when leaving an ephemeral group.
6984 The state which existed when entering the ephemeral is reset."
6985   (if (not (buffer-name (car quit-config)))
6986       (gnus-configure-windows 'group 'force)
6987     (set-buffer (car quit-config))
6988     (cond ((eq major-mode 'gnus-summary-mode)
6989            (gnus-set-global-variables))
6990           ((eq major-mode 'gnus-article-mode)
6991            (save-excursion
6992              ;; The `gnus-summary-buffer' variable may point
6993              ;; to the old summary buffer when using a single
6994              ;; article buffer.
6995              (unless (gnus-buffer-live-p gnus-summary-buffer)
6996                (set-buffer gnus-group-buffer))
6997              (set-buffer gnus-summary-buffer)
6998              (gnus-set-global-variables))))
6999     (if (or (eq (cdr quit-config) 'article)
7000             (eq (cdr quit-config) 'pick))
7001         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7002             (gnus-configure-windows 'pick 'force)
7003           (gnus-configure-windows (cdr quit-config) 'force))
7004       (gnus-configure-windows (cdr quit-config) 'force))
7005     (when (eq major-mode 'gnus-summary-mode)
7006       (gnus-summary-recenter)
7007       (gnus-summary-position-point))))
7008
7009 ;;; Dead summaries.
7010
7011 (defvar gnus-dead-summary-mode-map nil)
7012
7013 (unless gnus-dead-summary-mode-map
7014   (setq gnus-dead-summary-mode-map (make-keymap))
7015   (suppress-keymap gnus-dead-summary-mode-map)
7016   (substitute-key-definition
7017    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
7018   (dolist (key '("\C-d" "\r" "\177" [delete]))
7019     (define-key gnus-dead-summary-mode-map
7020       key 'gnus-summary-wake-up-the-dead))
7021   (dolist (key '("q" "Q"))
7022     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
7023
7024 (defvar gnus-dead-summary-mode nil
7025   "Minor mode for Gnus summary buffers.")
7026
7027 (defun gnus-dead-summary-mode (&optional arg)
7028   "Minor mode for Gnus summary buffers."
7029   (interactive "P")
7030   (when (eq major-mode 'gnus-summary-mode)
7031     (make-local-variable 'gnus-dead-summary-mode)
7032     (setq gnus-dead-summary-mode
7033           (if (null arg) (not gnus-dead-summary-mode)
7034             (> (prefix-numeric-value arg) 0)))
7035     (when gnus-dead-summary-mode
7036       (add-minor-mode
7037        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
7038
7039 (defun gnus-deaden-summary ()
7040   "Make the current summary buffer into a dead summary buffer."
7041   ;; Kill any previous dead summary buffer.
7042   (when (and gnus-dead-summary
7043              (buffer-name gnus-dead-summary))
7044     (with-current-buffer gnus-dead-summary
7045       (when gnus-dead-summary-mode
7046         (kill-buffer (current-buffer)))))
7047   ;; Make this the current dead summary.
7048   (setq gnus-dead-summary (current-buffer))
7049   (gnus-dead-summary-mode 1)
7050   (let ((name (buffer-name)))
7051     (when (string-match "Summary" name)
7052       (rename-buffer
7053        (concat (substring name 0 (match-beginning 0)) "Dead "
7054                (substring name (match-beginning 0)))
7055        t)
7056       (bury-buffer))))
7057
7058 (defun gnus-kill-or-deaden-summary (buffer)
7059   "Kill or deaden the summary BUFFER."
7060   (save-excursion
7061     (when (and (buffer-name buffer)
7062                (not gnus-single-article-buffer))
7063       (with-current-buffer buffer
7064         (gnus-kill-buffer gnus-article-buffer)
7065         (gnus-kill-buffer gnus-original-article-buffer)))
7066     (cond
7067      ;; Kill the buffer.
7068      (gnus-kill-summary-on-exit
7069       (when (and gnus-use-trees
7070                  (gnus-buffer-exists-p buffer))
7071         (save-excursion
7072           (set-buffer buffer)
7073           (gnus-tree-close gnus-newsgroup-name)))
7074       (gnus-kill-buffer buffer))
7075      ;; Deaden the buffer.
7076      ((gnus-buffer-exists-p buffer)
7077       (save-excursion
7078         (set-buffer buffer)
7079         (gnus-deaden-summary))))))
7080
7081 (defun gnus-summary-wake-up-the-dead (&rest args)
7082   "Wake up the dead summary buffer."
7083   (interactive)
7084   (gnus-dead-summary-mode -1)
7085   (let ((name (buffer-name)))
7086     (when (string-match "Dead " name)
7087       (rename-buffer
7088        (concat (substring name 0 (match-beginning 0))
7089                (substring name (match-end 0)))
7090        t)))
7091   (gnus-message 3 "This dead summary is now alive again"))
7092
7093 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7094 (defun gnus-summary-fetch-faq (&optional faq-dir)
7095   "Fetch the FAQ for the current group.
7096 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7097 in."
7098   (interactive
7099    (list
7100     (when current-prefix-arg
7101       (completing-read
7102        "FAQ dir: " (and (listp gnus-group-faq-directory)
7103                         (mapcar 'list
7104                                 gnus-group-faq-directory))))))
7105   (let (gnus-faq-buffer)
7106     (when (setq gnus-faq-buffer
7107                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7108       (gnus-configure-windows 'summary-faq))))
7109
7110 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7111 (defun gnus-summary-describe-group (&optional force)
7112   "Describe the current newsgroup."
7113   (interactive "P")
7114   (gnus-group-describe-group force gnus-newsgroup-name))
7115
7116 (defun gnus-summary-describe-briefly ()
7117   "Describe summary mode commands briefly."
7118   (interactive)
7119   (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")))
7120
7121 ;; Walking around group mode buffer from summary mode.
7122
7123 (defun gnus-summary-next-group (&optional no-article target-group backward)
7124   "Exit current newsgroup and then select next unread newsgroup.
7125 If prefix argument NO-ARTICLE is non-nil, no article is selected
7126 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7127 previous group instead."
7128   (interactive "P")
7129   ;; Stop pre-fetching.
7130   (gnus-async-halt-prefetch)
7131   (let ((current-group gnus-newsgroup-name)
7132         (current-buffer (current-buffer))
7133         entered)
7134     ;; First we semi-exit this group to update Xrefs and all variables.
7135     ;; We can't do a real exit, because the window conf must remain
7136     ;; the same in case the user is prompted for info, and we don't
7137     ;; want the window conf to change before that...
7138     (gnus-summary-exit t)
7139     (while (not entered)
7140       ;; Then we find what group we are supposed to enter.
7141       (set-buffer gnus-group-buffer)
7142       (gnus-group-jump-to-group current-group)
7143       (setq target-group
7144             (or target-group
7145                 (if (eq gnus-keep-same-level 'best)
7146                     (gnus-summary-best-group gnus-newsgroup-name)
7147                   (gnus-summary-search-group backward gnus-keep-same-level))))
7148       (if (not target-group)
7149           ;; There are no further groups, so we return to the group
7150           ;; buffer.
7151           (progn
7152             (gnus-message 5 "Returning to the group buffer")
7153             (setq entered t)
7154             (when (gnus-buffer-live-p current-buffer)
7155               (set-buffer current-buffer)
7156               (gnus-summary-exit))
7157             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7158         ;; We try to enter the target group.
7159         (gnus-group-jump-to-group target-group)
7160         (let ((unreads (gnus-group-group-unread)))
7161           (if (and (or (eq t unreads)
7162                        (and unreads (not (zerop unreads))))
7163                    (gnus-summary-read-group
7164                     target-group nil no-article
7165                     (and (buffer-name current-buffer) current-buffer)
7166                     nil backward))
7167               (setq entered t)
7168             (setq current-group target-group
7169                   target-group nil)))))))
7170
7171 (defun gnus-summary-prev-group (&optional no-article)
7172   "Exit current newsgroup and then select previous unread newsgroup.
7173 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7174   (interactive "P")
7175   (gnus-summary-next-group no-article nil t))
7176
7177 ;; Walking around summary lines.
7178
7179 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7180   "Go to the first subject satisfying any non-nil constraint.
7181 If UNREAD is non-nil, the article should be unread.
7182 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7183 If UNSEEN is non-nil, the article should be unseen.
7184 Returns the article selected or nil if there are no matching articles."
7185   (interactive "P")
7186   (cond
7187    ;; Empty summary.
7188    ((null gnus-newsgroup-data)
7189     (gnus-message 3 "No articles in the group")
7190     nil)
7191    ;; Pick the first article.
7192    ((not (or unread undownloaded unseen))
7193     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7194     (gnus-data-number (car gnus-newsgroup-data)))
7195    ;; Find the first unread article.
7196    (t
7197     (let ((data gnus-newsgroup-data))
7198       (while (and data
7199                   (let ((num (gnus-data-number (car data))))
7200                     (or (memq num gnus-newsgroup-unfetched)
7201                         (not (or (and unread
7202                                       (memq num gnus-newsgroup-unreads))
7203                                  (and undownloaded
7204                                       (memq num gnus-newsgroup-undownloaded))
7205                                  (and unseen
7206                                       (memq num gnus-newsgroup-unseen)))))))
7207         (setq data (cdr data)))
7208       (prog1
7209           (if data
7210               (progn
7211                 (goto-char (gnus-data-pos (car data)))
7212                 (gnus-data-number (car data)))
7213             (gnus-message 3 "No more%s articles"
7214                           (let* ((r (when unread " unread"))
7215                                  (d (when undownloaded " undownloaded"))
7216                                  (s (when unseen " unseen"))
7217                                  (l (delq nil (list r d s))))
7218                             (cond ((= 3 (length l))
7219                                    (concat r "," d ", or" s))
7220                                   ((= 2 (length l))
7221                                    (concat (car l) ", or" (cadr l)))
7222                                   ((= 1 (length l))
7223                                    (car l))
7224                                   (t
7225                                    ""))))
7226             nil
7227             )
7228         (gnus-summary-position-point))))))
7229
7230 (defun gnus-summary-next-subject (n &optional unread dont-display)
7231   "Go to next N'th summary line.
7232 If N is negative, go to the previous N'th subject line.
7233 If UNREAD is non-nil, only unread articles are selected.
7234 The difference between N and the actual number of steps taken is
7235 returned."
7236   (interactive "p")
7237   (let ((backward (< n 0))
7238         (n (abs n)))
7239     (while (and (> n 0)
7240                 (if backward
7241                     (gnus-summary-find-prev unread)
7242                   (gnus-summary-find-next unread)))
7243       (unless (zerop (setq n (1- n)))
7244         (gnus-summary-show-thread)))
7245     (when (/= 0 n)
7246       (gnus-message 7 "No more%s articles"
7247                     (if unread " unread" "")))
7248     (unless dont-display
7249       (gnus-summary-recenter)
7250       (gnus-summary-position-point))
7251     n))
7252
7253 (defun gnus-summary-next-unread-subject (n)
7254   "Go to next N'th unread summary line."
7255   (interactive "p")
7256   (gnus-summary-next-subject n t))
7257
7258 (defun gnus-summary-prev-subject (n &optional unread)
7259   "Go to previous N'th summary line.
7260 If optional argument UNREAD is non-nil, only unread article is selected."
7261   (interactive "p")
7262   (gnus-summary-next-subject (- n) unread))
7263
7264 (defun gnus-summary-prev-unread-subject (n)
7265   "Go to previous N'th unread summary line."
7266   (interactive "p")
7267   (gnus-summary-next-subject (- n) t))
7268
7269 (defun gnus-summary-goto-subjects (articles)
7270   "Insert the subject header for ARTICLES in the current buffer."
7271   (save-excursion
7272     (dolist (article articles)
7273       (gnus-summary-goto-subject article t)))
7274   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7275   (gnus-summary-position-point))
7276
7277 (defun gnus-summary-goto-subject (article &optional force silent)
7278   "Go the subject line of ARTICLE.
7279 If FORCE, also allow jumping to articles not currently shown."
7280   (interactive "nArticle number: ")
7281   (unless (numberp article)
7282     (error "Article %s is not a number" article))
7283   (let ((b (point))
7284         (data (gnus-data-find article)))
7285     ;; We read in the article if we have to.
7286     (and (not data)
7287          force
7288          (gnus-summary-insert-subject
7289           article
7290           (if (or (numberp force) (vectorp force)) force)
7291           t)
7292          (setq data (gnus-data-find article)))
7293     (goto-char b)
7294     (if (not data)
7295         (progn
7296           (unless silent
7297             (gnus-message 3 "Can't find article %d" article))
7298           nil)
7299       (let ((pt (gnus-data-pos data)))
7300         (goto-char pt)
7301         (gnus-summary-set-article-display-arrow pt))
7302       (gnus-summary-position-point)
7303       article)))
7304
7305 ;; Walking around summary lines with displaying articles.
7306
7307 (defun gnus-summary-expand-window (&optional arg)
7308   "Make the summary buffer take up the entire Emacs frame.
7309 Given a prefix, will force an `article' buffer configuration."
7310   (interactive "P")
7311   (if arg
7312       (gnus-configure-windows 'article 'force)
7313     (gnus-configure-windows 'summary 'force)))
7314
7315 (defun gnus-summary-display-article (article &optional all-header)
7316   "Display ARTICLE in article buffer."
7317   (when (gnus-buffer-live-p gnus-article-buffer)
7318     (with-current-buffer gnus-article-buffer
7319       (mm-enable-multibyte)))
7320   (gnus-set-global-variables)
7321   (when (gnus-buffer-live-p gnus-article-buffer)
7322     (with-current-buffer gnus-article-buffer
7323       (setq gnus-article-charset gnus-newsgroup-charset)
7324       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7325       (mm-enable-multibyte)))
7326   (if (null article)
7327       nil
7328     (prog1
7329         (if gnus-summary-display-article-function
7330             (funcall gnus-summary-display-article-function article all-header)
7331           (gnus-article-prepare article all-header))
7332       (gnus-run-hooks 'gnus-select-article-hook)
7333       (when (and gnus-current-article
7334                  (not (zerop gnus-current-article)))
7335         (gnus-summary-goto-subject gnus-current-article))
7336       (gnus-summary-recenter)
7337       (when (and gnus-use-trees gnus-show-threads)
7338         (gnus-possibly-generate-tree article)
7339         (gnus-highlight-selected-tree article))
7340       ;; Successfully display article.
7341       (gnus-article-set-window-start
7342        (cdr (assq article gnus-newsgroup-bookmarks))))))
7343
7344 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7345   "Select the current article.
7346 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7347 non-nil, the article will be re-fetched even if it already present in
7348 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7349 be displayed."
7350   ;; Make sure we are in the summary buffer to work around bbdb bug.
7351   (unless (eq major-mode 'gnus-summary-mode)
7352     (set-buffer gnus-summary-buffer))
7353   (let ((article (or article (gnus-summary-article-number)))
7354         (all-headers (not (not all-headers))) ;Must be t or nil.
7355         gnus-summary-display-article-function)
7356     (and (not pseudo)
7357          (gnus-summary-article-pseudo-p article)
7358          (error "This is a pseudo-article"))
7359     (save-excursion
7360       (set-buffer gnus-summary-buffer)
7361       (if (or (and gnus-single-article-buffer
7362                    (or (null gnus-current-article)
7363                        (null gnus-article-current)
7364                        (null (get-buffer gnus-article-buffer))
7365                        (not (eq article (cdr gnus-article-current)))
7366                        (not (equal (car gnus-article-current)
7367                                    gnus-newsgroup-name))))
7368               (and (not gnus-single-article-buffer)
7369                    (or (null gnus-current-article)
7370                        (not (eq gnus-current-article article))))
7371               force)
7372           ;; The requested article is different from the current article.
7373           (progn
7374             (gnus-summary-display-article article all-headers)
7375             (when (gnus-buffer-live-p gnus-article-buffer)
7376               (with-current-buffer gnus-article-buffer
7377                 (if (not gnus-article-decoded-p) ;; a local variable
7378                     (mm-disable-multibyte))))
7379             (gnus-article-set-window-start
7380              (cdr (assq article gnus-newsgroup-bookmarks)))
7381             article)
7382         'old))))
7383
7384 (defun gnus-summary-force-verify-and-decrypt ()
7385   "Display buttons for signed/encrypted parts and verify/decrypt them."
7386   (interactive)
7387   (let ((mm-verify-option 'known)
7388         (mm-decrypt-option 'known)
7389         (gnus-article-emulate-mime t)
7390         (gnus-buttonized-mime-types (append (list "multipart/signed"
7391                                                   "multipart/encrypted")
7392                                             gnus-buttonized-mime-types)))
7393     (gnus-summary-select-article nil 'force)))
7394
7395 (defun gnus-summary-set-current-mark (&optional current-mark)
7396   "Obsolete function."
7397   nil)
7398
7399 (defun gnus-summary-next-article (&optional unread subject backward push)
7400   "Select the next article.
7401 If UNREAD, only unread articles are selected.
7402 If SUBJECT, only articles with SUBJECT are selected.
7403 If BACKWARD, the previous article is selected instead of the next."
7404   (interactive "P")
7405   (cond
7406    ;; Is there such an article?
7407    ((and (gnus-summary-search-forward unread subject backward)
7408          (or (gnus-summary-display-article (gnus-summary-article-number))
7409              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7410     (gnus-summary-position-point))
7411    ;; If not, we try the first unread, if that is wanted.
7412    ((and subject
7413          gnus-auto-select-same
7414          (gnus-summary-first-unread-article))
7415     (gnus-summary-position-point)
7416     (gnus-message 6 "Wrapped"))
7417    ;; Try to get next/previous article not displayed in this group.
7418    ((and gnus-auto-extend-newsgroup
7419          (not unread) (not subject))
7420     (gnus-summary-goto-article
7421      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7422      nil (count-lines (point-min) (point))))
7423    ;; Go to next/previous group.
7424    (t
7425     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7426       (gnus-summary-jump-to-group gnus-newsgroup-name))
7427     (let ((cmd last-command-char)
7428           (point
7429            (with-current-buffer gnus-group-buffer
7430              (point)))
7431           (group
7432            (if (eq gnus-keep-same-level 'best)
7433                (gnus-summary-best-group gnus-newsgroup-name)
7434              (gnus-summary-search-group backward gnus-keep-same-level))))
7435       ;; For some reason, the group window gets selected.  We change
7436       ;; it back.
7437       (select-window (get-buffer-window (current-buffer)))
7438       ;; Select next unread newsgroup automagically.
7439       (cond
7440        ((or (not gnus-auto-select-next)
7441             (not cmd))
7442         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7443        ((or (eq gnus-auto-select-next 'quietly)
7444             (and (eq gnus-auto-select-next 'slightly-quietly)
7445                  push)
7446             (and (eq gnus-auto-select-next 'almost-quietly)
7447                  (gnus-summary-last-article-p)))
7448         ;; Select quietly.
7449         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7450             (gnus-summary-exit)
7451           (gnus-message 7 "No more%s articles (%s)..."
7452                         (if unread " unread" "")
7453                         (if group (concat "selecting " group)
7454                           "exiting"))
7455           (gnus-summary-next-group nil group backward)))
7456        (t
7457         (when (gnus-key-press-event-p last-input-event)
7458           (gnus-summary-walk-group-buffer
7459            gnus-newsgroup-name cmd unread backward point))))))))
7460
7461 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7462   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7463                       (?\C-p (gnus-group-prev-unread-group 1))))
7464         (cursor-in-echo-area t)
7465         keve key group ended prompt)
7466     (save-excursion
7467       (set-buffer gnus-group-buffer)
7468       (goto-char start)
7469       (setq group
7470             (if (eq gnus-keep-same-level 'best)
7471                 (gnus-summary-best-group gnus-newsgroup-name)
7472               (gnus-summary-search-group backward gnus-keep-same-level))))
7473     (while (not ended)
7474       (setq prompt
7475             (format
7476              "No more%s articles%s " (if unread " unread" "")
7477              (if (and group
7478                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7479                  (format " (Type %s for %s [%s])"
7480                          (single-key-description cmd)
7481                          (gnus-group-decoded-name group)
7482                          (gnus-group-unread group))
7483                (format " (Type %s to exit %s)"
7484                        (single-key-description cmd)
7485                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7486       ;; Confirm auto selection.
7487       (setq key (car (setq keve (gnus-read-event-char prompt)))
7488             ended t)
7489       (cond
7490        ((assq key keystrokes)
7491         (let ((obuf (current-buffer)))
7492           (switch-to-buffer gnus-group-buffer)
7493           (when group
7494             (gnus-group-jump-to-group group))
7495           (eval (cadr (assq key keystrokes)))
7496           (setq group (gnus-group-group-name))
7497           (switch-to-buffer obuf))
7498         (setq ended nil))
7499        ((equal key cmd)
7500         (if (or (not group)
7501                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7502             (gnus-summary-exit)
7503           (gnus-summary-next-group nil group backward)))
7504        (t
7505         (push (cdr keve) unread-command-events))))))
7506
7507 (defun gnus-summary-next-unread-article ()
7508   "Select unread article after current one."
7509   (interactive)
7510   (gnus-summary-next-article
7511    (or (not (eq gnus-summary-goto-unread 'never))
7512        (gnus-summary-last-article-p (gnus-summary-article-number)))
7513    (and gnus-auto-select-same
7514         (gnus-summary-article-subject))))
7515
7516 (defun gnus-summary-prev-article (&optional unread subject)
7517   "Select the article after the current one.
7518 If UNREAD is non-nil, only unread articles are selected."
7519   (interactive "P")
7520   (gnus-summary-next-article unread subject t))
7521
7522 (defun gnus-summary-prev-unread-article ()
7523   "Select unread article before current one."
7524   (interactive)
7525   (gnus-summary-prev-article
7526    (or (not (eq gnus-summary-goto-unread 'never))
7527        (gnus-summary-first-article-p (gnus-summary-article-number)))
7528    (and gnus-auto-select-same
7529         (gnus-summary-article-subject))))
7530
7531 (defun gnus-summary-next-page (&optional lines circular stop)
7532   "Show next page of the selected article.
7533 If at the end of the current article, select the next article.
7534 LINES says how many lines should be scrolled up.
7535
7536 If CIRCULAR is non-nil, go to the start of the article instead of
7537 selecting the next article when reaching the end of the current
7538 article.
7539
7540 If STOP is non-nil, just stop when reaching the end of the message.
7541
7542 Also see the variable `gnus-article-skip-boring'."
7543   (interactive "P")
7544   (setq gnus-summary-buffer (current-buffer))
7545   (gnus-set-global-variables)
7546   (let ((article (gnus-summary-article-number))
7547         (article-window (get-buffer-window gnus-article-buffer t))
7548         endp)
7549     ;; If the buffer is empty, we have no article.
7550     (unless article
7551       (error "No article to select"))
7552     (gnus-configure-windows 'article)
7553     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7554         (if (and (eq gnus-summary-goto-unread 'never)
7555                  (not (gnus-summary-last-article-p article)))
7556             (gnus-summary-next-article)
7557           (gnus-summary-next-unread-article))
7558       (if (or (null gnus-current-article)
7559               (null gnus-article-current)
7560               (/= article (cdr gnus-article-current))
7561               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7562           ;; Selected subject is different from current article's.
7563           (gnus-summary-display-article article)
7564         (when article-window
7565           (gnus-eval-in-buffer-window gnus-article-buffer
7566             (setq endp (or (gnus-article-next-page lines)
7567                            (gnus-article-only-boring-p))))
7568           (when endp
7569             (cond (stop
7570                    (gnus-message 3 "End of message"))
7571                   (circular
7572                    (gnus-summary-beginning-of-article))
7573                   (lines
7574                    (gnus-message 3 "End of message"))
7575                   ((null lines)
7576                    (if (and (eq gnus-summary-goto-unread 'never)
7577                             (not (gnus-summary-last-article-p article)))
7578                        (gnus-summary-next-article)
7579                      (gnus-summary-next-unread-article))))))))
7580     (gnus-summary-recenter)
7581     (gnus-summary-position-point)))
7582
7583 (defun gnus-summary-prev-page (&optional lines move)
7584   "Show previous page of selected article.
7585 Argument LINES specifies lines to be scrolled down.
7586 If MOVE, move to the previous unread article if point is at
7587 the beginning of the buffer."
7588   (interactive "P")
7589   (let ((article (gnus-summary-article-number))
7590         (article-window (get-buffer-window gnus-article-buffer t))
7591         endp)
7592     (gnus-configure-windows 'article)
7593     (if (or (null gnus-current-article)
7594             (null gnus-article-current)
7595             (/= article (cdr gnus-article-current))
7596             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7597         ;; Selected subject is different from current article's.
7598         (gnus-summary-display-article article)
7599       (gnus-summary-recenter)
7600       (when article-window
7601         (gnus-eval-in-buffer-window gnus-article-buffer
7602           (setq endp (gnus-article-prev-page lines)))
7603         (when (and move endp)
7604           (cond (lines
7605                  (gnus-message 3 "Beginning of message"))
7606                 ((null lines)
7607                  (if (and (eq gnus-summary-goto-unread 'never)
7608                           (not (gnus-summary-first-article-p article)))
7609                      (gnus-summary-prev-article)
7610                    (gnus-summary-prev-unread-article))))))))
7611   (gnus-summary-position-point))
7612
7613 (defun gnus-summary-prev-page-or-article (&optional lines)
7614   "Show previous page of selected article.
7615 Argument LINES specifies lines to be scrolled down.
7616 If at the beginning of the article, go to the next article."
7617   (interactive "P")
7618   (gnus-summary-prev-page lines t))
7619
7620 (defun gnus-summary-scroll-up (lines)
7621   "Scroll up (or down) one line current article.
7622 Argument LINES specifies lines to be scrolled up (or down if negative)."
7623   (interactive "p")
7624   (gnus-configure-windows 'article)
7625   (gnus-summary-show-thread)
7626   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7627     (gnus-eval-in-buffer-window gnus-article-buffer
7628       (cond ((> lines 0)
7629              (when (gnus-article-next-page lines)
7630                (gnus-message 3 "End of message")))
7631             ((< lines 0)
7632              (gnus-article-prev-page (- lines))))))
7633   (gnus-summary-recenter)
7634   (gnus-summary-position-point))
7635
7636 (defun gnus-summary-scroll-down (lines)
7637   "Scroll down (or up) one line current article.
7638 Argument LINES specifies lines to be scrolled down (or up if negative)."
7639   (interactive "p")
7640   (gnus-summary-scroll-up (- lines)))
7641
7642 (defun gnus-summary-next-same-subject ()
7643   "Select next article which has the same subject as current one."
7644   (interactive)
7645   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7646
7647 (defun gnus-summary-prev-same-subject ()
7648   "Select previous article which has the same subject as current one."
7649   (interactive)
7650   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7651
7652 (defun gnus-summary-next-unread-same-subject ()
7653   "Select next unread article which has the same subject as current one."
7654   (interactive)
7655   (gnus-summary-next-article t (gnus-summary-article-subject)))
7656
7657 (defun gnus-summary-prev-unread-same-subject ()
7658   "Select previous unread article which has the same subject as current one."
7659   (interactive)
7660   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7661
7662 (defun gnus-summary-first-unread-article ()
7663   "Select the first unread article.
7664 Return nil if there are no unread articles."
7665   (interactive)
7666   (prog1
7667       (when (gnus-summary-first-subject t)
7668         (gnus-summary-show-thread)
7669         (gnus-summary-first-subject t)
7670         (gnus-summary-display-article (gnus-summary-article-number)))
7671     (gnus-summary-position-point)))
7672
7673 (defun gnus-summary-first-unread-subject ()
7674   "Place the point on the subject line of the first unread article.
7675 Return nil if there are no unread articles."
7676   (interactive)
7677   (prog1
7678       (when (gnus-summary-first-subject t)
7679         (gnus-summary-show-thread)
7680         (gnus-summary-first-subject t))
7681     (gnus-summary-position-point)))
7682
7683 (defun gnus-summary-first-unseen-subject ()
7684   "Place the point on the subject line of the first unseen article.
7685 Return nil if there are no unseen articles."
7686   (interactive)
7687   (prog1
7688       (when (gnus-summary-first-subject nil nil t)
7689         (gnus-summary-show-thread)
7690         (gnus-summary-first-subject nil nil t))
7691     (gnus-summary-position-point)))
7692
7693 (defun gnus-summary-first-unseen-or-unread-subject ()
7694   "Place the point on the subject line of the first unseen article or,
7695 if all article have been seen, on the subject line of the first unread
7696 article."
7697   (interactive)
7698   (prog1
7699       (unless (when (gnus-summary-first-subject nil nil t)
7700                 (gnus-summary-show-thread)
7701                 (gnus-summary-first-subject nil nil t))
7702         (when (gnus-summary-first-subject t)
7703           (gnus-summary-show-thread)
7704           (gnus-summary-first-subject t)))
7705     (gnus-summary-position-point)))
7706
7707 (defun gnus-summary-first-article ()
7708   "Select the first article.
7709 Return nil if there are no articles."
7710   (interactive)
7711   (prog1
7712       (when (gnus-summary-first-subject)
7713         (gnus-summary-show-thread)
7714         (gnus-summary-first-subject)
7715         (gnus-summary-display-article (gnus-summary-article-number)))
7716     (gnus-summary-position-point)))
7717
7718 (defun gnus-summary-best-unread-article (&optional arg)
7719   "Select the unread article with the highest score.
7720 If given a prefix argument, select the next unread article that has a
7721 score higher than the default score."
7722   (interactive "P")
7723   (let ((article (if arg
7724                      (gnus-summary-better-unread-subject)
7725                    (gnus-summary-best-unread-subject))))
7726     (if article
7727         (gnus-summary-goto-article article)
7728       (error "No unread articles"))))
7729
7730 (defun gnus-summary-best-unread-subject ()
7731   "Select the unread subject with the highest score."
7732   (interactive)
7733   (let ((best -1000000)
7734         (data gnus-newsgroup-data)
7735         article score)
7736     (while data
7737       (and (gnus-data-unread-p (car data))
7738            (> (setq score
7739                     (gnus-summary-article-score (gnus-data-number (car data))))
7740               best)
7741            (setq best score
7742                  article (gnus-data-number (car data))))
7743       (setq data (cdr data)))
7744     (when article
7745       (gnus-summary-goto-subject article))
7746     (gnus-summary-position-point)
7747     article))
7748
7749 (defun gnus-summary-better-unread-subject ()
7750   "Select the first unread subject that has a score over the default score."
7751   (interactive)
7752   (let ((data gnus-newsgroup-data)
7753         article score)
7754     (while (and (setq article (gnus-data-number (car data)))
7755                 (or (gnus-data-read-p (car data))
7756                     (not (> (gnus-summary-article-score article)
7757                             gnus-summary-default-score))))
7758       (setq data (cdr data)))
7759     (when article
7760       (gnus-summary-goto-subject article))
7761     (gnus-summary-position-point)
7762     article))
7763
7764 (defun gnus-summary-last-subject ()
7765   "Go to the last displayed subject line in the group."
7766   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7767     (when article
7768       (gnus-summary-goto-subject article))))
7769
7770 (defun gnus-summary-goto-article (article &optional all-headers force)
7771   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7772 If ALL-HEADERS is non-nil, no header lines are hidden.
7773 If FORCE, go to the article even if it isn't displayed.  If FORCE
7774 is a number, it is the line the article is to be displayed on."
7775   (interactive
7776    (list
7777     (completing-read
7778      "Article number or Message-ID: "
7779      (mapcar (lambda (number) (list (int-to-string number)))
7780              gnus-newsgroup-limit))
7781     current-prefix-arg
7782     t))
7783   (prog1
7784       (if (and (stringp article)
7785                (string-match "@\\|%40" article))
7786           (gnus-summary-refer-article article)
7787         (when (stringp article)
7788           (setq article (string-to-number article)))
7789         (if (gnus-summary-goto-subject article force)
7790             (gnus-summary-display-article article all-headers)
7791           (gnus-message 4 "Couldn't go to article %s" article) nil))
7792     (gnus-summary-position-point)))
7793
7794 (defun gnus-summary-goto-last-article ()
7795   "Go to the previously read article."
7796   (interactive)
7797   (prog1
7798       (when gnus-last-article
7799         (gnus-summary-goto-article gnus-last-article nil t))
7800     (gnus-summary-position-point)))
7801
7802 (defun gnus-summary-pop-article (number)
7803   "Pop one article off the history and go to the previous.
7804 NUMBER articles will be popped off."
7805   (interactive "p")
7806   (let (to)
7807     (setq gnus-newsgroup-history
7808           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7809     (if to
7810         (gnus-summary-goto-article (car to) nil t)
7811       (error "Article history empty")))
7812   (gnus-summary-position-point))
7813
7814 ;; Summary commands and functions for limiting the summary buffer.
7815
7816 (defun gnus-summary-limit-to-articles (n)
7817   "Limit the summary buffer to the next N articles.
7818 If not given a prefix, use the process marked articles instead."
7819   (interactive "P")
7820   (prog1
7821       (let ((articles (gnus-summary-work-articles n)))
7822         (setq gnus-newsgroup-processable nil)
7823         (gnus-summary-limit articles))
7824     (gnus-summary-position-point)))
7825
7826 (defun gnus-summary-pop-limit (&optional total)
7827   "Restore the previous limit.
7828 If given a prefix, remove all limits."
7829   (interactive "P")
7830   (when total
7831     (setq gnus-newsgroup-limits
7832           (list (mapcar (lambda (h) (mail-header-number h))
7833                         gnus-newsgroup-headers))))
7834   (unless gnus-newsgroup-limits
7835     (error "No limit to pop"))
7836   (prog1
7837       (gnus-summary-limit nil 'pop)
7838     (gnus-summary-position-point)))
7839
7840 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7841   "Limit the summary buffer to articles that have subjects that match a regexp.
7842 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7843   (interactive
7844    (list (read-string (if current-prefix-arg
7845                           "Exclude subject (regexp): "
7846                         "Limit to subject (regexp): "))
7847          nil current-prefix-arg))
7848   (unless header
7849     (setq header "subject"))
7850   (when (not (equal "" subject))
7851     (prog1
7852         (let ((articles (gnus-summary-find-matching
7853                          (or header "subject") subject 'all nil nil
7854                          not-matching)))
7855           (unless articles
7856             (error "Found no matches for \"%s\"" subject))
7857           (gnus-summary-limit articles))
7858       (gnus-summary-position-point))))
7859
7860 (defun gnus-summary-limit-to-author (from &optional not-matching)
7861   "Limit the summary buffer to articles that have authors that match a regexp.
7862 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7863   (interactive
7864    (list (read-string (if current-prefix-arg
7865                           "Exclude author (regexp): "
7866                         "Limit to author (regexp): "))
7867          current-prefix-arg))
7868   (gnus-summary-limit-to-subject from "from" not-matching))
7869
7870 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7871   "Limit the summary buffer to articles with the given RECIPIENT.
7872
7873 If NOT-MATCHING, exclude RECIPIENT.
7874
7875 To and Cc headers are checked.  You need to include them in
7876 `nnmail-extra-headers'."
7877   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7878   (interactive
7879    (list (read-string (format "%s recipient (regexp): "
7880                               (if current-prefix-arg "Exclude" "Limit to")))
7881          current-prefix-arg))
7882   (when (not (equal "" recipient))
7883     (prog1 (let* ((to
7884                    (if (memq 'To nnmail-extra-headers)
7885                        (gnus-summary-find-matching
7886                         (cons 'extra 'To) recipient 'all nil nil
7887                         not-matching)
7888                      (gnus-message
7889                       1 "`To' isn't present in `nnmail-extra-headers'")
7890                      (sit-for 1)
7891                      nil))
7892                   (cc
7893                    (if (memq 'Cc nnmail-extra-headers)
7894                        (gnus-summary-find-matching
7895                         (cons 'extra 'Cc) recipient 'all nil nil
7896                         not-matching)
7897                      (gnus-message
7898                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7899                      (sit-for 1)
7900                      nil))
7901                   (articles
7902                    (if not-matching
7903                        ;; We need the numbers that are in both lists:
7904                        (mapcar (lambda (a)
7905                                  (and (memq a to) a))
7906                                cc)
7907                      (nconc to cc))))
7908              (unless articles
7909                (error "Found no matches for \"%s\"" recipient))
7910              (gnus-summary-limit articles))
7911       (gnus-summary-position-point))))
7912
7913 (defun gnus-summary-limit-strange-charsets-predicate (header)
7914   (let ((string (concat (mail-header-subject header)
7915                         (mail-header-from header)))
7916         charset found)
7917     (dotimes (i (1- (length string)))
7918       (setq charset (format "%s" (char-charset (aref string (1+ i)))))
7919       (when (string-match "unicode\\|big\\|japanese" charset)
7920         (setq found t)))
7921     found))
7922
7923 (defun gnus-summary-limit-to-predicate (predicate)
7924   "Limit to articles where PREDICATE returns non-nil.
7925 PREDICATE will be called with the header structures of the
7926 articles."
7927   (let ((articles nil)
7928         (case-fold-search t))
7929     (dolist (header gnus-newsgroup-headers)
7930       (when (funcall predicate header)
7931         (push (mail-header-number header) articles)))
7932     (gnus-summary-limit (nreverse articles))))
7933
7934 (defun gnus-summary-limit-to-age (age &optional younger-p)
7935   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7936 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7937 articles that are younger than AGE days."
7938   (interactive
7939    (let ((younger current-prefix-arg)
7940          (days-got nil)
7941          days)
7942      (while (not days-got)
7943        (setq days (if younger
7944                       (read-string "Limit to articles younger than (in days, older when negative): ")
7945                     (read-string
7946                      "Limit to articles older than (in days, younger when negative): ")))
7947        (when (> (length days) 0)
7948          (setq days (read days)))
7949        (if (numberp days)
7950            (progn
7951              (setq days-got t)
7952              (when (< days 0)
7953                (setq younger (not younger))
7954                (setq days (* days -1))))
7955          (message "Please enter a number.")
7956          (sleep-for 1)))
7957      (list days younger)))
7958   (prog1
7959       (let ((data gnus-newsgroup-data)
7960             (cutoff (days-to-time age))
7961             articles d date is-younger)
7962         (while (setq d (pop data))
7963           (when (and (vectorp (gnus-data-header d))
7964                      (setq date (mail-header-date (gnus-data-header d))))
7965             (setq is-younger (time-less-p
7966                               (time-since (condition-case ()
7967                                               (date-to-time date)
7968                                             (error '(0 0))))
7969                               cutoff))
7970             (when (if younger-p
7971                       is-younger
7972                     (not is-younger))
7973               (push (gnus-data-number d) articles))))
7974         (gnus-summary-limit (nreverse articles)))
7975     (gnus-summary-position-point)))
7976
7977 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7978   "Limit the summary buffer to articles that match an 'extra' header."
7979   (interactive
7980    (let ((header
7981           (intern
7982            (gnus-completing-read-with-default
7983             (symbol-name (car gnus-extra-headers))
7984             (if current-prefix-arg
7985                 "Exclude extra header"
7986               "Limit extra header")
7987             (mapcar (lambda (x)
7988                       (cons (symbol-name x) x))
7989                     gnus-extra-headers)
7990             nil
7991             t))))
7992      (list header
7993            (read-string (format "%s header %s (regexp): "
7994                                 (if current-prefix-arg "Exclude" "Limit to")
7995                                 header))
7996            current-prefix-arg)))
7997   (when (not (equal "" regexp))
7998     (prog1
7999         (let ((articles (gnus-summary-find-matching
8000                          (cons 'extra header) regexp 'all nil nil
8001                          not-matching)))
8002           (unless articles
8003             (error "Found no matches for \"%s\"" regexp))
8004           (gnus-summary-limit articles))
8005       (gnus-summary-position-point))))
8006
8007 (defun gnus-summary-limit-to-display-predicate ()
8008   "Limit the summary buffer to the predicated in the `display' group parameter."
8009   (interactive)
8010   (unless gnus-newsgroup-display
8011     (error "There is no `display' group parameter"))
8012   (let (articles)
8013     (dolist (number gnus-newsgroup-articles)
8014       (when (funcall gnus-newsgroup-display)
8015         (push number articles)))
8016     (gnus-summary-limit articles))
8017   (gnus-summary-position-point))
8018
8019 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8020 (make-obsolete
8021  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8022
8023 (defun gnus-summary-limit-to-unread (&optional all)
8024   "Limit the summary buffer to articles that are not marked as read.
8025 If ALL is non-nil, limit strictly to unread articles."
8026   (interactive "P")
8027   (if all
8028       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8029     (gnus-summary-limit-to-marks
8030      ;; Concat all the marks that say that an article is read and have
8031      ;; those removed.
8032      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8033            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8034            gnus-low-score-mark gnus-expirable-mark
8035            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8036            gnus-duplicate-mark gnus-souped-mark)
8037      'reverse)))
8038
8039 (defun gnus-summary-limit-to-headers (match &optional reverse)
8040   "Limit the summary buffer to articles that have headers that match MATCH.
8041 If REVERSE (the prefix), limit to articles that don't match."
8042   (interactive "sMatch headers (regexp): \nP")
8043   (gnus-summary-limit-to-bodies match reverse t))
8044
8045 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8046   "Limit the summary buffer to articles that have bodies that match MATCH.
8047 If REVERSE (the prefix), limit to articles that don't match."
8048   (interactive "sMatch body (regexp): \nP")
8049   (let ((articles nil)
8050         (gnus-select-article-hook nil)  ;Disable hook.
8051         (gnus-article-prepare-hook nil)
8052         (gnus-use-article-prefetch nil)
8053         (gnus-keep-backlog nil)
8054         (gnus-break-pages nil)
8055         (gnus-summary-display-arrow nil)
8056         (gnus-updated-mode-lines nil)
8057         (gnus-auto-center-summary nil)
8058         (gnus-display-mime-function nil))
8059     (dolist (data gnus-newsgroup-data)
8060       (let (gnus-mark-article-hook)
8061         (gnus-summary-select-article t t nil (gnus-data-number data)))
8062       (save-excursion
8063         (set-buffer gnus-article-buffer)
8064         (article-goto-body)
8065         (let* ((case-fold-search t)
8066                (found (if headersp
8067                           (re-search-backward match nil t)
8068                         (re-search-forward match nil t))))
8069           (when (or (and found
8070                          (not reverse))
8071                     (and (not found)
8072                          reverse))
8073             (push (gnus-data-number data) articles)))))
8074     (if (not articles)
8075         (message "No messages matched")
8076       (gnus-summary-limit articles)))
8077   (gnus-summary-position-point))
8078
8079 (defun gnus-summary-limit-to-replied (&optional unreplied)
8080   "Limit the summary buffer to replied articles.
8081 If UNREPLIED (the prefix), limit to unreplied articles."
8082   (interactive "P")
8083   (if unreplied
8084       (gnus-summary-limit
8085        (gnus-set-difference gnus-newsgroup-articles
8086         gnus-newsgroup-replied))
8087     (gnus-summary-limit gnus-newsgroup-replied))
8088   (gnus-summary-position-point))
8089
8090 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8091 (make-obsolete 'gnus-summary-delete-marked-with
8092                'gnus-summary-limit-exclude-marks)
8093
8094 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8095   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8096 If REVERSE, limit the summary buffer to articles that are marked
8097 with MARKS.  MARKS can either be a string of marks or a list of marks.
8098 Returns how many articles were removed."
8099   (interactive "sMarks: ")
8100   (gnus-summary-limit-to-marks marks t))
8101
8102 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8103   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8104 If REVERSE (the prefix), limit the summary buffer to articles that are
8105 not marked with MARKS.  MARKS can either be a string of marks or a
8106 list of marks.
8107 Returns how many articles were removed."
8108   (interactive "sMarks: \nP")
8109   (prog1
8110       (let ((data gnus-newsgroup-data)
8111             (marks (if (listp marks) marks
8112                      (append marks nil))) ; Transform to list.
8113             articles)
8114         (while data
8115           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8116                   (memq (gnus-data-mark (car data)) marks))
8117             (push (gnus-data-number (car data)) articles))
8118           (setq data (cdr data)))
8119         (gnus-summary-limit articles))
8120     (gnus-summary-position-point)))
8121
8122 (defun gnus-summary-limit-to-score (score)
8123   "Limit to articles with score at or above SCORE."
8124   (interactive "NLimit to articles with score of at least: ")
8125   (let ((data gnus-newsgroup-data)
8126         articles)
8127     (while data
8128       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8129                 score)
8130         (push (gnus-data-number (car data)) articles))
8131       (setq data (cdr data)))
8132     (prog1
8133         (gnus-summary-limit articles)
8134       (gnus-summary-position-point))))
8135
8136 (defun gnus-summary-limit-to-unseen ()
8137   "Limit to unseen articles."
8138   (interactive)
8139   (prog1
8140       (gnus-summary-limit gnus-newsgroup-unseen)
8141     (gnus-summary-position-point)))
8142
8143 (defun gnus-summary-limit-include-thread (id)
8144   "Display all the hidden articles that is in the thread with ID in it.
8145 When called interactively, ID is the Message-ID of the current
8146 article."
8147   (interactive (list (mail-header-id (gnus-summary-article-header))))
8148   (let ((articles (gnus-articles-in-thread
8149                    (gnus-id-to-thread (gnus-root-id id)))))
8150     (prog1
8151         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8152       (gnus-summary-limit-include-matching-articles
8153        "subject"
8154        (regexp-quote (gnus-simplify-subject-re
8155                       (mail-header-subject (gnus-id-to-header id)))))
8156       (gnus-summary-position-point))))
8157
8158 (defun gnus-summary-limit-include-matching-articles (header regexp)
8159   "Display all the hidden articles that have HEADERs that match REGEXP."
8160   (interactive (list (read-string "Match on header: ")
8161                      (read-string "Regexp: ")))
8162   (let ((articles (gnus-find-matching-articles header regexp)))
8163     (prog1
8164         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8165       (gnus-summary-position-point))))
8166
8167 (defun gnus-summary-insert-dormant-articles ()
8168   "Insert all the dormant articles for this group into the current buffer."
8169   (interactive)
8170   (let ((gnus-verbose (max 6 gnus-verbose)))
8171     (if (not gnus-newsgroup-dormant)
8172         (gnus-message 3 "No cached articles for this group")
8173       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8174
8175 (defun gnus-summary-limit-include-dormant ()
8176   "Display all the hidden articles that are marked as dormant.
8177 Note that this command only works on a subset of the articles currently
8178 fetched for this group."
8179   (interactive)
8180   (unless gnus-newsgroup-dormant
8181     (error "There are no dormant articles in this group"))
8182   (prog1
8183       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8184     (gnus-summary-position-point)))
8185
8186 (defun gnus-summary-limit-exclude-dormant ()
8187   "Hide all dormant articles."
8188   (interactive)
8189   (prog1
8190       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8191     (gnus-summary-position-point)))
8192
8193 (defun gnus-summary-limit-exclude-childless-dormant ()
8194   "Hide all dormant articles that have no children."
8195   (interactive)
8196   (let ((data (gnus-data-list t))
8197         articles d children)
8198     ;; Find all articles that are either not dormant or have
8199     ;; children.
8200     (while (setq d (pop data))
8201       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8202                 (and (setq children
8203                            (gnus-article-children (gnus-data-number d)))
8204                      (let (found)
8205                        (while children
8206                          (when (memq (car children) articles)
8207                            (setq children nil
8208                                  found t))
8209                          (pop children))
8210                        found)))
8211         (push (gnus-data-number d) articles)))
8212     ;; Do the limiting.
8213     (prog1
8214         (gnus-summary-limit articles)
8215       (gnus-summary-position-point))))
8216
8217 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8218   "Mark all unread excluded articles as read.
8219 If ALL, mark even excluded ticked and dormants as read."
8220   (interactive "P")
8221   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8222   (let ((articles (gnus-sorted-ndifference
8223                    (sort
8224                     (mapcar (lambda (h) (mail-header-number h))
8225                             gnus-newsgroup-headers)
8226                     '<)
8227                    gnus-newsgroup-limit))
8228         article)
8229     (setq gnus-newsgroup-unreads
8230           (gnus-sorted-intersection gnus-newsgroup-unreads
8231                                     gnus-newsgroup-limit))
8232     (if all
8233         (setq gnus-newsgroup-dormant nil
8234               gnus-newsgroup-marked nil
8235               gnus-newsgroup-reads
8236               (nconc
8237                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8238                gnus-newsgroup-reads))
8239       (while (setq article (pop articles))
8240         (unless (or (memq article gnus-newsgroup-dormant)
8241                     (memq article gnus-newsgroup-marked))
8242           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8243
8244 (defun gnus-summary-limit (articles &optional pop)
8245   (if pop
8246       ;; We pop the previous limit off the stack and use that.
8247       (setq articles (car gnus-newsgroup-limits)
8248             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8249     ;; We use the new limit, so we push the old limit on the stack.
8250     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8251   ;; Set the limit.
8252   (setq gnus-newsgroup-limit articles)
8253   (let ((total (length gnus-newsgroup-data))
8254         (data (gnus-data-find-list (gnus-summary-article-number)))
8255         (gnus-summary-mark-below nil)   ; Inhibit this.
8256         found)
8257     ;; This will do all the work of generating the new summary buffer
8258     ;; according to the new limit.
8259     (gnus-summary-prepare)
8260     ;; Hide any threads, possibly.
8261     (gnus-summary-maybe-hide-threads)
8262     ;; Try to return to the article you were at, or one in the
8263     ;; neighborhood.
8264     (when data
8265       ;; We try to find some article after the current one.
8266       (while data
8267         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8268           (setq data nil
8269                 found t))
8270         (setq data (cdr data))))
8271     (unless found
8272       ;; If there is no data, that means that we were after the last
8273       ;; article.  The same goes when we can't find any articles
8274       ;; after the current one.
8275       (goto-char (point-max))
8276       (gnus-summary-find-prev))
8277     (gnus-set-mode-line 'summary)
8278     ;; We return how many articles were removed from the summary
8279     ;; buffer as a result of the new limit.
8280     (- total (length gnus-newsgroup-data))))
8281
8282 (defsubst gnus-invisible-cut-children (threads)
8283   (let ((num 0))
8284     (while threads
8285       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8286         (incf num))
8287       (pop threads))
8288     (< num 2)))
8289
8290 (defsubst gnus-cut-thread (thread)
8291   "Go forwards in the thread until we find an article that we want to display."
8292   (when (or (eq gnus-fetch-old-headers 'some)
8293             (eq gnus-fetch-old-headers 'invisible)
8294             (numberp gnus-fetch-old-headers)
8295             (eq gnus-build-sparse-threads 'some)
8296             (eq gnus-build-sparse-threads 'more))
8297     ;; Deal with old-fetched headers and sparse threads.
8298     (while (and
8299             thread
8300             (or
8301              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8302              (gnus-summary-article-ancient-p
8303               (mail-header-number (car thread))))
8304             (if (or (<= (length (cdr thread)) 1)
8305                     (eq gnus-fetch-old-headers 'invisible))
8306                 (setq gnus-newsgroup-limit
8307                       (delq (mail-header-number (car thread))
8308                             gnus-newsgroup-limit)
8309                       thread (cadr thread))
8310               (when (gnus-invisible-cut-children (cdr thread))
8311                 (let ((th (cdr thread)))
8312                   (while th
8313                     (if (memq (mail-header-number (caar th))
8314                               gnus-newsgroup-limit)
8315                         (setq thread (car th)
8316                               th nil)
8317                       (setq th (cdr th))))))))))
8318   thread)
8319
8320 (defun gnus-cut-threads (threads)
8321   "Cut off all uninteresting articles from the beginning of THREADS."
8322   (when (or (eq gnus-fetch-old-headers 'some)
8323             (eq gnus-fetch-old-headers 'invisible)
8324             (numberp gnus-fetch-old-headers)
8325             (eq gnus-build-sparse-threads 'some)
8326             (eq gnus-build-sparse-threads 'more))
8327     (let ((th threads))
8328       (while th
8329         (setcar th (gnus-cut-thread (car th)))
8330         (setq th (cdr th)))))
8331   ;; Remove nixed out threads.
8332   (delq nil threads))
8333
8334 (defun gnus-summary-initial-limit (&optional show-if-empty)
8335   "Figure out what the initial limit is supposed to be on group entry.
8336 This entails weeding out unwanted dormants, low-scored articles,
8337 fetch-old-headers verbiage, and so on."
8338   ;; Most groups have nothing to remove.
8339   (if (or gnus-inhibit-limiting
8340           (and (null gnus-newsgroup-dormant)
8341                (eq gnus-newsgroup-display 'gnus-not-ignore)
8342                (not (eq gnus-fetch-old-headers 'some))
8343                (not (numberp gnus-fetch-old-headers))
8344                (not (eq gnus-fetch-old-headers 'invisible))
8345                (null gnus-summary-expunge-below)
8346                (not (eq gnus-build-sparse-threads 'some))
8347                (not (eq gnus-build-sparse-threads 'more))
8348                (null gnus-thread-expunge-below)
8349                (not gnus-use-nocem)))
8350       ()                                ; Do nothing.
8351     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8352     (setq gnus-newsgroup-limit nil)
8353     (mapatoms
8354      (lambda (node)
8355        (unless (car (symbol-value node))
8356          ;; These threads have no parents -- they are roots.
8357          (let ((nodes (cdr (symbol-value node)))
8358                thread)
8359            (while nodes
8360              (if (and gnus-thread-expunge-below
8361                       (< (gnus-thread-total-score (car nodes))
8362                          gnus-thread-expunge-below))
8363                  (gnus-expunge-thread (pop nodes))
8364                (setq thread (pop nodes))
8365                (gnus-summary-limit-children thread))))))
8366      gnus-newsgroup-dependencies)
8367     ;; If this limitation resulted in an empty group, we might
8368     ;; pop the previous limit and use it instead.
8369     (when (and (not gnus-newsgroup-limit)
8370                show-if-empty)
8371       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8372     gnus-newsgroup-limit))
8373
8374 (defun gnus-summary-limit-children (thread)
8375   "Return 1 if this subthread is visible and 0 if it is not."
8376   ;; First we get the number of visible children to this thread.  This
8377   ;; is done by recursing down the thread using this function, so this
8378   ;; will really go down to a leaf article first, before slowly
8379   ;; working its way up towards the root.
8380   (when thread
8381     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8382            (children
8383            (if (cdr thread)
8384                (apply '+ (mapcar 'gnus-summary-limit-children
8385                                  (cdr thread)))
8386              0))
8387           (number (mail-header-number (car thread)))
8388           score)
8389       (if (and
8390            (not (memq number gnus-newsgroup-marked))
8391            (or
8392             ;; If this article is dormant and has absolutely no visible
8393             ;; children, then this article isn't visible.
8394             (and (memq number gnus-newsgroup-dormant)
8395                  (zerop children))
8396             ;; If this is "fetch-old-headered" and there is no
8397             ;; visible children, then we don't want this article.
8398             (and (or (eq gnus-fetch-old-headers 'some)
8399                      (numberp gnus-fetch-old-headers))
8400                  (gnus-summary-article-ancient-p number)
8401                  (zerop children))
8402             ;; If this is "fetch-old-headered" and `invisible', then
8403             ;; we don't want this article.
8404             (and (eq gnus-fetch-old-headers 'invisible)
8405                  (gnus-summary-article-ancient-p number))
8406             ;; If this is a sparsely inserted article with no children,
8407             ;; we don't want it.
8408             (and (eq gnus-build-sparse-threads 'some)
8409                  (gnus-summary-article-sparse-p number)
8410                  (zerop children))
8411             ;; If we use expunging, and this article is really
8412             ;; low-scored, then we don't want this article.
8413             (when (and gnus-summary-expunge-below
8414                        (< (setq score
8415                                 (or (cdr (assq number gnus-newsgroup-scored))
8416                                     gnus-summary-default-score))
8417                           gnus-summary-expunge-below))
8418               ;; We increase the expunge-tally here, but that has
8419               ;; nothing to do with the limits, really.
8420               (incf gnus-newsgroup-expunged-tally)
8421               ;; We also mark as read here, if that's wanted.
8422               (when (and gnus-summary-mark-below
8423                          (< score gnus-summary-mark-below))
8424                 (setq gnus-newsgroup-unreads
8425                       (delq number gnus-newsgroup-unreads))
8426                 (if gnus-newsgroup-auto-expire
8427                     (push number gnus-newsgroup-expirable)
8428                   (push (cons number gnus-low-score-mark)
8429                         gnus-newsgroup-reads)))
8430               t)
8431             ;; Do the `display' group parameter.
8432             (and gnus-newsgroup-display
8433                  (not (funcall gnus-newsgroup-display)))
8434             ;; Check NoCeM things.
8435             (when (and gnus-use-nocem
8436                        (gnus-nocem-unwanted-article-p
8437                         (mail-header-id (car thread))))
8438               (setq gnus-newsgroup-unreads
8439                     (delq number gnus-newsgroup-unreads))
8440               t)))
8441           ;; Nope, invisible article.
8442           0
8443         ;; Ok, this article is to be visible, so we add it to the limit
8444         ;; and return 1.
8445         (push number gnus-newsgroup-limit)
8446         1))))
8447
8448 (defun gnus-expunge-thread (thread)
8449   "Mark all articles in THREAD as read."
8450   (let* ((number (mail-header-number (car thread))))
8451     (incf gnus-newsgroup-expunged-tally)
8452     ;; We also mark as read here, if that's wanted.
8453     (setq gnus-newsgroup-unreads
8454           (delq number gnus-newsgroup-unreads))
8455     (if gnus-newsgroup-auto-expire
8456         (push number gnus-newsgroup-expirable)
8457       (push (cons number gnus-low-score-mark)
8458             gnus-newsgroup-reads)))
8459   ;; Go recursively through all subthreads.
8460   (mapcar 'gnus-expunge-thread (cdr thread)))
8461
8462 ;; Summary article oriented commands
8463
8464 (defun gnus-summary-refer-parent-article (n)
8465   "Refer parent article N times.
8466 If N is negative, go to ancestor -N instead.
8467 The difference between N and the number of articles fetched is returned."
8468   (interactive "p")
8469   (let ((skip 1)
8470         error header ref)
8471     (when (not (natnump n))
8472       (setq skip (abs n)
8473             n 1))
8474     (while (and (> n 0)
8475                 (not error))
8476       (setq header (gnus-summary-article-header))
8477       (if (and (eq (mail-header-number header)
8478                    (cdr gnus-article-current))
8479                (equal gnus-newsgroup-name
8480                       (car gnus-article-current)))
8481           ;; If we try to find the parent of the currently
8482           ;; displayed article, then we take a look at the actual
8483           ;; References header, since this is slightly more
8484           ;; reliable than the References field we got from the
8485           ;; server.
8486           (save-excursion
8487             (set-buffer gnus-original-article-buffer)
8488             (nnheader-narrow-to-headers)
8489             (unless (setq ref (message-fetch-field "references"))
8490               (when (setq ref (message-fetch-field "in-reply-to"))
8491                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8492             (widen))
8493         (setq ref
8494               ;; It's not the current article, so we take a bet on
8495               ;; the value we got from the server.
8496               (mail-header-references header)))
8497       (if (and ref
8498                (not (equal ref "")))
8499           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8500             (gnus-message 1 "Couldn't find parent"))
8501         (gnus-message 1 "No references in article %d"
8502                       (gnus-summary-article-number))
8503         (setq error t))
8504       (decf n))
8505     (gnus-summary-position-point)
8506     n))
8507
8508 (defun gnus-summary-refer-references ()
8509   "Fetch all articles mentioned in the References header.
8510 Return the number of articles fetched."
8511   (interactive)
8512   (let ((ref (mail-header-references (gnus-summary-article-header)))
8513         (current (gnus-summary-article-number))
8514         (n 0))
8515     (if (or (not ref)
8516             (equal ref ""))
8517         (error "No References in the current article")
8518       ;; For each Message-ID in the References header...
8519       (while (string-match "<[^>]*>" ref)
8520         (incf n)
8521         ;; ... fetch that article.
8522         (gnus-summary-refer-article
8523          (prog1 (match-string 0 ref)
8524            (setq ref (substring ref (match-end 0))))))
8525       (gnus-summary-goto-subject current)
8526       (gnus-summary-position-point)
8527       n)))
8528
8529 (defun gnus-summary-refer-thread (&optional limit)
8530   "Fetch all articles in the current thread.
8531 If LIMIT (the numerical prefix), fetch that many old headers instead
8532 of what's specified by the `gnus-refer-thread-limit' variable."
8533   (interactive "P")
8534   (let ((id (mail-header-id (gnus-summary-article-header)))
8535         (limit (if limit (prefix-numeric-value limit)
8536                  gnus-refer-thread-limit)))
8537     (unless (eq gnus-fetch-old-headers 'invisible)
8538       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8539       ;; Retrieve the headers and read them in.
8540       (if (eq (if (numberp limit)
8541                   (gnus-retrieve-headers
8542                    (list (min
8543                           (+ (mail-header-number
8544                               (gnus-summary-article-header))
8545                              limit)
8546                           gnus-newsgroup-end))
8547                    gnus-newsgroup-name (* limit 2))
8548                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8549                 ;; headers.
8550                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8551                                        gnus-newsgroup-name limit))
8552               'nov)
8553           (gnus-build-all-threads)
8554         (error "Can't fetch thread from back ends that don't support NOV"))
8555       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8556     (gnus-summary-limit-include-thread id)))
8557
8558 (defun gnus-summary-refer-article (message-id)
8559   "Fetch an article specified by MESSAGE-ID."
8560   (interactive "sMessage-ID: ")
8561   (when (and (stringp message-id)
8562              (not (zerop (length message-id))))
8563     (setq message-id (gnus-replace-in-string message-id " " ""))
8564     ;; Construct the correct Message-ID if necessary.
8565     ;; Suggested by tale@pawl.rpi.edu.
8566     (unless (string-match "^<" message-id)
8567       (setq message-id (concat "<" message-id)))
8568     (unless (string-match ">$" message-id)
8569       (setq message-id (concat message-id ">")))
8570     ;; People often post MIDs from URLs, so unhex it:
8571     (unless (string-match "@" message-id)
8572       (setq message-id (gnus-url-unhex-string message-id)))
8573     (let* ((header (gnus-id-to-header message-id))
8574            (sparse (and header
8575                         (gnus-summary-article-sparse-p
8576                          (mail-header-number header))
8577                         (memq (mail-header-number header)
8578                               gnus-newsgroup-limit)))
8579            number)
8580       (cond
8581        ;; If the article is present in the buffer we just go to it.
8582        ((and header
8583              (or (not (gnus-summary-article-sparse-p
8584                        (mail-header-number header)))
8585                  sparse))
8586         (prog1
8587             (gnus-summary-goto-article
8588              (mail-header-number header) nil t)
8589           (when sparse
8590             (gnus-summary-update-article (mail-header-number header)))))
8591        (t
8592         ;; We fetch the article.
8593         (catch 'found
8594           (dolist (gnus-override-method (gnus-refer-article-methods))
8595             (when (and (gnus-check-server gnus-override-method)
8596                        ;; Fetch the header,
8597                        (setq number (gnus-summary-insert-subject message-id)))
8598               ;; and display the article.
8599               (gnus-summary-select-article nil nil nil number)
8600               (throw 'found t)))
8601           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8602
8603 (defun gnus-refer-article-methods ()
8604   "Return a list of referable methods."
8605   (cond
8606    ;; No method, so we default to current and native.
8607    ((null gnus-refer-article-method)
8608     (list gnus-current-select-method gnus-select-method))
8609    ;; Current.
8610    ((eq 'current gnus-refer-article-method)
8611     (list gnus-current-select-method))
8612    ;; List of select methods.
8613    ((not (and (symbolp (car gnus-refer-article-method))
8614               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8615     (let (out)
8616       (dolist (method gnus-refer-article-method)
8617         (push (if (eq 'current method)
8618                   gnus-current-select-method
8619                 method)
8620               out))
8621       (nreverse out)))
8622    ;; One single select method.
8623    (t
8624     (list gnus-refer-article-method))))
8625
8626 (defun gnus-summary-edit-parameters ()
8627   "Edit the group parameters of the current group."
8628   (interactive)
8629   (gnus-group-edit-group gnus-newsgroup-name 'params))
8630
8631 (defun gnus-summary-customize-parameters ()
8632   "Customize the group parameters of the current group."
8633   (interactive)
8634   (gnus-group-customize gnus-newsgroup-name))
8635
8636 (defun gnus-summary-enter-digest-group (&optional force)
8637   "Enter an nndoc group based on the current article.
8638 If FORCE, force a digest interpretation.  If not, try
8639 to guess what the document format is."
8640   (interactive "P")
8641   (let ((conf gnus-current-window-configuration))
8642     (save-window-excursion
8643       (save-excursion
8644         (let (gnus-article-prepare-hook
8645               gnus-display-mime-function
8646               gnus-break-pages)
8647           (gnus-summary-select-article))))
8648     (setq gnus-current-window-configuration conf)
8649     (let* ((name (format "%s-%d"
8650                          (gnus-group-prefixed-name
8651                           gnus-newsgroup-name (list 'nndoc ""))
8652                          (with-current-buffer gnus-summary-buffer
8653                            gnus-current-article)))
8654            (ogroup gnus-newsgroup-name)
8655            (params (append (gnus-info-params (gnus-get-info ogroup))
8656                            (list (cons 'to-group ogroup))
8657                            (list (cons 'parent-group ogroup))
8658                            (list (cons 'save-article-group ogroup))))
8659            (case-fold-search t)
8660            (buf (current-buffer))
8661            dig to-address)
8662       (save-excursion
8663         (set-buffer gnus-original-article-buffer)
8664         ;; Have the digest group inherit the main mail address of
8665         ;; the parent article.
8666         (when (setq to-address (or (gnus-fetch-field "reply-to")
8667                                    (gnus-fetch-field "from")))
8668           (setq params
8669                 (append
8670                  (list (cons 'to-address
8671                              (funcall gnus-decode-encoded-address-function
8672                                       to-address))))))
8673         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8674         (insert-buffer-substring gnus-original-article-buffer)
8675         ;; Remove lines that may lead nndoc to misinterpret the
8676         ;; document type.
8677         (narrow-to-region
8678          (goto-char (point-min))
8679          (or (search-forward "\n\n" nil t) (point)))
8680         (goto-char (point-min))
8681         (delete-matching-lines "^Path:\\|^From ")
8682         (widen))
8683       (unwind-protect
8684           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8685                     (gnus-newsgroup-ephemeral-ignored-charsets
8686                      gnus-newsgroup-ignored-charsets))
8687                 (gnus-group-read-ephemeral-group
8688                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8689                               (nndoc-article-type
8690                                ,(if force 'mbox 'guess)))
8691                  t nil nil nil
8692                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8693                                                         "ADAPT")))))
8694               ;; Make all postings to this group go to the parent group.
8695               (nconc (gnus-info-params (gnus-get-info name))
8696                      params)
8697             ;; Couldn't select this doc group.
8698             (switch-to-buffer buf)
8699             (gnus-set-global-variables)
8700             (gnus-configure-windows 'summary)
8701             (gnus-message 3 "Article couldn't be entered?"))
8702         (kill-buffer dig)))))
8703
8704 (defun gnus-summary-read-document (n)
8705   "Open a new group based on the current article(s).
8706 This will allow you to read digests and other similar
8707 documents as newsgroups.
8708 Obeys the standard process/prefix convention."
8709   (interactive "P")
8710   (let* ((ogroup gnus-newsgroup-name)
8711          (params (append (gnus-info-params (gnus-get-info ogroup))
8712                          (list (cons 'to-group ogroup))))
8713          group egroup groups vgroup)
8714     (dolist (article (gnus-summary-work-articles n))
8715       (setq group (format "%s-%d" gnus-newsgroup-name article))
8716       (gnus-summary-remove-process-mark article)
8717       (when (gnus-summary-display-article article)
8718         (save-excursion
8719           (with-temp-buffer
8720             (insert-buffer-substring gnus-original-article-buffer)
8721             ;; Remove some headers that may lead nndoc to make
8722             ;; the wrong guess.
8723             (message-narrow-to-head)
8724             (goto-char (point-min))
8725             (delete-matching-lines "^Path:\\|^From ")
8726             (widen)
8727             (if (setq egroup
8728                       (gnus-group-read-ephemeral-group
8729                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8730                                      (nndoc-article-type guess))
8731                        t nil t))
8732                 (progn
8733             ;; Make all postings to this group go to the parent group.
8734                   (nconc (gnus-info-params (gnus-get-info egroup))
8735                          params)
8736                   (push egroup groups))
8737               ;; Couldn't select this doc group.
8738               (gnus-error 3 "Article couldn't be entered"))))))
8739     ;; Now we have selected all the documents.
8740     (cond
8741      ((not groups)
8742       (error "None of the articles could be interpreted as documents"))
8743      ((gnus-group-read-ephemeral-group
8744        (setq vgroup (format
8745                      "nnvirtual:%s-%s" gnus-newsgroup-name
8746                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8747        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8748        t
8749        (cons (current-buffer) 'summary)))
8750      (t
8751       (error "Couldn't select virtual nndoc group")))))
8752
8753 (defun gnus-summary-isearch-article (&optional regexp-p)
8754   "Do incremental search forward on the current article.
8755 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8756   (interactive "P")
8757   (gnus-summary-select-article)
8758   (gnus-configure-windows 'article)
8759   (gnus-eval-in-buffer-window gnus-article-buffer
8760     (save-restriction
8761       (widen)
8762       (isearch-forward regexp-p))))
8763
8764 (defun gnus-summary-repeat-search-article-forward ()
8765   "Repeat the previous search forwards."
8766   (interactive)
8767   (unless gnus-last-search-regexp
8768     (error "No previous search"))
8769   (gnus-summary-search-article-forward gnus-last-search-regexp))
8770
8771 (defun gnus-summary-repeat-search-article-backward ()
8772   "Repeat the previous search backwards."
8773   (interactive)
8774   (unless gnus-last-search-regexp
8775     (error "No previous search"))
8776   (gnus-summary-search-article-forward gnus-last-search-regexp t))
8777
8778 (defun gnus-summary-search-article-forward (regexp &optional backward)
8779   "Search for an article containing REGEXP forward.
8780 If BACKWARD, search backward instead."
8781   (interactive
8782    (list (read-string
8783           (format "Search article %s (regexp%s): "
8784                   (if current-prefix-arg "backward" "forward")
8785                   (if gnus-last-search-regexp
8786                       (concat ", default " gnus-last-search-regexp)
8787                     "")))
8788          current-prefix-arg))
8789   (if (string-equal regexp "")
8790       (setq regexp (or gnus-last-search-regexp ""))
8791     (setq gnus-last-search-regexp regexp)
8792     (setq gnus-article-before-search gnus-current-article))
8793   ;; Intentionally set gnus-last-article.
8794   (setq gnus-last-article gnus-article-before-search)
8795   (let ((gnus-last-article gnus-last-article))
8796     (if (gnus-summary-search-article regexp backward)
8797         (gnus-summary-show-thread)
8798       (signal 'search-failed (list regexp)))))
8799
8800 (defun gnus-summary-search-article-backward (regexp)
8801   "Search for an article containing REGEXP backward."
8802   (interactive
8803    (list (read-string
8804           (format "Search article backward (regexp%s): "
8805                   (if gnus-last-search-regexp
8806                       (concat ", default " gnus-last-search-regexp)
8807                     "")))))
8808   (gnus-summary-search-article-forward regexp 'backward))
8809
8810 (defun gnus-summary-search-article (regexp &optional backward)
8811   "Search for an article containing REGEXP.
8812 Optional argument BACKWARD means do search for backward.
8813 `gnus-select-article-hook' is not called during the search."
8814   ;; We have to require this here to make sure that the following
8815   ;; dynamic binding isn't shadowed by autoloading.
8816   (require 'gnus-async)
8817   (require 'gnus-art)
8818   (let ((gnus-select-article-hook nil)  ;Disable hook.
8819         (gnus-article-prepare-hook nil)
8820         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8821         (gnus-use-article-prefetch nil)
8822         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8823         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8824         (gnus-visual nil)
8825         (gnus-keep-backlog nil)
8826         (gnus-break-pages nil)
8827         (gnus-summary-display-arrow nil)
8828         (gnus-updated-mode-lines nil)
8829         (gnus-auto-center-summary nil)
8830         (sum (current-buffer))
8831         (gnus-display-mime-function nil)
8832         (found nil)
8833         point)
8834     (gnus-save-hidden-threads
8835       (gnus-summary-select-article)
8836       (set-buffer gnus-article-buffer)
8837       (goto-char (window-point (get-buffer-window (current-buffer))))
8838       (when backward
8839         (forward-line -1))
8840       (while (not found)
8841         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8842         (if (if backward
8843                 (re-search-backward regexp nil t)
8844               (re-search-forward regexp nil t))
8845             ;; We found the regexp.
8846             (progn
8847               (setq found 'found)
8848               (beginning-of-line)
8849               (set-window-start
8850                (get-buffer-window (current-buffer))
8851                (point))
8852               (forward-line 1)
8853               (set-window-point
8854                (get-buffer-window (current-buffer))
8855                (point))
8856               (set-buffer sum)
8857               (setq point (point)))
8858           ;; We didn't find it, so we go to the next article.
8859           (set-buffer sum)
8860           (setq found 'not)
8861           (while (eq found 'not)
8862             (if (not (if backward (gnus-summary-find-prev)
8863                        (gnus-summary-find-next)))
8864                 ;; No more articles.
8865                 (setq found t)
8866               ;; Select the next article and adjust point.
8867               (unless (gnus-summary-article-sparse-p
8868                        (gnus-summary-article-number))
8869                 (setq found nil)
8870                 (gnus-summary-select-article)
8871                 (set-buffer gnus-article-buffer)
8872                 (widen)
8873                 (goto-char (if backward (point-max) (point-min))))))))
8874       (gnus-message 7 ""))
8875     ;; Return whether we found the regexp.
8876     (when (eq found 'found)
8877       (goto-char point)
8878       (gnus-summary-show-thread)
8879       (gnus-summary-goto-subject gnus-current-article)
8880       (gnus-summary-position-point)
8881       t)))
8882
8883 (defun gnus-find-matching-articles (header regexp)
8884   "Return a list of all articles that match REGEXP on HEADER.
8885 This search includes all articles in the current group that Gnus has
8886 fetched headers for, whether they are displayed or not."
8887   (let ((articles nil)
8888         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8889         (case-fold-search t))
8890     (dolist (header gnus-newsgroup-headers)
8891       (when (string-match regexp (funcall func header))
8892         (push (mail-header-number header) articles)))
8893     (nreverse articles)))
8894
8895 (defun gnus-summary-find-matching (header regexp &optional backward unread
8896                                           not-case-fold not-matching)
8897   "Return a list of all articles that match REGEXP on HEADER.
8898 The search stars on the current article and goes forwards unless
8899 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8900 If UNREAD is non-nil, only unread articles will
8901 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8902 in the comparisons. If NOT-MATCHING, return a list of all articles that
8903 not match REGEXP on HEADER."
8904   (let ((case-fold-search (not not-case-fold))
8905         articles d func)
8906     (if (consp header)
8907         (if (eq (car header) 'extra)
8908             (setq func
8909                   `(lambda (h)
8910                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8911                          "")))
8912           (error "%s is an invalid header" header))
8913       (unless (fboundp (intern (concat "mail-header-" header)))
8914         (error "%s is not a valid header" header))
8915       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8916     (dolist (d (if (eq backward 'all)
8917                    gnus-newsgroup-data
8918                  (gnus-data-find-list
8919                   (gnus-summary-article-number)
8920                   (gnus-data-list backward))))
8921       (when (and (or (not unread)       ; We want all articles...
8922                      (gnus-data-unread-p d)) ; Or just unreads.
8923                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8924                  (if not-matching
8925                      (not (string-match
8926                            regexp
8927                            (funcall func (gnus-data-header d))))
8928                    (string-match regexp
8929                                  (funcall func (gnus-data-header d)))))
8930         (push (gnus-data-number d) articles))) ; Success!
8931     (nreverse articles)))
8932
8933 (defun gnus-summary-execute-command (header regexp command &optional backward)
8934   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8935 If HEADER is an empty string (or nil), the match is done on the entire
8936 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8937   (interactive
8938    (list (let ((completion-ignore-case t))
8939            (completing-read
8940             "Header name: "
8941             (mapcar (lambda (header) (list (format "%s" header)))
8942                     (append
8943                      '("Number" "Subject" "From" "Lines" "Date"
8944                        "Message-ID" "Xref" "References" "Body")
8945                      gnus-extra-headers))
8946             nil 'require-match))
8947          (read-string "Regexp: ")
8948          (read-key-sequence "Command: ")
8949          current-prefix-arg))
8950   (when (equal header "Body")
8951     (setq header ""))
8952   ;; Hidden thread subtrees must be searched as well.
8953   (gnus-summary-show-all-threads)
8954   ;; We don't want to change current point nor window configuration.
8955   (save-excursion
8956     (save-window-excursion
8957       (let (gnus-visual
8958             gnus-treat-strip-trailing-blank-lines
8959             gnus-treat-strip-leading-blank-lines
8960             gnus-treat-strip-multiple-blank-lines
8961             gnus-treat-hide-boring-headers
8962             gnus-treat-fold-newsgroups
8963             gnus-article-prepare-hook)
8964         (gnus-message 6 "Executing %s..." (key-description command))
8965         ;; We'd like to execute COMMAND interactively so as to give arguments.
8966         (gnus-execute header regexp
8967                       `(call-interactively ',(key-binding command))
8968                       backward)
8969         (gnus-message 6 "Executing %s...done" (key-description command))))))
8970
8971 (defun gnus-summary-beginning-of-article ()
8972   "Scroll the article back to the beginning."
8973   (interactive)
8974   (gnus-summary-select-article)
8975   (gnus-configure-windows 'article)
8976   (gnus-eval-in-buffer-window gnus-article-buffer
8977     (widen)
8978     (goto-char (point-min))
8979     (when gnus-break-pages
8980       (gnus-narrow-to-page))))
8981
8982 (defun gnus-summary-end-of-article ()
8983   "Scroll to the end of the article."
8984   (interactive)
8985   (gnus-summary-select-article)
8986   (gnus-configure-windows 'article)
8987   (gnus-eval-in-buffer-window gnus-article-buffer
8988     (widen)
8989     (goto-char (point-max))
8990     (recenter -3)
8991     (when gnus-break-pages
8992       (when (re-search-backward page-delimiter nil t)
8993         (narrow-to-region (match-end 0) (point-max)))
8994       (gnus-narrow-to-page))))
8995
8996 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8997   "Truncate to LEN and quote all \"(\"'s in STRING."
8998   (gnus-replace-in-string (if (and len (> (length string) len))
8999                               (substring string 0 len)
9000                             string)
9001                           "[()]" "\\\\\\&"))
9002
9003 (defun gnus-summary-print-article (&optional filename n)
9004   "Generate and print a PostScript image of the process-marked (mail) articles.
9005
9006 If used interactively, print the current article if none are
9007 process-marked.  With prefix arg, prompt the user for the name of the
9008 file to save in.
9009
9010 When used from Lisp, accept two optional args FILENAME and N.  N means
9011 to print the next N articles.  If N is negative, print the N previous
9012 articles.  If N is nil and articles have been marked with the process
9013 mark, print these instead.
9014
9015 If the optional first argument FILENAME is nil, send the image to the
9016 printer.  If FILENAME is a string, save the PostScript image in a file with
9017 that name.  If FILENAME is a number, prompt the user for the name of the file
9018 to save in."
9019   (interactive (list (ps-print-preprint current-prefix-arg)))
9020   (dolist (article (gnus-summary-work-articles n))
9021     (gnus-summary-select-article nil nil 'pseudo article)
9022     (gnus-eval-in-buffer-window gnus-article-buffer
9023       (gnus-print-buffer))
9024     (gnus-summary-remove-process-mark article))
9025   (ps-despool filename))
9026
9027 (defun gnus-print-buffer ()
9028   (let ((buffer (generate-new-buffer " *print*")))
9029     (unwind-protect
9030         (progn
9031           (copy-to-buffer buffer (point-min) (point-max))
9032           (set-buffer buffer)
9033           (gnus-remove-text-with-property 'gnus-decoration)
9034           (when (gnus-visual-p 'article-highlight 'highlight)
9035             ;; Copy-to-buffer doesn't copy overlay.  So redo
9036             ;; highlight.
9037             (let ((gnus-article-buffer buffer))
9038               (gnus-article-highlight-citation t)
9039               (gnus-article-highlight-signature)
9040               (gnus-article-emphasize)
9041               (gnus-article-delete-invisible-text)))
9042           (let ((ps-left-header
9043                  (list
9044                   (concat "("
9045                           (gnus-summary-print-truncate-and-quote
9046                            (mail-header-subject gnus-current-headers)
9047                            66) ")")
9048                   (concat "("
9049                           (gnus-summary-print-truncate-and-quote
9050                            (mail-header-from gnus-current-headers)
9051                            45) ")")))
9052                 (ps-right-header
9053                  (list
9054                   "/pagenumberstring load"
9055                   (concat "("
9056                           (mail-header-date gnus-current-headers) ")"))))
9057             (gnus-run-hooks 'gnus-ps-print-hook)
9058             (save-excursion
9059               (if window-system
9060                   (ps-spool-buffer-with-faces)
9061                 (ps-spool-buffer)))))
9062       (kill-buffer buffer))))
9063
9064 (defun gnus-summary-show-article (&optional arg)
9065   "Force redisplaying of the current article.
9066 If ARG (the prefix) is a number, show the article with the charset
9067 defined in `gnus-summary-show-article-charset-alist', or the charset
9068 input.
9069 If ARG (the prefix) is non-nil and not a number, show the raw article
9070 without any article massaging functions being run.  Normally, the key
9071 strokes are `C-u g'."
9072   (interactive "P")
9073   (cond
9074    ((numberp arg)
9075     (gnus-summary-show-article t)
9076     (let ((gnus-newsgroup-charset
9077            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9078                (mm-read-coding-system
9079                 "View as charset: " ;; actually it is coding system.
9080                 (with-current-buffer gnus-article-buffer
9081                   (mm-detect-coding-region (point) (point-max))))))
9082           (gnus-newsgroup-ignored-charsets 'gnus-all))
9083       (gnus-summary-select-article nil 'force)
9084       (let ((deps gnus-newsgroup-dependencies)
9085             head header lines)
9086         (save-excursion
9087           (set-buffer gnus-original-article-buffer)
9088           (save-restriction
9089             (message-narrow-to-head)
9090             (setq head (buffer-string))
9091             (goto-char (point-min))
9092             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9093               (goto-char (point-max))
9094               (widen)
9095               (setq lines (1- (count-lines (point) (point-max))))))
9096           (with-temp-buffer
9097             (insert (format "211 %d Article retrieved.\n"
9098                             (cdr gnus-article-current)))
9099             (insert head)
9100             (if lines (insert (format "Lines: %d\n" lines)))
9101             (insert ".\n")
9102             (let ((nntp-server-buffer (current-buffer)))
9103               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9104         (gnus-data-set-header
9105          (gnus-data-find (cdr gnus-article-current))
9106          header)
9107         (gnus-summary-update-article-line
9108          (cdr gnus-article-current) header)
9109         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9110           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9111    ((not arg)
9112     ;; Select the article the normal way.
9113     (gnus-summary-select-article nil 'force))
9114    (t
9115     ;; We have to require this here to make sure that the following
9116     ;; dynamic binding isn't shadowed by autoloading.
9117     (require 'gnus-async)
9118     (require 'gnus-art)
9119     ;; Bind the article treatment functions to nil.
9120     (let ((gnus-have-all-headers t)
9121           gnus-article-prepare-hook
9122           gnus-article-decode-hook
9123           gnus-display-mime-function
9124           gnus-break-pages)
9125       ;; Destroy any MIME parts.
9126       (when (gnus-buffer-live-p gnus-article-buffer)
9127         (save-excursion
9128           (set-buffer gnus-article-buffer)
9129           (mm-destroy-parts gnus-article-mime-handles)
9130           ;; Set it to nil for safety reason.
9131           (setq gnus-article-mime-handle-alist nil)
9132           (setq gnus-article-mime-handles nil)))
9133       (gnus-summary-select-article nil 'force))))
9134   (gnus-summary-goto-subject gnus-current-article)
9135   (gnus-summary-position-point))
9136
9137 (defun gnus-summary-show-raw-article ()
9138   "Show the raw article without any article massaging functions being run."
9139   (interactive)
9140   (gnus-summary-show-article t))
9141
9142 (defun gnus-summary-verbose-headers (&optional arg)
9143   "Toggle permanent full header display.
9144 If ARG is a positive number, turn header display on.
9145 If ARG is a negative number, turn header display off."
9146   (interactive "P")
9147   (setq gnus-show-all-headers
9148         (cond ((or (not (numberp arg))
9149                    (zerop arg))
9150                (not gnus-show-all-headers))
9151               ((natnump arg)
9152                t)))
9153   (gnus-summary-show-article))
9154
9155 (defun gnus-summary-toggle-header (&optional arg)
9156   "Show the headers if they are hidden, or hide them if they are shown.
9157 If ARG is a positive number, show the entire header.
9158 If ARG is a negative number, hide the unwanted header lines."
9159   (interactive "P")
9160   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9161                      (get-buffer-window gnus-article-buffer t))))
9162     (with-current-buffer gnus-article-buffer
9163       (widen)
9164       (article-narrow-to-head)
9165       (let* ((buffer-read-only nil)
9166              (inhibit-point-motion-hooks t)
9167              (hidden (if (numberp arg)
9168                          (>= arg 0)
9169                        (or (not (looking-at "[^ \t\n]+:"))
9170                            (gnus-article-hidden-text-p 'headers))))
9171              s e)
9172         (delete-region (point-min) (point-max))
9173         (with-current-buffer gnus-original-article-buffer
9174           (goto-char (setq s (point-min)))
9175           (setq e (if (search-forward "\n\n" nil t)
9176                       (1- (point))
9177                     (point-max))))
9178         (insert-buffer-substring gnus-original-article-buffer s e)
9179         (run-hooks 'gnus-article-decode-hook)
9180         (if hidden
9181             (let ((gnus-treat-hide-headers nil)
9182                   (gnus-treat-hide-boring-headers nil))
9183               (gnus-delete-wash-type 'headers)
9184               (gnus-treat-article 'head))
9185           (gnus-treat-article 'head))
9186         (widen)
9187         (if window
9188             (set-window-start window (goto-char (point-min))))
9189         (if gnus-break-pages
9190             (gnus-narrow-to-page)
9191           (when (gnus-visual-p 'page-marker)
9192             (let ((buffer-read-only nil))
9193               (gnus-remove-text-with-property 'gnus-prev)
9194               (gnus-remove-text-with-property 'gnus-next))))
9195         (gnus-set-mode-line 'article)))))
9196
9197 (defun gnus-summary-show-all-headers ()
9198   "Make all header lines visible."
9199   (interactive)
9200   (gnus-summary-toggle-header 1))
9201
9202 (defun gnus-summary-caesar-message (&optional arg)
9203   "Caesar rotate the current article by 13.
9204 With a non-numerical prefix, also rotate headers.  A numerical
9205 prefix specifies how many places to rotate each letter forward."
9206   (interactive "P")
9207   (gnus-summary-select-article)
9208   (let ((mail-header-separator ""))
9209     (gnus-eval-in-buffer-window gnus-article-buffer
9210       (save-restriction
9211         (widen)
9212         (let ((start (window-start))
9213               buffer-read-only)
9214           (if (equal arg '(4))
9215               (message-caesar-buffer-body nil t)
9216             (message-caesar-buffer-body arg))
9217           (set-window-start (get-buffer-window (current-buffer)) start)))))
9218   ;; Create buttons and stuff...
9219   (gnus-treat-article nil))
9220
9221 (defun gnus-summary-idna-message (&optional arg)
9222   "Decode IDNA encoded domain names in the current articles.
9223 IDNA encoded domain names looks like `xn--bar'.  If a string
9224 remain unencoded after running this function, it is likely an
9225 invalid IDNA string (`xn--bar' is invalid).
9226
9227 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9228 installed for this command to work."
9229   (interactive "P")
9230   (if (not (and (condition-case nil (require 'idna)
9231                   (file-error))
9232                 (mm-coding-system-p 'utf-8)
9233                 (executable-find (symbol-value 'idna-program))))
9234       (gnus-message
9235        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9236     (gnus-summary-select-article)
9237     (let ((mail-header-separator ""))
9238       (gnus-eval-in-buffer-window gnus-article-buffer
9239         (save-restriction
9240           (widen)
9241           (let ((start (window-start))
9242                 buffer-read-only)
9243             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9244               (replace-match (idna-to-unicode (match-string 1))))
9245             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9246
9247 (defun gnus-summary-morse-message (&optional arg)
9248   "Morse decode the current article."
9249   (interactive "P")
9250   (gnus-summary-select-article)
9251   (let ((mail-header-separator ""))
9252     (gnus-eval-in-buffer-window gnus-article-buffer
9253       (save-excursion
9254         (save-restriction
9255           (widen)
9256           (let ((pos (window-start))
9257                 buffer-read-only)
9258             (goto-char (point-min))
9259             (when (message-goto-body)
9260               (gnus-narrow-to-body))
9261             (goto-char (point-min))
9262             (while (search-forward "·" (point-max) t)
9263               (replace-match "."))
9264             (unmorse-region (point-min) (point-max))
9265             (widen)
9266             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9267
9268 (defun gnus-summary-stop-page-breaking ()
9269   "Stop page breaking in the current article."
9270   (interactive)
9271   (gnus-summary-select-article)
9272   (gnus-eval-in-buffer-window gnus-article-buffer
9273     (widen)
9274     (when (gnus-visual-p 'page-marker)
9275       (let ((buffer-read-only nil))
9276         (gnus-remove-text-with-property 'gnus-prev)
9277         (gnus-remove-text-with-property 'gnus-next))
9278       (setq gnus-page-broken nil))))
9279
9280 (defun gnus-summary-move-article (&optional n to-newsgroup
9281                                             select-method action)
9282   "Move the current article to a different newsgroup.
9283 If N is a positive number, move the N next articles.
9284 If N is a negative number, move the N previous articles.
9285 If N is nil and any articles have been marked with the process mark,
9286 move those articles instead.
9287 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9288 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9289 re-spool using this method.
9290
9291 When called interactively with TO-NEWSGROUP being nil, the value of
9292 the variable `gnus-move-split-methods' is used for finding a default
9293 for the target newsgroup.
9294
9295 For this function to work, both the current newsgroup and the
9296 newsgroup that you want to move to have to support the `request-move'
9297 and `request-accept' functions.
9298
9299 ACTION can be either `move' (the default), `crosspost' or `copy'."
9300   (interactive "P")
9301   (unless action
9302     (setq action 'move))
9303   ;; Check whether the source group supports the required functions.
9304   (cond ((and (eq action 'move)
9305               (not (gnus-check-backend-function
9306                     'request-move-article gnus-newsgroup-name)))
9307          (error "The current group does not support article moving"))
9308         ((and (eq action 'crosspost)
9309               (not (gnus-check-backend-function
9310                     'request-replace-article gnus-newsgroup-name)))
9311          (error "The current group does not support article editing")))
9312   (let ((articles (gnus-summary-work-articles n))
9313         (prefix (if (gnus-check-backend-function
9314                      'request-move-article gnus-newsgroup-name)
9315                     (funcall gnus-move-group-prefix-function
9316                              gnus-newsgroup-name)
9317                   ""))
9318         (names '((move "Move" "Moving")
9319                  (copy "Copy" "Copying")
9320                  (crosspost "Crosspost" "Crossposting")))
9321         (copy-buf (save-excursion
9322                     (nnheader-set-temp-buffer " *copy article*")))
9323         art-group to-method new-xref article to-groups articles-to-update-marks)
9324     (unless (assq action names)
9325       (error "Unknown action %s" action))
9326     ;; Read the newsgroup name.
9327     (when (and (not to-newsgroup)
9328                (not select-method))
9329       (if (and gnus-move-split-methods
9330                (not
9331                 (and (memq gnus-current-article articles)
9332                      (gnus-buffer-live-p gnus-original-article-buffer))))
9333           ;; When `gnus-move-split-methods' is non-nil, we have to
9334           ;; select an article to give `gnus-read-move-group-name' an
9335           ;; opportunity to suggest an appropriate default.  However,
9336           ;; we needn't render or mark the article.
9337           (let ((gnus-display-mime-function nil)
9338                 (gnus-article-prepare-hook nil)
9339                 (gnus-mark-article-hook nil))
9340             (gnus-summary-select-article nil nil nil (car articles))))
9341       (setq to-newsgroup
9342             (gnus-read-move-group-name
9343              (cadr (assq action names))
9344              (symbol-value (intern (format "gnus-current-%s-group" action)))
9345              articles prefix))
9346       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9347     (setq to-method (or select-method
9348                         (gnus-server-to-method
9349                          (gnus-group-method to-newsgroup))))
9350     ;; Check the method we are to move this article to...
9351     (unless (gnus-check-backend-function
9352              'request-accept-article (car to-method))
9353       (error "%s does not support article copying" (car to-method)))
9354     (unless (gnus-check-server to-method)
9355       (error "Can't open server %s" (car to-method)))
9356     (gnus-message 6 "%s to %s: %s..."
9357                   (caddr (assq action names))
9358                   (or (car select-method) to-newsgroup) articles)
9359     (while articles
9360       (setq article (pop articles))
9361       (setq
9362        art-group
9363        (cond
9364         ;; Move the article.
9365         ((eq action 'move)
9366          ;; Remove this article from future suppression.
9367          (gnus-dup-unsuppress-article article)
9368          (let* ((from-method (gnus-find-method-for-group
9369                               gnus-newsgroup-name))
9370                 (to-method (gnus-find-method-for-group
9371                             to-newsgroup))
9372                 (move-is-internal (gnus-method-equal from-method to-method)))
9373            (gnus-request-move-article
9374             article                     ; Article to move
9375             gnus-newsgroup-name         ; From newsgroup
9376             (nth 1 (gnus-find-method-for-group
9377                     gnus-newsgroup-name)) ; Server
9378             (list 'gnus-request-accept-article
9379                   to-newsgroup (list 'quote select-method)
9380                   (not articles) t)     ; Accept form
9381             (not articles)              ; Only save nov last time
9382             move-is-internal)))         ; is this move internal?
9383         ;; Copy the article.
9384         ((eq action 'copy)
9385          (save-excursion
9386            (set-buffer copy-buf)
9387            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9388              (save-restriction
9389                (nnheader-narrow-to-headers)
9390                (dolist (hdr gnus-copy-article-ignored-headers)
9391                  (message-remove-header hdr t)))
9392              (gnus-request-accept-article
9393               to-newsgroup select-method (not articles) t))))
9394         ;; Crosspost the article.
9395         ((eq action 'crosspost)
9396          (let ((xref (message-tokenize-header
9397                       (mail-header-xref (gnus-summary-article-header article))
9398                       " ")))
9399            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9400                                   ":" (number-to-string article)))
9401            (unless xref
9402              (setq xref (list (system-name))))
9403            (setq new-xref
9404                  (concat
9405                   (mapconcat 'identity
9406                              (delete "Xref:" (delete new-xref xref))
9407                              " ")
9408                   " " new-xref))
9409            (save-excursion
9410              (set-buffer copy-buf)
9411              ;; First put the article in the destination group.
9412              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9413              (when (consp (setq art-group
9414                                 (gnus-request-accept-article
9415                                  to-newsgroup select-method (not articles) t)))
9416                (setq new-xref (concat new-xref " " (car art-group)
9417                                       ":"
9418                                       (number-to-string (cdr art-group))))
9419                ;; Now we have the new Xrefs header, so we insert
9420                ;; it and replace the new article.
9421                (nnheader-replace-header "Xref" new-xref)
9422                (gnus-request-replace-article
9423                 (cdr art-group) to-newsgroup (current-buffer) t)
9424                art-group))))))
9425       (cond
9426        ((not art-group)
9427         (gnus-message 1 "Couldn't %s article %s: %s"
9428                       (cadr (assq action names)) article
9429                       (nnheader-get-report (car to-method))))
9430        ((eq art-group 'junk)
9431         (when (eq action 'move)
9432           (gnus-summary-mark-article article gnus-canceled-mark)
9433           (gnus-message 4 "Deleted article %s" article)
9434           ;; run the delete hook
9435           (run-hook-with-args 'gnus-summary-article-delete-hook
9436                               action
9437                               (gnus-data-header
9438                                (assoc article (gnus-data-list nil)))
9439                               gnus-newsgroup-name nil
9440                               select-method)))
9441        (t
9442         (let* ((pto-group (gnus-group-prefixed-name
9443                            (car art-group) to-method))
9444                (info (gnus-get-info pto-group))
9445                (to-group (gnus-info-group info))
9446                to-marks)
9447           ;; Update the group that has been moved to.
9448           (when (and info
9449                      (memq action '(move copy)))
9450             (unless (member to-group to-groups)
9451               (push to-group to-groups))
9452
9453             (unless (memq article gnus-newsgroup-unreads)
9454               (push 'read to-marks)
9455               (gnus-info-set-read
9456                info (gnus-add-to-range (gnus-info-read info)
9457                                        (list (cdr art-group)))))
9458
9459             ;; See whether the article is to be put in the cache.
9460             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9461                              gnus-article-mark-lists
9462                            (delete '(expirable . expire)
9463                                    (copy-sequence gnus-article-mark-lists))))
9464                   (to-article (cdr art-group)))
9465
9466               ;; Enter the article into the cache in the new group,
9467               ;; if that is required.
9468               (when gnus-use-cache
9469                 (gnus-cache-possibly-enter-article
9470                  to-group to-article
9471                  (memq article gnus-newsgroup-marked)
9472                  (memq article gnus-newsgroup-dormant)
9473                  (memq article gnus-newsgroup-unreads)))
9474
9475               (when gnus-preserve-marks
9476                 ;; Copy any marks over to the new group.
9477                 (when (and (equal to-group gnus-newsgroup-name)
9478                            (not (memq article gnus-newsgroup-unreads)))
9479                   ;; Mark this article as read in this group.
9480                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9481                   (setcdr (gnus-active to-group) to-article)
9482                   (setcdr gnus-newsgroup-active to-article))
9483
9484                 (while marks
9485                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9486                     (when (memq article (symbol-value
9487                                          (intern (format "gnus-newsgroup-%s"
9488                                                          (caar marks)))))
9489                       (push (cdar marks) to-marks)
9490                       ;; If the other group is the same as this group,
9491                       ;; then we have to add the mark to the list.
9492                       (when (equal to-group gnus-newsgroup-name)
9493                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9494                              (cons to-article
9495                                    (symbol-value
9496                                     (intern (format "gnus-newsgroup-%s"
9497                                                     (caar marks)))))))
9498                       ;; Copy the marks to other group.
9499                       (gnus-add-marked-articles
9500                        to-group (cdar marks) (list to-article) info)))
9501                   (setq marks (cdr marks)))
9502
9503                 (gnus-request-set-mark
9504                  to-group (list (list (list to-article) 'add to-marks))))
9505
9506               (gnus-dribble-enter
9507                (concat "(gnus-group-set-info '"
9508                        (gnus-prin1-to-string (gnus-get-info to-group))
9509                        ")"))))
9510
9511           ;; Update the Xref header in this article to point to
9512           ;; the new crossposted article we have just created.
9513           (when (eq action 'crosspost)
9514             (save-excursion
9515               (set-buffer copy-buf)
9516               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9517               (nnheader-replace-header "Xref" new-xref)
9518               (gnus-request-replace-article
9519                article gnus-newsgroup-name (current-buffer) t)))
9520
9521           ;; run the move/copy/crosspost/respool hook
9522           (run-hook-with-args 'gnus-summary-article-move-hook
9523                               action
9524                               (gnus-data-header
9525                                (assoc article (gnus-data-list nil)))
9526                               gnus-newsgroup-name
9527                               to-newsgroup
9528                               select-method))
9529
9530         ;;;!!!Why is this necessary?
9531         (set-buffer gnus-summary-buffer)
9532
9533         (gnus-summary-goto-subject article)
9534         (when (eq action 'move)
9535           (gnus-summary-mark-article article gnus-canceled-mark))))
9536       (push article articles-to-update-marks))
9537
9538     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9539     ;; Re-activate all groups that have been moved to.
9540     (save-excursion
9541       (set-buffer gnus-group-buffer)
9542       (let ((gnus-group-marked to-groups))
9543         (gnus-group-get-new-news-this-group nil t)))
9544
9545     (gnus-kill-buffer copy-buf)
9546     (gnus-summary-position-point)
9547     (gnus-set-mode-line 'summary)))
9548
9549 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9550   "Copy the current article to some other group.
9551 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9552 When called interactively, if TO-NEWSGROUP is nil, use the value of
9553 the variable `gnus-move-split-methods' for finding a default target
9554 newsgroup.
9555 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9556 re-spool using this method."
9557   (interactive "P")
9558   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9559
9560 (defun gnus-summary-crosspost-article (&optional n)
9561   "Crosspost the current article to some other group."
9562   (interactive "P")
9563   (gnus-summary-move-article n nil nil 'crosspost))
9564
9565 (defcustom gnus-summary-respool-default-method nil
9566   "Default method type for respooling an article.
9567 If nil, use to the current newsgroup method."
9568   :type 'symbol
9569   :group 'gnus-summary-mail)
9570
9571 (defcustom gnus-summary-display-while-building nil
9572   "If non-nil, show and update the summary buffer as it's being built.
9573 If the value is t, update the buffer after every line is inserted.  If
9574 the value is an integer (N), update the display every N lines."
9575   :version "22.1"
9576   :group 'gnus-thread
9577   :type '(choice (const :tag "off" nil)
9578                  number
9579                  (const :tag "frequently" t)))
9580
9581 (defun gnus-summary-respool-article (&optional n method)
9582   "Respool the current article.
9583 The article will be squeezed through the mail spooling process again,
9584 which means that it will be put in some mail newsgroup or other
9585 depending on `nnmail-split-methods'.
9586 If N is a positive number, respool the N next articles.
9587 If N is a negative number, respool the N previous articles.
9588 If N is nil and any articles have been marked with the process mark,
9589 respool those articles instead.
9590
9591 Respooling can be done both from mail groups and \"real\" newsgroups.
9592 In the former case, the articles in question will be moved from the
9593 current group into whatever groups they are destined to.  In the
9594 latter case, they will be copied into the relevant groups."
9595   (interactive
9596    (list current-prefix-arg
9597          (let* ((methods (gnus-methods-using 'respool))
9598                 (methname
9599                  (symbol-name (or gnus-summary-respool-default-method
9600                                   (car (gnus-find-method-for-group
9601                                         gnus-newsgroup-name)))))
9602                 (method
9603                  (gnus-completing-read-with-default
9604                   methname "Backend to use when respooling"
9605                   methods nil t nil 'gnus-mail-method-history))
9606                 ms)
9607            (cond
9608             ((zerop (length (setq ms (gnus-servers-using-backend
9609                                       (intern method)))))
9610              (list (intern method) ""))
9611             ((= 1 (length ms))
9612              (car ms))
9613             (t
9614              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9615                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9616                            ms-alist))))))))
9617   (unless method
9618     (error "No method given for respooling"))
9619   (if (assoc (symbol-name
9620               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9621              (gnus-methods-using 'respool))
9622       (gnus-summary-move-article n nil method)
9623     (gnus-summary-copy-article n nil method)))
9624
9625 (defun gnus-summary-import-article (file &optional edit)
9626   "Import an arbitrary file into a mail newsgroup."
9627   (interactive "fImport file: \nP")
9628   (let ((group gnus-newsgroup-name)
9629         (now (current-time))
9630         atts lines group-art)
9631     (unless (gnus-check-backend-function 'request-accept-article group)
9632       (error "%s does not support article importing" group))
9633     (or (file-readable-p file)
9634         (not (file-regular-p file))
9635         (error "Can't read %s" file))
9636     (save-excursion
9637       (set-buffer (gnus-get-buffer-create " *import file*"))
9638       (erase-buffer)
9639       (nnheader-insert-file-contents file)
9640       (goto-char (point-min))
9641       (if (nnheader-article-p)
9642           (save-restriction
9643             (goto-char (point-min))
9644             (search-forward "\n\n" nil t)
9645             (narrow-to-region (point-min) (1- (point)))
9646             (goto-char (point-min))
9647             (unless (re-search-forward "^date:" nil t)
9648               (goto-char (point-max))
9649               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9650        ;; This doesn't look like an article, so we fudge some headers.
9651         (setq atts (file-attributes file)
9652               lines (count-lines (point-min) (point-max)))
9653         (insert "From: " (read-string "From: ") "\n"
9654                 "Subject: " (read-string "Subject: ") "\n"
9655                 "Date: " (message-make-date (nth 5 atts)) "\n"
9656                 "Message-ID: " (message-make-message-id) "\n"
9657                 "Lines: " (int-to-string lines) "\n"
9658                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9659       (setq group-art (gnus-request-accept-article group nil t))
9660       (kill-buffer (current-buffer)))
9661     (setq gnus-newsgroup-active (gnus-activate-group group))
9662     (forward-line 1)
9663     (gnus-summary-goto-article (cdr group-art) nil t)
9664     (when edit
9665       (gnus-summary-edit-article))))
9666
9667 (defun gnus-summary-create-article ()
9668   "Create an article in a mail newsgroup."
9669   (interactive)
9670   (let ((group gnus-newsgroup-name)
9671         (now (current-time))
9672         group-art)
9673     (unless (gnus-check-backend-function 'request-accept-article group)
9674       (error "%s does not support article importing" group))
9675     (save-excursion
9676       (set-buffer (gnus-get-buffer-create " *import file*"))
9677       (erase-buffer)
9678       (goto-char (point-min))
9679       ;; This doesn't look like an article, so we fudge some headers.
9680       (insert "From: " (read-string "From: ") "\n"
9681               "Subject: " (read-string "Subject: ") "\n"
9682               "Date: " (message-make-date now) "\n"
9683               "Message-ID: " (message-make-message-id) "\n")
9684       (setq group-art (gnus-request-accept-article group nil t))
9685       (kill-buffer (current-buffer)))
9686     (setq gnus-newsgroup-active (gnus-activate-group group))
9687     (forward-line 1)
9688     (gnus-summary-goto-article (cdr group-art) nil t)
9689     (gnus-summary-edit-article)))
9690
9691 (defun gnus-summary-article-posted-p ()
9692   "Say whether the current (mail) article is available from news as well.
9693 This will be the case if the article has both been mailed and posted."
9694   (interactive)
9695   (let ((id (mail-header-references (gnus-summary-article-header)))
9696         (gnus-override-method (car (gnus-refer-article-methods))))
9697     (if (gnus-request-head id "")
9698         (gnus-message 2 "The current message was found on %s"
9699                       gnus-override-method)
9700       (gnus-message 2 "The current message couldn't be found on %s"
9701                     gnus-override-method)
9702       nil)))
9703
9704 (defun gnus-summary-expire-articles (&optional now)
9705   "Expire all articles that are marked as expirable in the current group."
9706   (interactive)
9707   (when (and (not gnus-group-is-exiting-without-update-p)
9708              (gnus-check-backend-function
9709               'request-expire-articles gnus-newsgroup-name))
9710     ;; This backend supports expiry.
9711     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9712            (expirable (if total
9713                           (progn
9714                             ;; We need to update the info for
9715                             ;; this group for `gnus-list-of-read-articles'
9716                             ;; to give us the right answer.
9717                             (gnus-run-hooks 'gnus-exit-group-hook)
9718                             (gnus-summary-update-info)
9719                             (gnus-list-of-read-articles gnus-newsgroup-name))
9720                         (setq gnus-newsgroup-expirable
9721                               (sort gnus-newsgroup-expirable '<))))
9722            (expiry-wait (if now 'immediate
9723                           (gnus-group-find-parameter
9724                            gnus-newsgroup-name 'expiry-wait)))
9725            (nnmail-expiry-target
9726             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9727                 nnmail-expiry-target))
9728            es)
9729       (when expirable
9730         ;; There are expirable articles in this group, so we run them
9731         ;; through the expiry process.
9732         (gnus-message 6 "Expiring articles...")
9733         (unless (gnus-check-group gnus-newsgroup-name)
9734           (error "Can't open server for %s" gnus-newsgroup-name))
9735         ;; The list of articles that weren't expired is returned.
9736         (save-excursion
9737           (if expiry-wait
9738               (let ((nnmail-expiry-wait-function nil)
9739                     (nnmail-expiry-wait expiry-wait))
9740                 (setq es (gnus-request-expire-articles
9741                           expirable gnus-newsgroup-name)))
9742             (setq es (gnus-request-expire-articles
9743                       expirable gnus-newsgroup-name)))
9744           (unless total
9745             (setq gnus-newsgroup-expirable es))
9746           ;; We go through the old list of expirable, and mark all
9747           ;; really expired articles as nonexistent.
9748           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9749             (let ((gnus-use-cache nil))
9750               (dolist (article expirable)
9751                 (when (and (not (memq article es))
9752                            (gnus-data-find article))
9753                   (gnus-summary-mark-article article gnus-canceled-mark)
9754                   (run-hook-with-args 'gnus-summary-article-expire-hook
9755                                       'delete
9756                                       (gnus-data-header
9757                                        (assoc article (gnus-data-list nil)))
9758                                       gnus-newsgroup-name
9759                                       nil
9760                                       nil))))))
9761         (gnus-message 6 "Expiring articles...done")))))
9762
9763 (defun gnus-summary-expire-articles-now ()
9764   "Expunge all expirable articles in the current group.
9765 This means that *all* articles that are marked as expirable will be
9766 deleted forever, right now."
9767   (interactive)
9768   (or gnus-expert-user
9769       (gnus-yes-or-no-p
9770        "Are you really, really sure you want to delete all expirable messages? ")
9771       (error "Phew!"))
9772   (gnus-summary-expire-articles t))
9773
9774 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9775 (defun gnus-summary-delete-article (&optional n)
9776   "Delete the N next (mail) articles.
9777 This command actually deletes articles.  This is not a marking
9778 command.  The article will disappear forever from your life, never to
9779 return.
9780
9781 If N is negative, delete backwards.
9782 If N is nil and articles have been marked with the process mark,
9783 delete these instead.
9784
9785 If `gnus-novice-user' is non-nil you will be asked for
9786 confirmation before the articles are deleted."
9787   (interactive "P")
9788   (unless (gnus-check-backend-function 'request-expire-articles
9789                                        gnus-newsgroup-name)
9790     (error "The current newsgroup does not support article deletion"))
9791   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9792     (error "Couldn't open server"))
9793   ;; Compute the list of articles to delete.
9794   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9795         (nnmail-expiry-target 'delete)
9796         not-deleted)
9797     (if (and gnus-novice-user
9798              (not (gnus-yes-or-no-p
9799                    (format "Do you really want to delete %s forever? "
9800                            (if (> (length articles) 1)
9801                                (format "these %s articles" (length articles))
9802                              "this article")))))
9803         ()
9804       ;; Delete the articles.
9805       (setq not-deleted (gnus-request-expire-articles
9806                          articles gnus-newsgroup-name 'force))
9807       (while articles
9808         (gnus-summary-remove-process-mark (car articles))
9809         ;; The backend might not have been able to delete the article
9810         ;; after all.
9811         (unless (memq (car articles) not-deleted)
9812           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9813         (let* ((article (car articles))
9814                (ghead  (gnus-data-header
9815                                     (assoc article (gnus-data-list nil)))))
9816           (run-hook-with-args 'gnus-summary-article-delete-hook
9817                               'delete ghead gnus-newsgroup-name nil
9818                               nil))
9819         (setq articles (cdr articles)))
9820       (when not-deleted
9821         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9822     (gnus-summary-position-point)
9823     (gnus-set-mode-line 'summary)
9824     not-deleted))
9825
9826 (defun gnus-summary-edit-article (&optional arg)
9827   "Edit the current article.
9828 This will have permanent effect only in mail groups.
9829 If ARG is nil, edit the decoded articles.
9830 If ARG is 1, edit the raw articles.
9831 If ARG is 2, edit the raw articles even in read-only groups.
9832 If ARG is 3, edit the articles with the current handles.
9833 Otherwise, allow editing of articles even in read-only
9834 groups."
9835   (interactive "P")
9836   (let (force raw current-handles)
9837     (cond
9838      ((null arg))
9839      ((eq arg 1)
9840       (setq raw t))
9841      ((eq arg 2)
9842       (setq raw t
9843             force t))
9844      ((eq arg 3)
9845       (setq current-handles
9846             (and (gnus-buffer-live-p gnus-article-buffer)
9847                  (with-current-buffer gnus-article-buffer
9848                    (prog1
9849                        gnus-article-mime-handles
9850                      (setq gnus-article-mime-handles nil))))))
9851      (t
9852       (setq force t)))
9853     (when (and raw (not force)
9854                (member gnus-newsgroup-name '("nndraft:delayed"
9855                                              "nndraft:drafts"
9856                                              "nndraft:queue")))
9857       (error "Can't edit the raw article in group %s"
9858              gnus-newsgroup-name))
9859     (save-excursion
9860       (set-buffer gnus-summary-buffer)
9861       (let ((mail-parse-charset gnus-newsgroup-charset)
9862             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9863         (gnus-set-global-variables)
9864         (when (and (not force)
9865                    (gnus-group-read-only-p))
9866           (error "The current newsgroup does not support article editing"))
9867         (gnus-summary-show-article t)
9868         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9869           (with-current-buffer gnus-article-buffer
9870             (mm-enable-multibyte)))
9871         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9872             (setq raw t))
9873         (gnus-article-edit-article
9874          (if raw 'ignore
9875            `(lambda ()
9876               (let ((mbl mml-buffer-list))
9877                 (setq mml-buffer-list nil)
9878                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
9879                   (mime-to-mml ,'current-handles))
9880                 (let ((mbl1 mml-buffer-list))
9881                   (setq mml-buffer-list mbl)
9882                   (set (make-local-variable 'mml-buffer-list) mbl1))
9883                 (gnus-make-local-hook 'kill-buffer-hook)
9884                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9885          `(lambda (no-highlight)
9886             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9887                   (message-options message-options)
9888                   (message-options-set-recipient)
9889                   (mail-parse-ignored-charsets
9890                    ',gnus-newsgroup-ignored-charsets))
9891               ,(if (not raw) '(progn
9892                                 (mml-to-mime)
9893                                 (mml-destroy-buffers)
9894                                 (remove-hook 'kill-buffer-hook
9895                                              'mml-destroy-buffers t)
9896                                 (kill-local-variable 'mml-buffer-list)))
9897               (gnus-summary-edit-article-done
9898                ,(or (mail-header-references gnus-current-headers) "")
9899                ,(gnus-group-read-only-p)
9900                ,gnus-summary-buffer no-highlight))))))))
9901
9902 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9903
9904 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9905                                                  no-highlight)
9906   "Make edits to the current article permanent."
9907   (interactive)
9908   (save-excursion
9909    ;; The buffer restriction contains the entire article if it exists.
9910     (when (article-goto-body)
9911       (let ((lines (count-lines (point) (point-max)))
9912             (length (- (point-max) (point)))
9913             (case-fold-search t)
9914             (body (copy-marker (point))))
9915         (goto-char (point-min))
9916         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9917           (delete-region (match-beginning 1) (match-end 1))
9918           (insert (number-to-string length)))
9919         (goto-char (point-min))
9920         (when (re-search-forward
9921                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9922           (delete-region (match-beginning 1) (match-end 1))
9923           (insert (number-to-string length)))
9924         (goto-char (point-min))
9925         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9926           (delete-region (match-beginning 1) (match-end 1))
9927           (insert (number-to-string lines))))))
9928   ;; Replace the article.
9929   (let ((buf (current-buffer)))
9930     (with-temp-buffer
9931       (insert-buffer-substring buf)
9932
9933       (if (and (not read-only)
9934                (not (gnus-request-replace-article
9935                      (cdr gnus-article-current) (car gnus-article-current)
9936                      (current-buffer) t)))
9937           (error "Couldn't replace article")
9938         ;; Update the summary buffer.
9939         (if (and references
9940                  (equal (message-tokenize-header references " ")
9941                         (message-tokenize-header
9942                          (or (message-fetch-field "references") "") " ")))
9943             ;; We only have to update this line.
9944             (save-excursion
9945               (save-restriction
9946                 (message-narrow-to-head)
9947                 (let ((head (buffer-substring-no-properties
9948                              (point-min) (point-max)))
9949                       header)
9950                   (with-temp-buffer
9951                     (insert (format "211 %d Article retrieved.\n"
9952                                     (cdr gnus-article-current)))
9953                     (insert head)
9954                     (insert ".\n")
9955                     (let ((nntp-server-buffer (current-buffer)))
9956                       (setq header (car (gnus-get-newsgroup-headers
9957                                          nil t))))
9958                     (save-excursion
9959                       (set-buffer gnus-summary-buffer)
9960                       (gnus-data-set-header
9961                        (gnus-data-find (cdr gnus-article-current))
9962                        header)
9963                       (gnus-summary-update-article-line
9964                        (cdr gnus-article-current) header)
9965                       (if (gnus-summary-goto-subject
9966                            (cdr gnus-article-current) nil t)
9967                           (gnus-summary-update-secondary-mark
9968                            (cdr gnus-article-current))))))))
9969           ;; Update threads.
9970           (set-buffer (or buffer gnus-summary-buffer))
9971           (gnus-summary-update-article (cdr gnus-article-current))
9972           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9973               (gnus-summary-update-secondary-mark
9974                (cdr gnus-article-current))))
9975         ;; Prettify the article buffer again.
9976         (unless no-highlight
9977           (save-excursion
9978             (set-buffer gnus-article-buffer)
9979             ;;;!!! Fix this -- article should be rehighlighted.
9980             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9981             (set-buffer gnus-original-article-buffer)
9982             (gnus-request-article
9983              (cdr gnus-article-current)
9984              (car gnus-article-current) (current-buffer))))
9985         ;; Prettify the summary buffer line.
9986         (when (gnus-visual-p 'summary-highlight 'highlight)
9987           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9988
9989 (defun gnus-summary-edit-wash (key)
9990   "Perform editing command KEY in the article buffer."
9991   (interactive
9992    (list
9993     (progn
9994       (message "%s" (concat (this-command-keys) "- "))
9995       (read-char))))
9996   (message "")
9997   (gnus-summary-edit-article)
9998   (execute-kbd-macro (concat (this-command-keys) key))
9999   (gnus-article-edit-done))
10000
10001 ;;; Respooling
10002
10003 (defun gnus-summary-respool-query (&optional silent trace)
10004   "Query where the respool algorithm would put this article."
10005   (interactive)
10006   (let (gnus-mark-article-hook)
10007     (gnus-summary-select-article)
10008     (save-excursion
10009       (set-buffer gnus-original-article-buffer)
10010       (let ((groups (nnmail-article-group 'identity trace)))
10011         (unless silent
10012           (if groups
10013               (message "This message would go to %s"
10014                        (mapconcat 'car groups ", "))
10015             (message "This message would go to no groups"))
10016           groups)))))
10017
10018 (defun gnus-summary-respool-trace ()
10019   "Trace where the respool algorithm would put this article.
10020 Display a buffer showing all fancy splitting patterns which matched."
10021   (interactive)
10022   (gnus-summary-respool-query nil t))
10023
10024 ;; Summary marking commands.
10025
10026 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10027   "Mark articles which has the same subject as read, and then select the next.
10028 If UNMARK is positive, remove any kind of mark.
10029 If UNMARK is negative, tick articles."
10030   (interactive "P")
10031   (when unmark
10032     (setq unmark (prefix-numeric-value unmark)))
10033   (let ((count
10034          (gnus-summary-mark-same-subject
10035           (gnus-summary-article-subject) unmark)))
10036     ;; Select next unread article.  If auto-select-same mode, should
10037     ;; select the first unread article.
10038     (gnus-summary-next-article t (and gnus-auto-select-same
10039                                       (gnus-summary-article-subject)))
10040     (gnus-message 7 "%d article%s marked as %s"
10041                   count (if (= count 1) " is" "s are")
10042                   (if unmark "unread" "read"))))
10043
10044 (defun gnus-summary-kill-same-subject (&optional unmark)
10045   "Mark articles which has the same subject as read.
10046 If UNMARK is positive, remove any kind of mark.
10047 If UNMARK is negative, tick articles."
10048   (interactive "P")
10049   (when unmark
10050     (setq unmark (prefix-numeric-value unmark)))
10051   (let ((count
10052          (gnus-summary-mark-same-subject
10053           (gnus-summary-article-subject) unmark)))
10054     ;; If marked as read, go to next unread subject.
10055     (when (null unmark)
10056       ;; Go to next unread subject.
10057       (gnus-summary-next-subject 1 t))
10058     (gnus-message 7 "%d articles are marked as %s"
10059                   count (if unmark "unread" "read"))))
10060
10061 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10062   "Mark articles with same SUBJECT as read, and return marked number.
10063 If optional argument UNMARK is positive, remove any kinds of marks.
10064 If optional argument UNMARK is negative, mark articles as unread instead."
10065   (let ((count 1))
10066     (save-excursion
10067       (cond
10068        ((null unmark)                   ; Mark as read.
10069         (while (and
10070                 (progn
10071                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10072                   (gnus-summary-show-thread) t)
10073                 (gnus-summary-find-subject subject))
10074           (setq count (1+ count))))
10075        ((> unmark 0)                    ; Tick.
10076         (while (and
10077                 (progn
10078                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10079                   (gnus-summary-show-thread) t)
10080                 (gnus-summary-find-subject subject))
10081           (setq count (1+ count))))
10082        (t                               ; Mark as unread.
10083         (while (and
10084                 (progn
10085                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10086                   (gnus-summary-show-thread) t)
10087                 (gnus-summary-find-subject subject))
10088           (setq count (1+ count)))))
10089       (gnus-set-mode-line 'summary)
10090       ;; Return the number of marked articles.
10091       count)))
10092
10093 (defun gnus-summary-mark-as-processable (n &optional unmark)
10094   "Set the process mark on the next N articles.
10095 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10096 the process mark instead.  The difference between N and the actual
10097 number of articles marked is returned."
10098   (interactive "P")
10099   (if (and (null n) (gnus-region-active-p))
10100       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10101     (setq n (prefix-numeric-value n))
10102     (let ((backward (< n 0))
10103           (n (abs n)))
10104       (while (and
10105               (> n 0)
10106               (if unmark
10107                   (gnus-summary-remove-process-mark
10108                    (gnus-summary-article-number))
10109                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10110               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10111         (setq n (1- n)))
10112       (when (/= 0 n)
10113         (gnus-message 7 "No more articles"))
10114       (gnus-summary-recenter)
10115       (gnus-summary-position-point)
10116       n)))
10117
10118 (defun gnus-summary-unmark-as-processable (n)
10119   "Remove the process mark from the next N articles.
10120 If N is negative, unmark backward instead.  The difference between N and
10121 the actual number of articles unmarked is returned."
10122   (interactive "P")
10123   (gnus-summary-mark-as-processable n t))
10124
10125 (defun gnus-summary-unmark-all-processable ()
10126   "Remove the process mark from all articles."
10127   (interactive)
10128   (save-excursion
10129     (while gnus-newsgroup-processable
10130       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10131   (gnus-summary-position-point))
10132
10133 (defun gnus-summary-add-mark (article type)
10134   "Mark ARTICLE with a mark of TYPE."
10135   (let ((vtype (car (assq type gnus-article-mark-lists)))
10136         var)
10137     (if (not vtype)
10138         (error "No such mark type: %s" type)
10139       (setq var (intern (format "gnus-newsgroup-%s" type)))
10140       (set var (cons article (symbol-value var)))
10141       (if (memq type '(processable cached replied forwarded recent saved))
10142           (gnus-summary-update-secondary-mark article)
10143         ;;; !!! This is bogus.  We should find out what primary
10144         ;;; !!! mark we want to set.
10145         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10146
10147 (defun gnus-summary-mark-as-expirable (n)
10148   "Mark N articles forward as expirable.
10149 If N is negative, mark backward instead.  The difference between N and
10150 the actual number of articles marked is returned."
10151   (interactive "p")
10152   (gnus-summary-mark-forward n gnus-expirable-mark))
10153
10154 (defun gnus-summary-mark-as-spam (n)
10155   "Mark N articles forward as spam.
10156 If N is negative, mark backward instead.  The difference between N and
10157 the actual number of articles marked is returned."
10158   (interactive "p")
10159   (gnus-summary-mark-forward n gnus-spam-mark))
10160
10161 (defun gnus-summary-mark-article-as-replied (article)
10162   "Mark ARTICLE as replied to and update the summary line.
10163 ARTICLE can also be a list of articles."
10164   (interactive (list (gnus-summary-article-number)))
10165   (let ((articles (if (listp article) article (list article))))
10166     (dolist (article articles)
10167       (unless (numberp article)
10168         (error "%s is not a number" article))
10169       (push article gnus-newsgroup-replied)
10170       (let ((buffer-read-only nil))
10171         (when (gnus-summary-goto-subject article nil t)
10172           (gnus-summary-update-secondary-mark article))))))
10173
10174 (defun gnus-summary-mark-article-as-forwarded (article)
10175   "Mark ARTICLE as forwarded and update the summary line.
10176 ARTICLE can also be a list of articles."
10177   (let ((articles (if (listp article) article (list article))))
10178     (dolist (article articles)
10179       (push article gnus-newsgroup-forwarded)
10180       (let ((buffer-read-only nil))
10181         (when (gnus-summary-goto-subject article nil t)
10182           (gnus-summary-update-secondary-mark article))))))
10183
10184 (defun gnus-summary-set-bookmark (article)
10185   "Set a bookmark in current article."
10186   (interactive (list (gnus-summary-article-number)))
10187   (when (or (not (get-buffer gnus-article-buffer))
10188             (not gnus-current-article)
10189             (not gnus-article-current)
10190             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10191     (error "No current article selected"))
10192   ;; Remove old bookmark, if one exists.
10193   (gnus-pull article gnus-newsgroup-bookmarks)
10194   ;; Set the new bookmark, which is on the form
10195   ;; (article-number . line-number-in-body).
10196   (push
10197    (cons article
10198          (with-current-buffer gnus-article-buffer
10199            (count-lines
10200             (min (point)
10201                  (save-excursion
10202                    (article-goto-body)
10203                    (point)))
10204             (point))))
10205    gnus-newsgroup-bookmarks)
10206   (gnus-message 6 "A bookmark has been added to the current article."))
10207
10208 (defun gnus-summary-remove-bookmark (article)
10209   "Remove the bookmark from the current article."
10210   (interactive (list (gnus-summary-article-number)))
10211   ;; Remove old bookmark, if one exists.
10212   (if (not (assq article gnus-newsgroup-bookmarks))
10213       (gnus-message 6 "No bookmark in current article.")
10214     (gnus-pull article gnus-newsgroup-bookmarks)
10215     (gnus-message 6 "Removed bookmark.")))
10216
10217 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10218 (defun gnus-summary-mark-as-dormant (n)
10219   "Mark N articles forward as dormant.
10220 If N is negative, mark backward instead.  The difference between N and
10221 the actual number of articles marked is returned."
10222   (interactive "p")
10223   (gnus-summary-mark-forward n gnus-dormant-mark))
10224
10225 (defun gnus-summary-set-process-mark (article)
10226   "Set the process mark on ARTICLE and update the summary line."
10227   (setq gnus-newsgroup-processable
10228         (cons article
10229               (delq article gnus-newsgroup-processable)))
10230   (when (gnus-summary-goto-subject article)
10231     (gnus-summary-show-thread)
10232     (gnus-summary-goto-subject article)
10233     (gnus-summary-update-secondary-mark article)))
10234
10235 (defun gnus-summary-remove-process-mark (&rest articles)
10236   "Remove the process mark from ARTICLES and update the summary line."
10237   (dolist (article articles)
10238     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10239     (when (gnus-summary-goto-subject article)
10240       (gnus-summary-show-thread)
10241       (gnus-summary-goto-subject article)
10242       (gnus-summary-update-secondary-mark article)))
10243   t)
10244
10245 (defun gnus-summary-set-saved-mark (article)
10246   "Set the process mark on ARTICLE and update the summary line."
10247   (push article gnus-newsgroup-saved)
10248   (when (gnus-summary-goto-subject article)
10249     (gnus-summary-update-secondary-mark article)))
10250
10251 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10252   "Mark N articles as read forwards.
10253 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10254 The difference between N and the actual number of articles marked is
10255 returned.
10256 If NO-EXPIRE, auto-expiry will be inhibited."
10257   (interactive "p")
10258   (gnus-summary-show-thread)
10259   (let ((backward (< n 0))
10260         (gnus-summary-goto-unread
10261          (and gnus-summary-goto-unread
10262               (not (eq gnus-summary-goto-unread 'never))
10263               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10264                                     gnus-ticked-mark gnus-dormant-mark)))))
10265         (n (abs n))
10266         (mark (or mark gnus-del-mark)))
10267     (while (and (> n 0)
10268                 (gnus-summary-mark-article nil mark no-expire)
10269                 (zerop (gnus-summary-next-subject
10270                         (if backward -1 1)
10271                         (and gnus-summary-goto-unread
10272                              (not (eq gnus-summary-goto-unread 'never)))
10273                         t)))
10274       (setq n (1- n)))
10275     (when (/= 0 n)
10276       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10277     (gnus-summary-recenter)
10278     (gnus-summary-position-point)
10279     (gnus-set-mode-line 'summary)
10280     n))
10281
10282 (defun gnus-summary-mark-article-as-read (mark)
10283   "Mark the current article quickly as read with MARK."
10284   (let ((article (gnus-summary-article-number)))
10285     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10286     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10287     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10288     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10289     (push (cons article mark) gnus-newsgroup-reads)
10290     ;; Possibly remove from cache, if that is used.
10291     (when gnus-use-cache
10292       (gnus-cache-enter-remove-article article))
10293     ;; Allow the backend to change the mark.
10294     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10295     ;; Check for auto-expiry.
10296     (when (and gnus-newsgroup-auto-expire
10297                (memq mark gnus-auto-expirable-marks))
10298       (setq mark gnus-expirable-mark)
10299       ;; Let the backend know about the mark change.
10300       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10301       (push article gnus-newsgroup-expirable))
10302     ;; Set the mark in the buffer.
10303     (gnus-summary-update-mark mark 'unread)
10304     t))
10305
10306 (defun gnus-summary-mark-article-as-unread (mark)
10307   "Mark the current article quickly as unread with MARK."
10308   (let* ((article (gnus-summary-article-number))
10309          (old-mark (gnus-summary-article-mark article)))
10310     ;; Allow the backend to change the mark.
10311     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10312     (if (eq mark old-mark)
10313         t
10314       (if (<= article 0)
10315           (progn
10316             (gnus-error 1 "Can't mark negative article numbers")
10317             nil)
10318         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10319         (setq gnus-newsgroup-spam-marked
10320               (delq article gnus-newsgroup-spam-marked))
10321         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10322         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10323         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10324         (cond ((= mark gnus-ticked-mark)
10325                (setq gnus-newsgroup-marked
10326                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10327                                               article)))
10328               ((= mark gnus-spam-mark)
10329                (setq gnus-newsgroup-spam-marked
10330                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10331                                               article)))
10332               ((= mark gnus-dormant-mark)
10333                (setq gnus-newsgroup-dormant
10334                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10335                                               article)))
10336               (t
10337                (setq gnus-newsgroup-unreads
10338                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10339                                               article))))
10340         (gnus-pull article gnus-newsgroup-reads)
10341
10342         ;; See whether the article is to be put in the cache.
10343         (and gnus-use-cache
10344              (vectorp (gnus-summary-article-header article))
10345              (save-excursion
10346                (gnus-cache-possibly-enter-article
10347                 gnus-newsgroup-name article
10348                 (= mark gnus-ticked-mark)
10349                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10350
10351         ;; Fix the mark.
10352         (gnus-summary-update-mark mark 'unread)
10353         t))))
10354
10355 (defun gnus-summary-mark-article (&optional article mark no-expire)
10356   "Mark ARTICLE with MARK.  MARK can be any character.
10357 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10358 `??' (dormant) and `?E' (expirable).
10359 If MARK is nil, then the default character `?r' is used.
10360 If ARTICLE is nil, then the article on the current line will be
10361 marked.
10362 If NO-EXPIRE, auto-expiry will be inhibited."
10363   ;; The mark might be a string.
10364   (when (stringp mark)
10365     (setq mark (aref mark 0)))
10366   ;; If no mark is given, then we check auto-expiring.
10367   (when (null mark)
10368     (setq mark gnus-del-mark))
10369   (when (and (not no-expire)
10370              gnus-newsgroup-auto-expire
10371              (memq mark gnus-auto-expirable-marks))
10372     (setq mark gnus-expirable-mark))
10373   (let ((article (or article (gnus-summary-article-number)))
10374         (old-mark (gnus-summary-article-mark article)))
10375     ;; Allow the backend to change the mark.
10376     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10377     (if (eq mark old-mark)
10378         t
10379       (unless article
10380         (error "No article on current line"))
10381       (if (not (if (or (= mark gnus-unread-mark)
10382                        (= mark gnus-ticked-mark)
10383                        (= mark gnus-spam-mark)
10384                        (= mark gnus-dormant-mark))
10385                    (gnus-mark-article-as-unread article mark)
10386                  (gnus-mark-article-as-read article mark)))
10387           t
10388         ;; See whether the article is to be put in the cache.
10389         (and gnus-use-cache
10390              (not (= mark gnus-canceled-mark))
10391              (vectorp (gnus-summary-article-header article))
10392              (save-excursion
10393                (gnus-cache-possibly-enter-article
10394                 gnus-newsgroup-name article
10395                 (= mark gnus-ticked-mark)
10396                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10397
10398         (when (gnus-summary-goto-subject article nil t)
10399           (let ((buffer-read-only nil))
10400             (gnus-summary-show-thread)
10401             ;; Fix the mark.
10402             (gnus-summary-update-mark mark 'unread)
10403             t))))))
10404
10405 (defun gnus-summary-update-secondary-mark (article)
10406   "Update the secondary (read, process, cache) mark."
10407   (gnus-summary-update-mark
10408    (cond ((memq article gnus-newsgroup-processable)
10409           gnus-process-mark)
10410          ((memq article gnus-newsgroup-cached)
10411           gnus-cached-mark)
10412          ((memq article gnus-newsgroup-replied)
10413           gnus-replied-mark)
10414          ((memq article gnus-newsgroup-forwarded)
10415           gnus-forwarded-mark)
10416          ((memq article gnus-newsgroup-saved)
10417           gnus-saved-mark)
10418          ((memq article gnus-newsgroup-recent)
10419           gnus-recent-mark)
10420          ((memq article gnus-newsgroup-unseen)
10421           gnus-unseen-mark)
10422          (t gnus-no-mark))
10423    'replied)
10424   (when (gnus-visual-p 'summary-highlight 'highlight)
10425     (gnus-run-hooks 'gnus-summary-update-hook))
10426   t)
10427
10428 (defun gnus-summary-update-download-mark (article)
10429   "Update the download mark."
10430   (gnus-summary-update-mark
10431    (cond ((memq article gnus-newsgroup-undownloaded)
10432           gnus-undownloaded-mark)
10433          (gnus-newsgroup-agentized
10434           gnus-downloaded-mark)
10435          (t
10436           gnus-no-mark))
10437    'download)
10438   (gnus-summary-update-line t)
10439   t)
10440
10441 (defun gnus-summary-update-mark (mark type)
10442   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10443         (buffer-read-only nil))
10444     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10445     (when forward
10446       (when (looking-at "\r")
10447         (incf forward))
10448       (when (<= (+ forward (point)) (point-max))
10449         ;; Go to the right position on the line.
10450         (goto-char (+ forward (point)))
10451         ;; Replace the old mark with the new mark.
10452         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10453         ;; Optionally update the marks by some user rule.
10454         (when (eq type 'unread)
10455           (gnus-data-set-mark
10456            (gnus-data-find (gnus-summary-article-number)) mark)
10457           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10458
10459 (defun gnus-mark-article-as-read (article &optional mark)
10460   "Enter ARTICLE in the pertinent lists and remove it from others."
10461   ;; Make the article expirable.
10462   (let ((mark (or mark gnus-del-mark)))
10463     (setq gnus-newsgroup-expirable
10464           (if (= mark gnus-expirable-mark)
10465               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10466             (delq article gnus-newsgroup-expirable)))
10467     ;; Remove from unread and marked lists.
10468     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10469     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10470     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10471     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10472     (push (cons article mark) gnus-newsgroup-reads)
10473     ;; Possibly remove from cache, if that is used.
10474     (when gnus-use-cache
10475       (gnus-cache-enter-remove-article article))
10476     t))
10477
10478 (defun gnus-mark-article-as-unread (article &optional mark)
10479   "Enter ARTICLE in the pertinent lists and remove it from others."
10480   (let ((mark (or mark gnus-ticked-mark)))
10481     (if (<= article 0)
10482         (progn
10483           (gnus-error 1 "Can't mark negative article numbers")
10484           nil)
10485       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10486             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10487             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10488             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10489             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10490
10491       ;; Unsuppress duplicates?
10492       (when gnus-suppress-duplicates
10493         (gnus-dup-unsuppress-article article))
10494
10495       (cond ((= mark gnus-ticked-mark)
10496              (setq gnus-newsgroup-marked
10497                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10498             ((= mark gnus-spam-mark)
10499              (setq gnus-newsgroup-spam-marked
10500                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10501                                             article)))
10502             ((= mark gnus-dormant-mark)
10503              (setq gnus-newsgroup-dormant
10504                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10505             (t
10506              (setq gnus-newsgroup-unreads
10507                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10508       (gnus-pull article gnus-newsgroup-reads)
10509       t)))
10510
10511 (defalias 'gnus-summary-mark-as-unread-forward
10512   'gnus-summary-tick-article-forward)
10513 (make-obsolete 'gnus-summary-mark-as-unread-forward
10514                'gnus-summary-tick-article-forward)
10515 (defun gnus-summary-tick-article-forward (n)
10516   "Tick N articles forwards.
10517 If N is negative, tick backwards instead.
10518 The difference between N and the number of articles ticked is returned."
10519   (interactive "p")
10520   (gnus-summary-mark-forward n gnus-ticked-mark))
10521
10522 (defalias 'gnus-summary-mark-as-unread-backward
10523   'gnus-summary-tick-article-backward)
10524 (make-obsolete 'gnus-summary-mark-as-unread-backward
10525                'gnus-summary-tick-article-backward)
10526 (defun gnus-summary-tick-article-backward (n)
10527   "Tick N articles backwards.
10528 The difference between N and the number of articles ticked is returned."
10529   (interactive "p")
10530   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10531
10532 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10533 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10534 (defun gnus-summary-tick-article (&optional article clear-mark)
10535   "Mark current article as unread.
10536 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10537 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10538   (interactive)
10539   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10540                                        gnus-ticked-mark)))
10541
10542 (defun gnus-summary-mark-as-read-forward (n)
10543   "Mark N articles as read forwards.
10544 If N is negative, mark backwards instead.
10545 The difference between N and the actual number of articles marked is
10546 returned."
10547   (interactive "p")
10548   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10549
10550 (defun gnus-summary-mark-as-read-backward (n)
10551   "Mark the N articles as read backwards.
10552 The difference between N and the actual number of articles marked is
10553 returned."
10554   (interactive "p")
10555   (gnus-summary-mark-forward
10556    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10557
10558 (defun gnus-summary-mark-as-read (&optional article mark)
10559   "Mark current article as read.
10560 ARTICLE specifies the article to be marked as read.
10561 MARK specifies a string to be inserted at the beginning of the line."
10562   (gnus-summary-mark-article article mark))
10563
10564 (defun gnus-summary-clear-mark-forward (n)
10565   "Clear marks from N articles forward.
10566 If N is negative, clear backward instead.
10567 The difference between N and the number of marks cleared is returned."
10568   (interactive "p")
10569   (gnus-summary-mark-forward n gnus-unread-mark))
10570
10571 (defun gnus-summary-clear-mark-backward (n)
10572   "Clear marks from N articles backward.
10573 The difference between N and the number of marks cleared is returned."
10574   (interactive "p")
10575   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10576
10577 (defun gnus-summary-mark-unread-as-read ()
10578   "Intended to be used by `gnus-summary-mark-article-hook'."
10579   (when (memq gnus-current-article gnus-newsgroup-unreads)
10580     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10581
10582 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10583   "Intended to be used by `gnus-summary-mark-article-hook'."
10584   (let ((mark (gnus-summary-article-mark)))
10585     (when (or (gnus-unread-mark-p mark)
10586               (gnus-read-mark-p mark))
10587       (gnus-summary-mark-article gnus-current-article
10588                                  (or new-mark gnus-read-mark)))))
10589
10590 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10591   "Intended to be used by `gnus-summary-mark-article-hook'."
10592   (let ((mark (gnus-summary-article-mark)))
10593     (when (or (gnus-unread-mark-p mark)
10594               (gnus-read-mark-p mark))
10595       (gnus-summary-mark-article (gnus-summary-article-number)
10596                                  (or new-mark gnus-read-mark)))))
10597
10598 (defun gnus-summary-mark-unread-as-ticked ()
10599   "Intended to be used by `gnus-summary-mark-article-hook'."
10600   (when (memq gnus-current-article gnus-newsgroup-unreads)
10601     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10602
10603 (defun gnus-summary-mark-region-as-read (point mark all)
10604   "Mark all unread articles between point and mark as read.
10605 If given a prefix, mark all articles between point and mark as read,
10606 even ticked and dormant ones."
10607   (interactive "r\nP")
10608   (save-excursion
10609     (let (article)
10610       (goto-char point)
10611       (beginning-of-line)
10612       (while (and
10613               (< (point) mark)
10614               (progn
10615                 (when (or all
10616                           (memq (setq article (gnus-summary-article-number))
10617                                 gnus-newsgroup-unreads))
10618                   (gnus-summary-mark-article article gnus-del-mark))
10619                 t)
10620               (gnus-summary-find-next))))))
10621
10622 (defun gnus-summary-mark-below (score mark)
10623   "Mark articles with score less than SCORE with MARK."
10624   (interactive "P\ncMark: ")
10625   (setq score (if score
10626                   (prefix-numeric-value score)
10627                 (or gnus-summary-default-score 0)))
10628   (save-excursion
10629     (set-buffer gnus-summary-buffer)
10630     (goto-char (point-min))
10631     (while
10632         (progn
10633           (and (< (gnus-summary-article-score) score)
10634                (gnus-summary-mark-article nil mark))
10635           (gnus-summary-find-next)))))
10636
10637 (defun gnus-summary-kill-below (&optional score)
10638   "Mark articles with score below SCORE as read."
10639   (interactive "P")
10640   (gnus-summary-mark-below score gnus-killed-mark))
10641
10642 (defun gnus-summary-clear-above (&optional score)
10643   "Clear all marks from articles with score above SCORE."
10644   (interactive "P")
10645   (gnus-summary-mark-above score gnus-unread-mark))
10646
10647 (defun gnus-summary-tick-above (&optional score)
10648   "Tick all articles with score above SCORE."
10649   (interactive "P")
10650   (gnus-summary-mark-above score gnus-ticked-mark))
10651
10652 (defun gnus-summary-mark-above (score mark)
10653   "Mark articles with score over SCORE with MARK."
10654   (interactive "P\ncMark: ")
10655   (setq score (if score
10656                   (prefix-numeric-value score)
10657                 (or gnus-summary-default-score 0)))
10658   (save-excursion
10659     (set-buffer gnus-summary-buffer)
10660     (goto-char (point-min))
10661     (while (and (progn
10662                   (when (> (gnus-summary-article-score) score)
10663                     (gnus-summary-mark-article nil mark))
10664                   t)
10665                 (gnus-summary-find-next)))))
10666
10667 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10668 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10669 (defun gnus-summary-limit-include-expunged (&optional no-error)
10670   "Display all the hidden articles that were expunged for low scores."
10671   (interactive)
10672   (let ((buffer-read-only nil))
10673     (let ((scored gnus-newsgroup-scored)
10674           headers h)
10675       (while scored
10676         (unless (gnus-summary-article-header (caar scored))
10677           (and (setq h (gnus-number-to-header (caar scored)))
10678                (< (cdar scored) gnus-summary-expunge-below)
10679                (push h headers)))
10680         (setq scored (cdr scored)))
10681       (if (not headers)
10682           (when (not no-error)
10683             (error "No expunged articles hidden"))
10684         (goto-char (point-min))
10685         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10686         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10687         (mapcar (lambda (x) (push (mail-header-number x)
10688                                   gnus-newsgroup-limit))
10689                 headers)
10690         (gnus-summary-prepare-unthreaded (nreverse headers))
10691         (goto-char (point-min))
10692         (gnus-summary-position-point)
10693         t))))
10694
10695 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10696   "Mark all unread articles in this newsgroup as read.
10697 If prefix argument ALL is non-nil, ticked and dormant articles will
10698 also be marked as read.
10699 If QUIETLY is non-nil, no questions will be asked.
10700
10701 If TO-HERE is non-nil, it should be a point in the buffer.  All
10702 articles before (after, if REVERSE is set) this point will be marked
10703 as read.
10704
10705 Note that this function will only catch up the unread article
10706 in the current summary buffer limitation.
10707
10708 The number of articles marked as read is returned."
10709   (interactive "P")
10710   (prog1
10711       (save-excursion
10712         (when (or quietly
10713                   (not gnus-interactive-catchup) ;Without confirmation?
10714                   gnus-expert-user
10715                   (gnus-y-or-n-p
10716                    (if all
10717                        "Mark absolutely all articles as read? "
10718                      "Mark all unread articles as read? ")))
10719           (if (and not-mark
10720                    (not gnus-newsgroup-adaptive)
10721                    (not gnus-newsgroup-auto-expire)
10722                    (not gnus-suppress-duplicates)
10723                    (or (not gnus-use-cache)
10724                        (eq gnus-use-cache 'passive)))
10725               (progn
10726                 (when all
10727                   (setq gnus-newsgroup-marked nil
10728                         gnus-newsgroup-spam-marked nil
10729                         gnus-newsgroup-dormant nil))
10730                 (setq gnus-newsgroup-unreads
10731                       (gnus-sorted-nunion
10732                        (gnus-sorted-intersection gnus-newsgroup-unreads
10733                                                  gnus-newsgroup-downloadable)
10734                        gnus-newsgroup-unfetched)))
10735             ;; We actually mark all articles as canceled, which we
10736             ;; have to do when using auto-expiry or adaptive scoring.
10737             (gnus-summary-show-all-threads)
10738             (if (and to-here reverse)
10739                 (progn
10740                   (goto-char to-here)
10741                   (gnus-summary-mark-current-read-and-unread-as-read
10742                    gnus-catchup-mark)
10743                   (while (gnus-summary-find-next (not all))
10744                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10745               (when (gnus-summary-first-subject (not all))
10746                 (while (and
10747                         (if to-here (< (point) to-here) t)
10748                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10749                         (gnus-summary-find-next (not all))))))
10750             (gnus-set-mode-line 'summary))
10751           t))
10752     (gnus-summary-position-point)))
10753
10754 (defun gnus-summary-catchup-to-here (&optional all)
10755   "Mark all unticked articles before the current one as read.
10756 If ALL is non-nil, also mark ticked and dormant articles as read."
10757   (interactive "P")
10758   (save-excursion
10759     (gnus-save-hidden-threads
10760       (let ((beg (point)))
10761         ;; We check that there are unread articles.
10762         (when (or all (gnus-summary-find-prev))
10763           (gnus-summary-catchup all t beg)))))
10764   (gnus-summary-position-point))
10765
10766 (defun gnus-summary-catchup-from-here (&optional all)
10767   "Mark all unticked articles after (and including) the current one as read.
10768 If ALL is non-nil, also mark ticked and dormant articles as read."
10769   (interactive "P")
10770   (save-excursion
10771     (gnus-save-hidden-threads
10772       (let ((beg (point)))
10773         ;; We check that there are unread articles.
10774         (when (or all (gnus-summary-find-next))
10775           (gnus-summary-catchup all t beg nil t)))))
10776   (gnus-summary-position-point))
10777
10778 (defun gnus-summary-catchup-all (&optional quietly)
10779   "Mark all articles in this newsgroup as read.
10780 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10781 instead, which marks only unread articles as read."
10782   (interactive "P")
10783   (gnus-summary-catchup t quietly))
10784
10785 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10786   "Mark all unread articles in this group as read, then exit.
10787 If prefix argument ALL is non-nil, all articles are marked as read.
10788 If QUIETLY is non-nil, no questions will be asked."
10789   (interactive "P")
10790   (when (gnus-summary-catchup all quietly nil 'fast)
10791     ;; Select next newsgroup or exit.
10792     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10793              (eq gnus-auto-select-next 'quietly))
10794         (gnus-summary-next-group nil)
10795       (gnus-summary-exit))))
10796
10797 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10798   "Mark all articles in this newsgroup as read, and then exit.
10799 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10800 instead, which marks only unread articles as read."
10801   (interactive "P")
10802   (gnus-summary-catchup-and-exit t quietly))
10803
10804 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10805   "Mark all articles in this group as read and select the next group.
10806 If given a prefix, mark all articles, unread as well as ticked, as
10807 read."
10808   (interactive "P")
10809   (save-excursion
10810     (gnus-summary-catchup all))
10811   (gnus-summary-next-group))
10812
10813 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
10814   "Mark all articles in this group as read and select the previous group.
10815 If given a prefix, mark all articles, unread as well as ticked, as
10816 read."
10817   (interactive "P")
10818   (save-excursion
10819     (gnus-summary-catchup all))
10820   (gnus-summary-next-group nil nil t))
10821
10822 ;;;
10823 ;;; with article
10824 ;;;
10825
10826 (defmacro gnus-with-article (article &rest forms)
10827   "Select ARTICLE and perform FORMS in the original article buffer.
10828 Then replace the article with the result."
10829   `(progn
10830      ;; We don't want the article to be marked as read.
10831      (let (gnus-mark-article-hook)
10832        (gnus-summary-select-article t t nil ,article))
10833      (set-buffer gnus-original-article-buffer)
10834      ,@forms
10835      (if (not (gnus-check-backend-function
10836                'request-replace-article (car gnus-article-current)))
10837          (gnus-message 5 "Read-only group; not replacing")
10838        (unless (gnus-request-replace-article
10839                 ,article (car gnus-article-current)
10840                 (current-buffer) t)
10841          (error "Couldn't replace article")))
10842      ;; The cache and backlog have to be flushed somewhat.
10843      (when gnus-keep-backlog
10844        (gnus-backlog-remove-article
10845         (car gnus-article-current) (cdr gnus-article-current)))
10846      (when gnus-use-cache
10847        (gnus-cache-update-article
10848         (car gnus-article-current) (cdr gnus-article-current)))))
10849
10850 (put 'gnus-with-article 'lisp-indent-function 1)
10851 (put 'gnus-with-article 'edebug-form-spec '(form body))
10852
10853 ;; Thread-based commands.
10854
10855 (defun gnus-summary-articles-in-thread (&optional article)
10856   "Return a list of all articles in the current thread.
10857 If ARTICLE is non-nil, return all articles in the thread that starts
10858 with that article."
10859   (let* ((article (or article (gnus-summary-article-number)))
10860          (data (gnus-data-find-list article))
10861          (top-level (gnus-data-level (car data)))
10862          (top-subject
10863           (cond ((null gnus-thread-operation-ignore-subject)
10864                  (gnus-simplify-subject-re
10865                   (mail-header-subject (gnus-data-header (car data)))))
10866                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10867                  (gnus-simplify-subject-fuzzy
10868                   (mail-header-subject (gnus-data-header (car data)))))
10869                 (t nil)))
10870          (end-point (save-excursion
10871                       (if (gnus-summary-go-to-next-thread)
10872                           (point) (point-max))))
10873          articles)
10874     (while (and data
10875                 (< (gnus-data-pos (car data)) end-point))
10876       (when (or (not top-subject)
10877                 (string= top-subject
10878                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10879                              (gnus-simplify-subject-fuzzy
10880                               (mail-header-subject
10881                                (gnus-data-header (car data))))
10882                            (gnus-simplify-subject-re
10883                             (mail-header-subject
10884                              (gnus-data-header (car data)))))))
10885         (push (gnus-data-number (car data)) articles))
10886       (unless (and (setq data (cdr data))
10887                    (> (gnus-data-level (car data)) top-level))
10888         (setq data nil)))
10889     ;; Return the list of articles.
10890     (nreverse articles)))
10891
10892 (defun gnus-summary-rethread-current ()
10893   "Rethread the thread the current article is part of."
10894   (interactive)
10895   (let* ((gnus-show-threads t)
10896          (article (gnus-summary-article-number))
10897          (id (mail-header-id (gnus-summary-article-header)))
10898          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10899     (unless id
10900       (error "No article on the current line"))
10901     (gnus-rebuild-thread id)
10902     (gnus-summary-goto-subject article)))
10903
10904 (defun gnus-summary-reparent-thread ()
10905   "Make the current article child of the marked (or previous) article.
10906
10907 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10908 is non-nil or the Subject: of both articles are the same."
10909   (interactive)
10910   (unless (not (gnus-group-read-only-p))
10911     (error "The current newsgroup does not support article editing"))
10912   (unless (<= (length gnus-newsgroup-processable) 1)
10913     (error "No more than one article may be marked"))
10914   (let ((child (gnus-summary-article-number))
10915         ;; First grab the marked article, otherwise one line up.
10916         (parent (if (not (null gnus-newsgroup-processable))
10917                     (car gnus-newsgroup-processable)
10918                   (save-excursion
10919                     (if (eq (forward-line -1) 0)
10920                         (gnus-summary-article-number)
10921                       (error "Beginning of summary buffer"))))))
10922     (gnus-summary-reparent-children parent (list child))))
10923
10924 (defun gnus-summary-reparent-children (parent children)
10925   "Make PARENT the parent of CHILDREN.
10926 When called interactively, PARENT is is current article and
10927 CHILDREN are the process-marked articles."
10928   (interactive
10929    (list (gnus-summary-article-number)
10930          (gnus-summary-work-articles nil)))
10931   (dolist (child children)
10932     (save-window-excursion
10933       (let ((gnus-article-buffer " *reparent*"))
10934         (unless (not (eq parent child))
10935           (error "An article may not be self-referential"))
10936         (let ((message-id (mail-header-id
10937                            (gnus-summary-article-header parent))))
10938           (unless (and message-id (not (equal message-id "")))
10939             (error "No message-id in desired parent"))
10940           (gnus-with-article child
10941             (save-restriction
10942               (goto-char (point-min))
10943               (message-narrow-to-head)
10944               (if (re-search-forward "^References: " nil t)
10945                   (progn
10946                     (re-search-forward "^[^ \t]" nil t)
10947                     (forward-line -1)
10948                     (end-of-line)
10949                     (insert " " message-id))
10950                 (insert "References: " message-id "\n"))))
10951           (set-buffer gnus-summary-buffer)
10952           (gnus-summary-unmark-all-processable)
10953           (gnus-summary-update-article child)
10954           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10955             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10956           (gnus-summary-rethread-current)
10957           (gnus-message 3 "Article %d is now the child of article %d"
10958                         child parent))))))
10959
10960 (defun gnus-summary-toggle-threads (&optional arg)
10961   "Toggle showing conversation threads.
10962 If ARG is positive number, turn showing conversation threads on."
10963   (interactive "P")
10964   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10965     (setq gnus-show-threads
10966           (if (null arg) (not gnus-show-threads)
10967             (> (prefix-numeric-value arg) 0)))
10968     (gnus-summary-prepare)
10969     (gnus-summary-goto-subject current)
10970     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10971     (gnus-summary-position-point)))
10972
10973 (defun gnus-summary-show-all-threads ()
10974   "Show all threads."
10975   (interactive)
10976   (save-excursion
10977     (let ((buffer-read-only nil))
10978       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10979   (gnus-summary-position-point))
10980
10981 (defun gnus-summary-show-thread ()
10982   "Show thread subtrees.
10983 Returns nil if no thread was there to be shown."
10984   (interactive)
10985   (let ((buffer-read-only nil)
10986         (orig (point))
10987         (end (point-at-eol))
10988         ;; Leave point at bol
10989         (beg (progn (beginning-of-line) (point))))
10990     (prog1
10991         ;; Any hidden lines here?
10992         (search-forward "\r" end t)
10993       (subst-char-in-region beg end ?\^M ?\n t)
10994       (goto-char orig)
10995       (gnus-summary-position-point))))
10996
10997 (defun gnus-summary-maybe-hide-threads ()
10998   "If requested, hide the threads that should be hidden."
10999   (when (and gnus-show-threads
11000              gnus-thread-hide-subtree)
11001     (gnus-summary-hide-all-threads
11002      (if (or (consp gnus-thread-hide-subtree)
11003              (functionp gnus-thread-hide-subtree))
11004          (gnus-make-predicate gnus-thread-hide-subtree)
11005        nil))))
11006
11007 ;;; Hiding predicates.
11008
11009 (defun gnus-article-unread-p (header)
11010   (memq (mail-header-number header) gnus-newsgroup-unreads))
11011
11012 (defun gnus-article-unseen-p (header)
11013   (memq (mail-header-number header) gnus-newsgroup-unseen))
11014
11015 (defun gnus-map-articles (predicate articles)
11016   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11017   (apply 'gnus-or (mapcar predicate
11018                           (mapcar (lambda (number)
11019                                     (gnus-summary-article-header number))
11020                                   articles))))
11021
11022 (defun gnus-summary-hide-all-threads (&optional predicate)
11023   "Hide all thread subtrees.
11024 If PREDICATE is supplied, threads that satisfy this predicate
11025 will not be hidden."
11026   (interactive)
11027   (save-excursion
11028     (goto-char (point-min))
11029     (let ((end nil))
11030       (while (not end)
11031         (when (or (not predicate)
11032                   (gnus-map-articles
11033                    predicate (gnus-summary-article-children)))
11034             (gnus-summary-hide-thread))
11035         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11036   (gnus-summary-position-point))
11037
11038 (defun gnus-summary-hide-thread ()
11039   "Hide thread subtrees.
11040 If PREDICATE is supplied, threads that satisfy this predicate
11041 will not be hidden.
11042 Returns nil if no threads were there to be hidden."
11043   (interactive)
11044   (let ((buffer-read-only nil)
11045         (start (point))
11046         (article (gnus-summary-article-number)))
11047     (goto-char start)
11048     ;; Go forward until either the buffer ends or the subthread
11049     ;; ends.
11050     (when (and (not (eobp))
11051                (or (zerop (gnus-summary-next-thread 1 t))
11052                    (goto-char (point-max))))
11053       (prog1
11054           (if (and (> (point) start)
11055                    (search-backward "\n" start t))
11056               (progn
11057                 (subst-char-in-region start (point) ?\n ?\^M)
11058                 (gnus-summary-goto-subject article))
11059             (goto-char start)
11060             nil)))))
11061
11062 (defun gnus-summary-go-to-next-thread (&optional previous)
11063   "Go to the same level (or less) next thread.
11064 If PREVIOUS is non-nil, go to previous thread instead.
11065 Return the article number moved to, or nil if moving was impossible."
11066   (let ((level (gnus-summary-thread-level))
11067         (way (if previous -1 1))
11068         (beg (point)))
11069     (forward-line way)
11070     (while (and (not (eobp))
11071                 (< level (gnus-summary-thread-level)))
11072       (forward-line way))
11073     (if (eobp)
11074         (progn
11075           (goto-char beg)
11076           nil)
11077       (setq beg (point))
11078       (prog1
11079           (gnus-summary-article-number)
11080         (goto-char beg)))))
11081
11082 (defun gnus-summary-next-thread (n &optional silent)
11083   "Go to the same level next N'th thread.
11084 If N is negative, search backward instead.
11085 Returns the difference between N and the number of skips actually
11086 done.
11087
11088 If SILENT, don't output messages."
11089   (interactive "p")
11090   (let ((backward (< n 0))
11091         (n (abs n)))
11092     (while (and (> n 0)
11093                 (gnus-summary-go-to-next-thread backward))
11094       (decf n))
11095     (unless silent
11096       (gnus-summary-position-point))
11097     (when (and (not silent) (/= 0 n))
11098       (gnus-message 7 "No more threads"))
11099     n))
11100
11101 (defun gnus-summary-prev-thread (n)
11102   "Go to the same level previous N'th thread.
11103 Returns the difference between N and the number of skips actually
11104 done."
11105   (interactive "p")
11106   (gnus-summary-next-thread (- n)))
11107
11108 (defun gnus-summary-go-down-thread ()
11109   "Go down one level in the current thread."
11110   (let ((children (gnus-summary-article-children)))
11111     (when children
11112       (gnus-summary-goto-subject (car children)))))
11113
11114 (defun gnus-summary-go-up-thread ()
11115   "Go up one level in the current thread."
11116   (let ((parent (gnus-summary-article-parent)))
11117     (when parent
11118       (gnus-summary-goto-subject parent))))
11119
11120 (defun gnus-summary-down-thread (n)
11121   "Go down thread N steps.
11122 If N is negative, go up instead.
11123 Returns the difference between N and how many steps down that were
11124 taken."
11125   (interactive "p")
11126   (let ((up (< n 0))
11127         (n (abs n)))
11128     (while (and (> n 0)
11129                 (if up (gnus-summary-go-up-thread)
11130                   (gnus-summary-go-down-thread)))
11131       (setq n (1- n)))
11132     (gnus-summary-position-point)
11133     (when (/= 0 n)
11134       (gnus-message 7 "Can't go further"))
11135     n))
11136
11137 (defun gnus-summary-up-thread (n)
11138   "Go up thread N steps.
11139 If N is negative, go down instead.
11140 Returns the difference between N and how many steps down that were
11141 taken."
11142   (interactive "p")
11143   (gnus-summary-down-thread (- n)))
11144
11145 (defun gnus-summary-top-thread ()
11146   "Go to the top of the thread."
11147   (interactive)
11148   (while (gnus-summary-go-up-thread))
11149   (gnus-summary-article-number))
11150
11151 (defun gnus-summary-kill-thread (&optional unmark)
11152   "Mark articles under current thread as read.
11153 If the prefix argument is positive, remove any kinds of marks.
11154 If the prefix argument is negative, tick articles instead."
11155   (interactive "P")
11156   (when unmark
11157     (setq unmark (prefix-numeric-value unmark)))
11158   (let ((articles (gnus-summary-articles-in-thread)))
11159     (save-excursion
11160       ;; Expand the thread.
11161       (gnus-summary-show-thread)
11162       ;; Mark all the articles.
11163       (while articles
11164         (gnus-summary-goto-subject (car articles))
11165         (cond ((null unmark)
11166                (gnus-summary-mark-article-as-read gnus-killed-mark))
11167               ((> unmark 0)
11168                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11169               (t
11170                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11171         (setq articles (cdr articles))))
11172     ;; Hide killed subtrees.
11173     (and (null unmark)
11174          gnus-thread-hide-killed
11175          (gnus-summary-hide-thread))
11176     ;; If marked as read, go to next unread subject.
11177     (when (null unmark)
11178       ;; Go to next unread subject.
11179       (gnus-summary-next-subject 1 t)))
11180   (gnus-set-mode-line 'summary))
11181
11182 ;; Summary sorting commands
11183
11184 (defun gnus-summary-sort-by-number (&optional reverse)
11185   "Sort the summary buffer by article number.
11186 Argument REVERSE means reverse order."
11187   (interactive "P")
11188   (gnus-summary-sort 'number reverse))
11189
11190 (defun gnus-summary-sort-by-random (&optional reverse)
11191   "Randomize the order in the summary buffer.
11192 Argument REVERSE means to randomize in reverse order."
11193   (interactive "P")
11194   (gnus-summary-sort 'random reverse))
11195
11196 (defun gnus-summary-sort-by-author (&optional reverse)
11197   "Sort the summary buffer by author name alphabetically.
11198 If `case-fold-search' is non-nil, case of letters is ignored.
11199 Argument REVERSE means reverse order."
11200   (interactive "P")
11201   (gnus-summary-sort 'author reverse))
11202
11203 (defun gnus-summary-sort-by-recipient (&optional reverse)
11204   "Sort the summary buffer by recipient name alphabetically.
11205 If `case-fold-search' is non-nil, case of letters is ignored.
11206 Argument REVERSE means reverse order."
11207   (interactive "P")
11208   (gnus-summary-sort 'recipient reverse))
11209
11210 (defun gnus-summary-sort-by-subject (&optional reverse)
11211   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11212 If `case-fold-search' is non-nil, case of letters is ignored.
11213 Argument REVERSE means reverse order."
11214   (interactive "P")
11215   (gnus-summary-sort 'subject reverse))
11216
11217 (defun gnus-summary-sort-by-date (&optional reverse)
11218   "Sort the summary buffer by date.
11219 Argument REVERSE means reverse order."
11220   (interactive "P")
11221   (gnus-summary-sort 'date reverse))
11222
11223 (defun gnus-summary-sort-by-score (&optional reverse)
11224   "Sort the summary buffer by score.
11225 Argument REVERSE means reverse order."
11226   (interactive "P")
11227   (gnus-summary-sort 'score reverse))
11228
11229 (defun gnus-summary-sort-by-lines (&optional reverse)
11230   "Sort the summary buffer by the number of lines.
11231 Argument REVERSE means reverse order."
11232   (interactive "P")
11233   (gnus-summary-sort 'lines reverse))
11234
11235 (defun gnus-summary-sort-by-chars (&optional reverse)
11236   "Sort the summary buffer by article length.
11237 Argument REVERSE means reverse order."
11238   (interactive "P")
11239   (gnus-summary-sort 'chars reverse))
11240
11241 (defun gnus-summary-sort-by-original (&optional reverse)
11242   "Sort the summary buffer using the default sorting method.
11243 Argument REVERSE means reverse order."
11244   (interactive "P")
11245   (let* ((buffer-read-only)
11246          (gnus-summary-prepare-hook nil))
11247     ;; We do the sorting by regenerating the threads.
11248     (gnus-summary-prepare)
11249     ;; Hide subthreads if needed.
11250     (gnus-summary-maybe-hide-threads)))
11251
11252 (defun gnus-summary-sort (predicate reverse)
11253   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11254   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11255          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11256          (gnus-thread-sort-functions
11257           (if (not reverse)
11258               thread
11259             `(lambda (t1 t2)
11260                (,thread t2 t1))))
11261          (gnus-sort-gathered-threads-function
11262           gnus-thread-sort-functions)
11263          (gnus-article-sort-functions
11264           (if (not reverse)
11265               article
11266             `(lambda (t1 t2)
11267                (,article t2 t1))))
11268          (buffer-read-only)
11269          (gnus-summary-prepare-hook nil))
11270     ;; We do the sorting by regenerating the threads.
11271     (gnus-summary-prepare)
11272     ;; Hide subthreads if needed.
11273     (gnus-summary-maybe-hide-threads)))
11274
11275 ;; Summary saving commands.
11276
11277 (defun gnus-summary-save-article (&optional n not-saved)
11278   "Save the current article using the default saver function.
11279 If N is a positive number, save the N next articles.
11280 If N is a negative number, save the N previous articles.
11281 If N is nil and any articles have been marked with the process mark,
11282 save those articles instead.
11283 The variable `gnus-default-article-saver' specifies the saver function.
11284
11285 If the optional second argument NOT-SAVED is non-nil, articles saved
11286 will not be marked as saved."
11287   (interactive "P")
11288   (require 'gnus-art)
11289   (let* ((articles (gnus-summary-work-articles n))
11290          (save-buffer (save-excursion
11291                         (nnheader-set-temp-buffer " *Gnus Save*")))
11292          (num (length articles))
11293          ;; Whether to save decoded articles or raw articles.
11294          (decode (when gnus-article-save-coding-system
11295                    (get gnus-default-article-saver :decode)))
11296          ;; When saving many articles in a single file, use the other
11297          ;; function to save articles other than the first one.
11298          (saver2 (get gnus-default-article-saver :function))
11299          (gnus-prompt-before-saving (if saver2
11300                                         t
11301                                       gnus-prompt-before-saving))
11302          (gnus-default-article-saver gnus-default-article-saver)
11303          header file)
11304     (dolist (article articles)
11305       (setq header (gnus-summary-article-header article))
11306       (if (not (vectorp header))
11307           ;; This is a pseudo-article.
11308           (if (assq 'name header)
11309               (gnus-copy-file (cdr (assq 'name header)))
11310             (gnus-message 1 "Article %d is unsaveable" article))
11311         ;; This is a real article.
11312         (save-window-excursion
11313           (let ((gnus-display-mime-function (when decode
11314                                               gnus-display-mime-function))
11315                 (gnus-article-prepare-hook (when decode
11316                                              gnus-article-prepare-hook)))
11317             (gnus-summary-select-article t nil nil article)
11318             (gnus-summary-goto-subject article)))
11319         (save-excursion
11320           (set-buffer save-buffer)
11321           (erase-buffer)
11322           (insert-buffer-substring (if decode
11323                                        gnus-article-buffer
11324                                      gnus-original-article-buffer)))
11325         (setq file (gnus-article-save save-buffer file num))
11326         (gnus-summary-remove-process-mark article)
11327         (unless not-saved
11328           (gnus-summary-set-saved-mark article)))
11329       (when saver2
11330         (setq gnus-default-article-saver saver2
11331               saver2 nil)))
11332     (gnus-kill-buffer save-buffer)
11333     (gnus-summary-position-point)
11334     (gnus-set-mode-line 'summary)
11335     n))
11336
11337 (defun gnus-summary-pipe-output (&optional arg headers)
11338   "Pipe the current article to a subprocess.
11339 If N is a positive number, pipe the N next articles.
11340 If N is a negative number, pipe the N previous articles.
11341 If N is nil and any articles have been marked with the process mark,
11342 pipe those articles instead.
11343 If HEADERS (the symbolic prefix), include the headers, too."
11344   (interactive (gnus-interactive "P\ny"))
11345   (require 'gnus-art)
11346   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11347         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11348     (gnus-summary-save-article arg t))
11349   (let ((buffer (get-buffer "*Shell Command Output*")))
11350     (when (and buffer
11351                (not (zerop (buffer-size buffer))))
11352       (gnus-configure-windows 'pipe))))
11353
11354 (defun gnus-summary-save-article-mail (&optional arg)
11355   "Append the current article to a Unix mail box file.
11356 If N is a positive number, save the N next articles.
11357 If N is a negative number, save the N previous articles.
11358 If N is nil and any articles have been marked with the process mark,
11359 save those articles instead."
11360   (interactive "P")
11361   (require 'gnus-art)
11362   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11363     (gnus-summary-save-article arg)))
11364
11365 (defun gnus-summary-save-article-rmail (&optional arg)
11366   "Append the current article to an rmail file.
11367 If N is a positive number, save the N next articles.
11368 If N is a negative number, save the N previous articles.
11369 If N is nil and any articles have been marked with the process mark,
11370 save those articles instead."
11371   (interactive "P")
11372   (require 'gnus-art)
11373   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11374     (gnus-summary-save-article arg)))
11375
11376 (defun gnus-summary-save-article-file (&optional arg)
11377   "Append the current article to a file.
11378 If N is a positive number, save the N next articles.
11379 If N is a negative number, save the N previous articles.
11380 If N is nil and any articles have been marked with the process mark,
11381 save those articles instead."
11382   (interactive "P")
11383   (require 'gnus-art)
11384   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11385     (gnus-summary-save-article arg)))
11386
11387 (defun gnus-summary-write-article-file (&optional arg)
11388   "Write the current article to a file, deleting the previous file.
11389 If N is a positive number, save the N next articles.
11390 If N is a negative number, save the N previous articles.
11391 If N is nil and any articles have been marked with the process mark,
11392 save those articles instead."
11393   (interactive "P")
11394   (require 'gnus-art)
11395   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11396     (gnus-summary-save-article arg)))
11397
11398 (defun gnus-summary-save-article-body-file (&optional arg)
11399   "Append the current article body to a file.
11400 If N is a positive number, save the N next articles.
11401 If N is a negative number, save the N previous articles.
11402 If N is nil and any articles have been marked with the process mark,
11403 save those articles instead."
11404   (interactive "P")
11405   (require 'gnus-art)
11406   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11407     (gnus-summary-save-article arg)))
11408
11409 (defun gnus-summary-write-article-body-file (&optional arg)
11410   "Write the current article body to a file, deleting the previous file.
11411 If N is a positive number, save the N next articles.
11412 If N is a negative number, save the N previous articles.
11413 If N is nil and any articles have been marked with the process mark,
11414 save those articles instead."
11415   (interactive "P")
11416   (require 'gnus-art)
11417   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11418     (gnus-summary-save-article arg)))
11419
11420 (defun gnus-summary-muttprint (&optional arg)
11421   "Print the current article using Muttprint.
11422 If N is a positive number, save the N next articles.
11423 If N is a negative number, save the N previous articles.
11424 If N is nil and any articles have been marked with the process mark,
11425 save those articles instead."
11426   (interactive "P")
11427   (require 'gnus-art)
11428   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11429     (gnus-summary-save-article arg t)))
11430
11431 (defun gnus-summary-pipe-message (program)
11432   "Pipe the current article through PROGRAM."
11433   (interactive "sProgram: ")
11434   (gnus-summary-select-article)
11435   (let ((mail-header-separator ""))
11436     (gnus-eval-in-buffer-window gnus-article-buffer
11437       (save-restriction
11438         (widen)
11439         (let ((start (window-start))
11440               buffer-read-only)
11441           (message-pipe-buffer-body program)
11442           (set-window-start (get-buffer-window (current-buffer)) start))))))
11443
11444 (defun gnus-get-split-value (methods)
11445   "Return a value based on the split METHODS."
11446   (let (split-name method result match)
11447     (when methods
11448       (save-excursion
11449         (set-buffer gnus-original-article-buffer)
11450         (save-restriction
11451           (nnheader-narrow-to-headers)
11452           (while (and methods (not split-name))
11453             (goto-char (point-min))
11454             (setq method (pop methods))
11455             (setq match (car method))
11456             (when (cond
11457                    ((stringp match)
11458                     ;; Regular expression.
11459                     (ignore-errors
11460                       (re-search-forward match nil t)))
11461                    ((functionp match)
11462                     ;; Function.
11463                     (save-restriction
11464                       (widen)
11465                       (setq result (funcall match gnus-newsgroup-name))))
11466                    ((consp match)
11467                     ;; Form.
11468                     (save-restriction
11469                       (widen)
11470                       (setq result (eval match)))))
11471               (setq split-name (cdr method))
11472               (cond ((stringp result)
11473                      (push (expand-file-name
11474                             result gnus-article-save-directory)
11475                            split-name))
11476                     ((consp result)
11477                      (setq split-name (append result split-name)))))))))
11478     (nreverse split-name)))
11479
11480 (defun gnus-valid-move-group-p (group)
11481   (and (boundp group)
11482        (symbol-name group)
11483        (symbol-value group)
11484        (gnus-get-function (gnus-find-method-for-group
11485                            (symbol-name group)) 'request-accept-article t)))
11486
11487 (defun gnus-read-move-group-name (prompt default articles prefix)
11488   "Read a group name."
11489   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11490          (minibuffer-confirm-incomplete nil) ; XEmacs
11491          (prom
11492           (format "%s %s to"
11493                   prompt
11494                   (if (> (length articles) 1)
11495                       (format "these %d articles" (length articles))
11496                     "this article")))
11497          (to-newsgroup
11498           (cond
11499            ((null split-name)
11500             (gnus-completing-read-with-default
11501              default prom
11502              gnus-active-hashtb
11503              'gnus-valid-move-group-p
11504              nil prefix
11505              'gnus-group-history))
11506            ((= 1 (length split-name))
11507             (gnus-completing-read-with-default
11508              (car split-name) prom
11509              gnus-active-hashtb
11510              'gnus-valid-move-group-p
11511              nil nil
11512              'gnus-group-history))
11513            (t
11514             (gnus-completing-read-with-default
11515              nil prom
11516              (mapcar 'list (nreverse split-name))
11517              nil nil nil
11518              'gnus-group-history))))
11519          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11520     (when to-newsgroup
11521       (if (or (string= to-newsgroup "")
11522               (string= to-newsgroup prefix))
11523           (setq to-newsgroup default))
11524       (unless to-newsgroup
11525         (error "No group name entered"))
11526       (or (gnus-active to-newsgroup)
11527           (gnus-activate-group to-newsgroup nil nil to-method)
11528           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11529                                      to-newsgroup))
11530               (or (and (gnus-request-create-group to-newsgroup to-method)
11531                        (gnus-activate-group
11532                         to-newsgroup nil nil to-method)
11533                        (gnus-subscribe-group to-newsgroup))
11534                   (error "Couldn't create group %s" to-newsgroup)))
11535           (error "No such group: %s" to-newsgroup)))
11536     to-newsgroup))
11537
11538 (defvar gnus-summary-save-parts-counter)
11539
11540 (defun gnus-summary-save-parts (type dir n &optional reverse)
11541   "Save parts matching TYPE to DIR.
11542 If REVERSE, save parts that do not match TYPE."
11543   (interactive
11544    (list (read-string "Save parts of type: "
11545                       (or (car gnus-summary-save-parts-type-history)
11546                           gnus-summary-save-parts-default-mime)
11547                       'gnus-summary-save-parts-type-history)
11548          (setq gnus-summary-save-parts-last-directory
11549                (read-file-name "Save to directory: "
11550                                gnus-summary-save-parts-last-directory
11551                                nil t))
11552          current-prefix-arg))
11553   (gnus-summary-iterate n
11554     (let ((gnus-display-mime-function nil)
11555           (gnus-inhibit-treatment t))
11556       (gnus-summary-select-article))
11557     (save-excursion
11558       (set-buffer gnus-article-buffer)
11559       (let ((handles (or gnus-article-mime-handles
11560                          (mm-dissect-buffer nil gnus-article-loose-mime)
11561                          (and gnus-article-emulate-mime
11562                               (mm-uu-dissect))))
11563             (gnus-summary-save-parts-counter 1))
11564         (when handles
11565           (gnus-summary-save-parts-1 type dir handles reverse)
11566           (unless gnus-article-mime-handles ;; Don't destroy this case.
11567             (mm-destroy-parts handles)))))))
11568
11569 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11570   (if (stringp (car handle))
11571       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11572               (cdr handle))
11573     (when (if reverse
11574               (not (string-match type (mm-handle-media-type handle)))
11575             (string-match type (mm-handle-media-type handle)))
11576       (let ((file (expand-file-name
11577                    (gnus-map-function
11578                     mm-file-name-rewrite-functions
11579                     (file-name-nondirectory
11580                      (or
11581                       (mail-content-type-get
11582                        (mm-handle-disposition handle) 'filename)
11583                       (mail-content-type-get
11584                        (mm-handle-type handle) 'name)
11585                       (format "%s.%d.%d" gnus-newsgroup-name
11586                               (cdr gnus-article-current)
11587                               gnus-summary-save-parts-counter))))
11588                    dir)))
11589         (incf gnus-summary-save-parts-counter)
11590         (unless (file-exists-p file)
11591           (mm-save-part-to-file handle file))))))
11592
11593 ;; Summary extract commands
11594
11595 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11596   (let ((buffer-read-only nil)
11597         (article (gnus-summary-article-number))
11598         after-article b e)
11599     (unless (gnus-summary-goto-subject article)
11600       (error "No such article: %d" article))
11601     (gnus-summary-position-point)
11602     ;; If all commands are to be bunched up on one line, we collect
11603     ;; them here.
11604     (unless gnus-view-pseudos-separately
11605       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11606             files action)
11607         (while ps
11608           (setq action (cdr (assq 'action (car ps))))
11609           (setq files (list (cdr (assq 'name (car ps)))))
11610           (while (and ps (cdr ps)
11611                       (string= (or action "1")
11612                                (or (cdr (assq 'action (cadr ps))) "2")))
11613             (push (cdr (assq 'name (cadr ps))) files)
11614             (setcdr ps (cddr ps)))
11615           (when files
11616             (when (not (string-match "%s" action))
11617               (push " " files))
11618             (push " " files)
11619             (when (assq 'execute (car ps))
11620               (setcdr (assq 'execute (car ps))
11621                       (funcall (if (string-match "%s" action)
11622                                    'format 'concat)
11623                                action
11624                                (mapconcat
11625                                 (lambda (f)
11626                                   (if (equal f " ")
11627                                       f
11628                                     (shell-quote-argument f)))
11629                                 files " ")))))
11630           (setq ps (cdr ps)))))
11631     (if (and gnus-view-pseudos (not not-view))
11632         (while pslist
11633           (when (assq 'execute (car pslist))
11634             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11635                                   (eq gnus-view-pseudos 'not-confirm)))
11636           (setq pslist (cdr pslist)))
11637       (save-excursion
11638         (while pslist
11639           (setq after-article (or (cdr (assq 'article (car pslist)))
11640                                   (gnus-summary-article-number)))
11641           (gnus-summary-goto-subject after-article)
11642           (forward-line 1)
11643           (setq b (point))
11644           (insert "    " (file-name-nondirectory
11645                           (cdr (assq 'name (car pslist))))
11646                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11647           (setq e (point))
11648           (forward-line -1)             ; back to `b'
11649           (gnus-add-text-properties
11650            b (1- e) (list 'gnus-number gnus-reffed-article-number
11651                           gnus-mouse-face-prop gnus-mouse-face))
11652           (gnus-data-enter
11653            after-article gnus-reffed-article-number
11654            gnus-unread-mark b (car pslist) 0 (- e b))
11655           (setq gnus-newsgroup-unreads
11656                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11657                                          gnus-reffed-article-number))
11658           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11659           (setq pslist (cdr pslist)))))))
11660
11661 (defun gnus-pseudos< (p1 p2)
11662   (let ((c1 (cdr (assq 'action p1)))
11663         (c2 (cdr (assq 'action p2))))
11664     (and c1 c2 (string< c1 c2))))
11665
11666 (defun gnus-request-pseudo-article (props)
11667   (cond ((assq 'execute props)
11668          (gnus-execute-command (cdr (assq 'execute props)))))
11669   (let ((gnus-current-article (gnus-summary-article-number)))
11670     (gnus-run-hooks 'gnus-mark-article-hook)))
11671
11672 (defun gnus-execute-command (command &optional automatic)
11673   (save-excursion
11674     (gnus-article-setup-buffer)
11675     (set-buffer gnus-article-buffer)
11676     (setq buffer-read-only nil)
11677     (let ((command (if automatic command
11678                      (read-string "Command: " (cons command 0)))))
11679       (erase-buffer)
11680       (insert "$ " command "\n\n")
11681       (if gnus-view-pseudo-asynchronously
11682           (start-process "gnus-execute" (current-buffer) shell-file-name
11683                          shell-command-switch command)
11684         (call-process shell-file-name nil t nil
11685                       shell-command-switch command)))))
11686
11687 ;; Summary kill commands.
11688
11689 (defun gnus-summary-edit-global-kill (article)
11690   "Edit the \"global\" kill file."
11691   (interactive (list (gnus-summary-article-number)))
11692   (gnus-group-edit-global-kill article))
11693
11694 (defun gnus-summary-edit-local-kill ()
11695   "Edit a local kill file applied to the current newsgroup."
11696   (interactive)
11697   (setq gnus-current-headers (gnus-summary-article-header))
11698   (gnus-group-edit-local-kill
11699    (gnus-summary-article-number) gnus-newsgroup-name))
11700
11701 ;;; Header reading.
11702
11703 (defun gnus-read-header (id &optional header)
11704   "Read the headers of article ID and enter them into the Gnus system."
11705   (let ((group gnus-newsgroup-name)
11706         (gnus-override-method
11707          (or
11708           gnus-override-method
11709           (and (gnus-news-group-p gnus-newsgroup-name)
11710                (car (gnus-refer-article-methods)))))
11711         where)
11712     ;; First we check to see whether the header in question is already
11713     ;; fetched.
11714     (if (stringp id)
11715         ;; This is a Message-ID.
11716         (setq header (or header (gnus-id-to-header id)))
11717       ;; This is an article number.
11718       (setq header (or header (gnus-summary-article-header id))))
11719     (if (and header
11720              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11721         ;; We have found the header.
11722         header
11723       ;; We have to really fetch the header to this article.
11724       (save-excursion
11725         (set-buffer nntp-server-buffer)
11726         (when (setq where (gnus-request-head id group))
11727           (nnheader-fold-continuation-lines)
11728           (goto-char (point-max))
11729           (insert ".\n")
11730           (goto-char (point-min))
11731           (insert "211 ")
11732           (princ (cond
11733                   ((numberp id) id)
11734                   ((cdr where) (cdr where))
11735                   (header (mail-header-number header))
11736                   (t gnus-reffed-article-number))
11737                  (current-buffer))
11738           (insert " Article retrieved.\n"))
11739         (if (or (not where)
11740                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11741             ()                          ; Malformed head.
11742           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11743             (when (and (stringp id)
11744                        (or
11745                         (not (string= (gnus-group-real-name group)
11746                                       (car where)))
11747                         (not (gnus-server-equal gnus-override-method
11748                                                 (gnus-group-method group)))))
11749               ;; If we fetched by Message-ID and the article came from
11750               ;; a different group (or server), we fudge some bogus
11751               ;; article numbers for this article.
11752               (mail-header-set-number header gnus-reffed-article-number))
11753             (save-excursion
11754               (set-buffer gnus-summary-buffer)
11755               (decf gnus-reffed-article-number)
11756               (gnus-remove-header (mail-header-number header))
11757               (push header gnus-newsgroup-headers)
11758               (setq gnus-current-headers header)
11759               (push (mail-header-number header) gnus-newsgroup-limit)))
11760           header)))))
11761
11762 (defun gnus-remove-header (number)
11763   "Remove header NUMBER from `gnus-newsgroup-headers'."
11764   (if (and gnus-newsgroup-headers
11765            (= number (mail-header-number (car gnus-newsgroup-headers))))
11766       (pop gnus-newsgroup-headers)
11767     (let ((headers gnus-newsgroup-headers))
11768       (while (and (cdr headers)
11769                   (not (= number (mail-header-number (cadr headers)))))
11770         (pop headers))
11771       (when (cdr headers)
11772         (setcdr headers (cddr headers))))))
11773
11774 ;;;
11775 ;;; summary highlights
11776 ;;;
11777
11778 (defun gnus-highlight-selected-summary ()
11779   "Highlight selected article in summary buffer."
11780   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11781   (when gnus-summary-selected-face
11782     (save-excursion
11783       (let* ((beg (point-at-bol))
11784              (end (point-at-eol))
11785              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11786              (from (if (get-text-property beg gnus-mouse-face-prop)
11787                        beg
11788                      (or (next-single-property-change
11789                           beg gnus-mouse-face-prop nil end)
11790                          beg)))
11791              (to
11792               (if (= from end)
11793                   (- from 2)
11794                 (or (next-single-property-change
11795                      from gnus-mouse-face-prop nil end)
11796                     end))))
11797         ;; If no mouse-face prop on line we will have to = from = end,
11798         ;; so we highlight the entire line instead.
11799         (when (= (+ to 2) from)
11800           (setq from beg)
11801           (setq to end))
11802         (if gnus-newsgroup-selected-overlay
11803             ;; Move old overlay.
11804             (gnus-move-overlay
11805              gnus-newsgroup-selected-overlay from to (current-buffer))
11806           ;; Create new overlay.
11807           (gnus-overlay-put
11808            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11809            'face gnus-summary-selected-face))))))
11810
11811 (defvar gnus-summary-highlight-line-cached nil)
11812 (defvar gnus-summary-highlight-line-trigger nil)
11813
11814 (defun gnus-summary-highlight-line-0 ()
11815   (if (and (eq gnus-summary-highlight-line-trigger
11816                gnus-summary-highlight)
11817            gnus-summary-highlight-line-cached)
11818       gnus-summary-highlight-line-cached
11819     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11820           gnus-summary-highlight-line-cached
11821           (let* ((cond (list 'cond))
11822                  (c cond)
11823                  (list gnus-summary-highlight))
11824             (while list
11825               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11826                               nil))
11827               (setq c (cdr c)
11828                     list (cdr list)))
11829             (gnus-byte-compile (list 'lambda nil cond))))))
11830
11831 (defun gnus-summary-highlight-line ()
11832   "Highlight current line according to `gnus-summary-highlight'."
11833   (let* ((beg (point-at-bol))
11834          (article (or (gnus-summary-article-number) gnus-current-article))
11835          (score (or (cdr (assq article
11836                                gnus-newsgroup-scored))
11837                     gnus-summary-default-score 0))
11838          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11839          (inhibit-read-only t)
11840          (default gnus-summary-default-score)
11841          (default-high gnus-summary-default-high-score)
11842          (default-low gnus-summary-default-low-score)
11843          (uncached (and gnus-summary-use-undownloaded-faces
11844                         (memq article gnus-newsgroup-undownloaded)
11845                         (not (memq article gnus-newsgroup-cached)))))
11846     (let ((face (funcall (gnus-summary-highlight-line-0))))
11847       (unless (eq face (get-text-property beg 'face))
11848         (gnus-put-text-property-excluding-characters-with-faces
11849          beg (point-at-eol) 'face
11850          (setq face (if (boundp face) (symbol-value face) face)))
11851         (when gnus-summary-highlight-line-function
11852           (funcall gnus-summary-highlight-line-function article face))))))
11853
11854 (defun gnus-update-read-articles (group unread &optional compute)
11855   "Update the list of read articles in GROUP.
11856 UNREAD is a sorted list."
11857   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11858         (info (gnus-get-info group))
11859         (prev 1)
11860         read)
11861     (if (or (not info) (not active))
11862         ;; There is no info on this group if it was, in fact,
11863         ;; killed.  Gnus stores no information on killed groups, so
11864         ;; there's nothing to be done.
11865         ;; One could store the information somewhere temporarily,
11866         ;; perhaps...  Hmmm...
11867         ()
11868       ;; Remove any negative articles numbers.
11869       (while (and unread (< (car unread) 0))
11870         (setq unread (cdr unread)))
11871       ;; Remove any expired article numbers
11872       (while (and unread (< (car unread) (car active)))
11873         (setq unread (cdr unread)))
11874       ;; Compute the ranges of read articles by looking at the list of
11875       ;; unread articles.
11876       (while unread
11877         (when (/= (car unread) prev)
11878           (push (if (= prev (1- (car unread))) prev
11879                   (cons prev (1- (car unread))))
11880                 read))
11881         (setq prev (1+ (car unread)))
11882         (setq unread (cdr unread)))
11883       (when (<= prev (cdr active))
11884         (push (cons prev (cdr active)) read))
11885       (setq read (if (> (length read) 1) (nreverse read) read))
11886       (if compute
11887           read
11888         (save-excursion
11889           (let (setmarkundo)
11890             ;; Propagate the read marks to the backend.
11891             (when (gnus-check-backend-function 'request-set-mark group)
11892               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11893                     (add (gnus-remove-from-range read (gnus-info-read info))))
11894                 (when (or add del)
11895                   (unless (gnus-check-group group)
11896                     (error "Can't open server for %s" group))
11897                   (gnus-request-set-mark
11898                    group (delq nil (list (if add (list add 'add '(read)))
11899                                          (if del (list del 'del '(read))))))
11900                   (setq setmarkundo
11901                         `(gnus-request-set-mark
11902                           ,group
11903                           ',(delq nil (list
11904                                        (if del (list del 'add '(read)))
11905                                        (if add (list add 'del '(read))))))))))
11906             (set-buffer gnus-group-buffer)
11907             (gnus-undo-register
11908               `(progn
11909                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11910                  (gnus-info-set-read ',info ',(gnus-info-read info))
11911                  (gnus-get-unread-articles-in-group ',info
11912                                                     (gnus-active ,group))
11913                  (gnus-group-update-group ,group t)
11914                  ,setmarkundo))))
11915         ;; Enter this list into the group info.
11916         (gnus-info-set-read info read)
11917         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11918         (gnus-get-unread-articles-in-group info (gnus-active group))
11919         t))))
11920
11921 (defun gnus-offer-save-summaries ()
11922   "Offer to save all active summary buffers."
11923   (let (buffers)
11924     ;; Go through all buffers and find all summaries.
11925     (dolist (buffer (buffer-list))
11926       (when (and (setq buffer (buffer-name buffer))
11927                  (string-match "Summary" buffer)
11928                  (with-current-buffer buffer
11929                    ;; We check that this is, indeed, a summary buffer.
11930                    (and (eq major-mode 'gnus-summary-mode)
11931                         ;; Also make sure this isn't bogus.
11932                         gnus-newsgroup-prepared
11933                         ;; Also make sure that this isn't a
11934                         ;; dead summary buffer.
11935                         (not gnus-dead-summary-mode))))
11936         (push buffer buffers)))
11937     ;; Go through all these summary buffers and offer to save them.
11938     (when buffers
11939       (save-excursion
11940         (map-y-or-n-p
11941          "Update summary buffer %s? "
11942          (lambda (buf)
11943            (switch-to-buffer buf)
11944            (gnus-summary-exit))
11945          buffers)))))
11946
11947 (defun gnus-summary-setup-default-charset ()
11948   "Setup newsgroup default charset."
11949   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11950       (setq gnus-newsgroup-charset nil)
11951     (let* ((ignored-charsets
11952             (or gnus-newsgroup-ephemeral-ignored-charsets
11953                 (append
11954                  (and gnus-newsgroup-name
11955                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11956                  gnus-newsgroup-ignored-charsets))))
11957       (setq gnus-newsgroup-charset
11958             (or gnus-newsgroup-ephemeral-charset
11959                 (and gnus-newsgroup-name
11960                      (gnus-parameter-charset gnus-newsgroup-name))
11961                 gnus-default-charset))
11962       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11963            ignored-charsets))))
11964
11965 ;;;
11966 ;;; Mime Commands
11967 ;;;
11968
11969 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11970   "Display the current article buffer fully MIME-buttonized.
11971 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11972 treated as multipart/mixed."
11973   (interactive "P")
11974   (require 'gnus-art)
11975   (let ((gnus-unbuttonized-mime-types nil)
11976         (gnus-mime-display-multipart-as-mixed show-all-parts))
11977     (gnus-summary-show-article)))
11978
11979 (defun gnus-summary-repair-multipart (article)
11980   "Add a Content-Type header to a multipart article without one."
11981   (interactive (list (gnus-summary-article-number)))
11982   (gnus-with-article article
11983     (message-narrow-to-head)
11984     (message-remove-header "Mime-Version")
11985     (goto-char (point-max))
11986     (insert "Mime-Version: 1.0\n")
11987     (widen)
11988     (when (search-forward "\n--" nil t)
11989       (let ((separator (buffer-substring (point) (point-at-eol))))
11990         (message-narrow-to-head)
11991         (message-remove-header "Content-Type")
11992         (goto-char (point-max))
11993         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11994                         separator))
11995         (widen))))
11996   (let (gnus-mark-article-hook)
11997     (gnus-summary-select-article t t nil article)))
11998
11999 (defun gnus-summary-toggle-display-buttonized ()
12000   "Toggle the buttonizing of the article buffer."
12001   (interactive)
12002   (require 'gnus-art)
12003   (if (setq gnus-inhibit-mime-unbuttonizing
12004             (not gnus-inhibit-mime-unbuttonizing))
12005       (let ((gnus-unbuttonized-mime-types nil))
12006         (gnus-summary-show-article))
12007     (gnus-summary-show-article)))
12008
12009 ;;;
12010 ;;; Generic summary marking commands
12011 ;;;
12012
12013 (defvar gnus-summary-marking-alist
12014   '((read gnus-del-mark "d")
12015     (unread gnus-unread-mark "u")
12016     (ticked gnus-ticked-mark "!")
12017     (dormant gnus-dormant-mark "?")
12018     (expirable gnus-expirable-mark "e"))
12019   "An alist of names/marks/keystrokes.")
12020
12021 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12022 (defvar gnus-summary-mark-map)
12023
12024 (defun gnus-summary-make-all-marking-commands ()
12025   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12026   (dolist (elem gnus-summary-marking-alist)
12027     (apply 'gnus-summary-make-marking-command elem)))
12028
12029 (defun gnus-summary-make-marking-command (name mark keystroke)
12030   (let ((map (make-sparse-keymap)))
12031     (define-key gnus-summary-generic-mark-map keystroke map)
12032     (dolist (lway `((next "next" next nil "n")
12033                     (next-unread "next unread" next t "N")
12034                     (prev "previous" prev nil "p")
12035                     (prev-unread "previous unread" prev t "P")
12036                     (nomove "" nil nil ,keystroke)))
12037       (let ((func (gnus-summary-make-marking-command-1
12038                    mark (car lway) lway name)))
12039         (setq func (eval func))
12040         (define-key map (nth 4 lway) func)))))
12041
12042 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12043   `(defun ,(intern
12044             (format "gnus-summary-put-mark-as-%s%s"
12045                     name (if (eq way 'nomove)
12046                              ""
12047                            (concat "-" (symbol-name way)))))
12048      (n)
12049      ,(format
12050        "Mark the current article as %s%s.
12051 If N, the prefix, then repeat N times.
12052 If N is negative, move in reverse order.
12053 The difference between N and the actual number of articles marked is
12054 returned."
12055        name (cadr lway))
12056      (interactive "p")
12057      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12058
12059 (defun gnus-summary-generic-mark (n mark move unread)
12060   "Mark N articles with MARK."
12061   (unless (eq major-mode 'gnus-summary-mode)
12062     (error "This command can only be used in the summary buffer"))
12063   (gnus-summary-show-thread)
12064   (let ((nummove
12065          (cond
12066           ((eq move 'next) 1)
12067           ((eq move 'prev) -1)
12068           (t 0))))
12069     (if (zerop nummove)
12070         (setq n 1)
12071       (when (< n 0)
12072         (setq n (abs n)
12073               nummove (* -1 nummove))))
12074     (while (and (> n 0)
12075                 (gnus-summary-mark-article nil mark)
12076                 (zerop (gnus-summary-next-subject nummove unread t)))
12077       (setq n (1- n)))
12078     (when (/= 0 n)
12079       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12080     (gnus-summary-recenter)
12081     (gnus-summary-position-point)
12082     (gnus-set-mode-line 'summary)
12083     n))
12084
12085 (defun gnus-summary-insert-articles (articles)
12086   (when (setq articles
12087               (gnus-sorted-difference articles
12088                                       (mapcar (lambda (h)
12089                                                 (mail-header-number h))
12090                                               gnus-newsgroup-headers)))
12091     (setq gnus-newsgroup-headers
12092           (gnus-merge 'list
12093                       gnus-newsgroup-headers
12094                       (gnus-fetch-headers articles)
12095                       'gnus-article-sort-by-number))
12096     ;; Suppress duplicates?
12097     (when gnus-suppress-duplicates
12098       (gnus-dup-suppress-articles))
12099
12100     ;; We might want to build some more threads first.
12101     (when (and gnus-fetch-old-headers
12102                (eq gnus-headers-retrieved-by 'nov))
12103       (if (eq gnus-fetch-old-headers 'invisible)
12104           (gnus-build-all-threads)
12105         (gnus-build-old-threads)))
12106     ;; Let the Gnus agent mark articles as read.
12107     (when gnus-agent
12108       (gnus-agent-get-undownloaded-list))
12109     ;; Remove list identifiers from subject
12110     (when gnus-list-identifiers
12111       (gnus-summary-remove-list-identifiers))
12112     ;; First and last article in this newsgroup.
12113     (when gnus-newsgroup-headers
12114       (setq gnus-newsgroup-begin
12115             (mail-header-number (car gnus-newsgroup-headers))
12116             gnus-newsgroup-end
12117             (mail-header-number
12118              (gnus-last-element gnus-newsgroup-headers))))
12119     (when gnus-use-scoring
12120       (gnus-possibly-score-headers))))
12121
12122 (defun gnus-summary-insert-old-articles (&optional all)
12123   "Insert all old articles in this group.
12124 If ALL is non-nil, already read articles become readable.
12125 If ALL is a number, fetch this number of articles."
12126   (interactive "P")
12127   (prog1
12128       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12129             older len)
12130         (setq older
12131               ;; Some nntp servers lie about their active range.  When
12132               ;; this happens, the active range can be in the millions.
12133               ;; Use a compressed range to avoid creating a huge list.
12134               (gnus-range-difference (list gnus-newsgroup-active) old))
12135         (setq len (gnus-range-length older))
12136         (cond
12137          ((null older) nil)
12138          ((numberp all)
12139           (if (< all len)
12140               (let ((older-range (nreverse older)))
12141                 (setq older nil)
12142
12143                 (while (> all 0)
12144                   (let* ((r (pop older-range))
12145                          (min (if (numberp r) r (car r)))
12146                          (max (if (numberp r) r (cdr r))))
12147                     (while (and (<= min max)
12148                                 (> all 0))
12149                       (push max older)
12150                       (setq all (1- all)
12151                             max (1- max))))))
12152             (setq older (gnus-uncompress-range older))))
12153          (all
12154           (setq older (gnus-uncompress-range older)))
12155          (t
12156           (when (and (numberp gnus-large-newsgroup)
12157                    (> len gnus-large-newsgroup))
12158               (let* ((cursor-in-echo-area nil)
12159                      (initial (gnus-parameter-large-newsgroup-initial
12160                                gnus-newsgroup-name))
12161                      (input
12162                       (read-string
12163                        (format
12164                         "How many articles from %s (%s %d): "
12165                         (gnus-limit-string
12166                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12167                         (if initial "max" "default")
12168                         len)
12169                        (if initial
12170                            (cons (number-to-string initial)
12171                                  0)))))
12172                 (unless (string-match "^[ \t]*$" input)
12173                   (setq all (string-to-number input))
12174                   (if (< all len)
12175                       (let ((older-range (nreverse older)))
12176                         (setq older nil)
12177
12178                         (while (> all 0)
12179                           (let* ((r (pop older-range))
12180                                  (min (if (numberp r) r (car r)))
12181                                  (max (if (numberp r) r (cdr r))))
12182                             (while (and (<= min max)
12183                                         (> all 0))
12184                               (push max older)
12185                               (setq all (1- all)
12186                                     max (1- max))))))))))
12187           (setq older (gnus-uncompress-range older))))
12188         (if (not older)
12189             (message "No old news.")
12190           (gnus-summary-insert-articles older)
12191           (gnus-summary-limit (gnus-sorted-nunion old older))))
12192     (gnus-summary-position-point)))
12193
12194 (defun gnus-summary-insert-new-articles ()
12195   "Insert all new articles in this group."
12196   (interactive)
12197   (prog1
12198       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12199             (old-active gnus-newsgroup-active)
12200             (nnmail-fetched-sources (list t))
12201             i new)
12202         (setq gnus-newsgroup-active
12203               (gnus-activate-group gnus-newsgroup-name 'scan))
12204         (setq i (cdr gnus-newsgroup-active))
12205         (while (> i (cdr old-active))
12206           (push i new)
12207           (decf i))
12208         (if (not new)
12209             (message "No gnus is bad news")
12210           (gnus-summary-insert-articles new)
12211           (setq gnus-newsgroup-unreads
12212                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12213           (gnus-summary-limit (gnus-sorted-nunion old new))))
12214     (gnus-summary-position-point)))
12215
12216 (gnus-summary-make-all-marking-commands)
12217
12218 (gnus-ems-redefine)
12219
12220 (provide 'gnus-sum)
12221
12222 (run-hooks 'gnus-sum-load-hook)
12223
12224 ;; Local Variables:
12225 ;; coding: iso-8859-1
12226 ;; End:
12227
12228 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12229 ;;; gnus-sum.el ends here