Revision: miles@gnu.org--gnu-2004/gnus--devo--0--patch-182
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is t, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const :tag "on" t)
79                  (const some)
80                  (const invisible)
81                  number
82                  (sexp :menu-tag "other" t)))
83
84 (defcustom gnus-refer-thread-limit 200
85   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
86 If t, fetch all the available old headers."
87   :group 'gnus-thread
88   :type '(choice number
89                  (sexp :menu-tag "other" t)))
90
91 (defcustom gnus-summary-make-false-root 'adopt
92   "*nil means that Gnus won't gather loose threads.
93 If the root of a thread has expired or been read in a previous
94 session, the information necessary to build a complete thread has been
95 lost.  Instead of having many small sub-threads from this original thread
96 scattered all over the summary buffer, Gnus can gather them.
97
98 If non-nil, Gnus will try to gather all loose sub-threads from an
99 original thread into one large thread.
100
101 If this variable is non-nil, it should be one of `none', `adopt',
102 `dummy' or `empty'.
103
104 If this variable is `none', Gnus will not make a false root, but just
105 present the sub-threads after another.
106 If this variable is `dummy', Gnus will create a dummy root that will
107 have all the sub-threads as children.
108 If this variable is `adopt', Gnus will make one of the \"children\"
109 the parent and mark all the step-children as such.
110 If this variable is `empty', the \"children\" are printed with empty
111 subject fields.  (Or rather, they will be printed with a string
112 given by the `gnus-summary-same-subject' variable.)"
113   :group 'gnus-thread
114   :type '(choice (const :tag "off" nil)
115                  (const none)
116                  (const dummy)
117                  (const adopt)
118                  (const empty)))
119
120 (defcustom gnus-summary-make-false-root-always nil
121   "Always make a false dummy root."
122   :version "21.4"
123   :group 'gnus-thread
124   :type 'boolean)
125
126 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
127   "*A regexp to match subjects to be excluded from loose thread gathering.
128 As loose thread gathering is done on subjects only, that means that
129 there can be many false gatherings performed.  By rooting out certain
130 common subjects, gathering might become saner."
131   :group 'gnus-thread
132   :type 'regexp)
133
134 (defcustom gnus-summary-gather-subject-limit nil
135   "*Maximum length of subject comparisons when gathering loose threads.
136 Use nil to compare full subjects.  Setting this variable to a low
137 number will help gather threads that have been corrupted by
138 newsreaders chopping off subject lines, but it might also mean that
139 unrelated articles that have subject that happen to begin with the
140 same few characters will be incorrectly gathered.
141
142 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
143 comparing subjects."
144   :group 'gnus-thread
145   :type '(choice (const :tag "off" nil)
146                  (const fuzzy)
147                  (sexp :menu-tag "on" t)))
148
149 (defcustom gnus-simplify-subject-functions nil
150   "List of functions taking a string argument that simplify subjects.
151 The functions are applied recursively.
152
153 Useful functions to put in this list include:
154 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
155 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
156   :group 'gnus-thread
157   :type '(repeat function))
158
159 (defcustom gnus-simplify-ignored-prefixes nil
160   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
161   :group 'gnus-thread
162   :type '(choice (const :tag "off" nil)
163                  regexp))
164
165 (defcustom gnus-build-sparse-threads nil
166   "*If non-nil, fill in the gaps in threads.
167 If `some', only fill in the gaps that are needed to tie loose threads
168 together.  If `more', fill in all leaf nodes that Gnus can find.  If
169 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  (const some)
173                  (const more)
174                  (sexp :menu-tag "all" t)))
175
176 (defcustom gnus-summary-thread-gathering-function
177   'gnus-gather-threads-by-subject
178   "*Function used for gathering loose threads.
179 There are two pre-defined functions: `gnus-gather-threads-by-subject',
180 which only takes Subjects into consideration; and
181 `gnus-gather-threads-by-references', which compared the References
182 headers of the articles to find matches."
183   :group 'gnus-thread
184   :type '(radio (function-item gnus-gather-threads-by-subject)
185                 (function-item gnus-gather-threads-by-references)
186                 (function :tag "other")))
187
188 (defcustom gnus-summary-same-subject ""
189   "*String indicating that the current article has the same subject as the previous.
190 This variable will only be used if the value of
191 `gnus-summary-make-false-root' is `empty'."
192   :group 'gnus-summary-format
193   :type 'string)
194
195 (defcustom gnus-summary-goto-unread t
196   "*If t, many commands will go to the next unread article.
197 This applies to marking commands as well as other commands that
198 \"naturally\" select the next article, like, for instance, `SPC' at
199 the end of an article.
200
201 If nil, the marking commands do NOT go to the next unread article
202 \(they go to the next article instead).  If `never', commands that
203 usually go to the next unread article, will go to the next article,
204 whether it is read or not."
205   :group 'gnus-summary-marks
206   :link '(custom-manual "(gnus)Setting Marks")
207   :type '(choice (const :tag "off" nil)
208                  (const never)
209                  (sexp :menu-tag "on" t)))
210
211 (defcustom gnus-summary-default-score 0
212   "*Default article score level.
213 All scores generated by the score files will be added to this score.
214 If this variable is nil, scoring will be disabled."
215   :group 'gnus-score-default
216   :type '(choice (const :tag "disable")
217                  integer))
218
219 (defcustom gnus-summary-default-high-score 0
220   "*Default threshold for a high scored article.
221 An article will be highlighted as high scored if its score is greater
222 than this score."
223   :version "21.4"
224   :group 'gnus-score-default
225   :type 'integer)
226
227 (defcustom gnus-summary-default-low-score 0
228   "*Default threshold for a low scored article.
229 An article will be highlighted as low scored if its score is smaller
230 than this score."
231   :version "21.4"
232   :group 'gnus-score-default
233   :type 'integer)
234
235 (defcustom gnus-summary-zcore-fuzz 0
236   "*Fuzziness factor for the zcore in the summary buffer.
237 Articles with scores closer than this to `gnus-summary-default-score'
238 will not be marked."
239   :group 'gnus-summary-format
240   :type 'integer)
241
242 (defcustom gnus-simplify-subject-fuzzy-regexp nil
243   "*Strings to be removed when doing fuzzy matches.
244 This can either be a regular expression or list of regular expressions
245 that will be removed from subject strings if fuzzy subject
246 simplification is selected."
247   :group 'gnus-thread
248   :type '(repeat regexp))
249
250 (defcustom gnus-show-threads t
251   "*If non-nil, display threads in summary mode."
252   :group 'gnus-thread
253   :type 'boolean)
254
255 (defcustom gnus-thread-hide-subtree nil
256   "*If non-nil, hide all threads initially.
257 This can be a predicate specifier which says which threads to hide.
258 If threads are hidden, you have to run the command
259 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
260 to expose hidden threads."
261   :group 'gnus-thread
262   :type '(radio (sexp :format "Non-nil\n"
263                       :match (lambda (widget value)
264                                (not (or (consp value) (functionp value))))
265                       :value t)
266                 (const nil)
267                 (sexp :tag "Predicate specifier")))
268
269 (defcustom gnus-thread-hide-killed t
270   "*If non-nil, hide killed threads automatically."
271   :group 'gnus-thread
272   :type 'boolean)
273
274 (defcustom gnus-thread-ignore-subject t
275   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
276 If nil, articles that have different subjects from their parents will
277 start separate threads."
278   :group 'gnus-thread
279   :type 'boolean)
280
281 (defcustom gnus-thread-operation-ignore-subject t
282   "*If non-nil, subjects will be ignored when doing thread commands.
283 This affects commands like `gnus-summary-kill-thread' and
284 `gnus-summary-lower-thread'.
285
286 If this variable is nil, articles in the same thread with different
287 subjects will not be included in the operation in question.  If this
288 variable is `fuzzy', only articles that have subjects that are fuzzily
289 equal will be included."
290   :group 'gnus-thread
291   :type '(choice (const :tag "off" nil)
292                  (const fuzzy)
293                  (sexp :tag "on" t)))
294
295 (defcustom gnus-thread-indent-level 4
296   "*Number that says how much each sub-thread should be indented."
297   :group 'gnus-thread
298   :type 'integer)
299
300 (defcustom gnus-auto-extend-newsgroup t
301   "*If non-nil, extend newsgroup forward and backward when requested."
302   :group 'gnus-summary-choose
303   :type 'boolean)
304
305 (defcustom gnus-auto-select-first t
306   "*If non-nil, select the article under point.
307 Which article this is is controlled by the `gnus-auto-select-subject'
308 variable.
309
310 If you want to prevent automatic selection of articles in some
311 newsgroups, set the variable to nil in `gnus-select-group-hook'."
312   :group 'gnus-group-select
313   :type '(choice (const :tag "none" nil)
314                  (sexp :menu-tag "first" t)))
315
316 (defcustom gnus-auto-select-subject 'unread
317   "*Says what subject to place under point when entering a group.
318
319 This variable can either be the symbols `first' (place point on the
320 first subject), `unread' (place point on the subject line of the first
321 unread article), `best' (place point on the subject line of the
322 higest-scored article), `unseen' (place point on the subject line of
323 the first unseen article), 'unseen-or-unread' (place point on the subject
324 line of the first unseen article or, if all article have been seen, on the
325 subject line of the first unread article), or a function to be called to
326 place point on some subject line."
327   :version "21.4"
328   :group 'gnus-group-select
329   :type '(choice (const best)
330                  (const unread)
331                  (const first)
332                  (const unseen)
333                  (const unseen-or-unread)))
334
335 (defcustom gnus-auto-select-next t
336   "*If non-nil, offer to go to the next group from the end of the previous.
337 If the value is t and the next newsgroup is empty, Gnus will exit
338 summary mode and go back to group mode.  If the value is neither nil
339 nor t, Gnus will select the following unread newsgroup.  In
340 particular, if the value is the symbol `quietly', the next unread
341 newsgroup will be selected without any confirmation, and if it is
342 `almost-quietly', the next group will be selected without any
343 confirmation if you are located on the last article in the group.
344 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
345 will go to the next group without confirmation."
346   :group 'gnus-summary-maneuvering
347   :type '(choice (const :tag "off" nil)
348                  (const quietly)
349                  (const almost-quietly)
350                  (const slightly-quietly)
351                  (sexp :menu-tag "on" t)))
352
353 (defcustom gnus-auto-select-same nil
354   "*If non-nil, select the next article with the same subject.
355 If there are no more articles with the same subject, go to
356 the first unread article."
357   :group 'gnus-summary-maneuvering
358   :type 'boolean)
359
360 (defcustom gnus-auto-goto-ignores 'unfetched
361   "*Says how to handle unfetched articles when maneuvering.
362
363 This variable can either be the symbols nil (maneuver to any
364 article), `undownloaded' (maneuvering while unplugged ignores articles
365 that have not been fetched), `always-undownloaded' (maneuvering always
366 ignores articles that have not been fetched), `unfetched' (maneuvering
367 ignores articles whose headers have not been fetched).
368
369 NOTE: The list of unfetched articles will always be nil when plugged
370 and, when unplugged, a subset of the undownloaded article list."
371   :version "21.4"
372   :group 'gnus-summary-maneuvering
373   :type '(choice (const :tag "None" nil)
374                  (const :tag "Undownloaded when unplugged" undownloaded)
375                  (const :tag "Undownloaded" always-undownloaded)
376                  (const :tag "Unfetched" unfetched)))
377
378 (defcustom gnus-summary-check-current nil
379   "*If non-nil, consider the current article when moving.
380 The \"unread\" movement commands will stay on the same line if the
381 current article is unread."
382   :group 'gnus-summary-maneuvering
383   :type 'boolean)
384
385 (defcustom gnus-auto-center-summary 2
386   "*If non-nil, always center the current summary buffer.
387 In particular, if `vertical' do only vertical recentering.  If non-nil
388 and non-`vertical', do both horizontal and vertical recentering."
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "none" nil)
391                  (const vertical)
392                  (integer :tag "height")
393                  (sexp :menu-tag "both" t)))
394
395 (defvar gnus-auto-center-group t
396   "*If non-nil, always center the group buffer.")
397
398 (defcustom gnus-show-all-headers nil
399   "*If non-nil, don't hide any headers."
400   :group 'gnus-article-hiding
401   :group 'gnus-article-headers
402   :type 'boolean)
403
404 (defcustom gnus-summary-ignore-duplicates nil
405   "*If non-nil, ignore articles with identical Message-ID headers."
406   :group 'gnus-summary
407   :type 'boolean)
408
409 (defcustom gnus-single-article-buffer t
410   "*If non-nil, display all articles in the same buffer.
411 If nil, each group will get its own article buffer."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-break-pages t
416   "*If non-nil, do page breaking on articles.
417 The page delimiter is specified by the `gnus-page-delimiter'
418 variable."
419   :group 'gnus-article-various
420   :type 'boolean)
421
422 (defcustom gnus-move-split-methods nil
423   "*Variable used to suggest where articles are to be moved to.
424 It uses the same syntax as the `gnus-split-methods' variable.
425 However, whereas `gnus-split-methods' specifies file names as targets,
426 this variable specifies group names."
427   :group 'gnus-summary-mail
428   :type '(repeat (choice (list :value (fun) function)
429                          (cons :value ("" "") regexp (repeat string))
430                          (sexp :value nil))))
431
432 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
433   "Function used to compute default prefix for article move/copy/etc prompts.
434 The function should take one argument, a group name, and return a
435 string with the suggested prefix."
436   :group 'gnus-summary-mail
437   :type 'function)
438
439 ;; FIXME: Although the custom type is `character' for the following variables,
440 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
441
442 (defcustom gnus-unread-mark ?           ;Whitespace
443   "*Mark used for unread articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-ticked-mark ?!
448   "*Mark used for ticked articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-dormant-mark ??
453   "*Mark used for dormant articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-del-mark ?r
458   "*Mark used for del'd articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-read-mark ?R
463   "*Mark used for read articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-expirable-mark ?E
468   "*Mark used for expirable articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-killed-mark ?K
473   "*Mark used for killed articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-spam-mark ?$
478   "*Mark used for spam articles."
479   :version "21.4"
480   :group 'gnus-summary-marks
481   :type 'character)
482
483 (defcustom gnus-souped-mark ?F
484   "*Mark used for souped articles."
485   :group 'gnus-summary-marks
486   :type 'character)
487
488 (defcustom gnus-kill-file-mark ?X
489   "*Mark used for articles killed by kill files."
490   :group 'gnus-summary-marks
491   :type 'character)
492
493 (defcustom gnus-low-score-mark ?Y
494   "*Mark used for articles with a low score."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-catchup-mark ?C
499   "*Mark used for articles that are caught up."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-replied-mark ?A
504   "*Mark used for articles that have been replied to."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-forwarded-mark ?F
509   "*Mark used for articles that have been forwarded."
510   :version "21.4"
511   :group 'gnus-summary-marks
512   :type 'character)
513
514 (defcustom gnus-recent-mark ?N
515   "*Mark used for articles that are recent."
516   :version "21.4"
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-cached-mark ?*
521   "*Mark used for articles that are in the cache."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-saved-mark ?S
526   "*Mark used for articles that have been saved."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-unseen-mark ?.
531   "*Mark used for articles that haven't been seen."
532   :version "21.4"
533   :group 'gnus-summary-marks
534   :type 'character)
535
536 (defcustom gnus-no-mark ?               ;Whitespace
537   "*Mark used for articles that have no other secondary mark."
538   :version "21.4"
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-ancient-mark ?O
543   "*Mark used for ancient articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-sparse-mark ?Q
548   "*Mark used for sparsely reffed articles."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-canceled-mark ?G
553   "*Mark used for canceled articles."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-duplicate-mark ?M
558   "*Mark used for duplicate articles."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-undownloaded-mark ?-
563   "*Mark used for articles that weren't downloaded."
564   :version "21.4"
565   :group 'gnus-summary-marks
566   :type 'character)
567
568 (defcustom gnus-downloaded-mark ?+
569   "*Mark used for articles that were downloaded."
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-downloadable-mark ?%
574   "*Mark used for articles that are to be downloaded."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-unsendable-mark ?=
579   "*Mark used for articles that won't be sent."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-score-over-mark ?+
584   "*Score mark used for articles with high scores."
585   :group 'gnus-summary-marks
586   :type 'character)
587
588 (defcustom gnus-score-below-mark ?-
589   "*Score mark used for articles with low scores."
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-empty-thread-mark ?     ;Whitespace
594   "*There is no thread under the article."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-not-empty-thread-mark ?=
599   "*There is a thread under the article."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-view-pseudo-asynchronously nil
604   "*If non-nil, Gnus will view pseudo-articles asynchronously."
605   :group 'gnus-extract-view
606   :type 'boolean)
607
608 (defcustom gnus-auto-expirable-marks
609   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
610         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
611         gnus-souped-mark gnus-duplicate-mark)
612   "*The list of marks converted into expiration if a group is auto-expirable."
613   :version "21.1"
614   :group 'gnus-summary
615   :type '(repeat character))
616
617 (defcustom gnus-inhibit-user-auto-expire t
618   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
619   :version "21.1"
620   :group 'gnus-summary
621   :type 'boolean)
622
623 (defcustom gnus-view-pseudos nil
624   "*If `automatic', pseudo-articles will be viewed automatically.
625 If `not-confirm', pseudos will be viewed automatically, and the user
626 will not be asked to confirm the command."
627   :group 'gnus-extract-view
628   :type '(choice (const :tag "off" nil)
629                  (const automatic)
630                  (const not-confirm)))
631
632 (defcustom gnus-view-pseudos-separately t
633   "*If non-nil, one pseudo-article will be created for each file to be viewed.
634 If nil, all files that use the same viewing command will be given as a
635 list of parameters to that command."
636   :group 'gnus-extract-view
637   :type 'boolean)
638
639 (defcustom gnus-insert-pseudo-articles t
640   "*If non-nil, insert pseudo-articles when decoding articles."
641   :group 'gnus-extract-view
642   :type 'boolean)
643
644 (defcustom gnus-summary-dummy-line-format
645   "   %(:                             :%) %S\n"
646   "*The format specification for the dummy roots in the summary buffer.
647 It works along the same lines as a normal formatting string,
648 with some simple extensions.
649
650 %S  The subject
651
652 General format specifiers can also be used.
653 See `(gnus)Formatting Variables'."
654   :link '(custom-manual "(gnus)Formatting Variables")
655   :group 'gnus-threading
656   :type 'string)
657
658 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
659   "*The format specification for the summary mode line.
660 It works along the same lines as a normal formatting string,
661 with some simple extensions:
662
663 %G  Group name
664 %p  Unprefixed group name
665 %A  Current article number
666 %z  Current article score
667 %V  Gnus version
668 %U  Number of unread articles in the group
669 %e  Number of unselected articles in the group
670 %Z  A string with unread/unselected article counts
671 %g  Shortish group name
672 %S  Subject of the current article
673 %u  User-defined spec
674 %s  Current score file name
675 %d  Number of dormant articles
676 %r  Number of articles that have been marked as read in this session
677 %E  Number of articles expunged by the score files"
678   :group 'gnus-summary-format
679   :type 'string)
680
681 (defcustom gnus-list-identifiers nil
682   "Regexp that matches list identifiers to be removed from subject.
683 This can also be a list of regexps."
684   :version "21.1"
685   :group 'gnus-summary-format
686   :group 'gnus-article-hiding
687   :type '(choice (const :tag "none" nil)
688                  (regexp :value ".*")
689                  (repeat :value (".*") regexp)))
690
691 (defcustom gnus-summary-mark-below 0
692   "*Mark all articles with a score below this variable as read.
693 This variable is local to each summary buffer and usually set by the
694 score file."
695   :group 'gnus-score-default
696   :type 'integer)
697
698 (defun gnus-widget-reversible-match (widget value)
699   "Ignoring WIDGET, convert VALUE to internal form.
700 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
701   ;; (debug value)
702   (or (symbolp value)
703       (and (listp value)
704            (eq (length value) 2)
705            (eq (nth 0 value) 'not)
706            (symbolp (nth 1 value)))))
707
708 (defun gnus-widget-reversible-to-internal (widget value)
709   "Ignoring WIDGET, convert VALUE to internal form.
710 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
711 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
712   ;; (debug value)
713   (if (atom value)
714       (list value nil)
715     (list (nth 1 value) t)))
716
717 (defun gnus-widget-reversible-to-external (widget value)
718   "Ignoring WIDGET, convert VALUE to external form.
719 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
720 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
721   ;; (debug value)
722   (if (nth 1 value)
723       (list 'not (nth 0 value))
724     (nth 0 value)))
725
726 (define-widget 'gnus-widget-reversible 'group
727   "A `group' that convert values."
728   :match 'gnus-widget-reversible-match
729   :value-to-internal 'gnus-widget-reversible-to-internal
730   :value-to-external 'gnus-widget-reversible-to-external)
731
732 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
733   "*List of functions used for sorting articles in the summary buffer.
734
735 Each function takes two articles and returns non-nil if the first
736 article should be sorted before the other.  If you use more than one
737 function, the primary sort function should be the last.  You should
738 probably always include `gnus-article-sort-by-number' in the list of
739 sorting functions -- preferably first.  Also note that sorting by date
740 is often much slower than sorting by number, and the sorting order is
741 very similar.  (Sorting by date means sorting by the time the message
742 was sent, sorting by number means sorting by arrival time.)
743
744 Each item can also be a list `(not F)' where F is a function;
745 this reverses the sort order.
746
747 Ready-made functions include `gnus-article-sort-by-number',
748 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
749 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
750 and `gnus-article-sort-by-score'.
751
752 When threading is turned on, the variable `gnus-thread-sort-functions'
753 controls how articles are sorted."
754   :group 'gnus-summary-sort
755   :type '(repeat (gnus-widget-reversible
756                   (choice (function-item gnus-article-sort-by-number)
757                           (function-item gnus-article-sort-by-author)
758                           (function-item gnus-article-sort-by-subject)
759                           (function-item gnus-article-sort-by-date)
760                           (function-item gnus-article-sort-by-score)
761                           (function-item gnus-article-sort-by-random)
762                           (function :tag "other"))
763                   (boolean :tag "Reverse order"))))
764
765
766 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
767   "*List of functions used for sorting threads in the summary buffer.
768 By default, threads are sorted by article number.
769
770 Each function takes two threads and returns non-nil if the first
771 thread should be sorted before the other.  If you use more than one
772 function, the primary sort function should be the last.  You should
773 probably always include `gnus-thread-sort-by-number' in the list of
774 sorting functions -- preferably first.  Also note that sorting by date
775 is often much slower than sorting by number, and the sorting order is
776 very similar.  (Sorting by date means sorting by the time the message
777 was sent, sorting by number means sorting by arrival time.)
778
779 Each list item can also be a list `(not F)' where F is a
780 function; this specifies reversed sort order.
781
782 Ready-made functions include `gnus-thread-sort-by-number',
783 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
784 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
785 `gnus-thread-sort-by-most-recent-number',
786 `gnus-thread-sort-by-most-recent-date',
787 `gnus-thread-sort-by-random', and
788 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
789
790 When threading is turned off, the variable
791 `gnus-article-sort-functions' controls how articles are sorted."
792   :group 'gnus-summary-sort
793   :type '(repeat 
794           (gnus-widget-reversible
795            (choice (function-item gnus-thread-sort-by-number)
796                    (function-item gnus-thread-sort-by-author)
797                    (function-item gnus-thread-sort-by-subject)
798                    (function-item gnus-thread-sort-by-date)
799                    (function-item gnus-thread-sort-by-score)
800                    (function-item gnus-thread-sort-by-most-recent-number)
801                    (function-item gnus-thread-sort-by-most-recent-date)
802                    (function-item gnus-thread-sort-by-random)
803                    (function-item gnus-thread-sort-by-total-score)
804                    (function :tag "other"))
805            (boolean :tag "Reverse order"))))
806
807 (defcustom gnus-thread-score-function '+
808   "*Function used for calculating the total score of a thread.
809
810 The function is called with the scores of the article and each
811 subthread and should then return the score of the thread.
812
813 Some functions you can use are `+', `max', or `min'."
814   :group 'gnus-summary-sort
815   :type 'function)
816
817 (defcustom gnus-summary-expunge-below nil
818   "All articles that have a score less than this variable will be expunged.
819 This variable is local to the summary buffers."
820   :group 'gnus-score-default
821   :type '(choice (const :tag "off" nil)
822                  integer))
823
824 (defcustom gnus-thread-expunge-below nil
825   "All threads that have a total score less than this variable will be expunged.
826 See `gnus-thread-score-function' for en explanation of what a
827 \"thread score\" is.
828
829 This variable is local to the summary buffers."
830   :group 'gnus-threading
831   :group 'gnus-score-default
832   :type '(choice (const :tag "off" nil)
833                  integer))
834
835 (defcustom gnus-summary-mode-hook nil
836   "*A hook for Gnus summary mode.
837 This hook is run before any variables are set in the summary buffer."
838   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
839   :group 'gnus-summary-various
840   :type 'hook)
841
842 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
843 (when (featurep 'xemacs)
844   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
845   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
846   (add-hook 'gnus-summary-mode-hook
847             'gnus-xmas-switch-horizontal-scrollbar-off))
848
849 (defcustom gnus-summary-menu-hook nil
850   "*Hook run after the creation of the summary mode menu."
851   :group 'gnus-summary-visual
852   :type 'hook)
853
854 (defcustom gnus-summary-exit-hook nil
855   "*A hook called on exit from the summary buffer.
856 It will be called with point in the group buffer."
857   :group 'gnus-summary-exit
858   :type 'hook)
859
860 (defcustom gnus-summary-prepare-hook nil
861   "*A hook called after the summary buffer has been generated.
862 If you want to modify the summary buffer, you can use this hook."
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 (defcustom gnus-summary-prepared-hook nil
867   "*A hook called as the last thing after the summary buffer has been generated."
868   :group 'gnus-summary-various
869   :type 'hook)
870
871 (defcustom gnus-summary-generate-hook nil
872   "*A hook run just before generating the summary buffer.
873 This hook is commonly used to customize threading variables and the
874 like."
875   :group 'gnus-summary-various
876   :type 'hook)
877
878 (defcustom gnus-select-group-hook nil
879   "*A hook called when a newsgroup is selected.
880
881 If you'd like to simplify subjects like the
882 `gnus-summary-next-same-subject' command does, you can use the
883 following hook:
884
885  (add-hook gnus-select-group-hook
886            (lambda ()
887              (mapcar (lambda (header)
888                        (mail-header-set-subject
889                         header
890                         (gnus-simplify-subject
891                          (mail-header-subject header) 're-only)))
892                      gnus-newsgroup-headers)))"
893   :group 'gnus-group-select
894   :type 'hook)
895
896 (defcustom gnus-select-article-hook nil
897   "*A hook called when an article is selected."
898   :group 'gnus-summary-choose
899   :options '(gnus-agent-fetch-selected-article)
900   :type 'hook)
901
902 (defcustom gnus-visual-mark-article-hook
903   (list 'gnus-highlight-selected-summary)
904   "*Hook run after selecting an article in the summary buffer.
905 It is meant to be used for highlighting the article in some way.  It
906 is not run if `gnus-visual' is nil."
907   :group 'gnus-summary-visual
908   :type 'hook)
909
910 (defcustom gnus-parse-headers-hook nil
911   "*A hook called before parsing the headers."
912   :group 'gnus-various
913   :type 'hook)
914
915 (defcustom gnus-exit-group-hook nil
916   "*A hook called when exiting summary mode.
917 This hook is not called from the non-updating exit commands like `Q'."
918   :group 'gnus-various
919   :type 'hook)
920
921 (defcustom gnus-summary-update-hook
922   (list 'gnus-summary-highlight-line)
923   "*A hook called when a summary line is changed.
924 The hook will not be called if `gnus-visual' is nil.
925
926 The default function `gnus-summary-highlight-line' will
927 highlight the line according to the `gnus-summary-highlight'
928 variable."
929   :group 'gnus-summary-visual
930   :type 'hook)
931
932 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
933   "*A hook called when an article is selected for the first time.
934 The hook is intended to mark an article as read (or unread)
935 automatically when it is selected."
936   :group 'gnus-summary-choose
937   :type 'hook)
938
939 (defcustom gnus-group-no-more-groups-hook nil
940   "*A hook run when returning to group mode having no more (unread) groups."
941   :group 'gnus-group-select
942   :type 'hook)
943
944 (defcustom gnus-ps-print-hook nil
945   "*A hook run before ps-printing something from Gnus."
946   :group 'gnus-summary
947   :type 'hook)
948
949 (defcustom gnus-summary-article-move-hook nil
950   "*A hook called after an article is moved, copied, respooled, or crossposted."
951   :version "21.4"
952   :group 'gnus-summary
953   :type 'hook)
954
955 (defcustom gnus-summary-article-delete-hook nil
956   "*A hook called after an article is deleted."
957   :version "21.4"
958   :group 'gnus-summary
959   :type 'hook)
960
961 (defcustom gnus-summary-article-expire-hook nil
962   "*A hook called after an article is expired."
963   :version "21.4"
964   :group 'gnus-summary
965   :type 'hook)
966
967 (defcustom gnus-summary-display-arrow
968   (and (fboundp 'display-graphic-p)
969        (display-graphic-p))
970   "*If non-nil, display an arrow highlighting the current article."
971   :version "21.4"
972   :group 'gnus-summary
973   :type 'boolean)
974
975 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
976   "Face used for highlighting the current article in the summary buffer."
977   :group 'gnus-summary-visual
978   :type 'face)
979
980 (defvar gnus-tmp-downloaded nil)
981
982 (defcustom gnus-summary-highlight
983   '(((eq mark gnus-canceled-mark)
984      . gnus-summary-cancelled-face)
985     ((and uncached (> score default-high))
986      . gnus-summary-high-undownloaded-face)
987     ((and uncached (< score default-low))
988      . gnus-summary-low-undownloaded-face)
989     (uncached
990      . gnus-summary-normal-undownloaded-face)
991     ((and (> score default-high)
992           (or (eq mark gnus-dormant-mark)
993               (eq mark gnus-ticked-mark)))
994      . gnus-summary-high-ticked-face)
995     ((and (< score default-low)
996           (or (eq mark gnus-dormant-mark)
997               (eq mark gnus-ticked-mark)))
998      . gnus-summary-low-ticked-face)
999     ((or (eq mark gnus-dormant-mark)
1000          (eq mark gnus-ticked-mark))
1001      . gnus-summary-normal-ticked-face)
1002     ((and (> score default-high) (eq mark gnus-ancient-mark))
1003      . gnus-summary-high-ancient-face)
1004     ((and (< score default-low) (eq mark gnus-ancient-mark))
1005      . gnus-summary-low-ancient-face)
1006     ((eq mark gnus-ancient-mark)
1007      . gnus-summary-normal-ancient-face)
1008     ((and (> score default-high) (eq mark gnus-unread-mark))
1009      . gnus-summary-high-unread-face)
1010     ((and (< score default-low) (eq mark gnus-unread-mark))
1011      . gnus-summary-low-unread-face)
1012     ((eq mark gnus-unread-mark)
1013      . gnus-summary-normal-unread-face)
1014     ((> score default-high)
1015      . gnus-summary-high-read-face)
1016     ((< score default-low)
1017      . gnus-summary-low-read-face)
1018     (t
1019      . gnus-summary-normal-read-face))
1020   "*Controls the highlighting of summary buffer lines.
1021
1022 A list of (FORM . FACE) pairs.  When deciding how a a particular
1023 summary line should be displayed, each form is evaluated.  The content
1024 of the face field after the first true form is used.  You can change
1025 how those summary lines are displayed, by editing the face field.
1026
1027 You can use the following variables in the FORM field.
1028
1029 score:        The article's score
1030 default:      The default article score.
1031 default-high: The default score for high scored articles.
1032 default-low:  The default score for low scored articles.
1033 below:        The score below which articles are automatically marked as read.
1034 mark:         The article's mark.
1035 uncached:     Non-nil if the article is uncached."
1036   :group 'gnus-summary-visual
1037   :type '(repeat (cons (sexp :tag "Form" nil)
1038                        face)))
1039
1040 (defcustom gnus-alter-header-function nil
1041   "Function called to allow alteration of article header structures.
1042 The function is called with one parameter, the article header vector,
1043 which it may alter in any way."
1044   :type '(choice (const :tag "None" nil)
1045                  function)
1046   :group 'gnus-summary)
1047
1048 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1049   "Variable that says which function should be used to decode a string with encoded words.")
1050
1051 (defcustom gnus-extra-headers '(To Newsgroups)
1052   "*Extra headers to parse."
1053   :version "21.1"
1054   :group 'gnus-summary
1055   :type '(repeat symbol))
1056
1057 (defcustom gnus-ignored-from-addresses
1058   (and user-mail-address (regexp-quote user-mail-address))
1059   "*Regexp of From headers that may be suppressed in favor of To headers."
1060   :version "21.1"
1061   :group 'gnus-summary
1062   :type 'regexp)
1063
1064 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1065   "List of charsets that should be ignored.
1066 When these charsets are used in the \"charset\" parameter, the
1067 default charset will be used instead."
1068   :version "21.1"
1069   :type '(repeat symbol)
1070   :group 'gnus-charset)
1071
1072 (gnus-define-group-parameter
1073  ignored-charsets
1074  :type list
1075  :function-document
1076  "Return the ignored charsets of GROUP."
1077  :variable gnus-group-ignored-charsets-alist
1078  :variable-default
1079  '(("alt\\.chinese\\.text" iso-8859-1))
1080  :variable-document
1081  "Alist of regexps (to match group names) and charsets that should be ignored.
1082 When these charsets are used in the \"charset\" parameter, the
1083 default charset will be used instead."
1084  :variable-group gnus-charset
1085  :variable-type '(repeat (cons (regexp :tag "Group")
1086                                (repeat symbol)))
1087  :parameter-type '(choice :tag "Ignored charsets"
1088                           :value nil
1089                           (repeat (symbol)))
1090  :parameter-document       "\
1091 List of charsets that should be ignored.
1092
1093 When these charsets are used in the \"charset\" parameter, the
1094 default charset will be used instead.")
1095
1096 (defcustom gnus-group-highlight-words-alist nil
1097   "Alist of group regexps and highlight regexps.
1098 This variable uses the same syntax as `gnus-emphasis-alist'."
1099   :version "21.1"
1100   :type '(repeat (cons (regexp :tag "Group")
1101                        (repeat (list (regexp :tag "Highlight regexp")
1102                                      (number :tag "Group for entire word" 0)
1103                                      (number :tag "Group for displayed part" 0)
1104                                      (symbol :tag "Face"
1105                                              gnus-emphasis-highlight-words)))))
1106   :group 'gnus-summary-visual)
1107
1108 (defcustom gnus-summary-show-article-charset-alist
1109   nil
1110   "Alist of number and charset.
1111 The article will be shown with the charset corresponding to the
1112 numbered argument.
1113 For example: ((1 . cn-gb-2312) (2 . big5))."
1114   :version "21.1"
1115   :type '(repeat (cons (number :tag "Argument" 1)
1116                        (symbol :tag "Charset")))
1117   :group 'gnus-charset)
1118
1119 (defcustom gnus-preserve-marks t
1120   "Whether marks are preserved when moving, copying and respooling messages."
1121   :version "21.1"
1122   :type 'boolean
1123   :group 'gnus-summary-marks)
1124
1125 (defcustom gnus-alter-articles-to-read-function nil
1126   "Function to be called to alter the list of articles to be selected."
1127   :type '(choice (const nil) function)
1128   :group 'gnus-summary)
1129
1130 (defcustom gnus-orphan-score nil
1131   "*All orphans get this score added.  Set in the score file."
1132   :group 'gnus-score-default
1133   :type '(choice (const nil)
1134                  integer))
1135
1136 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1137   "*A regexp to match MIME parts when saving multiple parts of a
1138 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1139 This regexp will be used by default when prompting the user for which
1140 type of files to save."
1141   :group 'gnus-summary
1142   :type 'regexp)
1143
1144 (defcustom gnus-read-all-available-headers nil
1145   "Whether Gnus should parse all headers made available to it.
1146 This is mostly relevant for slow back ends where the user may
1147 wish to widen the summary buffer to include all headers
1148 that were fetched.  Say, for nnultimate groups."
1149   :version "21.4"
1150   :group 'gnus-summary
1151   :type '(choice boolean regexp))
1152
1153 (defcustom gnus-summary-muttprint-program "muttprint"
1154   "Command (and optional arguments) used to run Muttprint."
1155   :version "21.4"
1156   :group 'gnus-summary
1157   :type 'string)
1158
1159 (defcustom gnus-article-loose-mime t
1160   "If non-nil, don't require MIME-Version header.
1161 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1162 supply the MIME-Version header or deliberately strip it from the mail.
1163 If non-nil (the default), Gnus will treat some articles as MIME
1164 even if the MIME-Version header is missing."
1165   :version "21.4"
1166   :type 'boolean
1167   :group 'gnus-article-mime)
1168
1169 (defcustom gnus-article-emulate-mime t
1170   "If non-nil, use MIME emulation for uuencode and the like.
1171 This means that Gnus will search message bodies for text that look
1172 like uuencoded bits, yEncoded bits, and so on, and present that using
1173 the normal Gnus MIME machinery."
1174   :version "21.4"
1175   :type 'boolean
1176   :group 'gnus-article-mime)
1177
1178 ;;; Internal variables
1179
1180 (defvar gnus-summary-display-cache nil)
1181 (defvar gnus-article-mime-handles nil)
1182 (defvar gnus-article-decoded-p nil)
1183 (defvar gnus-article-charset nil)
1184 (defvar gnus-article-ignored-charsets nil)
1185 (defvar gnus-scores-exclude-files nil)
1186 (defvar gnus-page-broken nil)
1187
1188 (defvar gnus-original-article nil)
1189 (defvar gnus-article-internal-prepare-hook nil)
1190 (defvar gnus-newsgroup-process-stack nil)
1191
1192 (defvar gnus-thread-indent-array nil)
1193 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1194 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1195   "Function called to sort the articles within a thread after it has been gathered together.")
1196
1197 (defvar gnus-summary-save-parts-type-history nil)
1198 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1199
1200 ;; Avoid highlighting in kill files.
1201 (defvar gnus-summary-inhibit-highlight nil)
1202 (defvar gnus-newsgroup-selected-overlay nil)
1203 (defvar gnus-inhibit-limiting nil)
1204 (defvar gnus-newsgroup-adaptive-score-file nil)
1205 (defvar gnus-current-score-file nil)
1206 (defvar gnus-current-move-group nil)
1207 (defvar gnus-current-copy-group nil)
1208 (defvar gnus-current-crosspost-group nil)
1209 (defvar gnus-newsgroup-display nil)
1210
1211 (defvar gnus-newsgroup-dependencies nil)
1212 (defvar gnus-newsgroup-adaptive nil)
1213 (defvar gnus-summary-display-article-function nil)
1214 (defvar gnus-summary-highlight-line-function nil
1215   "Function called after highlighting a summary line.")
1216
1217 (defvar gnus-summary-line-format-alist
1218   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1219     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1220     (?s gnus-tmp-subject-or-nil ?s)
1221     (?n gnus-tmp-name ?s)
1222     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1223         ?s)
1224     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1225             gnus-tmp-from) ?s)
1226     (?F gnus-tmp-from ?s)
1227     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1228     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1229     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1230     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1231     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1232     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1233     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1234     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1235     (?L gnus-tmp-lines ?s)
1236     (?O gnus-tmp-downloaded ?c)
1237     (?I gnus-tmp-indentation ?s)
1238     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1239     (?R gnus-tmp-replied ?c)
1240     (?\[ gnus-tmp-opening-bracket ?c)
1241     (?\] gnus-tmp-closing-bracket ?c)
1242     (?\> (make-string gnus-tmp-level ? ) ?s)
1243     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1244     (?i gnus-tmp-score ?d)
1245     (?z gnus-tmp-score-char ?c)
1246     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1247     (?U gnus-tmp-unread ?c)
1248     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1249         ?s)
1250     (?t (gnus-summary-number-of-articles-in-thread
1251          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1252         ?d)
1253     (?e (gnus-summary-number-of-articles-in-thread
1254          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1255         ?c)
1256     (?u gnus-tmp-user-defined ?s)
1257     (?P (gnus-pick-line-number) ?d)
1258     (?B gnus-tmp-thread-tree-header-string ?s)
1259     (user-date (gnus-user-date
1260                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1261   "An alist of format specifications that can appear in summary lines.
1262 These are paired with what variables they correspond with, along with
1263 the type of the variable (string, integer, character, etc).")
1264
1265 (defvar gnus-summary-dummy-line-format-alist
1266   `((?S gnus-tmp-subject ?s)
1267     (?N gnus-tmp-number ?d)
1268     (?u gnus-tmp-user-defined ?s)))
1269
1270 (defvar gnus-summary-mode-line-format-alist
1271   `((?G gnus-tmp-group-name ?s)
1272     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1273     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1274     (?A gnus-tmp-article-number ?d)
1275     (?Z gnus-tmp-unread-and-unselected ?s)
1276     (?V gnus-version ?s)
1277     (?U gnus-tmp-unread-and-unticked ?d)
1278     (?S gnus-tmp-subject ?s)
1279     (?e gnus-tmp-unselected ?d)
1280     (?u gnus-tmp-user-defined ?s)
1281     (?d (length gnus-newsgroup-dormant) ?d)
1282     (?t (length gnus-newsgroup-marked) ?d)
1283     (?h (length gnus-newsgroup-spam-marked) ?d)
1284     (?r (length gnus-newsgroup-reads) ?d)
1285     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1286     (?E gnus-newsgroup-expunged-tally ?d)
1287     (?s (gnus-current-score-file-nondirectory) ?s)))
1288
1289 (defvar gnus-last-search-regexp nil
1290   "Default regexp for article search command.")
1291
1292 (defvar gnus-last-shell-command nil
1293   "Default shell command on article.")
1294
1295 (defvar gnus-newsgroup-agentized nil
1296   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1297 (defvar gnus-newsgroup-begin nil)
1298 (defvar gnus-newsgroup-end nil)
1299 (defvar gnus-newsgroup-last-rmail nil)
1300 (defvar gnus-newsgroup-last-mail nil)
1301 (defvar gnus-newsgroup-last-folder nil)
1302 (defvar gnus-newsgroup-last-file nil)
1303 (defvar gnus-newsgroup-auto-expire nil)
1304 (defvar gnus-newsgroup-active nil)
1305
1306 (defvar gnus-newsgroup-data nil)
1307 (defvar gnus-newsgroup-data-reverse nil)
1308 (defvar gnus-newsgroup-limit nil)
1309 (defvar gnus-newsgroup-limits nil)
1310 (defvar gnus-summary-use-undownloaded-faces nil)
1311
1312 (defvar gnus-newsgroup-unreads nil
1313   "Sorted list of unread articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-unselected nil
1316   "Sorted list of unselected unread articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-reads nil
1319   "Alist of read articles and article marks in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-expunged-tally nil)
1322
1323 (defvar gnus-newsgroup-marked nil
1324   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1325
1326 (defvar gnus-newsgroup-spam-marked nil
1327   "List of ranges of articles that have been marked as spam.")
1328
1329 (defvar gnus-newsgroup-killed nil
1330   "List of ranges of articles that have been through the scoring process.")
1331
1332 (defvar gnus-newsgroup-cached nil
1333   "Sorted list of articles that come from the article cache.")
1334
1335 (defvar gnus-newsgroup-saved nil
1336   "List of articles that have been saved.")
1337
1338 (defvar gnus-newsgroup-kill-headers nil)
1339
1340 (defvar gnus-newsgroup-replied nil
1341   "List of articles that have been replied to in the current newsgroup.")
1342
1343 (defvar gnus-newsgroup-forwarded nil
1344   "List of articles that have been forwarded in the current newsgroup.")
1345
1346 (defvar gnus-newsgroup-recent nil
1347   "List of articles that have are recent in the current newsgroup.")
1348
1349 (defvar gnus-newsgroup-expirable nil
1350   "Sorted list of articles in the current newsgroup that can be expired.")
1351
1352 (defvar gnus-newsgroup-processable nil
1353   "List of articles in the current newsgroup that can be processed.")
1354
1355 (defvar gnus-newsgroup-downloadable nil
1356   "Sorted list of articles in the current newsgroup that can be processed.")
1357
1358 (defvar gnus-newsgroup-unfetched nil
1359   "Sorted list of articles in the current newsgroup whose headers have
1360 not been fetched into the agent.
1361
1362 This list will always be a subset of gnus-newsgroup-undownloaded.")
1363
1364 (defvar gnus-newsgroup-undownloaded nil
1365   "List of articles in the current newsgroup that haven't been downloaded.")
1366
1367 (defvar gnus-newsgroup-unsendable nil
1368   "List of articles in the current newsgroup that won't be sent.")
1369
1370 (defvar gnus-newsgroup-bookmarks nil
1371   "List of articles in the current newsgroup that have bookmarks.")
1372
1373 (defvar gnus-newsgroup-dormant nil
1374   "Sorted list of dormant articles in the current newsgroup.")
1375
1376 (defvar gnus-newsgroup-unseen nil
1377   "List of unseen articles in the current newsgroup.")
1378
1379 (defvar gnus-newsgroup-seen nil
1380   "Range of seen articles in the current newsgroup.")
1381
1382 (defvar gnus-newsgroup-articles nil
1383   "List of articles in the current newsgroup.")
1384
1385 (defvar gnus-newsgroup-scored nil
1386   "List of scored articles in the current newsgroup.")
1387
1388 (defvar gnus-newsgroup-headers nil
1389   "List of article headers in the current newsgroup.")
1390
1391 (defvar gnus-newsgroup-threads nil)
1392
1393 (defvar gnus-newsgroup-prepared nil
1394   "Whether the current group has been prepared properly.")
1395
1396 (defvar gnus-newsgroup-ancient nil
1397   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-sparse nil)
1400
1401 (defvar gnus-current-article nil)
1402 (defvar gnus-article-current nil)
1403 (defvar gnus-current-headers nil)
1404 (defvar gnus-have-all-headers nil)
1405 (defvar gnus-last-article nil)
1406 (defvar gnus-newsgroup-history nil)
1407 (defvar gnus-newsgroup-charset nil)
1408 (defvar gnus-newsgroup-ephemeral-charset nil)
1409 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1410
1411 (defvar gnus-article-before-search nil)
1412
1413 (defvar gnus-summary-local-variables
1414   '(gnus-newsgroup-name
1415     gnus-newsgroup-begin gnus-newsgroup-end
1416     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1417     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1418     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1419     gnus-newsgroup-unselected gnus-newsgroup-marked
1420     gnus-newsgroup-spam-marked
1421     gnus-newsgroup-reads gnus-newsgroup-saved
1422     gnus-newsgroup-replied gnus-newsgroup-forwarded
1423     gnus-newsgroup-recent
1424     gnus-newsgroup-expirable
1425     gnus-newsgroup-processable gnus-newsgroup-killed
1426     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1427     gnus-newsgroup-unfetched
1428     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1429     gnus-newsgroup-seen gnus-newsgroup-articles
1430     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1431     gnus-newsgroup-headers gnus-newsgroup-threads
1432     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1433     gnus-current-article gnus-current-headers gnus-have-all-headers
1434     gnus-last-article gnus-article-internal-prepare-hook
1435     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1436     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1437     gnus-thread-expunge-below
1438     gnus-score-alist gnus-current-score-file
1439     (gnus-summary-expunge-below . global)
1440     (gnus-summary-mark-below . global)
1441     (gnus-orphan-score . global)
1442     gnus-newsgroup-active gnus-scores-exclude-files
1443     gnus-newsgroup-history gnus-newsgroup-ancient
1444     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1445     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1446     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1447     (gnus-newsgroup-expunged-tally . 0)
1448     gnus-cache-removable-articles gnus-newsgroup-cached
1449     gnus-newsgroup-data gnus-newsgroup-data-reverse
1450     gnus-newsgroup-limit gnus-newsgroup-limits
1451     gnus-newsgroup-charset gnus-newsgroup-display
1452     gnus-summary-use-undownloaded-faces)
1453   "Variables that are buffer-local to the summary buffers.")
1454
1455 (defvar gnus-newsgroup-variables nil
1456   "A list of variables that have separate values in different newsgroups.
1457 A list of newsgroup (summary buffer) local variables, or cons of
1458 variables and their default expressions to be evalled (when the default
1459 values are not nil), that should be made global while the summary buffer
1460 is active.
1461
1462 Note: The default expressions will be evaluated (using function `eval')
1463 before assignment to the local variable rather than just assigned to it.
1464 If the default expression is the symbol `global', that symbol will not
1465 be evaluated but the global value of the local variable will be used
1466 instead.
1467
1468 These variables can be used to set variables in the group parameters
1469 while still allowing them to affect operations done in other buffers.
1470 For example:
1471
1472 \(setq gnus-newsgroup-variables
1473      '(message-use-followup-to
1474        (gnus-visible-headers .
1475          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1476 ")
1477
1478 ;; Byte-compiler warning.
1479 (eval-when-compile
1480   ;; Bind features so that require will believe that gnus-sum has
1481   ;; already been loaded (avoids infinite recursion)
1482   (let ((features (cons 'gnus-sum features)))
1483     ;; Several of the declarations in gnus-sum are needed to load the
1484     ;; following files. Right now, these definitions have been
1485     ;; compiled but not defined (evaluated).  We could either do a
1486     ;; eval-and-compile about all of the declarations or evaluate the
1487     ;; source file.
1488     (if (boundp 'gnus-newsgroup-variables)
1489         nil
1490       (load "gnus-sum.el" t t t))
1491     (require 'gnus)
1492     (require 'gnus-art)))
1493
1494 ;; MIME stuff.
1495
1496 (defvar gnus-decode-encoded-word-methods
1497   '(mail-decode-encoded-word-string)
1498   "List of methods used to decode encoded words.
1499
1500 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1501 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1502 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1503 whose names match REGEXP.
1504
1505 For example:
1506 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1507  mail-decode-encoded-word-string
1508  (\"chinese\" . rfc1843-decode-string))")
1509
1510 (defvar gnus-decode-encoded-word-methods-cache nil)
1511
1512 (defun gnus-multi-decode-encoded-word-string (string)
1513   "Apply the functions from `gnus-encoded-word-methods' that match."
1514   (unless (and gnus-decode-encoded-word-methods-cache
1515                (eq gnus-newsgroup-name
1516                    (car gnus-decode-encoded-word-methods-cache)))
1517     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1518     (mapcar (lambda (x)
1519               (if (symbolp x)
1520                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1521                 (if (and gnus-newsgroup-name
1522                          (string-match (car x) gnus-newsgroup-name))
1523                     (nconc gnus-decode-encoded-word-methods-cache
1524                            (list (cdr x))))))
1525             gnus-decode-encoded-word-methods))
1526   (let ((xlist gnus-decode-encoded-word-methods-cache))
1527     (pop xlist)
1528     (while xlist
1529       (setq string (funcall (pop xlist) string))))
1530   string)
1531
1532 ;; Subject simplification.
1533
1534 (defun gnus-simplify-whitespace (str)
1535   "Remove excessive whitespace from STR."
1536   ;; Multiple spaces.
1537   (while (string-match "[ \t][ \t]+" str)
1538     (setq str (concat (substring str 0 (match-beginning 0))
1539                         " "
1540                         (substring str (match-end 0)))))
1541   ;; Leading spaces.
1542   (when (string-match "^[ \t]+" str)
1543     (setq str (substring str (match-end 0))))
1544   ;; Trailing spaces.
1545   (when (string-match "[ \t]+$" str)
1546     (setq str (substring str 0 (match-beginning 0))))
1547   str)
1548
1549 (defun gnus-simplify-all-whitespace (str)
1550   "Remove all whitespace from STR."
1551   (while (string-match "[ \t\n]+" str)
1552     (setq str (replace-match "" nil nil str)))
1553   str)
1554
1555 (defsubst gnus-simplify-subject-re (subject)
1556   "Remove \"Re:\" from subject lines."
1557   (if (string-match message-subject-re-regexp subject)
1558       (substring subject (match-end 0))
1559     subject))
1560
1561 (defun gnus-simplify-subject (subject &optional re-only)
1562   "Remove `Re:' and words in parentheses.
1563 If RE-ONLY is non-nil, strip leading `Re:'s only."
1564   (let ((case-fold-search t))           ;Ignore case.
1565     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1566     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1567       (setq subject (substring subject (match-end 0))))
1568     ;; Remove uninteresting prefixes.
1569     (when (and (not re-only)
1570                gnus-simplify-ignored-prefixes
1571                (string-match gnus-simplify-ignored-prefixes subject))
1572       (setq subject (substring subject (match-end 0))))
1573     ;; Remove words in parentheses from end.
1574     (unless re-only
1575       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1576         (setq subject (substring subject 0 (match-beginning 0)))))
1577     ;; Return subject string.
1578     subject))
1579
1580 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1581 ;; all whitespace.
1582 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1583   (goto-char (point-min))
1584   (while (re-search-forward regexp nil t)
1585     (replace-match (or newtext ""))))
1586
1587 (defun gnus-simplify-buffer-fuzzy ()
1588   "Simplify string in the buffer fuzzily.
1589 The string in the accessible portion of the current buffer is simplified.
1590 It is assumed to be a single-line subject.
1591 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1592 matter is removed.  Additional things can be deleted by setting
1593 `gnus-simplify-subject-fuzzy-regexp'."
1594   (let ((case-fold-search t)
1595         (modified-tick))
1596     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1597
1598     (while (not (eq modified-tick (buffer-modified-tick)))
1599       (setq modified-tick (buffer-modified-tick))
1600       (cond
1601        ((listp gnus-simplify-subject-fuzzy-regexp)
1602         (mapcar 'gnus-simplify-buffer-fuzzy-step
1603                 gnus-simplify-subject-fuzzy-regexp))
1604        (gnus-simplify-subject-fuzzy-regexp
1605         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1606       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1607       (gnus-simplify-buffer-fuzzy-step
1608        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1609       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1610
1611     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1612     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1613     (gnus-simplify-buffer-fuzzy-step " $")
1614     (gnus-simplify-buffer-fuzzy-step "^ +")))
1615
1616 (defun gnus-simplify-subject-fuzzy (subject)
1617   "Simplify a subject string fuzzily.
1618 See `gnus-simplify-buffer-fuzzy' for details."
1619   (save-excursion
1620     (gnus-set-work-buffer)
1621     (let ((case-fold-search t))
1622       ;; Remove uninteresting prefixes.
1623       (when (and gnus-simplify-ignored-prefixes
1624                  (string-match gnus-simplify-ignored-prefixes subject))
1625         (setq subject (substring subject (match-end 0))))
1626       (insert subject)
1627       (inline (gnus-simplify-buffer-fuzzy))
1628       (buffer-string))))
1629
1630 (defsubst gnus-simplify-subject-fully (subject)
1631   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1632   (cond
1633    (gnus-simplify-subject-functions
1634     (gnus-map-function gnus-simplify-subject-functions subject))
1635    ((null gnus-summary-gather-subject-limit)
1636     (gnus-simplify-subject-re subject))
1637    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1638     (gnus-simplify-subject-fuzzy subject))
1639    ((numberp gnus-summary-gather-subject-limit)
1640     (gnus-limit-string (gnus-simplify-subject-re subject)
1641                        gnus-summary-gather-subject-limit))
1642    (t
1643     subject)))
1644
1645 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1646   "Check whether two subjects are equal.
1647 If optional argument SIMPLE-FIRST is t, first argument is already
1648 simplified."
1649   (cond
1650    ((null simple-first)
1651     (equal (gnus-simplify-subject-fully s1)
1652            (gnus-simplify-subject-fully s2)))
1653    (t
1654     (equal s1
1655            (gnus-simplify-subject-fully s2)))))
1656
1657 (defun gnus-summary-bubble-group ()
1658   "Increase the score of the current group.
1659 This is a handy function to add to `gnus-summary-exit-hook' to
1660 increase the score of each group you read."
1661   (gnus-group-add-score gnus-newsgroup-name))
1662
1663 \f
1664 ;;;
1665 ;;; Gnus summary mode
1666 ;;;
1667
1668 (put 'gnus-summary-mode 'mode-class 'special)
1669
1670 (defvar gnus-article-commands-menu)
1671
1672 ;; Non-orthogonal keys
1673
1674 (gnus-define-keys gnus-summary-mode-map
1675   " " gnus-summary-next-page
1676   "\177" gnus-summary-prev-page
1677   [delete] gnus-summary-prev-page
1678   [backspace] gnus-summary-prev-page
1679   "\r" gnus-summary-scroll-up
1680   "\M-\r" gnus-summary-scroll-down
1681   "n" gnus-summary-next-unread-article
1682   "p" gnus-summary-prev-unread-article
1683   "N" gnus-summary-next-article
1684   "P" gnus-summary-prev-article
1685   "\M-\C-n" gnus-summary-next-same-subject
1686   "\M-\C-p" gnus-summary-prev-same-subject
1687   "\M-n" gnus-summary-next-unread-subject
1688   "\M-p" gnus-summary-prev-unread-subject
1689   "." gnus-summary-first-unread-article
1690   "," gnus-summary-best-unread-article
1691   "\M-s" gnus-summary-search-article-forward
1692   "\M-r" gnus-summary-search-article-backward
1693   "<" gnus-summary-beginning-of-article
1694   ">" gnus-summary-end-of-article
1695   "j" gnus-summary-goto-article
1696   "^" gnus-summary-refer-parent-article
1697   "\M-^" gnus-summary-refer-article
1698   "u" gnus-summary-tick-article-forward
1699   "!" gnus-summary-tick-article-forward
1700   "U" gnus-summary-tick-article-backward
1701   "d" gnus-summary-mark-as-read-forward
1702   "D" gnus-summary-mark-as-read-backward
1703   "E" gnus-summary-mark-as-expirable
1704   "\M-u" gnus-summary-clear-mark-forward
1705   "\M-U" gnus-summary-clear-mark-backward
1706   "k" gnus-summary-kill-same-subject-and-select
1707   "\C-k" gnus-summary-kill-same-subject
1708   "\M-\C-k" gnus-summary-kill-thread
1709   "\M-\C-l" gnus-summary-lower-thread
1710   "e" gnus-summary-edit-article
1711   "#" gnus-summary-mark-as-processable
1712   "\M-#" gnus-summary-unmark-as-processable
1713   "\M-\C-t" gnus-summary-toggle-threads
1714   "\M-\C-s" gnus-summary-show-thread
1715   "\M-\C-h" gnus-summary-hide-thread
1716   "\M-\C-f" gnus-summary-next-thread
1717   "\M-\C-b" gnus-summary-prev-thread
1718   [(meta down)] gnus-summary-next-thread
1719   [(meta up)] gnus-summary-prev-thread
1720   "\M-\C-u" gnus-summary-up-thread
1721   "\M-\C-d" gnus-summary-down-thread
1722   "&" gnus-summary-execute-command
1723   "c" gnus-summary-catchup-and-exit
1724   "\C-w" gnus-summary-mark-region-as-read
1725   "\C-t" gnus-summary-toggle-truncation
1726   "?" gnus-summary-mark-as-dormant
1727   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1728   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1729   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1730   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1731   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1732   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1733   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1734   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1735   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1736   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1737   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1738   "=" gnus-summary-expand-window
1739   "\C-x\C-s" gnus-summary-reselect-current-group
1740   "\M-g" gnus-summary-rescan-group
1741   "w" gnus-summary-stop-page-breaking
1742   "\C-c\C-r" gnus-summary-caesar-message
1743   "f" gnus-summary-followup
1744   "F" gnus-summary-followup-with-original
1745   "C" gnus-summary-cancel-article
1746   "r" gnus-summary-reply
1747   "R" gnus-summary-reply-with-original
1748   "\C-c\C-f" gnus-summary-mail-forward
1749   "o" gnus-summary-save-article
1750   "\C-o" gnus-summary-save-article-mail
1751   "|" gnus-summary-pipe-output
1752   "\M-k" gnus-summary-edit-local-kill
1753   "\M-K" gnus-summary-edit-global-kill
1754   ;; "V" gnus-version
1755   "\C-c\C-d" gnus-summary-describe-group
1756   "q" gnus-summary-exit
1757   "Q" gnus-summary-exit-no-update
1758   "\C-c\C-i" gnus-info-find-node
1759   gnus-mouse-2 gnus-mouse-pick-article
1760   "m" gnus-summary-mail-other-window
1761   "a" gnus-summary-post-news
1762   "i" gnus-summary-news-other-window
1763   "x" gnus-summary-limit-to-unread
1764   "s" gnus-summary-isearch-article
1765   "t" gnus-summary-toggle-header
1766   "g" gnus-summary-show-article
1767   "l" gnus-summary-goto-last-article
1768   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1769   "\C-d" gnus-summary-enter-digest-group
1770   "\M-\C-d" gnus-summary-read-document
1771   "\M-\C-e" gnus-summary-edit-parameters
1772   "\M-\C-a" gnus-summary-customize-parameters
1773   "\C-c\C-b" gnus-bug
1774   "*" gnus-cache-enter-article
1775   "\M-*" gnus-cache-remove-article
1776   "\M-&" gnus-summary-universal-argument
1777   "\C-l" gnus-recenter
1778   "I" gnus-summary-increase-score
1779   "L" gnus-summary-lower-score
1780   "\M-i" gnus-symbolic-argument
1781   "h" gnus-summary-select-article-buffer
1782
1783   "b" gnus-article-view-part
1784   "\M-t" gnus-summary-toggle-display-buttonized
1785
1786   "V" gnus-summary-score-map
1787   "X" gnus-uu-extract-map
1788   "S" gnus-summary-send-map)
1789
1790 ;; Sort of orthogonal keymap
1791 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1792   "t" gnus-summary-tick-article-forward
1793   "!" gnus-summary-tick-article-forward
1794   "d" gnus-summary-mark-as-read-forward
1795   "r" gnus-summary-mark-as-read-forward
1796   "c" gnus-summary-clear-mark-forward
1797   " " gnus-summary-clear-mark-forward
1798   "e" gnus-summary-mark-as-expirable
1799   "x" gnus-summary-mark-as-expirable
1800   "?" gnus-summary-mark-as-dormant
1801   "b" gnus-summary-set-bookmark
1802   "B" gnus-summary-remove-bookmark
1803   "#" gnus-summary-mark-as-processable
1804   "\M-#" gnus-summary-unmark-as-processable
1805   "S" gnus-summary-limit-include-expunged
1806   "C" gnus-summary-catchup
1807   "H" gnus-summary-catchup-to-here
1808   "h" gnus-summary-catchup-from-here
1809   "\C-c" gnus-summary-catchup-all
1810   "k" gnus-summary-kill-same-subject-and-select
1811   "K" gnus-summary-kill-same-subject
1812   "P" gnus-uu-mark-map)
1813
1814 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1815   "c" gnus-summary-clear-above
1816   "u" gnus-summary-tick-above
1817   "m" gnus-summary-mark-above
1818   "k" gnus-summary-kill-below)
1819
1820 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1821   "/" gnus-summary-limit-to-subject
1822   "n" gnus-summary-limit-to-articles
1823   "w" gnus-summary-pop-limit
1824   "s" gnus-summary-limit-to-subject
1825   "a" gnus-summary-limit-to-author
1826   "u" gnus-summary-limit-to-unread
1827   "m" gnus-summary-limit-to-marks
1828   "M" gnus-summary-limit-exclude-marks
1829   "v" gnus-summary-limit-to-score
1830   "*" gnus-summary-limit-include-cached
1831   "D" gnus-summary-limit-include-dormant
1832   "T" gnus-summary-limit-include-thread
1833   "d" gnus-summary-limit-exclude-dormant
1834   "t" gnus-summary-limit-to-age
1835   "." gnus-summary-limit-to-unseen
1836   "x" gnus-summary-limit-to-extra
1837   "p" gnus-summary-limit-to-display-predicate
1838   "E" gnus-summary-limit-include-expunged
1839   "c" gnus-summary-limit-exclude-childless-dormant
1840   "C" gnus-summary-limit-mark-excluded-as-read
1841   "o" gnus-summary-insert-old-articles
1842   "N" gnus-summary-insert-new-articles
1843   "r" gnus-summary-limit-to-replied
1844   "R" gnus-summary-limit-to-recipient)
1845
1846 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1847   "n" gnus-summary-next-unread-article
1848   "p" gnus-summary-prev-unread-article
1849   "N" gnus-summary-next-article
1850   "P" gnus-summary-prev-article
1851   "\C-n" gnus-summary-next-same-subject
1852   "\C-p" gnus-summary-prev-same-subject
1853   "\M-n" gnus-summary-next-unread-subject
1854   "\M-p" gnus-summary-prev-unread-subject
1855   "f" gnus-summary-first-unread-article
1856   "b" gnus-summary-best-unread-article
1857   "j" gnus-summary-goto-article
1858   "g" gnus-summary-goto-subject
1859   "l" gnus-summary-goto-last-article
1860   "o" gnus-summary-pop-article)
1861
1862 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1863   "k" gnus-summary-kill-thread
1864   "l" gnus-summary-lower-thread
1865   "i" gnus-summary-raise-thread
1866   "T" gnus-summary-toggle-threads
1867   "t" gnus-summary-rethread-current
1868   "^" gnus-summary-reparent-thread
1869   "s" gnus-summary-show-thread
1870   "S" gnus-summary-show-all-threads
1871   "h" gnus-summary-hide-thread
1872   "H" gnus-summary-hide-all-threads
1873   "n" gnus-summary-next-thread
1874   "p" gnus-summary-prev-thread
1875   "u" gnus-summary-up-thread
1876   "o" gnus-summary-top-thread
1877   "d" gnus-summary-down-thread
1878   "#" gnus-uu-mark-thread
1879   "\M-#" gnus-uu-unmark-thread)
1880
1881 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1882   "g" gnus-summary-prepare
1883   "c" gnus-summary-insert-cached-articles
1884   "d" gnus-summary-insert-dormant-articles)
1885
1886 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1887   "c" gnus-summary-catchup-and-exit
1888   "C" gnus-summary-catchup-all-and-exit
1889   "E" gnus-summary-exit-no-update
1890   "Q" gnus-summary-exit
1891   "Z" gnus-summary-exit
1892   "n" gnus-summary-catchup-and-goto-next-group
1893   "R" gnus-summary-reselect-current-group
1894   "G" gnus-summary-rescan-group
1895   "N" gnus-summary-next-group
1896   "s" gnus-summary-save-newsrc
1897   "P" gnus-summary-prev-group)
1898
1899 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1900   " " gnus-summary-next-page
1901   "n" gnus-summary-next-page
1902   "\177" gnus-summary-prev-page
1903   [delete] gnus-summary-prev-page
1904   "p" gnus-summary-prev-page
1905   "\r" gnus-summary-scroll-up
1906   "\M-\r" gnus-summary-scroll-down
1907   "<" gnus-summary-beginning-of-article
1908   ">" gnus-summary-end-of-article
1909   "b" gnus-summary-beginning-of-article
1910   "e" gnus-summary-end-of-article
1911   "^" gnus-summary-refer-parent-article
1912   "r" gnus-summary-refer-parent-article
1913   "D" gnus-summary-enter-digest-group
1914   "R" gnus-summary-refer-references
1915   "T" gnus-summary-refer-thread
1916   "g" gnus-summary-show-article
1917   "s" gnus-summary-isearch-article
1918   "P" gnus-summary-print-article
1919   "M" gnus-mailing-list-insinuate
1920   "t" gnus-article-babel)
1921
1922 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1923   "b" gnus-article-add-buttons
1924   "B" gnus-article-add-buttons-to-head
1925   "o" gnus-article-treat-overstrike
1926   "e" gnus-article-emphasize
1927   "w" gnus-article-fill-cited-article
1928   "Q" gnus-article-fill-long-lines
1929   "C" gnus-article-capitalize-sentences
1930   "c" gnus-article-remove-cr
1931   "q" gnus-article-de-quoted-unreadable
1932   "6" gnus-article-de-base64-unreadable
1933   "Z" gnus-article-decode-HZ
1934   "A" gnus-article-treat-ansi-sequences
1935   "h" gnus-article-wash-html
1936   "u" gnus-article-unsplit-urls
1937   "s" gnus-summary-force-verify-and-decrypt
1938   "f" gnus-article-display-x-face
1939   "l" gnus-summary-stop-page-breaking
1940   "r" gnus-summary-caesar-message
1941   "m" gnus-summary-morse-message
1942   "t" gnus-summary-toggle-header
1943   "g" gnus-treat-smiley
1944   "v" gnus-summary-verbose-headers
1945   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1946   "p" gnus-article-verify-x-pgp-sig
1947   "d" gnus-article-treat-dumbquotes)
1948
1949 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1950   ;; mnemonic: deuglif*Y*
1951   "u" gnus-article-outlook-unwrap-lines
1952   "a" gnus-article-outlook-repair-attribution
1953   "c" gnus-article-outlook-rearrange-citation
1954   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1955
1956 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1957   "a" gnus-article-hide
1958   "h" gnus-article-hide-headers
1959   "b" gnus-article-hide-boring-headers
1960   "s" gnus-article-hide-signature
1961   "c" gnus-article-hide-citation
1962   "C" gnus-article-hide-citation-in-followups
1963   "l" gnus-article-hide-list-identifiers
1964   "B" gnus-article-strip-banner
1965   "P" gnus-article-hide-pem
1966   "\C-c" gnus-article-hide-citation-maybe)
1967
1968 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1969   "a" gnus-article-highlight
1970   "h" gnus-article-highlight-headers
1971   "c" gnus-article-highlight-citation
1972   "s" gnus-article-highlight-signature)
1973
1974 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1975   "f" gnus-article-treat-fold-headers
1976   "u" gnus-article-treat-unfold-headers
1977   "n" gnus-article-treat-fold-newsgroups)
1978
1979 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1980   "x" gnus-article-display-x-face
1981   "d" gnus-article-display-face
1982   "s" gnus-treat-smiley
1983   "D" gnus-article-remove-images
1984   "f" gnus-treat-from-picon
1985   "m" gnus-treat-mail-picon
1986   "n" gnus-treat-newsgroups-picon)
1987
1988 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1989   "w" gnus-article-decode-mime-words
1990   "c" gnus-article-decode-charset
1991   "v" gnus-mime-view-all-parts
1992   "b" gnus-article-view-part)
1993
1994 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1995   "z" gnus-article-date-ut
1996   "u" gnus-article-date-ut
1997   "l" gnus-article-date-local
1998   "p" gnus-article-date-english
1999   "e" gnus-article-date-lapsed
2000   "o" gnus-article-date-original
2001   "i" gnus-article-date-iso8601
2002   "s" gnus-article-date-user)
2003
2004 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2005   "t" gnus-article-remove-trailing-blank-lines
2006   "l" gnus-article-strip-leading-blank-lines
2007   "m" gnus-article-strip-multiple-blank-lines
2008   "a" gnus-article-strip-blank-lines
2009   "A" gnus-article-strip-all-blank-lines
2010   "s" gnus-article-strip-leading-space
2011   "e" gnus-article-strip-trailing-space
2012   "w" gnus-article-remove-leading-whitespace)
2013
2014 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2015   "v" gnus-version
2016   "f" gnus-summary-fetch-faq
2017   "d" gnus-summary-describe-group
2018   "h" gnus-summary-describe-briefly
2019   "i" gnus-info-find-node
2020   "c" gnus-group-fetch-charter
2021   "C" gnus-group-fetch-control)
2022
2023 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2024   "e" gnus-summary-expire-articles
2025   "\M-\C-e" gnus-summary-expire-articles-now
2026   "\177" gnus-summary-delete-article
2027   [delete] gnus-summary-delete-article
2028   [backspace] gnus-summary-delete-article
2029   "m" gnus-summary-move-article
2030   "r" gnus-summary-respool-article
2031   "w" gnus-summary-edit-article
2032   "c" gnus-summary-copy-article
2033   "B" gnus-summary-crosspost-article
2034   "q" gnus-summary-respool-query
2035   "t" gnus-summary-respool-trace
2036   "i" gnus-summary-import-article
2037   "I" gnus-summary-create-article
2038   "p" gnus-summary-article-posted-p)
2039
2040 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2041   "o" gnus-summary-save-article
2042   "m" gnus-summary-save-article-mail
2043   "F" gnus-summary-write-article-file
2044   "r" gnus-summary-save-article-rmail
2045   "f" gnus-summary-save-article-file
2046   "b" gnus-summary-save-article-body-file
2047   "h" gnus-summary-save-article-folder
2048   "v" gnus-summary-save-article-vm
2049   "p" gnus-summary-pipe-output
2050   "P" gnus-summary-muttprint
2051   "s" gnus-soup-add-article)
2052
2053 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2054   "b" gnus-summary-display-buttonized
2055   "m" gnus-summary-repair-multipart
2056   "v" gnus-article-view-part
2057   "o" gnus-article-save-part
2058   "c" gnus-article-copy-part
2059   "C" gnus-article-view-part-as-charset
2060   "e" gnus-article-view-part-externally
2061   "E" gnus-article-encrypt-body
2062   "i" gnus-article-inline-part
2063   "|" gnus-article-pipe-part)
2064
2065 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2066   "p" gnus-summary-mark-as-processable
2067   "u" gnus-summary-unmark-as-processable
2068   "U" gnus-summary-unmark-all-processable
2069   "v" gnus-uu-mark-over
2070   "s" gnus-uu-mark-series
2071   "r" gnus-uu-mark-region
2072   "g" gnus-uu-unmark-region
2073   "R" gnus-uu-mark-by-regexp
2074   "G" gnus-uu-unmark-by-regexp
2075   "t" gnus-uu-mark-thread
2076   "T" gnus-uu-unmark-thread
2077   "a" gnus-uu-mark-all
2078   "b" gnus-uu-mark-buffer
2079   "S" gnus-uu-mark-sparse
2080   "k" gnus-summary-kill-process-mark
2081   "y" gnus-summary-yank-process-mark
2082   "w" gnus-summary-save-process-mark
2083   "i" gnus-uu-invert-processable)
2084
2085 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2086   ;;"x" gnus-uu-extract-any
2087   "m" gnus-summary-save-parts
2088   "u" gnus-uu-decode-uu
2089   "U" gnus-uu-decode-uu-and-save
2090   "s" gnus-uu-decode-unshar
2091   "S" gnus-uu-decode-unshar-and-save
2092   "o" gnus-uu-decode-save
2093   "O" gnus-uu-decode-save
2094   "b" gnus-uu-decode-binhex
2095   "B" gnus-uu-decode-binhex
2096   "p" gnus-uu-decode-postscript
2097   "P" gnus-uu-decode-postscript-and-save)
2098
2099 (gnus-define-keys
2100     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2101   "u" gnus-uu-decode-uu-view
2102   "U" gnus-uu-decode-uu-and-save-view
2103   "s" gnus-uu-decode-unshar-view
2104   "S" gnus-uu-decode-unshar-and-save-view
2105   "o" gnus-uu-decode-save-view
2106   "O" gnus-uu-decode-save-view
2107   "b" gnus-uu-decode-binhex-view
2108   "B" gnus-uu-decode-binhex-view
2109   "p" gnus-uu-decode-postscript-view
2110   "P" gnus-uu-decode-postscript-and-save-view)
2111
2112 (defvar gnus-article-post-menu nil)
2113
2114 (defconst gnus-summary-menu-maxlen 20)
2115
2116 (defun gnus-summary-menu-split (menu)
2117   ;; If we have lots of elements, divide them into groups of 20
2118   ;; and make a pane (or submenu) for each one.
2119   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2120       (let ((menu menu) sublists next
2121             (i 1))
2122         (while menu
2123           ;; Pull off the next gnus-summary-menu-maxlen elements
2124           ;; and make them the next element of sublist.
2125           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2126           (if next
2127               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2128                       nil))
2129           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2130                                              (aref (car (last menu)) 0)) menu)
2131                                sublists))
2132           (setq i (1+ i))
2133           (setq menu next))
2134         (nreverse sublists))
2135     ;; Few elements--put them all in one pane.
2136     menu))
2137
2138 (defun gnus-summary-make-menu-bar ()
2139   (gnus-turn-off-edit-menu 'summary)
2140
2141   (unless (boundp 'gnus-summary-misc-menu)
2142
2143     (easy-menu-define
2144       gnus-summary-kill-menu gnus-summary-mode-map ""
2145       (cons
2146        "Score"
2147        (nconc
2148         (list
2149          ["Customize" gnus-score-customize t])
2150         (gnus-make-score-map 'increase)
2151         (gnus-make-score-map 'lower)
2152         '(("Mark"
2153            ["Kill below" gnus-summary-kill-below t]
2154            ["Mark above" gnus-summary-mark-above t]
2155            ["Tick above" gnus-summary-tick-above t]
2156            ["Clear above" gnus-summary-clear-above t])
2157           ["Current score" gnus-summary-current-score t]
2158           ["Set score" gnus-summary-set-score t]
2159           ["Switch current score file..." gnus-score-change-score-file t]
2160           ["Set mark below..." gnus-score-set-mark-below t]
2161           ["Set expunge below..." gnus-score-set-expunge-below t]
2162           ["Edit current score file" gnus-score-edit-current-scores t]
2163           ["Edit score file" gnus-score-edit-file t]
2164           ["Trace score" gnus-score-find-trace t]
2165           ["Find words" gnus-score-find-favourite-words t]
2166           ["Rescore buffer" gnus-summary-rescore t]
2167           ["Increase score..." gnus-summary-increase-score t]
2168           ["Lower score..." gnus-summary-lower-score t]))))
2169
2170     ;; Define both the Article menu in the summary buffer and the
2171     ;; equivalent Commands menu in the article buffer here for
2172     ;; consistency.
2173     (let ((innards
2174            `(("Hide"
2175               ["All" gnus-article-hide t]
2176               ["Headers" gnus-article-hide-headers t]
2177               ["Signature" gnus-article-hide-signature t]
2178               ["Citation" gnus-article-hide-citation t]
2179               ["List identifiers" gnus-article-hide-list-identifiers t]
2180               ["Banner" gnus-article-strip-banner t]
2181               ["Boring headers" gnus-article-hide-boring-headers t])
2182              ("Highlight"
2183               ["All" gnus-article-highlight t]
2184               ["Headers" gnus-article-highlight-headers t]
2185               ["Signature" gnus-article-highlight-signature t]
2186               ["Citation" gnus-article-highlight-citation t])
2187              ("MIME"
2188               ["Words" gnus-article-decode-mime-words t]
2189               ["Charset" gnus-article-decode-charset t]
2190               ["QP" gnus-article-de-quoted-unreadable t]
2191               ["Base64" gnus-article-de-base64-unreadable t]
2192               ["View MIME buttons" gnus-summary-display-buttonized t]
2193               ["View all" gnus-mime-view-all-parts t]
2194               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2195               ["Encrypt body" gnus-article-encrypt-body
2196                :active (not (gnus-group-read-only-p))
2197                ,@(if (featurep 'xemacs) nil
2198                    '(:help "Encrypt the message body on disk"))]
2199               ["Extract all parts..." gnus-summary-save-parts t]
2200               ("Multipart"
2201                ["Repair multipart" gnus-summary-repair-multipart t]
2202                ["Pipe part..." gnus-article-pipe-part t]
2203                ["Inline part" gnus-article-inline-part t]
2204                ["Encrypt body" gnus-article-encrypt-body
2205                 :active (not (gnus-group-read-only-p))
2206                ,@(if (featurep 'xemacs) nil
2207                    '(:help "Encrypt the message body on disk"))]
2208                ["View part externally" gnus-article-view-part-externally t]
2209                ["View part with charset..." gnus-article-view-part-as-charset t]
2210                ["Copy part" gnus-article-copy-part t]
2211                ["Save part..." gnus-article-save-part t]
2212                ["View part" gnus-article-view-part t]))
2213              ("Date"
2214               ["Local" gnus-article-date-local t]
2215               ["ISO8601" gnus-article-date-iso8601 t]
2216               ["UT" gnus-article-date-ut t]
2217               ["Original" gnus-article-date-original t]
2218               ["Lapsed" gnus-article-date-lapsed t]
2219               ["User-defined" gnus-article-date-user t])
2220              ("Display"
2221               ["Remove images" gnus-article-remove-images t]
2222               ["Toggle smiley" gnus-treat-smiley t]
2223               ["Show X-Face" gnus-article-display-x-face t]
2224               ["Show picons in From" gnus-treat-from-picon t]
2225               ["Show picons in mail headers" gnus-treat-mail-picon t]
2226               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2227               ("View as different encoding"
2228                ,@(gnus-summary-menu-split
2229                   (mapcar
2230                    (lambda (cs)
2231                      ;; Since easymenu under Emacs doesn't allow
2232                      ;; lambda forms for menu commands, we should
2233                      ;; provide intern'ed function symbols.
2234                      (let ((command (intern (format "\
2235 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2236                        (fset command
2237                              `(lambda ()
2238                                 (interactive)
2239                                 (let ((gnus-summary-show-article-charset-alist
2240                                        '((1 . ,cs))))
2241                                   (gnus-summary-show-article 1))))
2242                        `[,(symbol-name cs) ,command t]))
2243                    (sort (if (fboundp 'coding-system-list)
2244                              (coding-system-list)
2245                            (mapcar 'car mm-mime-mule-charset-alist))
2246                          'string<)))))
2247              ("Washing"
2248               ("Remove Blanks"
2249                ["Leading" gnus-article-strip-leading-blank-lines t]
2250                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2251                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2252                ["All of the above" gnus-article-strip-blank-lines t]
2253                ["All" gnus-article-strip-all-blank-lines t]
2254                ["Leading space" gnus-article-strip-leading-space t]
2255                ["Trailing space" gnus-article-strip-trailing-space t]
2256                ["Leading space in headers"
2257                 gnus-article-remove-leading-whitespace t])
2258               ["Overstrike" gnus-article-treat-overstrike t]
2259               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2260               ["Emphasis" gnus-article-emphasize t]
2261               ["Word wrap" gnus-article-fill-cited-article t]
2262               ["Fill long lines" gnus-article-fill-long-lines t]
2263               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2264               ["Remove CR" gnus-article-remove-cr t]
2265               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2266               ["Base64" gnus-article-de-base64-unreadable t]
2267               ["Rot 13" gnus-summary-caesar-message
2268                ,@(if (featurep 'xemacs) '(t)
2269                    '(:help "\"Caesar rotate\" article by 13"))]
2270               ["Morse decode" gnus-summary-morse-message t]
2271               ["Unix pipe..." gnus-summary-pipe-message t]
2272               ["Add buttons" gnus-article-add-buttons t]
2273               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2274               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2275               ["Verbose header" gnus-summary-verbose-headers t]
2276               ["Toggle header" gnus-summary-toggle-header t]
2277               ["Unfold headers" gnus-article-treat-unfold-headers t]
2278               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2279               ["Html" gnus-article-wash-html t]
2280               ["Unsplit URLs" gnus-article-unsplit-urls t]
2281               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2282               ["Decode HZ" gnus-article-decode-HZ t]
2283               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2284               ("(Outlook) Deuglify"
2285                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2286                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2287                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2288                ["Full (Outlook) deuglify"
2289                 gnus-article-outlook-deuglify-article t])
2290               )
2291              ("Output"
2292               ["Save in default format..." gnus-summary-save-article
2293                ,@(if (featurep 'xemacs) '(t)
2294                    '(:help "Save article using default method"))]
2295               ["Save in file..." gnus-summary-save-article-file
2296                ,@(if (featurep 'xemacs) '(t)
2297                    '(:help "Save article in file"))]
2298               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2299               ["Save in MH folder..." gnus-summary-save-article-folder t]
2300               ["Save in VM folder..." gnus-summary-save-article-vm t]
2301               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2302               ["Save body in file..." gnus-summary-save-article-body-file t]
2303               ["Pipe through a filter..." gnus-summary-pipe-output t]
2304               ["Add to SOUP packet" gnus-soup-add-article t]
2305               ["Print with Muttprint..." gnus-summary-muttprint t]
2306               ["Print" gnus-summary-print-article
2307                ,@(if (featurep 'xemacs) '(t)
2308                    '(:help "Generate and print a PostScript image"))])
2309              ("Copy, move,... (Backend)"
2310               ,@(if (featurep 'xemacs) nil
2311                   '(:help "Copying, moving, expiring articles..."))
2312               ["Respool article..." gnus-summary-respool-article t]
2313               ["Move article..." gnus-summary-move-article
2314                (gnus-check-backend-function
2315                 'request-move-article gnus-newsgroup-name)]
2316               ["Copy article..." gnus-summary-copy-article t]
2317               ["Crosspost article..." gnus-summary-crosspost-article
2318                (gnus-check-backend-function
2319                 'request-replace-article gnus-newsgroup-name)]
2320               ["Import file..." gnus-summary-import-article
2321                (gnus-check-backend-function
2322                 'request-accept-article gnus-newsgroup-name)]
2323               ["Create article..." gnus-summary-create-article
2324                (gnus-check-backend-function
2325                 'request-accept-article gnus-newsgroup-name)]
2326               ["Check if posted" gnus-summary-article-posted-p t]
2327               ["Edit article" gnus-summary-edit-article
2328                (not (gnus-group-read-only-p))]
2329               ["Delete article" gnus-summary-delete-article
2330                (gnus-check-backend-function
2331                 'request-expire-articles gnus-newsgroup-name)]
2332               ["Query respool" gnus-summary-respool-query t]
2333               ["Trace respool" gnus-summary-respool-trace t]
2334               ["Delete expirable articles" gnus-summary-expire-articles-now
2335                (gnus-check-backend-function
2336                 'request-expire-articles gnus-newsgroup-name)])
2337              ("Extract"
2338               ["Uudecode" gnus-uu-decode-uu
2339                ,@(if (featurep 'xemacs) '(t)
2340                    '(:help "Decode uuencoded article(s)"))]
2341               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2342               ["Unshar" gnus-uu-decode-unshar t]
2343               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2344               ["Save" gnus-uu-decode-save t]
2345               ["Binhex" gnus-uu-decode-binhex t]
2346               ["Postscript" gnus-uu-decode-postscript t]
2347               ["All MIME parts" gnus-summary-save-parts t])
2348              ("Cache"
2349               ["Enter article" gnus-cache-enter-article t]
2350               ["Remove article" gnus-cache-remove-article t])
2351              ["Translate" gnus-article-babel t]
2352              ["Select article buffer" gnus-summary-select-article-buffer t]
2353              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2354              ["Isearch article..." gnus-summary-isearch-article t]
2355              ["Beginning of the article" gnus-summary-beginning-of-article t]
2356              ["End of the article" gnus-summary-end-of-article t]
2357              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2358              ["Fetch referenced articles" gnus-summary-refer-references t]
2359              ["Fetch current thread" gnus-summary-refer-thread t]
2360              ["Fetch article with id..." gnus-summary-refer-article t]
2361              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2362              ["Redisplay" gnus-summary-show-article t]
2363              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2364       (easy-menu-define
2365         gnus-summary-article-menu gnus-summary-mode-map ""
2366         (cons "Article" innards))
2367
2368       (if (not (keymapp gnus-summary-article-menu))
2369           (easy-menu-define
2370             gnus-article-commands-menu gnus-article-mode-map ""
2371             (cons "Commands" innards))
2372         ;; in Emacs, don't share menu.
2373         (setq gnus-article-commands-menu
2374               (copy-keymap gnus-summary-article-menu))
2375         (define-key gnus-article-mode-map [menu-bar commands]
2376           (cons "Commands" gnus-article-commands-menu))))
2377
2378     (easy-menu-define
2379       gnus-summary-thread-menu gnus-summary-mode-map ""
2380       '("Threads"
2381         ["Find all messages in thread" gnus-summary-refer-thread t]
2382         ["Toggle threading" gnus-summary-toggle-threads t]
2383         ["Hide threads" gnus-summary-hide-all-threads t]
2384         ["Show threads" gnus-summary-show-all-threads t]
2385         ["Hide thread" gnus-summary-hide-thread t]
2386         ["Show thread" gnus-summary-show-thread t]
2387         ["Go to next thread" gnus-summary-next-thread t]
2388         ["Go to previous thread" gnus-summary-prev-thread t]
2389         ["Go down thread" gnus-summary-down-thread t]
2390         ["Go up thread" gnus-summary-up-thread t]
2391         ["Top of thread" gnus-summary-top-thread t]
2392         ["Mark thread as read" gnus-summary-kill-thread t]
2393         ["Lower thread score" gnus-summary-lower-thread t]
2394         ["Raise thread score" gnus-summary-raise-thread t]
2395         ["Rethread current" gnus-summary-rethread-current t]))
2396
2397     (easy-menu-define
2398       gnus-summary-post-menu gnus-summary-mode-map ""
2399       `("Post"
2400         ["Send a message (mail or news)" gnus-summary-post-news
2401          ,@(if (featurep 'xemacs) '(t)
2402              '(:help "Compose a new message (mail or news)"))]
2403         ["Followup" gnus-summary-followup
2404          ,@(if (featurep 'xemacs) '(t)
2405              '(:help "Post followup to this article"))]
2406         ["Followup and yank" gnus-summary-followup-with-original
2407          ,@(if (featurep 'xemacs) '(t)
2408              '(:help "Post followup to this article, quoting its contents"))]
2409         ["Supersede article" gnus-summary-supersede-article t]
2410         ["Cancel article" gnus-summary-cancel-article
2411          ,@(if (featurep 'xemacs) '(t)
2412              '(:help "Cancel an article you posted"))]
2413         ["Reply" gnus-summary-reply t]
2414         ["Reply and yank" gnus-summary-reply-with-original t]
2415         ["Wide reply" gnus-summary-wide-reply t]
2416         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2417          ,@(if (featurep 'xemacs) '(t)
2418              '(:help "Mail a reply, quoting this article"))]
2419         ["Very wide reply" gnus-summary-very-wide-reply t]
2420         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2421          ,@(if (featurep 'xemacs) '(t)
2422              '(:help "Mail a very wide reply, quoting this article"))]
2423         ["Mail forward" gnus-summary-mail-forward t]
2424         ["Post forward" gnus-summary-post-forward t]
2425         ["Digest and mail" gnus-uu-digest-mail-forward t]
2426         ["Digest and post" gnus-uu-digest-post-forward t]
2427         ["Resend message" gnus-summary-resend-message t]
2428         ["Resend message edit" gnus-summary-resend-message-edit t]
2429         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2430         ["Send a mail" gnus-summary-mail-other-window t]
2431         ["Create a local message" gnus-summary-news-other-window t]
2432         ["Uuencode and post" gnus-uu-post-news
2433          ,@(if (featurep 'xemacs) '(t)
2434              '(:help "Post a uuencoded article"))]
2435         ["Followup via news" gnus-summary-followup-to-mail t]
2436         ["Followup via news and yank"
2437          gnus-summary-followup-to-mail-with-original t]
2438         ;;("Draft"
2439         ;;["Send" gnus-summary-send-draft t]
2440         ;;["Send bounced" gnus-resend-bounced-mail t])
2441         ))
2442
2443     (cond
2444      ((not (keymapp gnus-summary-post-menu))
2445       (setq gnus-article-post-menu gnus-summary-post-menu))
2446      ((not gnus-article-post-menu)
2447       ;; Don't share post menu.
2448       (setq gnus-article-post-menu
2449             (copy-keymap gnus-summary-post-menu))))
2450     (define-key gnus-article-mode-map [menu-bar post]
2451       (cons "Post" gnus-article-post-menu))
2452
2453     (easy-menu-define
2454       gnus-summary-misc-menu gnus-summary-mode-map ""
2455       `("Gnus"
2456         ("Mark Read"
2457          ["Mark as read" gnus-summary-mark-as-read-forward t]
2458          ["Mark same subject and select"
2459           gnus-summary-kill-same-subject-and-select t]
2460          ["Mark same subject" gnus-summary-kill-same-subject t]
2461          ["Catchup" gnus-summary-catchup
2462           ,@(if (featurep 'xemacs) '(t)
2463               '(:help "Mark unread articles in this group as read"))]
2464          ["Catchup all" gnus-summary-catchup-all t]
2465          ["Catchup to here" gnus-summary-catchup-to-here t]
2466          ["Catchup from here" gnus-summary-catchup-from-here t]
2467          ["Catchup region" gnus-summary-mark-region-as-read
2468           (gnus-mark-active-p)]
2469          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2470         ("Mark Various"
2471          ["Tick" gnus-summary-tick-article-forward t]
2472          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2473          ["Remove marks" gnus-summary-clear-mark-forward t]
2474          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2475          ["Set bookmark" gnus-summary-set-bookmark t]
2476          ["Remove bookmark" gnus-summary-remove-bookmark t])
2477         ("Limit to"
2478          ["Marks..." gnus-summary-limit-to-marks t]
2479          ["Subject..." gnus-summary-limit-to-subject t]
2480          ["Author..." gnus-summary-limit-to-author t]
2481          ["Recipient..." gnus-summary-limit-to-recipient t]
2482          ["Age..." gnus-summary-limit-to-age t]
2483          ["Extra..." gnus-summary-limit-to-extra t]
2484          ["Score..." gnus-summary-limit-to-score t]
2485          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2486          ["Unread" gnus-summary-limit-to-unread t]
2487          ["Unseen" gnus-summary-limit-to-unseen t]
2488          ["Replied" gnus-summary-limit-to-replied t]
2489          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2490          ["Next articles" gnus-summary-limit-to-articles t]
2491          ["Pop limit" gnus-summary-pop-limit t]
2492          ["Show dormant" gnus-summary-limit-include-dormant t]
2493          ["Hide childless dormant"
2494           gnus-summary-limit-exclude-childless-dormant t]
2495          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2496          ["Hide marked" gnus-summary-limit-exclude-marks t]
2497          ["Show expunged" gnus-summary-limit-include-expunged t])
2498         ("Process Mark"
2499          ["Set mark" gnus-summary-mark-as-processable t]
2500          ["Remove mark" gnus-summary-unmark-as-processable t]
2501          ["Remove all marks" gnus-summary-unmark-all-processable t]
2502          ["Invert marks" gnus-uu-invert-processable t]
2503          ["Mark above" gnus-uu-mark-over t]
2504          ["Mark series" gnus-uu-mark-series t]
2505          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2506          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2507          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2508          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2509          ["Mark all" gnus-uu-mark-all t]
2510          ["Mark buffer" gnus-uu-mark-buffer t]
2511          ["Mark sparse" gnus-uu-mark-sparse t]
2512          ["Mark thread" gnus-uu-mark-thread t]
2513          ["Unmark thread" gnus-uu-unmark-thread t]
2514          ("Process Mark Sets"
2515           ["Kill" gnus-summary-kill-process-mark t]
2516           ["Yank" gnus-summary-yank-process-mark
2517            gnus-newsgroup-process-stack]
2518           ["Save" gnus-summary-save-process-mark t]
2519           ["Run command on marked..." gnus-summary-universal-argument t]))
2520         ("Scroll article"
2521          ["Page forward" gnus-summary-next-page
2522           ,@(if (featurep 'xemacs) '(t)
2523               '(:help "Show next page of article"))]
2524          ["Page backward" gnus-summary-prev-page
2525           ,@(if (featurep 'xemacs) '(t)
2526               '(:help "Show previous page of article"))]
2527          ["Line forward" gnus-summary-scroll-up t])
2528         ("Move"
2529          ["Next unread article" gnus-summary-next-unread-article t]
2530          ["Previous unread article" gnus-summary-prev-unread-article t]
2531          ["Next article" gnus-summary-next-article t]
2532          ["Previous article" gnus-summary-prev-article t]
2533          ["Next unread subject" gnus-summary-next-unread-subject t]
2534          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2535          ["Next article same subject" gnus-summary-next-same-subject t]
2536          ["Previous article same subject" gnus-summary-prev-same-subject t]
2537          ["First unread article" gnus-summary-first-unread-article t]
2538          ["Best unread article" gnus-summary-best-unread-article t]
2539          ["Go to subject number..." gnus-summary-goto-subject t]
2540          ["Go to article number..." gnus-summary-goto-article t]
2541          ["Go to the last article" gnus-summary-goto-last-article t]
2542          ["Pop article off history" gnus-summary-pop-article t])
2543         ("Sort"
2544          ["Sort by number" gnus-summary-sort-by-number t]
2545          ["Sort by author" gnus-summary-sort-by-author t]
2546          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2547          ["Sort by subject" gnus-summary-sort-by-subject t]
2548          ["Sort by date" gnus-summary-sort-by-date t]
2549          ["Sort by score" gnus-summary-sort-by-score t]
2550          ["Sort by lines" gnus-summary-sort-by-lines t]
2551          ["Sort by characters" gnus-summary-sort-by-chars t]
2552          ["Randomize" gnus-summary-sort-by-random t]
2553          ["Original sort" gnus-summary-sort-by-original t])
2554         ("Help"
2555          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2556          ["Describe group" gnus-summary-describe-group t]
2557          ["Fetch charter" gnus-group-fetch-charter
2558           ,@(if (featurep 'xemacs) nil
2559               '(:help "Display the charter of the current group"))]
2560          ["Fetch control message" gnus-group-fetch-control
2561           ,@(if (featurep 'xemacs) nil
2562               '(:help "Display the archived control message for the current group"))]
2563          ["Read manual" gnus-info-find-node t])
2564         ("Modes"
2565          ["Pick and read" gnus-pick-mode t]
2566          ["Binary" gnus-binary-mode t])
2567         ("Regeneration"
2568          ["Regenerate" gnus-summary-prepare t]
2569          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2570          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2571          ["Toggle threading" gnus-summary-toggle-threads t])
2572         ["See old articles" gnus-summary-insert-old-articles t]
2573         ["See new articles" gnus-summary-insert-new-articles t]
2574         ["Filter articles..." gnus-summary-execute-command t]
2575         ["Run command on articles..." gnus-summary-universal-argument t]
2576         ["Search articles forward..." gnus-summary-search-article-forward t]
2577         ["Search articles backward..." gnus-summary-search-article-backward t]
2578         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2579         ["Expand window" gnus-summary-expand-window t]
2580         ["Expire expirable articles" gnus-summary-expire-articles
2581          (gnus-check-backend-function
2582           'request-expire-articles gnus-newsgroup-name)]
2583         ["Edit local kill file" gnus-summary-edit-local-kill t]
2584         ["Edit main kill file" gnus-summary-edit-global-kill t]
2585         ["Edit group parameters" gnus-summary-edit-parameters t]
2586         ["Customize group parameters" gnus-summary-customize-parameters t]
2587         ["Send a bug report" gnus-bug t]
2588         ("Exit"
2589          ["Catchup and exit" gnus-summary-catchup-and-exit
2590           ,@(if (featurep 'xemacs) '(t)
2591               '(:help "Mark unread articles in this group as read, then exit"))]
2592          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2593          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2594          ["Exit group" gnus-summary-exit
2595           ,@(if (featurep 'xemacs) '(t)
2596               '(:help "Exit current group, return to group selection mode"))]
2597          ["Exit group without updating" gnus-summary-exit-no-update t]
2598          ["Exit and goto next group" gnus-summary-next-group t]
2599          ["Exit and goto prev group" gnus-summary-prev-group t]
2600          ["Reselect group" gnus-summary-reselect-current-group t]
2601          ["Rescan group" gnus-summary-rescan-group t]
2602          ["Update dribble" gnus-summary-save-newsrc t])))
2603
2604     (gnus-run-hooks 'gnus-summary-menu-hook)))
2605
2606 (defvar gnus-summary-tool-bar-map nil)
2607
2608 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2609 (defun gnus-summary-make-tool-bar ()
2610   (if (and (fboundp 'tool-bar-add-item-from-menu)
2611            (default-value 'tool-bar-mode)
2612            (not gnus-summary-tool-bar-map))
2613       (setq gnus-summary-tool-bar-map
2614             (let ((tool-bar-map (make-sparse-keymap))
2615                   (load-path (mm-image-load-path)))
2616               (tool-bar-add-item-from-menu
2617                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2618               (tool-bar-add-item-from-menu
2619                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2620               (tool-bar-add-item-from-menu
2621                'gnus-summary-post-news "post" gnus-summary-mode-map)
2622               (tool-bar-add-item-from-menu
2623                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2624               (tool-bar-add-item-from-menu
2625                'gnus-summary-followup "followup" gnus-summary-mode-map)
2626               (tool-bar-add-item-from-menu
2627                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2628               (tool-bar-add-item-from-menu
2629                'gnus-summary-reply "reply" gnus-summary-mode-map)
2630               (tool-bar-add-item-from-menu
2631                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2632               (tool-bar-add-item-from-menu
2633                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2634               (tool-bar-add-item-from-menu
2635                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2636               (tool-bar-add-item-from-menu
2637                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2638               (tool-bar-add-item-from-menu
2639                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2640               (tool-bar-add-item-from-menu
2641                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2642               (tool-bar-add-item-from-menu
2643                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2644               (tool-bar-add-item-from-menu
2645                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2646               (tool-bar-add-item-from-menu
2647                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2648               tool-bar-map)))
2649   (if gnus-summary-tool-bar-map
2650       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2651
2652 (defun gnus-score-set-default (var value)
2653   "A version of set that updates the GNU Emacs menu-bar."
2654   (set var value)
2655   ;; It is the message that forces the active status to be updated.
2656   (message ""))
2657
2658 (defun gnus-make-score-map (type)
2659   "Make a summary score map of type TYPE."
2660   (if t
2661       nil
2662     (let ((headers '(("author" "from" string)
2663                      ("subject" "subject" string)
2664                      ("article body" "body" string)
2665                      ("article head" "head" string)
2666                      ("xref" "xref" string)
2667                      ("extra header" "extra" string)
2668                      ("lines" "lines" number)
2669                      ("followups to author" "followup" string)))
2670           (types '((number ("less than" <)
2671                            ("greater than" >)
2672                            ("equal" =))
2673                    (string ("substring" s)
2674                            ("exact string" e)
2675                            ("fuzzy string" f)
2676                            ("regexp" r))))
2677           (perms '(("temporary" (current-time-string))
2678                    ("permanent" nil)
2679                    ("immediate" now)))
2680           header)
2681       (list
2682        (apply
2683         'nconc
2684         (list
2685          (if (eq type 'lower)
2686              "Lower score"
2687            "Increase score"))
2688         (let (outh)
2689           (while headers
2690             (setq header (car headers))
2691             (setq outh
2692                   (cons
2693                    (apply
2694                     'nconc
2695                     (list (car header))
2696                     (let ((ts (cdr (assoc (nth 2 header) types)))
2697                           outt)
2698                       (while ts
2699                         (setq outt
2700                               (cons
2701                                (apply
2702                                 'nconc
2703                                 (list (caar ts))
2704                                 (let ((ps perms)
2705                                       outp)
2706                                   (while ps
2707                                     (setq outp
2708                                           (cons
2709                                            (vector
2710                                             (caar ps)
2711                                             (list
2712                                              'gnus-summary-score-entry
2713                                              (nth 1 header)
2714                                              (if (or (string= (nth 1 header)
2715                                                               "head")
2716                                                      (string= (nth 1 header)
2717                                                               "body"))
2718                                                  ""
2719                                                (list 'gnus-summary-header
2720                                                      (nth 1 header)))
2721                                              (list 'quote (nth 1 (car ts)))
2722                                              (list 'gnus-score-delta-default
2723                                                    nil)
2724                                              (nth 1 (car ps))
2725                                              t)
2726                                             t)
2727                                            outp))
2728                                     (setq ps (cdr ps)))
2729                                   (list (nreverse outp))))
2730                                outt))
2731                         (setq ts (cdr ts)))
2732                       (list (nreverse outt))))
2733                    outh))
2734             (setq headers (cdr headers)))
2735           (list (nreverse outh))))))))
2736
2737 \f
2738
2739 (defun gnus-summary-mode (&optional group)
2740   "Major mode for reading articles.
2741
2742 All normal editing commands are switched off.
2743 \\<gnus-summary-mode-map>
2744 Each line in this buffer represents one article.  To read an
2745 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2746 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2747 respectively.
2748
2749 You can also post articles and send mail from this buffer.  To
2750 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2751 of an article, type `\\[gnus-summary-reply]'.
2752
2753 There are approx. one gazillion commands you can execute in this
2754 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2755
2756 The following commands are available:
2757
2758 \\{gnus-summary-mode-map}"
2759   (interactive)
2760   (kill-all-local-variables)
2761   (when (gnus-visual-p 'summary-menu 'menu)
2762     (gnus-summary-make-menu-bar)
2763     (gnus-summary-make-tool-bar))
2764   (gnus-summary-make-local-variables)
2765   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2766     (gnus-summary-make-local-variables))
2767   (gnus-make-thread-indent-array)
2768   (gnus-simplify-mode-line)
2769   (setq major-mode 'gnus-summary-mode)
2770   (setq mode-name "Summary")
2771   (make-local-variable 'minor-mode-alist)
2772   (use-local-map gnus-summary-mode-map)
2773   (buffer-disable-undo)
2774   (setq buffer-read-only t              ;Disable modification
2775         show-trailing-whitespace nil)
2776   (setq truncate-lines t)
2777   (setq selective-display t)
2778   (setq selective-display-ellipses t)   ;Display `...'
2779   (gnus-summary-set-display-table)
2780   (gnus-set-default-directory)
2781   (setq gnus-newsgroup-name group)
2782   (make-local-variable 'gnus-summary-line-format)
2783   (make-local-variable 'gnus-summary-line-format-spec)
2784   (make-local-variable 'gnus-summary-dummy-line-format)
2785   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2786   (make-local-variable 'gnus-summary-mark-positions)
2787   (gnus-make-local-hook 'pre-command-hook)
2788   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2789   (gnus-run-hooks 'gnus-summary-mode-hook)
2790   (turn-on-gnus-mailing-list-mode)
2791   (mm-enable-multibyte)
2792   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2793   (gnus-update-summary-mark-positions))
2794
2795 (defun gnus-summary-make-local-variables ()
2796   "Make all the local summary buffer variables."
2797   (let (global)
2798     (dolist (local gnus-summary-local-variables)
2799       (if (consp local)
2800           (progn
2801             (if (eq (cdr local) 'global)
2802                 ;; Copy the global value of the variable.
2803                 (setq global (symbol-value (car local)))
2804               ;; Use the value from the list.
2805               (setq global (eval (cdr local))))
2806             (set (make-local-variable (car local)) global))
2807         ;; Simple nil-valued local variable.
2808         (set (make-local-variable local) nil)))))
2809
2810 (defun gnus-summary-clear-local-variables ()
2811   (let ((locals gnus-summary-local-variables))
2812     (while locals
2813       (if (consp (car locals))
2814           (and (symbolp (caar locals))
2815                (set (caar locals) nil))
2816         (and (symbolp (car locals))
2817              (set (car locals) nil)))
2818       (setq locals (cdr locals)))))
2819
2820 ;; Summary data functions.
2821
2822 (defmacro gnus-data-number (data)
2823   `(car ,data))
2824
2825 (defmacro gnus-data-set-number (data number)
2826   `(setcar ,data ,number))
2827
2828 (defmacro gnus-data-mark (data)
2829   `(nth 1 ,data))
2830
2831 (defmacro gnus-data-set-mark (data mark)
2832   `(setcar (nthcdr 1 ,data) ,mark))
2833
2834 (defmacro gnus-data-pos (data)
2835   `(nth 2 ,data))
2836
2837 (defmacro gnus-data-set-pos (data pos)
2838   `(setcar (nthcdr 2 ,data) ,pos))
2839
2840 (defmacro gnus-data-header (data)
2841   `(nth 3 ,data))
2842
2843 (defmacro gnus-data-set-header (data header)
2844   `(setf (nth 3 ,data) ,header))
2845
2846 (defmacro gnus-data-level (data)
2847   `(nth 4 ,data))
2848
2849 (defmacro gnus-data-unread-p (data)
2850   `(= (nth 1 ,data) gnus-unread-mark))
2851
2852 (defmacro gnus-data-read-p (data)
2853   `(/= (nth 1 ,data) gnus-unread-mark))
2854
2855 (defmacro gnus-data-pseudo-p (data)
2856   `(consp (nth 3 ,data)))
2857
2858 (defmacro gnus-data-find (number)
2859   `(assq ,number gnus-newsgroup-data))
2860
2861 (defmacro gnus-data-find-list (number &optional data)
2862   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2863      (memq (assq ,number bdata)
2864            bdata)))
2865
2866 (defmacro gnus-data-make (number mark pos header level)
2867   `(list ,number ,mark ,pos ,header ,level))
2868
2869 (defun gnus-data-enter (after-article number mark pos header level offset)
2870   (let ((data (gnus-data-find-list after-article)))
2871     (unless data
2872       (error "No such article: %d" after-article))
2873     (setcdr data (cons (gnus-data-make number mark pos header level)
2874                        (cdr data)))
2875     (setq gnus-newsgroup-data-reverse nil)
2876     (gnus-data-update-list (cddr data) offset)))
2877
2878 (defun gnus-data-enter-list (after-article list &optional offset)
2879   (when list
2880     (let ((data (and after-article (gnus-data-find-list after-article)))
2881           (ilist list))
2882       (if (not (or data
2883                    after-article))
2884           (let ((odata gnus-newsgroup-data))
2885             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2886             (when offset
2887               (gnus-data-update-list odata offset)))
2888         ;; Find the last element in the list to be spliced into the main
2889         ;; list.
2890         (setq list (last list))
2891         (if (not data)
2892             (progn
2893               (setcdr list gnus-newsgroup-data)
2894               (setq gnus-newsgroup-data ilist)
2895               (when offset
2896                 (gnus-data-update-list (cdr list) offset)))
2897           (setcdr list (cdr data))
2898           (setcdr data ilist)
2899           (when offset
2900             (gnus-data-update-list (cdr list) offset))))
2901       (setq gnus-newsgroup-data-reverse nil))))
2902
2903 (defun gnus-data-remove (article &optional offset)
2904   (let ((data gnus-newsgroup-data))
2905     (if (= (gnus-data-number (car data)) article)
2906         (progn
2907           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2908                 gnus-newsgroup-data-reverse nil)
2909           (when offset
2910             (gnus-data-update-list gnus-newsgroup-data offset)))
2911       (while (cdr data)
2912         (when (= (gnus-data-number (cadr data)) article)
2913           (setcdr data (cddr data))
2914           (when offset
2915             (gnus-data-update-list (cdr data) offset))
2916           (setq data nil
2917                 gnus-newsgroup-data-reverse nil))
2918         (setq data (cdr data))))))
2919
2920 (defmacro gnus-data-list (backward)
2921   `(if ,backward
2922        (or gnus-newsgroup-data-reverse
2923            (setq gnus-newsgroup-data-reverse
2924                  (reverse gnus-newsgroup-data)))
2925      gnus-newsgroup-data))
2926
2927 (defun gnus-data-update-list (data offset)
2928   "Add OFFSET to the POS of all data entries in DATA."
2929   (setq gnus-newsgroup-data-reverse nil)
2930   (while data
2931     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2932     (setq data (cdr data))))
2933
2934 (defun gnus-summary-article-pseudo-p (article)
2935   "Say whether this article is a pseudo article or not."
2936   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2937
2938 (defmacro gnus-summary-article-sparse-p (article)
2939   "Say whether this article is a sparse article or not."
2940   `(memq ,article gnus-newsgroup-sparse))
2941
2942 (defmacro gnus-summary-article-ancient-p (article)
2943   "Say whether this article is a sparse article or not."
2944   `(memq ,article gnus-newsgroup-ancient))
2945
2946 (defun gnus-article-parent-p (number)
2947   "Say whether this article is a parent or not."
2948   (let ((data (gnus-data-find-list number)))
2949     (and (cdr data)              ; There has to be an article after...
2950          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2951             (gnus-data-level (nth 1 data))))))
2952
2953 (defun gnus-article-children (number)
2954   "Return a list of all children to NUMBER."
2955   (let* ((data (gnus-data-find-list number))
2956          (level (gnus-data-level (car data)))
2957          children)
2958     (setq data (cdr data))
2959     (while (and data
2960                 (= (gnus-data-level (car data)) (1+ level)))
2961       (push (gnus-data-number (car data)) children)
2962       (setq data (cdr data)))
2963     children))
2964
2965 (defmacro gnus-summary-skip-intangible ()
2966   "If the current article is intangible, then jump to a different article."
2967   '(let ((to (get-text-property (point) 'gnus-intangible)))
2968      (and to (gnus-summary-goto-subject to))))
2969
2970 (defmacro gnus-summary-article-intangible-p ()
2971   "Say whether this article is intangible or not."
2972   '(get-text-property (point) 'gnus-intangible))
2973
2974 (defun gnus-article-read-p (article)
2975   "Say whether ARTICLE is read or not."
2976   (not (or (memq article gnus-newsgroup-marked)
2977            (memq article gnus-newsgroup-spam-marked)
2978            (memq article gnus-newsgroup-unreads)
2979            (memq article gnus-newsgroup-unselected)
2980            (memq article gnus-newsgroup-dormant))))
2981
2982 ;; Some summary mode macros.
2983
2984 (defmacro gnus-summary-article-number ()
2985   "The article number of the article on the current line.
2986 If there isn't an article number here, then we return the current
2987 article number."
2988   '(progn
2989      (gnus-summary-skip-intangible)
2990      (or (get-text-property (point) 'gnus-number)
2991          (gnus-summary-last-subject))))
2992
2993 (defmacro gnus-summary-article-header (&optional number)
2994   "Return the header of article NUMBER."
2995   `(gnus-data-header (gnus-data-find
2996                       ,(or number '(gnus-summary-article-number)))))
2997
2998 (defmacro gnus-summary-thread-level (&optional number)
2999   "Return the level of thread that starts with article NUMBER."
3000   `(if (and (eq gnus-summary-make-false-root 'dummy)
3001             (get-text-property (point) 'gnus-intangible))
3002        0
3003      (gnus-data-level (gnus-data-find
3004                        ,(or number '(gnus-summary-article-number))))))
3005
3006 (defmacro gnus-summary-article-mark (&optional number)
3007   "Return the mark of article NUMBER."
3008   `(gnus-data-mark (gnus-data-find
3009                     ,(or number '(gnus-summary-article-number)))))
3010
3011 (defmacro gnus-summary-article-pos (&optional number)
3012   "Return the position of the line of article NUMBER."
3013   `(gnus-data-pos (gnus-data-find
3014                    ,(or number '(gnus-summary-article-number)))))
3015
3016 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3017 (defmacro gnus-summary-article-subject (&optional number)
3018   "Return current subject string or nil if nothing."
3019   `(let ((headers
3020           ,(if number
3021                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3022              '(gnus-data-header (assq (gnus-summary-article-number)
3023                                       gnus-newsgroup-data)))))
3024      (and headers
3025           (vectorp headers)
3026           (mail-header-subject headers))))
3027
3028 (defmacro gnus-summary-article-score (&optional number)
3029   "Return current article score."
3030   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3031                   gnus-newsgroup-scored))
3032        gnus-summary-default-score 0))
3033
3034 (defun gnus-summary-article-children (&optional number)
3035   "Return a list of article numbers that are children of article NUMBER."
3036   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3037          (level (gnus-data-level (car data)))
3038          l children)
3039     (while (and (setq data (cdr data))
3040                 (> (setq l (gnus-data-level (car data))) level))
3041       (and (= (1+ level) l)
3042            (push (gnus-data-number (car data))
3043                  children)))
3044     (nreverse children)))
3045
3046 (defun gnus-summary-article-parent (&optional number)
3047   "Return the article number of the parent of article NUMBER."
3048   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3049                                     (gnus-data-list t)))
3050          (level (gnus-data-level (car data))))
3051     (if (zerop level)
3052         ()                              ; This is a root.
3053       ;; We search until we find an article with a level less than
3054       ;; this one.  That function has to be the parent.
3055       (while (and (setq data (cdr data))
3056                   (not (< (gnus-data-level (car data)) level))))
3057       (and data (gnus-data-number (car data))))))
3058
3059 (defun gnus-unread-mark-p (mark)
3060   "Say whether MARK is the unread mark."
3061   (= mark gnus-unread-mark))
3062
3063 (defun gnus-read-mark-p (mark)
3064   "Say whether MARK is one of the marks that mark as read.
3065 This is all marks except unread, ticked, dormant, and expirable."
3066   (not (or (= mark gnus-unread-mark)
3067            (= mark gnus-ticked-mark)
3068            (= mark gnus-spam-mark)
3069            (= mark gnus-dormant-mark)
3070            (= mark gnus-expirable-mark))))
3071
3072 (defmacro gnus-article-mark (number)
3073   "Return the MARK of article NUMBER.
3074 This macro should only be used when computing the mark the \"first\"
3075 time; i.e., when generating the summary lines.  After that,
3076 `gnus-summary-article-mark' should be used to examine the
3077 marks of articles."
3078   `(cond
3079     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3080     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3081     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3082     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3083     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3084     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3085     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3086     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3087            gnus-ancient-mark))))
3088
3089 ;; Saving hidden threads.
3090
3091 (defmacro gnus-save-hidden-threads (&rest forms)
3092   "Save hidden threads, eval FORMS, and restore the hidden threads."
3093   (let ((config (make-symbol "config")))
3094     `(let ((,config (gnus-hidden-threads-configuration)))
3095        (unwind-protect
3096            (save-excursion
3097              ,@forms)
3098          (gnus-restore-hidden-threads-configuration ,config)))))
3099 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3100 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3101
3102 (defun gnus-data-compute-positions ()
3103   "Compute the positions of all articles."
3104   (setq gnus-newsgroup-data-reverse nil)
3105   (let ((data gnus-newsgroup-data))
3106     (save-excursion
3107       (gnus-save-hidden-threads
3108         (gnus-summary-show-all-threads)
3109         (goto-char (point-min))
3110         (while data
3111           (while (get-text-property (point) 'gnus-intangible)
3112             (forward-line 1))
3113           (gnus-data-set-pos (car data) (+ (point) 3))
3114           (setq data (cdr data))
3115           (forward-line 1))))))
3116
3117 (defun gnus-hidden-threads-configuration ()
3118   "Return the current hidden threads configuration."
3119   (save-excursion
3120     (let (config)
3121       (goto-char (point-min))
3122       (while (search-forward "\r" nil t)
3123         (push (1- (point)) config))
3124       config)))
3125
3126 (defun gnus-restore-hidden-threads-configuration (config)
3127   "Restore hidden threads configuration from CONFIG."
3128   (save-excursion
3129     (let (point buffer-read-only)
3130       (while (setq point (pop config))
3131         (when (and (< point (point-max))
3132                    (goto-char point)
3133                    (eq (char-after) ?\n))
3134           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3135
3136 ;; Various summary mode internalish functions.
3137
3138 (defun gnus-mouse-pick-article (e)
3139   (interactive "e")
3140   (mouse-set-point e)
3141   (gnus-summary-next-page nil t))
3142
3143 (defun gnus-summary-set-display-table ()
3144   "Change the display table.
3145 Odd characters have a tendency to mess
3146 up nicely formatted displays - we make all possible glyphs
3147 display only a single character."
3148
3149   ;; We start from the standard display table, if any.
3150   (let ((table (or (copy-sequence standard-display-table)
3151                    (make-display-table)))
3152         (i 32))
3153     ;; Nix out all the control chars...
3154     (while (>= (setq i (1- i)) 0)
3155       (aset table i [??]))
3156    ;; ... but not newline and cr, of course.  (cr is necessary for the
3157     ;; selective display).
3158     (aset table ?\n nil)
3159     (aset table ?\r nil)
3160     ;; We keep TAB as well.
3161     (aset table ?\t nil)
3162     ;; We nix out any glyphs over 126 that are not set already.
3163     (let ((i 256))
3164       (while (>= (setq i (1- i)) 127)
3165         ;; Only modify if the entry is nil.
3166         (unless (aref table i)
3167           (aset table i [??]))))
3168     (setq buffer-display-table table)))
3169
3170 (defun gnus-summary-set-article-display-arrow (pos)
3171   "Update the overlay arrow to point to line at position POS."
3172   (when (and gnus-summary-display-arrow
3173              (boundp 'overlay-arrow-position)
3174              (boundp 'overlay-arrow-string))
3175     (save-excursion
3176       (goto-char pos)
3177       (beginning-of-line)
3178       (unless overlay-arrow-position
3179         (setq overlay-arrow-position (make-marker)))
3180       (setq overlay-arrow-string "=>"
3181             overlay-arrow-position (set-marker overlay-arrow-position
3182                                                (point)
3183                                                (current-buffer))))))
3184
3185 (defun gnus-summary-setup-buffer (group)
3186   "Initialize summary buffer."
3187   (let ((buffer (gnus-summary-buffer-name group))
3188         (dead-name (concat "*Dead Summary "
3189                            (gnus-group-decoded-name group) "*")))
3190     ;; If a dead summary buffer exists, we kill it.
3191     (when (gnus-buffer-live-p dead-name)
3192       (gnus-kill-buffer dead-name))
3193     (if (get-buffer buffer)
3194         (progn
3195           (set-buffer buffer)
3196           (setq gnus-summary-buffer (current-buffer))
3197           (not gnus-newsgroup-prepared))
3198       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3199       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3200       (gnus-summary-mode group)
3201       (when gnus-carpal
3202         (gnus-carpal-setup-buffer 'summary))
3203       (unless gnus-single-article-buffer
3204         (make-local-variable 'gnus-article-buffer)
3205         (make-local-variable 'gnus-article-current)
3206         (make-local-variable 'gnus-original-article-buffer))
3207       (setq gnus-newsgroup-name group)
3208       ;; Set any local variables in the group parameters.
3209       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3210       t)))
3211
3212 (defun gnus-set-global-variables ()
3213   "Set the global equivalents of the buffer-local variables.
3214 They are set to the latest values they had.  These reflect the summary
3215 buffer that was in action when the last article was fetched."
3216   (when (eq major-mode 'gnus-summary-mode)
3217     (setq gnus-summary-buffer (current-buffer))
3218     (let ((name gnus-newsgroup-name)
3219           (marked gnus-newsgroup-marked)
3220           (spam gnus-newsgroup-spam-marked)
3221           (unread gnus-newsgroup-unreads)
3222           (headers gnus-current-headers)
3223           (data gnus-newsgroup-data)
3224           (summary gnus-summary-buffer)
3225           (article-buffer gnus-article-buffer)
3226           (original gnus-original-article-buffer)
3227           (gac gnus-article-current)
3228           (reffed gnus-reffed-article-number)
3229           (score-file gnus-current-score-file)
3230           (default-charset gnus-newsgroup-charset)
3231           vlist)
3232       (let ((locals gnus-newsgroup-variables))
3233         (while locals
3234           (if (consp (car locals))
3235               (push (eval (caar locals)) vlist)
3236             (push (eval (car locals)) vlist))
3237           (setq locals (cdr locals)))
3238         (setq vlist (nreverse vlist)))
3239       (with-current-buffer gnus-group-buffer
3240         (setq gnus-newsgroup-name name
3241               gnus-newsgroup-marked marked
3242               gnus-newsgroup-spam-marked spam
3243               gnus-newsgroup-unreads unread
3244               gnus-current-headers headers
3245               gnus-newsgroup-data data
3246               gnus-article-current gac
3247               gnus-summary-buffer summary
3248               gnus-article-buffer article-buffer
3249               gnus-original-article-buffer original
3250               gnus-reffed-article-number reffed
3251               gnus-current-score-file score-file
3252               gnus-newsgroup-charset default-charset)
3253         (let ((locals gnus-newsgroup-variables))
3254           (while locals
3255             (if (consp (car locals))
3256                 (set (caar locals) (pop vlist))
3257               (set (car locals) (pop vlist)))
3258             (setq locals (cdr locals))))
3259         ;; The article buffer also has local variables.
3260         (when (gnus-buffer-live-p gnus-article-buffer)
3261           (set-buffer gnus-article-buffer)
3262           (setq gnus-summary-buffer summary))))))
3263
3264 (defun gnus-summary-article-unread-p (article)
3265   "Say whether ARTICLE is unread or not."
3266   (memq article gnus-newsgroup-unreads))
3267
3268 (defun gnus-summary-first-article-p (&optional article)
3269   "Return whether ARTICLE is the first article in the buffer."
3270   (if (not (setq article (or article (gnus-summary-article-number))))
3271       nil
3272     (eq article (caar gnus-newsgroup-data))))
3273
3274 (defun gnus-summary-last-article-p (&optional article)
3275   "Return whether ARTICLE is the last article in the buffer."
3276   (if (not (setq article (or article (gnus-summary-article-number))))
3277       ;; All non-existent numbers are the last article.  :-)
3278       t
3279     (not (cdr (gnus-data-find-list article)))))
3280
3281 (defun gnus-make-thread-indent-array ()
3282   (let ((n 200))
3283     (unless (and gnus-thread-indent-array
3284                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3285       (setq gnus-thread-indent-array (make-vector 201 "")
3286             gnus-thread-indent-array-level gnus-thread-indent-level)
3287       (while (>= n 0)
3288         (aset gnus-thread-indent-array n
3289               (make-string (* n gnus-thread-indent-level) ? ))
3290         (setq n (1- n))))))
3291
3292 (defun gnus-update-summary-mark-positions ()
3293   "Compute where the summary marks are to go."
3294   (save-excursion
3295     (when (gnus-buffer-exists-p gnus-summary-buffer)
3296       (set-buffer gnus-summary-buffer))
3297     (let ((spec gnus-summary-line-format-spec)
3298           pos)
3299       (save-excursion
3300         (gnus-set-work-buffer)
3301         (let ((gnus-tmp-unread ?Z)
3302               (gnus-replied-mark ?Z)
3303               (gnus-score-below-mark ?Z)
3304               (gnus-score-over-mark ?Z)
3305               (gnus-undownloaded-mark ?Z)
3306               (gnus-summary-line-format-spec spec)
3307               (gnus-newsgroup-downloadable '(0))
3308               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3309               case-fold-search ignores)
3310           ;; Here, all marks are bound to Z.
3311           (gnus-summary-insert-line header
3312                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3313           (goto-char (point-min))
3314           ;; Memorize the positions of the same characters as dummy marks.
3315           (while (re-search-forward "[A-D]" nil t)
3316             (push (point) ignores))
3317           (erase-buffer)
3318           ;; We use A-D as dummy marks in order to know column positions
3319           ;; where marks should be inserted.
3320           (setq gnus-tmp-unread ?A
3321                 gnus-replied-mark ?B
3322                 gnus-score-below-mark ?C
3323                 gnus-score-over-mark ?C
3324                 gnus-undownloaded-mark ?D)
3325           (gnus-summary-insert-line header
3326                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3327           ;; Ignore characters which aren't dummy marks.
3328           (dolist (p ignores)
3329             (delete-region (goto-char (1- p)) p)
3330             (insert ?Z))
3331           (goto-char (point-min))
3332           (setq pos (list (cons 'unread
3333                                 (and (search-forward "A" nil t)
3334                                      (- (point) (point-min) 1)))))
3335           (goto-char (point-min))
3336           (push (cons 'replied (and (search-forward "B" nil t)
3337                                     (- (point) (point-min) 1)))
3338                 pos)
3339           (goto-char (point-min))
3340           (push (cons 'score (and (search-forward "C" nil t)
3341                                   (- (point) (point-min) 1)))
3342                 pos)
3343           (goto-char (point-min))
3344           (push (cons 'download (and (search-forward "D" nil t)
3345                                      (- (point) (point-min) 1)))
3346                 pos)))
3347       (setq gnus-summary-mark-positions pos))))
3348
3349 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3350   "Insert a dummy root in the summary buffer."
3351   (beginning-of-line)
3352   (gnus-add-text-properties
3353    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3354    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3355
3356 (defun gnus-summary-extract-address-component (from)
3357   (or (car (funcall gnus-extract-address-components from))
3358       from))
3359
3360 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3361   (let ((mail-parse-charset gnus-newsgroup-charset)
3362         ; Is it really necessary to do this next part for each summary line?
3363         ; Luckily, doesn't seem to slow things down much.
3364         (mail-parse-ignored-charsets
3365          (with-current-buffer gnus-summary-buffer
3366            gnus-newsgroup-ignored-charsets)))
3367     (or
3368      (and gnus-ignored-from-addresses
3369           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3370           (let ((extra-headers (mail-header-extra header))
3371                 to
3372                 newsgroups)
3373             (cond
3374              ((setq to (cdr (assq 'To extra-headers)))
3375               (concat "-> "
3376                       (inline
3377                         (gnus-summary-extract-address-component
3378                          (funcall gnus-decode-encoded-word-function to)))))
3379              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3380               (concat "=> " newsgroups)))))
3381      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3382
3383 (defun gnus-summary-insert-line (gnus-tmp-header
3384                                  gnus-tmp-level gnus-tmp-current
3385                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3386                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3387                                  &optional gnus-tmp-dummy gnus-tmp-score
3388                                  gnus-tmp-process)
3389   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3390          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3391          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3392          (gnus-tmp-score-char
3393           (if (or (null gnus-summary-default-score)
3394                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3395                       gnus-summary-zcore-fuzz))
3396               ?                         ;Whitespace
3397             (if (< gnus-tmp-score gnus-summary-default-score)
3398                 gnus-score-below-mark gnus-score-over-mark)))
3399          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3400          (gnus-tmp-replied
3401           (cond (gnus-tmp-process gnus-process-mark)
3402                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3403                  gnus-cached-mark)
3404                 (gnus-tmp-replied gnus-replied-mark)
3405                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3406                  gnus-forwarded-mark)
3407                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3408                  gnus-saved-mark)
3409                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3410                  gnus-recent-mark)
3411                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3412                  gnus-unseen-mark)
3413                 (t gnus-no-mark)))
3414          (gnus-tmp-downloaded
3415           (cond (undownloaded
3416                  gnus-undownloaded-mark)
3417                 (gnus-newsgroup-agentized
3418                  gnus-downloaded-mark)
3419                 (t
3420                  gnus-no-mark)))
3421          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3422          (gnus-tmp-name
3423           (cond
3424            ((string-match "<[^>]+> *$" gnus-tmp-from)
3425             (let ((beg (match-beginning 0)))
3426               (or (and (string-match "^\".+\"" gnus-tmp-from)
3427                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3428                   (substring gnus-tmp-from 0 beg))))
3429            ((string-match "(.+)" gnus-tmp-from)
3430             (substring gnus-tmp-from
3431                        (1+ (match-beginning 0)) (1- (match-end 0))))
3432            (t gnus-tmp-from)))
3433          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3434          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3435          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3436          (buffer-read-only nil))
3437     (when (string= gnus-tmp-name "")
3438       (setq gnus-tmp-name gnus-tmp-from))
3439     (unless (numberp gnus-tmp-lines)
3440       (setq gnus-tmp-lines -1))
3441     (if (= gnus-tmp-lines -1)
3442         (setq gnus-tmp-lines "?")
3443       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3444       (gnus-put-text-property
3445      (point)
3446      (progn (eval gnus-summary-line-format-spec) (point))
3447        'gnus-number gnus-tmp-number)
3448     (when (gnus-visual-p 'summary-highlight 'highlight)
3449       (forward-line -1)
3450       (gnus-run-hooks 'gnus-summary-update-hook)
3451       (forward-line 1))))
3452
3453 (defun gnus-summary-update-line (&optional dont-update)
3454   "Update summary line after change."
3455   (when (and gnus-summary-default-score
3456              (not gnus-summary-inhibit-highlight))
3457     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3458            (article (gnus-summary-article-number))
3459            (score (gnus-summary-article-score article)))
3460       (unless dont-update
3461         (if (and gnus-summary-mark-below
3462                  (< (gnus-summary-article-score)
3463                     gnus-summary-mark-below))
3464             ;; This article has a low score, so we mark it as read.
3465             (when (memq article gnus-newsgroup-unreads)
3466               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3467           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3468             ;; This article was previously marked as read on account
3469             ;; of a low score, but now it has risen, so we mark it as
3470             ;; unread.
3471             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3472         (gnus-summary-update-mark
3473          (if (or (null gnus-summary-default-score)
3474                  (<= (abs (- score gnus-summary-default-score))
3475                      gnus-summary-zcore-fuzz))
3476              ?                          ;Whitespace
3477            (if (< score gnus-summary-default-score)
3478                gnus-score-below-mark gnus-score-over-mark))
3479          'score))
3480       ;; Do visual highlighting.
3481       (when (gnus-visual-p 'summary-highlight 'highlight)
3482         (gnus-run-hooks 'gnus-summary-update-hook)))))
3483
3484 (defvar gnus-tmp-new-adopts nil)
3485
3486 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3487   "Return the number of articles in THREAD.
3488 This may be 0 in some cases -- if none of the articles in
3489 the thread are to be displayed."
3490   (let* ((number
3491          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3492           (cond
3493            ((not (listp thread))
3494             1)
3495            ((and (consp thread) (cdr thread))
3496             (apply
3497              '+ 1 (mapcar
3498                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3499            ((null thread)
3500             1)
3501            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3502             1)
3503            (t 0))))
3504     (when (and level (zerop level) gnus-tmp-new-adopts)
3505       (incf number
3506             (apply '+ (mapcar
3507                        'gnus-summary-number-of-articles-in-thread
3508                        gnus-tmp-new-adopts))))
3509     (if char
3510         (if (> number 1) gnus-not-empty-thread-mark
3511           gnus-empty-thread-mark)
3512       number)))
3513
3514 (defsubst gnus-summary-line-message-size (head)
3515   "Return pretty-printed version of message size.
3516 This function is intended to be used in
3517 `gnus-summary-line-format-alist'."
3518   (let ((c (or (mail-header-chars head) -1)))
3519     (cond ((< c 0) "n/a")               ; chars not available
3520           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3521           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3522           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3523           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3524
3525
3526 (defun gnus-summary-set-local-parameters (group)
3527   "Go through the local params of GROUP and set all variable specs in that list."
3528   (let ((vars '(quit-config)))          ; Ignore quit-config.
3529     (dolist (elem (gnus-group-find-parameter group))
3530       (and (consp elem)                 ; Has to be a cons.
3531            (consp (cdr elem))           ; The cdr has to be a list.
3532            (symbolp (car elem))         ; Has to be a symbol in there.
3533            (not (memq (car elem) vars))
3534            (ignore-errors               ; So we set it.
3535              (push (car elem) vars)
3536              (make-local-variable (car elem))
3537              (set (car elem) (eval (nth 1 elem))))))))
3538
3539 (defun gnus-summary-read-group (group &optional show-all no-article
3540                                       kill-buffer no-display backward
3541                                       select-articles)
3542   "Start reading news in newsgroup GROUP.
3543 If SHOW-ALL is non-nil, already read articles are also listed.
3544 If NO-ARTICLE is non-nil, no article is selected initially.
3545 If NO-DISPLAY, don't generate a summary buffer."
3546   (let (result)
3547     (while (and group
3548                 (null (setq result
3549                             (let ((gnus-auto-select-next nil))
3550                               (or (gnus-summary-read-group-1
3551                                    group show-all no-article
3552                                    kill-buffer no-display
3553                                    select-articles)
3554                                   (setq show-all nil
3555                                         select-articles nil)))))
3556                 (eq gnus-auto-select-next 'quietly))
3557       (set-buffer gnus-group-buffer)
3558       ;; The entry function called above goes to the next
3559       ;; group automatically, so we go two groups back
3560       ;; if we are searching for the previous group.
3561       (when backward
3562         (gnus-group-prev-unread-group 2))
3563       (if (not (equal group (gnus-group-group-name)))
3564           (setq group (gnus-group-group-name))
3565         (setq group nil)))
3566     result))
3567
3568 (defun gnus-summary-read-group-1 (group show-all no-article
3569                                         kill-buffer no-display
3570                                         &optional select-articles)
3571   ;; Killed foreign groups can't be entered.
3572   ;;  (when (and (not (gnus-group-native-p group))
3573   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3574   ;;    (error "Dead non-native groups can't be entered"))
3575   (gnus-message 5 "Retrieving newsgroup: %s..."
3576                 (gnus-group-decoded-name group))
3577   (let* ((new-group (gnus-summary-setup-buffer group))
3578          (quit-config (gnus-group-quit-config group))
3579          (did-select (and new-group (gnus-select-newsgroup
3580                                      group show-all select-articles))))
3581     (cond
3582      ;; This summary buffer exists already, so we just select it.
3583      ((not new-group)
3584       (gnus-set-global-variables)
3585       (when kill-buffer
3586         (gnus-kill-or-deaden-summary kill-buffer))
3587       (gnus-configure-windows 'summary 'force)
3588       (gnus-set-mode-line 'summary)
3589       (gnus-summary-position-point)
3590       (message "")
3591       t)
3592      ;; We couldn't select this group.
3593      ((null did-select)
3594       (when (and (eq major-mode 'gnus-summary-mode)
3595                  (not (equal (current-buffer) kill-buffer)))
3596         (kill-buffer (current-buffer))
3597         (if (not quit-config)
3598             (progn
3599               ;; Update the info -- marks might need to be removed,
3600               ;; for instance.
3601               (gnus-summary-update-info)
3602               (set-buffer gnus-group-buffer)
3603               (gnus-group-jump-to-group group)
3604               (gnus-group-next-unread-group 1))
3605           (gnus-handle-ephemeral-exit quit-config)))
3606       (let ((grpinfo (gnus-get-info group)))
3607         (if (null (gnus-info-read grpinfo))
3608             (gnus-message 3 "Group %s contains no messages"
3609                           (gnus-group-decoded-name group))
3610           (gnus-message 3 "Can't select group")))
3611       nil)
3612      ;; The user did a `C-g' while prompting for number of articles,
3613      ;; so we exit this group.
3614      ((eq did-select 'quit)
3615       (and (eq major-mode 'gnus-summary-mode)
3616            (not (equal (current-buffer) kill-buffer))
3617            (kill-buffer (current-buffer)))
3618       (when kill-buffer
3619         (gnus-kill-or-deaden-summary kill-buffer))
3620       (if (not quit-config)
3621           (progn
3622             (set-buffer gnus-group-buffer)
3623             (gnus-group-jump-to-group group)
3624             (gnus-group-next-unread-group 1)
3625             (gnus-configure-windows 'group 'force))
3626         (gnus-handle-ephemeral-exit quit-config))
3627       ;; Finally signal the quit.
3628       (signal 'quit nil))
3629      ;; The group was successfully selected.
3630      (t
3631       (gnus-set-global-variables)
3632       ;; Save the active value in effect when the group was entered.
3633       (setq gnus-newsgroup-active
3634             (gnus-copy-sequence
3635              (gnus-active gnus-newsgroup-name)))
3636       ;; You can change the summary buffer in some way with this hook.
3637       (gnus-run-hooks 'gnus-select-group-hook)
3638       (when (memq 'summary (gnus-update-format-specifications
3639                             nil 'summary 'summary-mode 'summary-dummy))
3640         ;; The format specification for the summary line was updated,
3641         ;; so we need to update the mark positions as well.
3642         (gnus-update-summary-mark-positions))
3643       ;; Do score processing.
3644       (when gnus-use-scoring
3645         (gnus-possibly-score-headers))
3646       ;; Check whether to fill in the gaps in the threads.
3647       (when gnus-build-sparse-threads
3648         (gnus-build-sparse-threads))
3649       ;; Find the initial limit.
3650       (if show-all
3651           (let ((gnus-newsgroup-dormant nil))
3652             (gnus-summary-initial-limit show-all))
3653         (gnus-summary-initial-limit show-all))
3654       ;; Generate the summary buffer.
3655       (unless no-display
3656         (gnus-summary-prepare))
3657       (when gnus-use-trees
3658         (gnus-tree-open group)
3659         (setq gnus-summary-highlight-line-function
3660               'gnus-tree-highlight-article))
3661       ;; If the summary buffer is empty, but there are some low-scored
3662       ;; articles or some excluded dormants, we include these in the
3663       ;; buffer.
3664       (when (and (zerop (buffer-size))
3665                  (not no-display))
3666         (cond (gnus-newsgroup-dormant
3667                (gnus-summary-limit-include-dormant))
3668               ((and gnus-newsgroup-scored show-all)
3669                (gnus-summary-limit-include-expunged t))))
3670       ;; Function `gnus-apply-kill-file' must be called in this hook.
3671       (gnus-run-hooks 'gnus-apply-kill-hook)
3672       (if (and (zerop (buffer-size))
3673                (not no-display))
3674           (progn
3675             ;; This newsgroup is empty.
3676             (gnus-summary-catchup-and-exit nil t)
3677             (gnus-message 6 "No unread news")
3678             (when kill-buffer
3679               (gnus-kill-or-deaden-summary kill-buffer))
3680             ;; Return nil from this function.
3681             nil)
3682         ;; Hide conversation thread subtrees.  We cannot do this in
3683         ;; gnus-summary-prepare-hook since kill processing may not
3684         ;; work with hidden articles.
3685         (gnus-summary-maybe-hide-threads)
3686         (when kill-buffer
3687           (gnus-kill-or-deaden-summary kill-buffer))
3688         (gnus-summary-auto-select-subject)
3689         ;; Show first unread article if requested.
3690         (if (and (not no-article)
3691                  (not no-display)
3692                  gnus-newsgroup-unreads
3693                  gnus-auto-select-first)
3694             (progn
3695               (gnus-configure-windows 'summary)
3696               (let ((art (gnus-summary-article-number)))
3697                 (unless (and (not gnus-plugged)
3698                              (or (memq art gnus-newsgroup-undownloaded)
3699                                  (memq art gnus-newsgroup-downloadable)))
3700                   (gnus-summary-goto-article art))))
3701           ;; Don't select any articles.
3702           (gnus-summary-position-point)
3703           (gnus-configure-windows 'summary 'force)
3704           (gnus-set-mode-line 'summary))
3705         (when (and gnus-auto-center-group
3706                    (get-buffer-window gnus-group-buffer t))
3707           ;; Gotta use windows, because recenter does weird stuff if
3708           ;; the current buffer ain't the displayed window.
3709           (let ((owin (selected-window)))
3710             (select-window (get-buffer-window gnus-group-buffer t))
3711             (when (gnus-group-goto-group group)
3712               (recenter))
3713             (select-window owin)))
3714         ;; Mark this buffer as "prepared".
3715         (setq gnus-newsgroup-prepared t)
3716         (gnus-run-hooks 'gnus-summary-prepared-hook)
3717         (unless (gnus-ephemeral-group-p group)
3718           (gnus-group-update-group group))
3719         t)))))
3720
3721 (defun gnus-summary-auto-select-subject ()
3722   "Select the subject line on initial group entry."
3723   (goto-char (point-min))
3724   (cond
3725    ((eq gnus-auto-select-subject 'best)
3726     (gnus-summary-best-unread-subject))
3727    ((eq gnus-auto-select-subject 'unread)
3728     (gnus-summary-first-unread-subject))
3729    ((eq gnus-auto-select-subject 'unseen)
3730     (gnus-summary-first-unseen-subject))
3731    ((eq gnus-auto-select-subject 'unseen-or-unread)
3732     (gnus-summary-first-unseen-or-unread-subject))
3733    ((eq gnus-auto-select-subject 'first)
3734     ;; Do nothing.
3735     )
3736    ((functionp gnus-auto-select-subject)
3737     (funcall gnus-auto-select-subject))))
3738
3739 (defun gnus-summary-prepare ()
3740   "Generate the summary buffer."
3741   (interactive)
3742   (let ((buffer-read-only nil))
3743     (erase-buffer)
3744     (setq gnus-newsgroup-data nil
3745           gnus-newsgroup-data-reverse nil)
3746     (gnus-run-hooks 'gnus-summary-generate-hook)
3747     ;; Generate the buffer, either with threads or without.
3748     (when gnus-newsgroup-headers
3749       (gnus-summary-prepare-threads
3750        (if gnus-show-threads
3751            (gnus-sort-gathered-threads
3752             (funcall gnus-summary-thread-gathering-function
3753                      (gnus-sort-threads
3754                       (gnus-cut-threads (gnus-make-threads)))))
3755          ;; Unthreaded display.
3756          (gnus-sort-articles gnus-newsgroup-headers))))
3757     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3758     ;; Call hooks for modifying summary buffer.
3759     (goto-char (point-min))
3760     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3761
3762 (defsubst gnus-general-simplify-subject (subject)
3763   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3764   (setq subject
3765         (cond
3766          ;; Truncate the subject.
3767          (gnus-simplify-subject-functions
3768           (gnus-map-function gnus-simplify-subject-functions subject))
3769          ((numberp gnus-summary-gather-subject-limit)
3770           (setq subject (gnus-simplify-subject-re subject))
3771           (if (> (length subject) gnus-summary-gather-subject-limit)
3772               (substring subject 0 gnus-summary-gather-subject-limit)
3773             subject))
3774          ;; Fuzzily simplify it.
3775          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3776           (gnus-simplify-subject-fuzzy subject))
3777          ;; Just remove the leading "Re:".
3778          (t
3779           (gnus-simplify-subject-re subject))))
3780
3781   (if (and gnus-summary-gather-exclude-subject
3782            (string-match gnus-summary-gather-exclude-subject subject))
3783       nil                         ; This article shouldn't be gathered
3784     subject))
3785
3786 (defun gnus-summary-simplify-subject-query ()
3787   "Query where the respool algorithm would put this article."
3788   (interactive)
3789   (gnus-summary-select-article)
3790   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3791
3792 (defun gnus-gather-threads-by-subject (threads)
3793   "Gather threads by looking at Subject headers."
3794   (if (not gnus-summary-make-false-root)
3795       threads
3796     (let ((hashtb (gnus-make-hashtable 1024))
3797           (prev threads)
3798           (result threads)
3799           subject hthread whole-subject)
3800       (while threads
3801         (setq subject (gnus-general-simplify-subject
3802                        (setq whole-subject (mail-header-subject
3803                                             (caar threads)))))
3804         (when subject
3805           (if (setq hthread (gnus-gethash subject hashtb))
3806               (progn
3807                 ;; We enter a dummy root into the thread, if we
3808                 ;; haven't done that already.
3809                 (unless (stringp (caar hthread))
3810                   (setcar hthread (list whole-subject (car hthread))))
3811                 ;; We add this new gathered thread to this gathered
3812                 ;; thread.
3813                 (setcdr (car hthread)
3814                         (nconc (cdar hthread) (list (car threads))))
3815                 ;; Remove it from the list of threads.
3816                 (setcdr prev (cdr threads))
3817                 (setq threads prev))
3818             ;; Enter this thread into the hash table.
3819             (gnus-sethash subject
3820                           (if gnus-summary-make-false-root-always
3821                               (progn
3822                                 ;; If you want a dummy root above all
3823                                 ;; threads...
3824                                 (setcar threads (list whole-subject
3825                                                       (car threads)))
3826                                 threads)
3827                             threads)
3828                           hashtb)))
3829         (setq prev threads)
3830         (setq threads (cdr threads)))
3831       result)))
3832
3833 (defun gnus-gather-threads-by-references (threads)
3834   "Gather threads by looking at References headers."
3835   (let ((idhashtb (gnus-make-hashtable 1024))
3836         (thhashtb (gnus-make-hashtable 1024))
3837         (prev threads)
3838         (result threads)
3839         ids references id gthread gid entered ref)
3840     (while threads
3841       (when (setq references (mail-header-references (caar threads)))
3842         (setq id (mail-header-id (caar threads))
3843               ids (inline (gnus-split-references references))
3844               entered nil)
3845         (while (setq ref (pop ids))
3846           (setq ids (delete ref ids))
3847           (if (not (setq gid (gnus-gethash ref idhashtb)))
3848               (progn
3849                 (gnus-sethash ref id idhashtb)
3850                 (gnus-sethash id threads thhashtb))
3851             (setq gthread (gnus-gethash gid thhashtb))
3852             (unless entered
3853               ;; We enter a dummy root into the thread, if we
3854               ;; haven't done that already.
3855               (unless (stringp (caar gthread))
3856                 (setcar gthread (list (mail-header-subject (caar gthread))
3857                                       (car gthread))))
3858               ;; We add this new gathered thread to this gathered
3859               ;; thread.
3860               (setcdr (car gthread)
3861                       (nconc (cdar gthread) (list (car threads)))))
3862             ;; Add it into the thread hash table.
3863             (gnus-sethash id gthread thhashtb)
3864             (setq entered t)
3865             ;; Remove it from the list of threads.
3866             (setcdr prev (cdr threads))
3867             (setq threads prev))))
3868       (setq prev threads)
3869       (setq threads (cdr threads)))
3870     result))
3871
3872 (defun gnus-sort-gathered-threads (threads)
3873   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3874   (let ((result threads))
3875     (while threads
3876       (when (stringp (caar threads))
3877         (setcdr (car threads)
3878                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3879       (setq threads (cdr threads)))
3880     result))
3881
3882 (defun gnus-thread-loop-p (root thread)
3883   "Say whether ROOT is in THREAD."
3884   (let ((stack (list thread))
3885         (infloop 0)
3886         th)
3887     (while (setq thread (pop stack))
3888       (setq th (cdr thread))
3889       (while (and th
3890                   (not (eq (caar th) root)))
3891         (pop th))
3892       (if th
3893           ;; We have found a loop.
3894           (let (ref-dep)
3895             (setcdr thread (delq (car th) (cdr thread)))
3896             (if (boundp (setq ref-dep (intern "none"
3897                                               gnus-newsgroup-dependencies)))
3898                 (setcdr (symbol-value ref-dep)
3899                         (nconc (cdr (symbol-value ref-dep))
3900                                (list (car th))))
3901               (set ref-dep (list nil (car th))))
3902             (setq infloop 1
3903                   stack nil))
3904         ;; Push all the subthreads onto the stack.
3905         (push (cdr thread) stack)))
3906     infloop))
3907
3908 (defun gnus-make-threads ()
3909   "Go through the dependency hashtb and find the roots.  Return all threads."
3910   (let (threads)
3911     (while (catch 'infloop
3912              (mapatoms
3913               (lambda (refs)
3914                 ;; Deal with self-referencing References loops.
3915                 (when (and (car (symbol-value refs))
3916                            (not (zerop
3917                                  (apply
3918                                   '+
3919                                   (mapcar
3920                                    (lambda (thread)
3921                                      (gnus-thread-loop-p
3922                                       (car (symbol-value refs)) thread))
3923                                    (cdr (symbol-value refs)))))))
3924                   (setq threads nil)
3925                   (throw 'infloop t))
3926                 (unless (car (symbol-value refs))
3927                   ;; These threads do not refer back to any other
3928                   ;; articles, so they're roots.
3929                   (setq threads (append (cdr (symbol-value refs)) threads))))
3930               gnus-newsgroup-dependencies)))
3931     threads))
3932
3933 ;; Build the thread tree.
3934 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3935   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3936
3937 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3938 if it was already present.
3939
3940 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3941 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3942 Message-IDs will be renamed to a unique Message-ID before being
3943 entered.
3944
3945 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3946   (let* ((id (mail-header-id header))
3947          (id-dep (and id (intern id dependencies)))
3948          parent-id ref ref-dep ref-header replaced)
3949     ;; Enter this `header' in the `dependencies' table.
3950     (cond
3951      ((not id-dep)
3952       (setq header nil))
3953      ;; The first two cases do the normal part: enter a new `header'
3954      ;; in the `dependencies' table.
3955      ((not (boundp id-dep))
3956       (set id-dep (list header)))
3957      ((null (car (symbol-value id-dep)))
3958       (setcar (symbol-value id-dep) header))
3959
3960      ;; From here the `header' was already present in the
3961      ;; `dependencies' table.
3962      (force-new
3963       ;; Overrides an existing entry;
3964       ;; just set the header part of the entry.
3965       (setcar (symbol-value id-dep) header)
3966       (setq replaced t))
3967
3968      ;; Renames the existing `header' to a unique Message-ID.
3969      ((not gnus-summary-ignore-duplicates)
3970       ;; An article with this Message-ID has already been seen.
3971       ;; We rename the Message-ID.
3972       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3973            (list header))
3974       (mail-header-set-id header id))
3975
3976      ;; The last case ignores an existing entry, except it adds any
3977      ;; additional Xrefs (in case the two articles came from different
3978      ;; servers.
3979      ;; Also sets `header' to `nil' meaning that the `dependencies'
3980      ;; table was *not* modified.
3981      (t
3982       (mail-header-set-xref
3983        (car (symbol-value id-dep))
3984        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3985                    "")
3986                (or (mail-header-xref header) "")))
3987       (setq header nil)))
3988
3989     (when (and header (not replaced))
3990       ;; First check that we are not creating a References loop.
3991       (setq parent-id (gnus-parent-id (mail-header-references header)))
3992       (setq ref parent-id)
3993       (while (and ref
3994                   (setq ref-dep (intern-soft ref dependencies))
3995                   (boundp ref-dep)
3996                   (setq ref-header (car (symbol-value ref-dep))))
3997         (if (string= id ref)
3998             ;; Yuk!  This is a reference loop.  Make the article be a
3999             ;; root article.
4000             (progn
4001               (mail-header-set-references (car (symbol-value id-dep)) "none")
4002               (setq ref nil)
4003               (setq parent-id nil))
4004           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4005       (setq ref-dep (intern (or parent-id "none") dependencies))
4006       (if (boundp ref-dep)
4007           (setcdr (symbol-value ref-dep)
4008                   (nconc (cdr (symbol-value ref-dep))
4009                          (list (symbol-value id-dep))))
4010         (set ref-dep (list nil (symbol-value id-dep)))))
4011     header))
4012
4013 (defun gnus-extract-message-id-from-in-reply-to (string)
4014   (if (string-match "<[^>]+>" string)
4015       (substring string (match-beginning 0) (match-end 0))
4016     nil))
4017
4018 (defun gnus-build-sparse-threads ()
4019   (let ((headers gnus-newsgroup-headers)
4020         (mail-parse-charset gnus-newsgroup-charset)
4021         (gnus-summary-ignore-duplicates t)
4022         header references generation relations
4023         subject child end new-child date)
4024     ;; First we create an alist of generations/relations, where
4025     ;; generations is how much we trust the relation, and the relation
4026     ;; is parent/child.
4027     (gnus-message 7 "Making sparse threads...")
4028     (save-excursion
4029       (nnheader-set-temp-buffer " *gnus sparse threads*")
4030       (while (setq header (pop headers))
4031         (when (and (setq references (mail-header-references header))
4032                    (not (string= references "")))
4033           (insert references)
4034           (setq child (mail-header-id header)
4035                 subject (mail-header-subject header)
4036                 date (mail-header-date header)
4037                 generation 0)
4038           (while (search-backward ">" nil t)
4039             (setq end (1+ (point)))
4040             (when (search-backward "<" nil t)
4041               (setq new-child (buffer-substring (point) end))
4042               (push (list (incf generation)
4043                           child (setq child new-child)
4044                           subject date)
4045                     relations)))
4046           (when child
4047             (push (list (1+ generation) child nil subject) relations))
4048           (erase-buffer)))
4049       (kill-buffer (current-buffer)))
4050     ;; Sort over trustworthiness.
4051     (mapcar
4052      (lambda (relation)
4053        (when (gnus-dependencies-add-header
4054               (make-full-mail-header
4055                gnus-reffed-article-number
4056                (nth 3 relation) "" (or (nth 4 relation) "")
4057                (nth 1 relation)
4058                (or (nth 2 relation) "") 0 0 "")
4059               gnus-newsgroup-dependencies nil)
4060          (push gnus-reffed-article-number gnus-newsgroup-limit)
4061          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4062          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4063                gnus-newsgroup-reads)
4064          (decf gnus-reffed-article-number)))
4065      (sort relations 'car-less-than-car))
4066     (gnus-message 7 "Making sparse threads...done")))
4067
4068 (defun gnus-build-old-threads ()
4069   ;; Look at all the articles that refer back to old articles, and
4070   ;; fetch the headers for the articles that aren't there.  This will
4071   ;; build complete threads - if the roots haven't been expired by the
4072   ;; server, that is.
4073   (let ((mail-parse-charset gnus-newsgroup-charset)
4074         id heads)
4075     (mapatoms
4076      (lambda (refs)
4077        (when (not (car (symbol-value refs)))
4078          (setq heads (cdr (symbol-value refs)))
4079          (while heads
4080            (if (memq (mail-header-number (caar heads))
4081                      gnus-newsgroup-dormant)
4082                (setq heads (cdr heads))
4083              (setq id (symbol-name refs))
4084              (while (and (setq id (gnus-build-get-header id))
4085                          (not (car (gnus-id-to-thread id)))))
4086              (setq heads nil)))))
4087      gnus-newsgroup-dependencies)))
4088
4089 (defsubst gnus-remove-odd-characters (string)
4090   "Translate STRING into something that doesn't contain weird characters."
4091   (mm-subst-char-in-string
4092    ?\r ?\-
4093    (mm-subst-char-in-string ?\n ?\- string t) t))
4094
4095 ;; This function has to be called with point after the article number
4096 ;; on the beginning of the line.
4097 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4098   (let ((eol (point-at-eol))
4099         (buffer (current-buffer))
4100         header references in-reply-to)
4101
4102     ;; overview: [num subject from date id refs chars lines misc]
4103     (unwind-protect
4104         (let (x)
4105           (narrow-to-region (point) eol)
4106           (unless (eobp)
4107             (forward-char))
4108
4109           (setq header
4110                 (make-full-mail-header
4111                  number                 ; number
4112                  (condition-case ()     ; subject
4113                      (gnus-remove-odd-characters
4114                       (funcall gnus-decode-encoded-word-function
4115                                (setq x (nnheader-nov-field))))
4116                    (error x))
4117                  (condition-case ()     ; from
4118                      (gnus-remove-odd-characters
4119                       (funcall gnus-decode-encoded-word-function
4120                                (setq x (nnheader-nov-field))))
4121                    (error x))
4122                  (nnheader-nov-field)   ; date
4123                  (nnheader-nov-read-message-id number)  ; id
4124                  (setq references (nnheader-nov-field)) ; refs
4125                  (nnheader-nov-read-integer) ; chars
4126                  (nnheader-nov-read-integer) ; lines
4127                  (unless (eobp)
4128                    (if (looking-at "Xref: ")
4129                        (goto-char (match-end 0)))
4130                    (nnheader-nov-field)) ; Xref
4131                  (nnheader-nov-parse-extra)))) ; extra
4132
4133       (widen))
4134
4135     (when (and (string= references "")
4136                (setq in-reply-to (mail-header-extra header))
4137                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4138       (mail-header-set-references
4139        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4140
4141     (when gnus-alter-header-function
4142       (funcall gnus-alter-header-function header))
4143     (gnus-dependencies-add-header header dependencies force-new)))
4144
4145 (defun gnus-build-get-header (id)
4146   "Look through the buffer of NOV lines and find the header to ID.
4147 Enter this line into the dependencies hash table, and return
4148 the id of the parent article (if any)."
4149   (let ((deps gnus-newsgroup-dependencies)
4150         found header)
4151     (prog1
4152         (save-excursion
4153           (set-buffer nntp-server-buffer)
4154           (let ((case-fold-search nil))
4155             (goto-char (point-min))
4156             (while (and (not found)
4157                         (search-forward id nil t))
4158               (beginning-of-line)
4159               (setq found (looking-at
4160                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4161                                    (regexp-quote id))))
4162               (or found (beginning-of-line 2)))
4163             (when found
4164               (beginning-of-line)
4165               (and
4166                (setq header (gnus-nov-parse-line
4167                              (read (current-buffer)) deps))
4168                (gnus-parent-id (mail-header-references header))))))
4169       (when header
4170         (let ((number (mail-header-number header)))
4171           (push number gnus-newsgroup-limit)
4172           (push header gnus-newsgroup-headers)
4173           (if (memq number gnus-newsgroup-unselected)
4174               (progn
4175                 (setq gnus-newsgroup-unreads
4176                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4177                                                number))
4178                 (setq gnus-newsgroup-unselected
4179                       (delq number gnus-newsgroup-unselected)))
4180             (push number gnus-newsgroup-ancient)))))))
4181
4182 (defun gnus-build-all-threads ()
4183   "Read all the headers."
4184   (let ((gnus-summary-ignore-duplicates t)
4185         (mail-parse-charset gnus-newsgroup-charset)
4186         (dependencies gnus-newsgroup-dependencies)
4187         header article)
4188     (save-excursion
4189       (set-buffer nntp-server-buffer)
4190       (let ((case-fold-search nil))
4191         (goto-char (point-min))
4192         (while (not (eobp))
4193           (ignore-errors
4194             (setq article (read (current-buffer))
4195                   header (gnus-nov-parse-line article dependencies)))
4196           (when header
4197             (with-current-buffer gnus-summary-buffer
4198               (push header gnus-newsgroup-headers)
4199               (if (memq (setq article (mail-header-number header))
4200                         gnus-newsgroup-unselected)
4201                   (progn
4202                     (setq gnus-newsgroup-unreads
4203                           (gnus-add-to-sorted-list
4204                            gnus-newsgroup-unreads article))
4205                     (setq gnus-newsgroup-unselected
4206                           (delq article gnus-newsgroup-unselected)))
4207                 (push article gnus-newsgroup-ancient)))
4208             (forward-line 1)))))))
4209
4210 (defun gnus-summary-update-article-line (article header)
4211   "Update the line for ARTICLE using HEADER."
4212   (let* ((id (mail-header-id header))
4213          (thread (gnus-id-to-thread id)))
4214     (unless thread
4215       (error "Article in no thread"))
4216     ;; Update the thread.
4217     (setcar thread header)
4218     (gnus-summary-goto-subject article)
4219     (let* ((datal (gnus-data-find-list article))
4220            (data (car datal))
4221            (buffer-read-only nil)
4222            (level (gnus-summary-thread-level)))
4223       (gnus-delete-line)
4224       (let ((inserted (- (point)
4225                          (progn
4226                            (gnus-summary-insert-line
4227                             header level nil
4228                             (memq article gnus-newsgroup-undownloaded)
4229                             (gnus-article-mark article)
4230                             (memq article gnus-newsgroup-replied)
4231                             (memq article gnus-newsgroup-expirable)
4232                             ;; Only insert the Subject string when it's different
4233                             ;; from the previous Subject string.
4234                             (if (and
4235                                  gnus-show-threads
4236                                  (gnus-subject-equal
4237                                   (condition-case ()
4238                                       (mail-header-subject
4239                                        (gnus-data-header
4240                                         (cadr
4241                                          (gnus-data-find-list
4242                                           article
4243                                           (gnus-data-list t)))))
4244                                     ;; Error on the side of excessive subjects.
4245                                     (error ""))
4246                                   (mail-header-subject header)))
4247                                 ""
4248                               (mail-header-subject header))
4249                             nil (cdr (assq article gnus-newsgroup-scored))
4250                             (memq article gnus-newsgroup-processable))
4251                            (point)))))
4252         (when (cdr datal)
4253           (gnus-data-update-list
4254            (cdr datal)
4255            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4256
4257 (defun gnus-summary-update-article (article &optional iheader)
4258   "Update ARTICLE in the summary buffer."
4259   (set-buffer gnus-summary-buffer)
4260   (let* ((header (gnus-summary-article-header article))
4261          (id (mail-header-id header))
4262          (data (gnus-data-find article))
4263          (thread (gnus-id-to-thread id))
4264          (references (mail-header-references header))
4265          (parent
4266           (gnus-id-to-thread
4267            (or (gnus-parent-id
4268                 (when (and references
4269                            (not (equal "" references)))
4270                   references))
4271                "none")))
4272          (buffer-read-only nil)
4273          (old (car thread)))
4274     (when thread
4275       (unless iheader
4276         (setcar thread nil)
4277         (when parent
4278           (delq thread parent)))
4279       (if (gnus-summary-insert-subject id header)
4280           ;; Set the (possibly) new article number in the data structure.
4281           (gnus-data-set-number data (gnus-id-to-article id))
4282         (setcar thread old)
4283         nil))))
4284
4285 (defun gnus-rebuild-thread (id &optional line)
4286   "Rebuild the thread containing ID.
4287 If LINE, insert the rebuilt thread starting on line LINE."
4288   (let ((buffer-read-only nil)
4289         old-pos current thread data)
4290     (if (not gnus-show-threads)
4291         (setq thread (list (car (gnus-id-to-thread id))))
4292       ;; Get the thread this article is part of.
4293       (setq thread (gnus-remove-thread id)))
4294     (setq old-pos (point-at-bol))
4295     (setq current (save-excursion
4296                     (and (re-search-backward "[\r\n]" nil t)
4297                          (gnus-summary-article-number))))
4298     ;; If this is a gathered thread, we have to go some re-gathering.
4299     (when (stringp (car thread))
4300       (let ((subject (car thread))
4301             roots thr)
4302         (setq thread (cdr thread))
4303         (while thread
4304           (unless (memq (setq thr (gnus-id-to-thread
4305                                    (gnus-root-id
4306                                     (mail-header-id (caar thread)))))
4307                         roots)
4308             (push thr roots))
4309           (setq thread (cdr thread)))
4310         ;; We now have all (unique) roots.
4311         (if (= (length roots) 1)
4312             ;; All the loose roots are now one solid root.
4313             (setq thread (car roots))
4314           (setq thread (cons subject (gnus-sort-threads roots))))))
4315     (let (threads)
4316       ;; We then insert this thread into the summary buffer.
4317       (when line
4318         (goto-char (point-min))
4319         (forward-line (1- line)))
4320       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4321         (if gnus-show-threads
4322             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4323           (gnus-summary-prepare-unthreaded thread))
4324         (setq data (nreverse gnus-newsgroup-data))
4325         (setq threads gnus-newsgroup-threads))
4326       ;; We splice the new data into the data structure.
4327       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4328       ;;!!! then we want to insert at the beginning of the buffer.
4329       ;;!!! That happens to be true with Gnus now, but that may
4330       ;;!!! change in the future.  Perhaps.
4331       (gnus-data-enter-list
4332        (if line nil current) data (- (point) old-pos))
4333       (setq gnus-newsgroup-threads
4334             (nconc threads gnus-newsgroup-threads))
4335       (gnus-data-compute-positions))))
4336
4337 (defun gnus-number-to-header (number)
4338   "Return the header for article NUMBER."
4339   (let ((headers gnus-newsgroup-headers))
4340     (while (and headers
4341                 (not (= number (mail-header-number (car headers)))))
4342       (pop headers))
4343     (when headers
4344       (car headers))))
4345
4346 (defun gnus-parent-headers (in-headers &optional generation)
4347   "Return the headers of the GENERATIONeth parent of HEADERS."
4348   (unless generation
4349     (setq generation 1))
4350   (let ((parent t)
4351         (headers in-headers)
4352         references)
4353     (while (and parent
4354                 (not (zerop generation))
4355                 (setq references (mail-header-references headers)))
4356       (setq headers (if (and references
4357                              (setq parent (gnus-parent-id references)))
4358                         (car (gnus-id-to-thread parent))
4359                       nil))
4360       (decf generation))
4361     (and (not (eq headers in-headers))
4362          headers)))
4363
4364 (defun gnus-id-to-thread (id)
4365   "Return the (sub-)thread where ID appears."
4366   (gnus-gethash id gnus-newsgroup-dependencies))
4367
4368 (defun gnus-id-to-article (id)
4369   "Return the article number of ID."
4370   (let ((thread (gnus-id-to-thread id)))
4371     (when (and thread
4372                (car thread))
4373       (mail-header-number (car thread)))))
4374
4375 (defun gnus-id-to-header (id)
4376   "Return the article headers of ID."
4377   (car (gnus-id-to-thread id)))
4378
4379 (defun gnus-article-displayed-root-p (article)
4380   "Say whether ARTICLE is a root(ish) article."
4381   (let ((level (gnus-summary-thread-level article))
4382         (refs (mail-header-references  (gnus-summary-article-header article)))
4383         particle)
4384     (cond
4385      ((null level) nil)
4386      ((zerop level) t)
4387      ((null refs) t)
4388      ((null (gnus-parent-id refs)) t)
4389      ((and (= 1 level)
4390            (null (setq particle (gnus-id-to-article
4391                                  (gnus-parent-id refs))))
4392            (null (gnus-summary-thread-level particle)))))))
4393
4394 (defun gnus-root-id (id)
4395   "Return the id of the root of the thread where ID appears."
4396   (let (last-id prev)
4397     (while (and id (setq prev (car (gnus-id-to-thread id))))
4398       (setq last-id id
4399             id (gnus-parent-id (mail-header-references prev))))
4400     last-id))
4401
4402 (defun gnus-articles-in-thread (thread)
4403   "Return the list of articles in THREAD."
4404   (cons (mail-header-number (car thread))
4405         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4406
4407 (defun gnus-remove-thread (id &optional dont-remove)
4408   "Remove the thread that has ID in it."
4409   (let (headers thread last-id)
4410     ;; First go up in this thread until we find the root.
4411     (setq last-id (gnus-root-id id)
4412           headers (message-flatten-list (gnus-id-to-thread last-id)))
4413     ;; We have now found the real root of this thread.  It might have
4414     ;; been gathered into some loose thread, so we have to search
4415     ;; through the threads to find the thread we wanted.
4416     (let ((threads gnus-newsgroup-threads)
4417           sub)
4418       (while threads
4419         (setq sub (car threads))
4420         (if (stringp (car sub))
4421             ;; This is a gathered thread, so we look at the roots
4422             ;; below it to find whether this article is in this
4423             ;; gathered root.
4424             (progn
4425               (setq sub (cdr sub))
4426               (while sub
4427                 (when (member (caar sub) headers)
4428                   (setq thread (car threads)
4429                         threads nil
4430                         sub nil))
4431                 (setq sub (cdr sub))))
4432           ;; It's an ordinary thread, so we check it.
4433           (when (eq (car sub) (car headers))
4434             (setq thread sub
4435                   threads nil)))
4436         (setq threads (cdr threads)))
4437       ;; If this article is in no thread, then it's a root.
4438       (if thread
4439           (unless dont-remove
4440             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4441         (setq thread (gnus-id-to-thread last-id)))
4442       (when thread
4443         (prog1
4444             thread                      ; We return this thread.
4445           (unless dont-remove
4446             (if (stringp (car thread))
4447                 (progn
4448                   ;; If we use dummy roots, then we have to remove the
4449                   ;; dummy root as well.
4450                   (when (eq gnus-summary-make-false-root 'dummy)
4451                     ;; We go to the dummy root by going to
4452                     ;; the first sub-"thread", and then one line up.
4453                     (gnus-summary-goto-article
4454                      (mail-header-number (caadr thread)))
4455                     (forward-line -1)
4456                     (gnus-delete-line)
4457                     (gnus-data-compute-positions))
4458                   (setq thread (cdr thread))
4459                   (while thread
4460                     (gnus-remove-thread-1 (car thread))
4461                     (setq thread (cdr thread))))
4462               (gnus-remove-thread-1 thread))))))))
4463
4464 (defun gnus-remove-thread-1 (thread)
4465   "Remove the thread THREAD recursively."
4466   (let ((number (mail-header-number (pop thread)))
4467         d)
4468     (setq thread (reverse thread))
4469     (while thread
4470       (gnus-remove-thread-1 (pop thread)))
4471     (when (setq d (gnus-data-find number))
4472       (goto-char (gnus-data-pos d))
4473       (gnus-summary-show-thread)
4474       (gnus-data-remove
4475        number
4476        (- (point-at-bol)
4477           (prog1
4478               (1+ (point-at-eol))
4479             (gnus-delete-line)))))))
4480
4481 (defun gnus-sort-threads-1 (threads func)
4482   (sort (mapcar (lambda (thread)
4483                   (cons (car thread)
4484                         (and (cdr thread)
4485                              (gnus-sort-threads-1 (cdr thread) func))))
4486                 threads) func))
4487
4488 (defun gnus-sort-threads (threads)
4489   "Sort THREADS."
4490   (if (not gnus-thread-sort-functions)
4491       threads
4492     (gnus-message 8 "Sorting threads...")
4493     (let ((max-lisp-eval-depth 5000))
4494       (prog1 (gnus-sort-threads-1
4495          threads
4496          (gnus-make-sort-function gnus-thread-sort-functions))
4497         (gnus-message 8 "Sorting threads...done")))))
4498
4499 (defun gnus-sort-articles (articles)
4500   "Sort ARTICLES."
4501   (when gnus-article-sort-functions
4502     (gnus-message 7 "Sorting articles...")
4503     (prog1
4504         (setq gnus-newsgroup-headers
4505               (sort articles (gnus-make-sort-function
4506                               gnus-article-sort-functions)))
4507       (gnus-message 7 "Sorting articles...done"))))
4508
4509 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4510 (defmacro gnus-thread-header (thread)
4511   "Return header of first article in THREAD.
4512 Note that THREAD must never, ever be anything else than a variable -
4513 using some other form will lead to serious barfage."
4514   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4515   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4516   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4517         (vector thread) 2))
4518
4519 (defsubst gnus-article-sort-by-number (h1 h2)
4520   "Sort articles by article number."
4521   (< (mail-header-number h1)
4522      (mail-header-number h2)))
4523
4524 (defun gnus-thread-sort-by-number (h1 h2)
4525   "Sort threads by root article number."
4526   (gnus-article-sort-by-number
4527    (gnus-thread-header h1) (gnus-thread-header h2)))
4528
4529 (defsubst gnus-article-sort-by-random (h1 h2)
4530   "Sort articles by article number."
4531   (zerop (random 2)))
4532
4533 (defun gnus-thread-sort-by-random (h1 h2)
4534   "Sort threads by root article number."
4535   (gnus-article-sort-by-random
4536    (gnus-thread-header h1) (gnus-thread-header h2)))
4537
4538 (defsubst gnus-article-sort-by-lines (h1 h2)
4539   "Sort articles by article Lines header."
4540   (< (mail-header-lines h1)
4541      (mail-header-lines h2)))
4542
4543 (defun gnus-thread-sort-by-lines (h1 h2)
4544   "Sort threads by root article Lines header."
4545   (gnus-article-sort-by-lines
4546    (gnus-thread-header h1) (gnus-thread-header h2)))
4547
4548 (defsubst gnus-article-sort-by-chars (h1 h2)
4549   "Sort articles by octet length."
4550   (< (mail-header-chars h1)
4551      (mail-header-chars h2)))
4552
4553 (defun gnus-thread-sort-by-chars (h1 h2)
4554   "Sort threads by root article octet length."
4555   (gnus-article-sort-by-chars
4556    (gnus-thread-header h1) (gnus-thread-header h2)))
4557
4558 (defsubst gnus-article-sort-by-author (h1 h2)
4559   "Sort articles by root author."
4560   (string-lessp
4561    (let ((extract (funcall
4562                    gnus-extract-address-components
4563                    (mail-header-from h1))))
4564      (or (car extract) (cadr extract) ""))
4565    (let ((extract (funcall
4566                    gnus-extract-address-components
4567                    (mail-header-from h2))))
4568      (or (car extract) (cadr extract) ""))))
4569
4570 (defun gnus-thread-sort-by-author (h1 h2)
4571   "Sort threads by root author."
4572   (gnus-article-sort-by-author
4573    (gnus-thread-header h1)  (gnus-thread-header h2)))
4574
4575 (defsubst gnus-article-sort-by-recipient (h1 h2)
4576   "Sort articles by recipient."
4577   (string-lessp
4578    (let ((extract (funcall
4579                    gnus-extract-address-components
4580                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4581      (or (car extract) (cadr extract)))
4582    (let ((extract (funcall
4583                    gnus-extract-address-components
4584                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4585      (or (car extract) (cadr extract)))))
4586
4587 (defsubst gnus-article-sort-by-subject (h1 h2)
4588   "Sort articles by root subject."
4589   (string-lessp
4590    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4591    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4592
4593 (defun gnus-thread-sort-by-subject (h1 h2)
4594   "Sort threads by root subject."
4595   (gnus-article-sort-by-subject
4596    (gnus-thread-header h1) (gnus-thread-header h2)))
4597
4598 (defsubst gnus-article-sort-by-date (h1 h2)
4599   "Sort articles by root article date."
4600   (time-less-p
4601    (gnus-date-get-time (mail-header-date h1))
4602    (gnus-date-get-time (mail-header-date h2))))
4603
4604 (defun gnus-thread-sort-by-date (h1 h2)
4605   "Sort threads by root article date."
4606   (gnus-article-sort-by-date
4607    (gnus-thread-header h1) (gnus-thread-header h2)))
4608
4609 (defsubst gnus-article-sort-by-score (h1 h2)
4610   "Sort articles by root article score.
4611 Unscored articles will be counted as having a score of zero."
4612   (> (or (cdr (assq (mail-header-number h1)
4613                     gnus-newsgroup-scored))
4614          gnus-summary-default-score 0)
4615      (or (cdr (assq (mail-header-number h2)
4616                     gnus-newsgroup-scored))
4617          gnus-summary-default-score 0)))
4618
4619 (defun gnus-thread-sort-by-score (h1 h2)
4620   "Sort threads by root article score."
4621   (gnus-article-sort-by-score
4622    (gnus-thread-header h1) (gnus-thread-header h2)))
4623
4624 (defun gnus-thread-sort-by-total-score (h1 h2)
4625   "Sort threads by the sum of all scores in the thread.
4626 Unscored articles will be counted as having a score of zero."
4627   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4628
4629 (defun gnus-thread-total-score (thread)
4630   ;; This function find the total score of THREAD.
4631   (cond
4632    ((null thread)
4633     0)
4634    ((consp thread)
4635     (if (stringp (car thread))
4636         (apply gnus-thread-score-function 0
4637                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4638       (gnus-thread-total-score-1 thread)))
4639    (t
4640     (gnus-thread-total-score-1 (list thread)))))
4641
4642 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4643   "Sort threads such that the thread with the most recently arrived article comes first."
4644   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4645
4646 (defun gnus-thread-highest-number (thread)
4647   "Return the highest article number in THREAD."
4648   (apply 'max (mapcar (lambda (header)
4649                         (mail-header-number header))
4650                       (message-flatten-list thread))))
4651
4652 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4653   "Sort threads such that the thread with the most recently dated article comes first."
4654   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4655
4656 (defun gnus-thread-latest-date (thread)
4657   "Return the highest article date in THREAD."
4658   (let ((previous-time 0))
4659     (apply 'max
4660            (mapcar
4661             (lambda (header)
4662               (setq previous-time
4663                     (condition-case ()
4664                         (time-to-seconds (mail-header-parse-date
4665                                           (mail-header-date header)))
4666                       (error previous-time))))
4667             (sort
4668              (message-flatten-list thread)
4669              (lambda (h1 h2)
4670                (< (mail-header-number h1)
4671                   (mail-header-number h2))))))))
4672
4673 (defun gnus-thread-total-score-1 (root)
4674   ;; This function find the total score of the thread below ROOT.
4675   (setq root (car root))
4676   (apply gnus-thread-score-function
4677          (or (append
4678               (mapcar 'gnus-thread-total-score
4679                       (cdr (gnus-id-to-thread (mail-header-id root))))
4680               (when (> (mail-header-number root) 0)
4681                 (list (or (cdr (assq (mail-header-number root)
4682                                      gnus-newsgroup-scored))
4683                           gnus-summary-default-score 0))))
4684              (list gnus-summary-default-score)
4685              '(0))))
4686
4687 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4688 (defvar gnus-tmp-prev-subject nil)
4689 (defvar gnus-tmp-false-parent nil)
4690 (defvar gnus-tmp-root-expunged nil)
4691 (defvar gnus-tmp-dummy-line nil)
4692
4693 (eval-when-compile (defvar gnus-tmp-header))
4694 (defun gnus-extra-header (type &optional header)
4695   "Return the extra header of TYPE."
4696   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4697       ""))
4698
4699 (defvar gnus-tmp-thread-tree-header-string "")
4700
4701 (defcustom gnus-sum-thread-tree-root "> "
4702   "With %B spec, used for the root of a thread.
4703 If nil, use subject instead."
4704   :version "21.4"
4705   :type '(radio (const :format "%v  " nil) string)
4706   :group 'gnus-thread)
4707 (defcustom gnus-sum-thread-tree-false-root "> "
4708   "With %B spec, used for a false root of a thread.
4709 If nil, use subject instead."
4710   :version "21.4"
4711   :type '(radio (const :format "%v  " nil) string)
4712   :group 'gnus-thread)
4713 (defcustom gnus-sum-thread-tree-single-indent ""
4714   "With %B spec, used for a thread with just one message.
4715 If nil, use subject instead."
4716   :version "21.4"
4717   :type '(radio (const :format "%v  " nil) string)
4718   :group 'gnus-thread)
4719 (defcustom gnus-sum-thread-tree-vertical "| "
4720   "With %B spec, used for drawing a vertical line."
4721   :version "21.4"
4722   :type 'string
4723   :group 'gnus-thread)
4724 (defcustom gnus-sum-thread-tree-indent "  "
4725   "With %B spec, used for indenting."
4726   :version "21.4"
4727   :type 'string
4728   :group 'gnus-thread)
4729 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4730   "With %B spec, used for a leaf with brothers."
4731   :version "21.4"
4732   :type 'string
4733   :group 'gnus-thread)
4734 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4735   "With %B spec, used for a leaf without brothers."
4736   :version "21.4"
4737   :type 'string
4738   :group 'gnus-thread)
4739
4740 (defun gnus-summary-prepare-threads (threads)
4741   "Prepare summary buffer from THREADS and indentation LEVEL.
4742 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4743 or a straight list of headers."
4744   (gnus-message 7 "Generating summary...")
4745
4746   (setq gnus-newsgroup-threads threads)
4747   (beginning-of-line)
4748
4749   (let ((gnus-tmp-level 0)
4750         (default-score (or gnus-summary-default-score 0))
4751         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4752         (building-line-count gnus-summary-display-while-building)
4753         (building-count (integerp gnus-summary-display-while-building))
4754         thread number subject stack state gnus-tmp-gathered beg-match
4755         new-roots gnus-tmp-new-adopts thread-end simp-subject
4756         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4757         gnus-tmp-replied gnus-tmp-subject-or-nil
4758         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4759         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4760         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4761         tree-stack)
4762
4763     (setq gnus-tmp-prev-subject nil
4764           gnus-tmp-thread-tree-header-string "")
4765
4766     (if (vectorp (car threads))
4767         ;; If this is a straight (sic) list of headers, then a
4768         ;; threaded summary display isn't required, so we just create
4769         ;; an unthreaded one.
4770         (gnus-summary-prepare-unthreaded threads)
4771
4772       ;; Do the threaded display.
4773
4774       (if gnus-summary-display-while-building
4775           (switch-to-buffer (buffer-name)))
4776       (while (or threads stack gnus-tmp-new-adopts new-roots)
4777
4778         (if (and (= gnus-tmp-level 0)
4779                  (or (not stack)
4780                      (= (caar stack) 0))
4781                  (not gnus-tmp-false-parent)
4782                  (or gnus-tmp-new-adopts new-roots))
4783             (if gnus-tmp-new-adopts
4784                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4785                       thread (list (car gnus-tmp-new-adopts))
4786                       gnus-tmp-header (caar thread)
4787                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4788               (when new-roots
4789                 (setq thread (list (car new-roots))
4790                       gnus-tmp-header (caar thread)
4791                       new-roots (cdr new-roots))))
4792
4793           (if threads
4794               ;; If there are some threads, we do them before the
4795               ;; threads on the stack.
4796               (setq thread threads
4797                     gnus-tmp-header (caar thread))
4798             ;; There were no current threads, so we pop something off
4799             ;; the stack.
4800             (setq state (car stack)
4801                   gnus-tmp-level (car state)
4802                   tree-stack (cadr state)
4803                   thread (caddr state)
4804                   stack (cdr stack)
4805                   gnus-tmp-header (caar thread))))
4806
4807         (setq gnus-tmp-false-parent nil)
4808         (setq gnus-tmp-root-expunged nil)
4809         (setq thread-end nil)
4810
4811         (if (stringp gnus-tmp-header)
4812             ;; The header is a dummy root.
4813             (cond
4814              ((eq gnus-summary-make-false-root 'adopt)
4815               ;; We let the first article adopt the rest.
4816               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4817                                                (cddar thread)))
4818               (setq gnus-tmp-gathered
4819                     (nconc (mapcar
4820                             (lambda (h) (mail-header-number (car h)))
4821                             (cddar thread))
4822                            gnus-tmp-gathered))
4823               (setq thread (cons (list (caar thread)
4824                                        (cadar thread))
4825                                  (cdr thread)))
4826               (setq gnus-tmp-level -1
4827                     gnus-tmp-false-parent t))
4828              ((eq gnus-summary-make-false-root 'empty)
4829               ;; We print adopted articles with empty subject fields.
4830               (setq gnus-tmp-gathered
4831                     (nconc (mapcar
4832                             (lambda (h) (mail-header-number (car h)))
4833                             (cddar thread))
4834                            gnus-tmp-gathered))
4835               (setq gnus-tmp-level -1))
4836              ((eq gnus-summary-make-false-root 'dummy)
4837               ;; We remember that we probably want to output a dummy
4838               ;; root.
4839               (setq gnus-tmp-dummy-line gnus-tmp-header)
4840               (setq gnus-tmp-prev-subject gnus-tmp-header))
4841              (t
4842               ;; We do not make a root for the gathered
4843               ;; sub-threads at all.
4844               (setq gnus-tmp-level -1)))
4845
4846           (setq number (mail-header-number gnus-tmp-header)
4847                 subject (mail-header-subject gnus-tmp-header)
4848                 simp-subject (gnus-simplify-subject-fully subject))
4849
4850           (cond
4851            ;; If the thread has changed subject, we might want to make
4852            ;; this subthread into a root.
4853            ((and (null gnus-thread-ignore-subject)
4854                  (not (zerop gnus-tmp-level))
4855                  gnus-tmp-prev-subject
4856                  (not (string= gnus-tmp-prev-subject simp-subject)))
4857             (setq new-roots (nconc new-roots (list (car thread)))
4858                   thread-end t
4859                   gnus-tmp-header nil))
4860            ;; If the article lies outside the current limit,
4861            ;; then we do not display it.
4862            ((not (memq number gnus-newsgroup-limit))
4863             (setq gnus-tmp-gathered
4864                   (nconc (mapcar
4865                           (lambda (h) (mail-header-number (car h)))
4866                           (cdar thread))
4867                          gnus-tmp-gathered))
4868             (setq gnus-tmp-new-adopts (if (cdar thread)
4869                                           (append gnus-tmp-new-adopts
4870                                                   (cdar thread))
4871                                         gnus-tmp-new-adopts)
4872                   thread-end t
4873                   gnus-tmp-header nil)
4874             (when (zerop gnus-tmp-level)
4875               (setq gnus-tmp-root-expunged t)))
4876            ;; Perhaps this article is to be marked as read?
4877            ((and gnus-summary-mark-below
4878                  (< (or (cdr (assq number gnus-newsgroup-scored))
4879                         default-score)
4880                     gnus-summary-mark-below)
4881                  ;; Don't touch sparse articles.
4882                  (not (gnus-summary-article-sparse-p number))
4883                  (not (gnus-summary-article-ancient-p number)))
4884             (setq gnus-newsgroup-unreads
4885                   (delq number gnus-newsgroup-unreads))
4886             (if gnus-newsgroup-auto-expire
4887                 (setq gnus-newsgroup-expirable
4888                       (gnus-add-to-sorted-list
4889                        gnus-newsgroup-expirable number))
4890               (push (cons number gnus-low-score-mark)
4891                     gnus-newsgroup-reads))))
4892
4893           (when gnus-tmp-header
4894             ;; We may have an old dummy line to output before this
4895             ;; article.
4896             (when (and gnus-tmp-dummy-line
4897                        (gnus-subject-equal
4898                         gnus-tmp-dummy-line
4899                         (mail-header-subject gnus-tmp-header)))
4900               (gnus-summary-insert-dummy-line
4901                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4902               (setq gnus-tmp-dummy-line nil))
4903
4904             ;; Compute the mark.
4905             (setq gnus-tmp-unread (gnus-article-mark number))
4906
4907             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4908                                   gnus-tmp-header gnus-tmp-level)
4909                   gnus-newsgroup-data)
4910
4911             ;; Actually insert the line.
4912             (setq
4913              gnus-tmp-subject-or-nil
4914              (cond
4915               ((and gnus-thread-ignore-subject
4916                     gnus-tmp-prev-subject
4917                     (not (string= gnus-tmp-prev-subject simp-subject)))
4918                subject)
4919               ((zerop gnus-tmp-level)
4920                (if (and (eq gnus-summary-make-false-root 'empty)
4921                         (memq number gnus-tmp-gathered)
4922                         gnus-tmp-prev-subject
4923                         (string= gnus-tmp-prev-subject simp-subject))
4924                    gnus-summary-same-subject
4925                  subject))
4926               (t gnus-summary-same-subject)))
4927             (if (and (eq gnus-summary-make-false-root 'adopt)
4928                      (= gnus-tmp-level 1)
4929                      (memq number gnus-tmp-gathered))
4930                 (setq gnus-tmp-opening-bracket ?\<
4931                       gnus-tmp-closing-bracket ?\>)
4932               (setq gnus-tmp-opening-bracket ?\[
4933                     gnus-tmp-closing-bracket ?\]))
4934             (setq
4935              gnus-tmp-indentation
4936              (aref gnus-thread-indent-array gnus-tmp-level)
4937              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4938              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4939                                 gnus-summary-default-score 0)
4940              gnus-tmp-score-char
4941              (if (or (null gnus-summary-default-score)
4942                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4943                          gnus-summary-zcore-fuzz))
4944                  ?                      ;Whitespace
4945                (if (< gnus-tmp-score gnus-summary-default-score)
4946                    gnus-score-below-mark gnus-score-over-mark))
4947              gnus-tmp-replied
4948              (cond ((memq number gnus-newsgroup-processable)
4949                     gnus-process-mark)
4950                    ((memq number gnus-newsgroup-cached)
4951                     gnus-cached-mark)
4952                    ((memq number gnus-newsgroup-replied)
4953                     gnus-replied-mark)
4954                    ((memq number gnus-newsgroup-forwarded)
4955                     gnus-forwarded-mark)
4956                    ((memq number gnus-newsgroup-saved)
4957                     gnus-saved-mark)
4958                    ((memq number gnus-newsgroup-recent)
4959                     gnus-recent-mark)
4960                    ((memq number gnus-newsgroup-unseen)
4961                     gnus-unseen-mark)
4962                    (t gnus-no-mark))
4963              gnus-tmp-downloaded
4964              (cond ((memq number gnus-newsgroup-undownloaded)
4965                     gnus-undownloaded-mark)
4966                    (gnus-newsgroup-agentized
4967                     gnus-downloaded-mark)
4968                    (t
4969                     gnus-no-mark))
4970              gnus-tmp-from (mail-header-from gnus-tmp-header)
4971              gnus-tmp-name
4972              (cond
4973               ((string-match "<[^>]+> *$" gnus-tmp-from)
4974                (setq beg-match (match-beginning 0))
4975                (or (and (string-match "^\".+\"" gnus-tmp-from)
4976                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4977                    (substring gnus-tmp-from 0 beg-match)))
4978               ((string-match "(.+)" gnus-tmp-from)
4979                (substring gnus-tmp-from
4980                           (1+ (match-beginning 0)) (1- (match-end 0))))
4981               (t gnus-tmp-from))
4982
4983              ;; Do the %B string
4984              gnus-tmp-thread-tree-header-string
4985              (cond
4986               ((not gnus-show-threads) "")
4987               ((zerop gnus-tmp-level)
4988                (cond ((cdar thread)
4989                       (or gnus-sum-thread-tree-root subject))
4990                      (gnus-tmp-new-adopts
4991                       (or gnus-sum-thread-tree-false-root subject))
4992                      (t
4993                       (or gnus-sum-thread-tree-single-indent subject))))
4994               (t
4995                (concat (apply 'concat
4996                               (mapcar (lambda (item)
4997                                         (if (= item 1)
4998                                             gnus-sum-thread-tree-vertical
4999                                           gnus-sum-thread-tree-indent))
5000                                       (cdr (reverse tree-stack))))
5001                        (if (nth 1 thread)
5002                            gnus-sum-thread-tree-leaf-with-other
5003                          gnus-sum-thread-tree-single-leaf)))))
5004             (when (string= gnus-tmp-name "")
5005               (setq gnus-tmp-name gnus-tmp-from))
5006             (unless (numberp gnus-tmp-lines)
5007               (setq gnus-tmp-lines -1))
5008             (if (= gnus-tmp-lines -1)
5009                 (setq gnus-tmp-lines "?")
5010               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5011               (gnus-put-text-property
5012              (point)
5013              (progn (eval gnus-summary-line-format-spec) (point))
5014                'gnus-number number)
5015             (when gnus-visual-p
5016               (forward-line -1)
5017               (gnus-run-hooks 'gnus-summary-update-hook)
5018               (forward-line 1))
5019
5020             (setq gnus-tmp-prev-subject simp-subject)))
5021
5022         (when (nth 1 thread)
5023           (push (list (max 0 gnus-tmp-level)
5024                       (copy-sequence tree-stack)
5025                       (nthcdr 1 thread))
5026                 stack))
5027         (push (if (nth 1 thread) 1 0) tree-stack)
5028         (incf gnus-tmp-level)
5029         (setq threads (if thread-end nil (cdar thread)))
5030         (if gnus-summary-display-while-building
5031             (if building-count
5032                 (progn
5033                   ;; use a set frequency
5034                   (setq building-line-count (1- building-line-count))
5035                   (when (= building-line-count 0)
5036                     (sit-for 0)
5037                     (setq building-line-count
5038                           gnus-summary-display-while-building)))
5039               ;; always
5040               (sit-for 0)))
5041         (unless threads
5042           (setq gnus-tmp-level 0)))))
5043   (gnus-message 7 "Generating summary...done"))
5044
5045 (defun gnus-summary-prepare-unthreaded (headers)
5046   "Generate an unthreaded summary buffer based on HEADERS."
5047   (let (header number mark)
5048
5049     (beginning-of-line)
5050
5051     (while headers
5052       ;; We may have to root out some bad articles...
5053       (when (memq (setq number (mail-header-number
5054                                 (setq header (pop headers))))
5055                   gnus-newsgroup-limit)
5056         ;; Mark article as read when it has a low score.
5057         (when (and gnus-summary-mark-below
5058                    (< (or (cdr (assq number gnus-newsgroup-scored))
5059                           gnus-summary-default-score 0)
5060                       gnus-summary-mark-below)
5061                    (not (gnus-summary-article-ancient-p number)))
5062           (setq gnus-newsgroup-unreads
5063                 (delq number gnus-newsgroup-unreads))
5064           (if gnus-newsgroup-auto-expire
5065               (push number gnus-newsgroup-expirable)
5066             (push (cons number gnus-low-score-mark)
5067                   gnus-newsgroup-reads)))
5068
5069         (setq mark (gnus-article-mark number))
5070         (push (gnus-data-make number mark (1+ (point)) header 0)
5071               gnus-newsgroup-data)
5072         (gnus-summary-insert-line
5073          header 0 number
5074          (memq number gnus-newsgroup-undownloaded)
5075          mark (memq number gnus-newsgroup-replied)
5076          (memq number gnus-newsgroup-expirable)
5077          (mail-header-subject header) nil
5078          (cdr (assq number gnus-newsgroup-scored))
5079          (memq number gnus-newsgroup-processable))))))
5080
5081 (defun gnus-summary-remove-list-identifiers ()
5082   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5083   (let ((regexp (if (consp gnus-list-identifiers)
5084                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5085                   gnus-list-identifiers))
5086         changed subject)
5087     (when regexp
5088       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5089       (dolist (header gnus-newsgroup-headers)
5090         (setq subject (mail-header-subject header)
5091               changed nil)
5092         (while (string-match regexp subject)
5093           (setq subject
5094                 (concat (substring subject 0 (match-beginning 1))
5095                         (substring subject (match-end 0)))
5096                 changed t))
5097         (when changed
5098           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5099             (setq subject
5100                   (concat (substring subject 0 (match-beginning 1))
5101                           (substring subject (match-end 1)))))
5102           (mail-header-set-subject header subject))))))
5103
5104 (defun gnus-fetch-headers (articles)
5105   "Fetch headers of ARTICLES."
5106   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5107     (gnus-message 5 "Fetching headers for %s..." name)
5108     (prog1
5109         (if (eq 'nov
5110                 (setq gnus-headers-retrieved-by
5111                       (gnus-retrieve-headers
5112                        articles gnus-newsgroup-name
5113                        ;; We might want to fetch old headers, but
5114                        ;; not if there is only 1 article.
5115                        (and (or (and
5116                                  (not (eq gnus-fetch-old-headers 'some))
5117                                  (not (numberp gnus-fetch-old-headers)))
5118                                 (> (length articles) 1))
5119                             gnus-fetch-old-headers))))
5120             (gnus-get-newsgroup-headers-xover
5121              articles nil nil gnus-newsgroup-name t)
5122           (gnus-get-newsgroup-headers))
5123       (gnus-message 5 "Fetching headers for %s...done" name))))
5124
5125 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5126   "Select newsgroup GROUP.
5127 If READ-ALL is non-nil, all articles in the group are selected.
5128 If SELECT-ARTICLES, only select those articles from GROUP."
5129   (let* ((entry (gnus-group-entry group))
5130          ;;!!! Dirty hack; should be removed.
5131          (gnus-summary-ignore-duplicates
5132           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5133               t
5134             gnus-summary-ignore-duplicates))
5135          (info (nth 2 entry))
5136          articles fetched-articles cached)
5137
5138     (unless (gnus-check-server
5139              (set (make-local-variable 'gnus-current-select-method)
5140                   (gnus-find-method-for-group group)))
5141       (error "Couldn't open server"))
5142
5143     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5144         (gnus-activate-group group)     ; Or we can activate it...
5145         (progn                          ; Or we bug out.
5146           (when (equal major-mode 'gnus-summary-mode)
5147             (gnus-kill-buffer (current-buffer)))
5148           (error "Couldn't activate group %s: %s"
5149                  group (gnus-status-message group))))
5150
5151     (unless (gnus-request-group group t)
5152       (when (equal major-mode 'gnus-summary-mode)
5153         (gnus-kill-buffer (current-buffer)))
5154       (error "Couldn't request group %s: %s"
5155              group (gnus-status-message group)))
5156
5157     (when gnus-agent
5158       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5159       
5160       (setq gnus-summary-use-undownloaded-faces
5161             (gnus-agent-find-parameter
5162              group
5163              'agent-enable-undownloaded-faces)))
5164
5165     (setq gnus-newsgroup-name group
5166           gnus-newsgroup-unselected nil
5167           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5168
5169     (let ((display (gnus-group-find-parameter group 'display)))
5170       (setq gnus-newsgroup-display
5171             (cond
5172              ((not (zerop (or (car-safe read-all) 0)))
5173               ;; The user entered the group with C-u SPC/RET, let's show
5174               ;; all articles.
5175               'gnus-not-ignore)
5176              ((eq display 'all)
5177               'gnus-not-ignore)
5178              ((arrayp display)
5179               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5180              ((numberp display)
5181               ;; The following is probably the "correct" solution, but
5182               ;; it makes Gnus fetch all headers and then limit the
5183               ;; articles (which is slow), so instead we hack the
5184               ;; select-articles parameter instead. -- Simon Josefsson
5185               ;; <jas@kth.se>
5186               ;;
5187               ;; (gnus-byte-compile
5188               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5189               ;;                         display)))))
5190               (setq select-articles
5191                     (gnus-uncompress-range
5192                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5193                              (if (> tmp 0)
5194                                  tmp
5195                                1))
5196                            (cdr (gnus-active group)))))
5197               nil)
5198              (t
5199               nil))))
5200
5201     (gnus-summary-setup-default-charset)
5202
5203     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5204     (when (gnus-virtual-group-p group)
5205       (setq cached gnus-newsgroup-cached))
5206
5207     (setq gnus-newsgroup-unreads
5208           (gnus-sorted-ndifference
5209            (gnus-sorted-ndifference gnus-newsgroup-unreads
5210                                     gnus-newsgroup-marked)
5211            gnus-newsgroup-dormant))
5212
5213     (setq gnus-newsgroup-processable nil)
5214
5215     (gnus-update-read-articles group gnus-newsgroup-unreads)
5216
5217     ;; Adjust and set lists of article marks.
5218     (when info
5219       (gnus-adjust-marked-articles info))
5220     (if (setq articles select-articles)
5221         (setq gnus-newsgroup-unselected
5222               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5223       (setq articles (gnus-articles-to-read group read-all)))
5224
5225     (cond
5226      ((null articles)
5227       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5228       'quit)
5229      ((eq articles 0) nil)
5230      (t
5231       ;; Init the dependencies hash table.
5232       (setq gnus-newsgroup-dependencies
5233             (gnus-make-hashtable (length articles)))
5234       (gnus-set-global-variables)
5235       ;; Retrieve the headers and read them in.
5236
5237       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5238
5239       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5240       (when cached
5241         (setq gnus-newsgroup-cached cached))
5242
5243       ;; Suppress duplicates?
5244       (when gnus-suppress-duplicates
5245         (gnus-dup-suppress-articles))
5246
5247       ;; Set the initial limit.
5248       (setq gnus-newsgroup-limit (copy-sequence articles))
5249       ;; Remove canceled articles from the list of unread articles.
5250       (setq fetched-articles
5251             (mapcar (lambda (headers) (mail-header-number headers))
5252                     gnus-newsgroup-headers))
5253       (setq gnus-newsgroup-articles fetched-articles)
5254       (setq gnus-newsgroup-unreads
5255             (gnus-sorted-nintersection
5256              gnus-newsgroup-unreads fetched-articles))
5257       (gnus-compute-unseen-list)
5258
5259       ;; Removed marked articles that do not exist.
5260       (gnus-update-missing-marks
5261        (gnus-sorted-difference articles fetched-articles))
5262       ;; We might want to build some more threads first.
5263       (when (and gnus-fetch-old-headers
5264                  (eq gnus-headers-retrieved-by 'nov))
5265         (if (eq gnus-fetch-old-headers 'invisible)
5266             (gnus-build-all-threads)
5267           (gnus-build-old-threads)))
5268       ;; Let the Gnus agent mark articles as read.
5269       (when gnus-agent
5270         (gnus-agent-get-undownloaded-list))
5271       ;; Remove list identifiers from subject
5272       (when gnus-list-identifiers
5273         (gnus-summary-remove-list-identifiers))
5274       ;; Check whether auto-expire is to be done in this group.
5275       (setq gnus-newsgroup-auto-expire
5276             (gnus-group-auto-expirable-p group))
5277       ;; Set up the article buffer now, if necessary.
5278       (unless gnus-single-article-buffer
5279         (gnus-article-setup-buffer))
5280       ;; First and last article in this newsgroup.
5281       (when gnus-newsgroup-headers
5282         (setq gnus-newsgroup-begin
5283               (mail-header-number (car gnus-newsgroup-headers))
5284               gnus-newsgroup-end
5285               (mail-header-number
5286                (gnus-last-element gnus-newsgroup-headers))))
5287       ;; GROUP is successfully selected.
5288       (or gnus-newsgroup-headers t)))))
5289
5290 (defun gnus-compute-unseen-list ()
5291   ;; The `seen' marks are treated specially.
5292   (if (not gnus-newsgroup-seen)
5293       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5294     (setq gnus-newsgroup-unseen
5295           (gnus-inverse-list-range-intersection
5296            gnus-newsgroup-articles gnus-newsgroup-seen))))
5297
5298 (defun gnus-summary-display-make-predicate (display)
5299   (require 'gnus-agent)
5300   (when (= (length display) 1)
5301     (setq display (car display)))
5302   (unless gnus-summary-display-cache
5303     (dolist (elem (append '((unread . unread)
5304                             (read . read)
5305                             (unseen . unseen))
5306                           gnus-article-mark-lists))
5307       (push (cons (cdr elem)
5308                   (gnus-byte-compile
5309                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5310             gnus-summary-display-cache)))
5311   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5312         (gnus-category-predicate-cache gnus-summary-display-cache))
5313     (gnus-get-predicate display)))
5314
5315 ;; Uses the dynamically bound `number' variable.
5316 (eval-when-compile
5317   (defvar number))
5318 (defun gnus-article-marked-p (type &optional article)
5319   (let ((article (or article number)))
5320     (cond
5321      ((eq type 'tick)
5322       (memq article gnus-newsgroup-marked))
5323      ((eq type 'spam)
5324       (memq article gnus-newsgroup-spam-marked))
5325      ((eq type 'unsend)
5326       (memq article gnus-newsgroup-unsendable))
5327      ((eq type 'undownload)
5328       (memq article gnus-newsgroup-undownloaded))
5329      ((eq type 'download)
5330       (memq article gnus-newsgroup-downloadable))
5331      ((eq type 'unread)
5332       (memq article gnus-newsgroup-unreads))
5333      ((eq type 'read)
5334       (memq article gnus-newsgroup-reads))
5335      ((eq type 'dormant)
5336       (memq article gnus-newsgroup-dormant) )
5337      ((eq type 'expire)
5338       (memq article gnus-newsgroup-expirable))
5339      ((eq type 'reply)
5340       (memq article gnus-newsgroup-replied))
5341      ((eq type 'killed)
5342       (memq article gnus-newsgroup-killed))
5343      ((eq type 'bookmark)
5344       (assq article gnus-newsgroup-bookmarks))
5345      ((eq type 'score)
5346       (assq article gnus-newsgroup-scored))
5347      ((eq type 'save)
5348       (memq article gnus-newsgroup-saved))
5349      ((eq type 'cache)
5350       (memq article gnus-newsgroup-cached))
5351      ((eq type 'forward)
5352       (memq article gnus-newsgroup-forwarded))
5353      ((eq type 'seen)
5354       (not (memq article gnus-newsgroup-unseen)))
5355      ((eq type 'recent)
5356       (memq article gnus-newsgroup-recent))
5357      (t t))))
5358
5359 (defun gnus-articles-to-read (group &optional read-all)
5360   "Find out what articles the user wants to read."
5361   (let* ((articles
5362           ;; Select all articles if `read-all' is non-nil, or if there
5363           ;; are no unread articles.
5364           (if (or read-all
5365                   (and (zerop (length gnus-newsgroup-marked))
5366                        (zerop (length gnus-newsgroup-unreads)))
5367                   ;; Fetch all if the predicate is non-nil.
5368                   gnus-newsgroup-display)
5369               ;; We want to select the headers for all the articles in
5370               ;; the group, so we select either all the active
5371               ;; articles in the group, or (if that's nil), the
5372               ;; articles in the cache.
5373               (or
5374                (gnus-uncompress-range (gnus-active group))
5375                (gnus-cache-articles-in-group group))
5376             ;; Select only the "normal" subset of articles.
5377             (gnus-sorted-nunion
5378              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5379              gnus-newsgroup-unreads)))
5380          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5381          (scored (length scored-list))
5382          (number (length articles))
5383          (marked (+ (length gnus-newsgroup-marked)
5384                     (length gnus-newsgroup-dormant)))
5385          (select
5386           (cond
5387            ((numberp read-all)
5388             read-all)
5389            ((numberp gnus-newsgroup-display)
5390             gnus-newsgroup-display)
5391            (t
5392             (condition-case ()
5393                 (cond
5394                  ((and (or (<= scored marked) (= scored number))
5395                        (numberp gnus-large-newsgroup)
5396                        (> number gnus-large-newsgroup))
5397                   (let* ((cursor-in-echo-area nil)
5398                          (initial (gnus-parameter-large-newsgroup-initial
5399                                    gnus-newsgroup-name))
5400                          (input
5401                           (read-string
5402                            (format
5403                             "How many articles from %s (%s %d): "
5404                             (gnus-limit-string
5405                              (gnus-group-decoded-name gnus-newsgroup-name)
5406                              35)
5407                             (if initial "max" "default")
5408                             number)
5409                            (if initial
5410                                (cons (number-to-string initial)
5411                                      0)))))
5412                     (if (string-match "^[ \t]*$" input) number input)))
5413                  ((and (> scored marked) (< scored number)
5414                        (> (- scored number) 20))
5415                   (let ((input
5416                          (read-string
5417                           (format "%s %s (%d scored, %d total): "
5418                                   "How many articles from"
5419                                   (gnus-group-decoded-name group)
5420                                   scored number))))
5421                     (if (string-match "^[ \t]*$" input)
5422                         number input)))
5423                  (t number))
5424               (quit
5425                (message "Quit getting the articles to read")
5426                nil))))))
5427     (setq select (if (stringp select) (string-to-number select) select))
5428     (if (or (null select) (zerop select))
5429         select
5430       (if (and (not (zerop scored)) (<= (abs select) scored))
5431           (progn
5432             (setq articles (sort scored-list '<))
5433             (setq number (length articles)))
5434         (setq articles (copy-sequence articles)))
5435
5436       (when (< (abs select) number)
5437         (if (< select 0)
5438             ;; Select the N oldest articles.
5439             (setcdr (nthcdr (1- (abs select)) articles) nil)
5440           ;; Select the N most recent articles.
5441           (setq articles (nthcdr (- number select) articles))))
5442       (setq gnus-newsgroup-unselected
5443             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5444       (when gnus-alter-articles-to-read-function
5445         (setq articles
5446               (sort
5447                (funcall gnus-alter-articles-to-read-function
5448                         gnus-newsgroup-name articles)
5449                '<)))
5450       articles)))
5451
5452 (defun gnus-killed-articles (killed articles)
5453   (let (out)
5454     (while articles
5455       (when (inline (gnus-member-of-range (car articles) killed))
5456         (push (car articles) out))
5457       (setq articles (cdr articles)))
5458     out))
5459
5460 (defun gnus-uncompress-marks (marks)
5461   "Uncompress the mark ranges in MARKS."
5462   (let ((uncompressed '(score bookmark))
5463         out)
5464     (while marks
5465       (if (memq (caar marks) uncompressed)
5466           (push (car marks) out)
5467         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5468       (setq marks (cdr marks)))
5469     out))
5470
5471 (defun gnus-article-mark-to-type (mark)
5472   "Return the type of MARK."
5473   (or (cadr (assq mark gnus-article-special-mark-lists))
5474       'list))
5475
5476 (defun gnus-article-unpropagatable-p (mark)
5477   "Return whether MARK should be propagated to back end."
5478   (memq mark gnus-article-unpropagated-mark-lists))
5479
5480 (defun gnus-adjust-marked-articles (info)
5481   "Set all article lists and remove all marks that are no longer valid."
5482   (let* ((marked-lists (gnus-info-marks info))
5483          (active (gnus-active (gnus-info-group info)))
5484          (min (car active))
5485          (max (cdr active))
5486          (types gnus-article-mark-lists)
5487          marks var articles article mark mark-type
5488          bgn end)
5489
5490     (dolist (marks marked-lists)
5491       (setq mark (car marks)
5492             mark-type (gnus-article-mark-to-type mark)
5493             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5494
5495       ;; We set the variable according to the type of the marks list,
5496       ;; and then adjust the marks to a subset of the active articles.
5497       (cond
5498        ;; Adjust "simple" lists - compressed yet unsorted
5499        ((eq mark-type 'list)
5500         ;; Simultaneously uncompress and clip to active range
5501         ;; See gnus-uncompress-range for a description of possible marks
5502         (let (l lh)
5503           (if (not (cadr marks))
5504               (set var nil)
5505             (setq articles (if (numberp (cddr marks))
5506                                (list (cdr marks))
5507                              (cdr marks))
5508                   lh (cons nil nil)
5509                   l lh)
5510
5511             (while (setq article (pop articles))
5512               (cond ((consp article)
5513                      (setq bgn (max (car article) min)
5514                            end (min (cdr article) max))
5515                      (while (<= bgn end)
5516                        (setq l (setcdr l (cons bgn nil))
5517                              bgn (1+ bgn))))
5518                     ((and (<= min article)
5519                           (>= max article))
5520                      (setq l (setcdr l (cons article nil))))))
5521             (set var (cdr lh)))))
5522        ;; Adjust assocs.
5523        ((eq mark-type 'tuple)
5524         (set var (setq articles (cdr marks)))
5525         (when (not (listp (cdr (symbol-value var))))
5526           (set var (list (symbol-value var))))
5527         (when (not (listp (cdr articles)))
5528           (setq articles (list articles)))
5529         (while articles
5530           (when (or (not (consp (setq article (pop articles))))
5531                     (< (car article) min)
5532                     (> (car article) max))
5533             (set var (delq article (symbol-value var))))))
5534        ;; Adjust ranges (sloppily).
5535        ((eq mark-type 'range)
5536         (cond
5537          ((eq mark 'seen)
5538           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5539           ;; It should be (seen (NUM1 . NUM2)).
5540           (when (numberp (cddr marks))
5541             (setcdr marks (list (cdr marks))))
5542           (setq articles (cdr marks))
5543           (while (and articles
5544                       (or (and (consp (car articles))
5545                                (> min (cdar articles)))
5546                           (and (numberp (car articles))
5547                                (> min (car articles)))))
5548             (pop articles))
5549           (set var articles))))))))
5550
5551 (defun gnus-update-missing-marks (missing)
5552   "Go through the list of MISSING articles and remove them from the mark lists."
5553   (when missing
5554     (let (var m)
5555       ;; Go through all types.
5556       (dolist (elem gnus-article-mark-lists)
5557         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5558           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5559           (when (symbol-value var)
5560             ;; This list has articles.  So we delete all missing
5561             ;; articles from it.
5562             (setq m missing)
5563             (while m
5564               (set var (delq (pop m) (symbol-value var))))))))))
5565
5566 (defun gnus-update-marks ()
5567   "Enter the various lists of marked articles into the newsgroup info list."
5568   (let ((types gnus-article-mark-lists)
5569         (info (gnus-get-info gnus-newsgroup-name))
5570         type list newmarked symbol delta-marks)
5571     (when info
5572       ;; Add all marks lists to the list of marks lists.
5573       (while (setq type (pop types))
5574         (setq list (symbol-value
5575                     (setq symbol
5576                           (intern (format "gnus-newsgroup-%s" (car type))))))
5577
5578         (when list
5579           ;; Get rid of the entries of the articles that have the
5580           ;; default score.
5581           (when (and (eq (cdr type) 'score)
5582                      gnus-save-score
5583                      list)
5584             (let* ((arts list)
5585                    (prev (cons nil list))
5586                    (all prev))
5587               (while arts
5588                 (if (or (not (consp (car arts)))
5589                         (= (cdar arts) gnus-summary-default-score))
5590                     (setcdr prev (cdr arts))
5591                   (setq prev arts))
5592                 (setq arts (cdr arts)))
5593               (setq list (cdr all)))))
5594
5595         (when (eq (cdr type) 'seen)
5596           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5597
5598         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5599           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5600
5601         (when (and (gnus-check-backend-function
5602                     'request-set-mark gnus-newsgroup-name)
5603                    (not (gnus-article-unpropagatable-p (cdr type))))
5604           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5605                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5606                  (add (gnus-remove-from-range
5607                        (gnus-copy-sequence list) old)))
5608             (when add
5609               (push (list add 'add (list (cdr type))) delta-marks))
5610             (when del
5611               (push (list del 'del (list (cdr type))) delta-marks))))
5612
5613         (when list
5614           (push (cons (cdr type) list) newmarked)))
5615
5616       (when delta-marks
5617         (unless (gnus-check-group gnus-newsgroup-name)
5618           (error "Can't open server for %s" gnus-newsgroup-name))
5619         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5620
5621       ;; Enter these new marks into the info of the group.
5622       (if (nthcdr 3 info)
5623           (setcar (nthcdr 3 info) newmarked)
5624         ;; Add the marks lists to the end of the info.
5625         (when newmarked
5626           (setcdr (nthcdr 2 info) (list newmarked))))
5627
5628       ;; Cut off the end of the info if there's nothing else there.
5629       (let ((i 5))
5630         (while (and (> i 2)
5631                     (not (nth i info)))
5632           (when (nthcdr (decf i) info)
5633             (setcdr (nthcdr i info) nil)))))))
5634
5635 (defun gnus-set-mode-line (where)
5636   "Set the mode line of the article or summary buffers.
5637 If WHERE is `summary', the summary mode line format will be used."
5638   ;; Is this mode line one we keep updated?
5639   (when (and (memq where gnus-updated-mode-lines)
5640              (symbol-value
5641               (intern (format "gnus-%s-mode-line-format-spec" where))))
5642     (let (mode-string)
5643       (save-excursion
5644         ;; We evaluate this in the summary buffer since these
5645         ;; variables are buffer-local to that buffer.
5646         (set-buffer gnus-summary-buffer)
5647        ;; We bind all these variables that are used in the `eval' form
5648         ;; below.
5649         (let* ((mformat (symbol-value
5650                          (intern
5651                           (format "gnus-%s-mode-line-format-spec" where))))
5652                (gnus-tmp-group-name (gnus-group-decoded-name
5653                                      gnus-newsgroup-name))
5654                (gnus-tmp-article-number (or gnus-current-article 0))
5655                (gnus-tmp-unread gnus-newsgroup-unreads)
5656                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5657                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5658                (gnus-tmp-unread-and-unselected
5659                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5660                             (zerop gnus-tmp-unselected))
5661                        "")
5662                       ((zerop gnus-tmp-unselected)
5663                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5664                       (t (format "{%d(+%d) more}"
5665                                  gnus-tmp-unread-and-unticked
5666                                  gnus-tmp-unselected))))
5667                (gnus-tmp-subject
5668                 (if (and gnus-current-headers
5669                          (vectorp gnus-current-headers))
5670                     (gnus-mode-string-quote
5671                      (mail-header-subject gnus-current-headers))
5672                   ""))
5673                bufname-length max-len
5674                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5675           (setq mode-string (eval mformat))
5676           (setq bufname-length (if (string-match "%b" mode-string)
5677                                    (- (length
5678                                        (buffer-name
5679                                         (if (eq where 'summary)
5680                                             nil
5681                                           (get-buffer gnus-article-buffer))))
5682                                       2)
5683                                  0))
5684           (setq max-len (max 4 (if gnus-mode-non-string-length
5685                                    (- (window-width)
5686                                       gnus-mode-non-string-length
5687                                       bufname-length)
5688                                  (length mode-string))))
5689           ;; We might have to chop a bit of the string off...
5690           (when (> (length mode-string) max-len)
5691             (setq mode-string
5692                   (concat (truncate-string-to-width mode-string (- max-len 3))
5693                           "...")))
5694           ;; Pad the mode string a bit.
5695           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5696       ;; Update the mode line.
5697       (setq mode-line-buffer-identification
5698             (gnus-mode-line-buffer-identification (list mode-string)))
5699       (set-buffer-modified-p t))))
5700
5701 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5702   "Go through the HEADERS list and add all Xrefs to a hash table.
5703 The resulting hash table is returned, or nil if no Xrefs were found."
5704   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5705          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5706          (xref-hashtb (gnus-make-hashtable))
5707          start group entry number xrefs header)
5708     (while headers
5709       (setq header (pop headers))
5710       (when (and (setq xrefs (mail-header-xref header))
5711                  (not (memq (setq number (mail-header-number header))
5712                             unreads)))
5713         (setq start 0)
5714         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5715           (setq start (match-end 0))
5716           (setq group (if prefix
5717                           (concat prefix (substring xrefs (match-beginning 1)
5718                                                     (match-end 1)))
5719                         (substring xrefs (match-beginning 1) (match-end 1))))
5720           (setq number
5721                 (string-to-int (substring xrefs (match-beginning 2)
5722                                           (match-end 2))))
5723           (if (setq entry (gnus-gethash group xref-hashtb))
5724               (setcdr entry (cons number (cdr entry)))
5725             (gnus-sethash group (cons number nil) xref-hashtb)))))
5726     (and start xref-hashtb)))
5727
5728 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5729   "Look through all the headers and mark the Xrefs as read."
5730   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5731         name info xref-hashtb idlist method nth4)
5732     (save-excursion
5733       (set-buffer gnus-group-buffer)
5734       (when (setq xref-hashtb
5735                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5736         (mapatoms
5737          (lambda (group)
5738            (unless (string= from-newsgroup (setq name (symbol-name group)))
5739              (setq idlist (symbol-value group))
5740              ;; Dead groups are not updated.
5741              (and (prog1
5742                       (setq info (gnus-get-info name))
5743                     (when (stringp (setq nth4 (gnus-info-method info)))
5744                       (setq nth4 (gnus-server-to-method nth4))))
5745                   ;; Only do the xrefs if the group has the same
5746                   ;; select method as the group we have just read.
5747                   (or (gnus-methods-equal-p
5748                        nth4 (gnus-find-method-for-group from-newsgroup))
5749                       virtual
5750                       (equal nth4 (setq method (gnus-find-method-for-group
5751                                                 from-newsgroup)))
5752                       (and (equal (car nth4) (car method))
5753                            (equal (nth 1 nth4) (nth 1 method))))
5754                   gnus-use-cross-reference
5755                   (or (not (eq gnus-use-cross-reference t))
5756                       virtual
5757                       ;; Only do cross-references on subscribed
5758                       ;; groups, if that is what is wanted.
5759                       (<= (gnus-info-level info) gnus-level-subscribed))
5760                   (gnus-group-make-articles-read name idlist))))
5761          xref-hashtb)))))
5762
5763 (defun gnus-compute-read-articles (group articles)
5764   (let* ((entry (gnus-group-entry group))
5765          (info (nth 2 entry))
5766          (active (gnus-active group))
5767          ninfo)
5768     (when entry
5769       ;; First peel off all invalid article numbers.
5770       (when active
5771         (let ((ids articles)
5772               id first)
5773           (while (setq id (pop ids))
5774             (when (and first (> id (cdr active)))
5775               ;; We'll end up in this situation in one particular
5776               ;; obscure situation.  If you re-scan a group and get
5777               ;; a new article that is cross-posted to a different
5778               ;; group that has not been re-scanned, you might get
5779               ;; crossposted article that has a higher number than
5780               ;; Gnus believes possible.  So we re-activate this
5781               ;; group as well.  This might mean doing the
5782               ;; crossposting thingy will *increase* the number
5783               ;; of articles in some groups.  Tsk, tsk.
5784               (setq active (or (gnus-activate-group group) active)))
5785             (when (or (> id (cdr active))
5786                       (< id (car active)))
5787               (setq articles (delq id articles))))))
5788       ;; If the read list is nil, we init it.
5789       (if (and active
5790                (null (gnus-info-read info))
5791                (> (car active) 1))
5792           (setq ninfo (cons 1 (1- (car active))))
5793         (setq ninfo (gnus-info-read info)))
5794       ;; Then we add the read articles to the range.
5795       (gnus-add-to-range
5796        ninfo (setq articles (sort articles '<))))))
5797
5798 (defun gnus-group-make-articles-read (group articles)
5799   "Update the info of GROUP to say that ARTICLES are read."
5800   (let* ((num 0)
5801          (entry (gnus-group-entry group))
5802          (info (nth 2 entry))
5803          (active (gnus-active group))
5804          range)
5805     (when entry
5806       (setq range (gnus-compute-read-articles group articles))
5807       (with-current-buffer gnus-group-buffer
5808         (gnus-undo-register
5809           `(progn
5810              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5811              (gnus-info-set-read ',info ',(gnus-info-read info))
5812              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5813              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5814              (gnus-group-update-group ,group t))))
5815       ;; Add the read articles to the range.
5816       (gnus-info-set-read info range)
5817       (gnus-request-set-mark group (list (list range 'add '(read))))
5818       ;; Then we have to re-compute how many unread
5819       ;; articles there are in this group.
5820       (when active
5821         (cond
5822          ((not range)
5823           (setq num (- (1+ (cdr active)) (car active))))
5824          ((not (listp (cdr range)))
5825           (setq num (- (cdr active) (- (1+ (cdr range))
5826                                        (car range)))))
5827          (t
5828           (while range
5829             (if (numberp (car range))
5830                 (setq num (1+ num))
5831               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5832             (setq range (cdr range)))
5833           (setq num (- (cdr active) num))))
5834         ;; Update the number of unread articles.
5835         (setcar entry num)
5836         ;; Update the group buffer.
5837         (unless (gnus-ephemeral-group-p group)
5838           (gnus-group-update-group group t))))))
5839
5840 (defvar gnus-newsgroup-none-id 0)
5841
5842 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5843   (let ((cur nntp-server-buffer)
5844         (dependencies
5845          (or dependencies
5846              (with-current-buffer gnus-summary-buffer
5847                gnus-newsgroup-dependencies)))
5848         headers id end ref number
5849         (mail-parse-charset gnus-newsgroup-charset)
5850         (mail-parse-ignored-charsets
5851          (save-excursion (condition-case nil
5852                              (set-buffer gnus-summary-buffer)
5853                            (error))
5854                          gnus-newsgroup-ignored-charsets)))
5855     (save-excursion
5856       (set-buffer nntp-server-buffer)
5857       ;; Translate all TAB characters into SPACE characters.
5858       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5859       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5860       (ietf-drums-unfold-fws)
5861       (gnus-run-hooks 'gnus-parse-headers-hook)
5862       (let ((case-fold-search t)
5863             in-reply-to header p lines chars)
5864         (goto-char (point-min))
5865         ;; Search to the beginning of the next header.  Error messages
5866         ;; do not begin with 2 or 3.
5867         (while (re-search-forward "^[23][0-9]+ " nil t)
5868           (setq id nil
5869                 ref nil)
5870           ;; This implementation of this function, with nine
5871           ;; search-forwards instead of the one re-search-forward and
5872           ;; a case (which basically was the old function) is actually
5873           ;; about twice as fast, even though it looks messier.  You
5874           ;; can't have everything, I guess.  Speed and elegance
5875           ;; doesn't always go hand in hand.
5876           (setq
5877            header
5878            (vector
5879             ;; Number.
5880             (prog1
5881                 (setq number (read cur))
5882               (end-of-line)
5883               (setq p (point))
5884               (narrow-to-region (point)
5885                                 (or (and (search-forward "\n.\n" nil t)
5886                                          (- (point) 2))
5887                                     (point))))
5888             ;; Subject.
5889             (progn
5890               (goto-char p)
5891               (if (search-forward "\nsubject:" nil t)
5892                   (funcall gnus-decode-encoded-word-function
5893                            (nnheader-header-value))
5894                 "(none)"))
5895             ;; From.
5896             (progn
5897               (goto-char p)
5898               (if (search-forward "\nfrom:" nil t)
5899                   (funcall gnus-decode-encoded-word-function
5900                            (nnheader-header-value))
5901                 "(nobody)"))
5902             ;; Date.
5903             (progn
5904               (goto-char p)
5905               (if (search-forward "\ndate:" nil t)
5906                   (nnheader-header-value) ""))
5907             ;; Message-ID.
5908             (progn
5909               (goto-char p)
5910               (setq id (if (re-search-forward
5911                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5912                            ;; We do it this way to make sure the Message-ID
5913                            ;; is (somewhat) syntactically valid.
5914                            (buffer-substring (match-beginning 1)
5915                                              (match-end 1))
5916                          ;; If there was no message-id, we just fake one
5917                          ;; to make subsequent routines simpler.
5918                          (nnheader-generate-fake-message-id number))))
5919             ;; References.
5920             (progn
5921               (goto-char p)
5922               (if (search-forward "\nreferences:" nil t)
5923                   (progn
5924                     (setq end (point))
5925                     (prog1
5926                         (nnheader-header-value)
5927                       (setq ref
5928                             (buffer-substring
5929                              (progn
5930                                (end-of-line)
5931                                (search-backward ">" end t)
5932                                (1+ (point)))
5933                              (progn
5934                                (search-backward "<" end t)
5935                                (point))))))
5936                 ;; Get the references from the in-reply-to header if there
5937                 ;; were no references and the in-reply-to header looks
5938                 ;; promising.
5939                 (if (and (search-forward "\nin-reply-to:" nil t)
5940                          (setq in-reply-to (nnheader-header-value))
5941                          (string-match "<[^>]+>" in-reply-to))
5942                     (let (ref2)
5943                       (setq ref (substring in-reply-to (match-beginning 0)
5944                                            (match-end 0)))
5945                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5946                         (setq ref2 (substring in-reply-to (match-beginning 0)
5947                                               (match-end 0)))
5948                         (when (> (length ref2) (length ref))
5949                           (setq ref ref2)))
5950                       ref)
5951                   (setq ref nil))))
5952             ;; Chars.
5953             (progn
5954               (goto-char p)
5955               (if (search-forward "\nchars: " nil t)
5956                   (if (numberp (setq chars (ignore-errors (read cur))))
5957                       chars -1)
5958                 -1))
5959             ;; Lines.
5960             (progn
5961               (goto-char p)
5962               (if (search-forward "\nlines: " nil t)
5963                   (if (numberp (setq lines (ignore-errors (read cur))))
5964                       lines -1)
5965                 -1))
5966             ;; Xref.
5967             (progn
5968               (goto-char p)
5969               (and (search-forward "\nxref:" nil t)
5970                    (nnheader-header-value)))
5971             ;; Extra.
5972             (when gnus-extra-headers
5973               (let ((extra gnus-extra-headers)
5974                     out)
5975                 (while extra
5976                   (goto-char p)
5977                   (when (search-forward
5978                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5979                     (push (cons (car extra) (nnheader-header-value))
5980                           out))
5981                   (pop extra))
5982                 out))))
5983           (when (equal id ref)
5984             (setq ref nil))
5985
5986           (when gnus-alter-header-function
5987             (funcall gnus-alter-header-function header)
5988             (setq id (mail-header-id header)
5989                   ref (gnus-parent-id (mail-header-references header))))
5990
5991           (when (setq header
5992                       (gnus-dependencies-add-header
5993                        header dependencies force-new))
5994             (push header headers))
5995           (goto-char (point-max))
5996           (widen))
5997         (nreverse headers)))))
5998
5999 ;; Goes through the xover lines and returns a list of vectors
6000 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6001                                                   force-new dependencies
6002                                                   group also-fetch-heads)
6003   "Parse the news overview data in the server buffer.
6004 Return a list of headers that match SEQUENCE (see
6005 `nntp-retrieve-headers')."
6006   ;; Get the Xref when the users reads the articles since most/some
6007   ;; NNTP servers do not include Xrefs when using XOVER.
6008   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6009   (let ((mail-parse-charset gnus-newsgroup-charset)
6010         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6011         (cur nntp-server-buffer)
6012         (dependencies (or dependencies gnus-newsgroup-dependencies))
6013         (allp (cond
6014                ((eq gnus-read-all-available-headers t)
6015                 t)
6016                ((stringp gnus-read-all-available-headers)
6017                 (string-match gnus-read-all-available-headers group))
6018                (t
6019                 nil)))
6020         number headers header)
6021     (save-excursion
6022       (set-buffer nntp-server-buffer)
6023       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6024       ;; Allow the user to mangle the headers before parsing them.
6025       (gnus-run-hooks 'gnus-parse-headers-hook)
6026       (goto-char (point-min))
6027       (gnus-parse-without-error
6028         (while (and (or sequence allp)
6029                     (not (eobp)))
6030           (setq number (read cur))
6031           (when (not allp)
6032             (while (and sequence
6033                         (< (car sequence) number))
6034               (setq sequence (cdr sequence))))
6035           (when (and (or allp
6036                          (and sequence
6037                               (eq number (car sequence))))
6038                      (progn
6039                        (setq sequence (cdr sequence))
6040                        (setq header (inline
6041                                       (gnus-nov-parse-line
6042                                        number dependencies force-new)))))
6043             (push header headers))
6044           (forward-line 1)))
6045       ;; A common bug in inn is that if you have posted an article and
6046       ;; then retrieves the active file, it will answer correctly --
6047       ;; the new article is included.  However, a NOV entry for the
6048       ;; article may not have been generated yet, so this may fail.
6049       ;; We work around this problem by retrieving the last few
6050       ;; headers using HEAD.
6051       (if (or (not also-fetch-heads)
6052               (not sequence))
6053           ;; We (probably) got all the headers.
6054           (nreverse headers)
6055         (let ((gnus-nov-is-evil t))
6056           (nconc
6057            (nreverse headers)
6058            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6059              (gnus-get-newsgroup-headers))))))))
6060
6061 (defun gnus-article-get-xrefs ()
6062   "Fill in the Xref value in `gnus-current-headers', if necessary.
6063 This is meant to be called in `gnus-article-internal-prepare-hook'."
6064   (let ((headers (with-current-buffer gnus-summary-buffer
6065                    gnus-current-headers)))
6066     (or (not gnus-use-cross-reference)
6067         (not headers)
6068         (and (mail-header-xref headers)
6069              (not (string= (mail-header-xref headers) "")))
6070         (let ((case-fold-search t)
6071               xref)
6072           (save-restriction
6073             (nnheader-narrow-to-headers)
6074             (goto-char (point-min))
6075             (when (or (and (not (eobp))
6076                            (eq (downcase (char-after)) ?x)
6077                            (looking-at "Xref:"))
6078                       (search-forward "\nXref:" nil t))
6079               (goto-char (1+ (match-end 0)))
6080               (setq xref (buffer-substring (point) (point-at-eol)))
6081               (mail-header-set-xref headers xref)))))))
6082
6083 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6084   "Find article ID and insert the summary line for that article.
6085 OLD-HEADER can either be a header or a line number to insert
6086 the subject line on."
6087   (let* ((line (and (numberp old-header) old-header))
6088          (old-header (and (vectorp old-header) old-header))
6089          (header (cond ((and old-header use-old-header)
6090                         old-header)
6091                        ((and (numberp id)
6092                              (gnus-number-to-header id))
6093                         (gnus-number-to-header id))
6094                        (t
6095                         (gnus-read-header id))))
6096          (number (and (numberp id) id))
6097          d)
6098     (when header
6099       ;; Rebuild the thread that this article is part of and go to the
6100       ;; article we have fetched.
6101       (when (and (not gnus-show-threads)
6102                  old-header)
6103         (when (and number
6104                    (setq d (gnus-data-find (mail-header-number old-header))))
6105           (goto-char (gnus-data-pos d))
6106           (gnus-data-remove
6107            number
6108            (- (point-at-bol)
6109               (prog1
6110                   (1+ (point-at-eol))
6111                 (gnus-delete-line))))))
6112       ;; Remove list identifiers from subject.
6113       (when gnus-list-identifiers
6114         (let ((gnus-newsgroup-headers (list header)))
6115           (gnus-summary-remove-list-identifiers)))
6116       (when old-header
6117         (mail-header-set-number header (mail-header-number old-header)))
6118       (setq gnus-newsgroup-sparse
6119             (delq (setq number (mail-header-number header))
6120                   gnus-newsgroup-sparse))
6121       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6122       (push number gnus-newsgroup-limit)
6123       (gnus-rebuild-thread (mail-header-id header) line)
6124       (gnus-summary-goto-subject number nil t))
6125     (when (and (numberp number)
6126                (> number 0))
6127       ;; We have to update the boundaries even if we can't fetch the
6128       ;; article if ID is a number -- so that the next `P' or `N'
6129       ;; command will fetch the previous (or next) article even
6130       ;; if the one we tried to fetch this time has been canceled.
6131       (when (> number gnus-newsgroup-end)
6132         (setq gnus-newsgroup-end number))
6133       (when (< number gnus-newsgroup-begin)
6134         (setq gnus-newsgroup-begin number))
6135       (setq gnus-newsgroup-unselected
6136             (delq number gnus-newsgroup-unselected)))
6137     ;; Report back a success?
6138     (and header (mail-header-number header))))
6139
6140 ;;; Process/prefix in the summary buffer
6141
6142 (defun gnus-summary-work-articles (n)
6143   "Return a list of articles to be worked upon.
6144 The prefix argument, the list of process marked articles, and the
6145 current article will be taken into consideration."
6146   (save-excursion
6147     (set-buffer gnus-summary-buffer)
6148     (cond
6149      (n
6150       ;; A numerical prefix has been given.
6151       (setq n (prefix-numeric-value n))
6152       (let ((backward (< n 0))
6153             (n (abs (prefix-numeric-value n)))
6154             articles article)
6155         (save-excursion
6156           (while
6157               (and (> n 0)
6158                    (push (setq article (gnus-summary-article-number))
6159                          articles)
6160                    (if backward
6161                        (gnus-summary-find-prev nil article)
6162                      (gnus-summary-find-next nil article)))
6163             (decf n)))
6164         (nreverse articles)))
6165      ((and (gnus-region-active-p) (mark))
6166       (message "region active")
6167       ;; Work on the region between point and mark.
6168       (let ((max (max (point) (mark)))
6169             articles article)
6170         (save-excursion
6171           (goto-char (min (min (point) (mark))))
6172           (while
6173               (and
6174                (push (setq article (gnus-summary-article-number)) articles)
6175                (gnus-summary-find-next nil article)
6176                (< (point) max)))
6177           (nreverse articles))))
6178      (gnus-newsgroup-processable
6179       ;; There are process-marked articles present.
6180       ;; Save current state.
6181       (gnus-summary-save-process-mark)
6182       ;; Return the list.
6183       (reverse gnus-newsgroup-processable))
6184      (t
6185       ;; Just return the current article.
6186       (list (gnus-summary-article-number))))))
6187
6188 (defmacro gnus-summary-iterate (arg &rest forms)
6189   "Iterate over the process/prefixed articles and do FORMS.
6190 ARG is the interactive prefix given to the command.  FORMS will be
6191 executed with point over the summary line of the articles."
6192   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6193     `(let ((,articles (gnus-summary-work-articles ,arg)))
6194        (while ,articles
6195          (gnus-summary-goto-subject (car ,articles))
6196          ,@forms
6197          (pop ,articles)))))
6198
6199 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6200 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6201
6202 (defun gnus-summary-save-process-mark ()
6203   "Push the current set of process marked articles on the stack."
6204   (interactive)
6205   (push (copy-sequence gnus-newsgroup-processable)
6206         gnus-newsgroup-process-stack))
6207
6208 (defun gnus-summary-kill-process-mark ()
6209   "Push the current set of process marked articles on the stack and unmark."
6210   (interactive)
6211   (gnus-summary-save-process-mark)
6212   (gnus-summary-unmark-all-processable))
6213
6214 (defun gnus-summary-yank-process-mark ()
6215   "Pop the last process mark state off the stack and restore it."
6216   (interactive)
6217   (unless gnus-newsgroup-process-stack
6218     (error "Empty mark stack"))
6219   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6220
6221 (defun gnus-summary-process-mark-set (set)
6222   "Make SET into the current process marked articles."
6223   (gnus-summary-unmark-all-processable)
6224   (mapc 'gnus-summary-set-process-mark set))
6225
6226 ;;; Searching and stuff
6227
6228 (defun gnus-summary-search-group (&optional backward use-level)
6229   "Search for next unread newsgroup.
6230 If optional argument BACKWARD is non-nil, search backward instead."
6231   (save-excursion
6232     (set-buffer gnus-group-buffer)
6233     (when (gnus-group-search-forward
6234            backward nil (if use-level (gnus-group-group-level) nil))
6235       (gnus-group-group-name))))
6236
6237 (defun gnus-summary-best-group (&optional exclude-group)
6238   "Find the name of the best unread group.
6239 If EXCLUDE-GROUP, do not go to this group."
6240   (with-current-buffer gnus-group-buffer
6241     (save-excursion
6242       (gnus-group-best-unread-group exclude-group))))
6243
6244 (defun gnus-summary-find-next (&optional unread article backward)
6245   (if backward
6246       (gnus-summary-find-prev unread article)
6247     (let* ((dummy (gnus-summary-article-intangible-p))
6248            (article (or article (gnus-summary-article-number)))
6249            (data (gnus-data-find-list article))
6250            result)
6251       (when (and (not dummy)
6252                  (or (not gnus-summary-check-current)
6253                      (not unread)
6254                      (not (gnus-data-unread-p (car data)))))
6255         (setq data (cdr data)))
6256       (when (setq result
6257                   (if unread
6258                       (progn
6259                         (while data
6260                           (unless (memq (gnus-data-number (car data))
6261                                         (cond
6262                                          ((eq gnus-auto-goto-ignores
6263                                               'always-undownloaded)
6264                                           gnus-newsgroup-undownloaded)
6265                                          (gnus-plugged
6266                                           nil)
6267                                          ((eq gnus-auto-goto-ignores
6268                                               'unfetched)
6269                                           gnus-newsgroup-unfetched)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'undownloaded)
6272                                           gnus-newsgroup-undownloaded)))
6273                             (when (gnus-data-unread-p (car data))
6274                               (setq result (car data)
6275                                     data nil)))
6276                           (setq data (cdr data)))
6277                         result)
6278                     (car data)))
6279         (goto-char (gnus-data-pos result))
6280         (gnus-data-number result)))))
6281
6282 (defun gnus-summary-find-prev (&optional unread article)
6283   (let* ((eobp (eobp))
6284          (article (or article (gnus-summary-article-number)))
6285          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6286          result)
6287     (when (and (not eobp)
6288                (or (not gnus-summary-check-current)
6289                    (not unread)
6290                    (not (gnus-data-unread-p (car data)))))
6291       (setq data (cdr data)))
6292     (when (setq result
6293                 (if unread
6294                     (progn
6295                       (while data
6296                         (unless (memq (gnus-data-number (car data))
6297                                       (cond
6298                                        ((eq gnus-auto-goto-ignores
6299                                             'always-undownloaded)
6300                                         gnus-newsgroup-undownloaded)
6301                                        (gnus-plugged
6302                                         nil)
6303                                        ((eq gnus-auto-goto-ignores
6304                                             'unfetched)
6305                                         gnus-newsgroup-unfetched)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'undownloaded)
6308                                         gnus-newsgroup-undownloaded)))
6309                           (when (gnus-data-unread-p (car data))
6310                             (setq result (car data)
6311                                   data nil)))
6312                         (setq data (cdr data)))
6313                       result)
6314                   (car data)))
6315       (goto-char (gnus-data-pos result))
6316       (gnus-data-number result))))
6317
6318 (defun gnus-summary-find-subject (subject &optional unread backward article)
6319   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6320          (article (or article (gnus-summary-article-number)))
6321          (articles (gnus-data-list backward))
6322          (arts (gnus-data-find-list article articles))
6323          result)
6324     (when (or (not gnus-summary-check-current)
6325               (not unread)
6326               (not (gnus-data-unread-p (car arts))))
6327       (setq arts (cdr arts)))
6328     (while arts
6329       (and (or (not unread)
6330                (gnus-data-unread-p (car arts)))
6331            (vectorp (gnus-data-header (car arts)))
6332            (gnus-subject-equal
6333             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6334            (setq result (car arts)
6335                  arts nil))
6336       (setq arts (cdr arts)))
6337     (and result
6338          (goto-char (gnus-data-pos result))
6339          (gnus-data-number result))))
6340
6341 (defun gnus-summary-search-forward (&optional unread subject backward)
6342   "Search forward for an article.
6343 If UNREAD, look for unread articles.  If SUBJECT, look for
6344 articles with that subject.  If BACKWARD, search backward instead."
6345   (cond (subject (gnus-summary-find-subject subject unread backward))
6346         (backward (gnus-summary-find-prev unread))
6347         (t (gnus-summary-find-next unread))))
6348
6349 (defun gnus-recenter (&optional n)
6350   "Center point in window and redisplay frame.
6351 Also do horizontal recentering."
6352   (interactive "P")
6353   (when (and gnus-auto-center-summary
6354              (not (eq gnus-auto-center-summary 'vertical)))
6355     (gnus-horizontal-recenter))
6356   (recenter n))
6357
6358 (defun gnus-summary-recenter ()
6359   "Center point in the summary window.
6360 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6361 displayed, no centering will be performed."
6362   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6363   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6364   (interactive)
6365   ;; The user has to want it.
6366   (when gnus-auto-center-summary
6367     (let* ((top (cond ((< (window-height) 4) 0)
6368                       ((< (window-height) 7) 1)
6369                       (t (if (numberp gnus-auto-center-summary)
6370                              gnus-auto-center-summary
6371                            (/ (1- (window-height)) 2)))))
6372            (height (1- (window-height)))
6373            (bottom (save-excursion (goto-char (point-max))
6374                                    (forward-line (- height))
6375                                    (point)))
6376            (window (get-buffer-window (current-buffer))))
6377       (when (get-buffer-window gnus-article-buffer)
6378         ;; Only do recentering when the article buffer is displayed,
6379         ;; Set the window start to either `bottom', which is the biggest
6380         ;; possible valid number, or the second line from the top,
6381         ;; whichever is the least.
6382         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6383           (if (> bottom top-pos)
6384               ;; Keep the second line from the top visible
6385               (set-window-start window top-pos t)
6386             ;; Try to keep the bottom line visible; if it's partially
6387             ;; obscured, either scroll one more line to make it fully
6388             ;; visible, or revert to using TOP-POS.
6389             (save-excursion
6390               (goto-char (point-max))
6391               (forward-line -1)
6392               (let ((last-line-start (point)))
6393                 (goto-char bottom)
6394                 (set-window-start window (point) t)
6395                 (when (not (pos-visible-in-window-p last-line-start window))
6396                   (forward-line 1)
6397                   (set-window-start window (min (point) top-pos) t)))))))
6398       ;; Do horizontal recentering while we're at it.
6399       (when (and (get-buffer-window (current-buffer) t)
6400                  (not (eq gnus-auto-center-summary 'vertical)))
6401         (let ((selected (selected-window)))
6402           (select-window (get-buffer-window (current-buffer) t))
6403           (gnus-summary-position-point)
6404           (gnus-horizontal-recenter)
6405           (select-window selected))))))
6406
6407 (defun gnus-summary-jump-to-group (newsgroup)
6408   "Move point to NEWSGROUP in group mode buffer."
6409   ;; Keep update point of group mode buffer if visible.
6410   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6411       (save-window-excursion
6412         ;; Take care of tree window mode.
6413         (when (get-buffer-window gnus-group-buffer)
6414           (pop-to-buffer gnus-group-buffer))
6415         (gnus-group-jump-to-group newsgroup))
6416     (save-excursion
6417       ;; Take care of tree window mode.
6418       (if (get-buffer-window gnus-group-buffer)
6419           (pop-to-buffer gnus-group-buffer)
6420         (set-buffer gnus-group-buffer))
6421       (gnus-group-jump-to-group newsgroup))))
6422
6423 ;; This function returns a list of article numbers based on the
6424 ;; difference between the ranges of read articles in this group and
6425 ;; the range of active articles.
6426 (defun gnus-list-of-unread-articles (group)
6427   (let* ((read (gnus-info-read (gnus-get-info group)))
6428          (active (or (gnus-active group) (gnus-activate-group group)))
6429          (last (cdr active))
6430          first nlast unread)
6431     ;; If none are read, then all are unread.
6432     (if (not read)
6433         (setq first (car active))
6434       ;; If the range of read articles is a single range, then the
6435       ;; first unread article is the article after the last read
6436       ;; article.  Sounds logical, doesn't it?
6437       (if (and (not (listp (cdr read)))
6438                (or (< (car read) (car active))
6439                    (progn (setq read (list read))
6440                           nil)))
6441           (setq first (max (car active) (1+ (cdr read))))
6442         ;; `read' is a list of ranges.
6443         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6444                                   (caar read)))
6445                   1)
6446           (setq first (car active)))
6447         (while read
6448           (when first
6449             (while (< first nlast)
6450               (setq unread (cons first unread)
6451                     first (1+ first))))
6452           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6453           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6454           (setq read (cdr read)))))
6455     ;; And add the last unread articles.
6456     (while (<= first last)
6457       (setq unread (cons first unread)
6458             first (1+ first)))
6459     ;; Return the list of unread articles.
6460     (delq 0 (nreverse unread))))
6461
6462 (defun gnus-list-of-read-articles (group)
6463   "Return a list of unread, unticked and non-dormant articles."
6464   (let* ((info (gnus-get-info group))
6465          (marked (gnus-info-marks info))
6466          (active (gnus-active group)))
6467     (and info active
6468          (gnus-list-range-difference
6469           (gnus-list-range-difference
6470            (gnus-sorted-complement
6471             (gnus-uncompress-range active)
6472             (gnus-list-of-unread-articles group))
6473            (cdr (assq 'dormant marked)))
6474           (cdr (assq 'tick marked))))))
6475
6476 ;; This function returns a sequence of article numbers based on the
6477 ;; difference between the ranges of read articles in this group and
6478 ;; the range of active articles.
6479 (defun gnus-sequence-of-unread-articles (group)
6480   (let* ((read (gnus-info-read (gnus-get-info group)))
6481          (active (or (gnus-active group) (gnus-activate-group group)))
6482          (last (cdr active))
6483          first nlast unread)
6484     ;; If none are read, then all are unread.
6485     (if (not read)
6486         (setq first (car active))
6487       ;; If the range of read articles is a single range, then the
6488       ;; first unread article is the article after the last read
6489       ;; article.  Sounds logical, doesn't it?
6490       (if (and (not (listp (cdr read)))
6491                (or (< (car read) (car active))
6492                    (progn (setq read (list read))
6493                           nil)))
6494           (setq first (max (car active) (1+ (cdr read))))
6495         ;; `read' is a list of ranges.
6496         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6497                                   (caar read)))
6498                   1)
6499           (setq first (car active)))
6500         (while read
6501           (when first
6502             (push (cons first nlast) unread))
6503           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6504           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6505           (setq read (cdr read)))))
6506     ;; And add the last unread articles.
6507     (cond ((< first last)
6508            (push (cons first last) unread))
6509           ((= first last)
6510            (push first unread)))
6511     ;; Return the sequence of unread articles.
6512     (delq 0 (nreverse unread))))
6513
6514 ;; Various summary commands
6515
6516 (defun gnus-summary-select-article-buffer ()
6517   "Reconfigure windows to show article buffer."
6518   (interactive)
6519   (if (not (gnus-buffer-live-p gnus-article-buffer))
6520       (error "There is no article buffer for this summary buffer")
6521     (gnus-configure-windows 'article)
6522     (select-window (get-buffer-window gnus-article-buffer))))
6523
6524 (defun gnus-summary-universal-argument (arg)
6525   "Perform any operation on all articles that are process/prefixed."
6526   (interactive "P")
6527   (let ((articles (gnus-summary-work-articles arg))
6528         func article)
6529     (if (eq
6530          (setq
6531           func
6532           (key-binding
6533            (read-key-sequence
6534             (substitute-command-keys
6535              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6536          'undefined)
6537         (gnus-error 1 "Undefined key")
6538       (save-excursion
6539         (while articles
6540           (gnus-summary-goto-subject (setq article (pop articles)))
6541           (let (gnus-newsgroup-processable)
6542             (command-execute func))
6543           (gnus-summary-remove-process-mark article)))))
6544   (gnus-summary-position-point))
6545
6546 (defun gnus-summary-toggle-truncation (&optional arg)
6547   "Toggle truncation of summary lines.
6548 With ARG, turn line truncation on if ARG is positive."
6549   (interactive "P")
6550   (setq truncate-lines
6551         (if (null arg) (not truncate-lines)
6552           (> (prefix-numeric-value arg) 0)))
6553   (redraw-display))
6554
6555 (defun gnus-summary-find-for-reselect ()
6556   "Return the number of an article to stay on across a reselect.
6557 The current article is considered, then following articles, then previous
6558 articles.  An article is sought which is not cancelled and isn't a temporary
6559 insertion from another group.  If there's no such then return a dummy 0."
6560   (let (found)
6561     (dolist (rev '(nil t))
6562       (unless found      ; don't demand the reverse list if we don't need it
6563         (let ((data (gnus-data-find-list
6564                      (gnus-summary-article-number) (gnus-data-list rev))))
6565           (while (and data (not found))
6566             (if (and (< 0 (gnus-data-number (car data)))
6567                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6568                 (setq found (gnus-data-number (car data))))
6569             (setq data (cdr data))))))
6570     (or found 0)))
6571
6572 (defun gnus-summary-reselect-current-group (&optional all rescan)
6573   "Exit and then reselect the current newsgroup.
6574 The prefix argument ALL means to select all articles."
6575   (interactive "P")
6576   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6577     (error "Ephemeral groups can't be reselected"))
6578   (let ((current-subject (gnus-summary-find-for-reselect))
6579         (group gnus-newsgroup-name))
6580     (setq gnus-newsgroup-begin nil)
6581     (gnus-summary-exit nil 'leave-hidden)
6582     ;; We have to adjust the point of group mode buffer because
6583     ;; point was moved to the next unread newsgroup by exiting.
6584     (gnus-summary-jump-to-group group)
6585     (when rescan
6586       (save-excursion
6587         (gnus-group-get-new-news-this-group 1)))
6588     (gnus-group-read-group all t)
6589     (gnus-summary-goto-subject current-subject nil t)))
6590
6591 (defun gnus-summary-rescan-group (&optional all)
6592   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6593   (interactive "P")
6594   (gnus-summary-reselect-current-group all t))
6595
6596 (defun gnus-summary-update-info (&optional non-destructive)
6597   (save-excursion
6598     (let ((group gnus-newsgroup-name))
6599       (when group
6600         (when gnus-newsgroup-kill-headers
6601           (setq gnus-newsgroup-killed
6602                 (gnus-compress-sequence
6603                  (gnus-sorted-union
6604                   (gnus-list-range-intersection
6605                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6606                   gnus-newsgroup-unreads)
6607                  t)))
6608         (unless (listp (cdr gnus-newsgroup-killed))
6609           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6610         (let ((headers gnus-newsgroup-headers))
6611           ;; Set the new ranges of read articles.
6612           (with-current-buffer gnus-group-buffer
6613             (gnus-undo-force-boundary))
6614           (gnus-update-read-articles
6615            group (gnus-sorted-union
6616                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6617           ;; Set the current article marks.
6618           (let ((gnus-newsgroup-scored
6619                  (if (and (not gnus-save-score)
6620                           (not non-destructive))
6621                      nil
6622                    gnus-newsgroup-scored)))
6623             (save-excursion
6624               (gnus-update-marks)))
6625           ;; Do the cross-ref thing.
6626           (when gnus-use-cross-reference
6627             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6628           ;; Do not switch windows but change the buffer to work.
6629           (set-buffer gnus-group-buffer)
6630           (unless (gnus-ephemeral-group-p group)
6631             (gnus-group-update-group group)))))))
6632
6633 (defun gnus-summary-save-newsrc (&optional force)
6634   "Save the current number of read/marked articles in the dribble buffer.
6635 The dribble buffer will then be saved.
6636 If FORCE (the prefix), also save the .newsrc file(s)."
6637   (interactive "P")
6638   (gnus-summary-update-info t)
6639   (if force
6640       (gnus-save-newsrc-file)
6641     (gnus-dribble-save)))
6642
6643 (defun gnus-summary-exit (&optional temporary leave-hidden)
6644   "Exit reading current newsgroup, and then return to group selection mode.
6645 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6646   (interactive)
6647   (gnus-set-global-variables)
6648   (when (gnus-buffer-live-p gnus-article-buffer)
6649     (save-excursion
6650       (set-buffer gnus-article-buffer)
6651       (mm-destroy-parts gnus-article-mime-handles)
6652       ;; Set it to nil for safety reason.
6653       (setq gnus-article-mime-handle-alist nil)
6654       (setq gnus-article-mime-handles nil)))
6655   (gnus-kill-save-kill-buffer)
6656   (gnus-async-halt-prefetch)
6657   (let* ((group gnus-newsgroup-name)
6658          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6659          (gnus-group-is-exiting-p t)
6660          (mode major-mode)
6661          (group-point nil)
6662          (buf (current-buffer)))
6663     (unless quit-config
6664       ;; Do adaptive scoring, and possibly save score files.
6665       (when gnus-newsgroup-adaptive
6666         (gnus-score-adaptive))
6667       (when gnus-use-scoring
6668         (gnus-score-save)))
6669     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6670     ;; If we have several article buffers, we kill them at exit.
6671     (unless gnus-single-article-buffer
6672       (gnus-kill-buffer gnus-original-article-buffer)
6673       (setq gnus-article-current nil))
6674     (when gnus-use-cache
6675       (gnus-cache-possibly-remove-articles)
6676       (gnus-cache-save-buffers))
6677     (gnus-async-prefetch-remove-group group)
6678     (when gnus-suppress-duplicates
6679       (gnus-dup-enter-articles))
6680     (when gnus-use-trees
6681       (gnus-tree-close group))
6682     (when gnus-use-cache
6683       (gnus-cache-write-active))
6684     ;; Remove entries for this group.
6685     (nnmail-purge-split-history (gnus-group-real-name group))
6686     ;; Make all changes in this group permanent.
6687     (unless quit-config
6688       (gnus-run-hooks 'gnus-exit-group-hook)
6689       (gnus-summary-update-info))
6690     (gnus-close-group group)
6691     ;; Make sure where we were, and go to next newsgroup.
6692     (set-buffer gnus-group-buffer)
6693     (unless quit-config
6694       (gnus-group-jump-to-group group))
6695     (gnus-run-hooks 'gnus-summary-exit-hook)
6696     (unless (or quit-config
6697                 ;; If this group has disappeared from the summary
6698                 ;; buffer, don't skip forwards.
6699                 (not (string= group (gnus-group-group-name))))
6700       (gnus-group-next-unread-group 1))
6701     (setq group-point (point))
6702     (if temporary
6703         nil                             ;Nothing to do.
6704       ;; If we have several article buffers, we kill them at exit.
6705       (unless gnus-single-article-buffer
6706         (gnus-kill-buffer gnus-article-buffer)
6707         (gnus-kill-buffer gnus-original-article-buffer)
6708         (setq gnus-article-current nil))
6709       (set-buffer buf)
6710       (if (not gnus-kill-summary-on-exit)
6711           (progn
6712             (gnus-deaden-summary)
6713             (setq mode nil))
6714         ;; We set all buffer-local variables to nil.  It is unclear why
6715         ;; this is needed, but if we don't, buffer-local variables are
6716         ;; not garbage-collected, it seems.  This would the lead to en
6717         ;; ever-growing Emacs.
6718         (gnus-summary-clear-local-variables)
6719         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6720           (gnus-summary-clear-local-variables))
6721         (when (get-buffer gnus-article-buffer)
6722           (bury-buffer gnus-article-buffer))
6723         ;; We clear the global counterparts of the buffer-local
6724         ;; variables as well, just to be on the safe side.
6725         (set-buffer gnus-group-buffer)
6726         (gnus-summary-clear-local-variables)
6727         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6728           (gnus-summary-clear-local-variables))
6729         ;; Return to group mode buffer.
6730         (when (eq mode 'gnus-summary-mode)
6731           (gnus-kill-buffer buf)))
6732       (setq gnus-current-select-method gnus-select-method)
6733       (set-buffer gnus-group-buffer)
6734       (if quit-config
6735           (gnus-handle-ephemeral-exit quit-config)
6736         (goto-char group-point)
6737         (unless leave-hidden
6738           (gnus-configure-windows 'group 'force)))
6739       ;; Clear the current group name.
6740       (unless quit-config
6741         (setq gnus-newsgroup-name nil)))))
6742
6743 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6744 (defun gnus-summary-exit-no-update (&optional no-questions)
6745   "Quit reading current newsgroup without updating read article info."
6746   (interactive)
6747   (let* ((group gnus-newsgroup-name)
6748          (gnus-group-is-exiting-p t)
6749          (gnus-group-is-exiting-without-update-p t)
6750          (quit-config (gnus-group-quit-config group)))
6751     (when (or no-questions
6752               gnus-expert-user
6753               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6754       (gnus-async-halt-prefetch)
6755       (run-hooks 'gnus-summary-prepare-exit-hook)
6756       (when (gnus-buffer-live-p gnus-article-buffer)
6757         (save-excursion
6758           (set-buffer gnus-article-buffer)
6759           (mm-destroy-parts gnus-article-mime-handles)
6760           ;; Set it to nil for safety reason.
6761           (setq gnus-article-mime-handle-alist nil)
6762           (setq gnus-article-mime-handles nil)))
6763       ;; If we have several article buffers, we kill them at exit.
6764       (unless gnus-single-article-buffer
6765         (gnus-kill-buffer gnus-article-buffer)
6766         (gnus-kill-buffer gnus-original-article-buffer)
6767         (setq gnus-article-current nil))
6768       (if (not gnus-kill-summary-on-exit)
6769           (gnus-deaden-summary)
6770         (gnus-close-group group)
6771         (gnus-summary-clear-local-variables)
6772         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6773           (gnus-summary-clear-local-variables))
6774         (set-buffer gnus-group-buffer)
6775         (gnus-summary-clear-local-variables)
6776         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6777           (gnus-summary-clear-local-variables))
6778         (gnus-kill-buffer gnus-summary-buffer))
6779       (unless gnus-single-article-buffer
6780         (setq gnus-article-current nil))
6781       (when gnus-use-trees
6782         (gnus-tree-close group))
6783       (gnus-async-prefetch-remove-group group)
6784       (when (get-buffer gnus-article-buffer)
6785         (bury-buffer gnus-article-buffer))
6786       ;; Return to the group buffer.
6787       (gnus-configure-windows 'group 'force)
6788       ;; Clear the current group name.
6789       (setq gnus-newsgroup-name nil)
6790       (unless (gnus-ephemeral-group-p group)
6791         (gnus-group-update-group group))
6792       (when (equal (gnus-group-group-name) group)
6793         (gnus-group-next-unread-group 1))
6794       (when quit-config
6795         (gnus-handle-ephemeral-exit quit-config)))))
6796
6797 (defun gnus-handle-ephemeral-exit (quit-config)
6798   "Handle movement when leaving an ephemeral group.
6799 The state which existed when entering the ephemeral is reset."
6800   (if (not (buffer-name (car quit-config)))
6801       (gnus-configure-windows 'group 'force)
6802     (set-buffer (car quit-config))
6803     (cond ((eq major-mode 'gnus-summary-mode)
6804            (gnus-set-global-variables))
6805           ((eq major-mode 'gnus-article-mode)
6806            (save-excursion
6807              ;; The `gnus-summary-buffer' variable may point
6808              ;; to the old summary buffer when using a single
6809              ;; article buffer.
6810              (unless (gnus-buffer-live-p gnus-summary-buffer)
6811                (set-buffer gnus-group-buffer))
6812              (set-buffer gnus-summary-buffer)
6813              (gnus-set-global-variables))))
6814     (if (or (eq (cdr quit-config) 'article)
6815             (eq (cdr quit-config) 'pick))
6816         (progn
6817           ;; The current article may be from the ephemeral group
6818           ;; thus it is best that we reload this article
6819           ;;
6820           ;; If we're exiting from a large digest, this can be
6821           ;; extremely slow.  So, it's better not to reload it. -- jh.
6822           ;;(gnus-summary-show-article)
6823           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6824               (gnus-configure-windows 'pick 'force)
6825             (gnus-configure-windows (cdr quit-config) 'force)))
6826       (gnus-configure-windows (cdr quit-config) 'force))
6827     (when (eq major-mode 'gnus-summary-mode)
6828       (gnus-summary-next-subject 1 nil t)
6829       (gnus-summary-recenter)
6830       (gnus-summary-position-point))))
6831
6832 ;;; Dead summaries.
6833
6834 (defvar gnus-dead-summary-mode-map nil)
6835
6836 (unless gnus-dead-summary-mode-map
6837   (setq gnus-dead-summary-mode-map (make-keymap))
6838   (suppress-keymap gnus-dead-summary-mode-map)
6839   (substitute-key-definition
6840    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6841   (dolist (key '("\C-d" "\r" "\177" [delete]))
6842     (define-key gnus-dead-summary-mode-map
6843       key 'gnus-summary-wake-up-the-dead))
6844   (dolist (key '("q" "Q"))
6845     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6846
6847 (defvar gnus-dead-summary-mode nil
6848   "Minor mode for Gnus summary buffers.")
6849
6850 (defun gnus-dead-summary-mode (&optional arg)
6851   "Minor mode for Gnus summary buffers."
6852   (interactive "P")
6853   (when (eq major-mode 'gnus-summary-mode)
6854     (make-local-variable 'gnus-dead-summary-mode)
6855     (setq gnus-dead-summary-mode
6856           (if (null arg) (not gnus-dead-summary-mode)
6857             (> (prefix-numeric-value arg) 0)))
6858     (when gnus-dead-summary-mode
6859       (add-minor-mode
6860        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6861
6862 (defun gnus-deaden-summary ()
6863   "Make the current summary buffer into a dead summary buffer."
6864   ;; Kill any previous dead summary buffer.
6865   (when (and gnus-dead-summary
6866              (buffer-name gnus-dead-summary))
6867     (with-current-buffer gnus-dead-summary
6868       (when gnus-dead-summary-mode
6869         (kill-buffer (current-buffer)))))
6870   ;; Make this the current dead summary.
6871   (setq gnus-dead-summary (current-buffer))
6872   (gnus-dead-summary-mode 1)
6873   (let ((name (buffer-name)))
6874     (when (string-match "Summary" name)
6875       (rename-buffer
6876        (concat (substring name 0 (match-beginning 0)) "Dead "
6877                (substring name (match-beginning 0)))
6878        t)
6879       (bury-buffer))))
6880
6881 (defun gnus-kill-or-deaden-summary (buffer)
6882   "Kill or deaden the summary BUFFER."
6883   (save-excursion
6884     (when (and (buffer-name buffer)
6885                (not gnus-single-article-buffer))
6886       (with-current-buffer buffer
6887         (gnus-kill-buffer gnus-article-buffer)
6888         (gnus-kill-buffer gnus-original-article-buffer)))
6889     (cond
6890      ;; Kill the buffer.
6891      (gnus-kill-summary-on-exit
6892       (when (and gnus-use-trees
6893                  (gnus-buffer-exists-p buffer))
6894         (save-excursion
6895           (set-buffer buffer)
6896           (gnus-tree-close gnus-newsgroup-name)))
6897       (gnus-kill-buffer buffer))
6898      ;; Deaden the buffer.
6899      ((gnus-buffer-exists-p buffer)
6900       (save-excursion
6901         (set-buffer buffer)
6902         (gnus-deaden-summary))))))
6903
6904 (defun gnus-summary-wake-up-the-dead (&rest args)
6905   "Wake up the dead summary buffer."
6906   (interactive)
6907   (gnus-dead-summary-mode -1)
6908   (let ((name (buffer-name)))
6909     (when (string-match "Dead " name)
6910       (rename-buffer
6911        (concat (substring name 0 (match-beginning 0))
6912                (substring name (match-end 0)))
6913        t)))
6914   (gnus-message 3 "This dead summary is now alive again"))
6915
6916 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6917 (defun gnus-summary-fetch-faq (&optional faq-dir)
6918   "Fetch the FAQ for the current group.
6919 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6920 in."
6921   (interactive
6922    (list
6923     (when current-prefix-arg
6924       (completing-read
6925        "FAQ dir: " (and (listp gnus-group-faq-directory)
6926                         (mapcar 'list
6927                                 gnus-group-faq-directory))))))
6928   (let (gnus-faq-buffer)
6929     (when (setq gnus-faq-buffer
6930                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6931       (gnus-configure-windows 'summary-faq))))
6932
6933 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6934 (defun gnus-summary-describe-group (&optional force)
6935   "Describe the current newsgroup."
6936   (interactive "P")
6937   (gnus-group-describe-group force gnus-newsgroup-name))
6938
6939 (defun gnus-summary-describe-briefly ()
6940   "Describe summary mode commands briefly."
6941   (interactive)
6942   (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")))
6943
6944 ;; Walking around group mode buffer from summary mode.
6945
6946 (defun gnus-summary-next-group (&optional no-article target-group backward)
6947   "Exit current newsgroup and then select next unread newsgroup.
6948 If prefix argument NO-ARTICLE is non-nil, no article is selected
6949 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6950 previous group instead."
6951   (interactive "P")
6952   ;; Stop pre-fetching.
6953   (gnus-async-halt-prefetch)
6954   (let ((current-group gnus-newsgroup-name)
6955         (current-buffer (current-buffer))
6956         entered)
6957     ;; First we semi-exit this group to update Xrefs and all variables.
6958     ;; We can't do a real exit, because the window conf must remain
6959     ;; the same in case the user is prompted for info, and we don't
6960     ;; want the window conf to change before that...
6961     (gnus-summary-exit t)
6962     (while (not entered)
6963       ;; Then we find what group we are supposed to enter.
6964       (set-buffer gnus-group-buffer)
6965       (gnus-group-jump-to-group current-group)
6966       (setq target-group
6967             (or target-group
6968                 (if (eq gnus-keep-same-level 'best)
6969                     (gnus-summary-best-group gnus-newsgroup-name)
6970                   (gnus-summary-search-group backward gnus-keep-same-level))))
6971       (if (not target-group)
6972           ;; There are no further groups, so we return to the group
6973           ;; buffer.
6974           (progn
6975             (gnus-message 5 "Returning to the group buffer")
6976             (setq entered t)
6977             (when (gnus-buffer-live-p current-buffer)
6978               (set-buffer current-buffer)
6979               (gnus-summary-exit))
6980             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6981         ;; We try to enter the target group.
6982         (gnus-group-jump-to-group target-group)
6983         (let ((unreads (gnus-group-group-unread)))
6984           (if (and (or (eq t unreads)
6985                        (and unreads (not (zerop unreads))))
6986                    (gnus-summary-read-group
6987                     target-group nil no-article
6988                     (and (buffer-name current-buffer) current-buffer)
6989                     nil backward))
6990               (setq entered t)
6991             (setq current-group target-group
6992                   target-group nil)))))))
6993
6994 (defun gnus-summary-prev-group (&optional no-article)
6995   "Exit current newsgroup and then select previous unread newsgroup.
6996 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6997   (interactive "P")
6998   (gnus-summary-next-group no-article nil t))
6999
7000 ;; Walking around summary lines.
7001
7002 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7003   "Go to the first subject satisfying any non-nil constraint.
7004 If UNREAD is non-nil, the article should be unread.
7005 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7006 If UNSEEN is non-nil, the article should be unseen.
7007 Returns the article selected or nil if there are no matching articles."
7008   (interactive "P")
7009   (cond
7010    ;; Empty summary.
7011    ((null gnus-newsgroup-data)
7012     (gnus-message 3 "No articles in the group")
7013     nil)
7014    ;; Pick the first article.
7015    ((not (or unread undownloaded unseen))
7016     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7017     (gnus-data-number (car gnus-newsgroup-data)))
7018    ;; Find the first unread article.
7019    (t
7020     (let ((data gnus-newsgroup-data))
7021       (while (and data
7022                   (let ((num (gnus-data-number (car data))))
7023                     (or (memq num gnus-newsgroup-unfetched)
7024                         (not (or (and unread
7025                                       (memq num gnus-newsgroup-unreads))
7026                                  (and undownloaded
7027                                       (memq num gnus-newsgroup-undownloaded))
7028                                  (and unseen
7029                                       (memq num gnus-newsgroup-unseen)))))))
7030         (setq data (cdr data)))
7031       (prog1
7032           (if data
7033               (progn
7034                 (goto-char (gnus-data-pos (car data)))
7035                 (gnus-data-number (car data)))
7036             (gnus-message 3 "No more%s articles"
7037                           (let* ((r (when unread " unread"))
7038                                  (d (when undownloaded " undownloaded"))
7039                                  (s (when unseen " unseen"))
7040                                  (l (delq nil (list r d s))))
7041                             (cond ((= 3 (length l))
7042                                    (concat r "," d ", or" s))
7043                                   ((= 2 (length l))
7044                                    (concat (car l) ", or" (cadr l)))
7045                                   ((= 1 (length l))
7046                                    (car l))
7047                                   (t
7048                                    ""))))
7049             nil
7050             )
7051         (gnus-summary-position-point))))))
7052
7053 (defun gnus-summary-next-subject (n &optional unread dont-display)
7054   "Go to next N'th summary line.
7055 If N is negative, go to the previous N'th subject line.
7056 If UNREAD is non-nil, only unread articles are selected.
7057 The difference between N and the actual number of steps taken is
7058 returned."
7059   (interactive "p")
7060   (let ((backward (< n 0))
7061         (n (abs n)))
7062     (while (and (> n 0)
7063                 (if backward
7064                     (gnus-summary-find-prev unread)
7065                   (gnus-summary-find-next unread)))
7066       (unless (zerop (setq n (1- n)))
7067         (gnus-summary-show-thread)))
7068     (when (/= 0 n)
7069       (gnus-message 7 "No more%s articles"
7070                     (if unread " unread" "")))
7071     (unless dont-display
7072       (gnus-summary-recenter)
7073       (gnus-summary-position-point))
7074     n))
7075
7076 (defun gnus-summary-next-unread-subject (n)
7077   "Go to next N'th unread summary line."
7078   (interactive "p")
7079   (gnus-summary-next-subject n t))
7080
7081 (defun gnus-summary-prev-subject (n &optional unread)
7082   "Go to previous N'th summary line.
7083 If optional argument UNREAD is non-nil, only unread article is selected."
7084   (interactive "p")
7085   (gnus-summary-next-subject (- n) unread))
7086
7087 (defun gnus-summary-prev-unread-subject (n)
7088   "Go to previous N'th unread summary line."
7089   (interactive "p")
7090   (gnus-summary-next-subject (- n) t))
7091
7092 (defun gnus-summary-goto-subjects (articles)
7093   "Insert the subject header for ARTICLES in the current buffer."
7094   (save-excursion
7095     (dolist (article articles)
7096       (gnus-summary-goto-subject article t)))
7097   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7098   (gnus-summary-position-point))
7099  
7100 (defun gnus-summary-goto-subject (article &optional force silent)
7101   "Go the subject line of ARTICLE.
7102 If FORCE, also allow jumping to articles not currently shown."
7103   (interactive "nArticle number: ")
7104   (unless (numberp article)
7105     (error "Article %s is not a number" article))
7106   (let ((b (point))
7107         (data (gnus-data-find article)))
7108     ;; We read in the article if we have to.
7109     (and (not data)
7110          force
7111          (gnus-summary-insert-subject
7112           article
7113           (if (or (numberp force) (vectorp force)) force)
7114           t)
7115          (setq data (gnus-data-find article)))
7116     (goto-char b)
7117     (if (not data)
7118         (progn
7119           (unless silent
7120             (gnus-message 3 "Can't find article %d" article))
7121           nil)
7122       (let ((pt (gnus-data-pos data)))
7123         (goto-char pt)
7124         (gnus-summary-set-article-display-arrow pt))
7125       (gnus-summary-position-point)
7126       article)))
7127
7128 ;; Walking around summary lines with displaying articles.
7129
7130 (defun gnus-summary-expand-window (&optional arg)
7131   "Make the summary buffer take up the entire Emacs frame.
7132 Given a prefix, will force an `article' buffer configuration."
7133   (interactive "P")
7134   (if arg
7135       (gnus-configure-windows 'article 'force)
7136     (gnus-configure-windows 'summary 'force)))
7137
7138 (defun gnus-summary-display-article (article &optional all-header)
7139   "Display ARTICLE in article buffer."
7140   (when (gnus-buffer-live-p gnus-article-buffer)
7141     (with-current-buffer gnus-article-buffer
7142       (mm-enable-multibyte)))
7143   (gnus-set-global-variables)
7144   (when (gnus-buffer-live-p gnus-article-buffer)
7145     (with-current-buffer gnus-article-buffer
7146       (setq gnus-article-charset gnus-newsgroup-charset)
7147       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7148       (mm-enable-multibyte)))
7149   (if (null article)
7150       nil
7151     (prog1
7152         (if gnus-summary-display-article-function
7153             (funcall gnus-summary-display-article-function article all-header)
7154           (gnus-article-prepare article all-header))
7155       (gnus-run-hooks 'gnus-select-article-hook)
7156       (when (and gnus-current-article
7157                  (not (zerop gnus-current-article)))
7158         (gnus-summary-goto-subject gnus-current-article))
7159       (gnus-summary-recenter)
7160       (when (and gnus-use-trees gnus-show-threads)
7161         (gnus-possibly-generate-tree article)
7162         (gnus-highlight-selected-tree article))
7163       ;; Successfully display article.
7164       (gnus-article-set-window-start
7165        (cdr (assq article gnus-newsgroup-bookmarks))))))
7166
7167 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7168   "Select the current article.
7169 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7170 non-nil, the article will be re-fetched even if it already present in
7171 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7172 be displayed."
7173   ;; Make sure we are in the summary buffer to work around bbdb bug.
7174   (unless (eq major-mode 'gnus-summary-mode)
7175     (set-buffer gnus-summary-buffer))
7176   (let ((article (or article (gnus-summary-article-number)))
7177         (all-headers (not (not all-headers))) ;Must be t or nil.
7178         gnus-summary-display-article-function)
7179     (and (not pseudo)
7180          (gnus-summary-article-pseudo-p article)
7181          (error "This is a pseudo-article"))
7182     (save-excursion
7183       (set-buffer gnus-summary-buffer)
7184       (if (or (and gnus-single-article-buffer
7185                    (or (null gnus-current-article)
7186                        (null gnus-article-current)
7187                        (null (get-buffer gnus-article-buffer))
7188                        (not (eq article (cdr gnus-article-current)))
7189                        (not (equal (car gnus-article-current)
7190                                    gnus-newsgroup-name))))
7191               (and (not gnus-single-article-buffer)
7192                    (or (null gnus-current-article)
7193                        (not (eq gnus-current-article article))))
7194               force)
7195           ;; The requested article is different from the current article.
7196           (progn
7197             (gnus-summary-display-article article all-headers)
7198             (when (gnus-buffer-live-p gnus-article-buffer)
7199               (with-current-buffer gnus-article-buffer
7200                 (if (not gnus-article-decoded-p) ;; a local variable
7201                     (mm-disable-multibyte))))
7202             (gnus-article-set-window-start
7203              (cdr (assq article gnus-newsgroup-bookmarks)))
7204             article)
7205         'old))))
7206
7207 (defun gnus-summary-force-verify-and-decrypt ()
7208   "Display buttons for signed/encrypted parts and verify/decrypt them."
7209   (interactive)
7210   (let ((mm-verify-option 'known)
7211         (mm-decrypt-option 'known)
7212         (gnus-article-emulate-mime t)
7213         (gnus-buttonized-mime-types (append (list "multipart/signed"
7214                                                   "multipart/encrypted")
7215                                             gnus-buttonized-mime-types)))
7216     (gnus-summary-select-article nil 'force)))
7217
7218 (defun gnus-summary-set-current-mark (&optional current-mark)
7219   "Obsolete function."
7220   nil)
7221
7222 (defun gnus-summary-next-article (&optional unread subject backward push)
7223   "Select the next article.
7224 If UNREAD, only unread articles are selected.
7225 If SUBJECT, only articles with SUBJECT are selected.
7226 If BACKWARD, the previous article is selected instead of the next."
7227   (interactive "P")
7228   (cond
7229    ;; Is there such an article?
7230    ((and (gnus-summary-search-forward unread subject backward)
7231          (or (gnus-summary-display-article (gnus-summary-article-number))
7232              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7233     (gnus-summary-position-point))
7234    ;; If not, we try the first unread, if that is wanted.
7235    ((and subject
7236          gnus-auto-select-same
7237          (gnus-summary-first-unread-article))
7238     (gnus-summary-position-point)
7239     (gnus-message 6 "Wrapped"))
7240    ;; Try to get next/previous article not displayed in this group.
7241    ((and gnus-auto-extend-newsgroup
7242          (not unread) (not subject))
7243     (gnus-summary-goto-article
7244      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7245      nil (count-lines (point-min) (point))))
7246    ;; Go to next/previous group.
7247    (t
7248     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7249       (gnus-summary-jump-to-group gnus-newsgroup-name))
7250     (let ((cmd last-command-char)
7251           (point
7252            (with-current-buffer gnus-group-buffer
7253              (point)))
7254           (group
7255            (if (eq gnus-keep-same-level 'best)
7256                (gnus-summary-best-group gnus-newsgroup-name)
7257              (gnus-summary-search-group backward gnus-keep-same-level))))
7258       ;; For some reason, the group window gets selected.  We change
7259       ;; it back.
7260       (select-window (get-buffer-window (current-buffer)))
7261       ;; Select next unread newsgroup automagically.
7262       (cond
7263        ((or (not gnus-auto-select-next)
7264             (not cmd))
7265         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7266        ((or (eq gnus-auto-select-next 'quietly)
7267             (and (eq gnus-auto-select-next 'slightly-quietly)
7268                  push)
7269             (and (eq gnus-auto-select-next 'almost-quietly)
7270                  (gnus-summary-last-article-p)))
7271         ;; Select quietly.
7272         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7273             (gnus-summary-exit)
7274           (gnus-message 7 "No more%s articles (%s)..."
7275                         (if unread " unread" "")
7276                         (if group (concat "selecting " group)
7277                           "exiting"))
7278           (gnus-summary-next-group nil group backward)))
7279        (t
7280         (when (gnus-key-press-event-p last-input-event)
7281           (gnus-summary-walk-group-buffer
7282            gnus-newsgroup-name cmd unread backward point))))))))
7283
7284 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7285   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7286                       (?\C-p (gnus-group-prev-unread-group 1))))
7287         (cursor-in-echo-area t)
7288         keve key group ended prompt)
7289     (save-excursion
7290       (set-buffer gnus-group-buffer)
7291       (goto-char start)
7292       (setq group
7293             (if (eq gnus-keep-same-level 'best)
7294                 (gnus-summary-best-group gnus-newsgroup-name)
7295               (gnus-summary-search-group backward gnus-keep-same-level))))
7296     (while (not ended)
7297       (setq prompt
7298             (format
7299              "No more%s articles%s " (if unread " unread" "")
7300              (if (and group
7301                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7302                  (format " (Type %s for %s [%s])"
7303                          (single-key-description cmd) group
7304                          (gnus-group-unread group))
7305                (format " (Type %s to exit %s)"
7306                        (single-key-description cmd)
7307                        gnus-newsgroup-name))))
7308       ;; Confirm auto selection.
7309       (setq key (car (setq keve (gnus-read-event-char prompt)))
7310             ended t)
7311       (cond
7312        ((assq key keystrokes)
7313         (let ((obuf (current-buffer)))
7314           (switch-to-buffer gnus-group-buffer)
7315           (when group
7316             (gnus-group-jump-to-group group))
7317           (eval (cadr (assq key keystrokes)))
7318           (setq group (gnus-group-group-name))
7319           (switch-to-buffer obuf))
7320         (setq ended nil))
7321        ((equal key cmd)
7322         (if (or (not group)
7323                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7324             (gnus-summary-exit)
7325           (gnus-summary-next-group nil group backward)))
7326        (t
7327         (push (cdr keve) unread-command-events))))))
7328
7329 (defun gnus-summary-next-unread-article ()
7330   "Select unread article after current one."
7331   (interactive)
7332   (gnus-summary-next-article
7333    (or (not (eq gnus-summary-goto-unread 'never))
7334        (gnus-summary-last-article-p (gnus-summary-article-number)))
7335    (and gnus-auto-select-same
7336         (gnus-summary-article-subject))))
7337
7338 (defun gnus-summary-prev-article (&optional unread subject)
7339   "Select the article after the current one.
7340 If UNREAD is non-nil, only unread articles are selected."
7341   (interactive "P")
7342   (gnus-summary-next-article unread subject t))
7343
7344 (defun gnus-summary-prev-unread-article ()
7345   "Select unread article before current one."
7346   (interactive)
7347   (gnus-summary-prev-article
7348    (or (not (eq gnus-summary-goto-unread 'never))
7349        (gnus-summary-first-article-p (gnus-summary-article-number)))
7350    (and gnus-auto-select-same
7351         (gnus-summary-article-subject))))
7352
7353 (defun gnus-summary-next-page (&optional lines circular stop)
7354   "Show next page of the selected article.
7355 If at the end of the current article, select the next article.
7356 LINES says how many lines should be scrolled up.
7357
7358 If CIRCULAR is non-nil, go to the start of the article instead of
7359 selecting the next article when reaching the end of the current
7360 article.
7361
7362 If STOP is non-nil, just stop when reaching the end of the message.
7363
7364 Also see the variable `gnus-article-skip-boring'."
7365   (interactive "P")
7366   (setq gnus-summary-buffer (current-buffer))
7367   (gnus-set-global-variables)
7368   (let ((article (gnus-summary-article-number))
7369         (article-window (get-buffer-window gnus-article-buffer t))
7370         endp)
7371     ;; If the buffer is empty, we have no article.
7372     (unless article
7373       (error "No article to select"))
7374     (gnus-configure-windows 'article)
7375     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7376         (if (and (eq gnus-summary-goto-unread 'never)
7377                  (not (gnus-summary-last-article-p article)))
7378             (gnus-summary-next-article)
7379           (gnus-summary-next-unread-article))
7380       (if (or (null gnus-current-article)
7381               (null gnus-article-current)
7382               (/= article (cdr gnus-article-current))
7383               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7384           ;; Selected subject is different from current article's.
7385           (gnus-summary-display-article article)
7386         (when article-window
7387           (gnus-eval-in-buffer-window gnus-article-buffer
7388             (setq endp (or (gnus-article-next-page lines)
7389                            (gnus-article-only-boring-p))))
7390           (when endp
7391             (cond (stop
7392                    (gnus-message 3 "End of message"))
7393                   (circular
7394                    (gnus-summary-beginning-of-article))
7395                   (lines
7396                    (gnus-message 3 "End of message"))
7397                   ((null lines)
7398                    (if (and (eq gnus-summary-goto-unread 'never)
7399                             (not (gnus-summary-last-article-p article)))
7400                        (gnus-summary-next-article)
7401                      (gnus-summary-next-unread-article))))))))
7402     (gnus-summary-recenter)
7403     (gnus-summary-position-point)))
7404
7405 (defun gnus-summary-prev-page (&optional lines move)
7406   "Show previous page of selected article.
7407 Argument LINES specifies lines to be scrolled down.
7408 If MOVE, move to the previous unread article if point is at
7409 the beginning of the buffer."
7410   (interactive "P")
7411   (let ((article (gnus-summary-article-number))
7412         (article-window (get-buffer-window gnus-article-buffer t))
7413         endp)
7414     (gnus-configure-windows 'article)
7415     (if (or (null gnus-current-article)
7416             (null gnus-article-current)
7417             (/= article (cdr gnus-article-current))
7418             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7419         ;; Selected subject is different from current article's.
7420         (gnus-summary-display-article article)
7421       (gnus-summary-recenter)
7422       (when article-window
7423         (gnus-eval-in-buffer-window gnus-article-buffer
7424           (setq endp (gnus-article-prev-page lines)))
7425         (when (and move endp)
7426           (cond (lines
7427                  (gnus-message 3 "Beginning of message"))
7428                 ((null lines)
7429                  (if (and (eq gnus-summary-goto-unread 'never)
7430                           (not (gnus-summary-first-article-p article)))
7431                      (gnus-summary-prev-article)
7432                    (gnus-summary-prev-unread-article))))))))
7433   (gnus-summary-position-point))
7434
7435 (defun gnus-summary-prev-page-or-article (&optional lines)
7436   "Show previous page of selected article.
7437 Argument LINES specifies lines to be scrolled down.
7438 If at the beginning of the article, go to the next article."
7439   (interactive "P")
7440   (gnus-summary-prev-page lines t))
7441
7442 (defun gnus-summary-scroll-up (lines)
7443   "Scroll up (or down) one line current article.
7444 Argument LINES specifies lines to be scrolled up (or down if negative)."
7445   (interactive "p")
7446   (gnus-configure-windows 'article)
7447   (gnus-summary-show-thread)
7448   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7449     (gnus-eval-in-buffer-window gnus-article-buffer
7450       (cond ((> lines 0)
7451              (when (gnus-article-next-page lines)
7452                (gnus-message 3 "End of message")))
7453             ((< lines 0)
7454              (gnus-article-prev-page (- lines))))))
7455   (gnus-summary-recenter)
7456   (gnus-summary-position-point))
7457
7458 (defun gnus-summary-scroll-down (lines)
7459   "Scroll down (or up) one line current article.
7460 Argument LINES specifies lines to be scrolled down (or up if negative)."
7461   (interactive "p")
7462   (gnus-summary-scroll-up (- lines)))
7463
7464 (defun gnus-summary-next-same-subject ()
7465   "Select next article which has the same subject as current one."
7466   (interactive)
7467   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7468
7469 (defun gnus-summary-prev-same-subject ()
7470   "Select previous article which has the same subject as current one."
7471   (interactive)
7472   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7473
7474 (defun gnus-summary-next-unread-same-subject ()
7475   "Select next unread article which has the same subject as current one."
7476   (interactive)
7477   (gnus-summary-next-article t (gnus-summary-article-subject)))
7478
7479 (defun gnus-summary-prev-unread-same-subject ()
7480   "Select previous unread article which has the same subject as current one."
7481   (interactive)
7482   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7483
7484 (defun gnus-summary-first-unread-article ()
7485   "Select the first unread article.
7486 Return nil if there are no unread articles."
7487   (interactive)
7488   (prog1
7489       (when (gnus-summary-first-subject t)
7490         (gnus-summary-show-thread)
7491         (gnus-summary-first-subject t)
7492         (gnus-summary-display-article (gnus-summary-article-number)))
7493     (gnus-summary-position-point)))
7494
7495 (defun gnus-summary-first-unread-subject ()
7496   "Place the point on the subject line of the first unread article.
7497 Return nil if there are no unread articles."
7498   (interactive)
7499   (prog1
7500       (when (gnus-summary-first-subject t)
7501         (gnus-summary-show-thread)
7502         (gnus-summary-first-subject t))
7503     (gnus-summary-position-point)))
7504
7505 (defun gnus-summary-first-unseen-subject ()
7506   "Place the point on the subject line of the first unseen article.
7507 Return nil if there are no unseen articles."
7508   (interactive)
7509   (prog1
7510       (when (gnus-summary-first-subject nil nil t)
7511         (gnus-summary-show-thread)
7512         (gnus-summary-first-subject nil nil t))
7513     (gnus-summary-position-point)))
7514
7515 (defun gnus-summary-first-unseen-or-unread-subject ()
7516   "Place the point on the subject line of the first unseen article or,
7517 if all article have been seen, on the subject line of the first unread
7518 article."
7519   (interactive)
7520   (prog1
7521       (unless (when (gnus-summary-first-subject nil nil t)
7522                 (gnus-summary-show-thread)
7523                 (gnus-summary-first-subject nil nil t))
7524         (when (gnus-summary-first-subject t)
7525           (gnus-summary-show-thread)
7526           (gnus-summary-first-subject t)))
7527     (gnus-summary-position-point)))
7528
7529 (defun gnus-summary-first-article ()
7530   "Select the first article.
7531 Return nil if there are no articles."
7532   (interactive)
7533   (prog1
7534       (when (gnus-summary-first-subject)
7535         (gnus-summary-show-thread)
7536         (gnus-summary-first-subject)
7537         (gnus-summary-display-article (gnus-summary-article-number)))
7538     (gnus-summary-position-point)))
7539
7540 (defun gnus-summary-best-unread-article (&optional arg)
7541   "Select the unread article with the highest score.
7542 If given a prefix argument, select the next unread article that has a
7543 score higher than the default score."
7544   (interactive "P")
7545   (let ((article (if arg
7546                      (gnus-summary-better-unread-subject)
7547                    (gnus-summary-best-unread-subject))))
7548     (if article
7549         (gnus-summary-goto-article article)
7550       (error "No unread articles"))))
7551
7552 (defun gnus-summary-best-unread-subject ()
7553   "Select the unread subject with the highest score."
7554   (interactive)
7555   (let ((best -1000000)
7556         (data gnus-newsgroup-data)
7557         article score)
7558     (while data
7559       (and (gnus-data-unread-p (car data))
7560            (> (setq score
7561                     (gnus-summary-article-score (gnus-data-number (car data))))
7562               best)
7563            (setq best score
7564                  article (gnus-data-number (car data))))
7565       (setq data (cdr data)))
7566     (when article
7567       (gnus-summary-goto-subject article))
7568     (gnus-summary-position-point)
7569     article))
7570
7571 (defun gnus-summary-better-unread-subject ()
7572   "Select the first unread subject that has a score over the default score."
7573   (interactive)
7574   (let ((data gnus-newsgroup-data)
7575         article score)
7576     (while (and (setq article (gnus-data-number (car data)))
7577                 (or (gnus-data-read-p (car data))
7578                     (not (> (gnus-summary-article-score article)
7579                             gnus-summary-default-score))))
7580       (setq data (cdr data)))
7581     (when article
7582       (gnus-summary-goto-subject article))
7583     (gnus-summary-position-point)
7584     article))
7585
7586 (defun gnus-summary-last-subject ()
7587   "Go to the last displayed subject line in the group."
7588   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7589     (when article
7590       (gnus-summary-goto-subject article))))
7591
7592 (defun gnus-summary-goto-article (article &optional all-headers force)
7593   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7594 If ALL-HEADERS is non-nil, no header lines are hidden.
7595 If FORCE, go to the article even if it isn't displayed.  If FORCE
7596 is a number, it is the line the article is to be displayed on."
7597   (interactive
7598    (list
7599     (completing-read
7600      "Article number or Message-ID: "
7601      (mapcar (lambda (number) (list (int-to-string number)))
7602              gnus-newsgroup-limit))
7603     current-prefix-arg
7604     t))
7605   (prog1
7606       (if (and (stringp article)
7607                (string-match "@\\|%40" article))
7608           (gnus-summary-refer-article article)
7609         (when (stringp article)
7610           (setq article (string-to-number article)))
7611         (if (gnus-summary-goto-subject article force)
7612             (gnus-summary-display-article article all-headers)
7613           (gnus-message 4 "Couldn't go to article %s" article) nil))
7614     (gnus-summary-position-point)))
7615
7616 (defun gnus-summary-goto-last-article ()
7617   "Go to the previously read article."
7618   (interactive)
7619   (prog1
7620       (when gnus-last-article
7621         (gnus-summary-goto-article gnus-last-article nil t))
7622     (gnus-summary-position-point)))
7623
7624 (defun gnus-summary-pop-article (number)
7625   "Pop one article off the history and go to the previous.
7626 NUMBER articles will be popped off."
7627   (interactive "p")
7628   (let (to)
7629     (setq gnus-newsgroup-history
7630           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7631     (if to
7632         (gnus-summary-goto-article (car to) nil t)
7633       (error "Article history empty")))
7634   (gnus-summary-position-point))
7635
7636 ;; Summary commands and functions for limiting the summary buffer.
7637
7638 (defun gnus-summary-limit-to-articles (n)
7639   "Limit the summary buffer to the next N articles.
7640 If not given a prefix, use the process marked articles instead."
7641   (interactive "P")
7642   (prog1
7643       (let ((articles (gnus-summary-work-articles n)))
7644         (setq gnus-newsgroup-processable nil)
7645         (gnus-summary-limit articles))
7646     (gnus-summary-position-point)))
7647
7648 (defun gnus-summary-pop-limit (&optional total)
7649   "Restore the previous limit.
7650 If given a prefix, remove all limits."
7651   (interactive "P")
7652   (when total
7653     (setq gnus-newsgroup-limits
7654           (list (mapcar (lambda (h) (mail-header-number h))
7655                         gnus-newsgroup-headers))))
7656   (unless gnus-newsgroup-limits
7657     (error "No limit to pop"))
7658   (prog1
7659       (gnus-summary-limit nil 'pop)
7660     (gnus-summary-position-point)))
7661
7662 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7663   "Limit the summary buffer to articles that have subjects that match a regexp.
7664 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7665   (interactive
7666    (list (read-string (if current-prefix-arg
7667                           "Exclude subject (regexp): "
7668                         "Limit to subject (regexp): "))
7669          nil current-prefix-arg))
7670   (unless header
7671     (setq header "subject"))
7672   (when (not (equal "" subject))
7673     (prog1
7674         (let ((articles (gnus-summary-find-matching
7675                          (or header "subject") subject 'all nil nil
7676                          not-matching)))
7677           (unless articles
7678             (error "Found no matches for \"%s\"" subject))
7679           (gnus-summary-limit articles))
7680       (gnus-summary-position-point))))
7681
7682 (defun gnus-summary-limit-to-author (from &optional not-matching)
7683   "Limit the summary buffer to articles that have authors that match a regexp.
7684 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7685   (interactive
7686    (list (read-string (if current-prefix-arg
7687                           "Exclude author (regexp): "
7688                         "Limit to author (regexp): "))
7689          current-prefix-arg))
7690   (gnus-summary-limit-to-subject from "from" not-matching))
7691
7692 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7693   "Limit the summary buffer to articles with the given RECIPIENT.
7694
7695 If NOT-MATCHING, exclude RECIPIENT.
7696
7697 To and Cc headers are checked.  You need to include them in
7698 `nnmail-extra-headers'."
7699   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7700   (interactive
7701    (list (read-string (format "%s recipient (regexp): "
7702                               (if current-prefix-arg "Exclude" "Limit to")))
7703          current-prefix-arg))
7704   (when (not (equal "" recipient))
7705     (prog1 (let* ((to
7706                    (if (memq 'To nnmail-extra-headers)
7707                        (gnus-summary-find-matching
7708                         (cons 'extra 'To) recipient 'all nil nil
7709                         not-matching)
7710                      (gnus-message
7711                       1 "`To' isn't present in `nnmail-extra-headers'")
7712                      (sit-for 1)
7713                      nil))
7714                   (cc
7715                    (if (memq 'Cc nnmail-extra-headers)
7716                        (gnus-summary-find-matching
7717                         (cons 'extra 'Cc) recipient 'all nil nil
7718                         not-matching)
7719                      (gnus-message
7720                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7721                      (sit-for 1)
7722                      nil))
7723                   (articles
7724                    (if not-matching
7725                        ;; We need the numbers that are in both lists:
7726                        (mapcar (lambda (a)
7727                                  (and (memq a to) a))
7728                                cc)
7729                      (nconc to cc))))
7730              (unless articles
7731                (error "Found no matches for \"%s\"" recipient))
7732              (gnus-summary-limit articles))
7733       (gnus-summary-position-point))))
7734
7735 (defun gnus-summary-limit-to-age (age &optional younger-p)
7736   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7737 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7738 articles that are younger than AGE days."
7739   (interactive
7740    (let ((younger current-prefix-arg)
7741          (days-got nil)
7742          days)
7743      (while (not days-got)
7744        (setq days (if younger
7745                       (read-string "Limit to articles younger than (in days, older when negative): ")
7746                     (read-string
7747                      "Limit to articles older than (in days, younger when negative): ")))
7748        (when (> (length days) 0)
7749          (setq days (read days)))
7750        (if (numberp days)
7751            (progn
7752              (setq days-got t)
7753              (when (< days 0)
7754                (setq younger (not younger))
7755                (setq days (* days -1))))
7756          (message "Please enter a number.")
7757          (sleep-for 1)))
7758      (list days younger)))
7759   (prog1
7760       (let ((data gnus-newsgroup-data)
7761             (cutoff (days-to-time age))
7762             articles d date is-younger)
7763         (while (setq d (pop data))
7764           (when (and (vectorp (gnus-data-header d))
7765                      (setq date (mail-header-date (gnus-data-header d))))
7766             (setq is-younger (time-less-p
7767                               (time-since (condition-case ()
7768                                               (date-to-time date)
7769                                             (error '(0 0))))
7770                               cutoff))
7771             (when (if younger-p
7772                       is-younger
7773                     (not is-younger))
7774               (push (gnus-data-number d) articles))))
7775         (gnus-summary-limit (nreverse articles)))
7776     (gnus-summary-position-point)))
7777
7778 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7779   "Limit the summary buffer to articles that match an 'extra' header."
7780   (interactive
7781    (let ((header
7782           (intern
7783            (gnus-completing-read-with-default
7784             (symbol-name (car gnus-extra-headers))
7785             (if current-prefix-arg
7786                 "Exclude extra header:"
7787               "Limit extra header:")
7788             (mapcar (lambda (x)
7789                       (cons (symbol-name x) x))
7790                     gnus-extra-headers)
7791             nil
7792             t))))
7793      (list header
7794            (read-string (format "%s header %s (regexp): "
7795                                 (if current-prefix-arg "Exclude" "Limit to")
7796                                 header))
7797            current-prefix-arg)))
7798   (when (not (equal "" regexp))
7799     (prog1
7800         (let ((articles (gnus-summary-find-matching
7801                          (cons 'extra header) regexp 'all nil nil
7802                          not-matching)))
7803           (unless articles
7804             (error "Found no matches for \"%s\"" regexp))
7805           (gnus-summary-limit articles))
7806       (gnus-summary-position-point))))
7807
7808 (defun gnus-summary-limit-to-display-predicate ()
7809   "Limit the summary buffer to the predicated in the `display' group parameter."
7810   (interactive)
7811   (unless gnus-newsgroup-display
7812     (error "There is no `display' group parameter"))
7813   (let (articles)
7814     (dolist (number gnus-newsgroup-articles)
7815       (when (funcall gnus-newsgroup-display)
7816         (push number articles)))
7817     (gnus-summary-limit articles))
7818   (gnus-summary-position-point))
7819
7820 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7821 (make-obsolete
7822  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7823
7824 (defun gnus-summary-limit-to-unread (&optional all)
7825   "Limit the summary buffer to articles that are not marked as read.
7826 If ALL is non-nil, limit strictly to unread articles."
7827   (interactive "P")
7828   (if all
7829       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7830     (gnus-summary-limit-to-marks
7831      ;; Concat all the marks that say that an article is read and have
7832      ;; those removed.
7833      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7834            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7835            gnus-low-score-mark gnus-expirable-mark
7836            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7837            gnus-duplicate-mark gnus-souped-mark)
7838      'reverse)))
7839
7840 (defun gnus-summary-limit-to-replied (&optional unreplied)
7841   "Limit the summary buffer to replied articles.
7842 If UNREPLIED (the prefix), limit to unreplied articles."
7843   (interactive "P")
7844   (if unreplied
7845       (gnus-summary-limit
7846        (gnus-set-difference gnus-newsgroup-articles
7847         gnus-newsgroup-replied))
7848     (gnus-summary-limit gnus-newsgroup-replied))
7849   (gnus-summary-position-point))
7850
7851 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7852 (make-obsolete 'gnus-summary-delete-marked-with
7853                'gnus-summary-limit-exclude-marks)
7854
7855 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7856   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7857 If REVERSE, limit the summary buffer to articles that are marked
7858 with MARKS.  MARKS can either be a string of marks or a list of marks.
7859 Returns how many articles were removed."
7860   (interactive "sMarks: ")
7861   (gnus-summary-limit-to-marks marks t))
7862
7863 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7864   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7865 If REVERSE (the prefix), limit the summary buffer to articles that are
7866 not marked with MARKS.  MARKS can either be a string of marks or a
7867 list of marks.
7868 Returns how many articles were removed."
7869   (interactive "sMarks: \nP")
7870   (prog1
7871       (let ((data gnus-newsgroup-data)
7872             (marks (if (listp marks) marks
7873                      (append marks nil))) ; Transform to list.
7874             articles)
7875         (while data
7876           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7877                   (memq (gnus-data-mark (car data)) marks))
7878             (push (gnus-data-number (car data)) articles))
7879           (setq data (cdr data)))
7880         (gnus-summary-limit articles))
7881     (gnus-summary-position-point)))
7882
7883 (defun gnus-summary-limit-to-score (score)
7884   "Limit to articles with score at or above SCORE."
7885   (interactive "NLimit to articles with score of at least: ")
7886   (let ((data gnus-newsgroup-data)
7887         articles)
7888     (while data
7889       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7890                 score)
7891         (push (gnus-data-number (car data)) articles))
7892       (setq data (cdr data)))
7893     (prog1
7894         (gnus-summary-limit articles)
7895       (gnus-summary-position-point))))
7896
7897 (defun gnus-summary-limit-to-unseen ()
7898   "Limit to unseen articles."
7899   (interactive)
7900   (prog1
7901       (gnus-summary-limit gnus-newsgroup-unseen)
7902     (gnus-summary-position-point)))
7903
7904 (defun gnus-summary-limit-include-thread (id)
7905   "Display all the hidden articles that is in the thread with ID in it.
7906 When called interactively, ID is the Message-ID of the current
7907 article."
7908   (interactive (list (mail-header-id (gnus-summary-article-header))))
7909   (let ((articles (gnus-articles-in-thread
7910                    (gnus-id-to-thread (gnus-root-id id)))))
7911     (prog1
7912         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7913       (gnus-summary-limit-include-matching-articles
7914        "subject"
7915        (regexp-quote (gnus-simplify-subject-re
7916                       (mail-header-subject (gnus-id-to-header id)))))
7917       (gnus-summary-position-point))))
7918
7919 (defun gnus-summary-limit-include-matching-articles (header regexp)
7920   "Display all the hidden articles that have HEADERs that match REGEXP."
7921   (interactive (list (read-string "Match on header: ")
7922                      (read-string "Regexp: ")))
7923   (let ((articles (gnus-find-matching-articles header regexp)))
7924     (prog1
7925         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7926       (gnus-summary-position-point))))
7927
7928 (defun gnus-summary-insert-dormant-articles ()
7929   "Insert all the dormant articles for this group into the current buffer."
7930   (interactive)
7931   (let ((gnus-verbose (max 6 gnus-verbose)))
7932     (if (not gnus-newsgroup-dormant)
7933         (gnus-message 3 "No cached articles for this group")
7934       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7935
7936 (defun gnus-summary-limit-include-dormant ()
7937   "Display all the hidden articles that are marked as dormant.
7938 Note that this command only works on a subset of the articles currently
7939 fetched for this group."
7940   (interactive)
7941   (unless gnus-newsgroup-dormant
7942     (error "There are no dormant articles in this group"))
7943   (prog1
7944       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7945     (gnus-summary-position-point)))
7946
7947 (defun gnus-summary-limit-exclude-dormant ()
7948   "Hide all dormant articles."
7949   (interactive)
7950   (prog1
7951       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7952     (gnus-summary-position-point)))
7953
7954 (defun gnus-summary-limit-exclude-childless-dormant ()
7955   "Hide all dormant articles that have no children."
7956   (interactive)
7957   (let ((data (gnus-data-list t))
7958         articles d children)
7959     ;; Find all articles that are either not dormant or have
7960     ;; children.
7961     (while (setq d (pop data))
7962       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7963                 (and (setq children
7964                            (gnus-article-children (gnus-data-number d)))
7965                      (let (found)
7966                        (while children
7967                          (when (memq (car children) articles)
7968                            (setq children nil
7969                                  found t))
7970                          (pop children))
7971                        found)))
7972         (push (gnus-data-number d) articles)))
7973     ;; Do the limiting.
7974     (prog1
7975         (gnus-summary-limit articles)
7976       (gnus-summary-position-point))))
7977
7978 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7979   "Mark all unread excluded articles as read.
7980 If ALL, mark even excluded ticked and dormants as read."
7981   (interactive "P")
7982   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7983   (let ((articles (gnus-sorted-ndifference
7984                    (sort
7985                     (mapcar (lambda (h) (mail-header-number h))
7986                             gnus-newsgroup-headers)
7987                     '<)
7988                    gnus-newsgroup-limit))
7989         article)
7990     (setq gnus-newsgroup-unreads
7991           (gnus-sorted-intersection gnus-newsgroup-unreads
7992                                     gnus-newsgroup-limit))
7993     (if all
7994         (setq gnus-newsgroup-dormant nil
7995               gnus-newsgroup-marked nil
7996               gnus-newsgroup-reads
7997               (nconc
7998                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7999                gnus-newsgroup-reads))
8000       (while (setq article (pop articles))
8001         (unless (or (memq article gnus-newsgroup-dormant)
8002                     (memq article gnus-newsgroup-marked))
8003           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8004
8005 (defun gnus-summary-limit (articles &optional pop)
8006   (if pop
8007       ;; We pop the previous limit off the stack and use that.
8008       (setq articles (car gnus-newsgroup-limits)
8009             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8010     ;; We use the new limit, so we push the old limit on the stack.
8011     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8012   ;; Set the limit.
8013   (setq gnus-newsgroup-limit articles)
8014   (let ((total (length gnus-newsgroup-data))
8015         (data (gnus-data-find-list (gnus-summary-article-number)))
8016         (gnus-summary-mark-below nil)   ; Inhibit this.
8017         found)
8018     ;; This will do all the work of generating the new summary buffer
8019     ;; according to the new limit.
8020     (gnus-summary-prepare)
8021     ;; Hide any threads, possibly.
8022     (gnus-summary-maybe-hide-threads)
8023     ;; Try to return to the article you were at, or one in the
8024     ;; neighborhood.
8025     (when data
8026       ;; We try to find some article after the current one.
8027       (while data
8028         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8029           (setq data nil
8030                 found t))
8031         (setq data (cdr data))))
8032     (unless found
8033       ;; If there is no data, that means that we were after the last
8034       ;; article.  The same goes when we can't find any articles
8035       ;; after the current one.
8036       (goto-char (point-max))
8037       (gnus-summary-find-prev))
8038     (gnus-set-mode-line 'summary)
8039     ;; We return how many articles were removed from the summary
8040     ;; buffer as a result of the new limit.
8041     (- total (length gnus-newsgroup-data))))
8042
8043 (defsubst gnus-invisible-cut-children (threads)
8044   (let ((num 0))
8045     (while threads
8046       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8047         (incf num))
8048       (pop threads))
8049     (< num 2)))
8050
8051 (defsubst gnus-cut-thread (thread)
8052   "Go forwards in the thread until we find an article that we want to display."
8053   (when (or (eq gnus-fetch-old-headers 'some)
8054             (eq gnus-fetch-old-headers 'invisible)
8055             (numberp gnus-fetch-old-headers)
8056             (eq gnus-build-sparse-threads 'some)
8057             (eq gnus-build-sparse-threads 'more))
8058     ;; Deal with old-fetched headers and sparse threads.
8059     (while (and
8060             thread
8061             (or
8062              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8063              (gnus-summary-article-ancient-p
8064               (mail-header-number (car thread))))
8065             (if (or (<= (length (cdr thread)) 1)
8066                     (eq gnus-fetch-old-headers 'invisible))
8067                 (setq gnus-newsgroup-limit
8068                       (delq (mail-header-number (car thread))
8069                             gnus-newsgroup-limit)
8070                       thread (cadr thread))
8071               (when (gnus-invisible-cut-children (cdr thread))
8072                 (let ((th (cdr thread)))
8073                   (while th
8074                     (if (memq (mail-header-number (caar th))
8075                               gnus-newsgroup-limit)
8076                         (setq thread (car th)
8077                               th nil)
8078                       (setq th (cdr th))))))))))
8079   thread)
8080
8081 (defun gnus-cut-threads (threads)
8082   "Cut off all uninteresting articles from the beginning of THREADS."
8083   (when (or (eq gnus-fetch-old-headers 'some)
8084             (eq gnus-fetch-old-headers 'invisible)
8085             (numberp gnus-fetch-old-headers)
8086             (eq gnus-build-sparse-threads 'some)
8087             (eq gnus-build-sparse-threads 'more))
8088     (let ((th threads))
8089       (while th
8090         (setcar th (gnus-cut-thread (car th)))
8091         (setq th (cdr th)))))
8092   ;; Remove nixed out threads.
8093   (delq nil threads))
8094
8095 (defun gnus-summary-initial-limit (&optional show-if-empty)
8096   "Figure out what the initial limit is supposed to be on group entry.
8097 This entails weeding out unwanted dormants, low-scored articles,
8098 fetch-old-headers verbiage, and so on."
8099   ;; Most groups have nothing to remove.
8100   (if (or gnus-inhibit-limiting
8101           (and (null gnus-newsgroup-dormant)
8102                (eq gnus-newsgroup-display 'gnus-not-ignore)
8103                (not (eq gnus-fetch-old-headers 'some))
8104                (not (numberp gnus-fetch-old-headers))
8105                (not (eq gnus-fetch-old-headers 'invisible))
8106                (null gnus-summary-expunge-below)
8107                (not (eq gnus-build-sparse-threads 'some))
8108                (not (eq gnus-build-sparse-threads 'more))
8109                (null gnus-thread-expunge-below)
8110                (not gnus-use-nocem)))
8111       ()                                ; Do nothing.
8112     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8113     (setq gnus-newsgroup-limit nil)
8114     (mapatoms
8115      (lambda (node)
8116        (unless (car (symbol-value node))
8117          ;; These threads have no parents -- they are roots.
8118          (let ((nodes (cdr (symbol-value node)))
8119                thread)
8120            (while nodes
8121              (if (and gnus-thread-expunge-below
8122                       (< (gnus-thread-total-score (car nodes))
8123                          gnus-thread-expunge-below))
8124                  (gnus-expunge-thread (pop nodes))
8125                (setq thread (pop nodes))
8126                (gnus-summary-limit-children thread))))))
8127      gnus-newsgroup-dependencies)
8128     ;; If this limitation resulted in an empty group, we might
8129     ;; pop the previous limit and use it instead.
8130     (when (and (not gnus-newsgroup-limit)
8131                show-if-empty)
8132       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8133     gnus-newsgroup-limit))
8134
8135 (defun gnus-summary-limit-children (thread)
8136   "Return 1 if this subthread is visible and 0 if it is not."
8137   ;; First we get the number of visible children to this thread.  This
8138   ;; is done by recursing down the thread using this function, so this
8139   ;; will really go down to a leaf article first, before slowly
8140   ;; working its way up towards the root.
8141   (when thread
8142     (let* ((max-lisp-eval-depth 5000)
8143            (children
8144            (if (cdr thread)
8145                (apply '+ (mapcar 'gnus-summary-limit-children
8146                                  (cdr thread)))
8147              0))
8148           (number (mail-header-number (car thread)))
8149           score)
8150       (if (and
8151            (not (memq number gnus-newsgroup-marked))
8152            (or
8153             ;; If this article is dormant and has absolutely no visible
8154             ;; children, then this article isn't visible.
8155             (and (memq number gnus-newsgroup-dormant)
8156                  (zerop children))
8157             ;; If this is "fetch-old-headered" and there is no
8158             ;; visible children, then we don't want this article.
8159             (and (or (eq gnus-fetch-old-headers 'some)
8160                      (numberp gnus-fetch-old-headers))
8161                  (gnus-summary-article-ancient-p number)
8162                  (zerop children))
8163             ;; If this is "fetch-old-headered" and `invisible', then
8164             ;; we don't want this article.
8165             (and (eq gnus-fetch-old-headers 'invisible)
8166                  (gnus-summary-article-ancient-p number))
8167             ;; If this is a sparsely inserted article with no children,
8168             ;; we don't want it.
8169             (and (eq gnus-build-sparse-threads 'some)
8170                  (gnus-summary-article-sparse-p number)
8171                  (zerop children))
8172             ;; If we use expunging, and this article is really
8173             ;; low-scored, then we don't want this article.
8174             (when (and gnus-summary-expunge-below
8175                        (< (setq score
8176                                 (or (cdr (assq number gnus-newsgroup-scored))
8177                                     gnus-summary-default-score))
8178                           gnus-summary-expunge-below))
8179               ;; We increase the expunge-tally here, but that has
8180               ;; nothing to do with the limits, really.
8181               (incf gnus-newsgroup-expunged-tally)
8182               ;; We also mark as read here, if that's wanted.
8183               (when (and gnus-summary-mark-below
8184                          (< score gnus-summary-mark-below))
8185                 (setq gnus-newsgroup-unreads
8186                       (delq number gnus-newsgroup-unreads))
8187                 (if gnus-newsgroup-auto-expire
8188                     (push number gnus-newsgroup-expirable)
8189                   (push (cons number gnus-low-score-mark)
8190                         gnus-newsgroup-reads)))
8191               t)
8192             ;; Do the `display' group parameter.
8193             (and gnus-newsgroup-display
8194                  (not (funcall gnus-newsgroup-display)))
8195             ;; Check NoCeM things.
8196             (when (and gnus-use-nocem
8197                        (gnus-nocem-unwanted-article-p
8198                         (mail-header-id (car thread))))
8199               (setq gnus-newsgroup-unreads
8200                     (delq number gnus-newsgroup-unreads))
8201               t)))
8202           ;; Nope, invisible article.
8203           0
8204         ;; Ok, this article is to be visible, so we add it to the limit
8205         ;; and return 1.
8206         (push number gnus-newsgroup-limit)
8207         1))))
8208
8209 (defun gnus-expunge-thread (thread)
8210   "Mark all articles in THREAD as read."
8211   (let* ((number (mail-header-number (car thread))))
8212     (incf gnus-newsgroup-expunged-tally)
8213     ;; We also mark as read here, if that's wanted.
8214     (setq gnus-newsgroup-unreads
8215           (delq number gnus-newsgroup-unreads))
8216     (if gnus-newsgroup-auto-expire
8217         (push number gnus-newsgroup-expirable)
8218       (push (cons number gnus-low-score-mark)
8219             gnus-newsgroup-reads)))
8220   ;; Go recursively through all subthreads.
8221   (mapcar 'gnus-expunge-thread (cdr thread)))
8222
8223 ;; Summary article oriented commands
8224
8225 (defun gnus-summary-refer-parent-article (n)
8226   "Refer parent article N times.
8227 If N is negative, go to ancestor -N instead.
8228 The difference between N and the number of articles fetched is returned."
8229   (interactive "p")
8230   (let ((skip 1)
8231         error header ref)
8232     (when (not (natnump n))
8233       (setq skip (abs n)
8234             n 1))
8235     (while (and (> n 0)
8236                 (not error))
8237       (setq header (gnus-summary-article-header))
8238       (if (and (eq (mail-header-number header)
8239                    (cdr gnus-article-current))
8240                (equal gnus-newsgroup-name
8241                       (car gnus-article-current)))
8242           ;; If we try to find the parent of the currently
8243           ;; displayed article, then we take a look at the actual
8244           ;; References header, since this is slightly more
8245           ;; reliable than the References field we got from the
8246           ;; server.
8247           (save-excursion
8248             (set-buffer gnus-original-article-buffer)
8249             (nnheader-narrow-to-headers)
8250             (unless (setq ref (message-fetch-field "references"))
8251               (when (setq ref (message-fetch-field "in-reply-to"))
8252                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8253             (widen))
8254         (setq ref
8255               ;; It's not the current article, so we take a bet on
8256               ;; the value we got from the server.
8257               (mail-header-references header)))
8258       (if (and ref
8259                (not (equal ref "")))
8260           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8261             (gnus-message 1 "Couldn't find parent"))
8262         (gnus-message 1 "No references in article %d"
8263                       (gnus-summary-article-number))
8264         (setq error t))
8265       (decf n))
8266     (gnus-summary-position-point)
8267     n))
8268
8269 (defun gnus-summary-refer-references ()
8270   "Fetch all articles mentioned in the References header.
8271 Return the number of articles fetched."
8272   (interactive)
8273   (let ((ref (mail-header-references (gnus-summary-article-header)))
8274         (current (gnus-summary-article-number))
8275         (n 0))
8276     (if (or (not ref)
8277             (equal ref ""))
8278         (error "No References in the current article")
8279       ;; For each Message-ID in the References header...
8280       (while (string-match "<[^>]*>" ref)
8281         (incf n)
8282         ;; ... fetch that article.
8283         (gnus-summary-refer-article
8284          (prog1 (match-string 0 ref)
8285            (setq ref (substring ref (match-end 0))))))
8286       (gnus-summary-goto-subject current)
8287       (gnus-summary-position-point)
8288       n)))
8289
8290 (defun gnus-summary-refer-thread (&optional limit)
8291   "Fetch all articles in the current thread.
8292 If LIMIT (the numerical prefix), fetch that many old headers instead
8293 of what's specified by the `gnus-refer-thread-limit' variable."
8294   (interactive "P")
8295   (let ((id (mail-header-id (gnus-summary-article-header)))
8296         (limit (if limit (prefix-numeric-value limit)
8297                  gnus-refer-thread-limit)))
8298     (unless (eq gnus-fetch-old-headers 'invisible)
8299       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8300       ;; Retrieve the headers and read them in.
8301       (if (eq (if (numberp limit)
8302                   (gnus-retrieve-headers
8303                    (list (min
8304                           (+ (mail-header-number
8305                               (gnus-summary-article-header))
8306                              limit)
8307                           gnus-newsgroup-end))
8308                    gnus-newsgroup-name (* limit 2))
8309                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8310                 ;; headers.
8311                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8312                                        gnus-newsgroup-name limit))
8313               'nov)
8314           (gnus-build-all-threads)
8315         (error "Can't fetch thread from back ends that don't support NOV"))
8316       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8317     (gnus-summary-limit-include-thread id)))
8318
8319 (defun gnus-summary-refer-article (message-id)
8320   "Fetch an article specified by MESSAGE-ID."
8321   (interactive "sMessage-ID: ")
8322   (when (and (stringp message-id)
8323              (not (zerop (length message-id))))
8324     (setq message-id (gnus-replace-in-string message-id " " ""))
8325     ;; Construct the correct Message-ID if necessary.
8326     ;; Suggested by tale@pawl.rpi.edu.
8327     (unless (string-match "^<" message-id)
8328       (setq message-id (concat "<" message-id)))
8329     (unless (string-match ">$" message-id)
8330       (setq message-id (concat message-id ">")))
8331     ;; People often post MIDs from URLs, so unhex it:
8332     (unless (string-match "@" message-id)
8333       (setq message-id (gnus-url-unhex-string message-id)))
8334     (let* ((header (gnus-id-to-header message-id))
8335            (sparse (and header
8336                         (gnus-summary-article-sparse-p
8337                          (mail-header-number header))
8338                         (memq (mail-header-number header)
8339                               gnus-newsgroup-limit)))
8340            number)
8341       (cond
8342        ;; If the article is present in the buffer we just go to it.
8343        ((and header
8344              (or (not (gnus-summary-article-sparse-p
8345                        (mail-header-number header)))
8346                  sparse))
8347         (prog1
8348             (gnus-summary-goto-article
8349              (mail-header-number header) nil t)
8350           (when sparse
8351             (gnus-summary-update-article (mail-header-number header)))))
8352        (t
8353         ;; We fetch the article.
8354         (catch 'found
8355           (dolist (gnus-override-method (gnus-refer-article-methods))
8356             (when (and (gnus-check-server gnus-override-method)
8357                        ;; Fetch the header,
8358                        (setq number (gnus-summary-insert-subject message-id)))
8359               ;; and display the article.
8360               (gnus-summary-select-article nil nil nil number)
8361               (throw 'found t)))
8362           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8363
8364 (defun gnus-refer-article-methods ()
8365   "Return a list of referable methods."
8366   (cond
8367    ;; No method, so we default to current and native.
8368    ((null gnus-refer-article-method)
8369     (list gnus-current-select-method gnus-select-method))
8370    ;; Current.
8371    ((eq 'current gnus-refer-article-method)
8372     (list gnus-current-select-method))
8373    ;; List of select methods.
8374    ((not (and (symbolp (car gnus-refer-article-method))
8375               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8376     (let (out)
8377       (dolist (method gnus-refer-article-method)
8378         (push (if (eq 'current method)
8379                   gnus-current-select-method
8380                 method)
8381               out))
8382       (nreverse out)))
8383    ;; One single select method.
8384    (t
8385     (list gnus-refer-article-method))))
8386
8387 (defun gnus-summary-edit-parameters ()
8388   "Edit the group parameters of the current group."
8389   (interactive)
8390   (gnus-group-edit-group gnus-newsgroup-name 'params))
8391
8392 (defun gnus-summary-customize-parameters ()
8393   "Customize the group parameters of the current group."
8394   (interactive)
8395   (gnus-group-customize gnus-newsgroup-name))
8396
8397 (defun gnus-summary-enter-digest-group (&optional force)
8398   "Enter an nndoc group based on the current article.
8399 If FORCE, force a digest interpretation.  If not, try
8400 to guess what the document format is."
8401   (interactive "P")
8402   (let ((conf gnus-current-window-configuration))
8403     (save-window-excursion
8404       (save-excursion
8405         (let (gnus-article-prepare-hook
8406               gnus-display-mime-function
8407               gnus-break-pages)
8408           (gnus-summary-select-article))))
8409     (setq gnus-current-window-configuration conf)
8410     (let* ((name (format "%s-%d"
8411                          (gnus-group-prefixed-name
8412                           gnus-newsgroup-name (list 'nndoc ""))
8413                          (with-current-buffer gnus-summary-buffer
8414                            gnus-current-article)))
8415            (ogroup gnus-newsgroup-name)
8416            (params (append (gnus-info-params (gnus-get-info ogroup))
8417                            (list (cons 'to-group ogroup))
8418                            (list (cons 'parent-group ogroup))
8419                            (list (cons 'save-article-group ogroup))))
8420            (case-fold-search t)
8421            (buf (current-buffer))
8422            dig to-address)
8423       (save-excursion
8424         (set-buffer gnus-original-article-buffer)
8425         ;; Have the digest group inherit the main mail address of
8426         ;; the parent article.
8427         (when (setq to-address (or (gnus-fetch-field "reply-to")
8428                                    (gnus-fetch-field "from")))
8429           (setq params (append
8430                         (list (cons 'to-address
8431                                     (funcall gnus-decode-encoded-word-function
8432                                              to-address))))))
8433         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8434         (insert-buffer-substring gnus-original-article-buffer)
8435         ;; Remove lines that may lead nndoc to misinterpret the
8436         ;; document type.
8437         (narrow-to-region
8438          (goto-char (point-min))
8439          (or (search-forward "\n\n" nil t) (point)))
8440         (goto-char (point-min))
8441         (delete-matching-lines "^Path:\\|^From ")
8442         (widen))
8443       (unwind-protect
8444           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8445                     (gnus-newsgroup-ephemeral-ignored-charsets
8446                      gnus-newsgroup-ignored-charsets))
8447                 (gnus-group-read-ephemeral-group
8448                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8449                               (nndoc-article-type
8450                                ,(if force 'mbox 'guess)))
8451                  t nil nil nil
8452                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8453                                                         "ADAPT")))))
8454               ;; Make all postings to this group go to the parent group.
8455               (nconc (gnus-info-params (gnus-get-info name))
8456                      params)
8457             ;; Couldn't select this doc group.
8458             (switch-to-buffer buf)
8459             (gnus-set-global-variables)
8460             (gnus-configure-windows 'summary)
8461             (gnus-message 3 "Article couldn't be entered?"))
8462         (kill-buffer dig)))))
8463
8464 (defun gnus-summary-read-document (n)
8465   "Open a new group based on the current article(s).
8466 This will allow you to read digests and other similar
8467 documents as newsgroups.
8468 Obeys the standard process/prefix convention."
8469   (interactive "P")
8470   (let* ((ogroup gnus-newsgroup-name)
8471          (params (append (gnus-info-params (gnus-get-info ogroup))
8472                          (list (cons 'to-group ogroup))))
8473          group egroup groups vgroup)
8474     (dolist (article (gnus-summary-work-articles n))
8475       (setq group (format "%s-%d" gnus-newsgroup-name article))
8476       (gnus-summary-remove-process-mark article)
8477       (when (gnus-summary-display-article article)
8478         (save-excursion
8479           (with-temp-buffer
8480             (insert-buffer-substring gnus-original-article-buffer)
8481             ;; Remove some headers that may lead nndoc to make
8482             ;; the wrong guess.
8483             (message-narrow-to-head)
8484             (goto-char (point-min))
8485             (delete-matching-lines "^Path:\\|^From ")
8486             (widen)
8487             (if (setq egroup
8488                       (gnus-group-read-ephemeral-group
8489                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8490                                      (nndoc-article-type guess))
8491                        t nil t))
8492                 (progn
8493             ;; Make all postings to this group go to the parent group.
8494                   (nconc (gnus-info-params (gnus-get-info egroup))
8495                          params)
8496                   (push egroup groups))
8497               ;; Couldn't select this doc group.
8498               (gnus-error 3 "Article couldn't be entered"))))))
8499     ;; Now we have selected all the documents.
8500     (cond
8501      ((not groups)
8502       (error "None of the articles could be interpreted as documents"))
8503      ((gnus-group-read-ephemeral-group
8504        (setq vgroup (format
8505                      "nnvirtual:%s-%s" gnus-newsgroup-name
8506                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8507        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8508        t
8509        (cons (current-buffer) 'summary)))
8510      (t
8511       (error "Couldn't select virtual nndoc group")))))
8512
8513 (defun gnus-summary-isearch-article (&optional regexp-p)
8514   "Do incremental search forward on the current article.
8515 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8516   (interactive "P")
8517   (gnus-summary-select-article)
8518   (gnus-configure-windows 'article)
8519   (gnus-eval-in-buffer-window gnus-article-buffer
8520     (save-restriction
8521       (widen)
8522       (isearch-forward regexp-p))))
8523
8524 (defun gnus-summary-search-article-forward (regexp &optional backward)
8525   "Search for an article containing REGEXP forward.
8526 If BACKWARD, search backward instead."
8527   (interactive
8528    (list (read-string
8529           (format "Search article %s (regexp%s): "
8530                   (if current-prefix-arg "backward" "forward")
8531                   (if gnus-last-search-regexp
8532                       (concat ", default " gnus-last-search-regexp)
8533                     "")))
8534          current-prefix-arg))
8535   (if (string-equal regexp "")
8536       (setq regexp (or gnus-last-search-regexp ""))
8537     (setq gnus-last-search-regexp regexp)
8538     (setq gnus-article-before-search gnus-current-article))
8539   ;; Intentionally set gnus-last-article.
8540   (setq gnus-last-article gnus-article-before-search)
8541   (let ((gnus-last-article gnus-last-article))
8542     (if (gnus-summary-search-article regexp backward)
8543         (gnus-summary-show-thread)
8544       (signal 'search-failed (list regexp)))))
8545
8546 (defun gnus-summary-search-article-backward (regexp)
8547   "Search for an article containing REGEXP backward."
8548   (interactive
8549    (list (read-string
8550           (format "Search article backward (regexp%s): "
8551                   (if gnus-last-search-regexp
8552                       (concat ", default " gnus-last-search-regexp)
8553                     "")))))
8554   (gnus-summary-search-article-forward regexp 'backward))
8555
8556 (defun gnus-summary-search-article (regexp &optional backward)
8557   "Search for an article containing REGEXP.
8558 Optional argument BACKWARD means do search for backward.
8559 `gnus-select-article-hook' is not called during the search."
8560   ;; We have to require this here to make sure that the following
8561   ;; dynamic binding isn't shadowed by autoloading.
8562   (require 'gnus-async)
8563   (require 'gnus-art)
8564   (let ((gnus-select-article-hook nil)  ;Disable hook.
8565         (gnus-article-prepare-hook nil)
8566         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8567         (gnus-use-article-prefetch nil)
8568         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8569         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8570         (gnus-visual nil)
8571         (gnus-keep-backlog nil)
8572         (gnus-break-pages nil)
8573         (gnus-summary-display-arrow nil)
8574         (gnus-updated-mode-lines nil)
8575         (gnus-auto-center-summary nil)
8576         (sum (current-buffer))
8577         (gnus-display-mime-function nil)
8578         (found nil)
8579         point)
8580     (gnus-save-hidden-threads
8581       (gnus-summary-select-article)
8582       (set-buffer gnus-article-buffer)
8583       (goto-char (window-point (get-buffer-window (current-buffer))))
8584       (when backward
8585         (forward-line -1))
8586       (while (not found)
8587         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8588         (if (if backward
8589                 (re-search-backward regexp nil t)
8590               (re-search-forward regexp nil t))
8591             ;; We found the regexp.
8592             (progn
8593               (setq found 'found)
8594               (beginning-of-line)
8595               (set-window-start
8596                (get-buffer-window (current-buffer))
8597                (point))
8598               (forward-line 1)
8599               (set-window-point
8600                (get-buffer-window (current-buffer))
8601                (point))
8602               (set-buffer sum)
8603               (setq point (point)))
8604           ;; We didn't find it, so we go to the next article.
8605           (set-buffer sum)
8606           (setq found 'not)
8607           (while (eq found 'not)
8608             (if (not (if backward (gnus-summary-find-prev)
8609                        (gnus-summary-find-next)))
8610                 ;; No more articles.
8611                 (setq found t)
8612               ;; Select the next article and adjust point.
8613               (unless (gnus-summary-article-sparse-p
8614                        (gnus-summary-article-number))
8615                 (setq found nil)
8616                 (gnus-summary-select-article)
8617                 (set-buffer gnus-article-buffer)
8618                 (widen)
8619                 (goto-char (if backward (point-max) (point-min))))))))
8620       (gnus-message 7 ""))
8621     ;; Return whether we found the regexp.
8622     (when (eq found 'found)
8623       (goto-char point)
8624       (gnus-summary-show-thread)
8625       (gnus-summary-goto-subject gnus-current-article)
8626       (gnus-summary-position-point)
8627       t)))
8628
8629 (defun gnus-find-matching-articles (header regexp)
8630   "Return a list of all articles that match REGEXP on HEADER.
8631 This search includes all articles in the current group that Gnus has
8632 fetched headers for, whether they are displayed or not."
8633   (let ((articles nil)
8634         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8635         (case-fold-search t))
8636     (dolist (header gnus-newsgroup-headers)
8637       (when (string-match regexp (funcall func header))
8638         (push (mail-header-number header) articles)))
8639     (nreverse articles)))
8640
8641 (defun gnus-summary-find-matching (header regexp &optional backward unread
8642                                           not-case-fold not-matching)
8643   "Return a list of all articles that match REGEXP on HEADER.
8644 The search stars on the current article and goes forwards unless
8645 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8646 If UNREAD is non-nil, only unread articles will
8647 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8648 in the comparisons. If NOT-MATCHING, return a list of all articles that
8649 not match REGEXP on HEADER."
8650   (let ((case-fold-search (not not-case-fold))
8651         articles d func)
8652     (if (consp header)
8653         (if (eq (car header) 'extra)
8654             (setq func
8655                   `(lambda (h)
8656                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8657                          "")))
8658           (error "%s is an invalid header" header))
8659       (unless (fboundp (intern (concat "mail-header-" header)))
8660         (error "%s is not a valid header" header))
8661       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8662     (dolist (d (if (eq backward 'all)
8663                    gnus-newsgroup-data
8664                  (gnus-data-find-list
8665                   (gnus-summary-article-number)
8666                   (gnus-data-list backward))))
8667       (when (and (or (not unread)       ; We want all articles...
8668                      (gnus-data-unread-p d)) ; Or just unreads.
8669                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8670                  (if not-matching
8671                      (not (string-match
8672                            regexp
8673                            (funcall func (gnus-data-header d))))
8674                    (string-match regexp
8675                                  (funcall func (gnus-data-header d)))))
8676         (push (gnus-data-number d) articles))) ; Success!
8677     (nreverse articles)))
8678
8679 (defun gnus-summary-execute-command (header regexp command &optional backward)
8680   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8681 If HEADER is an empty string (or nil), the match is done on the entire
8682 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8683   (interactive
8684    (list (let ((completion-ignore-case t))
8685            (completing-read
8686             "Header name: "
8687             (mapcar (lambda (header) (list (format "%s" header)))
8688                     (append
8689                      '("Number" "Subject" "From" "Lines" "Date"
8690                        "Message-ID" "Xref" "References" "Body")
8691                      gnus-extra-headers))
8692             nil 'require-match))
8693          (read-string "Regexp: ")
8694          (read-key-sequence "Command: ")
8695          current-prefix-arg))
8696   (when (equal header "Body")
8697     (setq header ""))
8698   ;; Hidden thread subtrees must be searched as well.
8699   (gnus-summary-show-all-threads)
8700   ;; We don't want to change current point nor window configuration.
8701   (save-excursion
8702     (save-window-excursion
8703       (let (gnus-visual
8704             gnus-treat-strip-trailing-blank-lines
8705             gnus-treat-strip-leading-blank-lines
8706             gnus-treat-strip-multiple-blank-lines
8707             gnus-treat-hide-boring-headers
8708             gnus-treat-fold-newsgroups
8709             gnus-article-prepare-hook)
8710         (gnus-message 6 "Executing %s..." (key-description command))
8711         ;; We'd like to execute COMMAND interactively so as to give arguments.
8712         (gnus-execute header regexp
8713                       `(call-interactively ',(key-binding command))
8714                       backward)
8715         (gnus-message 6 "Executing %s...done" (key-description command))))))
8716
8717 (defun gnus-summary-beginning-of-article ()
8718   "Scroll the article back to the beginning."
8719   (interactive)
8720   (gnus-summary-select-article)
8721   (gnus-configure-windows 'article)
8722   (gnus-eval-in-buffer-window gnus-article-buffer
8723     (widen)
8724     (goto-char (point-min))
8725     (when gnus-break-pages
8726       (gnus-narrow-to-page))))
8727
8728 (defun gnus-summary-end-of-article ()
8729   "Scroll to the end of the article."
8730   (interactive)
8731   (gnus-summary-select-article)
8732   (gnus-configure-windows 'article)
8733   (gnus-eval-in-buffer-window gnus-article-buffer
8734     (widen)
8735     (goto-char (point-max))
8736     (recenter -3)
8737     (when gnus-break-pages
8738       (when (re-search-backward page-delimiter nil t)
8739         (narrow-to-region (match-end 0) (point-max)))
8740       (gnus-narrow-to-page))))
8741
8742 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8743   "Truncate to LEN and quote all \"(\"'s in STRING."
8744   (gnus-replace-in-string (if (and len (> (length string) len))
8745                               (substring string 0 len)
8746                             string)
8747                           "[()]" "\\\\\\&"))
8748
8749 (defun gnus-summary-print-article (&optional filename n)
8750   "Generate and print a PostScript image of the process-marked (mail) articles.
8751
8752 If used interactively, print the current article if none are
8753 process-marked.  With prefix arg, prompt the user for the name of the
8754 file to save in.
8755
8756 When used from Lisp, accept two optional args FILENAME and N.  N means
8757 to print the next N articles.  If N is negative, print the N previous
8758 articles.  If N is nil and articles have been marked with the process
8759 mark, print these instead.
8760
8761 If the optional first argument FILENAME is nil, send the image to the
8762 printer.  If FILENAME is a string, save the PostScript image in a file with
8763 that name.  If FILENAME is a number, prompt the user for the name of the file
8764 to save in."
8765   (interactive (list (ps-print-preprint current-prefix-arg)))
8766   (dolist (article (gnus-summary-work-articles n))
8767     (gnus-summary-select-article nil nil 'pseudo article)
8768     (gnus-eval-in-buffer-window gnus-article-buffer
8769       (gnus-print-buffer))
8770     (gnus-summary-remove-process-mark article))
8771   (ps-despool filename))
8772
8773 (defun gnus-print-buffer ()
8774   (let ((buffer (generate-new-buffer " *print*")))
8775     (unwind-protect
8776         (progn
8777           (copy-to-buffer buffer (point-min) (point-max))
8778           (set-buffer buffer)
8779           (gnus-remove-text-with-property 'gnus-decoration)
8780           (when (gnus-visual-p 'article-highlight 'highlight)
8781             ;; Copy-to-buffer doesn't copy overlay.  So redo
8782             ;; highlight.
8783             (let ((gnus-article-buffer buffer))
8784               (gnus-article-highlight-citation t)
8785               (gnus-article-highlight-signature)
8786               (gnus-article-emphasize)
8787               (gnus-article-delete-invisible-text)))
8788           (let ((ps-left-header
8789                  (list
8790                   (concat "("
8791                           (gnus-summary-print-truncate-and-quote
8792                            (mail-header-subject gnus-current-headers)
8793                            66) ")")
8794                   (concat "("
8795                           (gnus-summary-print-truncate-and-quote
8796                            (mail-header-from gnus-current-headers)
8797                            45) ")")))
8798                 (ps-right-header
8799                  (list
8800                   "/pagenumberstring load"
8801                   (concat "("
8802                           (mail-header-date gnus-current-headers) ")"))))
8803             (gnus-run-hooks 'gnus-ps-print-hook)
8804             (save-excursion
8805               (if window-system
8806                   (ps-spool-buffer-with-faces)
8807                 (ps-spool-buffer)))))
8808       (kill-buffer buffer))))
8809
8810 (defun gnus-summary-show-article (&optional arg)
8811   "Force redisplaying of the current article.
8812 If ARG (the prefix) is a number, show the article with the charset
8813 defined in `gnus-summary-show-article-charset-alist', or the charset
8814 input.
8815 If ARG (the prefix) is non-nil and not a number, show the raw article
8816 without any article massaging functions being run.  Normally, the key
8817 strokes are `C-u g'."
8818   (interactive "P")
8819   (cond
8820    ((numberp arg)
8821     (gnus-summary-show-article t)
8822     (let ((gnus-newsgroup-charset
8823            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8824                (mm-read-coding-system
8825                 "View as charset: " ;; actually it is coding system.
8826                 (with-current-buffer gnus-article-buffer
8827                   (mm-detect-coding-region (point) (point-max))))))
8828           (gnus-newsgroup-ignored-charsets 'gnus-all))
8829       (gnus-summary-select-article nil 'force)
8830       (let ((deps gnus-newsgroup-dependencies)
8831             head header lines)
8832         (save-excursion
8833           (set-buffer gnus-original-article-buffer)
8834           (save-restriction
8835             (message-narrow-to-head)
8836             (setq head (buffer-string))
8837             (goto-char (point-min))
8838             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8839               (goto-char (point-max))
8840               (widen)
8841               (setq lines (1- (count-lines (point) (point-max))))))
8842           (with-temp-buffer
8843             (insert (format "211 %d Article retrieved.\n"
8844                             (cdr gnus-article-current)))
8845             (insert head)
8846             (if lines (insert (format "Lines: %d\n" lines)))
8847             (insert ".\n")
8848             (let ((nntp-server-buffer (current-buffer)))
8849               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8850         (gnus-data-set-header
8851          (gnus-data-find (cdr gnus-article-current))
8852          header)
8853         (gnus-summary-update-article-line
8854          (cdr gnus-article-current) header)
8855         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8856           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8857    ((not arg)
8858     ;; Select the article the normal way.
8859     (gnus-summary-select-article nil 'force))
8860    (t
8861     ;; We have to require this here to make sure that the following
8862     ;; dynamic binding isn't shadowed by autoloading.
8863     (require 'gnus-async)
8864     (require 'gnus-art)
8865     ;; Bind the article treatment functions to nil.
8866     (let ((gnus-have-all-headers t)
8867           gnus-article-prepare-hook
8868           gnus-article-decode-hook
8869           gnus-display-mime-function
8870           gnus-break-pages)
8871       ;; Destroy any MIME parts.
8872       (when (gnus-buffer-live-p gnus-article-buffer)
8873         (save-excursion
8874           (set-buffer gnus-article-buffer)
8875           (mm-destroy-parts gnus-article-mime-handles)
8876           ;; Set it to nil for safety reason.
8877           (setq gnus-article-mime-handle-alist nil)
8878           (setq gnus-article-mime-handles nil)))
8879       (gnus-summary-select-article nil 'force))))
8880   (gnus-summary-goto-subject gnus-current-article)
8881   (gnus-summary-position-point))
8882
8883 (defun gnus-summary-show-raw-article ()
8884   "Show the raw article without any article massaging functions being run."
8885   (interactive)
8886   (gnus-summary-show-article t))
8887
8888 (defun gnus-summary-verbose-headers (&optional arg)
8889   "Toggle permanent full header display.
8890 If ARG is a positive number, turn header display on.
8891 If ARG is a negative number, turn header display off."
8892   (interactive "P")
8893   (setq gnus-show-all-headers
8894         (cond ((or (not (numberp arg))
8895                    (zerop arg))
8896                (not gnus-show-all-headers))
8897               ((natnump arg)
8898                t)))
8899   (gnus-summary-show-article))
8900
8901 (defun gnus-summary-toggle-header (&optional arg)
8902   "Show the headers if they are hidden, or hide them if they are shown.
8903 If ARG is a positive number, show the entire header.
8904 If ARG is a negative number, hide the unwanted header lines."
8905   (interactive "P")
8906   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8907                      (get-buffer-window gnus-article-buffer t))))
8908     (with-current-buffer gnus-article-buffer
8909       (widen)
8910       (article-narrow-to-head)
8911       (let* ((buffer-read-only nil)
8912              (inhibit-point-motion-hooks t)
8913              (hidden (if (numberp arg)
8914                          (>= arg 0)
8915                        (or (not (looking-at "[^ \t\n]+:"))
8916                            (gnus-article-hidden-text-p 'headers))))
8917              s e)
8918         (delete-region (point-min) (point-max))
8919         (with-current-buffer gnus-original-article-buffer
8920           (goto-char (setq s (point-min)))
8921           (setq e (if (search-forward "\n\n" nil t)
8922                       (1- (point))
8923                     (point-max))))
8924         (insert-buffer-substring gnus-original-article-buffer s e)
8925         (run-hooks 'gnus-article-decode-hook)
8926         (if hidden
8927             (let ((gnus-treat-hide-headers nil)
8928                   (gnus-treat-hide-boring-headers nil))
8929               (gnus-delete-wash-type 'headers)
8930               (gnus-treat-article 'head))
8931           (gnus-treat-article 'head))
8932         (widen)
8933         (if window
8934             (set-window-start window (goto-char (point-min))))
8935         (if gnus-break-pages
8936             (gnus-narrow-to-page)
8937           (when (gnus-visual-p 'page-marker)
8938             (let ((buffer-read-only nil))
8939               (gnus-remove-text-with-property 'gnus-prev)
8940               (gnus-remove-text-with-property 'gnus-next))))
8941         (gnus-set-mode-line 'article)))))
8942
8943 (defun gnus-summary-show-all-headers ()
8944   "Make all header lines visible."
8945   (interactive)
8946   (gnus-summary-toggle-header 1))
8947
8948 (defun gnus-summary-caesar-message (&optional arg)
8949   "Caesar rotate the current article by 13.
8950 The numerical prefix specifies how many places to rotate each letter
8951 forward."
8952   (interactive "P")
8953   (gnus-summary-select-article)
8954   (let ((mail-header-separator ""))
8955     (gnus-eval-in-buffer-window gnus-article-buffer
8956       (save-restriction
8957         (widen)
8958         (let ((start (window-start))
8959               buffer-read-only)
8960           (message-caesar-buffer-body arg)
8961           (set-window-start (get-buffer-window (current-buffer)) start))))))
8962
8963 (autoload 'unmorse-region "morse"
8964   "Convert morse coded text in region to ordinary ASCII text."
8965   t)
8966
8967 (defun gnus-summary-morse-message (&optional arg)
8968   "Morse decode the current article."
8969   (interactive "P")
8970   (gnus-summary-select-article)
8971   (let ((mail-header-separator ""))
8972     (gnus-eval-in-buffer-window gnus-article-buffer
8973       (save-excursion
8974         (save-restriction
8975           (widen)
8976           (let ((pos (window-start))
8977                 buffer-read-only)
8978             (goto-char (point-min))
8979             (when (message-goto-body)
8980               (gnus-narrow-to-body))
8981             (goto-char (point-min))
8982             (while (search-forward "·" (point-max) t)
8983               (replace-match "."))
8984             (unmorse-region (point-min) (point-max))
8985             (widen)
8986             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8987
8988 (defun gnus-summary-stop-page-breaking ()
8989   "Stop page breaking in the current article."
8990   (interactive)
8991   (gnus-summary-select-article)
8992   (gnus-eval-in-buffer-window gnus-article-buffer
8993     (widen)
8994     (when (gnus-visual-p 'page-marker)
8995       (let ((buffer-read-only nil))
8996         (gnus-remove-text-with-property 'gnus-prev)
8997         (gnus-remove-text-with-property 'gnus-next))
8998       (setq gnus-page-broken nil))))
8999
9000 (defun gnus-summary-move-article (&optional n to-newsgroup
9001                                             select-method action)
9002   "Move the current article to a different newsgroup.
9003 If N is a positive number, move the N next articles.
9004 If N is a negative number, move the N previous articles.
9005 If N is nil and any articles have been marked with the process mark,
9006 move those articles instead.
9007 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9008 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9009 re-spool using this method.
9010
9011 When called interactively with TO-NEWSGROUP being nil, the value of
9012 the variable `gnus-move-split-methods' is used for finding a default
9013 for the target newsgroup.
9014
9015 For this function to work, both the current newsgroup and the
9016 newsgroup that you want to move to have to support the `request-move'
9017 and `request-accept' functions.
9018
9019 ACTION can be either `move' (the default), `crosspost' or `copy'."
9020   (interactive "P")
9021   (unless action
9022     (setq action 'move))
9023   ;; Check whether the source group supports the required functions.
9024   (cond ((and (eq action 'move)
9025               (not (gnus-check-backend-function
9026                     'request-move-article gnus-newsgroup-name)))
9027          (error "The current group does not support article moving"))
9028         ((and (eq action 'crosspost)
9029               (not (gnus-check-backend-function
9030                     'request-replace-article gnus-newsgroup-name)))
9031          (error "The current group does not support article editing")))
9032   (let ((articles (gnus-summary-work-articles n))
9033         (prefix (if (gnus-check-backend-function
9034                      'request-move-article gnus-newsgroup-name)
9035                     (funcall gnus-move-group-prefix-function
9036                              gnus-newsgroup-name)
9037                   ""))
9038         (names '((move "Move" "Moving")
9039                  (copy "Copy" "Copying")
9040                  (crosspost "Crosspost" "Crossposting")))
9041         (copy-buf (save-excursion
9042                     (nnheader-set-temp-buffer " *copy article*")))
9043         art-group to-method new-xref article to-groups)
9044     (unless (assq action names)
9045       (error "Unknown action %s" action))
9046     ;; Read the newsgroup name.
9047     (when (and (not to-newsgroup)
9048                (not select-method))
9049       (if (and gnus-move-split-methods
9050                (not
9051                 (and (memq gnus-current-article articles)
9052                      (gnus-buffer-live-p gnus-original-article-buffer))))
9053           ;; When `gnus-move-split-methods' is non-nil, we have to
9054           ;; select an article to give `gnus-read-move-group-name' an
9055           ;; opportunity to suggest an appropriate default.  However,
9056           ;; we needn't render or mark the article.
9057           (let ((gnus-display-mime-function nil)
9058                 (gnus-article-prepare-hook nil)
9059                 (gnus-mark-article-hook nil))
9060             (gnus-summary-select-article nil nil nil (car articles))))
9061       (setq to-newsgroup
9062             (gnus-read-move-group-name
9063              (cadr (assq action names))
9064              (symbol-value (intern (format "gnus-current-%s-group" action)))
9065              articles prefix))
9066       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9067     (setq to-method (or select-method
9068                         (gnus-server-to-method
9069                          (gnus-group-method to-newsgroup))))
9070     ;; Check the method we are to move this article to...
9071     (unless (gnus-check-backend-function
9072              'request-accept-article (car to-method))
9073       (error "%s does not support article copying" (car to-method)))
9074     (unless (gnus-check-server to-method)
9075       (error "Can't open server %s" (car to-method)))
9076     (gnus-message 6 "%s to %s: %s..."
9077                   (caddr (assq action names))
9078                   (or (car select-method) to-newsgroup) articles)
9079     (while articles
9080       (setq article (pop articles))
9081       (setq
9082        art-group
9083        (cond
9084         ;; Move the article.
9085         ((eq action 'move)
9086          ;; Remove this article from future suppression.
9087          (gnus-dup-unsuppress-article article)
9088          (gnus-request-move-article
9089           article                       ; Article to move
9090           gnus-newsgroup-name           ; From newsgroup
9091           (nth 1 (gnus-find-method-for-group
9092                   gnus-newsgroup-name)) ; Server
9093           (list 'gnus-request-accept-article
9094                 to-newsgroup (list 'quote select-method)
9095                 (not articles) t)       ; Accept form
9096           (not articles)))              ; Only save nov last time
9097         ;; Copy the article.
9098         ((eq action 'copy)
9099          (save-excursion
9100            (set-buffer copy-buf)
9101            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9102              (save-restriction
9103                (nnheader-narrow-to-headers)
9104                (dolist (hdr gnus-copy-article-ignored-headers)
9105                  (message-remove-header hdr t)))
9106              (gnus-request-accept-article
9107               to-newsgroup select-method (not articles) t))))
9108         ;; Crosspost the article.
9109         ((eq action 'crosspost)
9110          (let ((xref (message-tokenize-header
9111                       (mail-header-xref (gnus-summary-article-header article))
9112                       " ")))
9113            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9114                                   ":" (number-to-string article)))
9115            (unless xref
9116              (setq xref (list (system-name))))
9117            (setq new-xref
9118                  (concat
9119                   (mapconcat 'identity
9120                              (delete "Xref:" (delete new-xref xref))
9121                              " ")
9122                   " " new-xref))
9123            (save-excursion
9124              (set-buffer copy-buf)
9125              ;; First put the article in the destination group.
9126              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9127              (when (consp (setq art-group
9128                                 (gnus-request-accept-article
9129                                  to-newsgroup select-method (not articles))))
9130                (setq new-xref (concat new-xref " " (car art-group)
9131                                       ":"
9132                                       (number-to-string (cdr art-group))))
9133                ;; Now we have the new Xrefs header, so we insert
9134                ;; it and replace the new article.
9135                (nnheader-replace-header "Xref" new-xref)
9136                (gnus-request-replace-article
9137                 (cdr art-group) to-newsgroup (current-buffer))
9138                art-group))))))
9139       (cond
9140        ((not art-group)
9141         (gnus-message 1 "Couldn't %s article %s: %s"
9142                       (cadr (assq action names)) article
9143                       (nnheader-get-report (car to-method))))
9144        ((eq art-group 'junk)
9145         (when (eq action 'move)
9146           (gnus-summary-mark-article article gnus-canceled-mark)
9147           (gnus-message 4 "Deleted article %s" article)
9148           ;; run the delete hook
9149           (run-hook-with-args 'gnus-summary-article-delete-hook
9150                               action
9151                               (gnus-data-header
9152                                (assoc article (gnus-data-list nil)))
9153                               gnus-newsgroup-name nil
9154                               select-method)))
9155        (t
9156         (let* ((pto-group (gnus-group-prefixed-name
9157                            (car art-group) to-method))
9158                (info (gnus-get-info pto-group))
9159                (to-group (gnus-info-group info))
9160                to-marks)
9161           ;; Update the group that has been moved to.
9162           (when (and info
9163                      (memq action '(move copy)))
9164             (unless (member to-group to-groups)
9165               (push to-group to-groups))
9166
9167             (unless (memq article gnus-newsgroup-unreads)
9168               (push 'read to-marks)
9169               (gnus-info-set-read
9170                info (gnus-add-to-range (gnus-info-read info)
9171                                        (list (cdr art-group)))))
9172
9173             ;; See whether the article is to be put in the cache.
9174             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9175                              gnus-article-mark-lists
9176                            (delete '(expirable . expire)
9177                                    (copy-sequence gnus-article-mark-lists))))
9178                   (to-article (cdr art-group)))
9179
9180               ;; Enter the article into the cache in the new group,
9181               ;; if that is required.
9182               (when gnus-use-cache
9183                 (gnus-cache-possibly-enter-article
9184                  to-group to-article
9185                  (memq article gnus-newsgroup-marked)
9186                  (memq article gnus-newsgroup-dormant)
9187                  (memq article gnus-newsgroup-unreads)))
9188
9189               (when gnus-preserve-marks
9190                 ;; Copy any marks over to the new group.
9191                 (when (and (equal to-group gnus-newsgroup-name)
9192                            (not (memq article gnus-newsgroup-unreads)))
9193                   ;; Mark this article as read in this group.
9194                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9195                   (setcdr (gnus-active to-group) to-article)
9196                   (setcdr gnus-newsgroup-active to-article))
9197
9198                 (while marks
9199                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9200                     (when (memq article (symbol-value
9201                                          (intern (format "gnus-newsgroup-%s"
9202                                                          (caar marks)))))
9203                       (push (cdar marks) to-marks)
9204                       ;; If the other group is the same as this group,
9205                       ;; then we have to add the mark to the list.
9206                       (when (equal to-group gnus-newsgroup-name)
9207                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9208                              (cons to-article
9209                                    (symbol-value
9210                                     (intern (format "gnus-newsgroup-%s"
9211                                                     (caar marks)))))))
9212                       ;; Copy the marks to other group.
9213                       (gnus-add-marked-articles
9214                        to-group (cdar marks) (list to-article) info)))
9215                   (setq marks (cdr marks)))
9216
9217                 (gnus-request-set-mark
9218                  to-group (list (list (list to-article) 'add to-marks))))
9219
9220               (gnus-dribble-enter
9221                (concat "(gnus-group-set-info '"
9222                        (gnus-prin1-to-string (gnus-get-info to-group))
9223                        ")"))))
9224
9225           ;; Update the Xref header in this article to point to
9226           ;; the new crossposted article we have just created.
9227           (when (eq action 'crosspost)
9228             (save-excursion
9229               (set-buffer copy-buf)
9230               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9231               (nnheader-replace-header "Xref" new-xref)
9232               (gnus-request-replace-article
9233                article gnus-newsgroup-name (current-buffer))))
9234
9235           ;; run the move/copy/crosspost/respool hook
9236           (run-hook-with-args 'gnus-summary-article-move-hook
9237                               action
9238                               (gnus-data-header
9239                                (assoc article (gnus-data-list nil)))
9240                               gnus-newsgroup-name
9241                               to-newsgroup
9242                               select-method))
9243
9244         ;;;!!!Why is this necessary?
9245         (set-buffer gnus-summary-buffer)
9246         
9247         (gnus-summary-goto-subject article)
9248         (when (eq action 'move)
9249           (gnus-summary-mark-article article gnus-canceled-mark))))
9250       (gnus-summary-remove-process-mark article))
9251     ;; Re-activate all groups that have been moved to.
9252     (save-excursion
9253       (set-buffer gnus-group-buffer)
9254       (let ((gnus-group-marked to-groups))
9255         (gnus-group-get-new-news-this-group nil t)))
9256
9257     (gnus-kill-buffer copy-buf)
9258     (gnus-summary-position-point)
9259     (gnus-set-mode-line 'summary)))
9260
9261 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9262   "Copy the current article to some other group.
9263 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9264 When called interactively, if TO-NEWSGROUP is nil, use the value of
9265 the variable `gnus-move-split-methods' for finding a default target
9266 newsgroup.
9267 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9268 re-spool using this method."
9269   (interactive "P")
9270   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9271
9272 (defun gnus-summary-crosspost-article (&optional n)
9273   "Crosspost the current article to some other group."
9274   (interactive "P")
9275   (gnus-summary-move-article n nil nil 'crosspost))
9276
9277 (defcustom gnus-summary-respool-default-method nil
9278   "Default method type for respooling an article.
9279 If nil, use to the current newsgroup method."
9280   :type 'symbol
9281   :group 'gnus-summary-mail)
9282
9283 (defcustom gnus-summary-display-while-building nil
9284   "If non-nil, show and update the summary buffer as it's being built.
9285 If the value is t, update the buffer after every line is inserted.  If
9286 the value is an integer (N), update the display every N lines."
9287   :version "21.4"
9288   :group 'gnus-thread
9289   :type '(choice (const :tag "off" nil)
9290                  number
9291                  (const :tag "frequently" t)))
9292
9293 (defun gnus-summary-respool-article (&optional n method)
9294   "Respool the current article.
9295 The article will be squeezed through the mail spooling process again,
9296 which means that it will be put in some mail newsgroup or other
9297 depending on `nnmail-split-methods'.
9298 If N is a positive number, respool the N next articles.
9299 If N is a negative number, respool the N previous articles.
9300 If N is nil and any articles have been marked with the process mark,
9301 respool those articles instead.
9302
9303 Respooling can be done both from mail groups and \"real\" newsgroups.
9304 In the former case, the articles in question will be moved from the
9305 current group into whatever groups they are destined to.  In the
9306 latter case, they will be copied into the relevant groups."
9307   (interactive
9308    (list current-prefix-arg
9309          (let* ((methods (gnus-methods-using 'respool))
9310                 (methname
9311                  (symbol-name (or gnus-summary-respool-default-method
9312                                   (car (gnus-find-method-for-group
9313                                         gnus-newsgroup-name)))))
9314                 (method
9315                  (gnus-completing-read-with-default
9316                   methname "What backend do you want to use when respooling?"
9317                   methods nil t nil 'gnus-mail-method-history))
9318                 ms)
9319            (cond
9320             ((zerop (length (setq ms (gnus-servers-using-backend
9321                                       (intern method)))))
9322              (list (intern method) ""))
9323             ((= 1 (length ms))
9324              (car ms))
9325             (t
9326              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9327                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9328                            ms-alist))))))))
9329   (unless method
9330     (error "No method given for respooling"))
9331   (if (assoc (symbol-name
9332               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9333              (gnus-methods-using 'respool))
9334       (gnus-summary-move-article n nil method)
9335     (gnus-summary-copy-article n nil method)))
9336
9337 (defun gnus-summary-import-article (file &optional edit)
9338   "Import an arbitrary file into a mail newsgroup."
9339   (interactive "fImport file: \nP")
9340   (let ((group gnus-newsgroup-name)
9341         (now (current-time))
9342         atts lines group-art)
9343     (unless (gnus-check-backend-function 'request-accept-article group)
9344       (error "%s does not support article importing" group))
9345     (or (file-readable-p file)
9346         (not (file-regular-p file))
9347         (error "Can't read %s" file))
9348     (save-excursion
9349       (set-buffer (gnus-get-buffer-create " *import file*"))
9350       (erase-buffer)
9351       (nnheader-insert-file-contents file)
9352       (goto-char (point-min))
9353       (if (nnheader-article-p)
9354           (save-restriction
9355             (goto-char (point-min))
9356             (search-forward "\n\n" nil t)
9357             (narrow-to-region (point-min) (1- (point)))
9358             (goto-char (point-min))
9359             (unless (re-search-forward "^date:" nil t)
9360               (goto-char (point-max))
9361               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9362        ;; This doesn't look like an article, so we fudge some headers.
9363         (setq atts (file-attributes file)
9364               lines (count-lines (point-min) (point-max)))
9365         (insert "From: " (read-string "From: ") "\n"
9366                 "Subject: " (read-string "Subject: ") "\n"
9367                 "Date: " (message-make-date (nth 5 atts)) "\n"
9368                 "Message-ID: " (message-make-message-id) "\n"
9369                 "Lines: " (int-to-string lines) "\n"
9370                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9371       (setq group-art (gnus-request-accept-article group nil t))
9372       (kill-buffer (current-buffer)))
9373     (setq gnus-newsgroup-active (gnus-activate-group group))
9374     (forward-line 1)
9375     (gnus-summary-goto-article (cdr group-art) nil t)
9376     (when edit
9377       (gnus-summary-edit-article))))
9378
9379 (defun gnus-summary-create-article ()
9380   "Create an article in a mail newsgroup."
9381   (interactive)
9382   (let ((group gnus-newsgroup-name)
9383         (now (current-time))
9384         group-art)
9385     (unless (gnus-check-backend-function 'request-accept-article group)
9386       (error "%s does not support article importing" group))
9387     (save-excursion
9388       (set-buffer (gnus-get-buffer-create " *import file*"))
9389       (erase-buffer)
9390       (goto-char (point-min))
9391       ;; This doesn't look like an article, so we fudge some headers.
9392       (insert "From: " (read-string "From: ") "\n"
9393               "Subject: " (read-string "Subject: ") "\n"
9394               "Date: " (message-make-date now) "\n"
9395               "Message-ID: " (message-make-message-id) "\n")
9396       (setq group-art (gnus-request-accept-article group nil t))
9397       (kill-buffer (current-buffer)))
9398     (setq gnus-newsgroup-active (gnus-activate-group group))
9399     (forward-line 1)
9400     (gnus-summary-goto-article (cdr group-art) nil t)
9401     (gnus-summary-edit-article)))
9402
9403 (defun gnus-summary-article-posted-p ()
9404   "Say whether the current (mail) article is available from news as well.
9405 This will be the case if the article has both been mailed and posted."
9406   (interactive)
9407   (let ((id (mail-header-references (gnus-summary-article-header)))
9408         (gnus-override-method (car (gnus-refer-article-methods))))
9409     (if (gnus-request-head id "")
9410         (gnus-message 2 "The current message was found on %s"
9411                       gnus-override-method)
9412       (gnus-message 2 "The current message couldn't be found on %s"
9413                     gnus-override-method)
9414       nil)))
9415
9416 (defun gnus-summary-expire-articles (&optional now)
9417   "Expire all articles that are marked as expirable in the current group."
9418   (interactive)
9419   (when (and (not gnus-group-is-exiting-without-update-p)
9420              (gnus-check-backend-function
9421               'request-expire-articles gnus-newsgroup-name))
9422     ;; This backend supports expiry.
9423     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9424            (expirable (if total
9425                           (progn
9426                             ;; We need to update the info for
9427                             ;; this group for `gnus-list-of-read-articles'
9428                             ;; to give us the right answer.
9429                             (gnus-run-hooks 'gnus-exit-group-hook)
9430                             (gnus-summary-update-info)
9431                             (gnus-list-of-read-articles gnus-newsgroup-name))
9432                         (setq gnus-newsgroup-expirable
9433                               (sort gnus-newsgroup-expirable '<))))
9434            (expiry-wait (if now 'immediate
9435                           (gnus-group-find-parameter
9436                            gnus-newsgroup-name 'expiry-wait)))
9437            (nnmail-expiry-target
9438             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9439                 nnmail-expiry-target))
9440            es)
9441       (when expirable
9442         ;; There are expirable articles in this group, so we run them
9443         ;; through the expiry process.
9444         (gnus-message 6 "Expiring articles...")
9445         (unless (gnus-check-group gnus-newsgroup-name)
9446           (error "Can't open server for %s" gnus-newsgroup-name))
9447         ;; The list of articles that weren't expired is returned.
9448         (save-excursion
9449           (if expiry-wait
9450               (let ((nnmail-expiry-wait-function nil)
9451                     (nnmail-expiry-wait expiry-wait))
9452                 (setq es (gnus-request-expire-articles
9453                           expirable gnus-newsgroup-name)))
9454             (setq es (gnus-request-expire-articles
9455                       expirable gnus-newsgroup-name)))
9456           (unless total
9457             (setq gnus-newsgroup-expirable es))
9458           ;; We go through the old list of expirable, and mark all
9459           ;; really expired articles as nonexistent.
9460           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9461             (let ((gnus-use-cache nil))
9462               (dolist (article expirable)
9463                 (when (and (not (memq article es))
9464                            (gnus-data-find article))
9465                   (gnus-summary-mark-article article gnus-canceled-mark)
9466                   (run-hook-with-args 'gnus-summary-article-expire-hook
9467                                       'delete
9468                                       (gnus-data-header
9469                                        (assoc article (gnus-data-list nil)))
9470                                       gnus-newsgroup-name
9471                                       nil
9472                                       nil))))))
9473         (gnus-message 6 "Expiring articles...done")))))
9474
9475 (defun gnus-summary-expire-articles-now ()
9476   "Expunge all expirable articles in the current group.
9477 This means that *all* articles that are marked as expirable will be
9478 deleted forever, right now."
9479   (interactive)
9480   (or gnus-expert-user
9481       (gnus-yes-or-no-p
9482        "Are you really, really, really sure you want to delete all these messages? ")
9483       (error "Phew!"))
9484   (gnus-summary-expire-articles t))
9485
9486 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9487 (defun gnus-summary-delete-article (&optional n)
9488   "Delete the N next (mail) articles.
9489 This command actually deletes articles.  This is not a marking
9490 command.  The article will disappear forever from your life, never to
9491 return.
9492
9493 If N is negative, delete backwards.
9494 If N is nil and articles have been marked with the process mark,
9495 delete these instead.
9496
9497 If `gnus-novice-user' is non-nil you will be asked for
9498 confirmation before the articles are deleted."
9499   (interactive "P")
9500   (unless (gnus-check-backend-function 'request-expire-articles
9501                                        gnus-newsgroup-name)
9502     (error "The current newsgroup does not support article deletion"))
9503   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9504     (error "Couldn't open server"))
9505   ;; Compute the list of articles to delete.
9506   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9507         (nnmail-expiry-target 'delete)
9508         not-deleted)
9509     (if (and gnus-novice-user
9510              (not (gnus-yes-or-no-p
9511                    (format "Do you really want to delete %s forever? "
9512                            (if (> (length articles) 1)
9513                                (format "these %s articles" (length articles))
9514                              "this article")))))
9515         ()
9516       ;; Delete the articles.
9517       (setq not-deleted (gnus-request-expire-articles
9518                          articles gnus-newsgroup-name 'force))
9519       (while articles
9520         (gnus-summary-remove-process-mark (car articles))
9521         ;; The backend might not have been able to delete the article
9522         ;; after all.
9523         (unless (memq (car articles) not-deleted)
9524           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9525         (let* ((article (car articles))
9526                (ghead  (gnus-data-header
9527                                     (assoc article (gnus-data-list nil)))))
9528           (run-hook-with-args 'gnus-summary-article-delete-hook
9529                               'delete ghead gnus-newsgroup-name nil
9530                               nil))
9531         (setq articles (cdr articles)))
9532       (when not-deleted
9533         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9534     (gnus-summary-position-point)
9535     (gnus-set-mode-line 'summary)
9536     not-deleted))
9537
9538 (defun gnus-summary-edit-article (&optional arg)
9539   "Edit the current article.
9540 This will have permanent effect only in mail groups.
9541 If ARG is nil, edit the decoded articles.
9542 If ARG is 1, edit the raw articles.
9543 If ARG is 2, edit the raw articles even in read-only groups.
9544 If ARG is 3, edit the articles with the current handles.
9545 Otherwise, allow editing of articles even in read-only
9546 groups."
9547   (interactive "P")
9548   (let (force raw current-handles)
9549     (cond
9550      ((null arg))
9551      ((eq arg 1)
9552       (setq raw t))
9553      ((eq arg 2)
9554       (setq raw t
9555             force t))
9556      ((eq arg 3)
9557       (setq current-handles
9558             (and (gnus-buffer-live-p gnus-article-buffer)
9559                  (with-current-buffer gnus-article-buffer
9560                    (prog1
9561                        gnus-article-mime-handles
9562                      (setq gnus-article-mime-handles nil))))))
9563      (t
9564       (setq force t)))
9565     (when (and raw (not force)
9566                (member gnus-newsgroup-name '("nndraft:delayed"
9567                                              "nndraft:drafts"
9568                                              "nndraft:queue")))
9569       (error "Can't edit the raw article in group %s"
9570              gnus-newsgroup-name))
9571     (save-excursion
9572       (set-buffer gnus-summary-buffer)
9573       (let ((mail-parse-charset gnus-newsgroup-charset)
9574             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9575         (gnus-set-global-variables)
9576         (when (and (not force)
9577                    (gnus-group-read-only-p))
9578           (error "The current newsgroup does not support article editing"))
9579         (gnus-summary-show-article t)
9580         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9581           (with-current-buffer gnus-article-buffer
9582             (mm-enable-multibyte)))
9583         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9584             (setq raw t))
9585         (gnus-article-edit-article
9586          (if raw 'ignore
9587            `(lambda ()
9588               (let ((mbl mml-buffer-list))
9589                 (setq mml-buffer-list nil)
9590                 (mime-to-mml ,'current-handles)
9591                 (let ((mbl1 mml-buffer-list))
9592                   (setq mml-buffer-list mbl)
9593                   (set (make-local-variable 'mml-buffer-list) mbl1))
9594                 (gnus-make-local-hook 'kill-buffer-hook)
9595                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9596          `(lambda (no-highlight)
9597             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9598                   (message-options message-options)
9599                   (message-options-set-recipient)
9600                   (mail-parse-ignored-charsets
9601                    ',gnus-newsgroup-ignored-charsets))
9602               ,(if (not raw) '(progn
9603                                 (mml-to-mime)
9604                                 (mml-destroy-buffers)
9605                                 (remove-hook 'kill-buffer-hook
9606                                              'mml-destroy-buffers t)
9607                                 (kill-local-variable 'mml-buffer-list)))
9608               (gnus-summary-edit-article-done
9609                ,(or (mail-header-references gnus-current-headers) "")
9610                ,(gnus-group-read-only-p)
9611                ,gnus-summary-buffer no-highlight))))))))
9612
9613 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9614
9615 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9616                                                  no-highlight)
9617   "Make edits to the current article permanent."
9618   (interactive)
9619   (save-excursion
9620    ;; The buffer restriction contains the entire article if it exists.
9621     (when (article-goto-body)
9622       (let ((lines (count-lines (point) (point-max)))
9623             (length (- (point-max) (point)))
9624             (case-fold-search t)
9625             (body (copy-marker (point))))
9626         (goto-char (point-min))
9627         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9628           (delete-region (match-beginning 1) (match-end 1))
9629           (insert (number-to-string length)))
9630         (goto-char (point-min))
9631         (when (re-search-forward
9632                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9633           (delete-region (match-beginning 1) (match-end 1))
9634           (insert (number-to-string length)))
9635         (goto-char (point-min))
9636         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9637           (delete-region (match-beginning 1) (match-end 1))
9638           (insert (number-to-string lines))))))
9639   ;; Replace the article.
9640   (let ((buf (current-buffer)))
9641     (with-temp-buffer
9642       (insert-buffer-substring buf)
9643
9644       (if (and (not read-only)
9645                (not (gnus-request-replace-article
9646                      (cdr gnus-article-current) (car gnus-article-current)
9647                      (current-buffer) t)))
9648           (error "Couldn't replace article")
9649         ;; Update the summary buffer.
9650         (if (and references
9651                  (equal (message-tokenize-header references " ")
9652                         (message-tokenize-header
9653                          (or (message-fetch-field "references") "") " ")))
9654             ;; We only have to update this line.
9655             (save-excursion
9656               (save-restriction
9657                 (message-narrow-to-head)
9658                 (let ((head (buffer-string))
9659                       header)
9660                   (with-temp-buffer
9661                     (insert (format "211 %d Article retrieved.\n"
9662                                     (cdr gnus-article-current)))
9663                     (insert head)
9664                     (insert ".\n")
9665                     (let ((nntp-server-buffer (current-buffer)))
9666                       (setq header (car (gnus-get-newsgroup-headers
9667                                          nil t))))
9668                     (save-excursion
9669                       (set-buffer gnus-summary-buffer)
9670                       (gnus-data-set-header
9671                        (gnus-data-find (cdr gnus-article-current))
9672                        header)
9673                       (gnus-summary-update-article-line
9674                        (cdr gnus-article-current) header)
9675                       (if (gnus-summary-goto-subject
9676                            (cdr gnus-article-current) nil t)
9677                           (gnus-summary-update-secondary-mark
9678                            (cdr gnus-article-current))))))))
9679           ;; Update threads.
9680           (set-buffer (or buffer gnus-summary-buffer))
9681           (gnus-summary-update-article (cdr gnus-article-current))
9682           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9683               (gnus-summary-update-secondary-mark
9684                (cdr gnus-article-current))))
9685         ;; Prettify the article buffer again.
9686         (unless no-highlight
9687           (save-excursion
9688             (set-buffer gnus-article-buffer)
9689             ;;;!!! Fix this -- article should be rehighlighted.
9690             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9691             (set-buffer gnus-original-article-buffer)
9692             (gnus-request-article
9693              (cdr gnus-article-current)
9694              (car gnus-article-current) (current-buffer))))
9695         ;; Prettify the summary buffer line.
9696         (when (gnus-visual-p 'summary-highlight 'highlight)
9697           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9698
9699 (defun gnus-summary-edit-wash (key)
9700   "Perform editing command KEY in the article buffer."
9701   (interactive
9702    (list
9703     (progn
9704       (message "%s" (concat (this-command-keys) "- "))
9705       (read-char))))
9706   (message "")
9707   (gnus-summary-edit-article)
9708   (execute-kbd-macro (concat (this-command-keys) key))
9709   (gnus-article-edit-done))
9710
9711 ;;; Respooling
9712
9713 (defun gnus-summary-respool-query (&optional silent trace)
9714   "Query where the respool algorithm would put this article."
9715   (interactive)
9716   (let (gnus-mark-article-hook)
9717     (gnus-summary-select-article)
9718     (save-excursion
9719       (set-buffer gnus-original-article-buffer)
9720       (let ((groups (nnmail-article-group 'identity trace)))
9721         (unless silent
9722           (if groups
9723               (message "This message would go to %s"
9724                        (mapconcat 'car groups ", "))
9725             (message "This message would go to no groups"))
9726           groups)))))
9727
9728 (defun gnus-summary-respool-trace ()
9729   "Trace where the respool algorithm would put this article.
9730 Display a buffer showing all fancy splitting patterns which matched."
9731   (interactive)
9732   (gnus-summary-respool-query nil t))
9733
9734 ;; Summary marking commands.
9735
9736 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9737   "Mark articles which has the same subject as read, and then select the next.
9738 If UNMARK is positive, remove any kind of mark.
9739 If UNMARK is negative, tick articles."
9740   (interactive "P")
9741   (when unmark
9742     (setq unmark (prefix-numeric-value unmark)))
9743   (let ((count
9744          (gnus-summary-mark-same-subject
9745           (gnus-summary-article-subject) unmark)))
9746     ;; Select next unread article.  If auto-select-same mode, should
9747     ;; select the first unread article.
9748     (gnus-summary-next-article t (and gnus-auto-select-same
9749                                       (gnus-summary-article-subject)))
9750     (gnus-message 7 "%d article%s marked as %s"
9751                   count (if (= count 1) " is" "s are")
9752                   (if unmark "unread" "read"))))
9753
9754 (defun gnus-summary-kill-same-subject (&optional unmark)
9755   "Mark articles which has the same subject as read.
9756 If UNMARK is positive, remove any kind of mark.
9757 If UNMARK is negative, tick articles."
9758   (interactive "P")
9759   (when unmark
9760     (setq unmark (prefix-numeric-value unmark)))
9761   (let ((count
9762          (gnus-summary-mark-same-subject
9763           (gnus-summary-article-subject) unmark)))
9764     ;; If marked as read, go to next unread subject.
9765     (when (null unmark)
9766       ;; Go to next unread subject.
9767       (gnus-summary-next-subject 1 t))
9768     (gnus-message 7 "%d articles are marked as %s"
9769                   count (if unmark "unread" "read"))))
9770
9771 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9772   "Mark articles with same SUBJECT as read, and return marked number.
9773 If optional argument UNMARK is positive, remove any kinds of marks.
9774 If optional argument UNMARK is negative, mark articles as unread instead."
9775   (let ((count 1))
9776     (save-excursion
9777       (cond
9778        ((null unmark)                   ; Mark as read.
9779         (while (and
9780                 (progn
9781                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9782                   (gnus-summary-show-thread) t)
9783                 (gnus-summary-find-subject subject))
9784           (setq count (1+ count))))
9785        ((> unmark 0)                    ; Tick.
9786         (while (and
9787                 (progn
9788                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9789                   (gnus-summary-show-thread) t)
9790                 (gnus-summary-find-subject subject))
9791           (setq count (1+ count))))
9792        (t                               ; Mark as unread.
9793         (while (and
9794                 (progn
9795                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9796                   (gnus-summary-show-thread) t)
9797                 (gnus-summary-find-subject subject))
9798           (setq count (1+ count)))))
9799       (gnus-set-mode-line 'summary)
9800       ;; Return the number of marked articles.
9801       count)))
9802
9803 (defun gnus-summary-mark-as-processable (n &optional unmark)
9804   "Set the process mark on the next N articles.
9805 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9806 the process mark instead.  The difference between N and the actual
9807 number of articles marked is returned."
9808   (interactive "P")
9809   (if (and (null n) (gnus-region-active-p))
9810       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9811     (setq n (prefix-numeric-value n))
9812     (let ((backward (< n 0))
9813           (n (abs n)))
9814       (while (and
9815               (> n 0)
9816               (if unmark
9817                   (gnus-summary-remove-process-mark
9818                    (gnus-summary-article-number))
9819                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9820               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9821         (setq n (1- n)))
9822       (when (/= 0 n)
9823         (gnus-message 7 "No more articles"))
9824       (gnus-summary-recenter)
9825       (gnus-summary-position-point)
9826       n)))
9827
9828 (defun gnus-summary-unmark-as-processable (n)
9829   "Remove the process mark from the next N articles.
9830 If N is negative, unmark backward instead.  The difference between N and
9831 the actual number of articles unmarked is returned."
9832   (interactive "P")
9833   (gnus-summary-mark-as-processable n t))
9834
9835 (defun gnus-summary-unmark-all-processable ()
9836   "Remove the process mark from all articles."
9837   (interactive)
9838   (save-excursion
9839     (while gnus-newsgroup-processable
9840       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9841   (gnus-summary-position-point))
9842
9843 (defun gnus-summary-add-mark (article type)
9844   "Mark ARTICLE with a mark of TYPE."
9845   (let ((vtype (car (assq type gnus-article-mark-lists)))
9846         var)
9847     (if (not vtype)
9848         (error "No such mark type: %s" type)
9849       (setq var (intern (format "gnus-newsgroup-%s" type)))
9850       (set var (cons article (symbol-value var)))
9851       (if (memq type '(processable cached replied forwarded recent saved))
9852           (gnus-summary-update-secondary-mark article)
9853         ;;; !!! This is bogus.  We should find out what primary
9854         ;;; !!! mark we want to set.
9855         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9856
9857 (defun gnus-summary-mark-as-expirable (n)
9858   "Mark N articles forward as expirable.
9859 If N is negative, mark backward instead.  The difference between N and
9860 the actual number of articles marked is returned."
9861   (interactive "p")
9862   (gnus-summary-mark-forward n gnus-expirable-mark))
9863
9864 (defun gnus-summary-mark-as-spam (n)
9865   "Mark N articles forward as spam.
9866 If N is negative, mark backward instead.  The difference between N and
9867 the actual number of articles marked is returned."
9868   (interactive "p")
9869   (gnus-summary-mark-forward n gnus-spam-mark))
9870
9871 (defun gnus-summary-mark-article-as-replied (article)
9872   "Mark ARTICLE as replied to and update the summary line.
9873 ARTICLE can also be a list of articles."
9874   (interactive (list (gnus-summary-article-number)))
9875   (let ((articles (if (listp article) article (list article))))
9876     (dolist (article articles)
9877       (unless (numberp article)
9878         (error "%s is not a number" article))
9879       (push article gnus-newsgroup-replied)
9880       (let ((buffer-read-only nil))
9881         (when (gnus-summary-goto-subject article nil t)
9882           (gnus-summary-update-secondary-mark article))))))
9883
9884 (defun gnus-summary-mark-article-as-forwarded (article)
9885   "Mark ARTICLE as forwarded and update the summary line.
9886 ARTICLE can also be a list of articles."
9887   (let ((articles (if (listp article) article (list article))))
9888     (dolist (article articles)
9889       (push article gnus-newsgroup-forwarded)
9890       (let ((buffer-read-only nil))
9891         (when (gnus-summary-goto-subject article nil t)
9892           (gnus-summary-update-secondary-mark article))))))
9893
9894 (defun gnus-summary-set-bookmark (article)
9895   "Set a bookmark in current article."
9896   (interactive (list (gnus-summary-article-number)))
9897   (when (or (not (get-buffer gnus-article-buffer))
9898             (not gnus-current-article)
9899             (not gnus-article-current)
9900             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9901     (error "No current article selected"))
9902   ;; Remove old bookmark, if one exists.
9903   (gnus-pull article gnus-newsgroup-bookmarks)
9904   ;; Set the new bookmark, which is on the form
9905   ;; (article-number . line-number-in-body).
9906   (push
9907    (cons article
9908          (with-current-buffer gnus-article-buffer
9909            (count-lines
9910             (min (point)
9911                  (save-excursion
9912                    (article-goto-body)
9913                    (point)))
9914             (point))))
9915    gnus-newsgroup-bookmarks)
9916   (gnus-message 6 "A bookmark has been added to the current article."))
9917
9918 (defun gnus-summary-remove-bookmark (article)
9919   "Remove the bookmark from the current article."
9920   (interactive (list (gnus-summary-article-number)))
9921   ;; Remove old bookmark, if one exists.
9922   (if (not (assq article gnus-newsgroup-bookmarks))
9923       (gnus-message 6 "No bookmark in current article.")
9924     (gnus-pull article gnus-newsgroup-bookmarks)
9925     (gnus-message 6 "Removed bookmark.")))
9926
9927 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9928 (defun gnus-summary-mark-as-dormant (n)
9929   "Mark N articles forward as dormant.
9930 If N is negative, mark backward instead.  The difference between N and
9931 the actual number of articles marked is returned."
9932   (interactive "p")
9933   (gnus-summary-mark-forward n gnus-dormant-mark))
9934
9935 (defun gnus-summary-set-process-mark (article)
9936   "Set the process mark on ARTICLE and update the summary line."
9937   (setq gnus-newsgroup-processable
9938         (cons article
9939               (delq article gnus-newsgroup-processable)))
9940   (when (gnus-summary-goto-subject article)
9941     (gnus-summary-show-thread)
9942     (gnus-summary-goto-subject article)
9943     (gnus-summary-update-secondary-mark article)))
9944
9945 (defun gnus-summary-remove-process-mark (article)
9946   "Remove the process mark from ARTICLE and update the summary line."
9947   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9948   (when (gnus-summary-goto-subject article)
9949     (gnus-summary-show-thread)
9950     (gnus-summary-goto-subject article)
9951     (gnus-summary-update-secondary-mark article)))
9952
9953 (defun gnus-summary-set-saved-mark (article)
9954   "Set the process mark on ARTICLE and update the summary line."
9955   (push article gnus-newsgroup-saved)
9956   (when (gnus-summary-goto-subject article)
9957     (gnus-summary-update-secondary-mark article)))
9958
9959 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9960   "Mark N articles as read forwards.
9961 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9962 The difference between N and the actual number of articles marked is
9963 returned.
9964 If NO-EXPIRE, auto-expiry will be inhibited."
9965   (interactive "p")
9966   (gnus-summary-show-thread)
9967   (let ((backward (< n 0))
9968         (gnus-summary-goto-unread
9969          (and gnus-summary-goto-unread
9970               (not (eq gnus-summary-goto-unread 'never))
9971               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9972                                     gnus-ticked-mark gnus-dormant-mark)))))
9973         (n (abs n))
9974         (mark (or mark gnus-del-mark)))
9975     (while (and (> n 0)
9976                 (gnus-summary-mark-article nil mark no-expire)
9977                 (zerop (gnus-summary-next-subject
9978                         (if backward -1 1)
9979                         (and gnus-summary-goto-unread
9980                              (not (eq gnus-summary-goto-unread 'never)))
9981                         t)))
9982       (setq n (1- n)))
9983     (when (/= 0 n)
9984       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9985     (gnus-summary-recenter)
9986     (gnus-summary-position-point)
9987     (gnus-set-mode-line 'summary)
9988     n))
9989
9990 (defun gnus-summary-mark-article-as-read (mark)
9991   "Mark the current article quickly as read with MARK."
9992   (let ((article (gnus-summary-article-number)))
9993     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9994     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9995     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9996     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9997     (push (cons article mark) gnus-newsgroup-reads)
9998     ;; Possibly remove from cache, if that is used.
9999     (when gnus-use-cache
10000       (gnus-cache-enter-remove-article article))
10001     ;; Allow the backend to change the mark.
10002     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10003     ;; Check for auto-expiry.
10004     (when (and gnus-newsgroup-auto-expire
10005                (memq mark gnus-auto-expirable-marks))
10006       (setq mark gnus-expirable-mark)
10007       ;; Let the backend know about the mark change.
10008       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10009       (push article gnus-newsgroup-expirable))
10010     ;; Set the mark in the buffer.
10011     (gnus-summary-update-mark mark 'unread)
10012     t))
10013
10014 (defun gnus-summary-mark-article-as-unread (mark)
10015   "Mark the current article quickly as unread with MARK."
10016   (let* ((article (gnus-summary-article-number))
10017          (old-mark (gnus-summary-article-mark article)))
10018     ;; Allow the backend to change the mark.
10019     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10020     (if (eq mark old-mark)
10021         t
10022       (if (<= article 0)
10023           (progn
10024             (gnus-error 1 "Can't mark negative article numbers")
10025             nil)
10026         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10027         (setq gnus-newsgroup-spam-marked
10028               (delq article gnus-newsgroup-spam-marked))
10029         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10030         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10031         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10032         (cond ((= mark gnus-ticked-mark)
10033                (setq gnus-newsgroup-marked
10034                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10035                                               article)))
10036               ((= mark gnus-spam-mark)
10037                (setq gnus-newsgroup-spam-marked
10038                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10039                                               article)))
10040               ((= mark gnus-dormant-mark)
10041                (setq gnus-newsgroup-dormant
10042                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10043                                               article)))
10044               (t
10045                (setq gnus-newsgroup-unreads
10046                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10047                                               article))))
10048         (gnus-pull article gnus-newsgroup-reads)
10049
10050         ;; See whether the article is to be put in the cache.
10051         (and gnus-use-cache
10052              (vectorp (gnus-summary-article-header article))
10053              (save-excursion
10054                (gnus-cache-possibly-enter-article
10055                 gnus-newsgroup-name article
10056                 (= mark gnus-ticked-mark)
10057                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10058
10059         ;; Fix the mark.
10060         (gnus-summary-update-mark mark 'unread)
10061         t))))
10062
10063 (defun gnus-summary-mark-article (&optional article mark no-expire)
10064   "Mark ARTICLE with MARK.  MARK can be any character.
10065 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10066 `??' (dormant) and `?E' (expirable).
10067 If MARK is nil, then the default character `?r' is used.
10068 If ARTICLE is nil, then the article on the current line will be
10069 marked.
10070 If NO-EXPIRE, auto-expiry will be inhibited."
10071   ;; The mark might be a string.
10072   (when (stringp mark)
10073     (setq mark (aref mark 0)))
10074   ;; If no mark is given, then we check auto-expiring.
10075   (when (null mark)
10076     (setq mark gnus-del-mark))
10077   (when (and (not no-expire)
10078              gnus-newsgroup-auto-expire
10079              (memq mark gnus-auto-expirable-marks))
10080     (setq mark gnus-expirable-mark))
10081   (let ((article (or article (gnus-summary-article-number)))
10082         (old-mark (gnus-summary-article-mark article)))
10083     ;; Allow the backend to change the mark.
10084     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10085     (if (eq mark old-mark)
10086         t
10087       (unless article
10088         (error "No article on current line"))
10089       (if (not (if (or (= mark gnus-unread-mark)
10090                        (= mark gnus-ticked-mark)
10091                        (= mark gnus-spam-mark)
10092                        (= mark gnus-dormant-mark))
10093                    (gnus-mark-article-as-unread article mark)
10094                  (gnus-mark-article-as-read article mark)))
10095           t
10096         ;; See whether the article is to be put in the cache.
10097         (and gnus-use-cache
10098              (not (= mark gnus-canceled-mark))
10099              (vectorp (gnus-summary-article-header article))
10100              (save-excursion
10101                (gnus-cache-possibly-enter-article
10102                 gnus-newsgroup-name article
10103                 (= mark gnus-ticked-mark)
10104                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10105
10106         (when (gnus-summary-goto-subject article nil t)
10107           (let ((buffer-read-only nil))
10108             (gnus-summary-show-thread)
10109             ;; Fix the mark.
10110             (gnus-summary-update-mark mark 'unread)
10111             t))))))
10112
10113 (defun gnus-summary-update-secondary-mark (article)
10114   "Update the secondary (read, process, cache) mark."
10115   (gnus-summary-update-mark
10116    (cond ((memq article gnus-newsgroup-processable)
10117           gnus-process-mark)
10118          ((memq article gnus-newsgroup-cached)
10119           gnus-cached-mark)
10120          ((memq article gnus-newsgroup-replied)
10121           gnus-replied-mark)
10122          ((memq article gnus-newsgroup-forwarded)
10123           gnus-forwarded-mark)
10124          ((memq article gnus-newsgroup-saved)
10125           gnus-saved-mark)
10126          ((memq article gnus-newsgroup-recent)
10127           gnus-recent-mark)
10128          ((memq article gnus-newsgroup-unseen)
10129           gnus-unseen-mark)
10130          (t gnus-no-mark))
10131    'replied)
10132   (when (gnus-visual-p 'summary-highlight 'highlight)
10133     (gnus-run-hooks 'gnus-summary-update-hook))
10134   t)
10135
10136 (defun gnus-summary-update-download-mark (article)
10137   "Update the download mark."
10138   (gnus-summary-update-mark
10139    (cond ((memq article gnus-newsgroup-undownloaded)
10140           gnus-undownloaded-mark)
10141          (gnus-newsgroup-agentized
10142           gnus-downloaded-mark)
10143          (t
10144           gnus-no-mark))
10145    'download)
10146   (gnus-summary-update-line t)
10147   t)
10148
10149 (defun gnus-summary-update-mark (mark type)
10150   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10151         (buffer-read-only nil))
10152     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10153     (when forward
10154       (when (looking-at "\r")
10155         (incf forward))
10156       (when (<= (+ forward (point)) (point-max))
10157         ;; Go to the right position on the line.
10158         (goto-char (+ forward (point)))
10159         ;; Replace the old mark with the new mark.
10160         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10161         ;; Optionally update the marks by some user rule.
10162         (when (eq type 'unread)
10163           (gnus-data-set-mark
10164            (gnus-data-find (gnus-summary-article-number)) mark)
10165           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10166
10167 (defun gnus-mark-article-as-read (article &optional mark)
10168   "Enter ARTICLE in the pertinent lists and remove it from others."
10169   ;; Make the article expirable.
10170   (let ((mark (or mark gnus-del-mark)))
10171     (setq gnus-newsgroup-expirable
10172           (if (= mark gnus-expirable-mark)
10173               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10174             (delq article gnus-newsgroup-expirable)))
10175     ;; Remove from unread and marked lists.
10176     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10177     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10178     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10179     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10180     (push (cons article mark) gnus-newsgroup-reads)
10181     ;; Possibly remove from cache, if that is used.
10182     (when gnus-use-cache
10183       (gnus-cache-enter-remove-article article))
10184     t))
10185
10186 (defun gnus-mark-article-as-unread (article &optional mark)
10187   "Enter ARTICLE in the pertinent lists and remove it from others."
10188   (let ((mark (or mark gnus-ticked-mark)))
10189     (if (<= article 0)
10190         (progn
10191           (gnus-error 1 "Can't mark negative article numbers")
10192           nil)
10193       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10194             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10195             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10196             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10197             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10198
10199       ;; Unsuppress duplicates?
10200       (when gnus-suppress-duplicates
10201         (gnus-dup-unsuppress-article article))
10202
10203       (cond ((= mark gnus-ticked-mark)
10204              (setq gnus-newsgroup-marked
10205                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10206             ((= mark gnus-spam-mark)
10207              (setq gnus-newsgroup-spam-marked
10208                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10209                                             article)))
10210             ((= mark gnus-dormant-mark)
10211              (setq gnus-newsgroup-dormant
10212                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10213             (t
10214              (setq gnus-newsgroup-unreads
10215                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10216       (gnus-pull article gnus-newsgroup-reads)
10217       t)))
10218
10219 (defalias 'gnus-summary-mark-as-unread-forward
10220   'gnus-summary-tick-article-forward)
10221 (make-obsolete 'gnus-summary-mark-as-unread-forward
10222                'gnus-summary-tick-article-forward)
10223 (defun gnus-summary-tick-article-forward (n)
10224   "Tick N articles forwards.
10225 If N is negative, tick backwards instead.
10226 The difference between N and the number of articles ticked is returned."
10227   (interactive "p")
10228   (gnus-summary-mark-forward n gnus-ticked-mark))
10229
10230 (defalias 'gnus-summary-mark-as-unread-backward
10231   'gnus-summary-tick-article-backward)
10232 (make-obsolete 'gnus-summary-mark-as-unread-backward
10233                'gnus-summary-tick-article-backward)
10234 (defun gnus-summary-tick-article-backward (n)
10235   "Tick N articles backwards.
10236 The difference between N and the number of articles ticked is returned."
10237   (interactive "p")
10238   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10239
10240 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10241 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10242 (defun gnus-summary-tick-article (&optional article clear-mark)
10243   "Mark current article as unread.
10244 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10245 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10246   (interactive)
10247   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10248                                        gnus-ticked-mark)))
10249
10250 (defun gnus-summary-mark-as-read-forward (n)
10251   "Mark N articles as read forwards.
10252 If N is negative, mark backwards instead.
10253 The difference between N and the actual number of articles marked is
10254 returned."
10255   (interactive "p")
10256   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10257
10258 (defun gnus-summary-mark-as-read-backward (n)
10259   "Mark the N articles as read backwards.
10260 The difference between N and the actual number of articles marked is
10261 returned."
10262   (interactive "p")
10263   (gnus-summary-mark-forward
10264    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10265
10266 (defun gnus-summary-mark-as-read (&optional article mark)
10267   "Mark current article as read.
10268 ARTICLE specifies the article to be marked as read.
10269 MARK specifies a string to be inserted at the beginning of the line."
10270   (gnus-summary-mark-article article mark))
10271
10272 (defun gnus-summary-clear-mark-forward (n)
10273   "Clear marks from N articles forward.
10274 If N is negative, clear backward instead.
10275 The difference between N and the number of marks cleared is returned."
10276   (interactive "p")
10277   (gnus-summary-mark-forward n gnus-unread-mark))
10278
10279 (defun gnus-summary-clear-mark-backward (n)
10280   "Clear marks from N articles backward.
10281 The difference between N and the number of marks cleared is returned."
10282   (interactive "p")
10283   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10284
10285 (defun gnus-summary-mark-unread-as-read ()
10286   "Intended to be used by `gnus-summary-mark-article-hook'."
10287   (when (memq gnus-current-article gnus-newsgroup-unreads)
10288     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10289
10290 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10291   "Intended to be used by `gnus-summary-mark-article-hook'."
10292   (let ((mark (gnus-summary-article-mark)))
10293     (when (or (gnus-unread-mark-p mark)
10294               (gnus-read-mark-p mark))
10295       (gnus-summary-mark-article gnus-current-article
10296                                  (or new-mark gnus-read-mark)))))
10297
10298 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10299   "Intended to be used by `gnus-summary-mark-article-hook'."
10300   (let ((mark (gnus-summary-article-mark)))
10301     (when (or (gnus-unread-mark-p mark)
10302               (gnus-read-mark-p mark))
10303       (gnus-summary-mark-article (gnus-summary-article-number)
10304                                  (or new-mark gnus-read-mark)))))
10305
10306 (defun gnus-summary-mark-unread-as-ticked ()
10307   "Intended to be used by `gnus-summary-mark-article-hook'."
10308   (when (memq gnus-current-article gnus-newsgroup-unreads)
10309     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10310
10311 (defun gnus-summary-mark-region-as-read (point mark all)
10312   "Mark all unread articles between point and mark as read.
10313 If given a prefix, mark all articles between point and mark as read,
10314 even ticked and dormant ones."
10315   (interactive "r\nP")
10316   (save-excursion
10317     (let (article)
10318       (goto-char point)
10319       (beginning-of-line)
10320       (while (and
10321               (< (point) mark)
10322               (progn
10323                 (when (or all
10324                           (memq (setq article (gnus-summary-article-number))
10325                                 gnus-newsgroup-unreads))
10326                   (gnus-summary-mark-article article gnus-del-mark))
10327                 t)
10328               (gnus-summary-find-next))))))
10329
10330 (defun gnus-summary-mark-below (score mark)
10331   "Mark articles with score less than SCORE with MARK."
10332   (interactive "P\ncMark: ")
10333   (setq score (if score
10334                   (prefix-numeric-value score)
10335                 (or gnus-summary-default-score 0)))
10336   (save-excursion
10337     (set-buffer gnus-summary-buffer)
10338     (goto-char (point-min))
10339     (while
10340         (progn
10341           (and (< (gnus-summary-article-score) score)
10342                (gnus-summary-mark-article nil mark))
10343           (gnus-summary-find-next)))))
10344
10345 (defun gnus-summary-kill-below (&optional score)
10346   "Mark articles with score below SCORE as read."
10347   (interactive "P")
10348   (gnus-summary-mark-below score gnus-killed-mark))
10349
10350 (defun gnus-summary-clear-above (&optional score)
10351   "Clear all marks from articles with score above SCORE."
10352   (interactive "P")
10353   (gnus-summary-mark-above score gnus-unread-mark))
10354
10355 (defun gnus-summary-tick-above (&optional score)
10356   "Tick all articles with score above SCORE."
10357   (interactive "P")
10358   (gnus-summary-mark-above score gnus-ticked-mark))
10359
10360 (defun gnus-summary-mark-above (score mark)
10361   "Mark articles with score over SCORE with MARK."
10362   (interactive "P\ncMark: ")
10363   (setq score (if score
10364                   (prefix-numeric-value score)
10365                 (or gnus-summary-default-score 0)))
10366   (save-excursion
10367     (set-buffer gnus-summary-buffer)
10368     (goto-char (point-min))
10369     (while (and (progn
10370                   (when (> (gnus-summary-article-score) score)
10371                     (gnus-summary-mark-article nil mark))
10372                   t)
10373                 (gnus-summary-find-next)))))
10374
10375 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10376 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10377 (defun gnus-summary-limit-include-expunged (&optional no-error)
10378   "Display all the hidden articles that were expunged for low scores."
10379   (interactive)
10380   (let ((buffer-read-only nil))
10381     (let ((scored gnus-newsgroup-scored)
10382           headers h)
10383       (while scored
10384         (unless (gnus-summary-article-header (caar scored))
10385           (and (setq h (gnus-number-to-header (caar scored)))
10386                (< (cdar scored) gnus-summary-expunge-below)
10387                (push h headers)))
10388         (setq scored (cdr scored)))
10389       (if (not headers)
10390           (when (not no-error)
10391             (error "No expunged articles hidden"))
10392         (goto-char (point-min))
10393         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10394         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10395         (mapcar (lambda (x) (push (mail-header-number x)
10396                                   gnus-newsgroup-limit))
10397                 headers)
10398         (gnus-summary-prepare-unthreaded (nreverse headers))
10399         (goto-char (point-min))
10400         (gnus-summary-position-point)
10401         t))))
10402
10403 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10404   "Mark all unread articles in this newsgroup as read.
10405 If prefix argument ALL is non-nil, ticked and dormant articles will
10406 also be marked as read.
10407 If QUIETLY is non-nil, no questions will be asked.
10408
10409 If TO-HERE is non-nil, it should be a point in the buffer.  All
10410 articles before (after, if REVERSE is set) this point will be marked
10411 as read.
10412
10413 Note that this function will only catch up the unread article
10414 in the current summary buffer limitation.
10415
10416 The number of articles marked as read is returned."
10417   (interactive "P")
10418   (prog1
10419       (save-excursion
10420         (when (or quietly
10421                   (not gnus-interactive-catchup) ;Without confirmation?
10422                   gnus-expert-user
10423                   (gnus-y-or-n-p
10424                    (if all
10425                        "Mark absolutely all articles as read? "
10426                      "Mark all unread articles as read? ")))
10427           (if (and not-mark
10428                    (not gnus-newsgroup-adaptive)
10429                    (not gnus-newsgroup-auto-expire)
10430                    (not gnus-suppress-duplicates)
10431                    (or (not gnus-use-cache)
10432                        (eq gnus-use-cache 'passive)))
10433               (progn
10434                 (when all
10435                   (setq gnus-newsgroup-marked nil
10436                         gnus-newsgroup-spam-marked nil
10437                         gnus-newsgroup-dormant nil))
10438                 (setq gnus-newsgroup-unreads
10439                       (gnus-sorted-nunion
10440                        (gnus-intersection gnus-newsgroup-unreads
10441                                           gnus-newsgroup-downloadable)
10442                        gnus-newsgroup-unfetched)))
10443             ;; We actually mark all articles as canceled, which we
10444             ;; have to do when using auto-expiry or adaptive scoring.
10445             (gnus-summary-show-all-threads)
10446             (if (and to-here reverse)
10447                 (progn
10448                   (goto-char to-here)
10449                   (gnus-summary-mark-current-read-and-unread-as-read
10450                    gnus-catchup-mark)
10451                   (while (gnus-summary-find-next (not all))
10452                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10453               (when (gnus-summary-first-subject (not all))
10454                 (while (and
10455                         (if to-here (< (point) to-here) t)
10456                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10457                         (gnus-summary-find-next (not all))))))
10458             (gnus-set-mode-line 'summary))
10459           t))
10460     (gnus-summary-position-point)))
10461
10462 (defun gnus-summary-catchup-to-here (&optional all)
10463   "Mark all unticked articles before the current one as read.
10464 If ALL is non-nil, also mark ticked and dormant articles as read."
10465   (interactive "P")
10466   (save-excursion
10467     (gnus-save-hidden-threads
10468       (let ((beg (point)))
10469         ;; We check that there are unread articles.
10470         (when (or all (gnus-summary-find-prev))
10471           (gnus-summary-catchup all t beg)))))
10472   (gnus-summary-position-point))
10473
10474 (defun gnus-summary-catchup-from-here (&optional all)
10475   "Mark all unticked articles after (and including) the current one as read.
10476 If ALL is non-nil, also mark ticked and dormant articles as read."
10477   (interactive "P")
10478   (save-excursion
10479     (gnus-save-hidden-threads
10480       (let ((beg (point)))
10481         ;; We check that there are unread articles.
10482         (when (or all (gnus-summary-find-next))
10483           (gnus-summary-catchup all t beg nil t)))))
10484   (gnus-summary-position-point))
10485
10486 (defun gnus-summary-catchup-all (&optional quietly)
10487   "Mark all articles in this newsgroup as read.
10488 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10489 instead, which marks only unread articles as read."
10490   (interactive "P")
10491   (gnus-summary-catchup t quietly))
10492
10493 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10494   "Mark all unread articles in this group as read, then exit.
10495 If prefix argument ALL is non-nil, all articles are marked as read.
10496 If QUIETLY is non-nil, no questions will be asked."
10497   (interactive "P")
10498   (when (gnus-summary-catchup all quietly nil 'fast)
10499     ;; Select next newsgroup or exit.
10500     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10501              (eq gnus-auto-select-next 'quietly))
10502         (gnus-summary-next-group nil)
10503       (gnus-summary-exit))))
10504
10505 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10506   "Mark all articles in this newsgroup as read, and then exit.
10507 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10508 instead, which marks only unread articles as read."
10509   (interactive "P")
10510   (gnus-summary-catchup-and-exit t quietly))
10511
10512 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10513   "Mark all articles in this group as read and select the next group.
10514 If given a prefix, mark all articles, unread as well as ticked, as
10515 read."
10516   (interactive "P")
10517   (save-excursion
10518     (gnus-summary-catchup all))
10519   (gnus-summary-next-group))
10520
10521 ;;;
10522 ;;; with article
10523 ;;;
10524
10525 (defmacro gnus-with-article (article &rest forms)
10526   "Select ARTICLE and perform FORMS in the original article buffer.
10527 Then replace the article with the result."
10528   `(progn
10529      ;; We don't want the article to be marked as read.
10530      (let (gnus-mark-article-hook)
10531        (gnus-summary-select-article t t nil ,article))
10532      (set-buffer gnus-original-article-buffer)
10533      ,@forms
10534      (if (not (gnus-check-backend-function
10535                'request-replace-article (car gnus-article-current)))
10536          (gnus-message 5 "Read-only group; not replacing")
10537        (unless (gnus-request-replace-article
10538                 ,article (car gnus-article-current)
10539                 (current-buffer) t)
10540          (error "Couldn't replace article")))
10541      ;; The cache and backlog have to be flushed somewhat.
10542      (when gnus-keep-backlog
10543        (gnus-backlog-remove-article
10544         (car gnus-article-current) (cdr gnus-article-current)))
10545      (when gnus-use-cache
10546        (gnus-cache-update-article
10547         (car gnus-article-current) (cdr gnus-article-current)))))
10548
10549 (put 'gnus-with-article 'lisp-indent-function 1)
10550 (put 'gnus-with-article 'edebug-form-spec '(form body))
10551
10552 ;; Thread-based commands.
10553
10554 (defun gnus-summary-articles-in-thread (&optional article)
10555   "Return a list of all articles in the current thread.
10556 If ARTICLE is non-nil, return all articles in the thread that starts
10557 with that article."
10558   (let* ((article (or article (gnus-summary-article-number)))
10559          (data (gnus-data-find-list article))
10560          (top-level (gnus-data-level (car data)))
10561          (top-subject
10562           (cond ((null gnus-thread-operation-ignore-subject)
10563                  (gnus-simplify-subject-re
10564                   (mail-header-subject (gnus-data-header (car data)))))
10565                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10566                  (gnus-simplify-subject-fuzzy
10567                   (mail-header-subject (gnus-data-header (car data)))))
10568                 (t nil)))
10569          (end-point (save-excursion
10570                       (if (gnus-summary-go-to-next-thread)
10571                           (point) (point-max))))
10572          articles)
10573     (while (and data
10574                 (< (gnus-data-pos (car data)) end-point))
10575       (when (or (not top-subject)
10576                 (string= top-subject
10577                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10578                              (gnus-simplify-subject-fuzzy
10579                               (mail-header-subject
10580                                (gnus-data-header (car data))))
10581                            (gnus-simplify-subject-re
10582                             (mail-header-subject
10583                              (gnus-data-header (car data)))))))
10584         (push (gnus-data-number (car data)) articles))
10585       (unless (and (setq data (cdr data))
10586                    (> (gnus-data-level (car data)) top-level))
10587         (setq data nil)))
10588     ;; Return the list of articles.
10589     (nreverse articles)))
10590
10591 (defun gnus-summary-rethread-current ()
10592   "Rethread the thread the current article is part of."
10593   (interactive)
10594   (let* ((gnus-show-threads t)
10595          (article (gnus-summary-article-number))
10596          (id (mail-header-id (gnus-summary-article-header)))
10597          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10598     (unless id
10599       (error "No article on the current line"))
10600     (gnus-rebuild-thread id)
10601     (gnus-summary-goto-subject article)))
10602
10603 (defun gnus-summary-reparent-thread ()
10604   "Make the current article child of the marked (or previous) article.
10605
10606 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10607 is non-nil or the Subject: of both articles are the same."
10608   (interactive)
10609   (unless (not (gnus-group-read-only-p))
10610     (error "The current newsgroup does not support article editing"))
10611   (unless (<= (length gnus-newsgroup-processable) 1)
10612     (error "No more than one article may be marked"))
10613   (save-window-excursion
10614     (let ((gnus-article-buffer " *reparent*")
10615           (current-article (gnus-summary-article-number))
10616           ;; First grab the marked article, otherwise one line up.
10617           (parent-article (if (not (null gnus-newsgroup-processable))
10618                               (car gnus-newsgroup-processable)
10619                             (save-excursion
10620                               (if (eq (forward-line -1) 0)
10621                                   (gnus-summary-article-number)
10622                                 (error "Beginning of summary buffer"))))))
10623       (unless (not (eq current-article parent-article))
10624         (error "An article may not be self-referential"))
10625       (let ((message-id (mail-header-id
10626                          (gnus-summary-article-header parent-article))))
10627         (unless (and message-id (not (equal message-id "")))
10628           (error "No message-id in desired parent"))
10629         (gnus-with-article current-article
10630           (save-restriction
10631             (goto-char (point-min))
10632             (message-narrow-to-head)
10633             (if (re-search-forward "^References: " nil t)
10634                 (progn
10635                   (re-search-forward "^[^ \t]" nil t)
10636                   (forward-line -1)
10637                   (end-of-line)
10638                   (insert " " message-id))
10639               (insert "References: " message-id "\n"))))
10640         (set-buffer gnus-summary-buffer)
10641         (gnus-summary-unmark-all-processable)
10642         (gnus-summary-update-article current-article)
10643         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10644             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10645         (gnus-summary-rethread-current)
10646         (gnus-message 3 "Article %d is now the child of article %d"
10647                       current-article parent-article)))))
10648
10649 (defun gnus-summary-toggle-threads (&optional arg)
10650   "Toggle showing conversation threads.
10651 If ARG is positive number, turn showing conversation threads on."
10652   (interactive "P")
10653   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10654     (setq gnus-show-threads
10655           (if (null arg) (not gnus-show-threads)
10656             (> (prefix-numeric-value arg) 0)))
10657     (gnus-summary-prepare)
10658     (gnus-summary-goto-subject current)
10659     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10660     (gnus-summary-position-point)))
10661
10662 (defun gnus-summary-show-all-threads ()
10663   "Show all threads."
10664   (interactive)
10665   (save-excursion
10666     (let ((buffer-read-only nil))
10667       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10668   (gnus-summary-position-point))
10669
10670 (defun gnus-summary-show-thread ()
10671   "Show thread subtrees.
10672 Returns nil if no thread was there to be shown."
10673   (interactive)
10674   (let ((buffer-read-only nil)
10675         (orig (point))
10676         (end (point-at-eol))
10677         ;; Leave point at bol
10678         (beg (progn (beginning-of-line) (point))))
10679     (prog1
10680         ;; Any hidden lines here?
10681         (search-forward "\r" end t)
10682       (subst-char-in-region beg end ?\^M ?\n t)
10683       (goto-char orig)
10684       (gnus-summary-position-point))))
10685
10686 (defun gnus-summary-maybe-hide-threads ()
10687   "If requested, hide the threads that should be hidden."
10688   (when (and gnus-show-threads
10689              gnus-thread-hide-subtree)
10690     (gnus-summary-hide-all-threads
10691      (if (or (consp gnus-thread-hide-subtree)
10692              (functionp gnus-thread-hide-subtree))
10693          (gnus-make-predicate gnus-thread-hide-subtree)
10694        nil))))
10695
10696 ;;; Hiding predicates.
10697
10698 (defun gnus-article-unread-p (header)
10699   (memq (mail-header-number header) gnus-newsgroup-unreads))
10700
10701 (defun gnus-article-unseen-p (header)
10702   (memq (mail-header-number header) gnus-newsgroup-unseen))
10703
10704 (defun gnus-map-articles (predicate articles)
10705   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10706   (apply 'gnus-or (mapcar predicate
10707                           (mapcar 'gnus-summary-article-header articles))))
10708
10709 (defun gnus-summary-hide-all-threads (&optional predicate)
10710   "Hide all thread subtrees.
10711 If PREDICATE is supplied, threads that satisfy this predicate
10712 will not be hidden."
10713   (interactive)
10714   (save-excursion
10715     (goto-char (point-min))
10716     (let ((end nil))
10717       (while (not end)
10718         (when (or (not predicate)
10719                   (gnus-map-articles
10720                    predicate (gnus-summary-article-children)))
10721             (gnus-summary-hide-thread))
10722         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10723   (gnus-summary-position-point))
10724
10725 (defun gnus-summary-hide-thread ()
10726   "Hide thread subtrees.
10727 If PREDICATE is supplied, threads that satisfy this predicate
10728 will not be hidden.
10729 Returns nil if no threads were there to be hidden."
10730   (interactive)
10731   (let ((buffer-read-only nil)
10732         (start (point))
10733         (article (gnus-summary-article-number)))
10734     (goto-char start)
10735     ;; Go forward until either the buffer ends or the subthread
10736     ;; ends.
10737     (when (and (not (eobp))
10738                (or (zerop (gnus-summary-next-thread 1 t))
10739                    (goto-char (point-max))))
10740       (prog1
10741           (if (and (> (point) start)
10742                    (search-backward "\n" start t))
10743               (progn
10744                 (subst-char-in-region start (point) ?\n ?\^M)
10745                 (gnus-summary-goto-subject article))
10746             (goto-char start)
10747             nil)))))
10748
10749 (defun gnus-summary-go-to-next-thread (&optional previous)
10750   "Go to the same level (or less) next thread.
10751 If PREVIOUS is non-nil, go to previous thread instead.
10752 Return the article number moved to, or nil if moving was impossible."
10753   (let ((level (gnus-summary-thread-level))
10754         (way (if previous -1 1))
10755         (beg (point)))
10756     (forward-line way)
10757     (while (and (not (eobp))
10758                 (< level (gnus-summary-thread-level)))
10759       (forward-line way))
10760     (if (eobp)
10761         (progn
10762           (goto-char beg)
10763           nil)
10764       (setq beg (point))
10765       (prog1
10766           (gnus-summary-article-number)
10767         (goto-char beg)))))
10768
10769 (defun gnus-summary-next-thread (n &optional silent)
10770   "Go to the same level next N'th thread.
10771 If N is negative, search backward instead.
10772 Returns the difference between N and the number of skips actually
10773 done.
10774
10775 If SILENT, don't output messages."
10776   (interactive "p")
10777   (let ((backward (< n 0))
10778         (n (abs n)))
10779     (while (and (> n 0)
10780                 (gnus-summary-go-to-next-thread backward))
10781       (decf n))
10782     (unless silent
10783       (gnus-summary-position-point))
10784     (when (and (not silent) (/= 0 n))
10785       (gnus-message 7 "No more threads"))
10786     n))
10787
10788 (defun gnus-summary-prev-thread (n)
10789   "Go to the same level previous N'th thread.
10790 Returns the difference between N and the number of skips actually
10791 done."
10792   (interactive "p")
10793   (gnus-summary-next-thread (- n)))
10794
10795 (defun gnus-summary-go-down-thread ()
10796   "Go down one level in the current thread."
10797   (let ((children (gnus-summary-article-children)))
10798     (when children
10799       (gnus-summary-goto-subject (car children)))))
10800
10801 (defun gnus-summary-go-up-thread ()
10802   "Go up one level in the current thread."
10803   (let ((parent (gnus-summary-article-parent)))
10804     (when parent
10805       (gnus-summary-goto-subject parent))))
10806
10807 (defun gnus-summary-down-thread (n)
10808   "Go down thread N steps.
10809 If N is negative, go up instead.
10810 Returns the difference between N and how many steps down that were
10811 taken."
10812   (interactive "p")
10813   (let ((up (< n 0))
10814         (n (abs n)))
10815     (while (and (> n 0)
10816                 (if up (gnus-summary-go-up-thread)
10817                   (gnus-summary-go-down-thread)))
10818       (setq n (1- n)))
10819     (gnus-summary-position-point)
10820     (when (/= 0 n)
10821       (gnus-message 7 "Can't go further"))
10822     n))
10823
10824 (defun gnus-summary-up-thread (n)
10825   "Go up thread N steps.
10826 If N is negative, go down instead.
10827 Returns the difference between N and how many steps down that were
10828 taken."
10829   (interactive "p")
10830   (gnus-summary-down-thread (- n)))
10831
10832 (defun gnus-summary-top-thread ()
10833   "Go to the top of the thread."
10834   (interactive)
10835   (while (gnus-summary-go-up-thread))
10836   (gnus-summary-article-number))
10837
10838 (defun gnus-summary-kill-thread (&optional unmark)
10839   "Mark articles under current thread as read.
10840 If the prefix argument is positive, remove any kinds of marks.
10841 If the prefix argument is negative, tick articles instead."
10842   (interactive "P")
10843   (when unmark
10844     (setq unmark (prefix-numeric-value unmark)))
10845   (let ((articles (gnus-summary-articles-in-thread)))
10846     (save-excursion
10847       ;; Expand the thread.
10848       (gnus-summary-show-thread)
10849       ;; Mark all the articles.
10850       (while articles
10851         (gnus-summary-goto-subject (car articles))
10852         (cond ((null unmark)
10853                (gnus-summary-mark-article-as-read gnus-killed-mark))
10854               ((> unmark 0)
10855                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10856               (t
10857                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10858         (setq articles (cdr articles))))
10859     ;; Hide killed subtrees.
10860     (and (null unmark)
10861          gnus-thread-hide-killed
10862          (gnus-summary-hide-thread))
10863     ;; If marked as read, go to next unread subject.
10864     (when (null unmark)
10865       ;; Go to next unread subject.
10866       (gnus-summary-next-subject 1 t)))
10867   (gnus-set-mode-line 'summary))
10868
10869 ;; Summary sorting commands
10870
10871 (defun gnus-summary-sort-by-number (&optional reverse)
10872   "Sort the summary buffer by article number.
10873 Argument REVERSE means reverse order."
10874   (interactive "P")
10875   (gnus-summary-sort 'number reverse))
10876
10877 (defun gnus-summary-sort-by-random (&optional reverse)
10878   "Randomize the order in the summary buffer.
10879 Argument REVERSE means to randomize in reverse order."
10880   (interactive "P")
10881   (gnus-summary-sort 'random reverse))
10882
10883 (defun gnus-summary-sort-by-author (&optional reverse)
10884   "Sort the summary buffer by author name alphabetically.
10885 If `case-fold-search' is non-nil, case of letters is ignored.
10886 Argument REVERSE means reverse order."
10887   (interactive "P")
10888   (gnus-summary-sort 'author reverse))
10889
10890 (defun gnus-summary-sort-by-recipient (&optional reverse)
10891   "Sort the summary buffer by recipient name alphabetically.
10892 If `case-fold-search' is non-nil, case of letters is ignored.
10893 Argument REVERSE means reverse order."
10894   (interactive "P")
10895   (gnus-summary-sort 'recipient reverse))
10896
10897 (defun gnus-summary-sort-by-subject (&optional reverse)
10898   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10899 If `case-fold-search' is non-nil, case of letters is ignored.
10900 Argument REVERSE means reverse order."
10901   (interactive "P")
10902   (gnus-summary-sort 'subject reverse))
10903
10904 (defun gnus-summary-sort-by-date (&optional reverse)
10905   "Sort the summary buffer by date.
10906 Argument REVERSE means reverse order."
10907   (interactive "P")
10908   (gnus-summary-sort 'date reverse))
10909
10910 (defun gnus-summary-sort-by-score (&optional reverse)
10911   "Sort the summary buffer by score.
10912 Argument REVERSE means reverse order."
10913   (interactive "P")
10914   (gnus-summary-sort 'score reverse))
10915
10916 (defun gnus-summary-sort-by-lines (&optional reverse)
10917   "Sort the summary buffer by the number of lines.
10918 Argument REVERSE means reverse order."
10919   (interactive "P")
10920   (gnus-summary-sort 'lines reverse))
10921
10922 (defun gnus-summary-sort-by-chars (&optional reverse)
10923   "Sort the summary buffer by article length.
10924 Argument REVERSE means reverse order."
10925   (interactive "P")
10926   (gnus-summary-sort 'chars reverse))
10927
10928 (defun gnus-summary-sort-by-original (&optional reverse)
10929   "Sort the summary buffer using the default sorting method.
10930 Argument REVERSE means reverse order."
10931   (interactive "P")
10932   (let* ((buffer-read-only)
10933          (gnus-summary-prepare-hook nil))
10934     ;; We do the sorting by regenerating the threads.
10935     (gnus-summary-prepare)
10936     ;; Hide subthreads if needed.
10937     (gnus-summary-maybe-hide-threads)))
10938
10939 (defun gnus-summary-sort (predicate reverse)
10940   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10941   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10942          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10943          (gnus-thread-sort-functions
10944           (if (not reverse)
10945               thread
10946             `(lambda (t1 t2)
10947                (,thread t2 t1))))
10948          (gnus-sort-gathered-threads-function
10949           gnus-thread-sort-functions)
10950          (gnus-article-sort-functions
10951           (if (not reverse)
10952               article
10953             `(lambda (t1 t2)
10954                (,article t2 t1))))
10955          (buffer-read-only)
10956          (gnus-summary-prepare-hook nil))
10957     ;; We do the sorting by regenerating the threads.
10958     (gnus-summary-prepare)
10959     ;; Hide subthreads if needed.
10960     (gnus-summary-maybe-hide-threads)))
10961
10962 ;; Summary saving commands.
10963
10964 (defun gnus-summary-save-article (&optional n not-saved)
10965   "Save the current article using the default saver function.
10966 If N is a positive number, save the N next articles.
10967 If N is a negative number, save the N previous articles.
10968 If N is nil and any articles have been marked with the process mark,
10969 save those articles instead.
10970 The variable `gnus-default-article-saver' specifies the saver function."
10971   (interactive "P")
10972   (let* ((articles (gnus-summary-work-articles n))
10973          (save-buffer (save-excursion
10974                         (nnheader-set-temp-buffer " *Gnus Save*")))
10975          (num (length articles))
10976          header file)
10977     (dolist (article articles)
10978       (setq header (gnus-summary-article-header article))
10979       (if (not (vectorp header))
10980           ;; This is a pseudo-article.
10981           (if (assq 'name header)
10982               (gnus-copy-file (cdr (assq 'name header)))
10983             (gnus-message 1 "Article %d is unsaveable" article))
10984         ;; This is a real article.
10985         (save-window-excursion
10986           (let ((gnus-display-mime-function nil)
10987                 (gnus-article-prepare-hook nil))
10988             (gnus-summary-select-article t nil nil article)))
10989         (save-excursion
10990           (set-buffer save-buffer)
10991           (erase-buffer)
10992           (insert-buffer-substring gnus-original-article-buffer))
10993         (setq file (gnus-article-save save-buffer file num))
10994         (gnus-summary-remove-process-mark article)
10995         (unless not-saved
10996           (gnus-summary-set-saved-mark article))))
10997     (gnus-kill-buffer save-buffer)
10998     (gnus-summary-position-point)
10999     (gnus-set-mode-line 'summary)
11000     n))
11001
11002 (defun gnus-summary-pipe-output (&optional arg headers)
11003   "Pipe the current article to a subprocess.
11004 If N is a positive number, pipe the N next articles.
11005 If N is a negative number, pipe the N previous articles.
11006 If N is nil and any articles have been marked with the process mark,
11007 pipe those articles instead.
11008 If HEADERS (the symbolic prefix), include the headers, too."
11009   (interactive (gnus-interactive "P\ny"))
11010   (require 'gnus-art)
11011   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11012         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11013     (gnus-summary-save-article arg t))
11014   (let ((buffer (get-buffer "*Shell Command Output*")))
11015     (when (and buffer
11016                (not (zerop (buffer-size buffer))))
11017       (gnus-configure-windows 'pipe))))
11018
11019 (defun gnus-summary-save-article-mail (&optional arg)
11020   "Append the current article to an mail file.
11021 If N is a positive number, save the N next articles.
11022 If N is a negative number, save the N previous articles.
11023 If N is nil and any articles have been marked with the process mark,
11024 save those articles instead."
11025   (interactive "P")
11026   (require 'gnus-art)
11027   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11028     (gnus-summary-save-article arg)))
11029
11030 (defun gnus-summary-save-article-rmail (&optional arg)
11031   "Append the current article to an rmail file.
11032 If N is a positive number, save the N next articles.
11033 If N is a negative number, save the N previous articles.
11034 If N is nil and any articles have been marked with the process mark,
11035 save those articles instead."
11036   (interactive "P")
11037   (require 'gnus-art)
11038   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11039     (gnus-summary-save-article arg)))
11040
11041 (defun gnus-summary-save-article-file (&optional arg)
11042   "Append the current article to a file.
11043 If N is a positive number, save the N next articles.
11044 If N is a negative number, save the N previous articles.
11045 If N is nil and any articles have been marked with the process mark,
11046 save those articles instead."
11047   (interactive "P")
11048   (require 'gnus-art)
11049   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11050     (gnus-summary-save-article arg)))
11051
11052 (defun gnus-summary-write-article-file (&optional arg)
11053   "Write the current article to a file, deleting the previous file.
11054 If N is a positive number, save the N next articles.
11055 If N is a negative number, save the N previous articles.
11056 If N is nil and any articles have been marked with the process mark,
11057 save those articles instead."
11058   (interactive "P")
11059   (require 'gnus-art)
11060   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11061     (gnus-summary-save-article arg)))
11062
11063 (defun gnus-summary-save-article-body-file (&optional arg)
11064   "Append the current article body to a file.
11065 If N is a positive number, save the N next articles.
11066 If N is a negative number, save the N previous articles.
11067 If N is nil and any articles have been marked with the process mark,
11068 save those articles instead."
11069   (interactive "P")
11070   (require 'gnus-art)
11071   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11072     (gnus-summary-save-article arg)))
11073
11074 (defun gnus-summary-muttprint (&optional arg)
11075   "Print the current article using Muttprint.
11076 If N is a positive number, save the N next articles.
11077 If N is a negative number, save the N previous articles.
11078 If N is nil and any articles have been marked with the process mark,
11079 save those articles instead."
11080   (interactive "P")
11081   (require 'gnus-art)
11082   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11083     (gnus-summary-save-article arg t)))
11084
11085 (defun gnus-summary-pipe-message (program)
11086   "Pipe the current article through PROGRAM."
11087   (interactive "sProgram: ")
11088   (gnus-summary-select-article)
11089   (let ((mail-header-separator ""))
11090     (gnus-eval-in-buffer-window gnus-article-buffer
11091       (save-restriction
11092         (widen)
11093         (let ((start (window-start))
11094               buffer-read-only)
11095           (message-pipe-buffer-body program)
11096           (set-window-start (get-buffer-window (current-buffer)) start))))))
11097
11098 (defun gnus-get-split-value (methods)
11099   "Return a value based on the split METHODS."
11100   (let (split-name method result match)
11101     (when methods
11102       (save-excursion
11103         (set-buffer gnus-original-article-buffer)
11104         (save-restriction
11105           (nnheader-narrow-to-headers)
11106           (while (and methods (not split-name))
11107             (goto-char (point-min))
11108             (setq method (pop methods))
11109             (setq match (car method))
11110             (when (cond
11111                    ((stringp match)
11112                     ;; Regular expression.
11113                     (ignore-errors
11114                       (re-search-forward match nil t)))
11115                    ((functionp match)
11116                     ;; Function.
11117                     (save-restriction
11118                       (widen)
11119                       (setq result (funcall match gnus-newsgroup-name))))
11120                    ((consp match)
11121                     ;; Form.
11122                     (save-restriction
11123                       (widen)
11124                       (setq result (eval match)))))
11125               (setq split-name (cdr method))
11126               (cond ((stringp result)
11127                      (push (expand-file-name
11128                             result gnus-article-save-directory)
11129                            split-name))
11130                     ((consp result)
11131                      (setq split-name (append result split-name)))))))))
11132     (nreverse split-name)))
11133
11134 (defun gnus-valid-move-group-p (group)
11135   (and (boundp group)
11136        (symbol-name group)
11137        (symbol-value group)
11138        (gnus-get-function (gnus-find-method-for-group
11139                            (symbol-name group)) 'request-accept-article t)))
11140
11141 (defun gnus-read-move-group-name (prompt default articles prefix)
11142   "Read a group name."
11143   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11144          (minibuffer-confirm-incomplete nil) ; XEmacs
11145          (prom
11146           (format "%s %s to:"
11147                   prompt
11148                   (if (> (length articles) 1)
11149                       (format "these %d articles" (length articles))
11150                     "this article")))
11151          (to-newsgroup
11152           (cond
11153            ((null split-name)
11154             (gnus-completing-read-with-default
11155              default prom
11156              gnus-active-hashtb
11157              'gnus-valid-move-group-p
11158              nil prefix
11159              'gnus-group-history))
11160            ((= 1 (length split-name))
11161             (gnus-completing-read-with-default
11162              (car split-name) prom
11163              gnus-active-hashtb
11164              'gnus-valid-move-group-p
11165              nil nil
11166              'gnus-group-history))
11167            (t
11168             (gnus-completing-read-with-default
11169              nil prom
11170              (mapcar 'list (nreverse split-name))
11171              nil nil nil
11172              'gnus-group-history))))
11173          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11174     (when to-newsgroup
11175       (if (or (string= to-newsgroup "")
11176               (string= to-newsgroup prefix))
11177           (setq to-newsgroup default))
11178       (unless to-newsgroup
11179         (error "No group name entered"))
11180       (or (gnus-active to-newsgroup)
11181           (gnus-activate-group to-newsgroup nil nil to-method)
11182           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11183                                      to-newsgroup))
11184               (or (and (gnus-request-create-group to-newsgroup to-method)
11185                        (gnus-activate-group
11186                         to-newsgroup nil nil to-method)
11187                        (gnus-subscribe-group to-newsgroup))
11188                   (error "Couldn't create group %s" to-newsgroup)))
11189           (error "No such group: %s" to-newsgroup)))
11190     to-newsgroup))
11191
11192 (defun gnus-summary-save-parts (type dir n &optional reverse)
11193   "Save parts matching TYPE to DIR.
11194 If REVERSE, save parts that do not match TYPE."
11195   (interactive
11196    (list (read-string "Save parts of type: "
11197                       (or (car gnus-summary-save-parts-type-history)
11198                           gnus-summary-save-parts-default-mime)
11199                       'gnus-summary-save-parts-type-history)
11200          (setq gnus-summary-save-parts-last-directory
11201                (read-file-name "Save to directory: "
11202                                gnus-summary-save-parts-last-directory
11203                                nil t))
11204          current-prefix-arg))
11205   (gnus-summary-iterate n
11206     (let ((gnus-display-mime-function nil)
11207           (gnus-inhibit-treatment t))
11208       (gnus-summary-select-article))
11209     (save-excursion
11210       (set-buffer gnus-article-buffer)
11211       (let ((handles (or gnus-article-mime-handles
11212                          (mm-dissect-buffer nil gnus-article-loose-mime)
11213                          (and gnus-article-emulate-mime
11214                               (mm-uu-dissect)))))
11215         (when handles
11216           (gnus-summary-save-parts-1 type dir handles reverse)
11217           (unless gnus-article-mime-handles ;; Don't destroy this case.
11218             (mm-destroy-parts handles)))))))
11219
11220 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11221   (if (stringp (car handle))
11222       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11223               (cdr handle))
11224     (when (if reverse
11225               (not (string-match type (mm-handle-media-type handle)))
11226             (string-match type (mm-handle-media-type handle)))
11227       (let ((file (expand-file-name
11228                    (gnus-map-function
11229                     mm-file-name-rewrite-functions
11230                     (file-name-nondirectory
11231                      (or
11232                       (mail-content-type-get
11233                        (mm-handle-disposition handle) 'filename)
11234                       (mail-content-type-get
11235                        (mm-handle-type handle) 'name)
11236                       (concat gnus-newsgroup-name
11237                               "." (number-to-string
11238                                    (cdr gnus-article-current))))))
11239                    dir)))
11240         (unless (file-exists-p file)
11241           (mm-save-part-to-file handle file))))))
11242
11243 ;; Summary extract commands
11244
11245 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11246   (let ((buffer-read-only nil)
11247         (article (gnus-summary-article-number))
11248         after-article b e)
11249     (unless (gnus-summary-goto-subject article)
11250       (error "No such article: %d" article))
11251     (gnus-summary-position-point)
11252     ;; If all commands are to be bunched up on one line, we collect
11253     ;; them here.
11254     (unless gnus-view-pseudos-separately
11255       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11256             files action)
11257         (while ps
11258           (setq action (cdr (assq 'action (car ps))))
11259           (setq files (list (cdr (assq 'name (car ps)))))
11260           (while (and ps (cdr ps)
11261                       (string= (or action "1")
11262                                (or (cdr (assq 'action (cadr ps))) "2")))
11263             (push (cdr (assq 'name (cadr ps))) files)
11264             (setcdr ps (cddr ps)))
11265           (when files
11266             (when (not (string-match "%s" action))
11267               (push " " files))
11268             (push " " files)
11269             (when (assq 'execute (car ps))
11270               (setcdr (assq 'execute (car ps))
11271                       (funcall (if (string-match "%s" action)
11272                                    'format 'concat)
11273                                action
11274                                (mapconcat
11275                                 (lambda (f)
11276                                   (if (equal f " ")
11277                                       f
11278                                     (shell-quote-argument f)))
11279                                 files " ")))))
11280           (setq ps (cdr ps)))))
11281     (if (and gnus-view-pseudos (not not-view))
11282         (while pslist
11283           (when (assq 'execute (car pslist))
11284             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11285                                   (eq gnus-view-pseudos 'not-confirm)))
11286           (setq pslist (cdr pslist)))
11287       (save-excursion
11288         (while pslist
11289           (setq after-article (or (cdr (assq 'article (car pslist)))
11290                                   (gnus-summary-article-number)))
11291           (gnus-summary-goto-subject after-article)
11292           (forward-line 1)
11293           (setq b (point))
11294           (insert "    " (file-name-nondirectory
11295                           (cdr (assq 'name (car pslist))))
11296                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11297           (setq e (point))
11298           (forward-line -1)             ; back to `b'
11299           (gnus-add-text-properties
11300            b (1- e) (list 'gnus-number gnus-reffed-article-number
11301                           gnus-mouse-face-prop gnus-mouse-face))
11302           (gnus-data-enter
11303            after-article gnus-reffed-article-number
11304            gnus-unread-mark b (car pslist) 0 (- e b))
11305           (setq gnus-newsgroup-unreads
11306                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11307                                          gnus-reffed-article-number))
11308           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11309           (setq pslist (cdr pslist)))))))
11310
11311 (defun gnus-pseudos< (p1 p2)
11312   (let ((c1 (cdr (assq 'action p1)))
11313         (c2 (cdr (assq 'action p2))))
11314     (and c1 c2 (string< c1 c2))))
11315
11316 (defun gnus-request-pseudo-article (props)
11317   (cond ((assq 'execute props)
11318          (gnus-execute-command (cdr (assq 'execute props)))))
11319   (let ((gnus-current-article (gnus-summary-article-number)))
11320     (gnus-run-hooks 'gnus-mark-article-hook)))
11321
11322 (defun gnus-execute-command (command &optional automatic)
11323   (save-excursion
11324     (gnus-article-setup-buffer)
11325     (set-buffer gnus-article-buffer)
11326     (setq buffer-read-only nil)
11327     (let ((command (if automatic command
11328                      (read-string "Command: " (cons command 0)))))
11329       (erase-buffer)
11330       (insert "$ " command "\n\n")
11331       (if gnus-view-pseudo-asynchronously
11332           (start-process "gnus-execute" (current-buffer) shell-file-name
11333                          shell-command-switch command)
11334         (call-process shell-file-name nil t nil
11335                       shell-command-switch command)))))
11336
11337 ;; Summary kill commands.
11338
11339 (defun gnus-summary-edit-global-kill (article)
11340   "Edit the \"global\" kill file."
11341   (interactive (list (gnus-summary-article-number)))
11342   (gnus-group-edit-global-kill article))
11343
11344 (defun gnus-summary-edit-local-kill ()
11345   "Edit a local kill file applied to the current newsgroup."
11346   (interactive)
11347   (setq gnus-current-headers (gnus-summary-article-header))
11348   (gnus-group-edit-local-kill
11349    (gnus-summary-article-number) gnus-newsgroup-name))
11350
11351 ;;; Header reading.
11352
11353 (defun gnus-read-header (id &optional header)
11354   "Read the headers of article ID and enter them into the Gnus system."
11355   (let ((group gnus-newsgroup-name)
11356         (gnus-override-method
11357          (or
11358           gnus-override-method
11359           (and (gnus-news-group-p gnus-newsgroup-name)
11360                (car (gnus-refer-article-methods)))))
11361         where)
11362     ;; First we check to see whether the header in question is already
11363     ;; fetched.
11364     (if (stringp id)
11365         ;; This is a Message-ID.
11366         (setq header (or header (gnus-id-to-header id)))
11367       ;; This is an article number.
11368       (setq header (or header (gnus-summary-article-header id))))
11369     (if (and header
11370              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11371         ;; We have found the header.
11372         header
11373       ;; We have to really fetch the header to this article.
11374       (save-excursion
11375         (set-buffer nntp-server-buffer)
11376         (when (setq where (gnus-request-head id group))
11377           (nnheader-fold-continuation-lines)
11378           (goto-char (point-max))
11379           (insert ".\n")
11380           (goto-char (point-min))
11381           (insert "211 ")
11382           (princ (cond
11383                   ((numberp id) id)
11384                   ((cdr where) (cdr where))
11385                   (header (mail-header-number header))
11386                   (t gnus-reffed-article-number))
11387                  (current-buffer))
11388           (insert " Article retrieved.\n"))
11389         (if (or (not where)
11390                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11391             ()                          ; Malformed head.
11392           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11393             (when (and (stringp id)
11394                        (not (string= (gnus-group-real-name group)
11395                                      (car where))))
11396               ;; If we fetched by Message-ID and the article came
11397               ;; from a different group, we fudge some bogus article
11398               ;; numbers for this article.
11399               (mail-header-set-number header gnus-reffed-article-number))
11400             (save-excursion
11401               (set-buffer gnus-summary-buffer)
11402               (decf gnus-reffed-article-number)
11403               (gnus-remove-header (mail-header-number header))
11404               (push header gnus-newsgroup-headers)
11405               (setq gnus-current-headers header)
11406               (push (mail-header-number header) gnus-newsgroup-limit)))
11407           header)))))
11408
11409 (defun gnus-remove-header (number)
11410   "Remove header NUMBER from `gnus-newsgroup-headers'."
11411   (if (and gnus-newsgroup-headers
11412            (= number (mail-header-number (car gnus-newsgroup-headers))))
11413       (pop gnus-newsgroup-headers)
11414     (let ((headers gnus-newsgroup-headers))
11415       (while (and (cdr headers)
11416                   (not (= number (mail-header-number (cadr headers)))))
11417         (pop headers))
11418       (when (cdr headers)
11419         (setcdr headers (cddr headers))))))
11420
11421 ;;;
11422 ;;; summary highlights
11423 ;;;
11424
11425 (defun gnus-highlight-selected-summary ()
11426   "Highlight selected article in summary buffer."
11427   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11428   (when gnus-summary-selected-face
11429     (save-excursion
11430       (let* ((beg (point-at-bol))
11431              (end (point-at-eol))
11432              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11433              (from (if (get-text-property beg gnus-mouse-face-prop)
11434                        beg
11435                      (or (next-single-property-change
11436                           beg gnus-mouse-face-prop nil end)
11437                          beg)))
11438              (to
11439               (if (= from end)
11440                   (- from 2)
11441                 (or (next-single-property-change
11442                      from gnus-mouse-face-prop nil end)
11443                     end))))
11444         ;; If no mouse-face prop on line we will have to = from = end,
11445         ;; so we highlight the entire line instead.
11446         (when (= (+ to 2) from)
11447           (setq from beg)
11448           (setq to end))
11449         (if gnus-newsgroup-selected-overlay
11450             ;; Move old overlay.
11451             (gnus-move-overlay
11452              gnus-newsgroup-selected-overlay from to (current-buffer))
11453           ;; Create new overlay.
11454           (gnus-overlay-put
11455            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11456            'face gnus-summary-selected-face))))))
11457
11458 (defvar gnus-summary-highlight-line-cached nil)
11459 (defvar gnus-summary-highlight-line-trigger nil)
11460
11461 (defun gnus-summary-highlight-line-0 ()
11462   (if (and (eq gnus-summary-highlight-line-trigger
11463                gnus-summary-highlight)
11464            gnus-summary-highlight-line-cached)
11465       gnus-summary-highlight-line-cached
11466     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11467           gnus-summary-highlight-line-cached
11468           (let* ((cond (list 'cond))
11469                  (c cond)
11470                  (list gnus-summary-highlight))
11471             (while list
11472               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11473                               nil))
11474               (setq c (cdr c)
11475                     list (cdr list)))
11476             (gnus-byte-compile (list 'lambda nil cond))))))
11477
11478 (defun gnus-summary-highlight-line ()
11479   "Highlight current line according to `gnus-summary-highlight'."
11480   (let* ((beg (point-at-bol))
11481          (article (or (gnus-summary-article-number) gnus-current-article))
11482          (score (or (cdr (assq article
11483                                gnus-newsgroup-scored))
11484                     gnus-summary-default-score 0))
11485          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11486          (inhibit-read-only t)
11487          (default gnus-summary-default-score)
11488          (default-high gnus-summary-default-high-score)
11489          (default-low gnus-summary-default-low-score)
11490          (uncached (and gnus-summary-use-undownloaded-faces
11491                         (memq article gnus-newsgroup-undownloaded)
11492                         (not (memq article gnus-newsgroup-cached)))))
11493     (let ((face (funcall (gnus-summary-highlight-line-0))))
11494       (unless (eq face (get-text-property beg 'face))
11495         (gnus-put-text-property-excluding-characters-with-faces
11496          beg (point-at-eol) 'face
11497          (setq face (if (boundp face) (symbol-value face) face)))
11498         (when gnus-summary-highlight-line-function
11499           (funcall gnus-summary-highlight-line-function article face))))))
11500
11501 (defun gnus-update-read-articles (group unread &optional compute)
11502   "Update the list of read articles in GROUP.
11503 UNREAD is a sorted list."
11504   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11505         (info (gnus-get-info group))
11506         (prev 1)
11507         read)
11508     (if (or (not info) (not active))
11509         ;; There is no info on this group if it was, in fact,
11510         ;; killed.  Gnus stores no information on killed groups, so
11511         ;; there's nothing to be done.
11512         ;; One could store the information somewhere temporarily,
11513         ;; perhaps...  Hmmm...
11514         ()
11515       ;; Remove any negative articles numbers.
11516       (while (and unread (< (car unread) 0))
11517         (setq unread (cdr unread)))
11518       ;; Remove any expired article numbers
11519       (while (and unread (< (car unread) (car active)))
11520         (setq unread (cdr unread)))
11521       ;; Compute the ranges of read articles by looking at the list of
11522       ;; unread articles.
11523       (while unread
11524         (when (/= (car unread) prev)
11525           (push (if (= prev (1- (car unread))) prev
11526                   (cons prev (1- (car unread))))
11527                 read))
11528         (setq prev (1+ (car unread)))
11529         (setq unread (cdr unread)))
11530       (when (<= prev (cdr active))
11531         (push (cons prev (cdr active)) read))
11532       (setq read (if (> (length read) 1) (nreverse read) read))
11533       (if compute
11534           read
11535         (save-excursion
11536           (let (setmarkundo)
11537             ;; Propagate the read marks to the backend.
11538             (when (gnus-check-backend-function 'request-set-mark group)
11539               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11540                     (add (gnus-remove-from-range read (gnus-info-read info))))
11541                 (when (or add del)
11542                   (unless (gnus-check-group group)
11543                     (error "Can't open server for %s" group))
11544                   (gnus-request-set-mark
11545                    group (delq nil (list (if add (list add 'add '(read)))
11546                                          (if del (list del 'del '(read))))))
11547                   (setq setmarkundo
11548                         `(gnus-request-set-mark
11549                           ,group
11550                           ',(delq nil (list
11551                                        (if del (list del 'add '(read)))
11552                                        (if add (list add 'del '(read))))))))))
11553             (set-buffer gnus-group-buffer)
11554             (gnus-undo-register
11555               `(progn
11556                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11557                  (gnus-info-set-read ',info ',(gnus-info-read info))
11558                  (gnus-get-unread-articles-in-group ',info
11559                                                     (gnus-active ,group))
11560                  (gnus-group-update-group ,group t)
11561                  ,setmarkundo))))
11562         ;; Enter this list into the group info.
11563         (gnus-info-set-read info read)
11564         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11565         (gnus-get-unread-articles-in-group info (gnus-active group))
11566         t))))
11567
11568 (defun gnus-offer-save-summaries ()
11569   "Offer to save all active summary buffers."
11570   (let (buffers)
11571     ;; Go through all buffers and find all summaries.
11572     (dolist (buffer (buffer-list))
11573       (when (and (setq buffer (buffer-name buffer))
11574                  (string-match "Summary" buffer)
11575                  (with-current-buffer buffer
11576                    ;; We check that this is, indeed, a summary buffer.
11577                    (and (eq major-mode 'gnus-summary-mode)
11578                         ;; Also make sure this isn't bogus.
11579                         gnus-newsgroup-prepared
11580                         ;; Also make sure that this isn't a
11581                         ;; dead summary buffer.
11582                         (not gnus-dead-summary-mode))))
11583         (push buffer buffers)))
11584     ;; Go through all these summary buffers and offer to save them.
11585     (when buffers
11586       (save-excursion
11587         (map-y-or-n-p
11588          "Update summary buffer %s? "
11589          (lambda (buf)
11590            (switch-to-buffer buf)
11591            (gnus-summary-exit))
11592          buffers)))))
11593
11594 (defun gnus-summary-setup-default-charset ()
11595   "Setup newsgroup default charset."
11596   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11597       (setq gnus-newsgroup-charset nil)
11598     (let* ((ignored-charsets
11599             (or gnus-newsgroup-ephemeral-ignored-charsets
11600                 (append
11601                  (and gnus-newsgroup-name
11602                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11603                  gnus-newsgroup-ignored-charsets))))
11604       (setq gnus-newsgroup-charset
11605             (or gnus-newsgroup-ephemeral-charset
11606                 (and gnus-newsgroup-name
11607                      (gnus-parameter-charset gnus-newsgroup-name))
11608                 gnus-default-charset))
11609       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11610            ignored-charsets))))
11611
11612 ;;;
11613 ;;; Mime Commands
11614 ;;;
11615
11616 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11617   "Display the current article buffer fully MIME-buttonized.
11618 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11619 treated as multipart/mixed."
11620   (interactive "P")
11621   (require 'gnus-art)
11622   (let ((gnus-unbuttonized-mime-types nil)
11623         (gnus-mime-display-multipart-as-mixed show-all-parts))
11624     (gnus-summary-show-article)))
11625
11626 (defun gnus-summary-repair-multipart (article)
11627   "Add a Content-Type header to a multipart article without one."
11628   (interactive (list (gnus-summary-article-number)))
11629   (gnus-with-article article
11630     (message-narrow-to-head)
11631     (message-remove-header "Mime-Version")
11632     (goto-char (point-max))
11633     (insert "Mime-Version: 1.0\n")
11634     (widen)
11635     (when (search-forward "\n--" nil t)
11636       (let ((separator (buffer-substring (point) (point-at-eol))))
11637         (message-narrow-to-head)
11638         (message-remove-header "Content-Type")
11639         (goto-char (point-max))
11640         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11641                         separator))
11642         (widen))))
11643   (let (gnus-mark-article-hook)
11644     (gnus-summary-select-article t t nil article)))
11645
11646 (defun gnus-summary-toggle-display-buttonized ()
11647   "Toggle the buttonizing of the article buffer."
11648   (interactive)
11649   (require 'gnus-art)
11650   (if (setq gnus-inhibit-mime-unbuttonizing
11651             (not gnus-inhibit-mime-unbuttonizing))
11652       (let ((gnus-unbuttonized-mime-types nil))
11653         (gnus-summary-show-article))
11654     (gnus-summary-show-article)))
11655
11656 ;;;
11657 ;;; Generic summary marking commands
11658 ;;;
11659
11660 (defvar gnus-summary-marking-alist
11661   '((read gnus-del-mark "d")
11662     (unread gnus-unread-mark "u")
11663     (ticked gnus-ticked-mark "!")
11664     (dormant gnus-dormant-mark "?")
11665     (expirable gnus-expirable-mark "e"))
11666   "An alist of names/marks/keystrokes.")
11667
11668 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11669 (defvar gnus-summary-mark-map)
11670
11671 (defun gnus-summary-make-all-marking-commands ()
11672   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11673   (dolist (elem gnus-summary-marking-alist)
11674     (apply 'gnus-summary-make-marking-command elem)))
11675
11676 (defun gnus-summary-make-marking-command (name mark keystroke)
11677   (let ((map (make-sparse-keymap)))
11678     (define-key gnus-summary-generic-mark-map keystroke map)
11679     (dolist (lway `((next "next" next nil "n")
11680                     (next-unread "next unread" next t "N")
11681                     (prev "previous" prev nil "p")
11682                     (prev-unread "previous unread" prev t "P")
11683                     (nomove "" nil nil ,keystroke)))
11684       (let ((func (gnus-summary-make-marking-command-1
11685                    mark (car lway) lway name)))
11686         (setq func (eval func))
11687         (define-key map (nth 4 lway) func)))))
11688
11689 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11690   `(defun ,(intern
11691             (format "gnus-summary-put-mark-as-%s%s"
11692                     name (if (eq way 'nomove)
11693                              ""
11694                            (concat "-" (symbol-name way)))))
11695      (n)
11696      ,(format
11697        "Mark the current article as %s%s.
11698 If N, the prefix, then repeat N times.
11699 If N is negative, move in reverse order.
11700 The difference between N and the actual number of articles marked is
11701 returned."
11702        name (cadr lway))
11703      (interactive "p")
11704      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11705
11706 (defun gnus-summary-generic-mark (n mark move unread)
11707   "Mark N articles with MARK."
11708   (unless (eq major-mode 'gnus-summary-mode)
11709     (error "This command can only be used in the summary buffer"))
11710   (gnus-summary-show-thread)
11711   (let ((nummove
11712          (cond
11713           ((eq move 'next) 1)
11714           ((eq move 'prev) -1)
11715           (t 0))))
11716     (if (zerop nummove)
11717         (setq n 1)
11718       (when (< n 0)
11719         (setq n (abs n)
11720               nummove (* -1 nummove))))
11721     (while (and (> n 0)
11722                 (gnus-summary-mark-article nil mark)
11723                 (zerop (gnus-summary-next-subject nummove unread t)))
11724       (setq n (1- n)))
11725     (when (/= 0 n)
11726       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11727     (gnus-summary-recenter)
11728     (gnus-summary-position-point)
11729     (gnus-set-mode-line 'summary)
11730     n))
11731
11732 (defun gnus-summary-insert-articles (articles)
11733   (when (setq articles
11734               (gnus-sorted-difference articles
11735                                       (mapcar (lambda (h)
11736                                                 (mail-header-number h))
11737                                               gnus-newsgroup-headers)))
11738     (setq gnus-newsgroup-headers
11739           (gnus-merge 'list
11740                       gnus-newsgroup-headers
11741                       (gnus-fetch-headers articles)
11742                       'gnus-article-sort-by-number))
11743     ;; Suppress duplicates?
11744     (when gnus-suppress-duplicates
11745       (gnus-dup-suppress-articles))
11746
11747     ;; We might want to build some more threads first.
11748     (when (and gnus-fetch-old-headers
11749                (eq gnus-headers-retrieved-by 'nov))
11750       (if (eq gnus-fetch-old-headers 'invisible)
11751           (gnus-build-all-threads)
11752         (gnus-build-old-threads)))
11753     ;; Let the Gnus agent mark articles as read.
11754     (when gnus-agent
11755       (gnus-agent-get-undownloaded-list))
11756     ;; Remove list identifiers from subject
11757     (when gnus-list-identifiers
11758       (gnus-summary-remove-list-identifiers))
11759     ;; First and last article in this newsgroup.
11760     (when gnus-newsgroup-headers
11761       (setq gnus-newsgroup-begin
11762             (mail-header-number (car gnus-newsgroup-headers))
11763             gnus-newsgroup-end
11764             (mail-header-number
11765              (gnus-last-element gnus-newsgroup-headers))))
11766     (when gnus-use-scoring
11767       (gnus-possibly-score-headers))))
11768
11769 (defun gnus-summary-insert-old-articles (&optional all)
11770   "Insert all old articles in this group.
11771 If ALL is non-nil, already read articles become readable.
11772 If ALL is a number, fetch this number of articles."
11773   (interactive "P")
11774   (prog1
11775       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11776             older len)
11777         (setq older
11778               ;; Some nntp servers lie about their active range.  When
11779               ;; this happens, the active range can be in the millions.
11780               ;; Use a compressed range to avoid creating a huge list.
11781               (gnus-range-difference (list gnus-newsgroup-active) old))
11782         (setq len (gnus-range-length older))
11783         (cond
11784          ((null older) nil)
11785          ((numberp all)
11786           (if (< all len)
11787               (let ((older-range (nreverse older)))
11788                 (setq older nil)
11789
11790                 (while (> all 0)
11791                   (let* ((r (pop older-range))
11792                          (min (if (numberp r) r (car r)))
11793                          (max (if (numberp r) r (cdr r))))
11794                     (while (and (<= min max)
11795                                 (> all 0))
11796                       (push max older)
11797                       (setq all (1- all)
11798                             max (1- max))))))
11799             (setq older (gnus-uncompress-range older))))
11800          (all
11801           (setq older (gnus-uncompress-range older)))
11802          (t
11803           (when (and (numberp gnus-large-newsgroup)
11804                    (> len gnus-large-newsgroup))
11805               (let* ((cursor-in-echo-area nil)
11806                      (initial (gnus-parameter-large-newsgroup-initial
11807                                gnus-newsgroup-name))
11808                      (input
11809                       (read-string
11810                        (format
11811                         "How many articles from %s (%s %d): "
11812                         (gnus-limit-string
11813                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11814                         (if initial "max" "default")
11815                         len)
11816                        (if initial
11817                            (cons (number-to-string initial)
11818                                  0)))))
11819                 (unless (string-match "^[ \t]*$" input)
11820                   (setq all (string-to-number input))
11821                   (if (< all len)
11822                       (let ((older-range (nreverse older)))
11823                         (setq older nil)
11824
11825                         (while (> all 0)
11826                           (let* ((r (pop older-range))
11827                                  (min (if (numberp r) r (car r)))
11828                                  (max (if (numberp r) r (cdr r))))
11829                             (while (and (<= min max)
11830                                         (> all 0))
11831                               (push max older)
11832                               (setq all (1- all)
11833                                     max (1- max))))))))))
11834           (setq older (gnus-uncompress-range older))))
11835         (if (not older)
11836             (message "No old news.")
11837           (gnus-summary-insert-articles older)
11838           (gnus-summary-limit (gnus-sorted-nunion old older))))
11839     (gnus-summary-position-point)))
11840
11841 (defun gnus-summary-insert-new-articles ()
11842   "Insert all new articles in this group."
11843   (interactive)
11844   (prog1
11845       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11846             (old-active gnus-newsgroup-active)
11847             (nnmail-fetched-sources (list t))
11848             i new)
11849         (setq gnus-newsgroup-active
11850               (gnus-activate-group gnus-newsgroup-name 'scan))
11851         (setq i (cdr gnus-newsgroup-active))
11852         (while (> i (cdr old-active))
11853           (push i new)
11854           (decf i))
11855         (if (not new)
11856             (message "No gnus is bad news")
11857           (gnus-summary-insert-articles new)
11858           (setq gnus-newsgroup-unreads
11859                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11860           (gnus-summary-limit (gnus-sorted-nunion old new))))
11861     (gnus-summary-position-point)))
11862
11863 (gnus-summary-make-all-marking-commands)
11864
11865 (gnus-ems-redefine)
11866
11867 (provide 'gnus-sum)
11868
11869 (run-hooks 'gnus-sum-load-hook)
11870
11871 ;; Local Variables:
11872 ;; coding: iso-8859-1
11873 ;; End:
11874
11875 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
11876 ;;; gnus-sum.el ends here