56ec9b1b53d689db4bad5a9da3ef0203ded2c26c
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile (require 'cl))
32 (eval-when-compile (require 'gnus-clfns))
33
34 (require 'gnus)
35 (require 'gnus-group)
36 (require 'gnus-spec)
37 (require 'gnus-range)
38 (require 'gnus-int)
39 (require 'gnus-undo)
40 (require 'gnus-util)
41 (require 'nnoo)
42 (require 'mime-view)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
55 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
56 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify" 
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61
62 (defcustom gnus-kill-summary-on-exit t
63   "*If non-nil, kill the summary buffer when you exit from it.
64 If nil, the summary will become a \"*Dead Summary*\" buffer, and
65 it will be killed sometime later."
66   :group 'gnus-summary-exit
67   :type 'boolean)
68
69 (defcustom gnus-fetch-old-headers nil
70   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
71 If an unread article in the group refers to an older, already read (or
72 just marked as read) article, the old article will not normally be
73 displayed in the Summary buffer.  If this variable is non-nil, Gnus
74 will attempt to grab the headers to the old articles, and thereby
75 build complete threads.  If it has the value `some', only enough
76 headers to connect otherwise loose threads will be displayed.  This
77 variable can also be a number.  In that case, no more than that number
78 of old headers will be fetched.  If it has the value `invisible', all
79 old headers will be fetched, but none will be displayed.
80
81 The server has to support NOV for any of this to work."
82   :group 'gnus-thread
83   :type '(choice (const :tag "off" nil)
84                  (const some)
85                  number
86                  (sexp :menu-tag "other" t)))
87
88 (defcustom gnus-refer-thread-limit 200
89   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
90 If t, fetch all the available old headers."
91   :group 'gnus-thread
92   :type '(choice number
93                  (sexp :menu-tag "other" t)))
94
95 (defcustom gnus-summary-make-false-root 'adopt
96   "*nil means that Gnus won't gather loose threads.
97 If the root of a thread has expired or been read in a previous
98 session, the information necessary to build a complete thread has been
99 lost.  Instead of having many small sub-threads from this original thread
100 scattered all over the summary buffer, Gnus can gather them.
101
102 If non-nil, Gnus will try to gather all loose sub-threads from an
103 original thread into one large thread.
104
105 If this variable is non-nil, it should be one of `none', `adopt',
106 `dummy' or `empty'.
107
108 If this variable is `none', Gnus will not make a false root, but just
109 present the sub-threads after another.
110 If this variable is `dummy', Gnus will create a dummy root that will
111 have all the sub-threads as children.
112 If this variable is `adopt', Gnus will make one of the \"children\"
113 the parent and mark all the step-children as such.
114 If this variable is `empty', the \"children\" are printed with empty
115 subject fields.  (Or rather, they will be printed with a string
116 given by the `gnus-summary-same-subject' variable.)"
117   :group 'gnus-thread
118   :type '(choice (const :tag "off" nil)
119                  (const none)
120                  (const dummy)
121                  (const adopt)
122                  (const empty)))
123
124 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
125   "*A regexp to match subjects to be excluded from loose thread gathering.
126 As loose thread gathering is done on subjects only, that means that
127 there can be many false gatherings performed.  By rooting out certain
128 common subjects, gathering might become saner."
129   :group 'gnus-thread
130   :type 'regexp)
131
132 (defcustom gnus-summary-gather-subject-limit nil
133   "*Maximum length of subject comparisons when gathering loose threads.
134 Use nil to compare full subjects.  Setting this variable to a low
135 number will help gather threads that have been corrupted by
136 newsreaders chopping off subject lines, but it might also mean that
137 unrelated articles that have subject that happen to begin with the
138 same few characters will be incorrectly gathered.
139
140 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
141 comparing subjects."
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const fuzzy)
145                  (sexp :menu-tag "on" t)))
146
147 (defcustom gnus-simplify-subject-functions nil
148   "List of functions taking a string argument that simplify subjects.
149 The functions are applied recursively.
150
151 Useful functions to put in this list include: `gnus-simplify-subject-re',
152 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 (they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type 'boolean)
258
259 (defcustom gnus-thread-hide-killed t
260   "*If non-nil, hide killed threads automatically."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-ignore-subject t
265   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
266 If nil, articles that have different subjects from their parents will
267 start separate threads."
268   :group 'gnus-thread
269   :type 'boolean)
270
271 (defcustom gnus-thread-operation-ignore-subject t
272   "*If non-nil, subjects will be ignored when doing thread commands.
273 This affects commands like `gnus-summary-kill-thread' and
274 `gnus-summary-lower-thread'.
275
276 If this variable is nil, articles in the same thread with different
277 subjects will not be included in the operation in question.  If this
278 variable is `fuzzy', only articles that have subjects that are fuzzily
279 equal will be included."
280   :group 'gnus-thread
281   :type '(choice (const :tag "off" nil)
282                  (const fuzzy)
283                  (sexp :tag "on" t)))
284
285 (defcustom gnus-thread-indent-level 4
286   "*Number that says how much each sub-thread should be indented."
287   :group 'gnus-thread
288   :type 'integer)
289
290 (defcustom gnus-auto-extend-newsgroup t
291   "*If non-nil, extend newsgroup forward and backward when requested."
292   :group 'gnus-summary-choose
293   :type 'boolean)
294
295 (defcustom gnus-auto-select-first t
296   "*If non-nil, select the article under point.
297 Which article this is is controlled by the `gnus-auto-select-subject'
298 variable.
299
300 If you want to prevent automatic selection of articles in some
301 newsgroups, set the variable to nil in `gnus-select-group-hook'."
302   :group 'gnus-group-select
303   :type '(choice (const :tag "none" nil)
304                  (sexp :menu-tag "first" t)))
305
306 (defcustom gnus-auto-select-subject 'unread
307   "*Says what subject to place under point when entering a group.
308
309 This variable can either be the symbols `first' (place point on the
310 first subject), `unread' (place point on the subject line of the first
311 unread article), `best' (place point on the subject line of the
312 higest-scored article), `unseen' (place point on the subject line of
313 the first unseen article), 'unseen-or-unread' (place point on the subject
314 line of the first unseen article or, if all article have been seen, on the
315 subject line of the first unread article), or a function to be called to
316 place point on some subject line."
317   :group 'gnus-group-select
318   :type '(choice (const best)
319                  (const unread)
320                  (const first)
321                  (const unseen)
322                  (const unseen-or-unread)))
323
324 (defcustom gnus-dont-select-after-jump-to-other-group nil
325   "If non-nil, don't select the first unread article after entering the
326 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
327 it is depend on the value of `gnus-auto-select-first' whether to select
328 or not."
329   :group 'gnus-group-select
330   :type 'boolean)
331
332 (defcustom gnus-auto-select-next t
333   "*If non-nil, offer to go to the next group from the end of the previous.
334 If the value is t and the next newsgroup is empty, Gnus will exit
335 summary mode and go back to group mode.  If the value is neither nil
336 nor t, Gnus will select the following unread newsgroup.  In
337 particular, if the value is the symbol `quietly', the next unread
338 newsgroup will be selected without any confirmation, and if it is
339 `almost-quietly', the next group will be selected without any
340 confirmation if you are located on the last article in the group.
341 Finally, if this variable is `slightly-quietly', the `Z n' command
342 will go to the next group without confirmation."
343   :group 'gnus-summary-maneuvering
344   :type '(choice (const :tag "off" nil)
345                  (const quietly)
346                  (const almost-quietly)
347                  (const slightly-quietly)
348                  (sexp :menu-tag "on" t)))
349
350 (defcustom gnus-auto-select-same nil
351   "*If non-nil, select the next article with the same subject.
352 If there are no more articles with the same subject, go to
353 the first unread article."
354   :group 'gnus-summary-maneuvering
355   :type 'boolean)
356
357 (defcustom gnus-summary-check-current nil
358   "*If non-nil, consider the current article when moving.
359 The \"unread\" movement commands will stay on the same line if the
360 current article is unread."
361   :group 'gnus-summary-maneuvering
362   :type 'boolean)
363
364 (defcustom gnus-auto-center-summary t
365   "*If non-nil, always center the current summary buffer.
366 In particular, if `vertical' do only vertical recentering.  If non-nil
367 and non-`vertical', do both horizontal and vertical recentering."
368   :group 'gnus-summary-maneuvering
369   :type '(choice (const :tag "none" nil)
370                  (const vertical)
371                  (integer :tag "height")
372                  (sexp :menu-tag "both" t)))
373
374 (defcustom gnus-show-all-headers nil
375   "*If non-nil, don't hide any headers."
376   :group 'gnus-article-hiding
377   :group 'gnus-article-headers
378   :type 'boolean)
379
380 (defcustom gnus-summary-ignore-duplicates nil
381   "*If non-nil, ignore articles with identical Message-ID headers."
382   :group 'gnus-summary
383   :type 'boolean)
384
385 (defcustom gnus-single-article-buffer t
386   "*If non-nil, display all articles in the same buffer.
387 If nil, each group will get its own article buffer."
388   :group 'gnus-article-various
389   :type 'boolean)
390
391 (defcustom gnus-break-pages t
392   "*If non-nil, do page breaking on articles.
393 The page delimiter is specified by the `gnus-page-delimiter'
394 variable."
395   :group 'gnus-article-various
396   :type 'boolean)
397
398 (defcustom gnus-show-mime t
399   "*If non-nil, do mime processing of articles.
400 The articles will simply be fed to the function given by
401 `gnus-article-display-method-for-mime'."
402   :group 'gnus-article-mime
403   :type 'boolean)
404
405 (defcustom gnus-move-split-methods nil
406   "*Variable used to suggest where articles are to be moved to.
407 It uses the same syntax as the `gnus-split-methods' variable.
408 However, whereas `gnus-split-methods' specifies file names as targets,
409 this variable specifies group names."
410   :group 'gnus-summary-mail
411   :type '(repeat (choice (list :value (fun) function)
412                          (cons :value ("" "") regexp (repeat string))
413                          (sexp :value nil))))
414
415 (defcustom gnus-unread-mark ?\ ;;;Whitespace
416   "*Mark used for unread articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-ticked-mark ?!
421   "*Mark used for ticked articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-dormant-mark ??
426   "*Mark used for dormant articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-del-mark ?r
431   "*Mark used for del'd articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-read-mark ?R
436   "*Mark used for read articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-expirable-mark ?E
441   "*Mark used for expirable articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-killed-mark ?K
446   "*Mark used for killed articles."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-souped-mark ?F
451   "*Mark used for souped articles."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-kill-file-mark ?X
456   "*Mark used for articles killed by kill files."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-low-score-mark ?Y
461   "*Mark used for articles with a low score."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-catchup-mark ?C
466   "*Mark used for articles that are caught up."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-replied-mark ?A
471   "*Mark used for articles that have been replied to."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-forwarded-mark ?F
476   "*Mark used for articles that have been forwarded."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-recent-mark ?N
481   "*Mark used for articles that are recent."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-cached-mark ?*
486   "*Mark used for articles that are in the cache."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-saved-mark ?S
491   "*Mark used for articles that have been saved."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-unseen-mark ?.
496   "*Mark used for articles that haven't been seen."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-no-mark ?\ ;;;Whitespace
501   "*Mark used for articles that have no other secondary mark."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ancient-mark ?O
506   "*Mark used for ancient articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-sparse-mark ?Q
511   "*Mark used for sparsely reffed articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-canceled-mark ?G
516   "*Mark used for canceled articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-duplicate-mark ?M
521   "*Mark used for duplicate articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-undownloaded-mark ?@
526   "*Mark used for articles that weren't downloaded."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-downloadable-mark ?%
531   "*Mark used for articles that are to be downloaded."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-unsendable-mark ?=
536   "*Mark used for articles that won't be sent."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-score-over-mark ?+
541   "*Score mark used for articles with high scores."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-score-below-mark ?-
546   "*Score mark used for articles with low scores."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
551   "*There is no thread under the article."
552   :group 'gnus-summary-marks
553   :type 'character)
554
555 (defcustom gnus-not-empty-thread-mark ?=
556   "*There is a thread under the article."
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-view-pseudo-asynchronously nil
561   "*If non-nil, Gnus will view pseudo-articles asynchronously."
562   :group 'gnus-extract-view
563   :type 'boolean)
564
565 (defcustom gnus-auto-expirable-marks
566   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
567         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
568         gnus-souped-mark gnus-duplicate-mark)
569   "*The list of marks converted into expiration if a group is auto-expirable."
570   :version "21.1"
571   :group 'gnus-summary
572   :type '(repeat character))
573
574 (defcustom gnus-inhibit-user-auto-expire t
575   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
576   :version "21.1"
577   :group 'gnus-summary
578   :type 'boolean)
579
580 (defcustom gnus-view-pseudos nil
581   "*If `automatic', pseudo-articles will be viewed automatically.
582 If `not-confirm', pseudos will be viewed automatically, and the user
583 will not be asked to confirm the command."
584   :group 'gnus-extract-view
585   :type '(choice (const :tag "off" nil)
586                  (const automatic)
587                  (const not-confirm)))
588
589 (defcustom gnus-view-pseudos-separately t
590   "*If non-nil, one pseudo-article will be created for each file to be viewed.
591 If nil, all files that use the same viewing command will be given as a
592 list of parameters to that command."
593   :group 'gnus-extract-view
594   :type 'boolean)
595
596 (defcustom gnus-insert-pseudo-articles t
597   "*If non-nil, insert pseudo-articles when decoding articles."
598   :group 'gnus-extract-view
599   :type 'boolean)
600
601 (defcustom gnus-summary-dummy-line-format
602   "  %(:                          :%) %S\n"
603   "*The format specification for the dummy roots in the summary buffer.
604 It works along the same lines as a normal formatting string,
605 with some simple extensions.
606
607 %S  The subject
608
609 General format specifiers can also be used.
610 See (gnus)Formatting Variables."
611   :link '(custom-manual "(gnus)Formatting Variables")
612   :group 'gnus-threading
613   :type 'string)
614
615 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
616   "*The format specification for the summary mode line.
617 It works along the same lines as a normal formatting string,
618 with some simple extensions:
619
620 %G  Group name
621 %p  Unprefixed group name
622 %A  Current article number
623 %z  Current article score
624 %V  Gnus version
625 %U  Number of unread articles in the group
626 %e  Number of unselected articles in the group
627 %Z  A string with unread/unselected article counts
628 %g  Shortish group name
629 %S  Subject of the current article
630 %u  User-defined spec
631 %s  Current score file name
632 %d  Number of dormant articles
633 %r  Number of articles that have been marked as read in this session
634 %E  Number of articles expunged by the score files"
635   :group 'gnus-summary-format
636   :type 'string)
637
638 (defcustom gnus-list-identifiers nil
639   "Regexp that matches list identifiers to be removed from subject.
640 This can also be a list of regexps."
641   :version "21.1"
642   :group 'gnus-summary-format
643   :group 'gnus-article-hiding
644   :type '(choice (const :tag "none" nil)
645                  (regexp :value ".*")
646                  (repeat :value (".*") regexp)))
647
648 (defcustom gnus-summary-mark-below 0
649   "*Mark all articles with a score below this variable as read.
650 This variable is local to each summary buffer and usually set by the
651 score file."
652   :group 'gnus-score-default
653   :type 'integer)
654
655 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
656   "*List of functions used for sorting articles in the summary buffer.
657
658 Each function takes two articles and returns non-nil if the first
659 article should be sorted before the other.  If you use more than one
660 function, the primary sort function should be the last.  You should
661 probably always include `gnus-article-sort-by-number' in the list of
662 sorting functions -- preferably first.  Also note that sorting by date
663 is often much slower than sorting by number, and the sorting order is
664 very similar.  (Sorting by date means sorting by the time the message
665 was sent, sorting by number means sorting by arrival time.)
666
667 Ready-made functions include `gnus-article-sort-by-number',
668 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
669 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
670
671 When threading is turned on, the variable `gnus-thread-sort-functions'
672 controls how articles are sorted."
673   :group 'gnus-summary-sort
674   :type '(repeat (choice (function-item gnus-article-sort-by-number)
675                          (function-item gnus-article-sort-by-author)
676                          (function-item gnus-article-sort-by-subject)
677                          (function-item gnus-article-sort-by-date)
678                          (function-item gnus-article-sort-by-score)
679                          (function :tag "other"))))
680
681 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
682   "*List of functions used for sorting threads in the summary buffer.
683 By default, threads are sorted by article number.
684
685 Each function takes two threads and returns non-nil if the first
686 thread should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-thread-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-thread-sort-by-number',
695 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
696 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
697 `gnus-thread-sort-by-most-recent-number',
698 `gnus-thread-sort-by-most-recent-date', and
699 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
700
701 When threading is turned off, the variable
702 `gnus-article-sort-functions' controls how articles are sorted."
703   :group 'gnus-summary-sort
704   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
705                          (function-item gnus-thread-sort-by-author)
706                          (function-item gnus-thread-sort-by-subject)
707                          (function-item gnus-thread-sort-by-date)
708                          (function-item gnus-thread-sort-by-score)
709                          (function-item gnus-thread-sort-by-total-score)
710                          (function :tag "other"))))
711
712 (defcustom gnus-thread-score-function '+
713   "*Function used for calculating the total score of a thread.
714
715 The function is called with the scores of the article and each
716 subthread and should then return the score of the thread.
717
718 Some functions you can use are `+', `max', or `min'."
719   :group 'gnus-summary-sort
720   :type 'function)
721
722 (defcustom gnus-summary-expunge-below nil
723   "All articles that have a score less than this variable will be expunged.
724 This variable is local to the summary buffers."
725   :group 'gnus-score-default
726   :type '(choice (const :tag "off" nil)
727                  integer))
728
729 (defcustom gnus-thread-expunge-below nil
730   "All threads that have a total score less than this variable will be expunged.
731 See `gnus-thread-score-function' for en explanation of what a
732 \"thread score\" is.
733
734 This variable is local to the summary buffers."
735   :group 'gnus-threading
736   :group 'gnus-score-default
737   :type '(choice (const :tag "off" nil)
738                  integer))
739
740 (defcustom gnus-summary-mode-hook nil
741   "*A hook for Gnus summary mode.
742 This hook is run before any variables are set in the summary buffer."
743   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
744   :group 'gnus-summary-various
745   :type 'hook)
746
747 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
748 (when (featurep 'xemacs)
749   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
750   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
751   (add-hook 'gnus-summary-mode-hook
752             'gnus-xmas-switch-horizontal-scrollbar-off))
753
754 (defcustom gnus-summary-menu-hook nil
755   "*Hook run after the creation of the summary mode menu."
756   :group 'gnus-summary-visual
757   :type 'hook)
758
759 (defcustom gnus-summary-exit-hook nil
760   "*A hook called on exit from the summary buffer.
761 It will be called with point in the group buffer."
762   :group 'gnus-summary-exit
763   :type 'hook)
764
765 (defcustom gnus-summary-prepare-hook nil
766   "*A hook called after the summary buffer has been generated.
767 If you want to modify the summary buffer, you can use this hook."
768   :group 'gnus-summary-various
769   :type 'hook)
770
771 (defcustom gnus-summary-prepared-hook nil
772   "*A hook called as the last thing after the summary buffer has been generated."
773   :group 'gnus-summary-various
774   :type 'hook)
775
776 (defcustom gnus-summary-generate-hook nil
777   "*A hook run just before generating the summary buffer.
778 This hook is commonly used to customize threading variables and the
779 like."
780   :group 'gnus-summary-various
781   :type 'hook)
782
783 (defcustom gnus-select-group-hook nil
784   "*A hook called when a newsgroup is selected.
785
786 If you'd like to simplify subjects like the
787 `gnus-summary-next-same-subject' command does, you can use the
788 following hook:
789
790  (add-hook gnus-select-group-hook
791            (lambda ()
792              (mapcar (lambda (header)
793                        (mail-header-set-subject
794                         header
795                         (gnus-simplify-subject
796                          (mail-header-subject header) 're-only)))
797                      gnus-newsgroup-headers)))"
798   :group 'gnus-group-select
799   :type 'hook)
800
801 (defcustom gnus-select-article-hook nil
802   "*A hook called when an article is selected."
803   :group 'gnus-summary-choose
804   :type 'hook)
805
806 (defcustom gnus-visual-mark-article-hook
807   (list 'gnus-highlight-selected-summary)
808   "*Hook run after selecting an article in the summary buffer.
809 It is meant to be used for highlighting the article in some way.  It
810 is not run if `gnus-visual' is nil."
811   :group 'gnus-summary-visual
812   :type 'hook)
813
814 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
815   "*A hook called before parsing the headers."
816   :group 'gnus-various
817   :type 'hook)
818
819 (defcustom gnus-exit-group-hook nil
820   "*A hook called when exiting summary mode.
821 This hook is not called from the non-updating exit commands like `Q'."
822   :group 'gnus-various
823   :type 'hook)
824
825 (defcustom gnus-summary-update-hook
826   (list 'gnus-summary-highlight-line)
827   "*A hook called when a summary line is changed.
828 The hook will not be called if `gnus-visual' is nil.
829
830 The default function `gnus-summary-highlight-line' will
831 highlight the line according to the `gnus-summary-highlight'
832 variable."
833   :group 'gnus-summary-visual
834   :type 'hook)
835
836 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
837   "*A hook called when an article is selected for the first time.
838 The hook is intended to mark an article as read (or unread)
839 automatically when it is selected."
840   :group 'gnus-summary-choose
841   :type 'hook)
842
843 (defcustom gnus-group-no-more-groups-hook nil
844   "*A hook run when returning to group mode having no more (unread) groups."
845   :group 'gnus-group-select
846   :type 'hook)
847
848 (defcustom gnus-ps-print-hook nil
849   "*A hook run before ps-printing something from Gnus."
850   :group 'gnus-summary
851   :type 'hook)
852
853 (defcustom gnus-summary-display-arrow
854   (and (fboundp 'display-graphic-p)
855        (display-graphic-p))
856   "*If non-nil, display an arrow highlighting the current article."
857   :version "21.1"
858   :group 'gnus-summary
859   :type 'boolean)
860
861 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
862   "Face used for highlighting the current article in the summary buffer."
863   :group 'gnus-summary-visual
864   :type 'face)
865
866 (defcustom gnus-summary-highlight
867   '(((= mark gnus-canceled-mark)
868      . gnus-summary-cancelled-face)
869     ((and (> score default-high)
870           (or (= mark gnus-dormant-mark)
871               (= mark gnus-ticked-mark)))
872      . gnus-summary-high-ticked-face)
873     ((and (< score default-low)
874           (or (= mark gnus-dormant-mark)
875               (= mark gnus-ticked-mark)))
876      . gnus-summary-low-ticked-face)
877     ((or (= mark gnus-dormant-mark)
878          (= mark gnus-ticked-mark))
879      . gnus-summary-normal-ticked-face)
880     ((and (> score default-high) (= mark gnus-ancient-mark))
881      . gnus-summary-high-ancient-face)
882     ((and (< score default-low) (= mark gnus-ancient-mark))
883      . gnus-summary-low-ancient-face)
884     ((= mark gnus-ancient-mark)
885      . gnus-summary-normal-ancient-face)
886     ((and (> score default-high) (= mark gnus-unread-mark))
887      . gnus-summary-high-unread-face)
888     ((and (< score default-low) (= mark gnus-unread-mark))
889      . gnus-summary-low-unread-face)
890     ((= mark gnus-unread-mark)
891      . gnus-summary-normal-unread-face)
892     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
893                                                   gnus-undownloaded-mark)))
894      . gnus-summary-high-unread-face)
895     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
896                                                  gnus-undownloaded-mark)))
897      . gnus-summary-low-unread-face)
898     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
899           (memq article gnus-newsgroup-unreads))
900      . gnus-summary-normal-unread-face)
901     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
902      . gnus-summary-normal-read-face)
903     ((> score default-high)
904      . gnus-summary-high-read-face)
905     ((< score default-low)
906      . gnus-summary-low-read-face)
907     (t
908      . gnus-summary-normal-read-face))
909   "*Controls the highlighting of summary buffer lines.
910
911 A list of (FORM . FACE) pairs.  When deciding how a a particular
912 summary line should be displayed, each form is evaluated.  The content
913 of the face field after the first true form is used.  You can change
914 how those summary lines are displayed, by editing the face field.
915
916 You can use the following variables in the FORM field.
917
918 score:        The article's score
919 default:      The default article score.
920 default-high: The default score for high scored articles.
921 default-low:  The default score for low scored articles.
922 below:        The score below which articles are automatically marked as read.
923 mark:         The articles mark."
924   :group 'gnus-summary-visual
925   :type '(repeat (cons (sexp :tag "Form" nil)
926                        face)))
927
928 (defcustom gnus-alter-header-function nil
929   "Function called to allow alteration of article header structures.
930 The function is called with one parameter, the article header vector,
931 which it may alter in any way.")
932
933 (defvar gnus-decode-encoded-word-function
934   (mime-find-field-decoder 'From 'nov)
935   "Variable that says which function should be used to decode a string with encoded words.")
936
937 (defcustom gnus-extra-headers '(To Newsgroups)
938   "*Extra headers to parse."
939   :version "21.1"
940   :group 'gnus-summary
941   :type '(repeat symbol))
942
943 (defcustom gnus-ignored-from-addresses
944   (and user-mail-address (regexp-quote user-mail-address))
945   "*Regexp of From headers that may be suppressed in favor of To headers."
946   :version "21.1"
947   :group 'gnus-summary
948   :type 'regexp)
949
950 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
951   "List of charsets that should be ignored.
952 When these charsets are used in the \"charset\" parameter, the
953 default charset will be used instead."
954   :version "21.1"
955   :type '(repeat symbol)
956   :group 'gnus-charset)
957
958 (gnus-define-group-parameter
959  ignored-charsets
960  :type list
961  :function-document
962  "Return the ignored charsets of GROUP."
963  :variable gnus-group-ignored-charsets-alist
964  :variable-default
965  '(("alt\\.chinese\\.text" iso-8859-1))
966  :variable-document
967  "Alist of regexps (to match group names) and charsets that should be ignored.
968 When these charsets are used in the \"charset\" parameter, the
969 default charset will be used instead."
970  :variable-group gnus-charset
971  :variable-type '(repeat (cons (regexp :tag "Group")
972                                (repeat symbol)))
973  :parameter-type '(choice :tag "Ignored charsets"
974                           :value nil
975                           (repeat (symbol)))
976  :parameter-document       "\
977 List of charsets that should be ignored.
978
979 When these charsets are used in the \"charset\" parameter, the
980 default charset will be used instead.")
981
982 (defcustom gnus-group-highlight-words-alist nil
983   "Alist of group regexps and highlight regexps.
984 This variable uses the same syntax as `gnus-emphasis-alist'."
985   :version "21.1"
986   :type '(repeat (cons (regexp :tag "Group")
987                        (repeat (list (regexp :tag "Highlight regexp")
988                                      (number :tag "Group for entire word" 0)
989                                      (number :tag "Group for displayed part" 0)
990                                      (symbol :tag "Face"
991                                              gnus-emphasis-highlight-words)))))
992   :group 'gnus-summary-visual)
993
994 (defcustom gnus-use-wheel nil
995   "Use Intelli-mouse on summary movement"
996   :type 'boolean
997   :group 'gnus-summary-maneuvering)
998
999 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1000   "Amount to scroll messages by spinning the mouse wheel.
1001 This is actually a cons cell, where the first item is the amount to scroll
1002 on a normal wheel event, and the second is the amount to scroll when the
1003 wheel is moved with the shift key depressed."
1004   :type '(cons (integer :tag "Shift") integer)
1005   :group 'gnus-summary-maneuvering)
1006
1007 (defcustom gnus-wheel-edge-resistance 2
1008   "How hard it should be to change the current article
1009 by moving the mouse over the edge of the article window."
1010   :type 'integer
1011   :group 'gnus-summary-maneuvering)
1012
1013 (defcustom gnus-summary-show-article-charset-alist
1014   nil
1015   "Alist of number and charset.
1016 The article will be shown with the charset corresponding to the
1017 numbered argument.
1018 For example: ((1 . cn-gb-2312) (2 . big5))."
1019   :version "21.1"
1020   :type '(repeat (cons (number :tag "Argument" 1)
1021                        (symbol :tag "Charset")))
1022   :group 'gnus-charset)
1023
1024 (defcustom gnus-preserve-marks t
1025   "Whether marks are preserved when moving, copying and respooling messages."
1026   :version "21.1"
1027   :type 'boolean
1028   :group 'gnus-summary-marks)
1029
1030 (defcustom gnus-alter-articles-to-read-function nil
1031   "Function to be called to alter the list of articles to be selected."
1032   :type '(choice (const nil) function)
1033   :group 'gnus-summary)
1034
1035 (defcustom gnus-orphan-score nil
1036   "*All orphans get this score added.  Set in the score file."
1037   :group 'gnus-score-default
1038   :type '(choice (const nil)
1039                  integer))
1040
1041 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1042   "*A regexp to match MIME parts when saving multiple parts of a message
1043 with gnus-summary-save-parts (X m). This regexp will be used by default
1044 when prompting the user for which type of files to save."
1045   :group 'gnus-summary
1046   :type 'regexp)
1047
1048 (defcustom gnus-read-all-available-headers nil
1049   "Whether Gnus should parse all headers made available to it.
1050 This is mostly relevant for slow backends where the user may
1051 wish to widen the summary buffer to include all headers
1052 that were fetched.  Say, for nnultimate groups."
1053   :group 'gnus-summary
1054   :type '(choice boolean regexp))
1055
1056 (defcustom gnus-summary-muttprint-program "muttprint"
1057   "Command (and optional arguments) used to run Muttprint."
1058   :version "21.3"
1059   :group 'gnus-summary
1060   :type 'string)
1061
1062 (defcustom gnus-article-loose-mime nil
1063   "If non-nil, don't require MIME-Version header.
1064 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1065 supply the MIME-Version header or deliberately strip it From the mail.
1066 Set it to non-nil, Gnus will treat some articles as MIME even if
1067 the MIME-Version header is missed."
1068   :version "21.3"
1069   :type 'boolean
1070   :group 'gnus-article)
1071
1072 ;;; Internal variables
1073
1074 (defvar gnus-summary-display-cache nil)
1075 (defvar gnus-article-mime-handles nil)
1076 (defvar gnus-article-decoded-p nil)
1077 (defvar gnus-article-charset nil)
1078 (defvar gnus-article-ignored-charsets nil)
1079 (defvar gnus-scores-exclude-files nil)
1080 (defvar gnus-page-broken nil)
1081 (defvar gnus-inhibit-mime-unbuttonizing nil)
1082
1083 (defvar gnus-original-article nil)
1084 (defvar gnus-article-internal-prepare-hook nil)
1085 (defvar gnus-newsgroup-process-stack nil)
1086
1087 (defvar gnus-thread-indent-array nil)
1088 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1089 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1090   "Function called to sort the articles within a thread after it has been gathered together.")
1091
1092 (defvar gnus-summary-save-parts-type-history nil)
1093 (defvar gnus-summary-save-parts-last-directory nil)
1094
1095 ;; Avoid highlighting in kill files.
1096 (defvar gnus-summary-inhibit-highlight nil)
1097 (defvar gnus-newsgroup-selected-overlay nil)
1098 (defvar gnus-inhibit-limiting nil)
1099 (defvar gnus-newsgroup-adaptive-score-file nil)
1100 (defvar gnus-current-score-file nil)
1101 (defvar gnus-current-move-group nil)
1102 (defvar gnus-current-copy-group nil)
1103 (defvar gnus-current-crosspost-group nil)
1104 (defvar gnus-newsgroup-display nil)
1105
1106 (defvar gnus-newsgroup-dependencies nil)
1107 (defvar gnus-newsgroup-adaptive nil)
1108 (defvar gnus-summary-display-article-function nil)
1109 (defvar gnus-summary-highlight-line-function nil
1110   "Function called after highlighting a summary line.")
1111
1112 (defvar gnus-summary-line-format-alist
1113   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1114     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1115     (?s gnus-tmp-subject-or-nil ?s)
1116     (?n gnus-tmp-name ?s)
1117     (?A (std11-address-string
1118          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1119     (?a (or (std11-full-name-string
1120              (car (mime-entity-read-field gnus-tmp-header 'From)))
1121             gnus-tmp-from) ?s)
1122     (?F gnus-tmp-from ?s)
1123     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1124     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1125     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1126     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1127     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1128     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1129     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1130     (?L gnus-tmp-lines ?s)
1131     (?I gnus-tmp-indentation ?s)
1132     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1133     (?R gnus-tmp-replied ?c)
1134     (?\[ gnus-tmp-opening-bracket ?c)
1135     (?\] gnus-tmp-closing-bracket ?c)
1136     (?\> (make-string gnus-tmp-level ? ) ?s)
1137     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1138     (?i gnus-tmp-score ?d)
1139     (?z gnus-tmp-score-char ?c)
1140     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1141     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1142     (?U gnus-tmp-unread ?c)
1143     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1144         ?s)
1145     (?t (gnus-summary-number-of-articles-in-thread
1146          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1147         ?d)
1148     (?e (gnus-summary-number-of-articles-in-thread
1149          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1150         ?c)
1151     (?u gnus-tmp-user-defined ?s)
1152     (?P (gnus-pick-line-number) ?d)
1153     (?B gnus-tmp-thread-tree-header-string ?s)
1154     (user-date (gnus-user-date
1155                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1156   "An alist of format specifications that can appear in summary lines.
1157 These are paired with what variables they correspond with, along with
1158 the type of the variable (string, integer, character, etc).")
1159
1160 (defvar gnus-summary-dummy-line-format-alist
1161   `((?S gnus-tmp-subject ?s)
1162     (?N gnus-tmp-number ?d)
1163     (?u gnus-tmp-user-defined ?s)))
1164
1165 (defvar gnus-summary-mode-line-format-alist
1166   `((?G gnus-tmp-group-name ?s)
1167     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1168     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1169     (?A gnus-tmp-article-number ?d)
1170     (?Z gnus-tmp-unread-and-unselected ?s)
1171     (?V gnus-version ?s)
1172     (?U gnus-tmp-unread-and-unticked ?d)
1173     (?S gnus-tmp-subject ?s)
1174     (?e gnus-tmp-unselected ?d)
1175     (?u gnus-tmp-user-defined ?s)
1176     (?d (length gnus-newsgroup-dormant) ?d)
1177     (?t (length gnus-newsgroup-marked) ?d)
1178     (?r (length gnus-newsgroup-reads) ?d)
1179     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1180     (?E gnus-newsgroup-expunged-tally ?d)
1181     (?s (gnus-current-score-file-nondirectory) ?s)))
1182
1183 (defvar gnus-last-search-regexp nil
1184   "Default regexp for article search command.")
1185
1186 (defvar gnus-summary-search-article-matched-data nil
1187   "Last matched data of article search command.  It is the local variable
1188 in `gnus-article-buffer' which consists of the list of start position,
1189 end position and text.")
1190
1191 (defvar gnus-last-shell-command nil
1192   "Default shell command on article.")
1193
1194 (defvar gnus-newsgroup-begin nil)
1195 (defvar gnus-newsgroup-end nil)
1196 (defvar gnus-newsgroup-last-rmail nil)
1197 (defvar gnus-newsgroup-last-mail nil)
1198 (defvar gnus-newsgroup-last-folder nil)
1199 (defvar gnus-newsgroup-last-file nil)
1200 (defvar gnus-newsgroup-auto-expire nil)
1201 (defvar gnus-newsgroup-active nil)
1202
1203 (defvar gnus-newsgroup-data nil)
1204 (defvar gnus-newsgroup-data-reverse nil)
1205 (defvar gnus-newsgroup-limit nil)
1206 (defvar gnus-newsgroup-limits nil)
1207
1208 (defvar gnus-newsgroup-unreads nil
1209   "Sorted list of unread articles in the current newsgroup.")
1210
1211 (defvar gnus-newsgroup-unselected nil
1212   "Sorted list of unselected unread articles in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-reads nil
1215   "Alist of read articles and article marks in the current newsgroup.")
1216
1217 (defvar gnus-newsgroup-expunged-tally nil)
1218
1219 (defvar gnus-newsgroup-marked nil
1220   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1221
1222 (defvar gnus-newsgroup-killed nil
1223   "List of ranges of articles that have been through the scoring process.")
1224
1225 (defvar gnus-newsgroup-cached nil
1226   "Sorted list of articles that come from the article cache.")
1227
1228 (defvar gnus-newsgroup-saved nil
1229   "List of articles that have been saved.")
1230
1231 (defvar gnus-newsgroup-kill-headers nil)
1232
1233 (defvar gnus-newsgroup-replied nil
1234   "List of articles that have been replied to in the current newsgroup.")
1235
1236 (defvar gnus-newsgroup-forwarded nil
1237   "List of articles that have been forwarded in the current newsgroup.")
1238
1239 (defvar gnus-newsgroup-recent nil
1240   "List of articles that have are recent in the current newsgroup.")
1241
1242 (defvar gnus-newsgroup-expirable nil
1243   "Sorted list of articles in the current newsgroup that can be expired.")
1244
1245 (defvar gnus-newsgroup-processable nil
1246   "List of articles in the current newsgroup that can be processed.")
1247
1248 (defvar gnus-newsgroup-downloadable nil
1249   "Sorted list of articles in the current newsgroup that can be processed.")
1250
1251 (defvar gnus-newsgroup-undownloaded nil
1252   "List of articles in the current newsgroup that haven't been downloaded..")
1253
1254 (defvar gnus-newsgroup-unsendable nil
1255   "List of articles in the current newsgroup that won't be sent.")
1256
1257 (defvar gnus-newsgroup-bookmarks nil
1258   "List of articles in the current newsgroup that have bookmarks.")
1259
1260 (defvar gnus-newsgroup-dormant nil
1261   "Sorted list of dormant articles in the current newsgroup.")
1262
1263 (defvar gnus-newsgroup-unseen nil
1264   "List of unseen articles in the current newsgroup.")
1265
1266 (defvar gnus-newsgroup-seen nil
1267   "Range of seen articles in the current newsgroup.")
1268
1269 (defvar gnus-newsgroup-articles nil
1270   "List of articles in the current newsgroup.")
1271
1272 (defvar gnus-newsgroup-scored nil
1273   "List of scored articles in the current newsgroup.")
1274
1275 (defvar gnus-newsgroup-incorporated nil
1276   "List of incorporated articles in the current newsgroup.")
1277
1278 (defvar gnus-newsgroup-headers nil
1279   "List of article headers in the current newsgroup.")
1280
1281 (defvar gnus-newsgroup-threads nil)
1282
1283 (defvar gnus-newsgroup-prepared nil
1284   "Whether the current group has been prepared properly.")
1285
1286 (defvar gnus-newsgroup-ancient nil
1287   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1288
1289 (defvar gnus-newsgroup-sparse nil)
1290
1291 (defvar gnus-current-article nil)
1292 (defvar gnus-article-current nil)
1293 (defvar gnus-current-headers nil)
1294 (defvar gnus-have-all-headers nil)
1295 (defvar gnus-last-article nil)
1296 (defvar gnus-newsgroup-history nil)
1297 (defvar gnus-newsgroup-charset nil)
1298 (defvar gnus-newsgroup-ephemeral-charset nil)
1299 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1300
1301 (defvar gnus-article-before-search nil)
1302
1303 (defconst gnus-summary-local-variables
1304   '(gnus-newsgroup-name
1305     gnus-newsgroup-begin gnus-newsgroup-end
1306     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1307     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1308     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1309     gnus-newsgroup-unselected gnus-newsgroup-marked
1310     gnus-newsgroup-reads gnus-newsgroup-saved
1311     gnus-newsgroup-replied gnus-newsgroup-forwarded
1312     gnus-newsgroup-recent
1313     gnus-newsgroup-expirable
1314     gnus-newsgroup-processable gnus-newsgroup-killed
1315     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1316     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1317     gnus-newsgroup-seen gnus-newsgroup-articles
1318     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1319     gnus-newsgroup-headers gnus-newsgroup-threads
1320     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1321     gnus-current-article gnus-current-headers gnus-have-all-headers
1322     gnus-last-article gnus-article-internal-prepare-hook
1323     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1324     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1325     gnus-thread-expunge-below
1326     gnus-score-alist gnus-current-score-file
1327     (gnus-summary-expunge-below . global)
1328     (gnus-summary-mark-below . global)
1329     (gnus-orphan-score . global)
1330     gnus-newsgroup-active gnus-scores-exclude-files
1331     gnus-newsgroup-history gnus-newsgroup-ancient
1332     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1333     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1334     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1335     (gnus-newsgroup-expunged-tally . 0)
1336     gnus-cache-removable-articles gnus-newsgroup-cached
1337     gnus-newsgroup-data gnus-newsgroup-data-reverse
1338     gnus-newsgroup-limit gnus-newsgroup-limits
1339     gnus-newsgroup-charset gnus-newsgroup-display
1340     gnus-newsgroup-incorporated)
1341   "Variables that are buffer-local to the summary buffers.")
1342
1343 (defvar gnus-newsgroup-variables nil
1344   "A list of variables that have separate values in different newsgroups.
1345 A list of newsgroup (summary buffer) local variables, or cons of
1346 variables and their default values (when the default values are not
1347 nil), that should be made global while the summary buffer is active.
1348 These variables can be used to set variables in the group parameters
1349 while still allowing them to affect operations done in other
1350 buffers. For example:
1351
1352 \(setq gnus-newsgroup-variables
1353      '(message-use-followup-to
1354        (gnus-visible-headers .
1355          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1356 ")
1357
1358 ;; Byte-compiler warning.
1359 (eval-when-compile (defvar gnus-article-mode-map))
1360
1361 ;; Subject simplification.
1362
1363 (defun gnus-simplify-whitespace (str)
1364   "Remove excessive whitespace from STR."
1365   (let ((mystr str))
1366     ;; Multiple spaces.
1367     (while (string-match "[ \t][ \t]+" mystr)
1368       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1369                           " "
1370                           (substring mystr (match-end 0)))))
1371     ;; Leading spaces.
1372     (when (string-match "^[ \t]+" mystr)
1373       (setq mystr (substring mystr (match-end 0))))
1374     ;; Trailing spaces.
1375     (when (string-match "[ \t]+$" mystr)
1376       (setq mystr (substring mystr 0 (match-beginning 0))))
1377     mystr))
1378
1379 (defsubst gnus-simplify-subject-re (subject)
1380   "Remove \"Re:\" from subject lines."
1381   (if (string-match message-subject-re-regexp subject)
1382       (substring subject (match-end 0))
1383     subject))
1384
1385 (defun gnus-simplify-subject (subject &optional re-only)
1386   "Remove `Re:' and words in parentheses.
1387 If RE-ONLY is non-nil, strip leading `Re:'s only."
1388   (let ((case-fold-search t))           ;Ignore case.
1389     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1390     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1391       (setq subject (substring subject (match-end 0))))
1392     ;; Remove uninteresting prefixes.
1393     (when (and (not re-only)
1394                gnus-simplify-ignored-prefixes
1395                (string-match gnus-simplify-ignored-prefixes subject))
1396       (setq subject (substring subject (match-end 0))))
1397     ;; Remove words in parentheses from end.
1398     (unless re-only
1399       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1400         (setq subject (substring subject 0 (match-beginning 0)))))
1401     ;; Return subject string.
1402     subject))
1403
1404 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1405 ;; all whitespace.
1406 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1407   (goto-char (point-min))
1408   (while (re-search-forward regexp nil t)
1409     (replace-match (or newtext ""))))
1410
1411 (defun gnus-simplify-buffer-fuzzy ()
1412   "Simplify string in the buffer fuzzily.
1413 The string in the accessible portion of the current buffer is simplified.
1414 It is assumed to be a single-line subject.
1415 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1416 matter is removed.  Additional things can be deleted by setting
1417 `gnus-simplify-subject-fuzzy-regexp'."
1418   (let ((case-fold-search t)
1419         (modified-tick))
1420     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1421
1422     (while (not (eq modified-tick (buffer-modified-tick)))
1423       (setq modified-tick (buffer-modified-tick))
1424       (cond
1425        ((listp gnus-simplify-subject-fuzzy-regexp)
1426         (mapcar 'gnus-simplify-buffer-fuzzy-step
1427                 gnus-simplify-subject-fuzzy-regexp))
1428        (gnus-simplify-subject-fuzzy-regexp
1429         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1430       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1431       (gnus-simplify-buffer-fuzzy-step
1432        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1433       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1434
1435     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1436     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1437     (gnus-simplify-buffer-fuzzy-step " $")
1438     (gnus-simplify-buffer-fuzzy-step "^ +")))
1439
1440 (defun gnus-simplify-subject-fuzzy (subject)
1441   "Simplify a subject string fuzzily.
1442 See `gnus-simplify-buffer-fuzzy' for details."
1443   (save-excursion
1444     (gnus-set-work-buffer)
1445     (let ((case-fold-search t))
1446       ;; Remove uninteresting prefixes.
1447       (when (and gnus-simplify-ignored-prefixes
1448                  (string-match gnus-simplify-ignored-prefixes subject))
1449         (setq subject (substring subject (match-end 0))))
1450       (insert subject)
1451       (inline (gnus-simplify-buffer-fuzzy))
1452       (buffer-string))))
1453
1454 (defsubst gnus-simplify-subject-fully (subject)
1455   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1456   (cond
1457    (gnus-simplify-subject-functions
1458     (gnus-map-function gnus-simplify-subject-functions subject))
1459    ((null gnus-summary-gather-subject-limit)
1460     (gnus-simplify-subject-re subject))
1461    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1462     (gnus-simplify-subject-fuzzy subject))
1463    ((numberp gnus-summary-gather-subject-limit)
1464     (gnus-limit-string (gnus-simplify-subject-re subject)
1465                        gnus-summary-gather-subject-limit))
1466    (t
1467     subject)))
1468
1469 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1470   "Check whether two subjects are equal.
1471 If optional argument simple-first is t, first argument is already
1472 simplified."
1473   (cond
1474    ((null simple-first)
1475     (equal (gnus-simplify-subject-fully s1)
1476            (gnus-simplify-subject-fully s2)))
1477    (t
1478     (equal s1
1479            (gnus-simplify-subject-fully s2)))))
1480
1481 (defun gnus-summary-bubble-group ()
1482   "Increase the score of the current group.
1483 This is a handy function to add to `gnus-summary-exit-hook' to
1484 increase the score of each group you read."
1485   (gnus-group-add-score gnus-newsgroup-name))
1486
1487 \f
1488 ;;;
1489 ;;; Gnus summary mode
1490 ;;;
1491
1492 (put 'gnus-summary-mode 'mode-class 'special)
1493
1494 (defvar gnus-article-commands-menu)
1495
1496 (when t
1497   ;; Non-orthogonal keys
1498
1499   (gnus-define-keys gnus-summary-mode-map
1500     " " gnus-summary-next-page
1501     "\177" gnus-summary-prev-page
1502     [delete] gnus-summary-prev-page
1503     [backspace] gnus-summary-prev-page
1504     "\r" gnus-summary-scroll-up
1505     "\M-\r" gnus-summary-scroll-down
1506     "n" gnus-summary-next-unread-article
1507     "p" gnus-summary-prev-unread-article
1508     "N" gnus-summary-next-article
1509     "P" gnus-summary-prev-article
1510     "\M-\C-n" gnus-summary-next-same-subject
1511     "\M-\C-p" gnus-summary-prev-same-subject
1512     "\M-n" gnus-summary-next-unread-subject
1513     "\M-p" gnus-summary-prev-unread-subject
1514     "." gnus-summary-first-unread-article
1515     "," gnus-summary-best-unread-article
1516     "\M-s" gnus-summary-search-article-forward
1517     "\M-r" gnus-summary-search-article-backward
1518     "<" gnus-summary-beginning-of-article
1519     ">" gnus-summary-end-of-article
1520     "j" gnus-summary-goto-article
1521     "^" gnus-summary-refer-parent-article
1522     "\M-^" gnus-summary-refer-article
1523     "u" gnus-summary-tick-article-forward
1524     "!" gnus-summary-tick-article-forward
1525     "U" gnus-summary-tick-article-backward
1526     "d" gnus-summary-mark-as-read-forward
1527     "D" gnus-summary-mark-as-read-backward
1528     "E" gnus-summary-mark-as-expirable
1529     "\M-u" gnus-summary-clear-mark-forward
1530     "\M-U" gnus-summary-clear-mark-backward
1531     "k" gnus-summary-kill-same-subject-and-select
1532     "\C-k" gnus-summary-kill-same-subject
1533     "\M-\C-k" gnus-summary-kill-thread
1534     "\M-\C-l" gnus-summary-lower-thread
1535     "e" gnus-summary-edit-article
1536     "#" gnus-summary-mark-as-processable
1537     "\M-#" gnus-summary-unmark-as-processable
1538     "\M-\C-t" gnus-summary-toggle-threads
1539     "\M-\C-s" gnus-summary-show-thread
1540     "\M-\C-h" gnus-summary-hide-thread
1541     "\M-\C-f" gnus-summary-next-thread
1542     "\M-\C-b" gnus-summary-prev-thread
1543     [(meta down)] gnus-summary-next-thread
1544     [(meta up)] gnus-summary-prev-thread
1545     "\M-\C-u" gnus-summary-up-thread
1546     "\M-\C-d" gnus-summary-down-thread
1547     "&" gnus-summary-execute-command
1548     "c" gnus-summary-catchup-and-exit
1549     "\C-w" gnus-summary-mark-region-as-read
1550     "\C-t" gnus-summary-toggle-truncation
1551     "?" gnus-summary-mark-as-dormant
1552     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1553     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1554     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1555     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1556     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1557     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1558     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1559     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1560     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1561     "=" gnus-summary-expand-window
1562     "\C-x\C-s" gnus-summary-reselect-current-group
1563     "\M-g" gnus-summary-rescan-group
1564     "w" gnus-summary-stop-page-breaking
1565     "\C-c\C-r" gnus-summary-caesar-message
1566     "\M-t" gnus-summary-toggle-mime
1567     "f" gnus-summary-followup
1568     "F" gnus-summary-followup-with-original
1569     "C" gnus-summary-cancel-article
1570     "r" gnus-summary-reply
1571     "R" gnus-summary-reply-with-original
1572     "\C-c\C-f" gnus-summary-mail-forward
1573     "o" gnus-summary-save-article
1574     "\C-o" gnus-summary-save-article-mail
1575     "|" gnus-summary-pipe-output
1576     "\M-k" gnus-summary-edit-local-kill
1577     "\M-K" gnus-summary-edit-global-kill
1578     ;; "V" gnus-version
1579     "\C-c\C-d" gnus-summary-describe-group
1580     "q" gnus-summary-exit
1581     "Q" gnus-summary-exit-no-update
1582     "\C-c\C-i" gnus-info-find-node
1583     gnus-mouse-2 gnus-mouse-pick-article
1584     "m" gnus-summary-mail-other-window
1585     "a" gnus-summary-post-news
1586     "i" gnus-summary-news-other-window
1587     "x" gnus-summary-limit-to-unread
1588     "s" gnus-summary-isearch-article
1589     "t" gnus-article-toggle-headers
1590     "g" gnus-summary-show-article
1591     "l" gnus-summary-goto-last-article
1592     "v" gnus-summary-preview-mime-message
1593     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1594     "\C-d" gnus-summary-enter-digest-group
1595     "\M-\C-d" gnus-summary-read-document
1596     "\M-\C-e" gnus-summary-edit-parameters
1597     "\M-\C-a" gnus-summary-customize-parameters
1598     "\C-c\C-b" gnus-bug
1599     "\C-c\C-n" gnus-namazu-search
1600     "*" gnus-cache-enter-article
1601     "\M-*" gnus-cache-remove-article
1602     "\M-&" gnus-summary-universal-argument
1603     "\C-l" gnus-recenter
1604     "I" gnus-summary-increase-score
1605     "L" gnus-summary-lower-score
1606     "\M-i" gnus-symbolic-argument
1607     "h" gnus-summary-select-article-buffer
1608
1609     "V" gnus-summary-score-map
1610     "X" gnus-uu-extract-map
1611     "S" gnus-summary-send-map)
1612
1613   ;; Sort of orthogonal keymap
1614   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1615     "t" gnus-summary-tick-article-forward
1616     "!" gnus-summary-tick-article-forward
1617     "d" gnus-summary-mark-as-read-forward
1618     "r" gnus-summary-mark-as-read-forward
1619     "c" gnus-summary-clear-mark-forward
1620     " " gnus-summary-clear-mark-forward
1621     "e" gnus-summary-mark-as-expirable
1622     "x" gnus-summary-mark-as-expirable
1623     "?" gnus-summary-mark-as-dormant
1624     "b" gnus-summary-set-bookmark
1625     "B" gnus-summary-remove-bookmark
1626     "#" gnus-summary-mark-as-processable
1627     "\M-#" gnus-summary-unmark-as-processable
1628     "S" gnus-summary-limit-include-expunged
1629     "C" gnus-summary-catchup
1630     "H" gnus-summary-catchup-to-here
1631     "h" gnus-summary-catchup-from-here
1632     "\C-c" gnus-summary-catchup-all
1633     "k" gnus-summary-kill-same-subject-and-select
1634     "K" gnus-summary-kill-same-subject
1635     "P" gnus-uu-mark-map)
1636
1637   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1638     "c" gnus-summary-clear-above
1639     "u" gnus-summary-tick-above
1640     "m" gnus-summary-mark-above
1641     "k" gnus-summary-kill-below)
1642
1643   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1644     "/" gnus-summary-limit-to-subject
1645     "n" gnus-summary-limit-to-articles
1646     "w" gnus-summary-pop-limit
1647     "s" gnus-summary-limit-to-subject
1648     "a" gnus-summary-limit-to-author
1649     "u" gnus-summary-limit-to-unread
1650     "m" gnus-summary-limit-to-marks
1651     "M" gnus-summary-limit-exclude-marks
1652     "v" gnus-summary-limit-to-score
1653     "*" gnus-summary-limit-include-cached
1654     "D" gnus-summary-limit-include-dormant
1655     "T" gnus-summary-limit-include-thread
1656     "d" gnus-summary-limit-exclude-dormant
1657     "t" gnus-summary-limit-to-age
1658     "x" gnus-summary-limit-to-extra
1659     "p" gnus-summary-limit-to-display-predicate
1660     "E" gnus-summary-limit-include-expunged
1661     "c" gnus-summary-limit-exclude-childless-dormant
1662     "C" gnus-summary-limit-mark-excluded-as-read
1663     "o" gnus-summary-insert-old-articles
1664     "N" gnus-summary-insert-new-articles)
1665
1666   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1667     "n" gnus-summary-next-unread-article
1668     "p" gnus-summary-prev-unread-article
1669     "N" gnus-summary-next-article
1670     "P" gnus-summary-prev-article
1671     "\C-n" gnus-summary-next-same-subject
1672     "\C-p" gnus-summary-prev-same-subject
1673     "\M-n" gnus-summary-next-unread-subject
1674     "\M-p" gnus-summary-prev-unread-subject
1675     "f" gnus-summary-first-unread-article
1676     "b" gnus-summary-best-unread-article
1677     "j" gnus-summary-goto-article
1678     "g" gnus-summary-goto-subject
1679     "l" gnus-summary-goto-last-article
1680     "o" gnus-summary-pop-article)
1681
1682   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1683     "k" gnus-summary-kill-thread
1684     "l" gnus-summary-lower-thread
1685     "i" gnus-summary-raise-thread
1686     "T" gnus-summary-toggle-threads
1687     "t" gnus-summary-rethread-current
1688     "^" gnus-summary-reparent-thread
1689     "s" gnus-summary-show-thread
1690     "S" gnus-summary-show-all-threads
1691     "h" gnus-summary-hide-thread
1692     "H" gnus-summary-hide-all-threads
1693     "n" gnus-summary-next-thread
1694     "p" gnus-summary-prev-thread
1695     "u" gnus-summary-up-thread
1696     "o" gnus-summary-top-thread
1697     "d" gnus-summary-down-thread
1698     "#" gnus-uu-mark-thread
1699     "\M-#" gnus-uu-unmark-thread)
1700
1701   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1702     "g" gnus-summary-prepare
1703     "c" gnus-summary-insert-cached-articles)
1704
1705   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1706     "c" gnus-summary-catchup-and-exit
1707     "C" gnus-summary-catchup-all-and-exit
1708     "E" gnus-summary-exit-no-update
1709     "J" gnus-summary-jump-to-other-group
1710     "Q" gnus-summary-exit
1711     "Z" gnus-summary-exit
1712     "n" gnus-summary-catchup-and-goto-next-group
1713     "R" gnus-summary-reselect-current-group
1714     "G" gnus-summary-rescan-group
1715     "N" gnus-summary-next-group
1716     "s" gnus-summary-save-newsrc
1717     "P" gnus-summary-prev-group)
1718
1719   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1720     " " gnus-summary-next-page
1721     "n" gnus-summary-next-page
1722     "\177" gnus-summary-prev-page
1723     [delete] gnus-summary-prev-page
1724     "p" gnus-summary-prev-page
1725     "\r" gnus-summary-scroll-up
1726     "\M-\r" gnus-summary-scroll-down
1727     "<" gnus-summary-beginning-of-article
1728     ">" gnus-summary-end-of-article
1729     "b" gnus-summary-beginning-of-article
1730     "e" gnus-summary-end-of-article
1731     "^" gnus-summary-refer-parent-article
1732     "r" gnus-summary-refer-parent-article
1733     "D" gnus-summary-enter-digest-group
1734     "R" gnus-summary-refer-references
1735     "T" gnus-summary-refer-thread
1736     "g" gnus-summary-show-article
1737     "s" gnus-summary-isearch-article
1738     "P" gnus-summary-print-article
1739     "M" gnus-mailing-list-insinuate
1740     "t" gnus-article-babel)
1741
1742   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1743     "b" gnus-article-add-buttons
1744     "B" gnus-article-add-buttons-to-head
1745     "o" gnus-article-treat-overstrike
1746     "e" gnus-article-emphasize
1747     "w" gnus-article-fill-cited-article
1748     "Q" gnus-article-fill-long-lines
1749     "C" gnus-article-capitalize-sentences
1750     "c" gnus-article-remove-cr
1751     "Z" gnus-article-decode-HZ
1752     "h" gnus-article-wash-html
1753     "u" gnus-article-unsplit-urls
1754     "f" gnus-article-display-x-face
1755     "l" gnus-summary-stop-page-breaking
1756     "r" gnus-summary-caesar-message
1757     "t" gnus-article-toggle-headers
1758     "g" gnus-treat-smiley
1759     "v" gnus-summary-verbose-headers
1760     "m" gnus-summary-toggle-mime
1761     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1762     "p" gnus-article-verify-x-pgp-sig
1763     "d" gnus-article-treat-dumbquotes
1764     "k" gnus-article-outlook-deuglify-article)
1765
1766   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1767     "a" gnus-article-hide
1768     "h" gnus-article-toggle-headers
1769     "b" gnus-article-hide-boring-headers
1770     "s" gnus-article-hide-signature
1771     "c" gnus-article-hide-citation
1772     "C" gnus-article-hide-citation-in-followups
1773     "l" gnus-article-hide-list-identifiers
1774     "p" gnus-article-hide-pgp
1775     "B" gnus-article-strip-banner
1776     "P" gnus-article-hide-pem
1777     "\C-c" gnus-article-hide-citation-maybe)
1778
1779   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1780     "a" gnus-article-highlight
1781     "h" gnus-article-highlight-headers
1782     "c" gnus-article-highlight-citation
1783     "s" gnus-article-highlight-signature)
1784
1785   (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1786     "f" gnus-article-treat-fold-headers
1787     "u" gnus-article-treat-unfold-headers
1788     "n" gnus-article-treat-fold-newsgroups)
1789
1790   (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1791     "x" gnus-article-display-x-face
1792     "s" gnus-treat-smiley
1793     "D" gnus-article-remove-images
1794     "f" gnus-treat-from-picon
1795     "m" gnus-treat-mail-picon
1796     "n" gnus-treat-newsgroups-picon)
1797
1798   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1799     "z" gnus-article-date-ut
1800     "u" gnus-article-date-ut
1801     "l" gnus-article-date-local
1802     "p" gnus-article-date-english
1803     "e" gnus-article-date-lapsed
1804     "o" gnus-article-date-original
1805     "i" gnus-article-date-iso8601
1806     "s" gnus-article-date-user)
1807
1808   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1809     "t" gnus-article-remove-trailing-blank-lines
1810     "l" gnus-article-strip-leading-blank-lines
1811     "m" gnus-article-strip-multiple-blank-lines
1812     "a" gnus-article-strip-blank-lines
1813     "A" gnus-article-strip-all-blank-lines
1814     "s" gnus-article-strip-leading-space
1815     "e" gnus-article-strip-trailing-space
1816     "w" gnus-article-remove-leading-whitespace)
1817
1818   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1819     "v" gnus-version
1820     "f" gnus-summary-fetch-faq
1821     "d" gnus-summary-describe-group
1822     "h" gnus-summary-describe-briefly
1823     "i" gnus-info-find-node)
1824
1825   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1826     "e" gnus-summary-expire-articles
1827     "\M-\C-e" gnus-summary-expire-articles-now
1828     "\177" gnus-summary-delete-article
1829     [delete] gnus-summary-delete-article
1830     [backspace] gnus-summary-delete-article
1831     "m" gnus-summary-move-article
1832     "r" gnus-summary-respool-article
1833     "w" gnus-summary-edit-article
1834     "c" gnus-summary-copy-article
1835     "B" gnus-summary-crosspost-article
1836     "q" gnus-summary-respool-query
1837     "t" gnus-summary-respool-trace
1838     "i" gnus-summary-import-article
1839     "I" gnus-summary-create-article
1840     "p" gnus-summary-article-posted-p)
1841
1842   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1843     "o" gnus-summary-save-article
1844     "m" gnus-summary-save-article-mail
1845     "F" gnus-summary-write-article-file
1846     "r" gnus-summary-save-article-rmail
1847     "f" gnus-summary-save-article-file
1848     "b" gnus-summary-save-article-body-file
1849     "h" gnus-summary-save-article-folder
1850     "v" gnus-summary-save-article-vm
1851     "p" gnus-summary-pipe-output
1852     "P" gnus-summary-muttprint
1853     "s" gnus-soup-add-article)
1854
1855   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1856     "b" gnus-summary-display-buttonized
1857     "m" gnus-summary-repair-multipart
1858     "v" gnus-article-view-part
1859     "o" gnus-article-save-part
1860     "c" gnus-article-copy-part
1861     "C" gnus-article-view-part-as-charset
1862     "e" gnus-article-view-part-externally
1863     "E" gnus-article-encrypt-body
1864     "i" gnus-article-inline-part
1865     "|" gnus-article-pipe-part)
1866
1867   (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1868     "p" gnus-summary-mark-as-processable
1869     "u" gnus-summary-unmark-as-processable
1870     "U" gnus-summary-unmark-all-processable
1871     "v" gnus-uu-mark-over
1872     "s" gnus-uu-mark-series
1873     "r" gnus-uu-mark-region
1874     "g" gnus-uu-unmark-region
1875     "R" gnus-uu-mark-by-regexp
1876     "G" gnus-uu-unmark-by-regexp
1877     "t" gnus-uu-mark-thread
1878     "T" gnus-uu-unmark-thread
1879     "a" gnus-uu-mark-all
1880     "b" gnus-uu-mark-buffer
1881     "S" gnus-uu-mark-sparse
1882     "k" gnus-summary-kill-process-mark
1883     "y" gnus-summary-yank-process-mark
1884     "w" gnus-summary-save-process-mark
1885     "i" gnus-uu-invert-processable)
1886
1887   (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
1888     ;;"x" gnus-uu-extract-any
1889     "m" gnus-summary-save-parts
1890     "u" gnus-uu-decode-uu
1891     "U" gnus-uu-decode-uu-and-save
1892     "s" gnus-uu-decode-unshar
1893     "S" gnus-uu-decode-unshar-and-save
1894     "o" gnus-uu-decode-save
1895     "O" gnus-uu-decode-save
1896     "b" gnus-uu-decode-binhex
1897     "B" gnus-uu-decode-binhex
1898     "p" gnus-uu-decode-postscript
1899     "P" gnus-uu-decode-postscript-and-save)
1900
1901   (gnus-define-keys
1902       (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
1903     "u" gnus-uu-decode-uu-view
1904     "U" gnus-uu-decode-uu-and-save-view
1905     "s" gnus-uu-decode-unshar-view
1906     "S" gnus-uu-decode-unshar-and-save-view
1907     "o" gnus-uu-decode-save-view
1908     "O" gnus-uu-decode-save-view
1909     "b" gnus-uu-decode-binhex-view
1910     "B" gnus-uu-decode-binhex-view
1911     "p" gnus-uu-decode-postscript-view
1912     "P" gnus-uu-decode-postscript-and-save-view))
1913
1914 (defvar gnus-article-post-menu nil)
1915
1916 (defun gnus-summary-make-menu-bar ()
1917   (gnus-turn-off-edit-menu 'summary)
1918
1919   (unless (boundp 'gnus-summary-misc-menu)
1920
1921     (easy-menu-define
1922      gnus-summary-kill-menu gnus-summary-mode-map ""
1923      (cons
1924       "Score"
1925       (nconc
1926        (list
1927         ["Customize" gnus-score-customize t])
1928        (gnus-make-score-map 'increase)
1929        (gnus-make-score-map 'lower)
1930        '(("Mark"
1931           ["Kill below" gnus-summary-kill-below t]
1932           ["Mark above" gnus-summary-mark-above t]
1933           ["Tick above" gnus-summary-tick-above t]
1934           ["Clear above" gnus-summary-clear-above t])
1935          ["Current score" gnus-summary-current-score t]
1936          ["Set score" gnus-summary-set-score t]
1937          ["Switch current score file..." gnus-score-change-score-file t]
1938          ["Set mark below..." gnus-score-set-mark-below t]
1939          ["Set expunge below..." gnus-score-set-expunge-below t]
1940          ["Edit current score file" gnus-score-edit-current-scores t]
1941          ["Edit score file" gnus-score-edit-file t]
1942          ["Trace score" gnus-score-find-trace t]
1943          ["Find words" gnus-score-find-favourite-words t]
1944          ["Rescore buffer" gnus-summary-rescore t]
1945          ["Increase score..." gnus-summary-increase-score t]
1946          ["Lower score..." gnus-summary-lower-score t]))))
1947
1948     ;; Define both the Article menu in the summary buffer and the
1949     ;; equivalent Commands menu in the article buffer here for
1950     ;; consistency.
1951     (let ((innards
1952            `(("Hide"
1953               ["All" gnus-article-hide t]
1954               ["Headers" gnus-article-toggle-headers t]
1955               ["Signature" gnus-article-hide-signature t]
1956               ["Citation" gnus-article-hide-citation t]
1957               ["List identifiers" gnus-article-hide-list-identifiers t]
1958               ["PGP" gnus-article-hide-pgp t]
1959               ["Banner" gnus-article-strip-banner t]
1960               ["Boring headers" gnus-article-hide-boring-headers t])
1961              ("Highlight"
1962               ["All" gnus-article-highlight t]
1963               ["Headers" gnus-article-highlight-headers t]
1964               ["Signature" gnus-article-highlight-signature t]
1965               ["Citation" gnus-article-highlight-citation t])
1966              ("Date"
1967               ["Local" gnus-article-date-local t]
1968               ["ISO8601" gnus-article-date-iso8601 t]
1969               ["UT" gnus-article-date-ut t]
1970               ["Original" gnus-article-date-original t]
1971               ["Lapsed" gnus-article-date-lapsed t]
1972               ["User-defined" gnus-article-date-user t])
1973              ("Display"
1974               ["Remove images" gnus-article-remove-images t]
1975               ["Toggle smiley" gnus-treat-smiley t]
1976               ["Show X-Face" gnus-article-display-x-face t]
1977               ["Show picons in From" gnus-treat-from-picon t]
1978               ["Show picons in mail headers" gnus-treat-mail-picon t]
1979               ["Show picons in news headers" gnus-treat-newsgroups-picon t])
1980              ("Washing"
1981               ("Remove Blanks"
1982                ["Leading" gnus-article-strip-leading-blank-lines t]
1983                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1984                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1985                ["All of the above" gnus-article-strip-blank-lines t]
1986                ["All" gnus-article-strip-all-blank-lines t]
1987                ["Leading space" gnus-article-strip-leading-space t]
1988                ["Trailing space" gnus-article-strip-trailing-space t]
1989                ["Leading space in headers"
1990                 gnus-article-remove-leading-whitespace t])
1991               ["Overstrike" gnus-article-treat-overstrike t]
1992               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1993               ["Emphasis" gnus-article-emphasize t]
1994               ["Word wrap" gnus-article-fill-cited-article t]
1995               ["Fill long lines" gnus-article-fill-long-lines t]
1996               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1997               ["CR" gnus-article-remove-cr t]
1998               ["Rot 13" gnus-summary-caesar-message
1999                ,@(if (featurep 'xemacs) '(t)
2000                    '(:help "\"Caesar rotate\" article by 13"))]
2001               ["Unix pipe" gnus-summary-pipe-message t]
2002               ["Add buttons" gnus-article-add-buttons t]
2003               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2004               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2005               ["Toggle MIME" gnus-summary-toggle-mime t]
2006               ["Verbose header" gnus-summary-verbose-headers t]
2007               ["Toggle header" gnus-summary-toggle-header t]
2008               ["Unfold headers" gnus-article-treat-unfold-headers t]
2009               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2010               ["Html" gnus-article-wash-html t]
2011               ["URLs" gnus-article-unsplit-urls t]
2012               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2013               ["HZ" gnus-article-decode-HZ t]
2014               ["OutlooK deuglify" gnus-article-outlook-deuglify-article t]
2015               )
2016              ("Output"
2017               ["Save in default format" gnus-summary-save-article
2018                ,@(if (featurep 'xemacs) '(t)
2019                    '(:help "Save article using default method"))]
2020               ["Save in file" gnus-summary-save-article-file
2021                ,@(if (featurep 'xemacs) '(t)
2022                    '(:help "Save article in file"))]
2023               ["Save in Unix mail format" gnus-summary-save-article-mail t]
2024               ["Save in MH folder" gnus-summary-save-article-folder t]
2025               ["Save in VM folder" gnus-summary-save-article-vm t]
2026               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
2027               ["Save body in file" gnus-summary-save-article-body-file t]
2028               ["Pipe through a filter" gnus-summary-pipe-output t]
2029               ["Add to SOUP packet" gnus-soup-add-article t]
2030               ["Print with Muttprint" gnus-summary-muttprint t]
2031               ["Print" gnus-summary-print-article t])
2032              ("Backend"
2033               ["Respool article..." gnus-summary-respool-article t]
2034               ["Move article..." gnus-summary-move-article
2035                (gnus-check-backend-function
2036                 'request-move-article gnus-newsgroup-name)]
2037               ["Copy article..." gnus-summary-copy-article t]
2038               ["Crosspost article..." gnus-summary-crosspost-article
2039                (gnus-check-backend-function
2040                 'request-replace-article gnus-newsgroup-name)]
2041               ["Import file..." gnus-summary-import-article t]
2042               ["Create article..." gnus-summary-create-article t]
2043               ["Check if posted" gnus-summary-article-posted-p t]
2044               ["Edit article" gnus-summary-edit-article
2045                (not (gnus-group-read-only-p))]
2046               ["Delete article" gnus-summary-delete-article
2047                (gnus-check-backend-function
2048                 'request-expire-articles gnus-newsgroup-name)]
2049               ["Query respool" gnus-summary-respool-query t]
2050               ["Trace respool" gnus-summary-respool-trace t]
2051               ["Delete expirable articles" gnus-summary-expire-articles-now
2052                (gnus-check-backend-function
2053                 'request-expire-articles gnus-newsgroup-name)])
2054              ("Extract"
2055               ["Uudecode" gnus-uu-decode-uu
2056                ,@(if (featurep 'xemacs) '(t)
2057                    '(:help "Decode uuencoded article(s)"))]
2058               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2059               ["Unshar" gnus-uu-decode-unshar t]
2060               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2061               ["Save" gnus-uu-decode-save t]
2062               ["Binhex" gnus-uu-decode-binhex t]
2063               ["Postscript" gnus-uu-decode-postscript t])
2064              ("Cache"
2065               ["Enter article" gnus-cache-enter-article t]
2066               ["Remove article" gnus-cache-remove-article t])
2067              ["Translate" gnus-article-babel t]
2068              ["Select article buffer" gnus-summary-select-article-buffer t]
2069              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2070              ["Isearch article..." gnus-summary-isearch-article t]
2071              ["Beginning of the article" gnus-summary-beginning-of-article t]
2072              ["End of the article" gnus-summary-end-of-article t]
2073              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2074              ["Fetch referenced articles" gnus-summary-refer-references t]
2075              ["Fetch current thread" gnus-summary-refer-thread t]
2076              ["Fetch article with id..." gnus-summary-refer-article t]
2077              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2078              ["Redisplay" gnus-summary-show-article t]
2079              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2080       (easy-menu-define
2081        gnus-summary-article-menu gnus-summary-mode-map ""
2082        (cons "Article" innards))
2083
2084       (if (not (keymapp gnus-summary-article-menu))
2085           (easy-menu-define
2086            gnus-article-commands-menu gnus-article-mode-map ""
2087            (cons "Commands" innards))
2088         ;; in Emacs, don't share menu.
2089         (setq gnus-article-commands-menu
2090               (copy-keymap gnus-summary-article-menu))
2091         (define-key gnus-article-mode-map [menu-bar commands]
2092           (cons "Commands" gnus-article-commands-menu))))
2093
2094     (easy-menu-define
2095      gnus-summary-thread-menu gnus-summary-mode-map ""
2096      '("Threads"
2097        ["Toggle threading" gnus-summary-toggle-threads t]
2098        ["Hide threads" gnus-summary-hide-all-threads t]
2099        ["Show threads" gnus-summary-show-all-threads t]
2100        ["Hide thread" gnus-summary-hide-thread t]
2101        ["Show thread" gnus-summary-show-thread t]
2102        ["Go to next thread" gnus-summary-next-thread t]
2103        ["Go to previous thread" gnus-summary-prev-thread t]
2104        ["Go down thread" gnus-summary-down-thread t]
2105        ["Go up thread" gnus-summary-up-thread t]
2106        ["Top of thread" gnus-summary-top-thread t]
2107        ["Mark thread as read" gnus-summary-kill-thread t]
2108        ["Lower thread score" gnus-summary-lower-thread t]
2109        ["Raise thread score" gnus-summary-raise-thread t]
2110        ["Rethread current" gnus-summary-rethread-current t]))
2111
2112     (easy-menu-define
2113      gnus-summary-post-menu gnus-summary-mode-map ""
2114      `("Post"
2115        ["Send a message (mail or news)" gnus-summary-post-news
2116         ,@(if (featurep 'xemacs) '(t)
2117             '(:help "Post an article"))]
2118        ["Followup" gnus-summary-followup
2119         ,@(if (featurep 'xemacs) '(t)
2120             '(:help "Post followup to this article"))]
2121        ["Followup and yank" gnus-summary-followup-with-original
2122         ,@(if (featurep 'xemacs) '(t)
2123             '(:help "Post followup to this article, quoting its contents"))]
2124        ["Supersede article" gnus-summary-supersede-article t]
2125        ["Cancel article" gnus-summary-cancel-article
2126         ,@(if (featurep 'xemacs) '(t)
2127             '(:help "Cancel an article you posted"))]
2128        ["Reply" gnus-summary-reply t]
2129        ["Reply and yank" gnus-summary-reply-with-original t]
2130        ["Wide reply" gnus-summary-wide-reply t]
2131        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2132         ,@(if (featurep 'xemacs) '(t)
2133             '(:help "Mail a reply, quoting this article"))]
2134        ["Very wide reply" gnus-summary-very-wide-reply t]
2135        ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2136         ,@(if (featurep 'xemacs) '(t)
2137             '(:help "Mail a very wide reply, quoting this article"))]
2138        ["Mail forward" gnus-summary-mail-forward t]
2139        ["Post forward" gnus-summary-post-forward t]
2140        ["Digest and mail" gnus-summary-digest-mail-forward t]
2141        ["Digest and post" gnus-summary-digest-post-forward t]
2142        ["Resend message" gnus-summary-resend-message t]
2143        ["Resend message edit" gnus-summary-resend-message-edit t]
2144        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2145        ["Send a mail" gnus-summary-mail-other-window t]
2146        ["Create a local message" gnus-summary-news-other-window t]
2147        ["Uuencode and post" gnus-uu-post-news
2148         ,@(if (featurep 'xemacs) '(t)
2149             '(:help "Post a uuencoded article"))]
2150        ["Followup via news" gnus-summary-followup-to-mail t]
2151        ["Followup via news and yank"
2152         gnus-summary-followup-to-mail-with-original t]
2153        ;;("Draft"
2154        ;;["Send" gnus-summary-send-draft t]
2155        ;;["Send bounced" gnus-resend-bounced-mail t])
2156        ))
2157
2158     (cond
2159      ((not (keymapp gnus-summary-post-menu))
2160       (setq gnus-article-post-menu gnus-summary-post-menu))
2161      ((not gnus-article-post-menu)
2162       ;; Don't share post menu.
2163       (setq gnus-article-post-menu
2164             (copy-keymap gnus-summary-post-menu))))
2165     (define-key gnus-article-mode-map [menu-bar post]
2166       (cons "Post" gnus-article-post-menu))
2167
2168     (easy-menu-define
2169      gnus-summary-misc-menu gnus-summary-mode-map ""
2170      `("Gnus"
2171        ("Mark Read"
2172         ["Mark as read" gnus-summary-mark-as-read-forward t]
2173         ["Mark same subject and select"
2174          gnus-summary-kill-same-subject-and-select t]
2175         ["Mark same subject" gnus-summary-kill-same-subject t]
2176         ["Catchup" gnus-summary-catchup
2177          ,@(if (featurep 'xemacs) '(t)
2178              '(:help "Mark unread articles in this group as read"))]
2179         ["Catchup all" gnus-summary-catchup-all t]
2180         ["Catchup to here" gnus-summary-catchup-to-here t]
2181         ["Catchup from here" gnus-summary-catchup-from-here t]
2182         ["Catchup region" gnus-summary-mark-region-as-read t]
2183         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2184        ("Mark Various"
2185         ["Tick" gnus-summary-tick-article-forward t]
2186         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2187         ["Remove marks" gnus-summary-clear-mark-forward t]
2188         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2189         ["Set bookmark" gnus-summary-set-bookmark t]
2190         ["Remove bookmark" gnus-summary-remove-bookmark t])
2191        ("Limit to"
2192         ["Marks..." gnus-summary-limit-to-marks t]
2193         ["Subject..." gnus-summary-limit-to-subject t]
2194         ["Author..." gnus-summary-limit-to-author t]
2195         ["Age..." gnus-summary-limit-to-age t]
2196         ["Extra..." gnus-summary-limit-to-extra t]
2197         ["Score" gnus-summary-limit-to-score t]
2198         ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2199         ["Unread" gnus-summary-limit-to-unread t]
2200         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2201         ["Articles" gnus-summary-limit-to-articles t]
2202         ["Pop limit" gnus-summary-pop-limit t]
2203         ["Show dormant" gnus-summary-limit-include-dormant t]
2204         ["Hide childless dormant"
2205          gnus-summary-limit-exclude-childless-dormant t]
2206         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2207         ["Hide marked" gnus-summary-limit-exclude-marks t]
2208         ["Show expunged" gnus-summary-limit-include-expunged t])
2209        ("Process Mark"
2210         ["Set mark" gnus-summary-mark-as-processable t]
2211         ["Remove mark" gnus-summary-unmark-as-processable t]
2212         ["Remove all marks" gnus-summary-unmark-all-processable t]
2213         ["Mark above" gnus-uu-mark-over t]
2214         ["Mark series" gnus-uu-mark-series t]
2215         ["Mark region" gnus-uu-mark-region t]
2216         ["Unmark region" gnus-uu-unmark-region t]
2217         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2218         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2219         ["Mark all" gnus-uu-mark-all t]
2220         ["Mark buffer" gnus-uu-mark-buffer t]
2221         ["Mark sparse" gnus-uu-mark-sparse t]
2222         ["Mark thread" gnus-uu-mark-thread t]
2223         ["Unmark thread" gnus-uu-unmark-thread t]
2224         ("Process Mark Sets"
2225          ["Kill" gnus-summary-kill-process-mark t]
2226          ["Yank" gnus-summary-yank-process-mark
2227           gnus-newsgroup-process-stack]
2228          ["Save" gnus-summary-save-process-mark t]))
2229        ("Scroll article"
2230         ["Page forward" gnus-summary-next-page
2231          ,@(if (featurep 'xemacs) '(t)
2232              '(:help "Show next page of article"))]
2233         ["Page backward" gnus-summary-prev-page
2234          ,@(if (featurep 'xemacs) '(t)
2235              '(:help "Show previous page of article"))]
2236         ["Line forward" gnus-summary-scroll-up t])
2237        ("Move"
2238         ["Next unread article" gnus-summary-next-unread-article t]
2239         ["Previous unread article" gnus-summary-prev-unread-article t]
2240         ["Next article" gnus-summary-next-article t]
2241         ["Previous article" gnus-summary-prev-article t]
2242         ["Next unread subject" gnus-summary-next-unread-subject t]
2243         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2244         ["Next article same subject" gnus-summary-next-same-subject t]
2245         ["Previous article same subject" gnus-summary-prev-same-subject t]
2246         ["First unread article" gnus-summary-first-unread-article t]
2247         ["Best unread article" gnus-summary-best-unread-article t]
2248         ["Go to subject number..." gnus-summary-goto-subject t]
2249         ["Go to article number..." gnus-summary-goto-article t]
2250         ["Go to the last article" gnus-summary-goto-last-article t]
2251         ["Pop article off history" gnus-summary-pop-article t])
2252        ("Sort"
2253         ["Sort by number" gnus-summary-sort-by-number t]
2254         ["Sort by author" gnus-summary-sort-by-author t]
2255         ["Sort by subject" gnus-summary-sort-by-subject t]
2256         ["Sort by date" gnus-summary-sort-by-date t]
2257         ["Sort by score" gnus-summary-sort-by-score t]
2258         ["Sort by lines" gnus-summary-sort-by-lines t]
2259         ["Sort by characters" gnus-summary-sort-by-chars t]
2260         ["Original sort" gnus-summary-sort-by-original t])
2261        ("Help"
2262         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2263         ["Describe group" gnus-summary-describe-group t]
2264         ["Read manual" gnus-info-find-node t])
2265        ("Modes"
2266         ["Pick and read" gnus-pick-mode t]
2267         ["Binary" gnus-binary-mode t])
2268        ("Regeneration"
2269         ["Regenerate" gnus-summary-prepare t]
2270         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2271         ["Toggle threading" gnus-summary-toggle-threads t])
2272        ["See old articles" gnus-summary-insert-old-articles t]
2273        ["See new articles" gnus-summary-insert-new-articles t]
2274        ["Filter articles..." gnus-summary-execute-command t]
2275        ["Run command on subjects..." gnus-summary-universal-argument t]
2276        ["Search articles forward..." gnus-summary-search-article-forward t]
2277        ["Search articles backward..." gnus-summary-search-article-backward t]
2278        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2279        ["Expand window" gnus-summary-expand-window t]
2280        ["Expire expirable articles" gnus-summary-expire-articles
2281         (gnus-check-backend-function
2282          'request-expire-articles gnus-newsgroup-name)]
2283        ["Edit local kill file" gnus-summary-edit-local-kill t]
2284        ["Edit main kill file" gnus-summary-edit-global-kill t]
2285        ["Edit group parameters" gnus-summary-edit-parameters t]
2286        ["Customize group parameters" gnus-summary-customize-parameters t]
2287        ["Send a bug report" gnus-bug t]
2288        ("Exit"
2289         ["Catchup and exit" gnus-summary-catchup-and-exit
2290          ,@(if (featurep 'xemacs) '(t)
2291              '(:help "Mark unread articles in this group as read, then exit"))]
2292         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2293         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2294         ["Exit group" gnus-summary-exit
2295          ,@(if (featurep 'xemacs) '(t)
2296              '(:help "Exit current group, return to group selection mode"))]
2297         ["Exit group without updating" gnus-summary-exit-no-update t]
2298         ["Exit and goto next group" gnus-summary-next-group t]
2299         ["Exit and goto prev group" gnus-summary-prev-group t]
2300         ["Reselect group" gnus-summary-reselect-current-group t]
2301         ["Rescan group" gnus-summary-rescan-group t]
2302         ["Update dribble" gnus-summary-save-newsrc t])))
2303
2304     (gnus-run-hooks 'gnus-summary-menu-hook)))
2305
2306 (defvar gnus-summary-tool-bar-map nil)
2307
2308 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2309 (defun gnus-summary-make-tool-bar ()
2310   (if (and (fboundp 'tool-bar-add-item-from-menu)
2311            (default-value 'tool-bar-mode)
2312            (not gnus-summary-tool-bar-map))
2313       (setq gnus-summary-tool-bar-map
2314             (let ((tool-bar-map (make-sparse-keymap))
2315                   (load-path (mm-image-load-path)))
2316               (tool-bar-add-item-from-menu
2317                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2318               (tool-bar-add-item-from-menu
2319                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2320               (tool-bar-add-item-from-menu
2321                'gnus-summary-post-news "post" gnus-summary-mode-map)
2322               (tool-bar-add-item-from-menu
2323                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2324               (tool-bar-add-item-from-menu
2325                'gnus-summary-followup "followup" gnus-summary-mode-map)
2326               (tool-bar-add-item-from-menu
2327                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2328               (tool-bar-add-item-from-menu
2329                'gnus-summary-reply "reply" gnus-summary-mode-map)
2330               (tool-bar-add-item-from-menu
2331                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2332               (tool-bar-add-item-from-menu
2333                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2334               (tool-bar-add-item-from-menu
2335                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2336               (tool-bar-add-item-from-menu
2337                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2338               (tool-bar-add-item-from-menu
2339                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2340               (tool-bar-add-item-from-menu
2341                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2342               (tool-bar-add-item-from-menu
2343                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2344               (tool-bar-add-item-from-menu
2345                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2346               tool-bar-map)))
2347   (if gnus-summary-tool-bar-map
2348       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2349
2350 (defun gnus-score-set-default (var value)
2351   "A version of set that updates the GNU Emacs menu-bar."
2352   (set var value)
2353   ;; It is the message that forces the active status to be updated.
2354   (message ""))
2355
2356 (defun gnus-make-score-map (type)
2357   "Make a summary score map of type TYPE."
2358   (if t
2359       nil
2360     (let ((headers '(("author" "from" string)
2361                      ("subject" "subject" string)
2362                      ("article body" "body" string)
2363                      ("article head" "head" string)
2364                      ("xref" "xref" string)
2365                      ("extra header" "extra" string)
2366                      ("lines" "lines" number)
2367                      ("followups to author" "followup" string)))
2368           (types '((number ("less than" <)
2369                            ("greater than" >)
2370                            ("equal" =))
2371                    (string ("substring" s)
2372                            ("exact string" e)
2373                            ("fuzzy string" f)
2374                            ("regexp" r))))
2375           (perms '(("temporary" (current-time-string))
2376                    ("permanent" nil)
2377                    ("immediate" now)))
2378           header)
2379       (list
2380        (apply
2381         'nconc
2382         (list
2383          (if (eq type 'lower)
2384              "Lower score"
2385            "Increase score"))
2386         (let (outh)
2387           (while headers
2388             (setq header (car headers))
2389             (setq outh
2390                   (cons
2391                    (apply
2392                     'nconc
2393                     (list (car header))
2394                     (let ((ts (cdr (assoc (nth 2 header) types)))
2395                           outt)
2396                       (while ts
2397                         (setq outt
2398                               (cons
2399                                (apply
2400                                 'nconc
2401                                 (list (caar ts))
2402                                 (let ((ps perms)
2403                                       outp)
2404                                   (while ps
2405                                     (setq outp
2406                                           (cons
2407                                            (vector
2408                                             (caar ps)
2409                                             (list
2410                                              'gnus-summary-score-entry
2411                                              (nth 1 header)
2412                                              (if (or (string= (nth 1 header)
2413                                                               "head")
2414                                                      (string= (nth 1 header)
2415                                                               "body"))
2416                                                  ""
2417                                                (list 'gnus-summary-header
2418                                                      (nth 1 header)))
2419                                              (list 'quote (nth 1 (car ts)))
2420                                              (list 'gnus-score-delta-default
2421                                                    nil)
2422                                              (nth 1 (car ps))
2423                                              t)
2424                                             t)
2425                                            outp))
2426                                     (setq ps (cdr ps)))
2427                                   (list (nreverse outp))))
2428                                outt))
2429                         (setq ts (cdr ts)))
2430                       (list (nreverse outt))))
2431                    outh))
2432             (setq headers (cdr headers)))
2433           (list (nreverse outh))))))))
2434
2435 \f
2436
2437 (defun gnus-summary-mode (&optional group)
2438   "Major mode for reading articles.
2439
2440 All normal editing commands are switched off.
2441 \\<gnus-summary-mode-map>
2442 Each line in this buffer represents one article.  To read an
2443 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2444 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2445 respectively.
2446
2447 You can also post articles and send mail from this buffer.  To
2448 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2449 of an article, type `\\[gnus-summary-reply]'.
2450
2451 There are approx. one gazillion commands you can execute in this
2452 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2453
2454 The following commands are available:
2455
2456 \\{gnus-summary-mode-map}"
2457   (interactive)
2458   (kill-all-local-variables)
2459   (when (gnus-visual-p 'summary-menu 'menu)
2460     (gnus-summary-make-menu-bar)
2461     (gnus-summary-make-tool-bar))
2462   (gnus-summary-make-local-variables)
2463   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2464     (gnus-summary-make-local-variables))
2465   (gnus-make-thread-indent-array)
2466   (gnus-simplify-mode-line)
2467   (setq major-mode 'gnus-summary-mode)
2468   (setq mode-name "Summary")
2469   (make-local-variable 'minor-mode-alist)
2470   (use-local-map gnus-summary-mode-map)
2471   (buffer-disable-undo)
2472   (setq buffer-read-only t)             ;Disable modification
2473   (setq truncate-lines t)
2474   (setq selective-display t)
2475   (setq selective-display-ellipses t)   ;Display `...'
2476   (gnus-summary-set-display-table)
2477   (gnus-set-default-directory)
2478   (setq gnus-newsgroup-name group)
2479   (unless (gnus-news-group-p group)
2480     (setq gnus-newsgroup-incorporated
2481           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2482   (make-local-variable 'gnus-summary-line-format)
2483   (make-local-variable 'gnus-summary-line-format-spec)
2484   (make-local-variable 'gnus-summary-dummy-line-format)
2485   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2486   (make-local-variable 'gnus-summary-mark-positions)
2487   (make-local-hook 'pre-command-hook)
2488   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2489   (gnus-run-hooks 'gnus-summary-mode-hook)
2490   (turn-on-gnus-mailing-list-mode)
2491   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2492   (gnus-update-summary-mark-positions))
2493
2494 (defun gnus-summary-make-local-variables ()
2495   "Make all the local summary buffer variables."
2496   (let (global)
2497     (dolist (local gnus-summary-local-variables)
2498       (if (consp local)
2499           (progn
2500             (if (eq (cdr local) 'global)
2501                 ;; Copy the global value of the variable.
2502                 (setq global (symbol-value (car local)))
2503               ;; Use the value from the list.
2504               (setq global (eval (cdr local))))
2505             (set (make-local-variable (car local)) global))
2506         ;; Simple nil-valued local variable.
2507         (set (make-local-variable local) nil)))))
2508
2509 (defun gnus-summary-clear-local-variables ()
2510   (let ((locals gnus-summary-local-variables))
2511     (while locals
2512       (if (consp (car locals))
2513           (and (vectorp (caar locals))
2514                (set (caar locals) nil))
2515         (and (vectorp (car locals))
2516              (set (car locals) nil)))
2517       (setq locals (cdr locals)))))
2518
2519 ;; Summary data functions.
2520
2521 (defmacro gnus-data-number (data)
2522   `(car ,data))
2523
2524 (defmacro gnus-data-set-number (data number)
2525   `(setcar ,data ,number))
2526
2527 (defmacro gnus-data-mark (data)
2528   `(nth 1 ,data))
2529
2530 (defmacro gnus-data-set-mark (data mark)
2531   `(setcar (nthcdr 1 ,data) ,mark))
2532
2533 (defmacro gnus-data-pos (data)
2534   `(nth 2 ,data))
2535
2536 (defmacro gnus-data-set-pos (data pos)
2537   `(setcar (nthcdr 2 ,data) ,pos))
2538
2539 (defmacro gnus-data-header (data)
2540   `(nth 3 ,data))
2541
2542 (defmacro gnus-data-set-header (data header)
2543   `(setcar (nthcdr 3 ,data) ,header))
2544
2545 (defmacro gnus-data-level (data)
2546   `(nth 4 ,data))
2547
2548 (defmacro gnus-data-unread-p (data)
2549   `(= (nth 1 ,data) gnus-unread-mark))
2550
2551 (defmacro gnus-data-read-p (data)
2552   `(/= (nth 1 ,data) gnus-unread-mark))
2553
2554 (defmacro gnus-data-pseudo-p (data)
2555   `(consp (nth 3 ,data)))
2556
2557 (defmacro gnus-data-find (number)
2558   `(assq ,number gnus-newsgroup-data))
2559
2560 (defmacro gnus-data-find-list (number &optional data)
2561   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2562      (memq (assq ,number bdata)
2563            bdata)))
2564
2565 (defmacro gnus-data-make (number mark pos header level)
2566   `(list ,number ,mark ,pos ,header ,level))
2567
2568 (defun gnus-data-enter (after-article number mark pos header level offset)
2569   (let ((data (gnus-data-find-list after-article)))
2570     (unless data
2571       (error "No such article: %d" after-article))
2572     (setcdr data (cons (gnus-data-make number mark pos header level)
2573                        (cdr data)))
2574     (setq gnus-newsgroup-data-reverse nil)
2575     (gnus-data-update-list (cddr data) offset)))
2576
2577 (defun gnus-data-enter-list (after-article list &optional offset)
2578   (when list
2579     (let ((data (and after-article (gnus-data-find-list after-article)))
2580           (ilist list))
2581       (if (not (or data
2582                    after-article))
2583           (let ((odata gnus-newsgroup-data))
2584             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2585             (when offset
2586               (gnus-data-update-list odata offset)))
2587         ;; Find the last element in the list to be spliced into the main
2588         ;; list.
2589         (while (cdr list)
2590           (setq list (cdr list)))
2591         (if (not data)
2592             (progn
2593               (setcdr list gnus-newsgroup-data)
2594               (setq gnus-newsgroup-data ilist)
2595               (when offset
2596                 (gnus-data-update-list (cdr list) offset)))
2597           (setcdr list (cdr data))
2598           (setcdr data ilist)
2599           (when offset
2600             (gnus-data-update-list (cdr list) offset))))
2601       (setq gnus-newsgroup-data-reverse nil))))
2602
2603 (defun gnus-data-remove (article &optional offset)
2604   (let ((data gnus-newsgroup-data))
2605     (if (= (gnus-data-number (car data)) article)
2606         (progn
2607           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2608                 gnus-newsgroup-data-reverse nil)
2609           (when offset
2610             (gnus-data-update-list gnus-newsgroup-data offset)))
2611       (while (cdr data)
2612         (when (= (gnus-data-number (cadr data)) article)
2613           (setcdr data (cddr data))
2614           (when offset
2615             (gnus-data-update-list (cdr data) offset))
2616           (setq data nil
2617                 gnus-newsgroup-data-reverse nil))
2618         (setq data (cdr data))))))
2619
2620 (defmacro gnus-data-list (backward)
2621   `(if ,backward
2622        (or gnus-newsgroup-data-reverse
2623            (setq gnus-newsgroup-data-reverse
2624                  (reverse gnus-newsgroup-data)))
2625      gnus-newsgroup-data))
2626
2627 (defun gnus-data-update-list (data offset)
2628   "Add OFFSET to the POS of all data entries in DATA."
2629   (setq gnus-newsgroup-data-reverse nil)
2630   (while data
2631     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2632     (setq data (cdr data))))
2633
2634 (defun gnus-summary-article-pseudo-p (article)
2635   "Say whether this article is a pseudo article or not."
2636   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2637
2638 (defmacro gnus-summary-article-sparse-p (article)
2639   "Say whether this article is a sparse article or not."
2640   `(memq ,article gnus-newsgroup-sparse))
2641
2642 (defmacro gnus-summary-article-ancient-p (article)
2643   "Say whether this article is a sparse article or not."
2644   `(memq ,article gnus-newsgroup-ancient))
2645
2646 (defun gnus-article-parent-p (number)
2647   "Say whether this article is a parent or not."
2648   (let ((data (gnus-data-find-list number)))
2649     (and (cdr data)                     ; There has to be an article after...
2650          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2651             (gnus-data-level (nth 1 data))))))
2652
2653 (defun gnus-article-children (number)
2654   "Return a list of all children to NUMBER."
2655   (let* ((data (gnus-data-find-list number))
2656          (level (gnus-data-level (car data)))
2657          children)
2658     (setq data (cdr data))
2659     (while (and data
2660                 (= (gnus-data-level (car data)) (1+ level)))
2661       (push (gnus-data-number (car data)) children)
2662       (setq data (cdr data)))
2663     children))
2664
2665 (defmacro gnus-summary-skip-intangible ()
2666   "If the current article is intangible, then jump to a different article."
2667   '(let ((to (get-text-property (point) 'gnus-intangible)))
2668      (and to (gnus-summary-goto-subject to))))
2669
2670 (defmacro gnus-summary-article-intangible-p ()
2671   "Say whether this article is intangible or not."
2672   '(get-text-property (point) 'gnus-intangible))
2673
2674 (defun gnus-article-read-p (article)
2675   "Say whether ARTICLE is read or not."
2676   (not (or (memq article gnus-newsgroup-marked)
2677            (memq article gnus-newsgroup-unreads)
2678            (memq article gnus-newsgroup-unselected)
2679            (memq article gnus-newsgroup-dormant))))
2680
2681 ;; Some summary mode macros.
2682
2683 (defmacro gnus-summary-article-number ()
2684   "The article number of the article on the current line.
2685 If there isn's an article number here, then we return the current
2686 article number."
2687   '(progn
2688      (gnus-summary-skip-intangible)
2689      (or (get-text-property (point) 'gnus-number)
2690          (gnus-summary-last-subject))))
2691
2692 (defmacro gnus-summary-article-header (&optional number)
2693   "Return the header of article NUMBER."
2694   `(gnus-data-header (gnus-data-find
2695                       ,(or number '(gnus-summary-article-number)))))
2696
2697 (defmacro gnus-summary-thread-level (&optional number)
2698   "Return the level of thread that starts with article NUMBER."
2699   `(if (and (eq gnus-summary-make-false-root 'dummy)
2700             (get-text-property (point) 'gnus-intangible))
2701        0
2702      (gnus-data-level (gnus-data-find
2703                        ,(or number '(gnus-summary-article-number))))))
2704
2705 (defmacro gnus-summary-article-mark (&optional number)
2706   "Return the mark of article NUMBER."
2707   `(gnus-data-mark (gnus-data-find
2708                     ,(or number '(gnus-summary-article-number)))))
2709
2710 (defmacro gnus-summary-article-pos (&optional number)
2711   "Return the position of the line of article NUMBER."
2712   `(gnus-data-pos (gnus-data-find
2713                    ,(or number '(gnus-summary-article-number)))))
2714
2715 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2716 (defmacro gnus-summary-article-subject (&optional number)
2717   "Return current subject string or nil if nothing."
2718   `(let ((headers
2719           ,(if number
2720                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2721              '(gnus-data-header (assq (gnus-summary-article-number)
2722                                       gnus-newsgroup-data)))))
2723      (and headers
2724           (vectorp headers)
2725           (mail-header-subject headers))))
2726
2727 (defmacro gnus-summary-article-score (&optional number)
2728   "Return current article score."
2729   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2730                   gnus-newsgroup-scored))
2731        gnus-summary-default-score 0))
2732
2733 (defun gnus-summary-article-children (&optional number)
2734   "Return a list of article numbers that are children of article NUMBER."
2735   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2736          (level (gnus-data-level (car data)))
2737          l children)
2738     (while (and (setq data (cdr data))
2739                 (> (setq l (gnus-data-level (car data))) level))
2740       (and (= (1+ level) l)
2741            (push (gnus-data-number (car data))
2742                  children)))
2743     (nreverse children)))
2744
2745 (defun gnus-summary-article-parent (&optional number)
2746   "Return the article number of the parent of article NUMBER."
2747   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2748                                     (gnus-data-list t)))
2749          (level (gnus-data-level (car data))))
2750     (if (zerop level)
2751         ()                              ; This is a root.
2752       ;; We search until we find an article with a level less than
2753       ;; this one.  That function has to be the parent.
2754       (while (and (setq data (cdr data))
2755                   (not (< (gnus-data-level (car data)) level))))
2756       (and data (gnus-data-number (car data))))))
2757
2758 (defun gnus-unread-mark-p (mark)
2759   "Say whether MARK is the unread mark."
2760   (= mark gnus-unread-mark))
2761
2762 (defun gnus-read-mark-p (mark)
2763   "Say whether MARK is one of the marks that mark as read.
2764 This is all marks except unread, ticked, dormant, and expirable."
2765   (not (or (= mark gnus-unread-mark)
2766            (= mark gnus-ticked-mark)
2767            (= mark gnus-dormant-mark)
2768            (= mark gnus-expirable-mark))))
2769
2770 (defmacro gnus-article-mark (number)
2771   "Return the MARK of article NUMBER.
2772 This macro should only be used when computing the mark the \"first\"
2773 time; i.e., when generating the summary lines.  After that,
2774 `gnus-summary-article-mark' should be used to examine the
2775 marks of articles."
2776   `(cond
2777     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2778     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2779     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2780     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2781     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2782     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2783     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2784     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2785            gnus-ancient-mark))))
2786
2787 ;; Saving hidden threads.
2788
2789 (defmacro gnus-save-hidden-threads (&rest forms)
2790   "Save hidden threads, eval FORMS, and restore the hidden threads."
2791   (let ((config (make-symbol "config")))
2792     `(let ((,config (gnus-hidden-threads-configuration)))
2793        (unwind-protect
2794            (save-excursion
2795              ,@forms)
2796          (gnus-restore-hidden-threads-configuration ,config)))))
2797 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2798 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2799
2800 (defun gnus-data-compute-positions ()
2801   "Compute the positions of all articles."
2802   (setq gnus-newsgroup-data-reverse nil)
2803   (let ((data gnus-newsgroup-data))
2804     (save-excursion
2805       (gnus-save-hidden-threads
2806         (gnus-summary-show-all-threads)
2807         (goto-char (point-min))
2808         (while data
2809           (while (get-text-property (point) 'gnus-intangible)
2810             (forward-line 1))
2811           (gnus-data-set-pos (car data) (+ (point) 3))
2812           (setq data (cdr data))
2813           (forward-line 1))))))
2814
2815 (defun gnus-hidden-threads-configuration ()
2816   "Return the current hidden threads configuration."
2817   (save-excursion
2818     (let (config)
2819       (goto-char (point-min))
2820       (while (search-forward "\r" nil t)
2821         (push (1- (point)) config))
2822       config)))
2823
2824 (defun gnus-restore-hidden-threads-configuration (config)
2825   "Restore hidden threads configuration from CONFIG."
2826   (save-excursion
2827     (let (point buffer-read-only)
2828       (while (setq point (pop config))
2829         (when (and (< point (point-max))
2830                    (goto-char point)
2831                    (eq (char-after) ?\n))
2832           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2833
2834 ;; Various summary mode internalish functions.
2835
2836 (defun gnus-mouse-pick-article (e)
2837   (interactive "e")
2838   (mouse-set-point e)
2839   (gnus-summary-next-page nil t))
2840
2841 (defun gnus-summary-set-display-table ()
2842   "Change the display table.
2843 Odd characters have a tendency to mess
2844 up nicely formatted displays - we make all possible glyphs
2845 display only a single character."
2846
2847   ;; We start from the standard display table, if any.
2848   (let ((table (or (copy-sequence standard-display-table)
2849                    (make-display-table)))
2850         (i 32))
2851     ;; Nix out all the control chars...
2852     (while (>= (setq i (1- i)) 0)
2853       (aset table i [??]))
2854     ;; ... but not newline and cr, of course.  (cr is necessary for the
2855     ;; selective display).
2856     (aset table ?\n nil)
2857     (aset table ?\r nil)
2858     ;; We keep TAB as well.
2859     (aset table ?\t nil)
2860     ;; We nix out any glyphs over 126 that are not set already.
2861     (let ((i 256))
2862       (while (>= (setq i (1- i)) 127)
2863         ;; Only modify if the entry is nil.
2864         (unless (aref table i)
2865           (aset table i [??]))))
2866     (setq buffer-display-table table)))
2867
2868 (defun gnus-summary-set-article-display-arrow (pos)
2869   "Update the overlay arrow to point to line at position POS."
2870   (when (and gnus-summary-display-arrow
2871              (boundp 'overlay-arrow-position)
2872              (boundp 'overlay-arrow-string))
2873     (save-excursion
2874       (goto-char pos)
2875       (beginning-of-line)
2876       (unless overlay-arrow-position
2877         (setq overlay-arrow-position (make-marker)))
2878       (setq overlay-arrow-string "=>"
2879             overlay-arrow-position (set-marker overlay-arrow-position
2880                                                (point)
2881                                                (current-buffer))))))
2882
2883 (defun gnus-summary-buffer-name (group)
2884   "Return the summary buffer name of GROUP."
2885   (concat "*Summary " (gnus-group-decoded-name group) "*"))
2886
2887 (defun gnus-summary-setup-buffer (group)
2888   "Initialize summary buffer."
2889   (let ((buffer (gnus-summary-buffer-name group))
2890         (dead-name (concat "*Dead Summary "
2891                            (gnus-group-decoded-name group) "*")))
2892     ;; If a dead summary buffer exists, we kill it.
2893     (when (gnus-buffer-live-p dead-name)
2894       (gnus-kill-buffer dead-name))
2895     (if (get-buffer buffer)
2896         (progn
2897           (set-buffer buffer)
2898           (setq gnus-summary-buffer (current-buffer))
2899           (not gnus-newsgroup-prepared))
2900       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2901       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2902       (gnus-summary-mode group)
2903       (when gnus-carpal
2904         (gnus-carpal-setup-buffer 'summary))
2905       (unless gnus-single-article-buffer
2906         (make-local-variable 'gnus-article-buffer)
2907         (make-local-variable 'gnus-article-current)
2908         (make-local-variable 'gnus-original-article-buffer))
2909       (setq gnus-newsgroup-name group)
2910       ;; Set any local variables in the group parameters.
2911       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2912       t)))
2913
2914 (defun gnus-set-global-variables ()
2915   "Set the global equivalents of the buffer-local variables.
2916 They are set to the latest values they had.  These reflect the summary
2917 buffer that was in action when the last article was fetched."
2918   (when (eq major-mode 'gnus-summary-mode)
2919     (setq gnus-summary-buffer (current-buffer))
2920     (let ((name gnus-newsgroup-name)
2921           (marked gnus-newsgroup-marked)
2922           (unread gnus-newsgroup-unreads)
2923           (headers gnus-current-headers)
2924           (data gnus-newsgroup-data)
2925           (summary gnus-summary-buffer)
2926           (article-buffer gnus-article-buffer)
2927           (original gnus-original-article-buffer)
2928           (gac gnus-article-current)
2929           (reffed gnus-reffed-article-number)
2930           (score-file gnus-current-score-file)
2931           (default-charset gnus-newsgroup-charset)
2932           vlist)
2933       (let ((locals gnus-newsgroup-variables))
2934         (while locals
2935           (if (consp (car locals))
2936               (push (eval (caar locals)) vlist)
2937             (push (eval (car locals)) vlist))
2938           (setq locals (cdr locals)))
2939         (setq vlist (nreverse vlist)))
2940       (save-excursion
2941         (set-buffer gnus-group-buffer)
2942         (setq gnus-newsgroup-name name
2943               gnus-newsgroup-marked marked
2944               gnus-newsgroup-unreads unread
2945               gnus-current-headers headers
2946               gnus-newsgroup-data data
2947               gnus-article-current gac
2948               gnus-summary-buffer summary
2949               gnus-article-buffer article-buffer
2950               gnus-original-article-buffer original
2951               gnus-reffed-article-number reffed
2952               gnus-current-score-file score-file
2953               gnus-newsgroup-charset default-charset)
2954         (let ((locals gnus-newsgroup-variables))
2955           (while locals
2956             (if (consp (car locals))
2957                 (set (caar locals) (pop vlist))
2958               (set (car locals) (pop vlist)))
2959             (setq locals (cdr locals))))
2960         ;; The article buffer also has local variables.
2961         (when (gnus-buffer-live-p gnus-article-buffer)
2962           (set-buffer gnus-article-buffer)
2963           (setq gnus-summary-buffer summary))))))
2964
2965 (defun gnus-summary-article-unread-p (article)
2966   "Say whether ARTICLE is unread or not."
2967   (memq article gnus-newsgroup-unreads))
2968
2969 (defun gnus-summary-first-article-p (&optional article)
2970   "Return whether ARTICLE is the first article in the buffer."
2971   (if (not (setq article (or article (gnus-summary-article-number))))
2972       nil
2973     (eq article (caar gnus-newsgroup-data))))
2974
2975 (defun gnus-summary-last-article-p (&optional article)
2976   "Return whether ARTICLE is the last article in the buffer."
2977   (if (not (setq article (or article (gnus-summary-article-number))))
2978       ;; All non-existent numbers are the last article.  :-)
2979       t
2980     (not (cdr (gnus-data-find-list article)))))
2981
2982 (defun gnus-make-thread-indent-array ()
2983   (let ((n 200))
2984     (unless (and gnus-thread-indent-array
2985                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2986       (setq gnus-thread-indent-array (make-vector 201 "")
2987             gnus-thread-indent-array-level gnus-thread-indent-level)
2988       (while (>= n 0)
2989         (aset gnus-thread-indent-array n
2990               (make-string (* n gnus-thread-indent-level) ? ))
2991         (setq n (1- n))))))
2992
2993 (defun gnus-update-summary-mark-positions ()
2994   "Compute where the summary marks are to go."
2995   (save-excursion
2996     (when (gnus-buffer-exists-p gnus-summary-buffer)
2997       (set-buffer gnus-summary-buffer))
2998     (let ((gnus-replied-mark 129)
2999           (gnus-score-below-mark 130)
3000           (gnus-score-over-mark 130)
3001           (gnus-download-mark 131)
3002           (spec gnus-summary-line-format-spec)
3003           gnus-visual pos)
3004       (save-excursion
3005         (gnus-set-work-buffer)
3006         (let ((gnus-summary-line-format-spec spec)
3007               (gnus-newsgroup-downloadable '((0 . t))))
3008           (gnus-summary-insert-line
3009            (make-full-mail-header 0 "" "nobody"
3010                                   "05 Apr 2001 23:33:09 +0400"
3011                                   "" "" 0 0 "" nil)
3012            0 nil 128 t nil "" nil 1)
3013           (goto-char (point-min))
3014           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3015                                              (- (point) 2)))))
3016           (goto-char (point-min))
3017           (push (cons 'replied (and (search-forward "\201" nil t)
3018                                     (- (point) 2)))
3019                 pos)
3020           (goto-char (point-min))
3021           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
3022                 pos)
3023           (goto-char (point-min))
3024           (push (cons 'download
3025                       (and (search-forward "\203" nil t) (- (point) 2)))
3026                 pos)))
3027       (setq gnus-summary-mark-positions pos))))
3028
3029 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3030   "Insert a dummy root in the summary buffer."
3031   (beginning-of-line)
3032   (gnus-add-text-properties
3033    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3034    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3035
3036 (defun gnus-summary-extract-address-component (from)
3037   (or (car (funcall gnus-extract-address-components from))
3038       from))
3039
3040 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3041   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3042                                 default-mime-charset)))
3043     ;; Is it really necessary to do this next part for each summary line?
3044     ;; Luckily, doesn't seem to slow things down much.
3045     (or
3046      (and gnus-ignored-from-addresses
3047           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3048           (let ((extra-headers (mail-header-extra header))
3049                 to
3050                 newsgroups)
3051             (cond
3052              ((setq to (cdr (assq 'To extra-headers)))
3053               (concat "-> "
3054                       (inline
3055                         (gnus-summary-extract-address-component
3056                          (funcall gnus-decode-encoded-word-function to)))))
3057              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3058               (concat "=> " newsgroups)))))
3059      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3060
3061 (defun gnus-summary-insert-line (gnus-tmp-header
3062                                  gnus-tmp-level gnus-tmp-current
3063                                  gnus-tmp-unread gnus-tmp-replied
3064                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3065                                  &optional gnus-tmp-dummy gnus-tmp-score
3066                                  gnus-tmp-process)
3067   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3068          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3069          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3070          (gnus-tmp-score-char
3071           (if (or (null gnus-summary-default-score)
3072                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3073                       gnus-summary-zcore-fuzz))
3074               ?\ ;;;Whitespace
3075             (if (< gnus-tmp-score gnus-summary-default-score)
3076                 gnus-score-below-mark gnus-score-over-mark)))
3077          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3078          (gnus-tmp-replied
3079           (cond (gnus-tmp-process gnus-process-mark)
3080                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3081                  gnus-cached-mark)
3082                 (gnus-tmp-replied gnus-replied-mark)
3083                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3084                  gnus-forwarded-mark)
3085                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3086                  gnus-saved-mark)
3087                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3088                  gnus-recent-mark)
3089                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3090                  gnus-unseen-mark)
3091                 (t gnus-no-mark)))
3092          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3093          (gnus-tmp-name
3094           (cond
3095            ((string-match "<[^>]+> *$" gnus-tmp-from)
3096             (let ((beg (match-beginning 0)))
3097               (or (and (string-match "^\".+\"" gnus-tmp-from)
3098                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3099                   (substring gnus-tmp-from 0 beg))))
3100            ((string-match "(.+)" gnus-tmp-from)
3101             (substring gnus-tmp-from
3102                        (1+ (match-beginning 0)) (1- (match-end 0))))
3103            (t gnus-tmp-from)))
3104          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3105          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3106          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3107          (buffer-read-only nil))
3108     (when (string= gnus-tmp-name "")
3109       (setq gnus-tmp-name gnus-tmp-from))
3110     (unless (numberp gnus-tmp-lines)
3111       (setq gnus-tmp-lines -1))
3112     (if (= gnus-tmp-lines -1)
3113         (setq gnus-tmp-lines "?")
3114       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3115     (gnus-put-text-property-excluding-characters-with-faces
3116      (point)
3117      (progn (eval gnus-summary-line-format-spec) (point))
3118      'gnus-number gnus-tmp-number)
3119     (when (gnus-visual-p 'summary-highlight 'highlight)
3120       (forward-line -1)
3121       (gnus-run-hooks 'gnus-summary-update-hook)
3122       (forward-line 1))))
3123
3124 (defun gnus-summary-update-line (&optional dont-update)
3125   "Update summary line after change."
3126   (when (and gnus-summary-default-score
3127              (not gnus-summary-inhibit-highlight))
3128     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3129            (article (gnus-summary-article-number))
3130            (score (gnus-summary-article-score article)))
3131       (unless dont-update
3132         (if (and gnus-summary-mark-below
3133                  (< (gnus-summary-article-score)
3134                     gnus-summary-mark-below))
3135             ;; This article has a low score, so we mark it as read.
3136             (when (memq article gnus-newsgroup-unreads)
3137               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3138           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3139             ;; This article was previously marked as read on account
3140             ;; of a low score, but now it has risen, so we mark it as
3141             ;; unread.
3142             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3143         (gnus-summary-update-mark
3144          (if (or (null gnus-summary-default-score)
3145                  (<= (abs (- score gnus-summary-default-score))
3146                      gnus-summary-zcore-fuzz))
3147              ?\ ;;;Whitespace
3148            (if (< score gnus-summary-default-score)
3149                gnus-score-below-mark gnus-score-over-mark))
3150          'score))
3151       ;; Do visual highlighting.
3152       (when (gnus-visual-p 'summary-highlight 'highlight)
3153         (gnus-run-hooks 'gnus-summary-update-hook)))))
3154
3155 (defvar gnus-tmp-new-adopts nil)
3156
3157 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3158   "Return the number of articles in THREAD.
3159 This may be 0 in some cases -- if none of the articles in
3160 the thread are to be displayed."
3161   (let* ((number
3162           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3163           (cond
3164            ((not (listp thread))
3165             1)
3166            ((and (consp thread) (cdr thread))
3167             (apply
3168              '+ 1 (mapcar
3169                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3170            ((null thread)
3171             1)
3172            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3173             1)
3174            (t 0))))
3175     (when (and level (zerop level) gnus-tmp-new-adopts)
3176       (incf number
3177             (apply '+ (mapcar
3178                        'gnus-summary-number-of-articles-in-thread
3179                        gnus-tmp-new-adopts))))
3180     (if char
3181         (if (> number 1) gnus-not-empty-thread-mark
3182           gnus-empty-thread-mark)
3183       number)))
3184
3185 (defun gnus-summary-set-local-parameters (group)
3186   "Go through the local params of GROUP and set all variable specs in that list."
3187   (let ((params (gnus-group-find-parameter group))
3188         (vars '(quit-config))           ; Ignore quit-config.
3189         elem)
3190     (while params
3191       (setq elem (car params)
3192             params (cdr params))
3193       (and (consp elem)                 ; Has to be a cons.
3194            (consp (cdr elem))           ; The cdr has to be a list.
3195            (symbolp (car elem))         ; Has to be a symbol in there.
3196            (not (memq (car elem) vars))
3197            (ignore-errors               ; So we set it.
3198              (push (car elem) vars)
3199              (make-local-variable (car elem))
3200              (set (car elem) (eval (nth 1 elem))))))))
3201
3202 (defun gnus-summary-read-group (group &optional show-all no-article
3203                                       kill-buffer no-display backward
3204                                       select-articles)
3205   "Start reading news in newsgroup GROUP.
3206 If SHOW-ALL is non-nil, already read articles are also listed.
3207 If NO-ARTICLE is non-nil, no article is selected initially.
3208 If NO-DISPLAY, don't generate a summary buffer."
3209   (let (result)
3210     (while (and group
3211                 (null (setq result
3212                             (let ((gnus-auto-select-next nil))
3213                               (or (gnus-summary-read-group-1
3214                                    group show-all no-article
3215                                    kill-buffer no-display
3216                                    select-articles)
3217                                   (setq show-all nil
3218                                         select-articles nil)))))
3219                 (eq gnus-auto-select-next 'quietly))
3220       (set-buffer gnus-group-buffer)
3221       ;; The entry function called above goes to the next
3222       ;; group automatically, so we go two groups back
3223       ;; if we are searching for the previous group.
3224       (when backward
3225         (gnus-group-prev-unread-group 2))
3226       (if (not (equal group (gnus-group-group-name)))
3227           (setq group (gnus-group-group-name))
3228         (setq group nil)))
3229     result))
3230
3231 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3232   "Directly jump to the other GROUP from summary buffer.
3233 If SHOW-ALL is non-nil, already read articles are also listed."
3234   (interactive
3235    (if (eq gnus-summary-buffer (current-buffer))
3236        (list (completing-read
3237               "Group: " gnus-active-hashtb nil t
3238               (when (and gnus-newsgroup-name
3239                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3240                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3241               'gnus-group-history)
3242              current-prefix-arg)
3243      (error "%s must be invoked from a gnus summary buffer." this-command)))
3244   (unless (or (zerop (length group))
3245               (and gnus-newsgroup-name
3246                    (string-equal gnus-newsgroup-name group)))
3247     (gnus-summary-exit)
3248     (gnus-summary-read-group group show-all
3249                              gnus-dont-select-after-jump-to-other-group)))
3250
3251 (defun gnus-summary-read-group-1 (group show-all no-article
3252                                         kill-buffer no-display
3253                                         &optional select-articles)
3254   ;; Killed foreign groups can't be entered.
3255   ;;  (when (and (not (gnus-group-native-p group))
3256   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3257   ;;    (error "Dead non-native groups can't be entered"))
3258   (gnus-message 5 "Retrieving newsgroup: %s..."
3259                 (gnus-group-decoded-name group))
3260   (let* ((new-group (gnus-summary-setup-buffer group))
3261          (quit-config (gnus-group-quit-config group))
3262          (did-select (and new-group (gnus-select-newsgroup
3263                                      group show-all select-articles))))
3264     (cond
3265      ;; This summary buffer exists already, so we just select it.
3266      ((not new-group)
3267       (gnus-set-global-variables)
3268       (when kill-buffer
3269         (gnus-kill-or-deaden-summary kill-buffer))
3270       (gnus-configure-windows 'summary 'force)
3271       (gnus-set-mode-line 'summary)
3272       (gnus-summary-position-point)
3273       (message "")
3274       t)
3275      ;; We couldn't select this group.
3276      ((null did-select)
3277       (when (and (eq major-mode 'gnus-summary-mode)
3278                  (not (equal (current-buffer) kill-buffer)))
3279         (kill-buffer (current-buffer))
3280         (if (not quit-config)
3281             (progn
3282               ;; Update the info -- marks might need to be removed,
3283               ;; for instance.
3284               (gnus-summary-update-info)
3285               (set-buffer gnus-group-buffer)
3286               (gnus-group-jump-to-group group)
3287               (gnus-group-next-unread-group 1))
3288           (gnus-handle-ephemeral-exit quit-config)))
3289       (let ((grpinfo (gnus-get-info group)))
3290         (if (null (gnus-info-read grpinfo))
3291             (gnus-message 3 "Group %s contains no messages"
3292                           (gnus-group-decoded-name group))
3293           (gnus-message 3 "Can't select group")))
3294       nil)
3295      ;; The user did a `C-g' while prompting for number of articles,
3296      ;; so we exit this group.
3297      ((eq did-select 'quit)
3298       (and (eq major-mode 'gnus-summary-mode)
3299            (not (equal (current-buffer) kill-buffer))
3300            (kill-buffer (current-buffer)))
3301       (when kill-buffer
3302         (gnus-kill-or-deaden-summary kill-buffer))
3303       (if (not quit-config)
3304           (progn
3305             (set-buffer gnus-group-buffer)
3306             (gnus-group-jump-to-group group)
3307             (gnus-group-next-unread-group 1)
3308             (gnus-configure-windows 'group 'force))
3309         (gnus-handle-ephemeral-exit quit-config))
3310       ;; Finally signal the quit.
3311       (signal 'quit nil))
3312      ;; The group was successfully selected.
3313      (t
3314       (gnus-set-global-variables)
3315       ;; Save the active value in effect when the group was entered.
3316       (setq gnus-newsgroup-active
3317             (gnus-copy-sequence
3318              (gnus-active gnus-newsgroup-name)))
3319       ;; You can change the summary buffer in some way with this hook.
3320       (gnus-run-hooks 'gnus-select-group-hook)
3321       (gnus-update-format-specifications
3322        nil 'summary 'summary-mode 'summary-dummy)
3323       (gnus-update-summary-mark-positions)
3324       ;; Do score processing.
3325       (when gnus-use-scoring
3326         (gnus-possibly-score-headers))
3327       ;; Check whether to fill in the gaps in the threads.
3328       (when gnus-build-sparse-threads
3329         (gnus-build-sparse-threads))
3330       ;; Find the initial limit.
3331       (if gnus-show-threads
3332           (if show-all
3333               (let ((gnus-newsgroup-dormant nil))
3334                 (gnus-summary-initial-limit show-all))
3335             (gnus-summary-initial-limit show-all))
3336         ;; When untreaded, all articles are always shown.
3337         (setq gnus-newsgroup-limit
3338               (mapcar
3339                (lambda (header) (mail-header-number header))
3340                gnus-newsgroup-headers)))
3341       ;; Generate the summary buffer.
3342       (unless no-display
3343         (gnus-summary-prepare))
3344       (when gnus-use-trees
3345         (gnus-tree-open group)
3346         (setq gnus-summary-highlight-line-function
3347               'gnus-tree-highlight-article))
3348       ;; If the summary buffer is empty, but there are some low-scored
3349       ;; articles or some excluded dormants, we include these in the
3350       ;; buffer.
3351       (when (and (zerop (buffer-size))
3352                  (not no-display))
3353         (cond (gnus-newsgroup-dormant
3354                (gnus-summary-limit-include-dormant))
3355               ((and gnus-newsgroup-scored show-all)
3356                (gnus-summary-limit-include-expunged t))))
3357       ;; Function `gnus-apply-kill-file' must be called in this hook.
3358       (gnus-run-hooks 'gnus-apply-kill-hook)
3359       (if (and (zerop (buffer-size))
3360                (not no-display))
3361           (progn
3362             ;; This newsgroup is empty.
3363             (gnus-summary-catchup-and-exit nil t)
3364             (gnus-message 6 "No unread news")
3365             (when kill-buffer
3366               (gnus-kill-or-deaden-summary kill-buffer))
3367             ;; Return nil from this function.
3368             nil)
3369         ;; Hide conversation thread subtrees.  We cannot do this in
3370         ;; gnus-summary-prepare-hook since kill processing may not
3371         ;; work with hidden articles.
3372         (gnus-summary-maybe-hide-threads)
3373         (when kill-buffer
3374           (gnus-kill-or-deaden-summary kill-buffer))
3375         (gnus-summary-auto-select-subject)
3376         ;; Show first unread article if requested.
3377         (if (and (not no-article)
3378                  (not no-display)
3379                  gnus-newsgroup-unreads
3380                  gnus-auto-select-first)
3381             (progn
3382               (gnus-configure-windows 'summary)
3383               (let ((art (gnus-summary-article-number)))
3384                 (unless (or (memq art gnus-newsgroup-undownloaded)
3385                             (memq art gnus-newsgroup-downloadable))
3386                   (gnus-summary-goto-article art))))
3387           ;; Don't select any articles.
3388           (gnus-summary-position-point)
3389           (gnus-configure-windows 'summary 'force)
3390           (gnus-set-mode-line 'summary))
3391         (when (get-buffer-window gnus-group-buffer t)
3392           ;; Gotta use windows, because recenter does weird stuff if
3393           ;; the current buffer ain't the displayed window.
3394           (let ((owin (selected-window)))
3395             (select-window (get-buffer-window gnus-group-buffer t))
3396             (when (gnus-group-goto-group group)
3397               (recenter))
3398             (select-window owin)))
3399         ;; Mark this buffer as "prepared".
3400         (setq gnus-newsgroup-prepared t)
3401         (gnus-run-hooks 'gnus-summary-prepared-hook)
3402         t)))))
3403
3404 (defun gnus-summary-auto-select-subject ()
3405   "Select the subject line on initial group entry."
3406   (goto-char (point-min))
3407   (cond
3408    ((eq gnus-auto-select-subject 'best)
3409     (gnus-summary-best-unread-subject))
3410    ((eq gnus-auto-select-subject 'unread)
3411     (gnus-summary-first-unread-subject))
3412    ((eq gnus-auto-select-subject 'unseen)
3413     (gnus-summary-first-unseen-subject))
3414    ((eq gnus-auto-select-subject 'unseen-or-unread)
3415     (gnus-summary-first-unseen-or-unread-subject))
3416    ((eq gnus-auto-select-subject 'first)
3417     ;; Do nothing.
3418     )
3419    ((gnus-functionp gnus-auto-select-subject)
3420     (funcall gnus-auto-select-subject))))
3421
3422 (defun gnus-summary-prepare ()
3423   "Generate the summary buffer."
3424   (interactive)
3425   (let ((buffer-read-only nil))
3426     (erase-buffer)
3427     (setq gnus-newsgroup-data nil
3428           gnus-newsgroup-data-reverse nil)
3429     (gnus-run-hooks 'gnus-summary-generate-hook)
3430     ;; Generate the buffer, either with threads or without.
3431     (when gnus-newsgroup-headers
3432       (gnus-summary-prepare-threads
3433        (if gnus-show-threads
3434            (gnus-sort-gathered-threads
3435             (funcall gnus-summary-thread-gathering-function
3436                      (gnus-sort-threads
3437                       (gnus-cut-threads (gnus-make-threads)))))
3438          ;; Unthreaded display.
3439          (gnus-sort-articles gnus-newsgroup-headers))))
3440     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3441     ;; Call hooks for modifying summary buffer.
3442     (goto-char (point-min))
3443     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3444
3445 (defsubst gnus-general-simplify-subject (subject)
3446   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3447   (setq subject
3448         (cond
3449          ;; Truncate the subject.
3450          (gnus-simplify-subject-functions
3451           (gnus-map-function gnus-simplify-subject-functions subject))
3452          ((numberp gnus-summary-gather-subject-limit)
3453           (setq subject (gnus-simplify-subject-re subject))
3454           (if (> (length subject) gnus-summary-gather-subject-limit)
3455               (substring subject 0 gnus-summary-gather-subject-limit)
3456             subject))
3457          ;; Fuzzily simplify it.
3458          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3459           (gnus-simplify-subject-fuzzy subject))
3460          ;; Just remove the leading "Re:".
3461          (t
3462           (gnus-simplify-subject-re subject))))
3463
3464   (if (and gnus-summary-gather-exclude-subject
3465            (string-match gnus-summary-gather-exclude-subject subject))
3466       nil                               ; This article shouldn't be gathered
3467     subject))
3468
3469 (defun gnus-summary-simplify-subject-query ()
3470   "Query where the respool algorithm would put this article."
3471   (interactive)
3472   (gnus-summary-select-article)
3473   (message "%s"
3474            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3475
3476 (defun gnus-gather-threads-by-subject (threads)
3477   "Gather threads by looking at Subject headers."
3478   (if (not gnus-summary-make-false-root)
3479       threads
3480     (let ((hashtb (gnus-make-hashtable 1024))
3481           (prev threads)
3482           (result threads)
3483           subject hthread whole-subject)
3484       (while threads
3485         (setq subject (gnus-general-simplify-subject
3486                        (setq whole-subject (mail-header-subject
3487                                             (caar threads)))))
3488         (when subject
3489           (if (setq hthread (gnus-gethash subject hashtb))
3490               (progn
3491                 ;; We enter a dummy root into the thread, if we
3492                 ;; haven't done that already.
3493                 (unless (stringp (caar hthread))
3494                   (setcar hthread (list whole-subject (car hthread))))
3495                 ;; We add this new gathered thread to this gathered
3496                 ;; thread.
3497                 (setcdr (car hthread)
3498                         (nconc (cdar hthread) (list (car threads))))
3499                 ;; Remove it from the list of threads.
3500                 (setcdr prev (cdr threads))
3501                 (setq threads prev))
3502             ;; Enter this thread into the hash table.
3503             (gnus-sethash subject threads hashtb)))
3504         (setq prev threads)
3505         (setq threads (cdr threads)))
3506       result)))
3507
3508 (defun gnus-gather-threads-by-references (threads)
3509   "Gather threads by looking at References headers."
3510   (let ((idhashtb (gnus-make-hashtable 1024))
3511         (thhashtb (gnus-make-hashtable 1024))
3512         (prev threads)
3513         (result threads)
3514         ids references id gthread gid entered ref)
3515     (while threads
3516       (when (setq references (mail-header-references (caar threads)))
3517         (setq id (mail-header-id (caar threads))
3518               ids (inline (gnus-split-references references))
3519               entered nil)
3520         (while (setq ref (pop ids))
3521           (setq ids (delete ref ids))
3522           (if (not (setq gid (gnus-gethash ref idhashtb)))
3523               (progn
3524                 (gnus-sethash ref id idhashtb)
3525                 (gnus-sethash id threads thhashtb))
3526             (setq gthread (gnus-gethash gid thhashtb))
3527             (unless entered
3528               ;; We enter a dummy root into the thread, if we
3529               ;; haven't done that already.
3530               (unless (stringp (caar gthread))
3531                 (setcar gthread (list (mail-header-subject (caar gthread))
3532                                       (car gthread))))
3533               ;; We add this new gathered thread to this gathered
3534               ;; thread.
3535               (setcdr (car gthread)
3536                       (nconc (cdar gthread) (list (car threads)))))
3537             ;; Add it into the thread hash table.
3538             (gnus-sethash id gthread thhashtb)
3539             (setq entered t)
3540             ;; Remove it from the list of threads.
3541             (setcdr prev (cdr threads))
3542             (setq threads prev))))
3543       (setq prev threads)
3544       (setq threads (cdr threads)))
3545     result))
3546
3547 (defun gnus-sort-gathered-threads (threads)
3548   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3549   (let ((result threads))
3550     (while threads
3551       (when (stringp (caar threads))
3552         (setcdr (car threads)
3553                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3554       (setq threads (cdr threads)))
3555     result))
3556
3557 (defun gnus-thread-loop-p (root thread)
3558   "Say whether ROOT is in THREAD."
3559   (let ((stack (list thread))
3560         (infloop 0)
3561         th)
3562     (while (setq thread (pop stack))
3563       (setq th (cdr thread))
3564       (while (and th
3565                   (not (eq (caar th) root)))
3566         (pop th))
3567       (if th
3568           ;; We have found a loop.
3569           (let (ref-dep)
3570             (setcdr thread (delq (car th) (cdr thread)))
3571             (if (boundp (setq ref-dep (intern "none"
3572                                               gnus-newsgroup-dependencies)))
3573                 (setcdr (symbol-value ref-dep)
3574                         (nconc (cdr (symbol-value ref-dep))
3575                                (list (car th))))
3576               (set ref-dep (list nil (car th))))
3577             (setq infloop 1
3578                   stack nil))
3579         ;; Push all the subthreads onto the stack.
3580         (push (cdr thread) stack)))
3581     infloop))
3582
3583 (defun gnus-make-threads ()
3584   "Go through the dependency hashtb and find the roots.  Return all threads."
3585   (let (threads)
3586     (while (catch 'infloop
3587              (mapatoms
3588               (lambda (refs)
3589                 ;; Deal with self-referencing References loops.
3590                 (when (and (car (symbol-value refs))
3591                            (not (zerop
3592                                  (apply
3593                                   '+
3594                                   (mapcar
3595                                    (lambda (thread)
3596                                      (gnus-thread-loop-p
3597                                       (car (symbol-value refs)) thread))
3598                                    (cdr (symbol-value refs)))))))
3599                   (setq threads nil)
3600                   (throw 'infloop t))
3601                 (unless (car (symbol-value refs))
3602                   ;; These threads do not refer back to any other articles,
3603                   ;; so they're roots.
3604                   (setq threads (append (cdr (symbol-value refs)) threads))))
3605               gnus-newsgroup-dependencies)))
3606     threads))
3607
3608 ;; Build the thread tree.
3609 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3610   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3611
3612 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3613 if it was already present.
3614
3615 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3616 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3617 Message-IDs will be renamed to a unique Message-ID before being
3618 entered.
3619
3620 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3621   (let* ((id (mail-header-id header))
3622          (id-dep (and id (intern id dependencies)))
3623          ref ref-dep ref-header replaced)
3624     ;; Enter this `header' in the `dependencies' table.
3625     (cond
3626      ((not id-dep)
3627       (setq header nil))
3628      ;; The first two cases do the normal part: enter a new `header'
3629      ;; in the `dependencies' table.
3630      ((not (boundp id-dep))
3631       (set id-dep (list header)))
3632      ((null (car (symbol-value id-dep)))
3633       (setcar (symbol-value id-dep) header))
3634
3635      ;; From here the `header' was already present in the
3636      ;; `dependencies' table.
3637      (force-new
3638       ;; Overrides an existing entry;
3639       ;; just set the header part of the entry.
3640       (setcar (symbol-value id-dep) header)
3641       (setq replaced t))
3642
3643      ;; Renames the existing `header' to a unique Message-ID.
3644      ((not gnus-summary-ignore-duplicates)
3645       ;; An article with this Message-ID has already been seen.
3646       ;; We rename the Message-ID.
3647       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3648            (list header))
3649       (mail-header-set-id header id))
3650
3651      ;; The last case ignores an existing entry, except it adds any
3652      ;; additional Xrefs (in case the two articles came from different
3653      ;; servers.
3654      ;; Also sets `header' to `nil' meaning that the `dependencies'
3655      ;; table was *not* modified.
3656      (t
3657       (mail-header-set-xref
3658        (car (symbol-value id-dep))
3659        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3660                    "")
3661                (or (mail-header-xref header) "")))
3662       (setq header nil)))
3663
3664     (when (and header (not replaced))
3665       ;; First check that we are not creating a References loop.
3666       (setq ref (gnus-parent-id (mail-header-references header)))
3667       (while (and ref
3668                   (setq ref-dep (intern-soft ref dependencies))
3669                   (boundp ref-dep)
3670                   (setq ref-header (car (symbol-value ref-dep))))
3671         (if (string= id ref)
3672             ;; Yuk!  This is a reference loop.  Make the article be a
3673             ;; root article.
3674             (progn
3675               (mail-header-set-references (car (symbol-value id-dep)) "none")
3676               (setq ref nil))
3677           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3678       (setq ref (gnus-parent-id (mail-header-references header)))
3679       (setq ref-dep (intern (or ref "none") dependencies))
3680       (if (boundp ref-dep)
3681           (setcdr (symbol-value ref-dep)
3682                   (nconc (cdr (symbol-value ref-dep))
3683                          (list (symbol-value id-dep))))
3684         (set ref-dep (list nil (symbol-value id-dep)))))
3685     header))
3686
3687 (defun gnus-extract-message-id-from-in-reply-to (string)
3688   (if (string-match "<[^>]+>" string)
3689       (substring string (match-beginning 0) (match-end 0))
3690     nil))
3691
3692 (defun gnus-build-sparse-threads ()
3693   (let ((headers gnus-newsgroup-headers)
3694         (mail-parse-charset gnus-newsgroup-charset)
3695         (gnus-summary-ignore-duplicates t)
3696         header references generation relations
3697         subject child end new-child date)
3698     ;; First we create an alist of generations/relations, where
3699     ;; generations is how much we trust the relation, and the relation
3700     ;; is parent/child.
3701     (gnus-message 7 "Making sparse threads...")
3702     (save-excursion
3703       (nnheader-set-temp-buffer " *gnus sparse threads*")
3704       (while (setq header (pop headers))
3705         (when (and (setq references (mail-header-references header))
3706                    (not (string= references "")))
3707           (insert references)
3708           (setq child (mail-header-id header)
3709                 subject (mail-header-subject header)
3710                 date (mail-header-date header)
3711                 generation 0)
3712           (while (search-backward ">" nil t)
3713             (setq end (1+ (point)))
3714             (when (search-backward "<" nil t)
3715               (setq new-child (buffer-substring (point) end))
3716               (push (list (incf generation)
3717                           child (setq child new-child)
3718                           subject date)
3719                     relations)))
3720           (when child
3721             (push (list (1+ generation) child nil subject) relations))
3722           (erase-buffer)))
3723       (kill-buffer (current-buffer)))
3724     ;; Sort over trustworthiness.
3725     (mapcar
3726      (lambda (relation)
3727        (when (gnus-dependencies-add-header
3728               (make-full-mail-header-from-decoded-header
3729                gnus-reffed-article-number
3730                (nth 3 relation) "" (or (nth 4 relation) "")
3731                (nth 1 relation)
3732                (or (nth 2 relation) "") 0 0 "")
3733               gnus-newsgroup-dependencies nil)
3734          (push gnus-reffed-article-number gnus-newsgroup-limit)
3735          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3736          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3737                gnus-newsgroup-reads)
3738          (decf gnus-reffed-article-number)))
3739      (sort relations 'car-less-than-car))
3740     (gnus-message 7 "Making sparse threads...done")))
3741
3742 (defun gnus-build-old-threads ()
3743   ;; Look at all the articles that refer back to old articles, and
3744   ;; fetch the headers for the articles that aren't there.  This will
3745   ;; build complete threads - if the roots haven't been expired by the
3746   ;; server, that is.
3747   (let ((mail-parse-charset gnus-newsgroup-charset)
3748         id heads)
3749     (mapatoms
3750      (lambda (refs)
3751        (when (not (car (symbol-value refs)))
3752          (setq heads (cdr (symbol-value refs)))
3753          (while heads
3754            (if (memq (mail-header-number (caar heads))
3755                      gnus-newsgroup-dormant)
3756                (setq heads (cdr heads))
3757              (setq id (symbol-name refs))
3758              (while (and (setq id (gnus-build-get-header id))
3759                          (not (car (gnus-id-to-thread id)))))
3760              (setq heads nil)))))
3761      gnus-newsgroup-dependencies)))
3762
3763 ;; This function has to be called with point after the article number
3764 ;; on the beginning of the line.
3765 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3766   (let ((eol (gnus-point-at-eol))
3767         (buffer (current-buffer))
3768         header references in-reply-to)
3769
3770     ;; overview: [num subject from date id refs chars lines misc]
3771     (unwind-protect
3772         (progn
3773           (narrow-to-region (point) eol)
3774           (unless (eobp)
3775             (forward-char))
3776
3777           (setq header
3778                 (make-full-mail-header
3779                  number                         ; number
3780                  (nnheader-nov-field)           ; subject
3781                  (nnheader-nov-field)           ; from
3782                  (nnheader-nov-field)           ; date
3783                  (nnheader-nov-read-message-id) ; id
3784                  (nnheader-nov-field)           ; refs
3785                  (nnheader-nov-read-integer)    ; chars
3786                  (nnheader-nov-read-integer)    ; lines
3787                  (unless (eobp)
3788                    (if (looking-at "Xref: ")
3789                        (goto-char (match-end 0)))
3790                    (nnheader-nov-field))        ; Xref
3791                  (nnheader-nov-parse-extra))))  ; extra
3792
3793       (widen))
3794
3795     (when (and (string= references "")
3796                (setq in-reply-to (mail-header-extra header))
3797                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
3798       (mail-header-set-references
3799        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
3800
3801     (when gnus-alter-header-function
3802       (funcall gnus-alter-header-function header))
3803     (gnus-dependencies-add-header header dependencies force-new)))
3804
3805 (defun gnus-build-get-header (id)
3806   "Look through the buffer of NOV lines and find the header to ID.
3807 Enter this line into the dependencies hash table, and return
3808 the id of the parent article (if any)."
3809   (let ((deps gnus-newsgroup-dependencies)
3810         found header)
3811     (prog1
3812         (save-excursion
3813           (set-buffer nntp-server-buffer)
3814           (let ((case-fold-search nil))
3815             (goto-char (point-min))
3816             (while (and (not found)
3817                         (search-forward id nil t))
3818               (beginning-of-line)
3819               (setq found (looking-at
3820                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3821                                    (regexp-quote id))))
3822               (or found (beginning-of-line 2)))
3823             (when found
3824               (beginning-of-line)
3825               (and
3826                (setq header (gnus-nov-parse-line
3827                              (read (current-buffer)) deps))
3828                (gnus-parent-id (mail-header-references header))))))
3829       (when header
3830         (let ((number (mail-header-number header)))
3831           (push number gnus-newsgroup-limit)
3832           (push header gnus-newsgroup-headers)
3833           (if (memq number gnus-newsgroup-unselected)
3834               (progn
3835                 (setq gnus-newsgroup-unreads
3836                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
3837                                                number))
3838                 (setq gnus-newsgroup-unselected
3839                       (delq number gnus-newsgroup-unselected)))
3840             (push number gnus-newsgroup-ancient)))))))
3841
3842 (defun gnus-build-all-threads ()
3843   "Read all the headers."
3844   (let ((gnus-summary-ignore-duplicates t)
3845         (mail-parse-charset gnus-newsgroup-charset)
3846         (dependencies gnus-newsgroup-dependencies)
3847         header article)
3848     (save-excursion
3849       (set-buffer nntp-server-buffer)
3850       (let ((case-fold-search nil))
3851         (goto-char (point-min))
3852         (while (not (eobp))
3853           (ignore-errors
3854             (setq article (read (current-buffer))
3855                   header (gnus-nov-parse-line article dependencies)))
3856           (when header
3857             (save-excursion
3858               (set-buffer gnus-summary-buffer)
3859               (push header gnus-newsgroup-headers)
3860               (if (memq (setq article (mail-header-number header))
3861                         gnus-newsgroup-unselected)
3862                   (progn
3863                     (setq gnus-newsgroup-unreads
3864                           (gnus-add-to-sorted-list
3865                            gnus-newsgroup-unreads article))
3866                     (setq gnus-newsgroup-unselected
3867                           (delq article gnus-newsgroup-unselected)))
3868                 (push article gnus-newsgroup-ancient)))
3869             (forward-line 1)))))))
3870
3871 (defun gnus-summary-update-article-line (article header)
3872   "Update the line for ARTICLE using HEADERS."
3873   (let* ((id (mail-header-id header))
3874          (thread (gnus-id-to-thread id)))
3875     (unless thread
3876       (error "Article in no thread"))
3877     ;; Update the thread.
3878     (setcar thread header)
3879     (gnus-summary-goto-subject article)
3880     (let* ((datal (gnus-data-find-list article))
3881            (data (car datal))
3882            (length (when (cdr datal)
3883                      (- (gnus-data-pos data)
3884                         (gnus-data-pos (cadr datal)))))
3885            (buffer-read-only nil)
3886            (level (gnus-summary-thread-level)))
3887       (gnus-delete-line)
3888       (gnus-summary-insert-line
3889        header level nil (gnus-article-mark article)
3890        (memq article gnus-newsgroup-replied)
3891        (memq article gnus-newsgroup-expirable)
3892        ;; Only insert the Subject string when it's different
3893        ;; from the previous Subject string.
3894        (if (and
3895             gnus-show-threads
3896             (gnus-subject-equal
3897              (condition-case ()
3898                  (mail-header-subject
3899                   (gnus-data-header
3900                    (cadr
3901                     (gnus-data-find-list
3902                      article
3903                      (gnus-data-list t)))))
3904                ;; Error on the side of excessive subjects.
3905                (error ""))
3906              (mail-header-subject header)))
3907            ""
3908          (mail-header-subject header))
3909        nil (cdr (assq article gnus-newsgroup-scored))
3910        (memq article gnus-newsgroup-processable))
3911       (when length
3912         (gnus-data-update-list
3913          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3914
3915 (defun gnus-summary-update-article (article &optional iheader)
3916   "Update ARTICLE in the summary buffer."
3917   (set-buffer gnus-summary-buffer)
3918   (let* ((header (gnus-summary-article-header article))
3919          (id (mail-header-id header))
3920          (data (gnus-data-find article))
3921          (thread (gnus-id-to-thread id))
3922          (references (mail-header-references header))
3923          (parent
3924           (gnus-id-to-thread
3925            (or (gnus-parent-id
3926                 (when (and references
3927                            (not (equal "" references)))
3928                   references))
3929                "none")))
3930          (buffer-read-only nil)
3931          (old (car thread)))
3932     (when thread
3933       (unless iheader
3934         (setcar thread nil)
3935         (when parent
3936           (delq thread parent)))
3937       (if (gnus-summary-insert-subject id header)
3938           ;; Set the (possibly) new article number in the data structure.
3939           (gnus-data-set-number data (gnus-id-to-article id))
3940         (setcar thread old)
3941         nil))))
3942
3943 (defun gnus-rebuild-thread (id &optional line)
3944   "Rebuild the thread containing ID.
3945 If LINE, insert the rebuilt thread starting on line LINE."
3946   (let ((buffer-read-only nil)
3947         old-pos current thread data)
3948     (if (not gnus-show-threads)
3949         (setq thread (list (car (gnus-id-to-thread id))))
3950       ;; Get the thread this article is part of.
3951       (setq thread (gnus-remove-thread id)))
3952     (setq old-pos (gnus-point-at-bol))
3953     (setq current (save-excursion
3954                     (and (re-search-backward "[\r\n]" nil t)
3955                          (gnus-summary-article-number))))
3956     ;; If this is a gathered thread, we have to go some re-gathering.
3957     (when (stringp (car thread))
3958       (let ((subject (car thread))
3959             roots thr)
3960         (setq thread (cdr thread))
3961         (while thread
3962           (unless (memq (setq thr (gnus-id-to-thread
3963                                    (gnus-root-id
3964                                     (mail-header-id (caar thread)))))
3965                         roots)
3966             (push thr roots))
3967           (setq thread (cdr thread)))
3968         ;; We now have all (unique) roots.
3969         (if (= (length roots) 1)
3970             ;; All the loose roots are now one solid root.
3971             (setq thread (car roots))
3972           (setq thread (cons subject (gnus-sort-threads roots))))))
3973     (let (threads)
3974       ;; We then insert this thread into the summary buffer.
3975       (when line
3976         (goto-char (point-min))
3977         (forward-line (1- line)))
3978       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3979         (if gnus-show-threads
3980             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3981           (gnus-summary-prepare-unthreaded thread))
3982         (setq data (nreverse gnus-newsgroup-data))
3983         (setq threads gnus-newsgroup-threads))
3984       ;; We splice the new data into the data structure.
3985       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3986       ;;!!! then we want to insert at the beginning of the buffer.
3987       ;;!!! That happens to be true with Gnus now, but that may
3988       ;;!!! change in the future.  Perhaps.
3989       (gnus-data-enter-list
3990        (if line nil current) data (- (point) old-pos))
3991       (setq gnus-newsgroup-threads
3992             (nconc threads gnus-newsgroup-threads))
3993       (gnus-data-compute-positions))))
3994
3995 (defun gnus-number-to-header (number)
3996   "Return the header for article NUMBER."
3997   (let ((headers gnus-newsgroup-headers))
3998     (while (and headers
3999                 (not (= number (mail-header-number (car headers)))))
4000       (pop headers))
4001     (when headers
4002       (car headers))))
4003
4004 (defun gnus-parent-headers (in-headers &optional generation)
4005   "Return the headers of the GENERATIONeth parent of HEADERS."
4006   (unless generation
4007     (setq generation 1))
4008   (let ((parent t)
4009         (headers in-headers)
4010         references)
4011     (while (and parent
4012                 (not (zerop generation))
4013                 (setq references (mail-header-references headers)))
4014       (setq headers (if (and references
4015                              (setq parent (gnus-parent-id references)))
4016                         (car (gnus-id-to-thread parent))
4017                       nil))
4018       (decf generation))
4019     (and (not (eq headers in-headers))
4020          headers)))
4021
4022 (defun gnus-id-to-thread (id)
4023   "Return the (sub-)thread where ID appears."
4024   (gnus-gethash id gnus-newsgroup-dependencies))
4025
4026 (defun gnus-id-to-article (id)
4027   "Return the article number of ID."
4028   (let ((thread (gnus-id-to-thread id)))
4029     (when (and thread
4030                (car thread))
4031       (mail-header-number (car thread)))))
4032
4033 (defun gnus-id-to-header (id)
4034   "Return the article headers of ID."
4035   (car (gnus-id-to-thread id)))
4036
4037 (defun gnus-article-displayed-root-p (article)
4038   "Say whether ARTICLE is a root(ish) article."
4039   (let ((level (gnus-summary-thread-level article))
4040         (refs (mail-header-references  (gnus-summary-article-header article)))
4041         particle)
4042     (cond
4043      ((null level) nil)
4044      ((zerop level) t)
4045      ((null refs) t)
4046      ((null (gnus-parent-id refs)) t)
4047      ((and (= 1 level)
4048            (null (setq particle (gnus-id-to-article
4049                                  (gnus-parent-id refs))))
4050            (null (gnus-summary-thread-level particle)))))))
4051
4052 (defun gnus-root-id (id)
4053   "Return the id of the root of the thread where ID appears."
4054   (let (last-id prev)
4055     (while (and id (setq prev (car (gnus-id-to-thread id))))
4056       (setq last-id id
4057             id (gnus-parent-id (mail-header-references prev))))
4058     last-id))
4059
4060 (defun gnus-articles-in-thread (thread)
4061   "Return the list of articles in THREAD."
4062   (cons (mail-header-number (car thread))
4063         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4064
4065 (defun gnus-remove-thread (id &optional dont-remove)
4066   "Remove the thread that has ID in it."
4067   (let (headers thread last-id)
4068     ;; First go up in this thread until we find the root.
4069     (setq last-id (gnus-root-id id)
4070           headers (message-flatten-list (gnus-id-to-thread last-id)))
4071     ;; We have now found the real root of this thread.  It might have
4072     ;; been gathered into some loose thread, so we have to search
4073     ;; through the threads to find the thread we wanted.
4074     (let ((threads gnus-newsgroup-threads)
4075           sub)
4076       (while threads
4077         (setq sub (car threads))
4078         (if (stringp (car sub))
4079             ;; This is a gathered thread, so we look at the roots
4080             ;; below it to find whether this article is in this
4081             ;; gathered root.
4082             (progn
4083               (setq sub (cdr sub))
4084               (while sub
4085                 (when (member (caar sub) headers)
4086                   (setq thread (car threads)
4087                         threads nil
4088                         sub nil))
4089                 (setq sub (cdr sub))))
4090           ;; It's an ordinary thread, so we check it.
4091           (when (eq (car sub) (car headers))
4092             (setq thread sub
4093                   threads nil)))
4094         (setq threads (cdr threads)))
4095       ;; If this article is in no thread, then it's a root.
4096       (if thread
4097           (unless dont-remove
4098             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4099         (setq thread (gnus-id-to-thread last-id)))
4100       (when thread
4101         (prog1
4102             thread                      ; We return this thread.
4103           (unless dont-remove
4104             (if (stringp (car thread))
4105                 (progn
4106                   ;; If we use dummy roots, then we have to remove the
4107                   ;; dummy root as well.
4108                   (when (eq gnus-summary-make-false-root 'dummy)
4109                     ;; We go to the dummy root by going to
4110                     ;; the first sub-"thread", and then one line up.
4111                     (gnus-summary-goto-article
4112                      (mail-header-number (caadr thread)))
4113                     (forward-line -1)
4114                     (gnus-delete-line)
4115                     (gnus-data-compute-positions))
4116                   (setq thread (cdr thread))
4117                   (while thread
4118                     (gnus-remove-thread-1 (car thread))
4119                     (setq thread (cdr thread))))
4120               (gnus-remove-thread-1 thread))))))))
4121
4122 (defun gnus-remove-thread-1 (thread)
4123   "Remove the thread THREAD recursively."
4124   (let ((number (mail-header-number (pop thread)))
4125         d)
4126     (setq thread (reverse thread))
4127     (while thread
4128       (gnus-remove-thread-1 (pop thread)))
4129     (when (setq d (gnus-data-find number))
4130       (goto-char (gnus-data-pos d))
4131       (gnus-summary-show-thread)
4132       (gnus-data-remove
4133        number
4134        (- (gnus-point-at-bol)
4135           (prog1
4136               (1+ (gnus-point-at-eol))
4137             (gnus-delete-line)))))))
4138
4139 (defun gnus-sort-threads-1 (threads func)
4140   (sort (mapcar (lambda (thread)
4141                   (cons (car thread)
4142                         (and (cdr thread)
4143                              (gnus-sort-threads-1 (cdr thread) func))))
4144                 threads) func))
4145
4146 (defun gnus-sort-threads (threads)
4147   "Sort THREADS."
4148   (if (not gnus-thread-sort-functions)
4149       threads
4150     (gnus-message 8 "Sorting threads...")
4151     (prog1
4152         (gnus-sort-threads-1
4153          threads
4154          (gnus-make-sort-function gnus-thread-sort-functions))
4155       (gnus-message 8 "Sorting threads...done"))))
4156
4157 (defun gnus-sort-articles (articles)
4158   "Sort ARTICLES."
4159   (when gnus-article-sort-functions
4160     (gnus-message 7 "Sorting articles...")
4161     (prog1
4162         (setq gnus-newsgroup-headers
4163               (sort articles (gnus-make-sort-function
4164                               gnus-article-sort-functions)))
4165       (gnus-message 7 "Sorting articles...done"))))
4166
4167 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4168 (defmacro gnus-thread-header (thread)
4169   "Return header of first article in THREAD.
4170 Note that THREAD must never, ever be anything else than a variable -
4171 using some other form will lead to serious barfage."
4172   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4173   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4174   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4175         (vector thread) 2))
4176
4177 (defsubst gnus-article-sort-by-number (h1 h2)
4178   "Sort articles by article number."
4179   (< (mail-header-number h1)
4180      (mail-header-number h2)))
4181
4182 (defun gnus-thread-sort-by-number (h1 h2)
4183   "Sort threads by root article number."
4184   (gnus-article-sort-by-number
4185    (gnus-thread-header h1) (gnus-thread-header h2)))
4186
4187 (defsubst gnus-article-sort-by-lines (h1 h2)
4188   "Sort articles by article Lines header."
4189   (< (mail-header-lines h1)
4190      (mail-header-lines h2)))
4191
4192 (defun gnus-thread-sort-by-lines (h1 h2)
4193   "Sort threads by root article Lines header."
4194   (gnus-article-sort-by-lines
4195    (gnus-thread-header h1) (gnus-thread-header h2)))
4196
4197 (defsubst gnus-article-sort-by-chars (h1 h2)
4198   "Sort articles by octet length."
4199   (< (mail-header-chars h1)
4200      (mail-header-chars h2)))
4201
4202 (defun gnus-thread-sort-by-chars (h1 h2)
4203   "Sort threads by root article octet length."
4204   (gnus-article-sort-by-chars
4205    (gnus-thread-header h1) (gnus-thread-header h2)))
4206
4207 (defsubst gnus-article-sort-by-author (h1 h2)
4208   "Sort articles by root author."
4209   (string-lessp
4210    (let ((addr (car (mime-entity-read-field h1 'From))))
4211      (or (std11-full-name-string addr)
4212          (std11-address-string addr)
4213          ""))
4214    (let ((addr (car (mime-entity-read-field h2 'From))))
4215      (or (std11-full-name-string addr)
4216          (std11-address-string addr)
4217          ""))
4218    ))
4219
4220 (defun gnus-thread-sort-by-author (h1 h2)
4221   "Sort threads by root author."
4222   (gnus-article-sort-by-author
4223    (gnus-thread-header h1)  (gnus-thread-header h2)))
4224
4225 (defsubst gnus-article-sort-by-subject (h1 h2)
4226   "Sort articles by root subject."
4227   (string-lessp
4228    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4229    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4230
4231 (defun gnus-thread-sort-by-subject (h1 h2)
4232   "Sort threads by root subject."
4233   (gnus-article-sort-by-subject
4234    (gnus-thread-header h1) (gnus-thread-header h2)))
4235
4236 (defsubst gnus-article-sort-by-date (h1 h2)
4237   "Sort articles by root article date."
4238   (time-less-p
4239    (gnus-date-get-time (mail-header-date h1))
4240    (gnus-date-get-time (mail-header-date h2))))
4241
4242 (defun gnus-thread-sort-by-date (h1 h2)
4243   "Sort threads by root article date."
4244   (gnus-article-sort-by-date
4245    (gnus-thread-header h1) (gnus-thread-header h2)))
4246
4247 (defsubst gnus-article-sort-by-score (h1 h2)
4248   "Sort articles by root article score.
4249 Unscored articles will be counted as having a score of zero."
4250   (> (or (cdr (assq (mail-header-number h1)
4251                     gnus-newsgroup-scored))
4252          gnus-summary-default-score 0)
4253      (or (cdr (assq (mail-header-number h2)
4254                     gnus-newsgroup-scored))
4255          gnus-summary-default-score 0)))
4256
4257 (defun gnus-thread-sort-by-score (h1 h2)
4258   "Sort threads by root article score."
4259   (gnus-article-sort-by-score
4260    (gnus-thread-header h1) (gnus-thread-header h2)))
4261
4262 (defun gnus-thread-sort-by-total-score (h1 h2)
4263   "Sort threads by the sum of all scores in the thread.
4264 Unscored articles will be counted as having a score of zero."
4265   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4266
4267 (defun gnus-thread-total-score (thread)
4268   ;; This function find the total score of THREAD.
4269   (cond
4270    ((null thread)
4271     0)
4272    ((consp thread)
4273     (if (stringp (car thread))
4274         (apply gnus-thread-score-function 0
4275                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4276       (gnus-thread-total-score-1 thread)))
4277    (t
4278     (gnus-thread-total-score-1 (list thread)))))
4279
4280 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4281   "Sort threads such that the thread with the most recently arrived article comes first."
4282   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4283
4284 (defun gnus-thread-highest-number (thread)
4285   "Return the highest article number in THREAD."
4286   (apply 'max (mapcar (lambda (header)
4287                         (mail-header-number header))
4288                       (message-flatten-list thread))))
4289
4290 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4291   "Sort threads such that the thread with the most recently dated article comes first."
4292   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4293
4294 (defun gnus-thread-latest-date (thread)
4295   "Return the highest article date in THREAD."
4296   (let ((previous-time 0))
4297     (apply 'max (mapcar
4298                  (lambda (header)
4299                    (setq previous-time
4300                          (time-to-seconds
4301                           (mail-header-parse-date
4302                            (condition-case ()
4303                                (mail-header-date header)
4304                              (error previous-time))))))
4305                  (sort
4306                   (message-flatten-list thread)
4307                   (lambda (h1 h2)
4308                     (< (mail-header-number h1)
4309                        (mail-header-number h2))))))))
4310
4311 (defun gnus-thread-total-score-1 (root)
4312   ;; This function find the total score of the thread below ROOT.
4313   (setq root (car root))
4314   (apply gnus-thread-score-function
4315          (or (append
4316               (mapcar 'gnus-thread-total-score
4317                       (cdr (gnus-id-to-thread (mail-header-id root))))
4318               (when (> (mail-header-number root) 0)
4319                 (list (or (cdr (assq (mail-header-number root)
4320                                      gnus-newsgroup-scored))
4321                           gnus-summary-default-score 0))))
4322              (list gnus-summary-default-score)
4323              '(0))))
4324
4325 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4326 (defvar gnus-tmp-prev-subject nil)
4327 (defvar gnus-tmp-false-parent nil)
4328 (defvar gnus-tmp-root-expunged nil)
4329 (defvar gnus-tmp-dummy-line nil)
4330
4331 (eval-when-compile (defvar gnus-tmp-header))
4332 (defun gnus-extra-header (type &optional header)
4333   "Return the extra header of TYPE."
4334   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4335       ""))
4336
4337 (defvar gnus-tmp-thread-tree-header-string "")
4338
4339 (defcustom gnus-sum-thread-tree-root "> "
4340   "With %B spec, used for the root of a thread.
4341 If nil, use subject instead."
4342   :type 'string
4343   :group 'gnus-thread)
4344 (defcustom gnus-sum-thread-tree-single-indent ""
4345   "With %B spec, used for a thread with just one message.
4346 If nil, use subject instead."
4347   :type 'string
4348   :group 'gnus-thread)
4349 (defcustom gnus-sum-thread-tree-vertical "| "
4350   "With %B spec, used for drawing a vertical line."
4351   :type 'string
4352   :group 'gnus-thread)
4353 (defcustom gnus-sum-thread-tree-indent "  "
4354   "With %B spec, used for indenting."
4355   :type 'string
4356   :group 'gnus-thread)
4357 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4358   "With %B spec, used for a leaf with brothers."
4359   :type 'string
4360   :group 'gnus-thread)
4361 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4362   "With %B spec, used for a leaf without brothers."
4363   :type 'string
4364   :group 'gnus-thread)
4365
4366 (defun gnus-summary-prepare-threads (threads)
4367   "Prepare summary buffer from THREADS and indentation LEVEL.
4368 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4369 or a straight list of headers."
4370   (gnus-message 7 "Generating summary...")
4371
4372   (setq gnus-newsgroup-threads threads)
4373   (beginning-of-line)
4374
4375   (let ((gnus-tmp-level 0)
4376         (default-score (or gnus-summary-default-score 0))
4377         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4378         thread number subject stack state gnus-tmp-gathered beg-match
4379         new-roots gnus-tmp-new-adopts thread-end
4380         gnus-tmp-header gnus-tmp-unread
4381         gnus-tmp-replied gnus-tmp-subject-or-nil
4382         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4383         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4384         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4385         tree-stack)
4386
4387     (setq gnus-tmp-prev-subject nil)
4388
4389     (if (vectorp (car threads))
4390         ;; If this is a straight (sic) list of headers, then a
4391         ;; threaded summary display isn't required, so we just create
4392         ;; an unthreaded one.
4393         (gnus-summary-prepare-unthreaded threads)
4394
4395       ;; Do the threaded display.
4396
4397       (while (or threads stack gnus-tmp-new-adopts new-roots)
4398
4399         (if (and (= gnus-tmp-level 0)
4400                  (or (not stack)
4401                      (= (caar stack) 0))
4402                  (not gnus-tmp-false-parent)
4403                  (or gnus-tmp-new-adopts new-roots))
4404             (if gnus-tmp-new-adopts
4405                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4406                       thread (list (car gnus-tmp-new-adopts))
4407                       gnus-tmp-header (caar thread)
4408                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4409               (when new-roots
4410                 (setq thread (list (car new-roots))
4411                       gnus-tmp-header (caar thread)
4412                       new-roots (cdr new-roots))))
4413
4414           (if threads
4415               ;; If there are some threads, we do them before the
4416               ;; threads on the stack.
4417               (setq thread threads
4418                     gnus-tmp-header (caar thread))
4419             ;; There were no current threads, so we pop something off
4420             ;; the stack.
4421             (setq state (car stack)
4422                   gnus-tmp-level (car state)
4423                   tree-stack (cadr state)
4424                   thread (caddr state)
4425                   stack (cdr stack)
4426                   gnus-tmp-header (caar thread))))
4427
4428         (setq gnus-tmp-false-parent nil)
4429         (setq gnus-tmp-root-expunged nil)
4430         (setq thread-end nil)
4431
4432         (if (stringp gnus-tmp-header)
4433             ;; The header is a dummy root.
4434             (cond
4435              ((eq gnus-summary-make-false-root 'adopt)
4436               ;; We let the first article adopt the rest.
4437               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4438                                                (cddar thread)))
4439               (setq gnus-tmp-gathered
4440                     (nconc (mapcar
4441                             (lambda (h) (mail-header-number (car h)))
4442                             (cddar thread))
4443                            gnus-tmp-gathered))
4444               (setq thread (cons (list (caar thread)
4445                                        (cadar thread))
4446                                  (cdr thread)))
4447               (setq gnus-tmp-level -1
4448                     gnus-tmp-false-parent t))
4449              ((eq gnus-summary-make-false-root 'empty)
4450               ;; We print adopted articles with empty subject fields.
4451               (setq gnus-tmp-gathered
4452                     (nconc (mapcar
4453                             (lambda (h) (mail-header-number (car h)))
4454                             (cddar thread))
4455                            gnus-tmp-gathered))
4456               (setq gnus-tmp-level -1))
4457              ((eq gnus-summary-make-false-root 'dummy)
4458               ;; We remember that we probably want to output a dummy
4459               ;; root.
4460               (setq gnus-tmp-dummy-line gnus-tmp-header)
4461               (setq gnus-tmp-prev-subject gnus-tmp-header))
4462              (t
4463               ;; We do not make a root for the gathered
4464               ;; sub-threads at all.
4465               (setq gnus-tmp-level -1)))
4466
4467           (setq number (mail-header-number gnus-tmp-header)
4468                 subject (mail-header-subject gnus-tmp-header))
4469
4470           (cond
4471            ;; If the thread has changed subject, we might want to make
4472            ;; this subthread into a root.
4473            ((and (null gnus-thread-ignore-subject)
4474                  (not (zerop gnus-tmp-level))
4475                  gnus-tmp-prev-subject
4476                  (not (inline
4477                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4478             (setq new-roots (nconc new-roots (list (car thread)))
4479                   thread-end t
4480                   gnus-tmp-header nil))
4481            ;; If the article lies outside the current limit,
4482            ;; then we do not display it.
4483            ((not (memq number gnus-newsgroup-limit))
4484             (setq gnus-tmp-gathered
4485                   (nconc (mapcar
4486                           (lambda (h) (mail-header-number (car h)))
4487                           (cdar thread))
4488                          gnus-tmp-gathered))
4489             (setq gnus-tmp-new-adopts (if (cdar thread)
4490                                           (append gnus-tmp-new-adopts
4491                                                   (cdar thread))
4492                                         gnus-tmp-new-adopts)
4493                   thread-end t
4494                   gnus-tmp-header nil)
4495             (when (zerop gnus-tmp-level)
4496               (setq gnus-tmp-root-expunged t)))
4497            ;; Perhaps this article is to be marked as read?
4498            ((and gnus-summary-mark-below
4499                  (< (or (cdr (assq number gnus-newsgroup-scored))
4500                         default-score)
4501                     gnus-summary-mark-below)
4502                  ;; Don't touch sparse articles.
4503                  (not (gnus-summary-article-sparse-p number))
4504                  (not (gnus-summary-article-ancient-p number)))
4505             (setq gnus-newsgroup-unreads
4506                   (delq number gnus-newsgroup-unreads))
4507             (if gnus-newsgroup-auto-expire
4508                 (setq gnus-newsgroup-expirable
4509                       (gnus-add-to-sorted-list
4510                        gnus-newsgroup-expirable number))
4511               (push (cons number gnus-low-score-mark)
4512                     gnus-newsgroup-reads))))
4513
4514           (when gnus-tmp-header
4515             ;; We may have an old dummy line to output before this
4516             ;; article.
4517             (when (and gnus-tmp-dummy-line
4518                        (gnus-subject-equal
4519                         gnus-tmp-dummy-line
4520                         (mail-header-subject gnus-tmp-header)))
4521               (gnus-summary-insert-dummy-line
4522                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4523               (setq gnus-tmp-dummy-line nil))
4524
4525             ;; Compute the mark.
4526             (setq gnus-tmp-unread (gnus-article-mark number))
4527
4528             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4529                                   gnus-tmp-header gnus-tmp-level)
4530                   gnus-newsgroup-data)
4531
4532             ;; Actually insert the line.
4533             (setq
4534              gnus-tmp-subject-or-nil
4535              (cond
4536               ((and gnus-thread-ignore-subject
4537                     gnus-tmp-prev-subject
4538                     (not (inline (gnus-subject-equal
4539                                   gnus-tmp-prev-subject subject))))
4540                subject)
4541               ((zerop gnus-tmp-level)
4542                (if (and (eq gnus-summary-make-false-root 'empty)
4543                         (memq number gnus-tmp-gathered)
4544                         gnus-tmp-prev-subject
4545                         (inline (gnus-subject-equal
4546                                  gnus-tmp-prev-subject subject)))
4547                    gnus-summary-same-subject
4548                  subject))
4549               (t gnus-summary-same-subject)))
4550             (if (and (eq gnus-summary-make-false-root 'adopt)
4551                      (= gnus-tmp-level 1)
4552                      (memq number gnus-tmp-gathered))
4553                 (setq gnus-tmp-opening-bracket ?\<
4554                       gnus-tmp-closing-bracket ?\>)
4555               (setq gnus-tmp-opening-bracket ?\[
4556                     gnus-tmp-closing-bracket ?\]))
4557             (setq
4558              gnus-tmp-indentation
4559              (aref gnus-thread-indent-array gnus-tmp-level)
4560              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4561              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4562                                 gnus-summary-default-score 0)
4563              gnus-tmp-score-char
4564              (if (or (null gnus-summary-default-score)
4565                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4566                          gnus-summary-zcore-fuzz))
4567                  ?\ ;;;Whitespace
4568                (if (< gnus-tmp-score gnus-summary-default-score)
4569                    gnus-score-below-mark gnus-score-over-mark))
4570              gnus-tmp-replied
4571              (cond ((memq number gnus-newsgroup-processable)
4572                     gnus-process-mark)
4573                    ((memq number gnus-newsgroup-cached)
4574                     gnus-cached-mark)
4575                    ((memq number gnus-newsgroup-replied)
4576                     gnus-replied-mark)
4577                    ((memq number gnus-newsgroup-forwarded)
4578                     gnus-forwarded-mark)
4579                    ((memq number gnus-newsgroup-saved)
4580                     gnus-saved-mark)
4581                    ((memq number gnus-newsgroup-recent)
4582                     gnus-recent-mark)
4583                    ((memq number gnus-newsgroup-unseen)
4584                     gnus-unseen-mark)
4585                    (t gnus-no-mark))
4586              gnus-tmp-from (mail-header-from gnus-tmp-header)
4587              gnus-tmp-name
4588              (cond
4589               ((string-match "<[^>]+> *$" gnus-tmp-from)
4590                (setq beg-match (match-beginning 0))
4591                (or (and (string-match "^\".+\"" gnus-tmp-from)
4592                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4593                    (substring gnus-tmp-from 0 beg-match)))
4594               ((string-match "(.+)" gnus-tmp-from)
4595                (substring gnus-tmp-from
4596                           (1+ (match-beginning 0)) (1- (match-end 0))))
4597               (t gnus-tmp-from))
4598              gnus-tmp-thread-tree-header-string
4599              (cond
4600               ((not gnus-show-threads) "")
4601               ((zerop gnus-tmp-level)
4602                (if (cdar thread)
4603                    (or gnus-sum-thread-tree-root subject)
4604                  (or gnus-sum-thread-tree-single-indent subject)))
4605               (t
4606                (concat (apply 'concat
4607                               (mapcar (lambda (item)
4608                                         (if (= item 1)
4609                                             gnus-sum-thread-tree-vertical
4610                                           gnus-sum-thread-tree-indent))
4611                                       (cdr (reverse tree-stack))))
4612                        (if (nth 1 thread)
4613                            gnus-sum-thread-tree-leaf-with-other
4614                          gnus-sum-thread-tree-single-leaf)))))
4615             (when (string= gnus-tmp-name "")
4616               (setq gnus-tmp-name gnus-tmp-from))
4617             (unless (numberp gnus-tmp-lines)
4618               (setq gnus-tmp-lines -1))
4619             (if (= gnus-tmp-lines -1)
4620                 (setq gnus-tmp-lines "?")
4621               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4622             (gnus-put-text-property
4623              (point)
4624              (progn (eval gnus-summary-line-format-spec) (point))
4625              'gnus-number number)
4626             (when gnus-visual-p
4627               (forward-line -1)
4628               (gnus-run-hooks 'gnus-summary-update-hook)
4629               (forward-line 1))
4630
4631             (setq gnus-tmp-prev-subject subject)))
4632
4633         (when (nth 1 thread)
4634           (push (list (max 0 gnus-tmp-level)
4635                       (copy-list tree-stack)
4636                       (nthcdr 1 thread))
4637                 stack))
4638         (push (if (nth 1 thread) 1 0) tree-stack)
4639         (incf gnus-tmp-level)
4640         (setq threads (if thread-end nil (cdar thread)))
4641         (unless threads
4642           (setq gnus-tmp-level 0)))))
4643   (gnus-message 7 "Generating summary...done"))
4644
4645 (defun gnus-summary-prepare-unthreaded (headers)
4646   "Generate an unthreaded summary buffer based on HEADERS."
4647   (let (header number mark)
4648
4649     (beginning-of-line)
4650
4651     (while headers
4652       ;; We may have to root out some bad articles...
4653       (when (memq (setq number (mail-header-number
4654                                 (setq header (pop headers))))
4655                   gnus-newsgroup-limit)
4656         ;; Mark article as read when it has a low score.
4657         (when (and gnus-summary-mark-below
4658                    (< (or (cdr (assq number gnus-newsgroup-scored))
4659                           gnus-summary-default-score 0)
4660                       gnus-summary-mark-below)
4661                    (not (gnus-summary-article-ancient-p number)))
4662           (setq gnus-newsgroup-unreads
4663                 (delq number gnus-newsgroup-unreads))
4664           (if gnus-newsgroup-auto-expire
4665               (push number gnus-newsgroup-expirable)
4666             (push (cons number gnus-low-score-mark)
4667                   gnus-newsgroup-reads)))
4668
4669         (setq mark (gnus-article-mark number))
4670         (push (gnus-data-make number mark (1+ (point)) header 0)
4671               gnus-newsgroup-data)
4672         (gnus-summary-insert-line
4673          header 0 number
4674          mark (memq number gnus-newsgroup-replied)
4675          (memq number gnus-newsgroup-expirable)
4676          (mail-header-subject header) nil
4677          (cdr (assq number gnus-newsgroup-scored))
4678          (memq number gnus-newsgroup-processable))))))
4679
4680 (defun gnus-summary-remove-list-identifiers ()
4681   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4682   (let ((regexp (if (consp gnus-list-identifiers)
4683                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4684                   gnus-list-identifiers))
4685         changed subject)
4686     (when regexp
4687       (dolist (header gnus-newsgroup-headers)
4688         (setq subject (mail-header-subject header)
4689               changed nil)
4690         (while (string-match
4691                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4692                 subject)
4693           (setq subject
4694                 (concat (substring subject 0 (match-beginning 2))
4695                         (substring subject (match-end 0)))
4696                 changed t))
4697         (when (and changed
4698                    (string-match
4699                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4700           (setq subject
4701                 (concat (substring subject 0 (match-beginning 1))
4702                         (substring subject (match-end 1)))))
4703         (when changed
4704           (mail-header-set-subject header subject))))))
4705
4706 (defun gnus-fetch-headers (articles)
4707   "Fetch headers of ARTICLES."
4708   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4709     (gnus-message 5 "Fetching headers for %s..." name)
4710     (prog1
4711         (if (eq 'nov
4712                 (setq gnus-headers-retrieved-by
4713                       (gnus-retrieve-headers
4714                        articles gnus-newsgroup-name
4715                        ;; We might want to fetch old headers, but
4716                        ;; not if there is only 1 article.
4717                        (and (or (and
4718                                  (not (eq gnus-fetch-old-headers 'some))
4719                                  (not (numberp gnus-fetch-old-headers)))
4720                                 (> (length articles) 1))
4721                             gnus-fetch-old-headers))))
4722             (gnus-get-newsgroup-headers-xover
4723              articles nil nil gnus-newsgroup-name t)
4724           (gnus-get-newsgroup-headers))
4725       (gnus-message 5 "Fetching headers for %s...done" name))))
4726
4727 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4728   "Select newsgroup GROUP.
4729 If READ-ALL is non-nil, all articles in the group are selected.
4730 If SELECT-ARTICLES, only select those articles from GROUP."
4731   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4732          ;;!!! Dirty hack; should be removed.
4733          (gnus-summary-ignore-duplicates
4734           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4735               t
4736             gnus-summary-ignore-duplicates))
4737          (info (nth 2 entry))
4738          articles fetched-articles cached)
4739
4740     (unless (gnus-check-server
4741              (set (make-local-variable 'gnus-current-select-method)
4742                   (gnus-find-method-for-group group)))
4743       (error "Couldn't open server"))
4744
4745     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4746         (gnus-activate-group group)     ; Or we can activate it...
4747         (progn                          ; Or we bug out.
4748           (when (equal major-mode 'gnus-summary-mode)
4749             (kill-buffer (current-buffer)))
4750           (error "Couldn't activate group %s: %s"
4751                  group (gnus-status-message group))))
4752
4753     (unless (gnus-request-group group t)
4754       (when (equal major-mode 'gnus-summary-mode)
4755         (kill-buffer (current-buffer)))
4756       (error "Couldn't request group %s: %s"
4757              group (gnus-status-message group)))
4758
4759     (setq gnus-newsgroup-name group
4760           gnus-newsgroup-unselected nil
4761           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4762
4763     (let ((display (gnus-group-find-parameter group 'display)))
4764       (setq gnus-newsgroup-display
4765             (cond
4766              ((not (zerop (or (car-safe read-all) 0)))
4767               ;; The user entered the group with C-u SPC/RET, let's show
4768               ;; all articles.
4769               'gnus-not-ignore)
4770              ((eq display 'all)
4771               'gnus-not-ignore)
4772              ((arrayp display)
4773               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4774              ((numberp display)
4775               ;; The following is probably the "correct" solution, but
4776               ;; it makes Gnus fetch all headers and then limit the
4777               ;; articles (which is slow), so instead we hack the
4778               ;; select-articles parameter instead. -- Simon Josefsson
4779               ;; <jas@kth.se>
4780               ;;
4781               ;; (gnus-byte-compile
4782               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
4783               ;;                         display)))))
4784               (setq select-articles
4785                     (gnus-uncompress-range
4786                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
4787                              (if (> tmp 0)
4788                                  tmp
4789                                1))
4790                            (cdr (gnus-active group)))))
4791               nil)
4792              (t
4793               nil))))
4794
4795     (gnus-summary-setup-default-charset)
4796
4797     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4798     (when (gnus-virtual-group-p group)
4799       (setq cached gnus-newsgroup-cached))
4800
4801     (setq gnus-newsgroup-unreads
4802           (gnus-sorted-ndifference
4803            (gnus-sorted-ndifference gnus-newsgroup-unreads
4804                                     gnus-newsgroup-marked)
4805            gnus-newsgroup-dormant))
4806
4807     (setq gnus-newsgroup-processable nil)
4808
4809     (gnus-update-read-articles group gnus-newsgroup-unreads)
4810
4811     ;; Adjust and set lists of article marks.
4812     (when info
4813       (gnus-adjust-marked-articles info))
4814
4815     (if (setq articles select-articles)
4816         (setq gnus-newsgroup-unselected
4817               (gnus-sorted-difference gnus-newsgroup-unreads articles))
4818       (setq articles (gnus-articles-to-read group read-all)))
4819
4820     (cond
4821      ((null articles)
4822       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4823       'quit)
4824      ((eq articles 0) nil)
4825      (t
4826       ;; Init the dependencies hash table.
4827       (setq gnus-newsgroup-dependencies
4828             (gnus-make-hashtable (length articles)))
4829       (gnus-set-global-variables)
4830       ;; Retrieve the headers and read them in.
4831       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4832
4833       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4834       (when cached
4835         (setq gnus-newsgroup-cached cached))
4836
4837       ;; Suppress duplicates?
4838       (when gnus-suppress-duplicates
4839         (gnus-dup-suppress-articles))
4840
4841       ;; Set the initial limit.
4842       (setq gnus-newsgroup-limit (copy-sequence articles))
4843       ;; Remove canceled articles from the list of unread articles.
4844       (setq fetched-articles
4845             (mapcar (lambda (headers) (mail-header-number headers))
4846                     gnus-newsgroup-headers))
4847       (setq gnus-newsgroup-articles fetched-articles)
4848       (setq gnus-newsgroup-unreads
4849             (gnus-sorted-nintersection
4850              gnus-newsgroup-unreads fetched-articles))
4851       (gnus-compute-unseen-list)
4852
4853       ;; Removed marked articles that do not exist.
4854       (gnus-update-missing-marks
4855        (gnus-sorted-difference articles fetched-articles))
4856       ;; We might want to build some more threads first.
4857       (when (and gnus-fetch-old-headers
4858                  (eq gnus-headers-retrieved-by 'nov))
4859         (if (eq gnus-fetch-old-headers 'invisible)
4860             (gnus-build-all-threads)
4861           (gnus-build-old-threads)))
4862       ;; Let the Gnus agent mark articles as read.
4863       (when gnus-agent
4864         (gnus-agent-get-undownloaded-list))
4865       ;; Remove list identifiers from subject
4866       (when gnus-list-identifiers
4867         (gnus-summary-remove-list-identifiers))
4868       ;; Check whether auto-expire is to be done in this group.
4869       (setq gnus-newsgroup-auto-expire
4870             (gnus-group-auto-expirable-p group))
4871       ;; Set up the article buffer now, if necessary.
4872       (unless gnus-single-article-buffer
4873         (gnus-article-setup-buffer))
4874       ;; First and last article in this newsgroup.
4875       (when gnus-newsgroup-headers
4876         (setq gnus-newsgroup-begin
4877               (mail-header-number (car gnus-newsgroup-headers))
4878               gnus-newsgroup-end
4879               (mail-header-number
4880                (gnus-last-element gnus-newsgroup-headers))))
4881       ;; GROUP is successfully selected.
4882       (or gnus-newsgroup-headers t)))))
4883
4884 (defun gnus-compute-unseen-list ()
4885   ;; The `seen' marks are treated specially.
4886   (if (not gnus-newsgroup-seen)
4887       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
4888     (setq gnus-newsgroup-unseen
4889           (gnus-inverse-list-range-intersection
4890            gnus-newsgroup-articles gnus-newsgroup-seen))))
4891
4892 (defun gnus-summary-display-make-predicate (display)
4893   (require 'gnus-agent)
4894   (when (= (length display) 1)
4895     (setq display (car display)))
4896   (unless gnus-summary-display-cache
4897     (dolist (elem (append '((unread . unread)
4898                             (read . read)
4899                             (unseen . unseen))
4900                           gnus-article-mark-lists))
4901       (push (cons (cdr elem)
4902                   (gnus-byte-compile
4903                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4904             gnus-summary-display-cache)))
4905   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
4906         (gnus-category-predicate-cache gnus-summary-display-cache))
4907     (gnus-get-predicate display)))
4908
4909 ;; Uses the dynamically bound `number' variable.
4910 (defvar number)
4911 (defun gnus-article-marked-p (type &optional article)
4912   (let ((article (or article number)))
4913     (cond
4914      ((eq type 'tick)
4915       (memq article gnus-newsgroup-marked))
4916      ((eq type 'unsend)
4917       (memq article gnus-newsgroup-unsendable))
4918      ((eq type 'undownload)
4919       (memq article gnus-newsgroup-undownloaded))
4920      ((eq type 'download)
4921       (memq article gnus-newsgroup-downloadable))
4922      ((eq type 'unread)
4923       (memq article gnus-newsgroup-unreads))
4924      ((eq type 'read)
4925       (memq article gnus-newsgroup-reads))
4926      ((eq type 'dormant)
4927       (memq article gnus-newsgroup-dormant) )
4928      ((eq type 'expire)
4929       (memq article gnus-newsgroup-expirable))
4930      ((eq type 'reply)
4931       (memq article gnus-newsgroup-replied))
4932      ((eq type 'killed)
4933       (memq article gnus-newsgroup-killed))
4934      ((eq type 'bookmark)
4935       (assq article gnus-newsgroup-bookmarks))
4936      ((eq type 'score)
4937       (assq article gnus-newsgroup-scored))
4938      ((eq type 'save)
4939       (memq article gnus-newsgroup-saved))
4940      ((eq type 'cache)
4941       (memq article gnus-newsgroup-cached))
4942      ((eq type 'forward)
4943       (memq article gnus-newsgroup-forwarded))
4944      ((eq type 'seen)
4945       (not (memq article gnus-newsgroup-unseen)))
4946      ((eq type 'recent)
4947       (memq article gnus-newsgroup-recent))
4948      (t t))))
4949
4950 (defun gnus-articles-to-read (group &optional read-all)
4951   "Find out what articles the user wants to read."
4952   (let* ((articles
4953           ;; Select all articles if `read-all' is non-nil, or if there
4954           ;; are no unread articles.
4955           (if (or read-all
4956                   (and (zerop (length gnus-newsgroup-marked))
4957                        (zerop (length gnus-newsgroup-unreads)))
4958                   ;; Fetch all if the predicate is non-nil.
4959                   gnus-newsgroup-display)
4960               ;; We want to select the headers for all the articles in
4961               ;; the group, so we select either all the active
4962               ;; articles in the group, or (if that's nil), the
4963               ;; articles in the cache.
4964               (or
4965                (gnus-uncompress-range (gnus-active group))
4966                (gnus-cache-articles-in-group group))
4967             ;; Select only the "normal" subset of articles.
4968             (gnus-sorted-nunion
4969              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
4970              gnus-newsgroup-unreads)))
4971          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4972          (scored (length scored-list))
4973          (number (length articles))
4974          (marked (+ (length gnus-newsgroup-marked)
4975                     (length gnus-newsgroup-dormant)))
4976          (select
4977           (cond
4978            ((numberp read-all)
4979             read-all)
4980            ((numberp gnus-newsgroup-display)
4981             gnus-newsgroup-display)
4982            (t
4983             (condition-case ()
4984                 (cond
4985                  ((and (or (<= scored marked) (= scored number))
4986                        (numberp gnus-large-newsgroup)
4987                        (> number gnus-large-newsgroup))
4988                   (let* ((cursor-in-echo-area nil)
4989                          (initial (gnus-parameter-large-newsgroup-initial
4990                                    gnus-newsgroup-name))
4991                          (input
4992                           (read-string
4993                            (format
4994                             "How many articles from %s (%s %d): "
4995                             (gnus-limit-string
4996                              (gnus-group-decoded-name gnus-newsgroup-name)
4997                              35)
4998                             (if initial "max" "default")
4999                             number)
5000                            (if initial
5001                                (cons (number-to-string initial)
5002                                      0)))))
5003                     (if (string-match "^[ \t]*$" input) number input)))
5004                  ((and (> scored marked) (< scored number)
5005                        (> (- scored number) 20))
5006                   (let ((input
5007                          (read-string
5008                           (format "%s %s (%d scored, %d total): "
5009                                   "How many articles from"
5010                                   (gnus-group-decoded-name group)
5011                                   scored number))))
5012                     (if (string-match "^[ \t]*$" input)
5013                         number input)))
5014                  (t number))
5015               (quit
5016                (message "Quit getting the articles to read")
5017                nil))))))
5018     (setq select (if (stringp select) (string-to-number select) select))
5019     (if (or (null select) (zerop select))
5020         select
5021       (if (and (not (zerop scored)) (<= (abs select) scored))
5022           (progn
5023             (setq articles (sort scored-list '<))
5024             (setq number (length articles)))
5025         (setq articles (copy-sequence articles)))
5026
5027       (when (< (abs select) number)
5028         (if (< select 0)
5029             ;; Select the N oldest articles.
5030             (setcdr (nthcdr (1- (abs select)) articles) nil)
5031           ;; Select the N most recent articles.
5032           (setq articles (nthcdr (- number select) articles))))
5033       (setq gnus-newsgroup-unselected
5034             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5035       (when gnus-alter-articles-to-read-function
5036         (setq gnus-newsgroup-unreads
5037               (sort
5038                (funcall gnus-alter-articles-to-read-function
5039                         gnus-newsgroup-name gnus-newsgroup-unreads)
5040                '<)))
5041       articles)))
5042
5043 (defun gnus-killed-articles (killed articles)
5044   (let (out)
5045     (while articles
5046       (when (inline (gnus-member-of-range (car articles) killed))
5047         (push (car articles) out))
5048       (setq articles (cdr articles)))
5049     out))
5050
5051 (defun gnus-uncompress-marks (marks)
5052   "Uncompress the mark ranges in MARKS."
5053   (let ((uncompressed '(score bookmark))
5054         out)
5055     (while marks
5056       (if (memq (caar marks) uncompressed)
5057           (push (car marks) out)
5058         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5059       (setq marks (cdr marks)))
5060     out))
5061
5062 (defun gnus-article-mark-to-type (mark)
5063   "Return the type of MARK."
5064   (or (cadr (assq mark gnus-article-special-mark-lists))
5065       'list))
5066
5067 (defun gnus-article-unpropagatable-p (mark)
5068   "Return whether MARK should be propagated to backend."
5069   (memq mark gnus-article-unpropagated-mark-lists))
5070
5071 (defun gnus-adjust-marked-articles (info)
5072   "Set all article lists and remove all marks that are no longer valid."
5073   (let* ((marked-lists (gnus-info-marks info))
5074          (active (gnus-active (gnus-info-group info)))
5075          (min (car active))
5076          (max (cdr active))
5077          (types gnus-article-mark-lists)
5078          marks var articles article mark mark-type)
5079
5080     (dolist (marks marked-lists)
5081       (setq mark (car marks)
5082             mark-type (gnus-article-mark-to-type mark)
5083             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5084
5085       ;; We set the variable according to the type of the marks list,
5086       ;; and then adjust the marks to a subset of the active articles.
5087       (cond
5088        ;; Adjust "simple" lists.
5089        ((eq mark-type 'list)
5090         (set var (setq articles (gnus-uncompress-range (cdr marks))))
5091         (when (memq mark '(tick dormant expire reply save))
5092           (while articles
5093             (when (or (< (setq article (pop articles)) min) (> article max))
5094               (set var (delq article (symbol-value var)))))))
5095        ;; Adjust assocs.
5096        ((eq mark-type 'tuple)
5097         (set var (setq articles (cdr marks)))
5098         (when (not (listp (cdr (symbol-value var))))
5099           (set var (list (symbol-value var))))
5100         (when (not (listp (cdr articles)))
5101           (setq articles (list articles)))
5102         (while articles
5103           (when (or (not (consp (setq article (pop articles))))
5104                     (< (car article) min)
5105                     (> (car article) max))
5106             (set var (delq article (symbol-value var))))))
5107        ;; Adjust ranges (sloppily).
5108        ((eq mark-type 'range)
5109         (cond
5110          ((eq mark 'seen)
5111           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5112           ;; It should be (seen (NUM1 . NUM2)).
5113           (when (numberp (cddr marks))
5114             (setcdr marks (list (cdr marks))))
5115           (setq articles (cdr marks))
5116           (while (and articles
5117                       (or (and (consp (car articles))
5118                                (> min (cdar articles)))
5119                           (and (numberp (car articles))
5120                                (> min (car articles)))))
5121             (pop articles))
5122           (set var articles))))))))
5123
5124 (defun gnus-update-missing-marks (missing)
5125   "Go through the list of MISSING articles and remove them from the mark lists."
5126   (when missing
5127     (let (var m)
5128       ;; Go through all types.
5129       (dolist (elem gnus-article-mark-lists)
5130         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5131           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5132           (when (symbol-value var)
5133             ;; This list has articles.  So we delete all missing
5134             ;; articles from it.
5135             (setq m missing)
5136             (while m
5137               (set var (delq (pop m) (symbol-value var))))))))))
5138
5139 (defun gnus-update-marks ()
5140   "Enter the various lists of marked articles into the newsgroup info list."
5141   (let ((types gnus-article-mark-lists)
5142         (info (gnus-get-info gnus-newsgroup-name))
5143         type list newmarked symbol delta-marks)
5144     (when info
5145       ;; Add all marks lists to the list of marks lists.
5146       (while (setq type (pop types))
5147         (setq list (symbol-value
5148                     (setq symbol
5149                           (intern (format "gnus-newsgroup-%s" (car type))))))
5150
5151         (when list
5152           ;; Get rid of the entries of the articles that have the
5153           ;; default score.
5154           (when (and (eq (cdr type) 'score)
5155                      gnus-save-score
5156                      list)
5157             (let* ((arts list)
5158                    (prev (cons nil list))
5159                    (all prev))
5160               (while arts
5161                 (if (or (not (consp (car arts)))
5162                         (= (cdar arts) gnus-summary-default-score))
5163                     (setcdr prev (cdr arts))
5164                   (setq prev arts))
5165                 (setq arts (cdr arts)))
5166               (setq list (cdr all)))))
5167
5168         (when (eq (cdr type) 'seen)
5169           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5170
5171         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5172           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5173
5174         (when (and (gnus-check-backend-function
5175                     'request-set-mark gnus-newsgroup-name)
5176                    (not (gnus-article-unpropagatable-p (cdr type))))
5177           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5178                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5179                  (add (gnus-remove-from-range
5180                        (gnus-copy-sequence list) old)))
5181             (when add
5182               (push (list add 'add (list (cdr type))) delta-marks))
5183             (when del
5184               (push (list del 'del (list (cdr type))) delta-marks))))
5185
5186         (when list
5187           (push (cons (cdr type) list) newmarked)))
5188
5189       (when delta-marks
5190         (unless (gnus-check-group gnus-newsgroup-name)
5191           (error "Can't open server for %s" gnus-newsgroup-name))
5192         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5193
5194       ;; Enter these new marks into the info of the group.
5195       (if (nthcdr 3 info)
5196           (setcar (nthcdr 3 info) newmarked)
5197         ;; Add the marks lists to the end of the info.
5198         (when newmarked
5199           (setcdr (nthcdr 2 info) (list newmarked))))
5200
5201       ;; Cut off the end of the info if there's nothing else there.
5202       (let ((i 5))
5203         (while (and (> i 2)
5204                     (not (nth i info)))
5205           (when (nthcdr (decf i) info)
5206             (setcdr (nthcdr i info) nil)))))))
5207
5208 (defun gnus-set-mode-line (where)
5209   "Set the mode line of the article or summary buffers.
5210 If WHERE is `summary', the summary mode line format will be used."
5211   ;; Is this mode line one we keep updated?
5212   (when (and (memq where gnus-updated-mode-lines)
5213              (symbol-value
5214               (intern (format "gnus-%s-mode-line-format-spec" where))))
5215     (let (mode-string)
5216       (save-excursion
5217         ;; We evaluate this in the summary buffer since these
5218         ;; variables are buffer-local to that buffer.
5219         (set-buffer gnus-summary-buffer)
5220         ;; We bind all these variables that are used in the `eval' form
5221         ;; below.
5222         (let* ((mformat (symbol-value
5223                          (intern
5224                           (format "gnus-%s-mode-line-format-spec" where))))
5225                (gnus-tmp-group-name (gnus-group-decoded-name
5226                                      gnus-newsgroup-name))
5227                (gnus-tmp-article-number (or gnus-current-article 0))
5228                (gnus-tmp-unread gnus-newsgroup-unreads)
5229                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5230                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5231                (gnus-tmp-unread-and-unselected
5232                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5233                             (zerop gnus-tmp-unselected))
5234                        "")
5235                       ((zerop gnus-tmp-unselected)
5236                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5237                       (t (format "{%d(+%d) more}"
5238                                  gnus-tmp-unread-and-unticked
5239                                  gnus-tmp-unselected))))
5240                (gnus-tmp-subject
5241                 (if (and gnus-current-headers
5242                          (vectorp gnus-current-headers))
5243                     (gnus-mode-string-quote
5244                      (mail-header-subject gnus-current-headers))
5245                   ""))
5246                bufname-length max-len
5247                gnus-tmp-header);; passed as argument to any user-format-funcs
5248           (setq mode-string (eval mformat))
5249           (setq bufname-length (if (string-match "%b" mode-string)
5250                                    (- (length
5251                                        (buffer-name
5252                                         (if (eq where 'summary)
5253                                             nil
5254                                           (get-buffer gnus-article-buffer))))
5255                                       2)
5256                                  0))
5257           (setq max-len (max 4 (if gnus-mode-non-string-length
5258                                    (- (window-width)
5259                                       gnus-mode-non-string-length
5260                                       bufname-length)
5261                                  (length mode-string))))
5262           ;; We might have to chop a bit of the string off...
5263           (when (> (length mode-string) max-len)
5264             (setq mode-string
5265                   (concat (gnus-truncate-string mode-string (- max-len 3))
5266                           "...")))
5267           ;; Pad the mode string a bit.
5268           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5269       ;; Update the mode line.
5270       (setq mode-line-buffer-identification
5271             (gnus-mode-line-buffer-identification (list mode-string)))
5272       (set-buffer-modified-p t))))
5273
5274 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5275   "Go through the HEADERS list and add all Xrefs to a hash table.
5276 The resulting hash table is returned, or nil if no Xrefs were found."
5277   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5278          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5279          (xref-hashtb (gnus-make-hashtable))
5280          start group entry number xrefs header)
5281     (while headers
5282       (setq header (pop headers))
5283       (when (and (setq xrefs (mail-header-xref header))
5284                  (not (memq (setq number (mail-header-number header))
5285                             unreads)))
5286         (setq start 0)
5287         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5288           (setq start (match-end 0))
5289           (setq group (if prefix
5290                           (concat prefix (substring xrefs (match-beginning 1)
5291                                                     (match-end 1)))
5292                         (substring xrefs (match-beginning 1) (match-end 1))))
5293           (setq number
5294                 (string-to-int (substring xrefs (match-beginning 2)
5295                                           (match-end 2))))
5296           (if (setq entry (gnus-gethash group xref-hashtb))
5297               (setcdr entry (cons number (cdr entry)))
5298             (gnus-sethash group (cons number nil) xref-hashtb)))))
5299     (and start xref-hashtb)))
5300
5301 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5302   "Look through all the headers and mark the Xrefs as read."
5303   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5304         name entry info xref-hashtb idlist method nth4)
5305     (save-excursion
5306       (set-buffer gnus-group-buffer)
5307       (when (setq xref-hashtb
5308                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5309         (mapatoms
5310          (lambda (group)
5311            (unless (string= from-newsgroup (setq name (symbol-name group)))
5312              (setq idlist (symbol-value group))
5313              ;; Dead groups are not updated.
5314              (and (prog1
5315                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5316                             info (nth 2 entry))
5317                     (when (stringp (setq nth4 (gnus-info-method info)))
5318                       (setq nth4 (gnus-server-to-method nth4))))
5319                   ;; Only do the xrefs if the group has the same
5320                   ;; select method as the group we have just read.
5321                   (or (gnus-methods-equal-p
5322                        nth4 (gnus-find-method-for-group from-newsgroup))
5323                       virtual
5324                       (equal nth4 (setq method (gnus-find-method-for-group
5325                                                 from-newsgroup)))
5326                       (and (equal (car nth4) (car method))
5327                            (equal (nth 1 nth4) (nth 1 method))))
5328                   gnus-use-cross-reference
5329                   (or (not (eq gnus-use-cross-reference t))
5330                       virtual
5331                       ;; Only do cross-references on subscribed
5332                       ;; groups, if that is what is wanted.
5333                       (<= (gnus-info-level info) gnus-level-subscribed))
5334                   (gnus-group-make-articles-read name idlist))))
5335          xref-hashtb)))))
5336
5337 (defun gnus-compute-read-articles (group articles)
5338   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5339          (info (nth 2 entry))
5340          (active (gnus-active group))
5341          ninfo)
5342     (when entry
5343       ;; First peel off all invalid article numbers.
5344       (when active
5345         (let ((ids articles)
5346               id first)
5347           (while (setq id (pop ids))
5348             (when (and first (> id (cdr active)))
5349               ;; We'll end up in this situation in one particular
5350               ;; obscure situation.  If you re-scan a group and get
5351               ;; a new article that is cross-posted to a different
5352               ;; group that has not been re-scanned, you might get
5353               ;; crossposted article that has a higher number than
5354               ;; Gnus believes possible.  So we re-activate this
5355               ;; group as well.  This might mean doing the
5356               ;; crossposting thingy will *increase* the number
5357               ;; of articles in some groups.  Tsk, tsk.
5358               (setq active (or (gnus-activate-group group) active)))
5359             (when (or (> id (cdr active))
5360                       (< id (car active)))
5361               (setq articles (delq id articles))))))
5362       ;; If the read list is nil, we init it.
5363       (if (and active
5364                (null (gnus-info-read info))
5365                (> (car active) 1))
5366           (setq ninfo (cons 1 (1- (car active))))
5367         (setq ninfo (gnus-info-read info)))
5368       ;; Then we add the read articles to the range.
5369       (gnus-add-to-range
5370        ninfo (setq articles (sort articles '<))))))
5371
5372 (defun gnus-group-make-articles-read (group articles)
5373   "Update the info of GROUP to say that ARTICLES are read."
5374   (let* ((num 0)
5375          (entry (gnus-gethash group gnus-newsrc-hashtb))
5376          (info (nth 2 entry))
5377          (active (gnus-active group))
5378          range)
5379     (when entry
5380       (setq range (gnus-compute-read-articles group articles))
5381       (save-excursion
5382         (set-buffer gnus-group-buffer)
5383         (gnus-undo-register
5384           `(progn
5385              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5386              (gnus-info-set-read ',info ',(gnus-info-read info))
5387              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5388              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5389              (gnus-group-update-group ,group t))))
5390       ;; Add the read articles to the range.
5391       (gnus-info-set-read info range)
5392       (gnus-request-set-mark group (list (list range 'add '(read))))
5393       ;; Then we have to re-compute how many unread
5394       ;; articles there are in this group.
5395       (when active
5396         (cond
5397          ((not range)
5398           (setq num (- (1+ (cdr active)) (car active))))
5399          ((not (listp (cdr range)))
5400           (setq num (- (cdr active) (- (1+ (cdr range))
5401                                        (car range)))))
5402          (t
5403           (while range
5404             (if (numberp (car range))
5405                 (setq num (1+ num))
5406               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5407             (setq range (cdr range)))
5408           (setq num (- (cdr active) num))))
5409         ;; Update the number of unread articles.
5410         (setcar entry num)
5411         ;; Update the group buffer.
5412         (gnus-group-update-group group t)))))
5413
5414 (defvar gnus-newsgroup-none-id 0)
5415
5416 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5417   (let ((cur nntp-server-buffer)
5418         (dependencies
5419          (or dependencies
5420              (save-excursion (set-buffer gnus-summary-buffer)
5421                              gnus-newsgroup-dependencies)))
5422         headers id end ref
5423         (mail-parse-charset gnus-newsgroup-charset)
5424         (mail-parse-ignored-charsets
5425          (save-excursion (condition-case nil
5426                              (set-buffer gnus-summary-buffer)
5427                            (error))
5428                          gnus-newsgroup-ignored-charsets)))
5429     (save-excursion
5430       (set-buffer nntp-server-buffer)
5431       ;; Translate all TAB characters into SPACE characters.
5432       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5433       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5434       (gnus-run-hooks 'gnus-parse-headers-hook)
5435       (let ((case-fold-search t)
5436             in-reply-to header p lines chars ctype)
5437         (goto-char (point-min))
5438         ;; Search to the beginning of the next header.  Error messages
5439         ;; do not begin with 2 or 3.
5440         (while (re-search-forward "^[23][0-9]+ " nil t)
5441           (setq id nil
5442                 ref nil)
5443           ;; This implementation of this function, with nine
5444           ;; search-forwards instead of the one re-search-forward and
5445           ;; a case (which basically was the old function) is actually
5446           ;; about twice as fast, even though it looks messier.  You
5447           ;; can't have everything, I guess.  Speed and elegance
5448           ;; doesn't always go hand in hand.
5449           (setq
5450            header
5451            (make-full-mail-header
5452             ;; Number.
5453             (prog1
5454                 (read cur)
5455               (end-of-line)
5456               (setq p (point))
5457               (narrow-to-region (point)
5458                                 (or (and (search-forward "\n.\n" nil t)
5459                                          (- (point) 2))
5460                                     (point))))
5461             ;; Subject.
5462             (progn
5463               (goto-char p)
5464               (if (search-forward "\nsubject:" nil t)
5465                   (nnheader-header-value)
5466                 "(none)"))
5467             ;; From.
5468             (progn
5469               (goto-char p)
5470               (if (search-forward "\nfrom:" nil t)
5471                   (nnheader-header-value)
5472                 "(nobody)"))
5473             ;; Date.
5474             (progn
5475               (goto-char p)
5476               (if (search-forward "\ndate:" nil t)
5477                   (nnheader-header-value) ""))
5478             ;; Message-ID.
5479             (progn
5480               (goto-char p)
5481               (setq id (if (re-search-forward
5482                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5483                            ;; We do it this way to make sure the Message-ID
5484                            ;; is (somewhat) syntactically valid.
5485                            (buffer-substring (match-beginning 1)
5486                                              (match-end 1))
5487                          ;; If there was no message-id, we just fake one
5488                          ;; to make subsequent routines simpler.
5489                          (nnheader-generate-fake-message-id))))
5490             ;; References.
5491             (progn
5492               (goto-char p)
5493               (if (search-forward "\nreferences:" nil t)
5494                   (progn
5495                     (setq end (point))
5496                     (prog1
5497                         (nnheader-header-value)
5498                       (setq ref
5499                             (buffer-substring
5500                              (progn
5501                                ;; (end-of-line)
5502                                (search-backward ">" end t)
5503                                (1+ (point)))
5504                              (progn
5505                                (search-backward "<" end t)
5506                                (point))))))
5507                 ;; Get the references from the in-reply-to header if there
5508                 ;; were no references and the in-reply-to header looks
5509                 ;; promising.
5510                 (if (and (search-forward "\nin-reply-to:" nil t)
5511                          (setq in-reply-to (nnheader-header-value))
5512                          (string-match "<[^>]+>" in-reply-to))
5513                     (let (ref2)
5514                       (setq ref (substring in-reply-to (match-beginning 0)
5515                                            (match-end 0)))
5516                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5517                         (setq ref2 (substring in-reply-to (match-beginning 0)
5518                                               (match-end 0)))
5519                         (when (> (length ref2) (length ref))
5520                           (setq ref ref2)))
5521                       ref)
5522                   (setq ref nil))))
5523             ;; Chars.
5524             (progn
5525               (goto-char p)
5526               (if (search-forward "\nchars: " nil t)
5527                   (if (numberp (setq chars (ignore-errors (read cur))))
5528                       chars -1)
5529                 -1))
5530             ;; Lines.
5531             (progn
5532               (goto-char p)
5533               (if (search-forward "\nlines: " nil t)
5534                   (if (numberp (setq lines (ignore-errors (read cur))))
5535                       lines -1)
5536                 -1))
5537             ;; Xref.
5538             (progn
5539               (goto-char p)
5540               (and (search-forward "\nxref:" nil t)
5541                    (nnheader-header-value)))
5542             ;; Extra.
5543             (when gnus-extra-headers
5544               (let ((extra gnus-extra-headers)
5545                     out)
5546                 (while extra
5547                   (goto-char p)
5548                   (when (search-forward
5549                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5550                     (push (cons (car extra) (nnheader-header-value)) out))
5551                   (pop extra))
5552                 out))))
5553           (goto-char p)
5554           (if (and (search-forward "\ncontent-type: " nil t)
5555                    (setq ctype (nnheader-header-value)))
5556               (mime-entity-set-content-type-internal
5557                header (mime-parse-Content-Type ctype)))
5558           (when (equal id ref)
5559             (setq ref nil))
5560
5561           (when gnus-alter-header-function
5562             (funcall gnus-alter-header-function header)
5563             (setq id (mail-header-id header)
5564                   ref (gnus-parent-id (mail-header-references header))))
5565
5566           (when (setq header
5567                       (gnus-dependencies-add-header
5568                        header dependencies force-new))
5569             (push header headers))
5570           (goto-char (point-max))
5571           (widen))
5572         (nreverse headers)))))
5573
5574 ;; Goes through the xover lines and returns a list of vectors
5575 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5576                                                   force-new dependencies
5577                                                   group also-fetch-heads)
5578   "Parse the news overview data in the server buffer.
5579 Return a list of headers that match SEQUENCE (see
5580 `nntp-retrieve-headers')."
5581   ;; Get the Xref when the users reads the articles since most/some
5582   ;; NNTP servers do not include Xrefs when using XOVER.
5583   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5584   (let ((mail-parse-charset gnus-newsgroup-charset)
5585         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5586         (cur nntp-server-buffer)
5587         (dependencies (or dependencies gnus-newsgroup-dependencies))
5588         (allp (cond
5589                ((eq gnus-read-all-available-headers t)
5590                 t)
5591                ((stringp gnus-read-all-available-headers)
5592                 (string-match gnus-read-all-available-headers group))
5593                (t
5594                 nil)))
5595         number headers header)
5596     (save-excursion
5597       (set-buffer nntp-server-buffer)
5598       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5599       ;; Allow the user to mangle the headers before parsing them.
5600       (gnus-run-hooks 'gnus-parse-headers-hook)
5601       (goto-char (point-min))
5602       (gnus-parse-without-error
5603         (while (and (or sequence allp)
5604                     (not (eobp)))
5605           (setq number (read cur))
5606           (when (not allp)
5607             (while (and sequence
5608                         (< (car sequence) number))
5609               (setq sequence (cdr sequence))))
5610           (when (and (or allp
5611                          (and sequence
5612                               (eq number (car sequence))))
5613                      (progn
5614                        (setq sequence (cdr sequence))
5615                        (setq header (inline
5616                                       (gnus-nov-parse-line
5617                                        number dependencies force-new)))))
5618             (push header headers))
5619           (forward-line 1)))
5620       ;; A common bug in inn is that if you have posted an article and
5621       ;; then retrieves the active file, it will answer correctly --
5622       ;; the new article is included.  However, a NOV entry for the
5623       ;; article may not have been generated yet, so this may fail.
5624       ;; We work around this problem by retrieving the last few
5625       ;; headers using HEAD.
5626       (if (or (not also-fetch-heads)
5627               (not sequence))
5628           ;; We (probably) got all the headers.
5629           (nreverse headers)
5630         (let ((gnus-nov-is-evil t))
5631           (nconc
5632            (nreverse headers)
5633            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5634              (gnus-get-newsgroup-headers))))))))
5635
5636 (defun gnus-article-get-xrefs ()
5637   "Fill in the Xref value in `gnus-current-headers', if necessary.
5638 This is meant to be called in `gnus-article-internal-prepare-hook'."
5639   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5640                                  gnus-current-headers)))
5641     (or (not gnus-use-cross-reference)
5642         (not headers)
5643         (and (mail-header-xref headers)
5644              (not (string= (mail-header-xref headers) "")))
5645         (let ((case-fold-search t)
5646               xref)
5647           (save-restriction
5648             (nnheader-narrow-to-headers)
5649             (goto-char (point-min))
5650             (when (or (and (not (eobp))
5651                            (eq (downcase (char-after)) ?x)
5652                            (looking-at "Xref:"))
5653                       (search-forward "\nXref:" nil t))
5654               (goto-char (1+ (match-end 0)))
5655               (setq xref (buffer-substring (point)
5656                                            (progn (end-of-line) (point))))
5657               (mail-header-set-xref headers xref)))))))
5658
5659 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5660   "Find article ID and insert the summary line for that article.
5661 OLD-HEADER can either be a header or a line number to insert
5662 the subject line on."
5663   (let* ((line (and (numberp old-header) old-header))
5664          (old-header (and (vectorp old-header) old-header))
5665          (header (cond ((and old-header use-old-header)
5666                         old-header)
5667                        ((and (numberp id)
5668                              (gnus-number-to-header id))
5669                         (gnus-number-to-header id))
5670                        (t
5671                         (gnus-read-header id))))
5672          (number (and (numberp id) id))
5673          d)
5674     (when header
5675       ;; Rebuild the thread that this article is part of and go to the
5676       ;; article we have fetched.
5677       (when (and (not gnus-show-threads)
5678                  old-header)
5679         (when (and number
5680                    (setq d (gnus-data-find (mail-header-number old-header))))
5681           (goto-char (gnus-data-pos d))
5682           (gnus-data-remove
5683            number
5684            (- (gnus-point-at-bol)
5685               (prog1
5686                   (1+ (gnus-point-at-eol))
5687                 (gnus-delete-line))))))
5688       (when old-header
5689         (mail-header-set-number header (mail-header-number old-header)))
5690       (setq gnus-newsgroup-sparse
5691             (delq (setq number (mail-header-number header))
5692                   gnus-newsgroup-sparse))
5693       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5694       (push number gnus-newsgroup-limit)
5695       (gnus-rebuild-thread (mail-header-id header) line)
5696       (gnus-summary-goto-subject number nil t))
5697     (when (and (numberp number)
5698                (> number 0))
5699       ;; We have to update the boundaries even if we can't fetch the
5700       ;; article if ID is a number -- so that the next `P' or `N'
5701       ;; command will fetch the previous (or next) article even
5702       ;; if the one we tried to fetch this time has been canceled.
5703       (when (> number gnus-newsgroup-end)
5704         (setq gnus-newsgroup-end number))
5705       (when (< number gnus-newsgroup-begin)
5706         (setq gnus-newsgroup-begin number))
5707       (setq gnus-newsgroup-unselected
5708             (delq number gnus-newsgroup-unselected)))
5709     ;; Report back a success?
5710     (and header (mail-header-number header))))
5711
5712 ;;; Process/prefix in the summary buffer
5713
5714 (defun gnus-summary-work-articles (n)
5715   "Return a list of articles to be worked upon.
5716 The prefix argument, the list of process marked articles, and the
5717 current article will be taken into consideration."
5718   (save-excursion
5719     (set-buffer gnus-summary-buffer)
5720     (cond
5721      (n
5722       ;; A numerical prefix has been given.
5723       (setq n (prefix-numeric-value n))
5724       (let ((backward (< n 0))
5725             (n (abs (prefix-numeric-value n)))
5726             articles article)
5727         (save-excursion
5728           (while
5729               (and (> n 0)
5730                    (push (setq article (gnus-summary-article-number))
5731                          articles)
5732                    (if backward
5733                        (gnus-summary-find-prev nil article)
5734                      (gnus-summary-find-next nil article)))
5735             (decf n)))
5736         (nreverse articles)))
5737      ((and (gnus-region-active-p) (mark))
5738       (message "region active")
5739       ;; Work on the region between point and mark.
5740       (let ((max (max (point) (mark)))
5741             articles article)
5742         (save-excursion
5743           (goto-char (min (point) (mark)))
5744           (while
5745               (and
5746                (push (setq article (gnus-summary-article-number)) articles)
5747                (gnus-summary-find-next nil article)
5748                (< (point) max)))
5749           (nreverse articles))))
5750      (gnus-newsgroup-processable
5751       ;; There are process-marked articles present.
5752       ;; Save current state.
5753       (gnus-summary-save-process-mark)
5754       ;; Return the list.
5755       (reverse gnus-newsgroup-processable))
5756      (t
5757       ;; Just return the current article.
5758       (list (gnus-summary-article-number))))))
5759
5760 (defmacro gnus-summary-iterate (arg &rest forms)
5761   "Iterate over the process/prefixed articles and do FORMS.
5762 ARG is the interactive prefix given to the command.  FORMS will be
5763 executed with point over the summary line of the articles."
5764   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5765     `(let ((,articles (gnus-summary-work-articles ,arg)))
5766        (while ,articles
5767          (gnus-summary-goto-subject (car ,articles))
5768          ,@forms
5769          (pop ,articles)))))
5770
5771 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5772 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5773
5774 (defun gnus-summary-save-process-mark ()
5775   "Push the current set of process marked articles on the stack."
5776   (interactive)
5777   (push (copy-sequence gnus-newsgroup-processable)
5778         gnus-newsgroup-process-stack))
5779
5780 (defun gnus-summary-kill-process-mark ()
5781   "Push the current set of process marked articles on the stack and unmark."
5782   (interactive)
5783   (gnus-summary-save-process-mark)
5784   (gnus-summary-unmark-all-processable))
5785
5786 (defun gnus-summary-yank-process-mark ()
5787   "Pop the last process mark state off the stack and restore it."
5788   (interactive)
5789   (unless gnus-newsgroup-process-stack
5790     (error "Empty mark stack"))
5791   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5792
5793 (defun gnus-summary-process-mark-set (set)
5794   "Make SET into the current process marked articles."
5795   (gnus-summary-unmark-all-processable)
5796   (while set
5797     (gnus-summary-set-process-mark (pop set))))
5798
5799 ;;; Searching and stuff
5800
5801 (defun gnus-summary-search-group (&optional backward use-level)
5802   "Search for next unread newsgroup.
5803 If optional argument BACKWARD is non-nil, search backward instead."
5804   (save-excursion
5805     (set-buffer gnus-group-buffer)
5806     (when (gnus-group-search-forward
5807            backward nil (if use-level (gnus-group-group-level) nil))
5808       (gnus-group-group-name))))
5809
5810 (defun gnus-summary-best-group (&optional exclude-group)
5811   "Find the name of the best unread group.
5812 If EXCLUDE-GROUP, do not go to this group."
5813   (save-excursion
5814     (set-buffer gnus-group-buffer)
5815     (save-excursion
5816       (gnus-group-best-unread-group exclude-group))))
5817
5818 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5819   (if backward (gnus-summary-find-prev)
5820     (let* ((dummy (gnus-summary-article-intangible-p))
5821            (article (or article (gnus-summary-article-number)))
5822            (arts (gnus-data-find-list article))
5823            result)
5824       (when (and (not dummy)
5825                  (or (not gnus-summary-check-current)
5826                      (not unread)
5827                      (not (gnus-data-unread-p (car arts)))))
5828         (setq arts (cdr arts)))
5829       (when (setq result
5830                   (if unread
5831                       (progn
5832                         (while arts
5833                           (when (or (and undownloaded
5834                                          (eq gnus-undownloaded-mark
5835                                              (gnus-data-mark (car arts))))
5836                                     (gnus-data-unread-p (car arts)))
5837                             (setq result (car arts)
5838                                   arts nil))
5839                           (setq arts (cdr arts)))
5840                         result)
5841                     (car arts)))
5842         (goto-char (gnus-data-pos result))
5843         (gnus-data-number result)))))
5844
5845 (defun gnus-summary-find-prev (&optional unread article)
5846   (let* ((eobp (eobp))
5847          (article (or article (gnus-summary-article-number)))
5848          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5849          result)
5850     (when (and (not eobp)
5851                (or (not gnus-summary-check-current)
5852                    (not unread)
5853                    (not (gnus-data-unread-p (car arts)))))
5854       (setq arts (cdr arts)))
5855     (when (setq result
5856                 (if unread
5857                     (progn
5858                       (while arts
5859                         (when (gnus-data-unread-p (car arts))
5860                           (setq result (car arts)
5861                                 arts nil))
5862                         (setq arts (cdr arts)))
5863                       result)
5864                   (car arts)))
5865       (goto-char (gnus-data-pos result))
5866       (gnus-data-number result))))
5867
5868 (defun gnus-summary-find-subject (subject &optional unread backward article)
5869   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5870          (article (or article (gnus-summary-article-number)))
5871          (articles (gnus-data-list backward))
5872          (arts (gnus-data-find-list article articles))
5873          result)
5874     (when (or (not gnus-summary-check-current)
5875               (not unread)
5876               (not (gnus-data-unread-p (car arts))))
5877       (setq arts (cdr arts)))
5878     (while arts
5879       (and (or (not unread)
5880                (gnus-data-unread-p (car arts)))
5881            (vectorp (gnus-data-header (car arts)))
5882            (gnus-subject-equal
5883             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5884            (setq result (car arts)
5885                  arts nil))
5886       (setq arts (cdr arts)))
5887     (and result
5888          (goto-char (gnus-data-pos result))
5889          (gnus-data-number result))))
5890
5891 (defun gnus-summary-search-forward (&optional unread subject backward)
5892   "Search forward for an article.
5893 If UNREAD, look for unread articles.  If SUBJECT, look for
5894 articles with that subject.  If BACKWARD, search backward instead."
5895   (cond (subject (gnus-summary-find-subject subject unread backward))
5896         (backward (gnus-summary-find-prev unread))
5897         (t (gnus-summary-find-next unread))))
5898
5899 (defun gnus-recenter (&optional n)
5900   "Center point in window and redisplay frame.
5901 Also do horizontal recentering."
5902   (interactive "P")
5903   (when (and gnus-auto-center-summary
5904              (not (eq gnus-auto-center-summary 'vertical)))
5905     (gnus-horizontal-recenter))
5906   (recenter n))
5907
5908 (defun gnus-summary-recenter ()
5909   "Center point in the summary window.
5910 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5911 displayed, no centering will be performed."
5912   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5913   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5914   (interactive)
5915   (let* ((top (cond ((< (window-height) 4) 0)
5916                     ((< (window-height) 7) 1)
5917                     (t (if (numberp gnus-auto-center-summary)
5918                            gnus-auto-center-summary
5919                          2))))
5920          (height (1- (window-height)))
5921          (bottom (save-excursion (goto-char (point-max))
5922                                  (forward-line (- height))
5923                                  (point)))
5924          (window (get-buffer-window (current-buffer))))
5925     ;; The user has to want it.
5926     (when gnus-auto-center-summary
5927       (when (get-buffer-window gnus-article-buffer)
5928         ;; Only do recentering when the article buffer is displayed,
5929         ;; Set the window start to either `bottom', which is the biggest
5930         ;; possible valid number, or the second line from the top,
5931         ;; whichever is the least.
5932         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5933           (if (> bottom top-pos)
5934               ;; Keep the second line from the top visible
5935               (set-window-start window top-pos t)
5936             ;; Try to keep the bottom line visible; if it's partially
5937             ;; obscured, either scroll one more line to make it fully
5938             ;; visible, or revert to using TOP-POS.
5939             (save-excursion
5940               (goto-char (point-max))
5941               (forward-line -1)
5942               (let ((last-line-start (point)))
5943                 (goto-char bottom)
5944                 (set-window-start window (point) t)
5945                 (when (not (pos-visible-in-window-p last-line-start window))
5946                   (forward-line 1)
5947                   (set-window-start window (min (point) top-pos) t)))))))
5948       ;; Do horizontal recentering while we're at it.
5949       (when (and (get-buffer-window (current-buffer) t)
5950                  (not (eq gnus-auto-center-summary 'vertical)))
5951         (let ((selected (selected-window)))
5952           (select-window (get-buffer-window (current-buffer) t))
5953           (gnus-summary-position-point)
5954           (gnus-horizontal-recenter)
5955           (select-window selected))))))
5956
5957 (defun gnus-summary-jump-to-group (newsgroup)
5958   "Move point to NEWSGROUP in group mode buffer."
5959   ;; Keep update point of group mode buffer if visible.
5960   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5961       (save-window-excursion
5962         ;; Take care of tree window mode.
5963         (when (get-buffer-window gnus-group-buffer)
5964           (pop-to-buffer gnus-group-buffer))
5965         (gnus-group-jump-to-group newsgroup))
5966     (save-excursion
5967       ;; Take care of tree window mode.
5968       (if (get-buffer-window gnus-group-buffer)
5969           (pop-to-buffer gnus-group-buffer)
5970         (set-buffer gnus-group-buffer))
5971       (gnus-group-jump-to-group newsgroup))))
5972
5973 ;; This function returns a list of article numbers based on the
5974 ;; difference between the ranges of read articles in this group and
5975 ;; the range of active articles.
5976 (defun gnus-list-of-unread-articles (group)
5977   (let* ((read (gnus-info-read (gnus-get-info group)))
5978          (active (or (gnus-active group) (gnus-activate-group group)))
5979          (last (cdr active))
5980          first nlast unread)
5981     ;; If none are read, then all are unread.
5982     (if (not read)
5983         (setq first (car active))
5984       ;; If the range of read articles is a single range, then the
5985       ;; first unread article is the article after the last read
5986       ;; article.  Sounds logical, doesn't it?
5987       (if (and (not (listp (cdr read)))
5988                (or (< (car read) (car active))
5989                    (progn (setq read (list read))
5990                           nil)))
5991           (setq first (max (car active) (1+ (cdr read))))
5992         ;; `read' is a list of ranges.
5993         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5994                                   (caar read)))
5995                   1)
5996           (setq first (car active)))
5997         (while read
5998           (when first
5999             (while (< first nlast)
6000               (push first unread)
6001               (setq first (1+ first))))
6002           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6003           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6004           (setq read (cdr read)))))
6005     ;; And add the last unread articles.
6006     (while (<= first last)
6007       (push first unread)
6008       (setq first (1+ first)))
6009     ;; Return the list of unread articles.
6010     (delq 0 (nreverse unread))))
6011
6012 (defun gnus-list-of-read-articles (group)
6013   "Return a list of unread, unticked and non-dormant articles."
6014   (let* ((info (gnus-get-info group))
6015          (marked (gnus-info-marks info))
6016          (active (gnus-active group)))
6017     (and info active
6018          (gnus-list-range-difference
6019           (gnus-list-range-difference
6020            (gnus-sorted-complement
6021             (gnus-uncompress-range active)
6022             (gnus-list-of-unread-articles group))
6023            (cdr (assq 'dormant marked)))
6024           (cdr (assq 'tick marked))))))
6025
6026 ;; Various summary commands
6027
6028 (defun gnus-summary-select-article-buffer ()
6029   "Reconfigure windows to show article buffer."
6030   (interactive)
6031   (if (not (gnus-buffer-live-p gnus-article-buffer))
6032       (error "There is no article buffer for this summary buffer")
6033     (gnus-configure-windows 'article)
6034     (select-window (get-buffer-window gnus-article-buffer))))
6035
6036 (defun gnus-summary-universal-argument (arg)
6037   "Perform any operation on all articles that are process/prefixed."
6038   (interactive "P")
6039   (let ((articles (gnus-summary-work-articles arg))
6040         func article)
6041     (if (eq
6042          (setq
6043           func
6044           (key-binding
6045            (read-key-sequence
6046             (substitute-command-keys
6047              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6048          'undefined)
6049         (gnus-error 1 "Undefined key")
6050       (save-excursion
6051         (while articles
6052           (gnus-summary-goto-subject (setq article (pop articles)))
6053           (let (gnus-newsgroup-processable)
6054             (command-execute func))
6055           (gnus-summary-remove-process-mark article)))))
6056   (gnus-summary-position-point))
6057
6058 (defun gnus-summary-toggle-truncation (&optional arg)
6059   "Toggle truncation of summary lines.
6060 With arg, turn line truncation on iff arg is positive."
6061   (interactive "P")
6062   (setq truncate-lines
6063         (if (null arg) (not truncate-lines)
6064           (> (prefix-numeric-value arg) 0)))
6065   (redraw-display))
6066
6067 (defun gnus-summary-reselect-current-group (&optional all rescan)
6068   "Exit and then reselect the current newsgroup.
6069 The prefix argument ALL means to select all articles."
6070   (interactive "P")
6071   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6072     (error "Ephemeral groups can't be reselected"))
6073   (let ((current-subject (gnus-summary-article-number))
6074         (group gnus-newsgroup-name))
6075     (setq gnus-newsgroup-begin nil)
6076     (gnus-summary-exit)
6077     ;; We have to adjust the point of group mode buffer because
6078     ;; point was moved to the next unread newsgroup by exiting.
6079     (gnus-summary-jump-to-group group)
6080     (when rescan
6081       (save-excursion
6082         (save-window-excursion
6083           ;; Don't show group contents.
6084           (set-window-start (selected-window) (point-max))
6085           (gnus-group-get-new-news-this-group 1))))
6086     (gnus-group-read-group all t)
6087     (gnus-summary-goto-subject current-subject nil t)))
6088
6089 (defun gnus-summary-rescan-group (&optional all)
6090   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6091   (interactive "P")
6092   (gnus-summary-reselect-current-group all t))
6093
6094 (defun gnus-summary-update-info (&optional non-destructive)
6095   (save-excursion
6096     (let ((group gnus-newsgroup-name))
6097       (when group
6098         (when gnus-newsgroup-kill-headers
6099           (setq gnus-newsgroup-killed
6100                 (gnus-compress-sequence
6101                  (gnus-sorted-union
6102                   (gnus-list-range-intersection
6103                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6104                   gnus-newsgroup-unreads)
6105                  t)))
6106         (unless (listp (cdr gnus-newsgroup-killed))
6107           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6108         (let ((headers gnus-newsgroup-headers))
6109           ;; Set the new ranges of read articles.
6110           (save-excursion
6111             (set-buffer gnus-group-buffer)
6112             (gnus-undo-force-boundary))
6113           (gnus-update-read-articles
6114            group (gnus-sorted-union
6115                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6116           ;; Set the current article marks.
6117           (let ((gnus-newsgroup-scored
6118                  (if (and (not gnus-save-score)
6119                           (not non-destructive))
6120                      nil
6121                    gnus-newsgroup-scored)))
6122             (save-excursion
6123               (gnus-update-marks)))
6124           ;; Do the cross-ref thing.
6125           (when gnus-use-cross-reference
6126             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6127           ;; Do not switch windows but change the buffer to work.
6128           (set-buffer gnus-group-buffer)
6129           (unless (gnus-ephemeral-group-p group)
6130             (gnus-group-update-group group)))))))
6131
6132 (defun gnus-summary-save-newsrc (&optional force)
6133   "Save the current number of read/marked articles in the dribble buffer.
6134 The dribble buffer will then be saved.
6135 If FORCE (the prefix), also save the .newsrc file(s)."
6136   (interactive "P")
6137   (gnus-summary-update-info t)
6138   (if force
6139       (gnus-save-newsrc-file)
6140     (gnus-dribble-save)))
6141
6142 (defun gnus-summary-exit (&optional temporary)
6143   "Exit reading current newsgroup, and then return to group selection mode.
6144 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6145   (interactive)
6146   (gnus-set-global-variables)
6147   (gnus-kill-save-kill-buffer)
6148   (gnus-async-halt-prefetch)
6149   (let* ((group gnus-newsgroup-name)
6150          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6151          (mode major-mode)
6152          (group-point nil)
6153          (buf (current-buffer)))
6154     (unless quit-config
6155       ;; Do adaptive scoring, and possibly save score files.
6156       (when gnus-newsgroup-adaptive
6157         (gnus-score-adaptive))
6158       (when gnus-use-scoring
6159         (gnus-score-save)))
6160     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6161     ;; If we have several article buffers, we kill them at exit.
6162     (unless gnus-single-article-buffer
6163       (gnus-kill-buffer gnus-original-article-buffer)
6164       (setq gnus-article-current nil))
6165     (when gnus-use-cache
6166       (gnus-cache-possibly-remove-articles)
6167       (gnus-cache-save-buffers))
6168     (gnus-async-prefetch-remove-group group)
6169     (when gnus-suppress-duplicates
6170       (gnus-dup-enter-articles))
6171     (when gnus-use-trees
6172       (gnus-tree-close group))
6173     (when gnus-use-cache
6174       (gnus-cache-write-active))
6175     ;; Remove entries for this group.
6176     (nnmail-purge-split-history (gnus-group-real-name group))
6177     ;; Make all changes in this group permanent.
6178     (unless quit-config
6179       (gnus-run-hooks 'gnus-exit-group-hook)
6180       (gnus-summary-update-info))
6181     (gnus-close-group group)
6182     ;; Make sure where we were, and go to next newsgroup.
6183     (set-buffer gnus-group-buffer)
6184     (unless quit-config
6185       (gnus-group-jump-to-group group))
6186     (gnus-run-hooks 'gnus-summary-exit-hook)
6187     (unless (or quit-config
6188                 ;; If this group has disappeared from the summary
6189                 ;; buffer, don't skip forwards.
6190                 (not (string= group (gnus-group-group-name))))
6191       (gnus-group-next-unread-group 1))
6192     (setq group-point (point))
6193     (if temporary
6194         nil                             ;Nothing to do.
6195       ;; If we have several article buffers, we kill them at exit.
6196       (unless gnus-single-article-buffer
6197         (gnus-kill-buffer gnus-article-buffer)
6198         (gnus-kill-buffer gnus-original-article-buffer)
6199         (setq gnus-article-current nil))
6200       (set-buffer buf)
6201       (if (not gnus-kill-summary-on-exit)
6202           (progn
6203             (gnus-deaden-summary)
6204             (setq mode nil))
6205         ;; We set all buffer-local variables to nil.  It is unclear why
6206         ;; this is needed, but if we don't, buffer-local variables are
6207         ;; not garbage-collected, it seems.  This would the lead to en
6208         ;; ever-growing Emacs.
6209         (gnus-summary-clear-local-variables)
6210         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6211           (gnus-summary-clear-local-variables))
6212         (when (get-buffer gnus-article-buffer)
6213           (bury-buffer gnus-article-buffer))
6214         ;; We clear the global counterparts of the buffer-local
6215         ;; variables as well, just to be on the safe side.
6216         (set-buffer gnus-group-buffer)
6217         (gnus-summary-clear-local-variables)
6218         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6219           (gnus-summary-clear-local-variables)))
6220       (setq gnus-current-select-method gnus-select-method)
6221       (pop-to-buffer gnus-group-buffer)
6222       (if (not quit-config)
6223           (progn
6224             (goto-char group-point)
6225             (gnus-configure-windows 'group 'force)
6226             (unless (pos-visible-in-window-p)
6227               (forward-line (/ (static-if (featurep 'xemacs)
6228                                    (window-displayed-height)
6229                                  (1- (window-height)))
6230                                -2))
6231               (set-window-start (selected-window) (point))
6232               (goto-char group-point)))
6233         (gnus-handle-ephemeral-exit quit-config))
6234       ;; Return to group mode buffer.
6235       (when (eq mode 'gnus-summary-mode)
6236         (gnus-kill-buffer buf))
6237       ;; Clear the current group name.
6238       (unless quit-config
6239         (setq gnus-newsgroup-name nil)))))
6240
6241 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6242 (defun gnus-summary-exit-no-update (&optional no-questions)
6243   "Quit reading current newsgroup without updating read article info."
6244   (interactive)
6245   (let* ((group gnus-newsgroup-name)
6246          (quit-config (gnus-group-quit-config group)))
6247     (when (or no-questions
6248               gnus-expert-user
6249               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6250       (gnus-async-halt-prefetch)
6251       (mapcar 'funcall
6252               (delq 'gnus-summary-expire-articles
6253                     (copy-sequence gnus-summary-prepare-exit-hook)))
6254       ;; If we have several article buffers, we kill them at exit.
6255       (unless gnus-single-article-buffer
6256         (gnus-kill-buffer gnus-article-buffer)
6257         (gnus-kill-buffer gnus-original-article-buffer)
6258         (setq gnus-article-current nil))
6259       (if (not gnus-kill-summary-on-exit)
6260           (gnus-deaden-summary)
6261         (gnus-close-group group)
6262         (gnus-summary-clear-local-variables)
6263         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6264           (gnus-summary-clear-local-variables))
6265         (set-buffer gnus-group-buffer)
6266         (gnus-summary-clear-local-variables)
6267         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6268           (gnus-summary-clear-local-variables))
6269         (when (get-buffer gnus-summary-buffer)
6270           (kill-buffer gnus-summary-buffer)))
6271       (unless gnus-single-article-buffer
6272         (setq gnus-article-current nil))
6273       (when gnus-use-trees
6274         (gnus-tree-close group))
6275       (gnus-async-prefetch-remove-group group)
6276       (when (get-buffer gnus-article-buffer)
6277         (bury-buffer gnus-article-buffer))
6278       ;; Return to the group buffer.
6279       (gnus-configure-windows 'group 'force)
6280       ;; Clear the current group name.
6281       (setq gnus-newsgroup-name nil)
6282       (when (equal (gnus-group-group-name) group)
6283         (gnus-group-next-unread-group 1))
6284       (when quit-config
6285         (gnus-handle-ephemeral-exit quit-config)))))
6286
6287 (defun gnus-handle-ephemeral-exit (quit-config)
6288   "Handle movement when leaving an ephemeral group.
6289 The state which existed when entering the ephemeral is reset."
6290   (if (not (buffer-name (car quit-config)))
6291       (gnus-configure-windows 'group 'force)
6292     (set-buffer (car quit-config))
6293     (cond ((eq major-mode 'gnus-summary-mode)
6294            (gnus-set-global-variables))
6295           ((eq major-mode 'gnus-article-mode)
6296            (save-excursion
6297              ;; The `gnus-summary-buffer' variable may point
6298              ;; to the old summary buffer when using a single
6299              ;; article buffer.
6300              (unless (gnus-buffer-live-p gnus-summary-buffer)
6301                (set-buffer gnus-group-buffer))
6302              (set-buffer gnus-summary-buffer)
6303              (gnus-set-global-variables))))
6304     (if (or (eq (cdr quit-config) 'article)
6305             (eq (cdr quit-config) 'pick))
6306         (progn
6307           ;; The current article may be from the ephemeral group
6308           ;; thus it is best that we reload this article
6309           (gnus-summary-show-article)
6310           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6311               (gnus-configure-windows 'pick 'force)
6312             (gnus-configure-windows (cdr quit-config) 'force)))
6313       (gnus-configure-windows (cdr quit-config) 'force))
6314     (when (eq major-mode 'gnus-summary-mode)
6315       (gnus-summary-next-subject 1 nil t)
6316       (gnus-summary-recenter)
6317       (gnus-summary-position-point))))
6318
6319 (defun gnus-summary-preview-mime-message ()
6320   "MIME decode and play this message."
6321   (interactive)
6322   (let ((gnus-break-pages nil)
6323         (gnus-show-mime t))
6324     (gnus-summary-select-article gnus-show-all-headers t))
6325   (let ((w (get-buffer-window gnus-article-buffer)))
6326     (when w
6327       (select-window (get-buffer-window gnus-article-buffer)))))
6328
6329 ;;; Dead summaries.
6330
6331 (defvar gnus-dead-summary-mode-map nil)
6332
6333 (unless gnus-dead-summary-mode-map
6334   (setq gnus-dead-summary-mode-map (make-keymap))
6335   (suppress-keymap gnus-dead-summary-mode-map)
6336   (substitute-key-definition
6337    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6338   (dolist (key '("\C-d" "\r" "\177" [delete]))
6339     (define-key gnus-dead-summary-mode-map
6340       key 'gnus-summary-wake-up-the-dead))
6341   (dolist (key '("q" "Q"))
6342     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6343
6344 (defvar gnus-dead-summary-mode nil
6345   "Minor mode for Gnus summary buffers.")
6346
6347 (defun gnus-dead-summary-mode (&optional arg)
6348   "Minor mode for Gnus summary buffers."
6349   (interactive "P")
6350   (when (eq major-mode 'gnus-summary-mode)
6351     (make-local-variable 'gnus-dead-summary-mode)
6352     (setq gnus-dead-summary-mode
6353           (if (null arg) (not gnus-dead-summary-mode)
6354             (> (prefix-numeric-value arg) 0)))
6355     (when gnus-dead-summary-mode
6356       (gnus-add-minor-mode
6357        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6358
6359 (defun gnus-deaden-summary ()
6360   "Make the current summary buffer into a dead summary buffer."
6361   ;; Kill any previous dead summary buffer.
6362   (when (and gnus-dead-summary
6363              (buffer-name gnus-dead-summary))
6364     (save-excursion
6365       (set-buffer gnus-dead-summary)
6366       (when gnus-dead-summary-mode
6367         (kill-buffer (current-buffer)))))
6368   ;; Make this the current dead summary.
6369   (setq gnus-dead-summary (current-buffer))
6370   (gnus-dead-summary-mode 1)
6371   (let ((name (buffer-name)))
6372     (when (string-match "Summary" name)
6373       (rename-buffer
6374        (concat (substring name 0 (match-beginning 0)) "Dead "
6375                (substring name (match-beginning 0)))
6376        t)
6377       (bury-buffer))))
6378
6379 (defun gnus-kill-or-deaden-summary (buffer)
6380   "Kill or deaden the summary BUFFER."
6381   (save-excursion
6382     (when (and (buffer-name buffer)
6383                (not gnus-single-article-buffer))
6384       (save-excursion
6385         (set-buffer buffer)
6386         (gnus-kill-buffer gnus-article-buffer)
6387         (gnus-kill-buffer gnus-original-article-buffer)))
6388     (cond
6389      ;; Kill the buffer.
6390      (gnus-kill-summary-on-exit
6391       (when (and gnus-use-trees
6392                  (gnus-buffer-exists-p buffer))
6393         (save-excursion
6394           (set-buffer buffer)
6395           (gnus-tree-close gnus-newsgroup-name)))
6396       (gnus-kill-buffer buffer))
6397      ;; Deaden the buffer.
6398      ((gnus-buffer-exists-p buffer)
6399       (save-excursion
6400         (set-buffer buffer)
6401         (gnus-deaden-summary))))))
6402
6403 (defun gnus-summary-wake-up-the-dead (&rest args)
6404   "Wake up the dead summary buffer."
6405   (interactive)
6406   (gnus-dead-summary-mode -1)
6407   (let ((name (buffer-name)))
6408     (when (string-match "Dead " name)
6409       (rename-buffer
6410        (concat (substring name 0 (match-beginning 0))
6411                (substring name (match-end 0)))
6412        t)))
6413   (gnus-message 3 "This dead summary is now alive again"))
6414
6415 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6416 (defun gnus-summary-fetch-faq (&optional faq-dir)
6417   "Fetch the FAQ for the current group.
6418 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6419 in."
6420   (interactive
6421    (list
6422     (when current-prefix-arg
6423       (completing-read
6424        "Faq dir: " (and (listp gnus-group-faq-directory)
6425                         (mapcar (lambda (file) (list file))
6426                                 gnus-group-faq-directory))))))
6427   (let (gnus-faq-buffer)
6428     (when (setq gnus-faq-buffer
6429                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6430       (gnus-configure-windows 'summary-faq))))
6431
6432 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6433 (defun gnus-summary-describe-group (&optional force)
6434   "Describe the current newsgroup."
6435   (interactive "P")
6436   (gnus-group-describe-group force gnus-newsgroup-name))
6437
6438 (defun gnus-summary-describe-briefly ()
6439   "Describe summary mode commands briefly."
6440   (interactive)
6441   (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")))
6442
6443 ;; Walking around group mode buffer from summary mode.
6444
6445 (defun gnus-summary-next-group (&optional no-article target-group backward)
6446   "Exit current newsgroup and then select next unread newsgroup.
6447 If prefix argument NO-ARTICLE is non-nil, no article is selected
6448 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6449 previous group instead."
6450   (interactive "P")
6451   ;; Stop pre-fetching.
6452   (gnus-async-halt-prefetch)
6453   (let ((current-group gnus-newsgroup-name)
6454         (current-buffer (current-buffer))
6455         entered)
6456     ;; First we semi-exit this group to update Xrefs and all variables.
6457     ;; We can't do a real exit, because the window conf must remain
6458     ;; the same in case the user is prompted for info, and we don't
6459     ;; want the window conf to change before that...
6460     (gnus-summary-exit t)
6461     (while (not entered)
6462       ;; Then we find what group we are supposed to enter.
6463       (set-buffer gnus-group-buffer)
6464       (gnus-group-jump-to-group current-group)
6465       (setq target-group
6466             (or target-group
6467                 (if (eq gnus-keep-same-level 'best)
6468                     (gnus-summary-best-group gnus-newsgroup-name)
6469                   (gnus-summary-search-group backward gnus-keep-same-level))))
6470       (if (not target-group)
6471           ;; There are no further groups, so we return to the group
6472           ;; buffer.
6473           (progn
6474             (gnus-message 5 "Returning to the group buffer")
6475             (setq entered t)
6476             (when (gnus-buffer-live-p current-buffer)
6477               (set-buffer current-buffer)
6478               (gnus-summary-exit))
6479             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6480         ;; We try to enter the target group.
6481         (gnus-group-jump-to-group target-group)
6482         (let ((unreads (gnus-group-group-unread)))
6483           (if (and (or (eq t unreads)
6484                        (and unreads (not (zerop unreads))))
6485                    (gnus-summary-read-group
6486                     target-group nil no-article
6487                     (and (buffer-name current-buffer) current-buffer)
6488                     nil backward))
6489               (setq entered t)
6490             (setq current-group target-group
6491                   target-group nil)))))))
6492
6493 (defun gnus-summary-prev-group (&optional no-article)
6494   "Exit current newsgroup and then select previous unread newsgroup.
6495 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6496   (interactive "P")
6497   (gnus-summary-next-group no-article nil t))
6498
6499 ;; Walking around summary lines.
6500
6501 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6502   "Go to the first unread subject.
6503 If UNREAD is non-nil, go to the first unread article.
6504 Returns the article selected or nil if there are no unread articles."
6505   (interactive "P")
6506   (prog1
6507       (cond
6508        ;; Empty summary.
6509        ((null gnus-newsgroup-data)
6510         (gnus-message 3 "No articles in the group")
6511         nil)
6512        ;; Pick the first article.
6513        ((not unread)
6514         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6515         (gnus-data-number (car gnus-newsgroup-data)))
6516        ;; No unread articles.
6517        ((null gnus-newsgroup-unreads)
6518         (gnus-message 3 "No more unread articles")
6519         nil)
6520        ;; Find the first unread article.
6521        (t
6522         (let ((data gnus-newsgroup-data))
6523           (while (and data
6524                       (and (not (and undownloaded
6525                                      (eq gnus-undownloaded-mark
6526                                          (gnus-data-mark (car data)))))
6527                            (if unseen
6528                                (or (not (memq
6529                                          (gnus-data-number (car data))
6530                                          gnus-newsgroup-unseen))
6531                                    (not (gnus-data-unread-p (car data))))
6532                              (not (gnus-data-unread-p (car data))))))
6533             (setq data (cdr data)))
6534           (when data
6535             (goto-char (gnus-data-pos (car data)))
6536             (gnus-data-number (car data))))))
6537     (gnus-summary-position-point)))
6538
6539 (defun gnus-summary-next-subject (n &optional unread dont-display)
6540   "Go to next N'th summary line.
6541 If N is negative, go to the previous N'th subject line.
6542 If UNREAD is non-nil, only unread articles are selected.
6543 The difference between N and the actual number of steps taken is
6544 returned."
6545   (interactive "p")
6546   (let ((backward (< n 0))
6547         (n (abs n)))
6548     (while (and (> n 0)
6549                 (if backward
6550                     (gnus-summary-find-prev unread)
6551                   (gnus-summary-find-next unread)))
6552       (unless (zerop (setq n (1- n)))
6553         (gnus-summary-show-thread)))
6554     (when (/= 0 n)
6555       (gnus-message 7 "No more%s articles"
6556                     (if unread " unread" "")))
6557     (unless dont-display
6558       (gnus-summary-recenter)
6559       (gnus-summary-position-point))
6560     n))
6561
6562 (defun gnus-summary-next-unread-subject (n)
6563   "Go to next N'th unread summary line."
6564   (interactive "p")
6565   (gnus-summary-next-subject n t))
6566
6567 (defun gnus-summary-prev-subject (n &optional unread)
6568   "Go to previous N'th summary line.
6569 If optional argument UNREAD is non-nil, only unread article is selected."
6570   (interactive "p")
6571   (gnus-summary-next-subject (- n) unread))
6572
6573 (defun gnus-summary-prev-unread-subject (n)
6574   "Go to previous N'th unread summary line."
6575   (interactive "p")
6576   (gnus-summary-next-subject (- n) t))
6577
6578 (defun gnus-summary-goto-subject (article &optional force silent)
6579   "Go the subject line of ARTICLE.
6580 If FORCE, also allow jumping to articles not currently shown."
6581   (interactive "nArticle number: ")
6582   (unless (numberp article)
6583     (error "Article %s is not a number" article))
6584   (let ((b (point))
6585         (data (gnus-data-find article)))
6586     ;; We read in the article if we have to.
6587     (and (not data)
6588          force
6589          (gnus-summary-insert-subject
6590           article
6591           (if (or (numberp force) (vectorp force)) force)
6592           t)
6593          (setq data (gnus-data-find article)))
6594     (goto-char b)
6595     (if (not data)
6596         (progn
6597           (unless silent
6598             (gnus-message 3 "Can't find article %d" article))
6599           nil)
6600       (let ((pt (gnus-data-pos data)))
6601         (goto-char pt)
6602         (gnus-summary-set-article-display-arrow pt))
6603       (gnus-summary-position-point)
6604       article)))
6605
6606 ;; Walking around summary lines with displaying articles.
6607
6608 (defun gnus-summary-expand-window (&optional arg)
6609   "Make the summary buffer take up the entire Emacs frame.
6610 Given a prefix, will force an `article' buffer configuration."
6611   (interactive "P")
6612   (if arg
6613       (gnus-configure-windows 'article 'force)
6614     (gnus-configure-windows 'summary 'force)))
6615
6616 (defun gnus-summary-display-article (article &optional all-header)
6617   "Display ARTICLE in article buffer."
6618   (when (gnus-buffer-live-p gnus-article-buffer)
6619     (with-current-buffer gnus-article-buffer
6620       (set-buffer-multibyte t)))
6621   (gnus-set-global-variables)
6622   (when (gnus-buffer-live-p gnus-article-buffer)
6623     (with-current-buffer gnus-article-buffer
6624       (setq gnus-article-charset gnus-newsgroup-charset)
6625       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
6626       (set-buffer-multibyte t)))
6627   (if (null article)
6628       nil
6629     (prog1
6630         (if gnus-summary-display-article-function
6631             (funcall gnus-summary-display-article-function article all-header)
6632           (gnus-article-prepare article all-header))
6633       (with-current-buffer gnus-article-buffer
6634         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6635              nil))
6636       (gnus-run-hooks 'gnus-select-article-hook)
6637       (when (and gnus-current-article
6638                  (not (zerop gnus-current-article)))
6639         (gnus-summary-goto-subject gnus-current-article))
6640       (gnus-summary-recenter)
6641       (when (and gnus-use-trees gnus-show-threads)
6642         (gnus-possibly-generate-tree article)
6643         (gnus-highlight-selected-tree article))
6644       ;; Successfully display article.
6645       (gnus-article-set-window-start
6646        (cdr (assq article gnus-newsgroup-bookmarks))))))
6647
6648 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6649   "Select the current article.
6650 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6651 non-nil, the article will be re-fetched even if it already present in
6652 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6653 be displayed."
6654   ;; Make sure we are in the summary buffer to work around bbdb bug.
6655   (unless (eq major-mode 'gnus-summary-mode)
6656     (set-buffer gnus-summary-buffer))
6657   (let ((article (or article (gnus-summary-article-number)))
6658         (all-headers (not (not all-headers))) ;Must be T or NIL.
6659         gnus-summary-display-article-function)
6660     (and (not pseudo)
6661          (gnus-summary-article-pseudo-p article)
6662          (error "This is a pseudo-article"))
6663     (save-excursion
6664       (set-buffer gnus-summary-buffer)
6665       (if (or (and gnus-single-article-buffer
6666                    (or (null gnus-current-article)
6667                        (null gnus-article-current)
6668                        (null (get-buffer gnus-article-buffer))
6669                        (not (eq article (cdr gnus-article-current)))
6670                        (not (equal (car gnus-article-current)
6671                                    gnus-newsgroup-name))))
6672               (and (not gnus-single-article-buffer)
6673                    (or (null gnus-current-article)
6674                        (not (eq gnus-current-article article))))
6675               force)
6676           ;; The requested article is different from the current article.
6677           (progn
6678             (gnus-summary-display-article article all-headers)
6679             (gnus-article-set-window-start
6680              (cdr (assq article gnus-newsgroup-bookmarks)))
6681             article)
6682         'old))))
6683
6684 (defun gnus-summary-force-verify-and-decrypt ()
6685   (interactive)
6686   (let ((mm-verify-option 'known)
6687         (mm-decrypt-option 'known))
6688     (gnus-summary-select-article nil 'force)))
6689
6690 (defun gnus-summary-set-current-mark (&optional current-mark)
6691   "Obsolete function."
6692   nil)
6693
6694 (defun gnus-summary-next-article (&optional unread subject backward push)
6695   "Select the next article.
6696 If UNREAD, only unread articles are selected.
6697 If SUBJECT, only articles with SUBJECT are selected.
6698 If BACKWARD, the previous article is selected instead of the next."
6699   (interactive "P")
6700   (cond
6701    ;; Is there such an article?
6702    ((and (gnus-summary-search-forward unread subject backward)
6703          (or (gnus-summary-display-article (gnus-summary-article-number))
6704              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6705     (gnus-summary-position-point))
6706    ;; If not, we try the first unread, if that is wanted.
6707    ((and subject
6708          gnus-auto-select-same
6709          (gnus-summary-first-unread-article))
6710     (gnus-summary-position-point)
6711     (gnus-message 6 "Wrapped"))
6712    ;; Try to get next/previous article not displayed in this group.
6713    ((and gnus-auto-extend-newsgroup
6714          (not unread) (not subject))
6715     (gnus-summary-goto-article
6716      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6717      nil (count-lines (point-min) (point))))
6718    ;; Go to next/previous group.
6719    (t
6720     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6721       (gnus-summary-jump-to-group gnus-newsgroup-name))
6722     (let ((cmd last-command-char)
6723           (point
6724            (save-excursion
6725              (set-buffer gnus-group-buffer)
6726              (point)))
6727           (group
6728            (if (eq gnus-keep-same-level 'best)
6729                (gnus-summary-best-group gnus-newsgroup-name)
6730              (gnus-summary-search-group backward gnus-keep-same-level))))
6731       ;; For some reason, the group window gets selected.  We change
6732       ;; it back.
6733       (select-window (get-buffer-window (current-buffer)))
6734       ;; Select next unread newsgroup automagically.
6735       (cond
6736        ((or (not gnus-auto-select-next)
6737             (not cmd))
6738         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6739        ((or (eq gnus-auto-select-next 'quietly)
6740             (and (eq gnus-auto-select-next 'slightly-quietly)
6741                  push)
6742             (and (eq gnus-auto-select-next 'almost-quietly)
6743                  (gnus-summary-last-article-p)))
6744         ;; Select quietly.
6745         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6746             (gnus-summary-exit)
6747           (gnus-message 7 "No more%s articles (%s)..."
6748                         (if unread " unread" "")
6749                         (if group (concat "selecting " group)
6750                           "exiting"))
6751           (gnus-summary-next-group nil group backward)))
6752        (t
6753         (when (gnus-key-press-event-p last-input-event)
6754           (gnus-summary-walk-group-buffer
6755            gnus-newsgroup-name cmd unread backward point))))))))
6756
6757 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6758   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6759                       (?\C-p (gnus-group-prev-unread-group 1))))
6760         (cursor-in-echo-area t)
6761         keve key group ended)
6762     (save-excursion
6763       (set-buffer gnus-group-buffer)
6764       (goto-char start)
6765       (setq group
6766             (if (eq gnus-keep-same-level 'best)
6767                 (gnus-summary-best-group gnus-newsgroup-name)
6768               (gnus-summary-search-group backward gnus-keep-same-level))))
6769     (while (not ended)
6770       (gnus-message
6771        5 "No more%s articles%s" (if unread " unread" "")
6772        (if (and group
6773                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6774            (format " (Type %s for %s [%s])"
6775                    (single-key-description cmd) group
6776                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6777          (format " (Type %s to exit %s)"
6778                  (single-key-description cmd)
6779                  gnus-newsgroup-name)))
6780       ;; Confirm auto selection.
6781       (setq key (car (setq keve (gnus-read-event-char))))
6782       (setq ended t)
6783       (cond
6784        ((assq key keystrokes)
6785         (let ((obuf (current-buffer)))
6786           (switch-to-buffer gnus-group-buffer)
6787           (when group
6788             (gnus-group-jump-to-group group))
6789           (eval (cadr (assq key keystrokes)))
6790           (setq group (gnus-group-group-name))
6791           (switch-to-buffer obuf))
6792         (setq ended nil))
6793        ((equal key cmd)
6794         (if (or (not group)
6795                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6796             (gnus-summary-exit)
6797           (gnus-summary-next-group nil group backward)))
6798        (t
6799         (push (cdr keve) unread-command-events))))))
6800
6801 (defun gnus-summary-next-unread-article ()
6802   "Select unread article after current one."
6803   (interactive)
6804   (gnus-summary-next-article
6805    (or (not (eq gnus-summary-goto-unread 'never))
6806        (gnus-summary-last-article-p (gnus-summary-article-number)))
6807    (and gnus-auto-select-same
6808         (gnus-summary-article-subject))))
6809
6810 (defun gnus-summary-prev-article (&optional unread subject)
6811   "Select the article after the current one.
6812 If UNREAD is non-nil, only unread articles are selected."
6813   (interactive "P")
6814   (gnus-summary-next-article unread subject t))
6815
6816 (defun gnus-summary-prev-unread-article ()
6817   "Select unread article before current one."
6818   (interactive)
6819   (gnus-summary-prev-article
6820    (or (not (eq gnus-summary-goto-unread 'never))
6821        (gnus-summary-first-article-p (gnus-summary-article-number)))
6822    (and gnus-auto-select-same
6823         (gnus-summary-article-subject))))
6824
6825 (defun gnus-summary-next-page (&optional lines circular)
6826   "Show next page of the selected article.
6827 If at the end of the current article, select the next article.
6828 LINES says how many lines should be scrolled up.
6829
6830 If CIRCULAR is non-nil, go to the start of the article instead of
6831 selecting the next article when reaching the end of the current
6832 article."
6833   (interactive "P")
6834   (setq gnus-summary-buffer (current-buffer))
6835   (gnus-set-global-variables)
6836   (let ((article (gnus-summary-article-number))
6837         (article-window (get-buffer-window gnus-article-buffer t))
6838         endp)
6839     ;; If the buffer is empty, we have no article.
6840     (unless article
6841       (error "No article to select"))
6842     (gnus-configure-windows 'article)
6843     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6844         (if (and (eq gnus-summary-goto-unread 'never)
6845                  (not (gnus-summary-last-article-p article)))
6846             (gnus-summary-next-article)
6847           (gnus-summary-next-unread-article))
6848       (if (or (null gnus-current-article)
6849               (null gnus-article-current)
6850               (/= article (cdr gnus-article-current))
6851               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6852           ;; Selected subject is different from current article's.
6853           (gnus-summary-display-article article)
6854         (when article-window
6855           (gnus-eval-in-buffer-window gnus-article-buffer
6856             (setq endp (gnus-article-next-page lines)))
6857           (when endp
6858             (cond (circular
6859                    (gnus-summary-beginning-of-article))
6860                   (lines
6861                    (gnus-message 3 "End of message"))
6862                   ((null lines)
6863                    (if (and (eq gnus-summary-goto-unread 'never)
6864                             (not (gnus-summary-last-article-p article)))
6865                        (gnus-summary-next-article)
6866                      (gnus-summary-next-unread-article))))))))
6867     (gnus-summary-recenter)
6868     (gnus-summary-position-point)))
6869
6870 (defun gnus-summary-prev-page (&optional lines move)
6871   "Show previous page of selected article.
6872 Argument LINES specifies lines to be scrolled down.
6873 If MOVE, move to the previous unread article if point is at
6874 the beginning of the buffer."
6875   (interactive "P")
6876   (let ((article (gnus-summary-article-number))
6877         (article-window (get-buffer-window gnus-article-buffer t))
6878         endp)
6879     (gnus-configure-windows 'article)
6880     (if (or (null gnus-current-article)
6881             (null gnus-article-current)
6882             (/= article (cdr gnus-article-current))
6883             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6884         ;; Selected subject is different from current article's.
6885         (gnus-summary-display-article article)
6886       (gnus-summary-recenter)
6887       (when article-window
6888         (gnus-eval-in-buffer-window gnus-article-buffer
6889           (setq endp (gnus-article-prev-page lines)))
6890         (when (and move endp)
6891           (cond (lines
6892                  (gnus-message 3 "Beginning of message"))
6893                 ((null lines)
6894                  (if (and (eq gnus-summary-goto-unread 'never)
6895                           (not (gnus-summary-first-article-p article)))
6896                      (gnus-summary-prev-article)
6897                    (gnus-summary-prev-unread-article))))))))
6898   (gnus-summary-position-point))
6899
6900 (defun gnus-summary-prev-page-or-article (&optional lines)
6901   "Show previous page of selected article.
6902 Argument LINES specifies lines to be scrolled down.
6903 If at the beginning of the article, go to the next article."
6904   (interactive "P")
6905   (gnus-summary-prev-page lines t))
6906
6907 (defun gnus-summary-scroll-up (lines)
6908   "Scroll up (or down) one line current article.
6909 Argument LINES specifies lines to be scrolled up (or down if negative)."
6910   (interactive "p")
6911   (gnus-configure-windows 'article)
6912   (gnus-summary-show-thread)
6913   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6914     (gnus-eval-in-buffer-window gnus-article-buffer
6915       (cond ((> lines 0)
6916              (when (gnus-article-next-page lines)
6917                (gnus-message 3 "End of message")))
6918             ((< lines 0)
6919              (gnus-article-prev-page (- lines))))))
6920   (gnus-summary-recenter)
6921   (gnus-summary-position-point))
6922
6923 (defun gnus-summary-scroll-down (lines)
6924   "Scroll down (or up) one line current article.
6925 Argument LINES specifies lines to be scrolled down (or up if negative)."
6926   (interactive "p")
6927   (gnus-summary-scroll-up (- lines)))
6928
6929 (defun gnus-summary-next-same-subject ()
6930   "Select next article which has the same subject as current one."
6931   (interactive)
6932   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6933
6934 (defun gnus-summary-prev-same-subject ()
6935   "Select previous article which has the same subject as current one."
6936   (interactive)
6937   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6938
6939 (defun gnus-summary-next-unread-same-subject ()
6940   "Select next unread article which has the same subject as current one."
6941   (interactive)
6942   (gnus-summary-next-article t (gnus-summary-article-subject)))
6943
6944 (defun gnus-summary-prev-unread-same-subject ()
6945   "Select previous unread article which has the same subject as current one."
6946   (interactive)
6947   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6948
6949 (defun gnus-summary-first-unread-article ()
6950   "Select the first unread article.
6951 Return nil if there are no unread articles."
6952   (interactive)
6953   (prog1
6954       (when (gnus-summary-first-subject t)
6955         (gnus-summary-show-thread)
6956         (gnus-summary-first-subject t)
6957         (gnus-summary-display-article (gnus-summary-article-number)))
6958     (gnus-summary-position-point)))
6959
6960 (defun gnus-summary-first-unread-subject ()
6961   "Place the point on the subject line of the first unread article.
6962 Return nil if there are no unread articles."
6963   (interactive)
6964   (prog1
6965       (when (gnus-summary-first-subject t)
6966         (gnus-summary-show-thread)
6967         (gnus-summary-first-subject t))
6968     (gnus-summary-position-point)))
6969
6970 (defun gnus-summary-first-unseen-subject ()
6971   "Place the point on the subject line of the first unseen article.
6972 Return nil if there are no unseen articles."
6973   (interactive)
6974   (prog1
6975       (when (gnus-summary-first-subject t t t)
6976         (gnus-summary-show-thread)
6977         (gnus-summary-first-subject t t t))
6978     (gnus-summary-position-point)))
6979
6980 (defun gnus-summary-first-unseen-or-unread-subject ()
6981   "Place the point on the subject line of the first unseen article.
6982 Return nil if there are no unseen articles."
6983   (interactive)
6984   (prog1
6985       (unless (when (gnus-summary-first-subject t t t)
6986                 (gnus-summary-show-thread)
6987                 (gnus-summary-first-subject t t t))
6988         (when (gnus-summary-first-subject t)
6989           (gnus-summary-show-thread)
6990           (gnus-summary-first-subject t)))
6991     (gnus-summary-position-point)))
6992
6993 (defun gnus-summary-first-article ()
6994   "Select the first article.
6995 Return nil if there are no articles."
6996   (interactive)
6997   (prog1
6998       (when (gnus-summary-first-subject)
6999         (gnus-summary-show-thread)
7000         (gnus-summary-first-subject)
7001         (gnus-summary-display-article (gnus-summary-article-number)))
7002     (gnus-summary-position-point)))
7003
7004 (defun gnus-summary-best-unread-article (&optional arg)
7005   "Select the unread article with the highest score.
7006 If given a prefix argument, select the next unread article that has a
7007 score higher than the default score."
7008   (interactive "P")
7009   (let ((article (if arg
7010                      (gnus-summary-better-unread-subject)
7011                    (gnus-summary-best-unread-subject))))
7012     (if article
7013         (gnus-summary-goto-article article)
7014       (error "No unread articles"))))
7015
7016 (defun gnus-summary-best-unread-subject ()
7017   "Select the unread subject with the highest score."
7018   (interactive)
7019   (let ((best -1000000)
7020         (data gnus-newsgroup-data)
7021         article score)
7022     (while data
7023       (and (gnus-data-unread-p (car data))
7024            (> (setq score
7025                     (gnus-summary-article-score (gnus-data-number (car data))))
7026               best)
7027            (setq best score
7028                  article (gnus-data-number (car data))))
7029       (setq data (cdr data)))
7030     (when article
7031       (gnus-summary-goto-subject article))
7032     (gnus-summary-position-point)
7033     article))
7034
7035 (defun gnus-summary-better-unread-subject ()
7036   "Select the first unread subject that has a score over the default score."
7037   (interactive)
7038   (let ((data gnus-newsgroup-data)
7039         article score)
7040     (while (and (setq article (gnus-data-number (car data)))
7041                 (or (gnus-data-read-p (car data))
7042                     (not (> (gnus-summary-article-score article)
7043                             gnus-summary-default-score))))
7044       (setq data (cdr data)))
7045     (when article
7046       (gnus-summary-goto-subject article))
7047     (gnus-summary-position-point)
7048     article))
7049
7050 (defun gnus-summary-last-subject ()
7051   "Go to the last displayed subject line in the group."
7052   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7053     (when article
7054       (gnus-summary-goto-subject article))))
7055
7056 (defun gnus-summary-goto-article (article &optional all-headers force)
7057   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7058 If ALL-HEADERS is non-nil, no header lines are hidden.
7059 If FORCE, go to the article even if it isn't displayed.  If FORCE
7060 is a number, it is the line the article is to be displayed on."
7061   (interactive
7062    (list
7063     (completing-read
7064      "Article number or Message-ID: "
7065      (mapcar (lambda (number) (list (int-to-string number)))
7066              gnus-newsgroup-limit))
7067     current-prefix-arg
7068     t))
7069   (prog1
7070       (if (and (stringp article)
7071                (string-match "@" article))
7072           (gnus-summary-refer-article article)
7073         (when (stringp article)
7074           (setq article (string-to-number article)))
7075         (if (gnus-summary-goto-subject article force)
7076             (gnus-summary-display-article article all-headers)
7077           (gnus-message 4 "Couldn't go to article %s" article) nil))
7078     (gnus-summary-position-point)))
7079
7080 (defun gnus-summary-goto-last-article ()
7081   "Go to the previously read article."
7082   (interactive)
7083   (prog1
7084       (when gnus-last-article
7085         (gnus-summary-goto-article gnus-last-article nil t))
7086     (gnus-summary-position-point)))
7087
7088 (defun gnus-summary-pop-article (number)
7089   "Pop one article off the history and go to the previous.
7090 NUMBER articles will be popped off."
7091   (interactive "p")
7092   (let (to)
7093     (setq gnus-newsgroup-history
7094           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7095     (if to
7096         (gnus-summary-goto-article (car to) nil t)
7097       (error "Article history empty")))
7098   (gnus-summary-position-point))
7099
7100 ;; Summary commands and functions for limiting the summary buffer.
7101
7102 (defun gnus-summary-limit-to-articles (n)
7103   "Limit the summary buffer to the next N articles.
7104 If not given a prefix, use the process marked articles instead."
7105   (interactive "P")
7106   (prog1
7107       (let ((articles (gnus-summary-work-articles n)))
7108         (setq gnus-newsgroup-processable nil)
7109         (gnus-summary-limit articles))
7110     (gnus-summary-position-point)))
7111
7112 (defun gnus-summary-pop-limit (&optional total)
7113   "Restore the previous limit.
7114 If given a prefix, remove all limits."
7115   (interactive "P")
7116   (when total
7117     (setq gnus-newsgroup-limits
7118           (list (mapcar (lambda (h) (mail-header-number h))
7119                         gnus-newsgroup-headers))))
7120   (unless gnus-newsgroup-limits
7121     (error "No limit to pop"))
7122   (prog1
7123       (gnus-summary-limit nil 'pop)
7124     (gnus-summary-position-point)))
7125
7126 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7127   "Limit the summary buffer to articles that have subjects that match a regexp.
7128 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7129   (interactive
7130    (list (read-string (if current-prefix-arg
7131                           "Exclude subject (regexp): "
7132                         "Limit to subject (regexp): "))
7133          nil current-prefix-arg))
7134   (unless header
7135     (setq header "subject"))
7136   (when (not (equal "" subject))
7137     (prog1
7138         (let ((articles (gnus-summary-find-matching
7139                          (or header "subject") subject 'all nil nil
7140                          not-matching)))
7141           (unless articles
7142             (error "Found no matches for \"%s\"" subject))
7143           (gnus-summary-limit articles))
7144       (gnus-summary-position-point))))
7145
7146 (defun gnus-summary-limit-to-author (from &optional not-matching)
7147   "Limit the summary buffer to articles that have authors that match a regexp.
7148 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7149   (interactive
7150    (list (read-string (if current-prefix-arg
7151                           "Exclude author (regexp): "
7152                         "Limit to author (regexp): "))
7153          current-prefix-arg))
7154   (gnus-summary-limit-to-subject from "from" not-matching))
7155
7156 (defun gnus-summary-limit-to-age (age &optional younger-p)
7157   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7158 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7159 articles that are younger than AGE days."
7160   (interactive
7161    (let ((younger current-prefix-arg)
7162          (days-got nil)
7163          days)
7164      (while (not days-got)
7165        (setq days (if younger
7166                       (read-string "Limit to articles within (in days): ")
7167                     (read-string "Limit to articles older than (in days): ")))
7168        (when (> (length days) 0)
7169          (setq days (read days)))
7170        (if (numberp days)
7171            (progn
7172              (setq days-got t)
7173              (if (< days 0)
7174                  (progn
7175                    (setq younger (not younger))
7176                    (setq days (* days -1)))))
7177          (message "Please enter a number.")
7178          (sleep-for 1)))
7179      (list days younger)))
7180   (prog1
7181       (let ((data gnus-newsgroup-data)
7182             (cutoff (days-to-time age))
7183             articles d date is-younger)
7184         (while (setq d (pop data))
7185           (when (and (vectorp (gnus-data-header d))
7186                      (setq date (mail-header-date (gnus-data-header d))))
7187             (setq is-younger (time-less-p
7188                               (time-since (condition-case ()
7189                                               (date-to-time date)
7190                                             (error '(0 0))))
7191                               cutoff))
7192             (when (if younger-p
7193                       is-younger
7194                     (not is-younger))
7195               (push (gnus-data-number d) articles))))
7196         (gnus-summary-limit (nreverse articles)))
7197     (gnus-summary-position-point)))
7198
7199 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7200   "Limit the summary buffer to articles that match an 'extra' header."
7201   (interactive
7202    (let ((header
7203           (intern
7204            (gnus-completing-read-with-default
7205             (symbol-name (car gnus-extra-headers))
7206             (if current-prefix-arg
7207                 "Exclude extra header:"
7208               "Limit extra header:")
7209             (mapcar (lambda (x)
7210                       (cons (symbol-name x) x))
7211                     gnus-extra-headers)
7212             nil
7213             t))))
7214      (list header
7215            (read-string (format "%s header %s (regexp): "
7216                                 (if current-prefix-arg "Exclude" "Limit to")
7217                                 header))
7218            current-prefix-arg)))
7219   (when (not (equal "" regexp))
7220     (prog1
7221         (let ((articles (gnus-summary-find-matching
7222                          (cons 'extra header) regexp 'all nil nil
7223                          not-matching)))
7224           (unless articles
7225             (error "Found no matches for \"%s\"" regexp))
7226           (gnus-summary-limit articles))
7227       (gnus-summary-position-point))))
7228
7229 (defun gnus-summary-limit-to-display-predicate ()
7230   "Limit the summary buffer to the predicated in the `display' group parameter."
7231   (interactive)
7232   (unless gnus-newsgroup-display
7233     (error "There is no `display' group parameter"))
7234   (let (articles)
7235     (dolist (number gnus-newsgroup-articles)
7236       (when (funcall gnus-newsgroup-display)
7237         (push number articles)))
7238     (gnus-summary-limit articles))
7239   (gnus-summary-position-point))
7240
7241 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7242 (make-obsolete
7243  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7244
7245 (defun gnus-summary-limit-to-unread (&optional all)
7246   "Limit the summary buffer to articles that are not marked as read.
7247 If ALL is non-nil, limit strictly to unread articles."
7248   (interactive "P")
7249   (if all
7250       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7251     (gnus-summary-limit-to-marks
7252      ;; Concat all the marks that say that an article is read and have
7253      ;; those removed.
7254      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7255            gnus-killed-mark gnus-kill-file-mark
7256            gnus-low-score-mark gnus-expirable-mark
7257            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7258            gnus-duplicate-mark gnus-souped-mark)
7259      'reverse)))
7260
7261 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7262 (make-obsolete 'gnus-summary-delete-marked-with
7263                'gnus-summary-limit-exlude-marks)
7264
7265 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7266   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7267 If REVERSE, limit the summary buffer to articles that are marked
7268 with MARKS.  MARKS can either be a string of marks or a list of marks.
7269 Returns how many articles were removed."
7270   (interactive "sMarks: ")
7271   (gnus-summary-limit-to-marks marks t))
7272
7273 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7274   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7275 If REVERSE (the prefix), limit the summary buffer to articles that are
7276 not marked with MARKS.  MARKS can either be a string of marks or a
7277 list of marks.
7278 Returns how many articles were removed."
7279   (interactive "sMarks: \nP")
7280   (prog1
7281       (let ((data gnus-newsgroup-data)
7282             (marks (if (listp marks) marks
7283                      (append marks nil))) ; Transform to list.
7284             articles)
7285         (while data
7286           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7287                   (memq (gnus-data-mark (car data)) marks))
7288             (push (gnus-data-number (car data)) articles))
7289           (setq data (cdr data)))
7290         (gnus-summary-limit articles))
7291     (gnus-summary-position-point)))
7292
7293 (defun gnus-summary-limit-to-score (score)
7294   "Limit to articles with score at or above SCORE."
7295   (interactive "NLimit to articles with score of at least: ")
7296   (let ((data gnus-newsgroup-data)
7297         articles)
7298     (while data
7299       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7300                 score)
7301         (push (gnus-data-number (car data)) articles))
7302       (setq data (cdr data)))
7303     (prog1
7304         (gnus-summary-limit articles)
7305       (gnus-summary-position-point))))
7306
7307 (defun gnus-summary-limit-include-thread (id)
7308   "Display all the hidden articles that is in the thread with ID in it.
7309 When called interactively, ID is the Message-ID of the current
7310 article."
7311   (interactive (list (mail-header-id (gnus-summary-article-header))))
7312   (let ((articles (gnus-articles-in-thread
7313                    (gnus-id-to-thread (gnus-root-id id)))))
7314     (prog1
7315         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7316       (gnus-summary-limit-include-matching-articles
7317        "subject"
7318        (regexp-quote (gnus-simplify-subject-re
7319                       (mail-header-subject (gnus-id-to-header id)))))
7320       (gnus-summary-position-point))))
7321
7322 (defun gnus-summary-limit-include-matching-articles (header regexp)
7323   "Display all the hidden articles that have HEADERs that match REGEXP."
7324   (interactive (list (read-string "Match on header: ")
7325                      (read-string "Regexp: ")))
7326   (let ((articles (gnus-find-matching-articles header regexp)))
7327     (prog1
7328         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7329       (gnus-summary-position-point))))
7330
7331 (defun gnus-summary-limit-include-dormant ()
7332   "Display all the hidden articles that are marked as dormant.
7333 Note that this command only works on a subset of the articles currently
7334 fetched for this group."
7335   (interactive)
7336   (unless gnus-newsgroup-dormant
7337     (error "There are no dormant articles in this group"))
7338   (prog1
7339       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7340     (gnus-summary-position-point)))
7341
7342 (defun gnus-summary-limit-exclude-dormant ()
7343   "Hide all dormant articles."
7344   (interactive)
7345   (prog1
7346       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7347     (gnus-summary-position-point)))
7348
7349 (defun gnus-summary-limit-exclude-childless-dormant ()
7350   "Hide all dormant articles that have no children."
7351   (interactive)
7352   (let ((data (gnus-data-list t))
7353         articles d children)
7354     ;; Find all articles that are either not dormant or have
7355     ;; children.
7356     (while (setq d (pop data))
7357       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7358                 (and (setq children
7359                            (gnus-article-children (gnus-data-number d)))
7360                      (let (found)
7361                        (while children
7362                          (when (memq (car children) articles)
7363                            (setq children nil
7364                                  found t))
7365                          (pop children))
7366                        found)))
7367         (push (gnus-data-number d) articles)))
7368     ;; Do the limiting.
7369     (prog1
7370         (gnus-summary-limit articles)
7371       (gnus-summary-position-point))))
7372
7373 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7374   "Mark all unread excluded articles as read.
7375 If ALL, mark even excluded ticked and dormants as read."
7376   (interactive "P")
7377   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7378   (let ((articles (gnus-sorted-ndifference
7379                    (sort
7380                     (mapcar (lambda (h) (mail-header-number h))
7381                             gnus-newsgroup-headers)
7382                     '<)
7383                    gnus-newsgroup-limit))
7384         article)
7385     (setq gnus-newsgroup-unreads
7386           (gnus-sorted-intersection gnus-newsgroup-unreads
7387                                     gnus-newsgroup-limit))
7388     (if all
7389         (setq gnus-newsgroup-dormant nil
7390               gnus-newsgroup-marked nil
7391               gnus-newsgroup-reads
7392               (nconc
7393                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7394                gnus-newsgroup-reads))
7395       (while (setq article (pop articles))
7396         (unless (or (memq article gnus-newsgroup-dormant)
7397                     (memq article gnus-newsgroup-marked))
7398           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7399
7400 (defun gnus-summary-limit (articles &optional pop)
7401   (if pop
7402       ;; We pop the previous limit off the stack and use that.
7403       (setq articles (car gnus-newsgroup-limits)
7404             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7405     ;; We use the new limit, so we push the old limit on the stack.
7406     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7407   ;; Set the limit.
7408   (setq gnus-newsgroup-limit articles)
7409   (let ((total (length gnus-newsgroup-data))
7410         (data (gnus-data-find-list (gnus-summary-article-number)))
7411         (gnus-summary-mark-below nil)   ; Inhibit this.
7412         found)
7413     ;; This will do all the work of generating the new summary buffer
7414     ;; according to the new limit.
7415     (gnus-summary-prepare)
7416     ;; Hide any threads, possibly.
7417     (gnus-summary-maybe-hide-threads)
7418     ;; Try to return to the article you were at, or one in the
7419     ;; neighborhood.
7420     (when data
7421       ;; We try to find some article after the current one.
7422       (while data
7423         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7424           (setq data nil
7425                 found t))
7426         (setq data (cdr data))))
7427     (unless found
7428       ;; If there is no data, that means that we were after the last
7429       ;; article.  The same goes when we can't find any articles
7430       ;; after the current one.
7431       (goto-char (point-max))
7432       (gnus-summary-find-prev))
7433     (gnus-set-mode-line 'summary)
7434     ;; We return how many articles were removed from the summary
7435     ;; buffer as a result of the new limit.
7436     (- total (length gnus-newsgroup-data))))
7437
7438 (defsubst gnus-invisible-cut-children (threads)
7439   (let ((num 0))
7440     (while threads
7441       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7442         (incf num))
7443       (pop threads))
7444     (< num 2)))
7445
7446 (defsubst gnus-cut-thread (thread)
7447   "Go forwards in the thread until we find an article that we want to display."
7448   (when (or (eq gnus-fetch-old-headers 'some)
7449             (eq gnus-fetch-old-headers 'invisible)
7450             (numberp gnus-fetch-old-headers)
7451             (eq gnus-build-sparse-threads 'some)
7452             (eq gnus-build-sparse-threads 'more))
7453     ;; Deal with old-fetched headers and sparse threads.
7454     (while (and
7455             thread
7456             (or
7457              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7458              (gnus-summary-article-ancient-p
7459               (mail-header-number (car thread))))
7460             (if (or (<= (length (cdr thread)) 1)
7461                     (eq gnus-fetch-old-headers 'invisible))
7462                 (setq gnus-newsgroup-limit
7463                       (delq (mail-header-number (car thread))
7464                             gnus-newsgroup-limit)
7465                       thread (cadr thread))
7466               (when (gnus-invisible-cut-children (cdr thread))
7467                 (let ((th (cdr thread)))
7468                   (while th
7469                     (if (memq (mail-header-number (caar th))
7470                               gnus-newsgroup-limit)
7471                         (setq thread (car th)
7472                               th nil)
7473                       (setq th (cdr th))))))))))
7474   thread)
7475
7476 (defun gnus-cut-threads (threads)
7477   "Cut off all uninteresting articles from the beginning of threads."
7478   (when (or (eq gnus-fetch-old-headers 'some)
7479             (eq gnus-fetch-old-headers 'invisible)
7480             (numberp gnus-fetch-old-headers)
7481             (eq gnus-build-sparse-threads 'some)
7482             (eq gnus-build-sparse-threads 'more))
7483     (let ((th threads))
7484       (while th
7485         (setcar th (gnus-cut-thread (car th)))
7486         (setq th (cdr th)))))
7487   ;; Remove nixed out threads.
7488   (delq nil threads))
7489
7490 (defun gnus-summary-initial-limit (&optional show-if-empty)
7491   "Figure out what the initial limit is supposed to be on group entry.
7492 This entails weeding out unwanted dormants, low-scored articles,
7493 fetch-old-headers verbiage, and so on."
7494   ;; Most groups have nothing to remove.
7495   (if (or gnus-inhibit-limiting
7496           (and (null gnus-newsgroup-dormant)
7497                (eq gnus-newsgroup-display 'gnus-not-ignore)
7498                (not (eq gnus-fetch-old-headers 'some))
7499                (not (numberp gnus-fetch-old-headers))
7500                (not (eq gnus-fetch-old-headers 'invisible))
7501                (null gnus-summary-expunge-below)
7502                (not (eq gnus-build-sparse-threads 'some))
7503                (not (eq gnus-build-sparse-threads 'more))
7504                (null gnus-thread-expunge-below)
7505                (not gnus-use-nocem)))
7506       ()                                ; Do nothing.
7507     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7508     (setq gnus-newsgroup-limit nil)
7509     (mapatoms
7510      (lambda (node)
7511        (unless (car (symbol-value node))
7512          ;; These threads have no parents -- they are roots.
7513          (let ((nodes (cdr (symbol-value node)))
7514                thread)
7515            (while nodes
7516              (if (and gnus-thread-expunge-below
7517                       (< (gnus-thread-total-score (car nodes))
7518                          gnus-thread-expunge-below))
7519                  (gnus-expunge-thread (pop nodes))
7520                (setq thread (pop nodes))
7521                (gnus-summary-limit-children thread))))))
7522      gnus-newsgroup-dependencies)
7523     ;; If this limitation resulted in an empty group, we might
7524     ;; pop the previous limit and use it instead.
7525     (when (and (not gnus-newsgroup-limit)
7526                show-if-empty)
7527       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7528     gnus-newsgroup-limit))
7529
7530 (defun gnus-summary-limit-children (thread)
7531   "Return 1 if this subthread is visible and 0 if it is not."
7532   ;; First we get the number of visible children to this thread.  This
7533   ;; is done by recursing down the thread using this function, so this
7534   ;; will really go down to a leaf article first, before slowly
7535   ;; working its way up towards the root.
7536   (when thread
7537     (let ((children
7538            (if (cdr thread)
7539                (apply '+ (mapcar 'gnus-summary-limit-children
7540                                  (cdr thread)))
7541              0))
7542           (number (mail-header-number (car thread)))
7543           score)
7544       (if (and
7545            (not (memq number gnus-newsgroup-marked))
7546            (or
7547             ;; If this article is dormant and has absolutely no visible
7548             ;; children, then this article isn't visible.
7549             (and (memq number gnus-newsgroup-dormant)
7550                  (zerop children))
7551             ;; If this is "fetch-old-headered" and there is no
7552             ;; visible children, then we don't want this article.
7553             (and (or (eq gnus-fetch-old-headers 'some)
7554                      (numberp gnus-fetch-old-headers))
7555                  (gnus-summary-article-ancient-p number)
7556                  (zerop children))
7557             ;; If this is "fetch-old-headered" and `invisible', then
7558             ;; we don't want this article.
7559             (and (eq gnus-fetch-old-headers 'invisible)
7560                  (gnus-summary-article-ancient-p number))
7561             ;; If this is a sparsely inserted article with no children,
7562             ;; we don't want it.
7563             (and (eq gnus-build-sparse-threads 'some)
7564                  (gnus-summary-article-sparse-p number)
7565                  (zerop children))
7566             ;; If we use expunging, and this article is really
7567             ;; low-scored, then we don't want this article.
7568             (when (and gnus-summary-expunge-below
7569                        (< (setq score
7570                                 (or (cdr (assq number gnus-newsgroup-scored))
7571                                     gnus-summary-default-score))
7572                           gnus-summary-expunge-below))
7573               ;; We increase the expunge-tally here, but that has
7574               ;; nothing to do with the limits, really.
7575               (incf gnus-newsgroup-expunged-tally)
7576               ;; We also mark as read here, if that's wanted.
7577               (when (and gnus-summary-mark-below
7578                          (< score gnus-summary-mark-below))
7579                 (setq gnus-newsgroup-unreads
7580                       (delq number gnus-newsgroup-unreads))
7581                 (if gnus-newsgroup-auto-expire
7582                     (push number gnus-newsgroup-expirable)
7583                   (push (cons number gnus-low-score-mark)
7584                         gnus-newsgroup-reads)))
7585               t)
7586             ;; Do the `display' group parameter.
7587             (and gnus-newsgroup-display
7588                  (not (funcall gnus-newsgroup-display)))
7589             ;; Check NoCeM things.
7590             (if (and gnus-use-nocem
7591                      (gnus-nocem-unwanted-article-p
7592                       (mail-header-id (car thread))))
7593                 (progn
7594                   (setq gnus-newsgroup-unreads
7595                         (delq number gnus-newsgroup-unreads))
7596                   t))))
7597           ;; Nope, invisible article.
7598           0
7599         ;; Ok, this article is to be visible, so we add it to the limit
7600         ;; and return 1.
7601         (push number gnus-newsgroup-limit)
7602         1))))
7603
7604 (defun gnus-expunge-thread (thread)
7605   "Mark all articles in THREAD as read."
7606   (let* ((number (mail-header-number (car thread))))
7607     (incf gnus-newsgroup-expunged-tally)
7608     ;; We also mark as read here, if that's wanted.
7609     (setq gnus-newsgroup-unreads
7610           (delq number gnus-newsgroup-unreads))
7611     (if gnus-newsgroup-auto-expire
7612         (push number gnus-newsgroup-expirable)
7613       (push (cons number gnus-low-score-mark)
7614             gnus-newsgroup-reads)))
7615   ;; Go recursively through all subthreads.
7616   (mapcar 'gnus-expunge-thread (cdr thread)))
7617
7618 ;; Summary article oriented commands
7619
7620 (defun gnus-summary-refer-parent-article (n)
7621   "Refer parent article N times.
7622 If N is negative, go to ancestor -N instead.
7623 The difference between N and the number of articles fetched is returned."
7624   (interactive "p")
7625   (let ((skip 1)
7626         error header ref)
7627     (when (not (natnump n))
7628       (setq skip (abs n)
7629             n 1))
7630     (while (and (> n 0)
7631                 (not error))
7632       (setq header (gnus-summary-article-header))
7633       (if (and (eq (mail-header-number header)
7634                    (cdr gnus-article-current))
7635                (equal gnus-newsgroup-name
7636                       (car gnus-article-current)))
7637           ;; If we try to find the parent of the currently
7638           ;; displayed article, then we take a look at the actual
7639           ;; References header, since this is slightly more
7640           ;; reliable than the References field we got from the
7641           ;; server.
7642           (save-excursion
7643             (set-buffer gnus-original-article-buffer)
7644             (nnheader-narrow-to-headers)
7645             (unless (setq ref (message-fetch-field "references"))
7646               (setq ref (message-fetch-field "in-reply-to")))
7647             (widen))
7648         (setq ref
7649               ;; It's not the current article, so we take a bet on
7650               ;; the value we got from the server.
7651               (mail-header-references header)))
7652       (if (and ref
7653                (not (equal ref "")))
7654           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7655             (gnus-message 1 "Couldn't find parent"))
7656         (gnus-message 1 "No references in article %d"
7657                       (gnus-summary-article-number))
7658         (setq error t))
7659       (decf n))
7660     (gnus-summary-position-point)
7661     n))
7662
7663 (defun gnus-summary-refer-references ()
7664   "Fetch all articles mentioned in the References header.
7665 Return the number of articles fetched."
7666   (interactive)
7667   (let ((ref (mail-header-references (gnus-summary-article-header)))
7668         (current (gnus-summary-article-number))
7669         (n 0))
7670     (if (or (not ref)
7671             (equal ref ""))
7672         (error "No References in the current article")
7673       ;; For each Message-ID in the References header...
7674       (while (string-match "<[^>]*>" ref)
7675         (incf n)
7676         ;; ... fetch that article.
7677         (gnus-summary-refer-article
7678          (prog1 (match-string 0 ref)
7679            (setq ref (substring ref (match-end 0))))))
7680       (gnus-summary-goto-subject current)
7681       (gnus-summary-position-point)
7682       n)))
7683
7684 (defun gnus-summary-refer-thread (&optional limit)
7685   "Fetch all articles in the current thread.
7686 If LIMIT (the numerical prefix), fetch that many old headers instead
7687 of what's specified by the `gnus-refer-thread-limit' variable."
7688   (interactive "P")
7689   (let ((id (mail-header-id (gnus-summary-article-header)))
7690         (limit (if limit (prefix-numeric-value limit)
7691                  gnus-refer-thread-limit)))
7692     ;; We want to fetch LIMIT *old* headers, but we also have to
7693     ;; re-fetch all the headers in the current buffer, because many of
7694     ;; them may be undisplayed.  So we adjust LIMIT.
7695     (when (numberp limit)
7696       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7697     (unless (eq gnus-fetch-old-headers 'invisible)
7698       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7699       ;; Retrieve the headers and read them in.
7700       (if (eq (gnus-retrieve-headers
7701                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7702               'nov)
7703           (gnus-build-all-threads)
7704         (error "Can't fetch thread from backends that don't support NOV"))
7705       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7706     (gnus-summary-limit-include-thread id)))
7707
7708 (defun gnus-summary-refer-article (message-id)
7709   "Fetch an article specified by MESSAGE-ID."
7710   (interactive "sMessage-ID: ")
7711   (when (and (stringp message-id)
7712              (not (zerop (length message-id))))
7713     ;; Construct the correct Message-ID if necessary.
7714     ;; Suggested by tale@pawl.rpi.edu.
7715     (unless (string-match "^<" message-id)
7716       (setq message-id (concat "<" message-id)))
7717     (unless (string-match ">$" message-id)
7718       (setq message-id (concat message-id ">")))
7719     (let* ((header (gnus-id-to-header message-id))
7720            (sparse (and header
7721                         (gnus-summary-article-sparse-p
7722                          (mail-header-number header))
7723                         (memq (mail-header-number header)
7724                               gnus-newsgroup-limit)))
7725            number)
7726       (cond
7727        ;; If the article is present in the buffer we just go to it.
7728        ((and header
7729              (or (not (gnus-summary-article-sparse-p
7730                        (mail-header-number header)))
7731                  sparse))
7732         (prog1
7733             (gnus-summary-goto-article
7734              (mail-header-number header) nil t)
7735           (when sparse
7736             (gnus-summary-update-article (mail-header-number header)))))
7737        (t
7738         ;; We fetch the article.
7739         (catch 'found
7740           (dolist (gnus-override-method (gnus-refer-article-methods))
7741             (gnus-check-server gnus-override-method)
7742             ;; Fetch the header, and display the article.
7743             (when (setq number (gnus-summary-insert-subject message-id))
7744               (gnus-summary-select-article nil nil nil number)
7745               (throw 'found t)))
7746           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7747
7748 (defun gnus-refer-article-methods ()
7749   "Return a list of referrable methods."
7750   (cond
7751    ;; No method, so we default to current and native.
7752    ((null gnus-refer-article-method)
7753     (list gnus-current-select-method gnus-select-method))
7754    ;; Current.
7755    ((eq 'current gnus-refer-article-method)
7756     (list gnus-current-select-method))
7757    ;; List of select methods.
7758    ((not (and (symbolp (car gnus-refer-article-method))
7759               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7760     (let (out)
7761       (dolist (method gnus-refer-article-method)
7762         (push (if (eq 'current method)
7763                   gnus-current-select-method
7764                 method)
7765               out))
7766       (nreverse out)))
7767    ;; One single select method.
7768    (t
7769     (list gnus-refer-article-method))))
7770
7771 (defun gnus-summary-edit-parameters ()
7772   "Edit the group parameters of the current group."
7773   (interactive)
7774   (gnus-group-edit-group gnus-newsgroup-name 'params))
7775
7776 (defun gnus-summary-customize-parameters ()
7777   "Customize the group parameters of the current group."
7778   (interactive)
7779   (gnus-group-customize gnus-newsgroup-name))
7780
7781 (defun gnus-summary-enter-digest-group (&optional force)
7782   "Enter an nndoc group based on the current article.
7783 If FORCE, force a digest interpretation.  If not, try
7784 to guess what the document format is."
7785   (interactive "P")
7786   (let ((conf gnus-current-window-configuration))
7787     (save-excursion
7788       (gnus-summary-select-article))
7789     (setq gnus-current-window-configuration conf)
7790     (let* ((name (format "%s-%d"
7791                          (gnus-group-prefixed-name
7792                           gnus-newsgroup-name (list 'nndoc ""))
7793                          (save-excursion
7794                            (set-buffer gnus-summary-buffer)
7795                            gnus-current-article)))
7796            (ogroup gnus-newsgroup-name)
7797            (params (append (gnus-info-params (gnus-get-info ogroup))
7798                            (list (cons 'to-group ogroup))
7799                            (list (cons 'save-article-group ogroup))))
7800            (case-fold-search t)
7801            (buf (current-buffer))
7802            dig to-address)
7803       (save-excursion
7804         (set-buffer gnus-original-article-buffer)
7805         ;; Have the digest group inherit the main mail address of
7806         ;; the parent article.
7807         (when (setq to-address (or (message-fetch-field "reply-to")
7808                                    (message-fetch-field "from")))
7809           (setq params (append
7810                         (list (cons 'to-address
7811                                     (funcall gnus-decode-encoded-word-function
7812                                              to-address))))))
7813         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7814         (insert-buffer-substring gnus-original-article-buffer)
7815         ;; Remove lines that may lead nndoc to misinterpret the
7816         ;; document type.
7817         (narrow-to-region
7818          (goto-char (point-min))
7819          (or (search-forward "\n\n" nil t) (point)))
7820         (goto-char (point-min))
7821         (delete-matching-lines "^Path:\\|^From ")
7822         (widen))
7823       (unwind-protect
7824           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7825                     (gnus-newsgroup-ephemeral-ignored-charsets
7826                      gnus-newsgroup-ignored-charsets))
7827                 (gnus-group-read-ephemeral-group
7828                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7829                               (nndoc-article-type
7830                                ,(if force 'mbox 'guess)))
7831                  t nil nil nil
7832                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
7833                                                         "ADAPT")))))
7834               ;; Make all postings to this group go to the parent group.
7835               (nconc (gnus-info-params (gnus-get-info name))
7836                      params)
7837             ;; Couldn't select this doc group.
7838             (switch-to-buffer buf)
7839             (gnus-set-global-variables)
7840             (gnus-configure-windows 'summary)
7841             (gnus-message 3 "Article couldn't be entered?"))
7842         (kill-buffer dig)))))
7843
7844 (defun gnus-summary-read-document (n)
7845   "Open a new group based on the current article(s).
7846 This will allow you to read digests and other similar
7847 documents as newsgroups.
7848 Obeys the standard process/prefix convention."
7849   (interactive "P")
7850   (let* ((articles (gnus-summary-work-articles n))
7851          (ogroup gnus-newsgroup-name)
7852          (params (append (gnus-info-params (gnus-get-info ogroup))
7853                          (list (cons 'to-group ogroup))))
7854          article group egroup groups vgroup)
7855     (while (setq article (pop articles))
7856       (setq group (format "%s-%d" gnus-newsgroup-name article))
7857       (gnus-summary-remove-process-mark article)
7858       (when (gnus-summary-display-article article)
7859         (save-excursion
7860           (with-temp-buffer
7861             (insert-buffer-substring gnus-original-article-buffer)
7862             ;; Remove some headers that may lead nndoc to make
7863             ;; the wrong guess.
7864             (message-narrow-to-head)
7865             (goto-char (point-min))
7866             (delete-matching-lines "^\\(Path\\):\\|^From ")
7867             (widen)
7868             (if (setq egroup
7869                       (gnus-group-read-ephemeral-group
7870                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7871                                      (nndoc-article-type guess))
7872                        t nil t))
7873                 (progn
7874                   ;; Make all postings to this group go to the parent group.
7875                   (nconc (gnus-info-params (gnus-get-info egroup))
7876                          params)
7877                   (push egroup groups))
7878               ;; Couldn't select this doc group.
7879               (gnus-error 3 "Article couldn't be entered"))))))
7880     ;; Now we have selected all the documents.
7881     (cond
7882      ((not groups)
7883       (error "None of the articles could be interpreted as documents"))
7884      ((gnus-group-read-ephemeral-group
7885        (setq vgroup (format
7886                      "nnvirtual:%s-%s" gnus-newsgroup-name
7887                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7888        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7889        t
7890        (cons (current-buffer) 'summary)))
7891      (t
7892       (error "Couldn't select virtual nndoc group")))))
7893
7894 (defun gnus-summary-isearch-article (&optional regexp-p)
7895   "Do incremental search forward on the current article.
7896 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7897   (interactive "P")
7898   (let* ((gnus-inhibit-treatment t)
7899          (old (gnus-summary-select-article)))
7900     (gnus-configure-windows 'article)
7901     (gnus-eval-in-buffer-window gnus-article-buffer
7902       (save-restriction
7903         (widen)
7904         (when (eq 'old old)
7905           (gnus-article-show-all-headers))
7906         (goto-char (point-min))
7907         (isearch-forward regexp-p)))))
7908
7909 (defun gnus-summary-search-article-forward (regexp &optional backward)
7910   "Search for an article containing REGEXP forward.
7911 If BACKWARD, search backward instead."
7912   (interactive
7913    (list (read-string
7914           (format "Search article %s (regexp%s): "
7915                   (if current-prefix-arg "backward" "forward")
7916                   (if gnus-last-search-regexp
7917                       (concat ", default " gnus-last-search-regexp)
7918                     "")))
7919          current-prefix-arg))
7920   (if (string-equal regexp "")
7921       (setq regexp (or gnus-last-search-regexp ""))
7922     (setq gnus-last-search-regexp regexp)
7923     (setq gnus-article-before-search gnus-current-article))
7924   ;; Intentionally set gnus-last-article.
7925   (setq gnus-last-article gnus-article-before-search)
7926   (let ((gnus-last-article gnus-last-article))
7927     (if (gnus-summary-search-article regexp backward)
7928         (gnus-summary-show-thread)
7929       (error "Search failed: \"%s\"" regexp))))
7930
7931 (defun gnus-summary-search-article-backward (regexp)
7932   "Search for an article containing REGEXP backward."
7933   (interactive
7934    (list (read-string
7935           (format "Search article backward (regexp%s): "
7936                   (if gnus-last-search-regexp
7937                       (concat ", default " gnus-last-search-regexp)
7938                     "")))))
7939   (gnus-summary-search-article-forward regexp 'backward))
7940
7941 (eval-when-compile
7942   (defmacro gnus-summary-search-article-position-point (regexp backward)
7943     "Dehighlight the last matched text and goto the beginning position."
7944     (` (if (and gnus-summary-search-article-matched-data
7945                 (let ((text (caddr gnus-summary-search-article-matched-data))
7946                       (inhibit-read-only t)
7947                       buffer-read-only)
7948                   (delete-region
7949                    (goto-char (car gnus-summary-search-article-matched-data))
7950                    (cadr gnus-summary-search-article-matched-data))
7951                   (insert text)
7952                   (string-match (, regexp) text)))
7953            (if (, backward) (beginning-of-line) (end-of-line))
7954          (goto-char (if (, backward) (point-max) (point-min))))))
7955
7956   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7957     "Place point where X-Face image is displayed."
7958     (if (featurep 'xemacs)
7959         (` (let ((end (if (search-forward "\n\n" nil t)
7960                           (goto-char (1- (point)))
7961                         (point-min)))
7962                  extent)
7963              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7964              (unless (and (re-search-forward "^From:" end t)
7965                           (setq extent (extent-at (point)))
7966                           (extent-begin-glyph extent))
7967                (goto-char (, opoint)))))
7968       (` (let ((end (if (search-forward "\n\n" nil t)
7969                         (goto-char (1- (point)))
7970                       (point-min)))
7971                (start (or (search-backward "\n\n" nil t) (point-min))))
7972            (goto-char
7973             (or (text-property-any start end 'x-face-image t);; x-face-e21
7974                 (text-property-any start end 'x-face-mule-bitmap-image t)
7975                 (, opoint)))))))
7976
7977   (defmacro gnus-summary-search-article-highlight-matched-text
7978     (backward treated x-face)
7979     "Highlight matched text in the function `gnus-summary-search-article'."
7980     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7981              (end (set-marker (make-marker) (match-end 0)))
7982              (inhibit-read-only t)
7983              buffer-read-only)
7984          (unless treated
7985            (let ((,@
7986                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7987                     (mapcar
7988                      (lambda (item) (setq items (delq item items)))
7989                      '(gnus-treat-buttonize
7990                        gnus-treat-fill-article
7991                        gnus-treat-fill-long-lines
7992                        gnus-treat-emphasize
7993                        gnus-treat-highlight-headers
7994                        gnus-treat-highlight-citation
7995                        gnus-treat-highlight-signature
7996                        gnus-treat-overstrike
7997                        gnus-treat-display-xface
7998                        gnus-treat-buttonize-head
7999                        gnus-treat-decode-article-as-default-mime-charset))
8000                     (static-if (featurep 'xemacs)
8001                         items
8002                       (cons '(x-face-mule-delete-x-face-field
8003                               (quote never))
8004                             items))))
8005                  (gnus-treat-display-xface
8006                   (when (, x-face) gnus-treat-display-xface)))
8007              (gnus-article-prepare-mime-display)))
8008          (goto-char (if (, backward) start end))
8009          (when (, x-face)
8010            (gnus-summary-search-article-highlight-goto-x-face (point)))
8011          (setq gnus-summary-search-article-matched-data
8012                (list start end (buffer-substring start end)))
8013          (unless (eq start end);; matched text has been deleted. :-<
8014            (put-text-property start end 'face
8015                               (or (find-face 'isearch)
8016                                   'secondary-selection))))))
8017   )
8018
8019 (defun gnus-summary-search-article (regexp &optional backward)
8020   "Search for an article containing REGEXP.
8021 Optional argument BACKWARD means do search for backward.
8022 `gnus-select-article-hook' is not called during the search."
8023   ;; We have to require this here to make sure that the following
8024   ;; dynamic binding isn't shadowed by autoloading.
8025   (require 'gnus-async)
8026   (require 'gnus-art)
8027   (let ((gnus-select-article-hook nil)  ;Disable hook.
8028         (gnus-article-prepare-hook nil)
8029         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8030         (gnus-use-article-prefetch nil)
8031         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8032         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8033         (sum (current-buffer))
8034         (found nil)
8035         point treated)
8036     (gnus-save-hidden-threads
8037       (static-if (featurep 'xemacs)
8038           (let ((gnus-inhibit-treatment t))
8039             (setq treated (eq 'old (gnus-summary-select-article)))
8040             (when (and treated
8041                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8042                                  (window-live-p (get-buffer-window
8043                                                  gnus-article-buffer t)))))
8044               (gnus-summary-select-article nil t)
8045               (setq treated nil)))
8046         (let ((gnus-inhibit-treatment t)
8047               (x-face-mule-delete-x-face-field 'never))
8048           (setq treated (eq 'old (gnus-summary-select-article)))
8049           (when (and treated
8050                      (not
8051                       (and (gnus-buffer-live-p gnus-article-buffer)
8052                            (window-live-p (get-buffer-window
8053                                            gnus-article-buffer t))
8054                            (or (not (string-match "^\\^X-Face:" regexp))
8055                                (with-current-buffer gnus-article-buffer
8056                                  gnus-summary-search-article-matched-data)))))
8057             (gnus-summary-select-article nil t)
8058             (setq treated nil))))
8059       (set-buffer gnus-article-buffer)
8060       (widen)
8061       (if treated
8062           (progn
8063             (gnus-article-show-all-headers)
8064             (gnus-summary-search-article-position-point regexp backward))
8065         (goto-char (if backward (point-max) (point-min))))
8066       (while (not found)
8067         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8068         (if (if backward
8069                 (re-search-backward regexp nil t)
8070               (re-search-forward regexp nil t))
8071             ;; We found the regexp.
8072             (progn
8073               (gnus-summary-search-article-highlight-matched-text
8074                backward treated (string-match "^\\^X-Face:" regexp))
8075               (setq found 'found)
8076               (forward-line
8077                (/ (- 2 (window-height
8078                         (get-buffer-window gnus-article-buffer t)))
8079                   2))
8080               (set-window-start
8081                (get-buffer-window (current-buffer))
8082                (point))
8083               (set-buffer sum)
8084               (setq point (point)))
8085           ;; We didn't find it, so we go to the next article.
8086           (set-buffer sum)
8087           (setq found 'not)
8088           (while (eq found 'not)
8089             (if (not (if backward (gnus-summary-find-prev)
8090                        (gnus-summary-find-next)))
8091                 ;; No more articles.
8092                 (setq found t)
8093               ;; Select the next article and adjust point.
8094               (unless (gnus-summary-article-sparse-p
8095                        (gnus-summary-article-number))
8096                 (setq found nil)
8097                 (let ((gnus-inhibit-treatment t))
8098                   (gnus-summary-select-article))
8099                 (setq treated nil)
8100                 (set-buffer gnus-article-buffer)
8101                 (widen)
8102                 (goto-char (if backward (point-max) (point-min))))))))
8103       (gnus-message 7 ""))
8104     ;; Return whether we found the regexp.
8105     (when (eq found 'found)
8106       (goto-char point)
8107       (gnus-summary-show-thread)
8108       (gnus-summary-goto-subject gnus-current-article)
8109       (gnus-summary-position-point)
8110       t)))
8111
8112 (defun gnus-find-matching-articles (header regexp)
8113   "Return a list of all articles that match REGEXP on HEADER.
8114 This search includes all articles in the current group that Gnus has
8115 fetched headers for, whether they are displayed or not."
8116   (let ((articles nil)
8117         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8118         (case-fold-search t))
8119     (dolist (header gnus-newsgroup-headers)
8120       (when (string-match regexp (funcall func header))
8121         (push (mail-header-number header) articles)))
8122     (nreverse articles)))
8123
8124 (defun gnus-summary-find-matching (header regexp &optional backward unread
8125                                           not-case-fold not-matching)
8126   "Return a list of all articles that match REGEXP on HEADER.
8127 The search stars on the current article and goes forwards unless
8128 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8129 If UNREAD is non-nil, only unread articles will
8130 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8131 in the comparisons. If NOT-MATCHING, return a list of all articles that
8132 not match REGEXP on HEADER."
8133   (let ((case-fold-search (not not-case-fold))
8134         articles d func)
8135     (if (consp header)
8136         (if (eq (car header) 'extra)
8137             (setq func
8138                   `(lambda (h)
8139                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8140                          "")))
8141           (error "%s is an invalid header" header))
8142       (unless (fboundp (intern (concat "mail-header-" header)))
8143         (error "%s is not a valid header" header))
8144       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8145     (dolist (d (if (eq backward 'all)
8146                    gnus-newsgroup-data
8147                  (gnus-data-find-list
8148                   (gnus-summary-article-number)
8149                   (gnus-data-list backward))))
8150       (when (and (or (not unread)       ; We want all articles...
8151                      (gnus-data-unread-p d)) ; Or just unreads.
8152                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8153                  (if not-matching
8154                      (not (string-match
8155                            regexp
8156                            (funcall func (gnus-data-header d))))
8157                    (string-match regexp
8158                                  (funcall func (gnus-data-header d)))))
8159         (push (gnus-data-number d) articles))) ; Success!
8160     (nreverse articles)))
8161
8162 (defun gnus-summary-execute-command (header regexp command &optional backward)
8163   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8164 If HEADER is an empty string (or nil), the match is done on the entire
8165 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8166   (interactive
8167    (list (let ((completion-ignore-case t))
8168            (completing-read
8169             "Header name: "
8170             (mapcar (lambda (header) (list (format "%s" header)))
8171                     (append
8172                      '("Number" "Subject" "From" "Lines" "Date"
8173                        "Message-ID" "Xref" "References" "Body")
8174                      gnus-extra-headers))
8175             nil 'require-match))
8176          (read-string "Regexp: ")
8177          (read-key-sequence "Command: ")
8178          current-prefix-arg))
8179   (when (equal header "Body")
8180     (setq header ""))
8181   ;; Hidden thread subtrees must be searched as well.
8182   (gnus-summary-show-all-threads)
8183   ;; We don't want to change current point nor window configuration.
8184   (save-excursion
8185     (save-window-excursion
8186       (gnus-message 6 "Executing %s..." (key-description command))
8187       ;; We'd like to execute COMMAND interactively so as to give arguments.
8188       (gnus-execute header regexp
8189                     `(call-interactively ',(key-binding command))
8190                     backward)
8191       (gnus-message 6 "Executing %s...done" (key-description command)))))
8192
8193 (defun gnus-summary-beginning-of-article ()
8194   "Scroll the article back to the beginning."
8195   (interactive)
8196   (gnus-summary-select-article)
8197   (gnus-configure-windows 'article)
8198   (gnus-eval-in-buffer-window gnus-article-buffer
8199     (widen)
8200     (goto-char (point-min))
8201     (when gnus-page-broken
8202       (gnus-narrow-to-page))))
8203
8204 (defun gnus-summary-end-of-article ()
8205   "Scroll to the end of the article."
8206   (interactive)
8207   (gnus-summary-select-article)
8208   (gnus-configure-windows 'article)
8209   (gnus-eval-in-buffer-window gnus-article-buffer
8210     (widen)
8211     (goto-char (point-max))
8212     (recenter -3)
8213     (when gnus-page-broken
8214       (gnus-narrow-to-page))))
8215
8216 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8217   "Truncate to LEN and quote all \"(\"'s in STRING."
8218   (gnus-replace-in-string (if (and len (> (length string) len))
8219                               (substring string 0 len)
8220                             string)
8221                           "[()]" "\\\\\\&"))
8222
8223 (defun gnus-summary-print-article (&optional filename n)
8224   "Generate and print a PostScript image of the N next (mail) articles.
8225
8226 If N is negative, print the N previous articles.  If N is nil and articles
8227 have been marked with the process mark, print these instead.
8228
8229 If the optional first argument FILENAME is nil, send the image to the
8230 printer.  If FILENAME is a string, save the PostScript image in a file with
8231 that name.  If FILENAME is a number, prompt the user for the name of the file
8232 to save in."
8233   (interactive (list (ps-print-preprint current-prefix-arg)))
8234   (dolist (article (gnus-summary-work-articles n))
8235     (gnus-summary-select-article nil nil 'pseudo article)
8236     (gnus-eval-in-buffer-window gnus-article-buffer
8237       (gnus-print-buffer))
8238     (gnus-summary-remove-process-mark article))
8239   (ps-despool filename))
8240
8241 (defun gnus-print-buffer ()
8242   (let ((buffer (generate-new-buffer " *print*")))
8243     (unwind-protect
8244         (progn
8245           (copy-to-buffer buffer (point-min) (point-max))
8246           (set-buffer buffer)
8247           (gnus-article-delete-invisible-text)
8248           (when (gnus-visual-p 'article-highlight 'highlight)
8249             ;; Copy-to-buffer doesn't copy overlay.  So redo
8250             ;; highlight.
8251             (let ((gnus-article-buffer buffer))
8252               (gnus-article-highlight-citation t)
8253               (gnus-article-highlight-signature)))
8254           (let ((ps-left-header
8255                  (list
8256                   (concat "("
8257                           (gnus-summary-print-truncate-and-quote
8258                            (mail-header-subject gnus-current-headers)
8259                            66) ")")
8260                   (concat "("
8261                           (gnus-summary-print-truncate-and-quote
8262                            (mail-header-from gnus-current-headers)
8263                            45) ")")))
8264                 (ps-right-header
8265                  (list
8266                   "/pagenumberstring load"
8267                   (concat "("
8268                           (mail-header-date gnus-current-headers) ")"))))
8269             (gnus-run-hooks 'gnus-ps-print-hook)
8270             (save-excursion
8271               (if window-system
8272                   (ps-spool-buffer-with-faces)
8273                 (ps-spool-buffer)))))
8274       (kill-buffer buffer))))
8275
8276 (defun gnus-summary-show-article (&optional arg)
8277   "Force redisplaying of the current article.
8278 If ARG (the prefix) is a number, show the article with the charset
8279 defined in `gnus-summary-show-article-charset-alist', or the charset
8280 input.
8281 If ARG (the prefix) is non-nil and not a number, show the raw article
8282 without any article massaging functions being run.  Normally, the key strokes
8283 are `C-u g'."
8284   (interactive "P")
8285   (cond
8286    ((numberp arg)
8287     (gnus-summary-show-article t)
8288     (let* ((gnus-newsgroup-charset
8289             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8290                 (mm-read-coding-system
8291                  "View as charset: " ;; actually it is coding system.
8292                  (save-excursion
8293                    (set-buffer gnus-article-buffer)
8294                    (mm-detect-coding-region (point) (point-max))))))
8295            (default-mime-charset gnus-newsgroup-charset)
8296            (gnus-newsgroup-ignored-charsets 'gnus-all))
8297       (gnus-summary-select-article nil 'force)
8298       (let ((deps gnus-newsgroup-dependencies)
8299             head header lines)
8300         (save-excursion
8301           (set-buffer gnus-original-article-buffer)
8302           (save-restriction
8303             (message-narrow-to-head)
8304             (setq head (buffer-string))
8305             (goto-char (point-min))
8306             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8307               (goto-char (point-max))
8308               (widen)
8309               (setq lines (1- (count-lines (point) (point-max))))))
8310           (with-temp-buffer
8311             (insert (format "211 %d Article retrieved.\n"
8312                             (cdr gnus-article-current)))
8313             (insert head)
8314             (if lines (insert (format "Lines: %d\n" lines)))
8315             (insert ".\n")
8316             (let ((nntp-server-buffer (current-buffer)))
8317               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8318         (gnus-data-set-header
8319          (gnus-data-find (cdr gnus-article-current))
8320          header)
8321         (gnus-summary-update-article-line
8322          (cdr gnus-article-current) header)
8323         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8324           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8325    ((not arg)
8326     ;; Select the article the normal way.
8327     (gnus-summary-select-article nil 'force))
8328    (t
8329     ;; We have to require this here to make sure that the following
8330     ;; dynamic binding isn't shadowed by autoloading.
8331     (require 'gnus-async)
8332     (require 'gnus-art)
8333     ;; Bind the article treatment functions to nil.
8334     (let ((gnus-have-all-headers t)
8335           gnus-article-prepare-hook
8336           gnus-article-decode-hook
8337           gnus-break-pages
8338           gnus-show-mime
8339           (gnus-inhibit-treatment t))
8340       (gnus-summary-select-article nil 'force))))
8341   (gnus-summary-goto-subject gnus-current-article)
8342   (gnus-summary-position-point))
8343
8344 (defun gnus-summary-show-raw-article ()
8345   "Show the raw article without any article massaging functions being run."
8346   (interactive)
8347   (gnus-summary-show-article t))
8348
8349 (defun gnus-summary-verbose-headers (&optional arg)
8350   "Toggle permanent full header display.
8351 If ARG is a positive number, turn header display on.
8352 If ARG is a negative number, turn header display off."
8353   (interactive "P")
8354   (setq gnus-show-all-headers
8355         (cond ((or (not (numberp arg))
8356                    (zerop arg))
8357                (not gnus-show-all-headers))
8358               ((natnump arg)
8359                t)))
8360   (gnus-summary-show-article))
8361
8362 (defun gnus-summary-toggle-header (&optional arg)
8363   "Show the headers if they are hidden, or hide them if they are shown.
8364 If ARG is a positive number, show the entire header.
8365 If ARG is a negative number, hide the unwanted header lines."
8366   (interactive "P")
8367   (save-excursion
8368     (set-buffer gnus-article-buffer)
8369     (save-restriction
8370       (let* ((buffer-read-only nil)
8371              (inhibit-point-motion-hooks t)
8372              hidden e)
8373         (save-restriction
8374           (article-narrow-to-head)
8375           (setq e (point-max)
8376                 hidden (if (numberp arg)
8377                            (>= arg 0)
8378                          (gnus-article-hidden-text-p 'headers))))
8379         (delete-region (point-min) e)
8380         (goto-char (point-min))
8381         (save-excursion
8382           (set-buffer gnus-original-article-buffer)
8383           (goto-char (point-min))
8384           (setq e (search-forward "\n\n" nil t)
8385                 e (if e (1- e) (point-max))))
8386         (insert-buffer-substring gnus-original-article-buffer 1 e)
8387         (save-restriction
8388           (narrow-to-region (point-min) (point))
8389           (article-decode-encoded-words)
8390           (if  hidden
8391               (let ((gnus-treat-hide-headers nil)
8392                     (gnus-treat-hide-boring-headers nil))
8393                 (gnus-delete-wash-type 'headers)
8394                 (gnus-treat-article 'head))
8395             (gnus-treat-article 'head)))
8396         (gnus-set-mode-line 'article)))))
8397
8398 (defun gnus-summary-show-all-headers ()
8399   "Make all header lines visible."
8400   (interactive)
8401   (gnus-summary-toggle-header 1))
8402
8403 (defun gnus-summary-toggle-mime (&optional arg)
8404   "Toggle MIME processing.
8405 If ARG is a positive number, turn MIME processing on."
8406   (interactive "P")
8407   (setq gnus-show-mime
8408         (if (null arg)
8409             (not gnus-show-mime)
8410           (> (prefix-numeric-value arg) 0)))
8411   (gnus-summary-select-article t 'force))
8412
8413 (defun gnus-summary-caesar-message (&optional arg)
8414   "Caesar rotate the current article by 13.
8415 The numerical prefix specifies how many places to rotate each letter
8416 forward."
8417   (interactive "P")
8418   (gnus-summary-select-article)
8419   (let ((mail-header-separator ""))
8420     (gnus-eval-in-buffer-window gnus-article-buffer
8421       (save-restriction
8422         (widen)
8423         (let ((start (window-start))
8424               buffer-read-only)
8425           (message-caesar-buffer-body arg)
8426           (set-window-start (get-buffer-window (current-buffer)) start))))))
8427
8428 (defun gnus-summary-stop-page-breaking ()
8429   "Stop page breaking in the current article."
8430   (interactive)
8431   (gnus-summary-select-article)
8432   (gnus-eval-in-buffer-window gnus-article-buffer
8433     (widen)
8434     (when (gnus-visual-p 'page-marker)
8435       (let ((buffer-read-only nil))
8436         (gnus-remove-text-with-property 'gnus-prev)
8437         (gnus-remove-text-with-property 'gnus-next))
8438       (setq gnus-page-broken nil))))
8439
8440 (defun gnus-summary-move-article (&optional n to-newsgroup
8441                                             select-method action)
8442   "Move the current article to a different newsgroup.
8443 If N is a positive number, move the N next articles.
8444 If N is a negative number, move the N previous articles.
8445 If N is nil and any articles have been marked with the process mark,
8446 move those articles instead.
8447 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8448 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8449 re-spool using this method.
8450
8451 For this function to work, both the current newsgroup and the
8452 newsgroup that you want to move to have to support the `request-move'
8453 and `request-accept' functions.
8454
8455 ACTION can be either `move' (the default), `crosspost' or `copy'."
8456   (interactive "P")
8457   (unless action
8458     (setq action 'move))
8459   ;; Check whether the source group supports the required functions.
8460   (cond ((and (eq action 'move)
8461               (not (gnus-check-backend-function
8462                     'request-move-article gnus-newsgroup-name)))
8463          (error "The current group does not support article moving"))
8464         ((and (eq action 'crosspost)
8465               (not (gnus-check-backend-function
8466                     'request-replace-article gnus-newsgroup-name)))
8467          (error "The current group does not support article editing")))
8468   (let ((articles (gnus-summary-work-articles n))
8469         (prefix (if (gnus-check-backend-function
8470                      'request-move-article gnus-newsgroup-name)
8471                     (gnus-group-real-prefix gnus-newsgroup-name)
8472                   ""))
8473         (names '((move "Move" "Moving")
8474                  (copy "Copy" "Copying")
8475                  (crosspost "Crosspost" "Crossposting")))
8476         (copy-buf (save-excursion
8477                     (nnheader-set-temp-buffer " *copy article*")))
8478         (default-marks gnus-article-mark-lists)
8479         (no-expire-marks (delete '(expirable . expire)
8480                                  (copy-sequence gnus-article-mark-lists)))
8481         art-group to-method new-xref article to-groups)
8482     (unless (assq action names)
8483       (error "Unknown action %s" action))
8484     ;; Read the newsgroup name.
8485     (when (and (not to-newsgroup)
8486                (not select-method))
8487       (if (and gnus-move-split-methods
8488                (not
8489                 (and (memq gnus-current-article articles)
8490                      (gnus-buffer-live-p gnus-original-article-buffer))))
8491           ;; When `gnus-move-split-methods' is non-nil, we have to
8492           ;; select an article to give `gnus-read-move-group-name' an
8493           ;; opportunity to suggest an appropriate default.  However,
8494           ;; we needn't render or mark the article.
8495           (let ((gnus-display-mime-function nil)
8496                 (gnus-article-prepare-hook nil)
8497                 (gnus-mark-article-hook nil))
8498             (gnus-summary-select-article nil nil nil (car articles))))
8499       (setq to-newsgroup
8500             (gnus-read-move-group-name
8501              (cadr (assq action names))
8502              (symbol-value (intern (format "gnus-current-%s-group" action)))
8503              articles prefix))
8504       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8505     (setq to-method (or select-method
8506                         (gnus-server-to-method
8507                          (gnus-group-method to-newsgroup))))
8508     ;; Check the method we are to move this article to...
8509     (unless (gnus-check-backend-function
8510              'request-accept-article (car to-method))
8511       (error "%s does not support article copying" (car to-method)))
8512     (unless (gnus-check-server to-method)
8513       (error "Can't open server %s" (car to-method)))
8514     (gnus-message 6 "%s to %s: %s..."
8515                   (caddr (assq action names))
8516                   (or (car select-method) to-newsgroup) articles)
8517     (while articles
8518       (setq article (pop articles))
8519       (setq
8520        art-group
8521        (cond
8522         ;; Move the article.
8523         ((eq action 'move)
8524          ;; Remove this article from future suppression.
8525          (gnus-dup-unsuppress-article article)
8526          (gnus-request-move-article
8527           article                       ; Article to move
8528           gnus-newsgroup-name           ; From newsgroup
8529           (nth 1 (gnus-find-method-for-group
8530                   gnus-newsgroup-name)) ; Server
8531           (list 'gnus-request-accept-article
8532                 to-newsgroup (list 'quote select-method)
8533                 (not articles) t)       ; Accept form
8534           (not articles)))              ; Only save nov last time
8535         ;; Copy the article.
8536         ((eq action 'copy)
8537          (save-excursion
8538            (set-buffer copy-buf)
8539            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8540              (gnus-request-accept-article
8541               to-newsgroup select-method (not articles) t))))
8542         ;; Crosspost the article.
8543         ((eq action 'crosspost)
8544          (let ((xref (message-tokenize-header
8545                       (mail-header-xref (gnus-summary-article-header article))
8546                       " ")))
8547            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8548                                   ":" (number-to-string article)))
8549            (unless xref
8550              (setq xref (list (system-name))))
8551            (setq new-xref
8552                  (concat
8553                   (mapconcat 'identity
8554                              (delete "Xref:" (delete new-xref xref))
8555                              " ")
8556                   " " new-xref))
8557            (save-excursion
8558              (set-buffer copy-buf)
8559              ;; First put the article in the destination group.
8560              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8561              (when (consp (setq art-group
8562                                 (gnus-request-accept-article
8563                                  to-newsgroup select-method (not articles))))
8564                (setq new-xref (concat new-xref " " (car art-group)
8565                                       ":"
8566                                       (number-to-string (cdr art-group))))
8567                ;; Now we have the new Xrefs header, so we insert
8568                ;; it and replace the new article.
8569                (nnheader-replace-header "Xref" new-xref)
8570                (gnus-request-replace-article
8571                 (cdr art-group) to-newsgroup (current-buffer))
8572                art-group))))))
8573       (cond
8574        ((not art-group)
8575         (gnus-message 1 "Couldn't %s article %s: %s"
8576                       (cadr (assq action names)) article
8577                       (nnheader-get-report (car to-method))))
8578        ((eq art-group 'junk)
8579         (when (eq action 'move)
8580           (gnus-summary-mark-article article gnus-canceled-mark)
8581           (gnus-message 4 "Deleted article %s" article)))
8582        (t
8583         (let* ((pto-group (gnus-group-prefixed-name
8584                            (car art-group) to-method))
8585                (entry
8586                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8587                (info (nth 2 entry))
8588                (to-group (gnus-info-group info))
8589                to-marks)
8590           ;; Update the group that has been moved to.
8591           (when (and info
8592                      (memq action '(move copy)))
8593             (unless (member to-group to-groups)
8594               (push to-group to-groups))
8595
8596             (unless (memq article gnus-newsgroup-unreads)
8597               (push 'read to-marks)
8598               (gnus-info-set-read
8599                info (gnus-add-to-range (gnus-info-read info)
8600                                        (list (cdr art-group)))))
8601
8602             ;; See whether the article is to be put in the cache.
8603             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8604                              default-marks
8605                            no-expire-marks))
8606                   (to-article (cdr art-group)))
8607
8608               ;; Enter the article into the cache in the new group,
8609               ;; if that is required.
8610               (when gnus-use-cache
8611                 (gnus-cache-possibly-enter-article
8612                  to-group to-article
8613                  (let ((header (copy-sequence
8614                                 (gnus-summary-article-header article))))
8615                    (mail-header-set-number header to-article)
8616                    header)
8617                  (memq article gnus-newsgroup-marked)
8618                  (memq article gnus-newsgroup-dormant)
8619                  (memq article gnus-newsgroup-unreads)))
8620
8621               (when gnus-preserve-marks
8622                 ;; Copy any marks over to the new group.
8623                 (when (and (equal to-group gnus-newsgroup-name)
8624                            (not (memq article gnus-newsgroup-unreads)))
8625                   ;; Mark this article as read in this group.
8626                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8627                   (setcdr (gnus-active to-group) to-article)
8628                   (setcdr gnus-newsgroup-active to-article))
8629
8630                 (while marks
8631                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8632                     (when (memq article (symbol-value
8633                                          (intern (format "gnus-newsgroup-%s"
8634                                                          (caar marks)))))
8635                       (push (cdar marks) to-marks)
8636                       ;; If the other group is the same as this group,
8637                       ;; then we have to add the mark to the list.
8638                       (when (equal to-group gnus-newsgroup-name)
8639                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8640                              (cons to-article
8641                                    (symbol-value
8642                                     (intern (format "gnus-newsgroup-%s"
8643                                                     (caar marks)))))))
8644                       ;; Copy the marks to other group.
8645                       (gnus-add-marked-articles
8646                        to-group (cdar marks) (list to-article) info)))
8647                   (setq marks (cdr marks)))
8648
8649                 (gnus-request-set-mark to-group (list (list (list to-article)
8650                                                             'add
8651                                                             to-marks))))
8652
8653               (gnus-dribble-enter
8654                (concat "(gnus-group-set-info '"
8655                        (gnus-prin1-to-string (gnus-get-info to-group))
8656                        ")"))))
8657
8658           ;; Update the Xref header in this article to point to
8659           ;; the new crossposted article we have just created.
8660           (when (eq action 'crosspost)
8661             (save-excursion
8662               (set-buffer copy-buf)
8663               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8664               (nnheader-replace-header "Xref" new-xref)
8665               (gnus-request-replace-article
8666                article gnus-newsgroup-name (current-buffer)))))
8667
8668         ;;;!!!Why is this necessary?
8669         (set-buffer gnus-summary-buffer)
8670
8671         (gnus-summary-goto-subject article)
8672         (when (eq action 'move)
8673           (gnus-summary-mark-article article gnus-canceled-mark))))
8674       (gnus-summary-remove-process-mark article))
8675     ;; Re-activate all groups that have been moved to.
8676     (save-excursion
8677       (set-buffer gnus-group-buffer)
8678       (let ((gnus-group-marked to-groups))
8679         (gnus-group-get-new-news-this-group nil t)))
8680
8681     (gnus-kill-buffer copy-buf)
8682     (gnus-summary-position-point)
8683     (gnus-set-mode-line 'summary)))
8684
8685 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8686   "Move the current article to a different newsgroup.
8687 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8688 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8689 re-spool using this method."
8690   (interactive "P")
8691   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8692
8693 (defun gnus-summary-crosspost-article (&optional n)
8694   "Crosspost the current article to some other group."
8695   (interactive "P")
8696   (gnus-summary-move-article n nil nil 'crosspost))
8697
8698 (defcustom gnus-summary-respool-default-method nil
8699   "Default method type for respooling an article.
8700 If nil, use to the current newsgroup method."
8701   :type 'symbol
8702   :group 'gnus-summary-mail)
8703
8704 (defun gnus-summary-respool-article (&optional n method)
8705   "Respool the current article.
8706 The article will be squeezed through the mail spooling process again,
8707 which means that it will be put in some mail newsgroup or other
8708 depending on `nnmail-split-methods'.
8709 If N is a positive number, respool the N next articles.
8710 If N is a negative number, respool the N previous articles.
8711 If N is nil and any articles have been marked with the process mark,
8712 respool those articles instead.
8713
8714 Respooling can be done both from mail groups and \"real\" newsgroups.
8715 In the former case, the articles in question will be moved from the
8716 current group into whatever groups they are destined to.  In the
8717 latter case, they will be copied into the relevant groups."
8718   (interactive
8719    (list current-prefix-arg
8720          (let* ((methods (gnus-methods-using 'respool))
8721                 (methname
8722                  (symbol-name (or gnus-summary-respool-default-method
8723                                   (car (gnus-find-method-for-group
8724                                         gnus-newsgroup-name)))))
8725                 (method
8726                  (gnus-completing-read-with-default
8727                   methname "What backend do you want to use when respooling?"
8728                   methods nil t nil 'gnus-mail-method-history))
8729                 ms)
8730            (cond
8731             ((zerop (length (setq ms (gnus-servers-using-backend
8732                                       (intern method)))))
8733              (list (intern method) ""))
8734             ((= 1 (length ms))
8735              (car ms))
8736             (t
8737              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8738                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8739                            ms-alist))))))))
8740   (unless method
8741     (error "No method given for respooling"))
8742   (if (assoc (symbol-name
8743               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8744              (gnus-methods-using 'respool))
8745       (gnus-summary-move-article n nil method)
8746     (gnus-summary-copy-article n nil method)))
8747
8748 (defun gnus-summary-import-article (file &optional edit)
8749   "Import an arbitrary file into a mail newsgroup."
8750   (interactive "fImport file: \nP")
8751   (let ((group gnus-newsgroup-name)
8752         (now (current-time))
8753         atts lines group-art)
8754     (unless (gnus-check-backend-function 'request-accept-article group)
8755       (error "%s does not support article importing" group))
8756     (or (file-readable-p file)
8757         (not (file-regular-p file))
8758         (error "Can't read %s" file))
8759     (save-excursion
8760       (set-buffer (gnus-get-buffer-create " *import file*"))
8761       (erase-buffer)
8762       (nnheader-insert-file-contents file)
8763       (goto-char (point-min))
8764       (if (nnheader-article-p)
8765           (save-restriction
8766             (goto-char (point-min))
8767             (search-forward "\n\n" nil t)
8768             (narrow-to-region (point-min) (1- (point)))
8769             (goto-char (point-min))
8770             (unless (re-search-forward "^date:" nil t)
8771               (goto-char (point-max))
8772               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8773         ;; This doesn't look like an article, so we fudge some headers.
8774         (setq atts (file-attributes file)
8775               lines (count-lines (point-min) (point-max)))
8776         (insert "From: " (read-string "From: ") "\n"
8777                 "Subject: " (read-string "Subject: ") "\n"
8778                 "Date: " (message-make-date (nth 5 atts)) "\n"
8779                 "Message-ID: " (message-make-message-id) "\n"
8780                 "Lines: " (int-to-string lines) "\n"
8781                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8782       (setq group-art (gnus-request-accept-article group nil t))
8783       (kill-buffer (current-buffer)))
8784     (setq gnus-newsgroup-active (gnus-activate-group group))
8785     (forward-line 1)
8786     (gnus-summary-goto-article (cdr group-art) nil t)
8787     (when edit
8788       (gnus-summary-edit-article))))
8789
8790 (defun gnus-summary-create-article ()
8791   "Create an article in a mail newsgroup."
8792   (interactive)
8793   (let ((group gnus-newsgroup-name)
8794         (now (current-time))
8795         group-art)
8796     (unless (gnus-check-backend-function 'request-accept-article group)
8797       (error "%s does not support article importing" group))
8798     (save-excursion
8799       (set-buffer (gnus-get-buffer-create " *import file*"))
8800       (erase-buffer)
8801       (goto-char (point-min))
8802       ;; This doesn't look like an article, so we fudge some headers.
8803       (insert "From: " (read-string "From: ") "\n"
8804               "Subject: " (read-string "Subject: ") "\n"
8805               "Date: " (message-make-date now) "\n"
8806               "Message-ID: " (message-make-message-id) "\n")
8807       (setq group-art (gnus-request-accept-article group nil t))
8808       (kill-buffer (current-buffer)))
8809     (setq gnus-newsgroup-active (gnus-activate-group group))
8810     (forward-line 1)
8811     (gnus-summary-goto-article (cdr group-art) nil t)
8812     (gnus-summary-edit-article)))
8813
8814 (defun gnus-summary-article-posted-p ()
8815   "Say whether the current (mail) article is available from news as well.
8816 This will be the case if the article has both been mailed and posted."
8817   (interactive)
8818   (let ((id (mail-header-references (gnus-summary-article-header)))
8819         (gnus-override-method (car (gnus-refer-article-methods))))
8820     (if (gnus-request-head id "")
8821         (gnus-message 2 "The current message was found on %s"
8822                       gnus-override-method)
8823       (gnus-message 2 "The current message couldn't be found on %s"
8824                     gnus-override-method)
8825       nil)))
8826
8827 (defun gnus-summary-expire-articles (&optional now)
8828   "Expire all articles that are marked as expirable in the current group."
8829   (interactive)
8830   (when (gnus-check-backend-function
8831          'request-expire-articles gnus-newsgroup-name)
8832     ;; This backend supports expiry.
8833     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8834            (expirable (if total
8835                           (progn
8836                             ;; We need to update the info for
8837                             ;; this group for `gnus-list-of-read-articles'
8838                             ;; to give us the right answer.
8839                             (gnus-run-hooks 'gnus-exit-group-hook)
8840                             (gnus-summary-update-info)
8841                             (gnus-list-of-read-articles gnus-newsgroup-name))
8842                         (setq gnus-newsgroup-expirable
8843                               (sort gnus-newsgroup-expirable '<))))
8844            (expiry-wait (if now 'immediate
8845                           (gnus-group-find-parameter
8846                            gnus-newsgroup-name 'expiry-wait)))
8847            (nnmail-expiry-target
8848             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8849                 nnmail-expiry-target))
8850            es)
8851       (when expirable
8852         ;; There are expirable articles in this group, so we run them
8853         ;; through the expiry process.
8854         (gnus-message 6 "Expiring articles...")
8855         (unless (gnus-check-group gnus-newsgroup-name)
8856           (error "Can't open server for %s" gnus-newsgroup-name))
8857         ;; The list of articles that weren't expired is returned.
8858         (save-excursion
8859           (if expiry-wait
8860               (let ((nnmail-expiry-wait-function nil)
8861                     (nnmail-expiry-wait expiry-wait))
8862                 (setq es (gnus-request-expire-articles
8863                           expirable gnus-newsgroup-name)))
8864             (setq es (gnus-request-expire-articles
8865                       expirable gnus-newsgroup-name)))
8866           (unless total
8867             (setq gnus-newsgroup-expirable es))
8868           ;; We go through the old list of expirable, and mark all
8869           ;; really expired articles as nonexistent.
8870           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8871             (let ((gnus-use-cache nil))
8872               (dolist (article expirable)
8873                 (when (and (not (memq article es))
8874                            (gnus-data-find article))
8875                   (gnus-summary-mark-article article gnus-canceled-mark))))))
8876         (gnus-message 6 "Expiring articles...done")))))
8877
8878 (defun gnus-summary-expire-articles-now ()
8879   "Expunge all expirable articles in the current group.
8880 This means that *all* articles that are marked as expirable will be
8881 deleted forever, right now."
8882   (interactive)
8883   (or gnus-expert-user
8884       (gnus-yes-or-no-p
8885        "Are you really, really, really sure you want to delete all these messages? ")
8886       (error "Phew!"))
8887   (gnus-summary-expire-articles t))
8888
8889 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8890 (defun gnus-summary-delete-article (&optional n)
8891   "Delete the N next (mail) articles.
8892 This command actually deletes articles.  This is not a marking
8893 command.  The article will disappear forever from your life, never to
8894 return.
8895 If N is negative, delete backwards.
8896 If N is nil and articles have been marked with the process mark,
8897 delete these instead."
8898   (interactive "P")
8899   (unless (gnus-check-backend-function 'request-expire-articles
8900                                        gnus-newsgroup-name)
8901     (error "The current newsgroup does not support article deletion"))
8902   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8903     (error "Couldn't open server"))
8904   ;; Compute the list of articles to delete.
8905   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8906         not-deleted)
8907     (if (and gnus-novice-user
8908              (not (gnus-yes-or-no-p
8909                    (format "Do you really want to delete %s forever? "
8910                            (if (> (length articles) 1)
8911                                (format "these %s articles" (length articles))
8912                              "this article")))))
8913         ()
8914       ;; Delete the articles.
8915       (setq not-deleted (gnus-request-expire-articles
8916                          articles gnus-newsgroup-name 'force))
8917       (while articles
8918         (gnus-summary-remove-process-mark (car articles))
8919         ;; The backend might not have been able to delete the article
8920         ;; after all.
8921         (unless (memq (car articles) not-deleted)
8922           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8923         (setq articles (cdr articles)))
8924       (when not-deleted
8925         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8926     (gnus-summary-position-point)
8927     (gnus-set-mode-line 'summary)
8928     not-deleted))
8929
8930 (defun gnus-summary-edit-article (&optional force)
8931   "Edit the current article.
8932 This will have permanent effect only in mail groups.
8933 If FORCE is non-nil, allow editing of articles even in read-only
8934 groups."
8935   (interactive "P")
8936   (save-excursion
8937     (set-buffer gnus-summary-buffer)
8938     (let ((mail-parse-charset gnus-newsgroup-charset)
8939           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8940       (gnus-set-global-variables)
8941       (when (and (not force)
8942                  (gnus-group-read-only-p))
8943         (error "The current newsgroup does not support article editing"))
8944       (gnus-summary-show-article t)
8945       (gnus-article-edit-article
8946        'ignore
8947        `(lambda (no-highlight)
8948           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8949                 (message-options message-options)
8950                 (message-options-set-recipient)
8951                 (mail-parse-ignored-charsets
8952                  ',gnus-newsgroup-ignored-charsets))
8953             (gnus-summary-edit-article-done
8954              ,(or (mail-header-references gnus-current-headers) "")
8955              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8956
8957 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8958
8959 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8960                                                  no-highlight)
8961   "Make edits to the current article permanent."
8962   (interactive)
8963   (save-excursion
8964     ;; The buffer restriction contains the entire article if it exists.
8965     (when (article-goto-body)
8966       (let ((lines (count-lines (point) (point-max)))
8967             (length (- (point-max) (point)))
8968             (case-fold-search t)
8969             (body (copy-marker (point))))
8970         (goto-char (point-min))
8971         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8972           (delete-region (match-beginning 1) (match-end 1))
8973           (insert (number-to-string length)))
8974         (goto-char (point-min))
8975         (when (re-search-forward
8976                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8977           (delete-region (match-beginning 1) (match-end 1))
8978           (insert (number-to-string length)))
8979         (goto-char (point-min))
8980         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8981           (delete-region (match-beginning 1) (match-end 1))
8982           (insert (number-to-string lines))))))
8983   ;; Replace the article.
8984   (let ((buf (current-buffer)))
8985     (with-temp-buffer
8986       (insert-buffer-substring buf)
8987
8988       (if (and (not read-only)
8989                (not (gnus-request-replace-article
8990                      (cdr gnus-article-current) (car gnus-article-current)
8991                      (current-buffer) t)))
8992           (error "Couldn't replace article")
8993         ;; Update the summary buffer.
8994         (if (and references
8995                  (equal (message-tokenize-header references " ")
8996                         (message-tokenize-header
8997                          (or (message-fetch-field "references") "") " ")))
8998             ;; We only have to update this line.
8999             (save-excursion
9000               (save-restriction
9001                 (message-narrow-to-head)
9002                 (let ((head (buffer-string))
9003                       header)
9004                   (with-temp-buffer
9005                     (insert (format "211 %d Article retrieved.\n"
9006                                     (cdr gnus-article-current)))
9007                     (insert head)
9008                     (insert ".\n")
9009                     (let ((nntp-server-buffer (current-buffer)))
9010                       (setq header (car (gnus-get-newsgroup-headers
9011                                          nil t))))
9012                     (save-excursion
9013                       (set-buffer gnus-summary-buffer)
9014                       (gnus-data-set-header
9015                        (gnus-data-find (cdr gnus-article-current))
9016                        header)
9017                       (gnus-summary-update-article-line
9018                        (cdr gnus-article-current) header)
9019                       (if (gnus-summary-goto-subject
9020                            (cdr gnus-article-current) nil t)
9021                           (gnus-summary-update-secondary-mark
9022                            (cdr gnus-article-current))))))))
9023           ;; Update threads.
9024           (set-buffer (or buffer gnus-summary-buffer))
9025           (gnus-summary-update-article (cdr gnus-article-current))
9026           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9027               (gnus-summary-update-secondary-mark
9028                (cdr gnus-article-current))))
9029         ;; Prettify the article buffer again.
9030         (unless no-highlight
9031           (save-excursion
9032             (set-buffer gnus-article-buffer)
9033             ;;;!!! Fix this -- article should be rehighlighted.
9034             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9035             (set-buffer gnus-original-article-buffer)
9036             (gnus-request-article
9037              (cdr gnus-article-current)
9038              (car gnus-article-current) (current-buffer))))
9039         ;; Prettify the summary buffer line.
9040         (when (gnus-visual-p 'summary-highlight 'highlight)
9041           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9042
9043 (defun gnus-summary-edit-wash (key)
9044   "Perform editing command KEY in the article buffer."
9045   (interactive
9046    (list
9047     (progn
9048       (message "%s" (concat (this-command-keys) "- "))
9049       (read-char))))
9050   (message "")
9051   (gnus-summary-edit-article)
9052   (execute-kbd-macro (concat (this-command-keys) key))
9053   (gnus-article-edit-done))
9054
9055 ;;; Respooling
9056
9057 (defun gnus-summary-respool-query (&optional silent trace)
9058   "Query where the respool algorithm would put this article."
9059   (interactive)
9060   (let (gnus-mark-article-hook)
9061     (gnus-summary-select-article)
9062     (save-excursion
9063       (set-buffer gnus-original-article-buffer)
9064       (save-restriction
9065         (message-narrow-to-head)
9066         (let ((groups (nnmail-article-group 'identity trace)))
9067           (unless silent
9068             (if groups
9069                 (message "This message would go to %s"
9070                          (mapconcat 'car groups ", "))
9071               (message "This message would go to no groups"))
9072             groups))))))
9073
9074 (defun gnus-summary-respool-trace ()
9075   "Trace where the respool algorithm would put this article.
9076 Display a buffer showing all fancy splitting patterns which matched."
9077   (interactive)
9078   (gnus-summary-respool-query nil t))
9079
9080 ;; Summary marking commands.
9081
9082 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9083   "Mark articles which has the same subject as read, and then select the next.
9084 If UNMARK is positive, remove any kind of mark.
9085 If UNMARK is negative, tick articles."
9086   (interactive "P")
9087   (when unmark
9088     (setq unmark (prefix-numeric-value unmark)))
9089   (let ((count
9090          (gnus-summary-mark-same-subject
9091           (gnus-summary-article-subject) unmark)))
9092     ;; Select next unread article.  If auto-select-same mode, should
9093     ;; select the first unread article.
9094     (gnus-summary-next-article t (and gnus-auto-select-same
9095                                       (gnus-summary-article-subject)))
9096     (gnus-message 7 "%d article%s marked as %s"
9097                   count (if (= count 1) " is" "s are")
9098                   (if unmark "unread" "read"))))
9099
9100 (defun gnus-summary-kill-same-subject (&optional unmark)
9101   "Mark articles which has the same subject as read.
9102 If UNMARK is positive, remove any kind of mark.
9103 If UNMARK is negative, tick articles."
9104   (interactive "P")
9105   (when unmark
9106     (setq unmark (prefix-numeric-value unmark)))
9107   (let ((count
9108          (gnus-summary-mark-same-subject
9109           (gnus-summary-article-subject) unmark)))
9110     ;; If marked as read, go to next unread subject.
9111     (when (null unmark)
9112       ;; Go to next unread subject.
9113       (gnus-summary-next-subject 1 t))
9114     (gnus-message 7 "%d articles are marked as %s"
9115                   count (if unmark "unread" "read"))))
9116
9117 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9118   "Mark articles with same SUBJECT as read, and return marked number.
9119 If optional argument UNMARK is positive, remove any kinds of marks.
9120 If optional argument UNMARK is negative, mark articles as unread instead."
9121   (let ((count 1))
9122     (save-excursion
9123       (cond
9124        ((null unmark)                   ; Mark as read.
9125         (while (and
9126                 (progn
9127                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9128                   (gnus-summary-show-thread) t)
9129                 (gnus-summary-find-subject subject))
9130           (setq count (1+ count))))
9131        ((> unmark 0)                    ; Tick.
9132         (while (and
9133                 (progn
9134                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9135                   (gnus-summary-show-thread) t)
9136                 (gnus-summary-find-subject subject))
9137           (setq count (1+ count))))
9138        (t                               ; Mark as unread.
9139         (while (and
9140                 (progn
9141                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9142                   (gnus-summary-show-thread) t)
9143                 (gnus-summary-find-subject subject))
9144           (setq count (1+ count)))))
9145       (gnus-set-mode-line 'summary)
9146       ;; Return the number of marked articles.
9147       count)))
9148
9149 (defun gnus-summary-mark-as-processable (n &optional unmark)
9150   "Set the process mark on the next N articles.
9151 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9152 the process mark instead.  The difference between N and the actual
9153 number of articles marked is returned."
9154   (interactive "P")
9155   (if (and (null n) (gnus-region-active-p))
9156       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9157     (setq n (prefix-numeric-value n))
9158     (let ((backward (< n 0))
9159           (n (abs n)))
9160       (while (and
9161               (> n 0)
9162               (if unmark
9163                   (gnus-summary-remove-process-mark
9164                    (gnus-summary-article-number))
9165                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9166               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9167         (setq n (1- n)))
9168       (when (/= 0 n)
9169         (gnus-message 7 "No more articles"))
9170       (gnus-summary-recenter)
9171       (gnus-summary-position-point)
9172       n)))
9173
9174 (defun gnus-summary-unmark-as-processable (n)
9175   "Remove the process mark from the next N articles.
9176 If N is negative, unmark backward instead.  The difference between N and
9177 the actual number of articles unmarked is returned."
9178   (interactive "P")
9179   (gnus-summary-mark-as-processable n t))
9180
9181 (defun gnus-summary-unmark-all-processable ()
9182   "Remove the process mark from all articles."
9183   (interactive)
9184   (save-excursion
9185     (while gnus-newsgroup-processable
9186       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9187   (gnus-summary-position-point))
9188
9189 (defun gnus-summary-add-mark (article type)
9190   "Mark ARTICLE with a mark of TYPE."
9191   (let ((vtype (car (assq type gnus-article-mark-lists)))
9192         var)
9193     (if (not vtype)
9194         (error "No such mark type: %s" type)
9195       (setq var (intern (format "gnus-newsgroup-%s" type)))
9196       (set var (cons article (symbol-value var)))
9197       (if (memq type '(processable cached replied forwarded recent saved))
9198           (gnus-summary-update-secondary-mark article)
9199         ;;; !!! This is bogus.  We should find out what primary
9200         ;;; !!! mark we want to set.
9201         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9202
9203 (defun gnus-summary-mark-as-expirable (n)
9204   "Mark N articles forward as expirable.
9205 If N is negative, mark backward instead.  The difference between N and
9206 the actual number of articles marked is returned."
9207   (interactive "p")
9208   (gnus-summary-mark-forward n gnus-expirable-mark))
9209
9210 (defun gnus-summary-mark-article-as-replied (article)
9211   "Mark ARTICLE as replied to and update the summary line.
9212 ARTICLE can also be a list of articles."
9213   (interactive (list (gnus-summary-article-number)))
9214   (let ((articles (if (listp article) article (list article))))
9215     (dolist (article articles)
9216       (push article gnus-newsgroup-replied)
9217       (let ((buffer-read-only nil))
9218         (when (gnus-summary-goto-subject article nil t)
9219           (gnus-summary-update-secondary-mark article))))))
9220
9221 (defun gnus-summary-mark-article-as-forwarded (article)
9222   "Mark ARTICLE as forwarded and update the summary line.
9223 ARTICLE can also be a list of articles."
9224   (let ((articles (if (listp article) article (list article))))
9225     (dolist (article articles)
9226       (push article gnus-newsgroup-forwarded)
9227       (let ((buffer-read-only nil))
9228         (when (gnus-summary-goto-subject article nil t)
9229           (gnus-summary-update-secondary-mark article))))))
9230
9231 (defun gnus-summary-set-bookmark (article)
9232   "Set a bookmark in current article."
9233   (interactive (list (gnus-summary-article-number)))
9234   (when (or (not (get-buffer gnus-article-buffer))
9235             (not gnus-current-article)
9236             (not gnus-article-current)
9237             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9238     (error "No current article selected"))
9239   ;; Remove old bookmark, if one exists.
9240   (let ((old (assq article gnus-newsgroup-bookmarks)))
9241     (when old
9242       (setq gnus-newsgroup-bookmarks
9243             (delq old gnus-newsgroup-bookmarks))))
9244   ;; Set the new bookmark, which is on the form
9245   ;; (article-number . line-number-in-body).
9246   (push
9247    (cons article
9248          (save-excursion
9249            (set-buffer gnus-article-buffer)
9250            (count-lines
9251             (min (point)
9252                  (save-excursion
9253                    (goto-char (point-min))
9254                    (search-forward "\n\n" nil t)
9255                    (point)))
9256             (point))))
9257    gnus-newsgroup-bookmarks)
9258   (gnus-message 6 "A bookmark has been added to the current article."))
9259
9260 (defun gnus-summary-remove-bookmark (article)
9261   "Remove the bookmark from the current article."
9262   (interactive (list (gnus-summary-article-number)))
9263   ;; Remove old bookmark, if one exists.
9264   (let ((old (assq article gnus-newsgroup-bookmarks)))
9265     (if old
9266         (progn
9267           (setq gnus-newsgroup-bookmarks
9268                 (delq old gnus-newsgroup-bookmarks))
9269           (gnus-message 6 "Removed bookmark."))
9270       (gnus-message 6 "No bookmark in current article."))))
9271
9272 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9273 (defun gnus-summary-mark-as-dormant (n)
9274   "Mark N articles forward as dormant.
9275 If N is negative, mark backward instead.  The difference between N and
9276 the actual number of articles marked is returned."
9277   (interactive "p")
9278   (gnus-summary-mark-forward n gnus-dormant-mark))
9279
9280 (defun gnus-summary-set-process-mark (article)
9281   "Set the process mark on ARTICLE and update the summary line."
9282   (setq gnus-newsgroup-processable
9283         (cons article
9284               (delq article gnus-newsgroup-processable)))
9285   (when (gnus-summary-goto-subject article)
9286     (gnus-summary-show-thread)
9287     (gnus-summary-goto-subject article)
9288     (gnus-summary-update-secondary-mark article)))
9289
9290 (defun gnus-summary-remove-process-mark (article)
9291   "Remove the process mark from ARTICLE and update the summary line."
9292   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9293   (when (gnus-summary-goto-subject article)
9294     (gnus-summary-show-thread)
9295     (gnus-summary-goto-subject article)
9296     (gnus-summary-update-secondary-mark article)))
9297
9298 (defun gnus-summary-set-saved-mark (article)
9299   "Set the process mark on ARTICLE and update the summary line."
9300   (push article gnus-newsgroup-saved)
9301   (when (gnus-summary-goto-subject article)
9302     (gnus-summary-update-secondary-mark article)))
9303
9304 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9305   "Mark N articles as read forwards.
9306 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9307 The difference between N and the actual number of articles marked is
9308 returned.
9309 Iff NO-EXPIRE, auto-expiry will be inhibited."
9310   (interactive "p")
9311   (gnus-summary-show-thread)
9312   (let ((backward (< n 0))
9313         (gnus-summary-goto-unread
9314          (and gnus-summary-goto-unread
9315               (not (eq gnus-summary-goto-unread 'never))
9316               (not (memq mark (list gnus-unread-mark
9317                                     gnus-ticked-mark gnus-dormant-mark)))))
9318         (n (abs n))
9319         (mark (or mark gnus-del-mark)))
9320     (while (and (> n 0)
9321                 (gnus-summary-mark-article nil mark no-expire)
9322                 (zerop (gnus-summary-next-subject
9323                         (if backward -1 1)
9324                         (and gnus-summary-goto-unread
9325                              (not (eq gnus-summary-goto-unread 'never)))
9326                         t)))
9327       (setq n (1- n)))
9328     (when (/= 0 n)
9329       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9330     (gnus-summary-recenter)
9331     (gnus-summary-position-point)
9332     (gnus-set-mode-line 'summary)
9333     n))
9334
9335 (defun gnus-summary-mark-article-as-read (mark)
9336   "Mark the current article quickly as read with MARK."
9337   (let ((article (gnus-summary-article-number)))
9338     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9339     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9340     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9341     (push (cons article mark) gnus-newsgroup-reads)
9342     ;; Possibly remove from cache, if that is used.
9343     (when gnus-use-cache
9344       (gnus-cache-enter-remove-article article))
9345     ;; Allow the backend to change the mark.
9346     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9347     ;; Check for auto-expiry.
9348     (when (and gnus-newsgroup-auto-expire
9349                (memq mark gnus-auto-expirable-marks))
9350       (setq mark gnus-expirable-mark)
9351       ;; Let the backend know about the mark change.
9352       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9353       (push article gnus-newsgroup-expirable))
9354     ;; Set the mark in the buffer.
9355     (gnus-summary-update-mark mark 'unread)
9356     t))
9357
9358 (defun gnus-summary-mark-article-as-unread (mark)
9359   "Mark the current article quickly as unread with MARK."
9360   (let* ((article (gnus-summary-article-number))
9361          (old-mark (gnus-summary-article-mark article)))
9362     ;; Allow the backend to change the mark.
9363     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9364     (if (eq mark old-mark)
9365         t
9366       (if (<= article 0)
9367           (progn
9368             (gnus-error 1 "Can't mark negative article numbers")
9369             nil)
9370         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9371         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9372         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9373         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9374         (cond ((= mark gnus-ticked-mark)
9375                (setq gnus-newsgroup-marked
9376                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9377                                               article)))
9378               ((= mark gnus-dormant-mark)
9379                (setq gnus-newsgroup-dormant
9380                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9381                                               article)))
9382               (t
9383                (setq gnus-newsgroup-unreads
9384                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9385                                               article))))
9386         (gnus-pull article gnus-newsgroup-reads)
9387
9388         ;; See whether the article is to be put in the cache.
9389         (and gnus-use-cache
9390              (vectorp (gnus-summary-article-header article))
9391              (save-excursion
9392                (gnus-cache-possibly-enter-article
9393                 gnus-newsgroup-name article
9394                 (gnus-summary-article-header article)
9395                 (= mark gnus-ticked-mark)
9396                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9397
9398         ;; Fix the mark.
9399         (gnus-summary-update-mark mark 'unread)
9400         t))))
9401
9402 (defun gnus-summary-mark-article (&optional article mark no-expire)
9403   "Mark ARTICLE with MARK.  MARK can be any character.
9404 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9405 `??' (dormant) and `?E' (expirable).
9406 If MARK is nil, then the default character `?r' is used.
9407 If ARTICLE is nil, then the article on the current line will be
9408 marked.
9409 Iff NO-EXPIRE, auto-expiry will be inhibited."
9410   ;; The mark might be a string.
9411   (when (stringp mark)
9412     (setq mark (aref mark 0)))
9413   ;; If no mark is given, then we check auto-expiring.
9414   (when (null mark)
9415     (setq mark gnus-del-mark))
9416   (when (and (not no-expire)
9417              gnus-newsgroup-auto-expire
9418              (memq mark gnus-auto-expirable-marks))
9419     (setq mark gnus-expirable-mark))
9420   (let ((article (or article (gnus-summary-article-number)))
9421         (old-mark (gnus-summary-article-mark article)))
9422     ;; Allow the backend to change the mark.
9423     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9424     (if (eq mark old-mark)
9425         t
9426       (unless article
9427         (error "No article on current line"))
9428       (if (not (if (or (= mark gnus-unread-mark)
9429                        (= mark gnus-ticked-mark)
9430                        (= mark gnus-dormant-mark))
9431                    (gnus-mark-article-as-unread article mark)
9432                  (gnus-mark-article-as-read article mark)))
9433           t
9434         ;; See whether the article is to be put in the cache.
9435         (and gnus-use-cache
9436              (not (= mark gnus-canceled-mark))
9437              (vectorp (gnus-summary-article-header article))
9438              (save-excursion
9439                (gnus-cache-possibly-enter-article
9440                 gnus-newsgroup-name article
9441                 (gnus-summary-article-header article)
9442                 (= mark gnus-ticked-mark)
9443                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9444
9445         (when (gnus-summary-goto-subject article nil t)
9446           (let ((buffer-read-only nil))
9447             (gnus-summary-show-thread)
9448             ;; Fix the mark.
9449             (gnus-summary-update-mark mark 'unread)
9450             t))))))
9451
9452 (defun gnus-summary-update-secondary-mark (article)
9453   "Update the secondary (read, process, cache) mark."
9454   (gnus-summary-update-mark
9455    (cond ((memq article gnus-newsgroup-processable)
9456           gnus-process-mark)
9457          ((memq article gnus-newsgroup-cached)
9458           gnus-cached-mark)
9459          ((memq article gnus-newsgroup-replied)
9460           gnus-replied-mark)
9461          ((memq article gnus-newsgroup-forwarded)
9462           gnus-forwarded-mark)
9463          ((memq article gnus-newsgroup-saved)
9464           gnus-saved-mark)
9465          ((memq article gnus-newsgroup-recent)
9466           gnus-recent-mark)
9467          ((memq article gnus-newsgroup-unseen)
9468           gnus-unseen-mark)
9469          (t gnus-no-mark))
9470    'replied)
9471   (when (gnus-visual-p 'summary-highlight 'highlight)
9472     (gnus-run-hooks 'gnus-summary-update-hook))
9473   t)
9474
9475 (defun gnus-summary-update-mark (mark type)
9476   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9477         (buffer-read-only nil))
9478     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9479     (when forward
9480       (when (looking-at "\r")
9481         (incf forward))
9482       (when (<= (+ forward (point)) (point-max))
9483         ;; Go to the right position on the line.
9484         (goto-char (+ forward (point)))
9485         ;; Replace the old mark with the new mark.
9486         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9487         ;; Optionally update the marks by some user rule.
9488         (when (eq type 'unread)
9489           (gnus-data-set-mark
9490            (gnus-data-find (gnus-summary-article-number)) mark)
9491           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9492
9493 (defun gnus-mark-article-as-read (article &optional mark)
9494   "Enter ARTICLE in the pertinent lists and remove it from others."
9495   ;; Make the article expirable.
9496   (let ((mark (or mark gnus-del-mark)))
9497     (setq gnus-newsgroup-expirable
9498           (if (= mark gnus-expirable-mark)
9499               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
9500             (delq article gnus-newsgroup-expirable)))
9501     ;; Remove from unread and marked lists.
9502     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9503     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9504     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9505     (push (cons article mark) gnus-newsgroup-reads)
9506     ;; Possibly remove from cache, if that is used.
9507     (when gnus-use-cache
9508       (gnus-cache-enter-remove-article article))
9509     t))
9510
9511 (defun gnus-mark-article-as-unread (article &optional mark)
9512   "Enter ARTICLE in the pertinent lists and remove it from others."
9513   (let ((mark (or mark gnus-ticked-mark)))
9514     (if (<= article 0)
9515         (progn
9516           (gnus-error 1 "Can't mark negative article numbers")
9517           nil)
9518       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9519             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9520             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9521             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9522
9523       ;; Unsuppress duplicates?
9524       (when gnus-suppress-duplicates
9525         (gnus-dup-unsuppress-article article))
9526
9527       (cond ((= mark gnus-ticked-mark)
9528              (setq gnus-newsgroup-marked
9529                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
9530             ((= mark gnus-dormant-mark)
9531              (setq gnus-newsgroup-dormant
9532                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
9533             (t
9534              (setq gnus-newsgroup-unreads
9535                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
9536       (gnus-pull article gnus-newsgroup-reads)
9537       t)))
9538
9539 (defalias 'gnus-summary-mark-as-unread-forward
9540   'gnus-summary-tick-article-forward)
9541 (make-obsolete 'gnus-summary-mark-as-unread-forward
9542                'gnus-summary-tick-article-forward)
9543 (defun gnus-summary-tick-article-forward (n)
9544   "Tick N articles forwards.
9545 If N is negative, tick backwards instead.
9546 The difference between N and the number of articles ticked is returned."
9547   (interactive "p")
9548   (gnus-summary-mark-forward n gnus-ticked-mark))
9549
9550 (defalias 'gnus-summary-mark-as-unread-backward
9551   'gnus-summary-tick-article-backward)
9552 (make-obsolete 'gnus-summary-mark-as-unread-backward
9553                'gnus-summary-tick-article-backward)
9554 (defun gnus-summary-tick-article-backward (n)
9555   "Tick N articles backwards.
9556 The difference between N and the number of articles ticked is returned."
9557   (interactive "p")
9558   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9559
9560 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9561 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9562 (defun gnus-summary-tick-article (&optional article clear-mark)
9563   "Mark current article as unread.
9564 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9565 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9566   (interactive)
9567   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9568                                        gnus-ticked-mark)))
9569
9570 (defun gnus-summary-mark-as-read-forward (n)
9571   "Mark N articles as read forwards.
9572 If N is negative, mark backwards instead.
9573 The difference between N and the actual number of articles marked is
9574 returned."
9575   (interactive "p")
9576   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9577
9578 (defun gnus-summary-mark-as-read-backward (n)
9579   "Mark the N articles as read backwards.
9580 The difference between N and the actual number of articles marked is
9581 returned."
9582   (interactive "p")
9583   (gnus-summary-mark-forward
9584    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9585
9586 (defun gnus-summary-mark-as-read (&optional article mark)
9587   "Mark current article as read.
9588 ARTICLE specifies the article to be marked as read.
9589 MARK specifies a string to be inserted at the beginning of the line."
9590   (gnus-summary-mark-article article mark))
9591
9592 (defun gnus-summary-clear-mark-forward (n)
9593   "Clear marks from N articles forward.
9594 If N is negative, clear backward instead.
9595 The difference between N and the number of marks cleared is returned."
9596   (interactive "p")
9597   (gnus-summary-mark-forward n gnus-unread-mark))
9598
9599 (defun gnus-summary-clear-mark-backward (n)
9600   "Clear marks from N articles backward.
9601 The difference between N and the number of marks cleared is returned."
9602   (interactive "p")
9603   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9604
9605 (defun gnus-summary-mark-unread-as-read ()
9606   "Intended to be used by `gnus-summary-mark-article-hook'."
9607   (when (memq gnus-current-article gnus-newsgroup-unreads)
9608     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9609
9610 (defun gnus-summary-mark-read-and-unread-as-read ()
9611   "Intended to be used by `gnus-summary-mark-article-hook'."
9612   (let ((mark (gnus-summary-article-mark)))
9613     (when (or (gnus-unread-mark-p mark)
9614               (gnus-read-mark-p mark))
9615       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9616
9617 (defun gnus-summary-mark-unread-as-ticked ()
9618   "Intended to be used by `gnus-summary-mark-article-hook'."
9619   (when (memq gnus-current-article gnus-newsgroup-unreads)
9620     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9621
9622 (defun gnus-summary-mark-region-as-read (point mark all)
9623   "Mark all unread articles between point and mark as read.
9624 If given a prefix, mark all articles between point and mark as read,
9625 even ticked and dormant ones."
9626   (interactive "r\nP")
9627   (save-excursion
9628     (let (article)
9629       (goto-char point)
9630       (beginning-of-line)
9631       (while (and
9632               (< (point) mark)
9633               (progn
9634                 (when (or all
9635                           (memq (setq article (gnus-summary-article-number))
9636                                 gnus-newsgroup-unreads))
9637                   (gnus-summary-mark-article article gnus-del-mark))
9638                 t)
9639               (gnus-summary-find-next))))))
9640
9641 (defun gnus-summary-mark-below (score mark)
9642   "Mark articles with score less than SCORE with MARK."
9643   (interactive "P\ncMark: ")
9644   (setq score (if score
9645                   (prefix-numeric-value score)
9646                 (or gnus-summary-default-score 0)))
9647   (save-excursion
9648     (set-buffer gnus-summary-buffer)
9649     (goto-char (point-min))
9650     (while
9651         (progn
9652           (and (< (gnus-summary-article-score) score)
9653                (gnus-summary-mark-article nil mark))
9654           (gnus-summary-find-next)))))
9655
9656 (defun gnus-summary-kill-below (&optional score)
9657   "Mark articles with score below SCORE as read."
9658   (interactive "P")
9659   (gnus-summary-mark-below score gnus-killed-mark))
9660
9661 (defun gnus-summary-clear-above (&optional score)
9662   "Clear all marks from articles with score above SCORE."
9663   (interactive "P")
9664   (gnus-summary-mark-above score gnus-unread-mark))
9665
9666 (defun gnus-summary-tick-above (&optional score)
9667   "Tick all articles with score above SCORE."
9668   (interactive "P")
9669   (gnus-summary-mark-above score gnus-ticked-mark))
9670
9671 (defun gnus-summary-mark-above (score mark)
9672   "Mark articles with score over SCORE with MARK."
9673   (interactive "P\ncMark: ")
9674   (setq score (if score
9675                   (prefix-numeric-value score)
9676                 (or gnus-summary-default-score 0)))
9677   (save-excursion
9678     (set-buffer gnus-summary-buffer)
9679     (goto-char (point-min))
9680     (while (and (progn
9681                   (when (> (gnus-summary-article-score) score)
9682                     (gnus-summary-mark-article nil mark))
9683                   t)
9684                 (gnus-summary-find-next)))))
9685
9686 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9687 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9688 (defun gnus-summary-limit-include-expunged (&optional no-error)
9689   "Display all the hidden articles that were expunged for low scores."
9690   (interactive)
9691   (let ((buffer-read-only nil))
9692     (let ((scored gnus-newsgroup-scored)
9693           headers h)
9694       (while scored
9695         (unless (gnus-summary-article-header (caar scored))
9696           (and (setq h (gnus-number-to-header (caar scored)))
9697                (< (cdar scored) gnus-summary-expunge-below)
9698                (push h headers)))
9699         (setq scored (cdr scored)))
9700       (if (not headers)
9701           (when (not no-error)
9702             (error "No expunged articles hidden"))
9703         (goto-char (point-min))
9704         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9705         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9706         (mapcar (lambda (x) (push (mail-header-number x)
9707                                   gnus-newsgroup-limit))
9708                 headers)
9709         (gnus-summary-prepare-unthreaded (nreverse headers))
9710         (goto-char (point-min))
9711         (gnus-summary-position-point)
9712         t))))
9713
9714 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9715   "Mark all unread articles in this newsgroup as read.
9716 If prefix argument ALL is non-nil, ticked and dormant articles will
9717 also be marked as read.
9718 If QUIETLY is non-nil, no questions will be asked.
9719 If TO-HERE is non-nil, it should be a point in the buffer.  All
9720 articles before (after, if REVERSE is set) this point will be marked as read.
9721 Note that this function will only catch up the unread article
9722 in the current summary buffer limitation.
9723 The number of articles marked as read is returned."
9724   (interactive "P")
9725   (prog1
9726       (save-excursion
9727         (when (or quietly
9728                   (not gnus-interactive-catchup) ;Without confirmation?
9729                   gnus-expert-user
9730                   (gnus-y-or-n-p
9731                    (if all
9732                        "Mark absolutely all articles as read? "
9733                      "Mark all unread articles as read? ")))
9734           (if (and not-mark
9735                    (not gnus-newsgroup-adaptive)
9736                    (not gnus-newsgroup-auto-expire)
9737                    (not gnus-suppress-duplicates)
9738                    (or (not gnus-use-cache)
9739                        (eq gnus-use-cache 'passive)))
9740               (progn
9741                 (when all
9742                   (setq gnus-newsgroup-marked nil
9743                         gnus-newsgroup-dormant nil))
9744                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9745             ;; We actually mark all articles as canceled, which we
9746             ;; have to do when using auto-expiry or adaptive scoring.
9747             (gnus-summary-show-all-threads)
9748             (if (and to-here reverse)
9749                 (progn
9750                   (goto-char to-here)
9751                   (while (and
9752                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9753                           (gnus-summary-find-next (not all) nil nil t))))
9754               (when (gnus-summary-first-subject (not all) t)
9755                 (while (and
9756                         (if to-here (< (point) to-here) t)
9757                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9758                         (gnus-summary-find-next (not all) nil nil t)))))
9759             (gnus-set-mode-line 'summary))
9760           t))
9761     (gnus-summary-position-point)))
9762
9763 (defun gnus-summary-catchup-to-here (&optional all)
9764   "Mark all unticked articles before the current one as read.
9765 If ALL is non-nil, also mark ticked and dormant articles as read."
9766   (interactive "P")
9767   (save-excursion
9768     (gnus-save-hidden-threads
9769       (let ((beg (point)))
9770         ;; We check that there are unread articles.
9771         (when (or all (gnus-summary-find-prev))
9772           (gnus-summary-catchup all t beg)))))
9773   (gnus-summary-position-point))
9774
9775 (defun gnus-summary-catchup-from-here (&optional all)
9776   "Mark all unticked articles after the current one as read.
9777 If ALL is non-nil, also mark ticked and dormant articles as read."
9778   (interactive "P")
9779   (save-excursion
9780     (gnus-save-hidden-threads
9781       (let ((beg (point)))
9782         ;; We check that there are unread articles.
9783         (when (or all (gnus-summary-find-next))
9784           (gnus-summary-catchup all t beg nil t)))))
9785   (gnus-summary-position-point))
9786
9787 (defun gnus-summary-catchup-all (&optional quietly)
9788   "Mark all articles in this newsgroup as read."
9789   (interactive "P")
9790   (gnus-summary-catchup t quietly))
9791
9792 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9793   "Mark all unread articles in this group as read, then exit.
9794 If prefix argument ALL is non-nil, all articles are marked as read.
9795 If QUIETLY is non-nil, no questions will be asked."
9796   (interactive "P")
9797   (when (gnus-summary-catchup all quietly nil 'fast)
9798     ;; Select next newsgroup or exit.
9799     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9800              (eq gnus-auto-select-next 'quietly))
9801         (gnus-summary-next-group nil)
9802       (gnus-summary-exit))))
9803
9804 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9805   "Mark all articles in this newsgroup as read, and then exit."
9806   (interactive "P")
9807   (gnus-summary-catchup-and-exit t quietly))
9808
9809 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9810   "Mark all articles in this group as read and select the next group.
9811 If given a prefix, mark all articles, unread as well as ticked, as
9812 read."
9813   (interactive "P")
9814   (save-excursion
9815     (gnus-summary-catchup all))
9816   (gnus-summary-next-group))
9817
9818 ;;;
9819 ;;; with article
9820 ;;;
9821
9822 (defmacro gnus-with-article (article &rest forms)
9823   "Select ARTICLE and perform FORMS in the original article buffer.
9824 Then replace the article with the result."
9825   `(progn
9826      ;; We don't want the article to be marked as read.
9827      (let (gnus-mark-article-hook)
9828        (gnus-summary-select-article t t nil ,article))
9829      (set-buffer gnus-original-article-buffer)
9830      ,@forms
9831      (if (not (gnus-check-backend-function
9832                'request-replace-article (car gnus-article-current)))
9833          (gnus-message 5 "Read-only group; not replacing")
9834        (unless (gnus-request-replace-article
9835                 ,article (car gnus-article-current)
9836                 (current-buffer) t)
9837          (error "Couldn't replace article")))
9838      ;; The cache and backlog have to be flushed somewhat.
9839      (when gnus-keep-backlog
9840        (gnus-backlog-remove-article
9841         (car gnus-article-current) (cdr gnus-article-current)))
9842      (when gnus-use-cache
9843        (gnus-cache-update-article
9844         (car gnus-article-current) (cdr gnus-article-current)))))
9845
9846 (put 'gnus-with-article 'lisp-indent-function 1)
9847 (put 'gnus-with-article 'edebug-form-spec '(form body))
9848
9849 ;; Thread-based commands.
9850
9851 (defun gnus-summary-articles-in-thread (&optional article)
9852   "Return a list of all articles in the current thread.
9853 If ARTICLE is non-nil, return all articles in the thread that starts
9854 with that article."
9855   (let* ((article (or article (gnus-summary-article-number)))
9856          (data (gnus-data-find-list article))
9857          (top-level (gnus-data-level (car data)))
9858          (top-subject
9859           (cond ((null gnus-thread-operation-ignore-subject)
9860                  (gnus-simplify-subject-re
9861                   (mail-header-subject (gnus-data-header (car data)))))
9862                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9863                  (gnus-simplify-subject-fuzzy
9864                   (mail-header-subject (gnus-data-header (car data)))))
9865                 (t nil)))
9866          (end-point (save-excursion
9867                       (if (gnus-summary-go-to-next-thread)
9868                           (point) (point-max))))
9869          articles)
9870     (while (and data
9871                 (< (gnus-data-pos (car data)) end-point))
9872       (when (or (not top-subject)
9873                 (string= top-subject
9874                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9875                              (gnus-simplify-subject-fuzzy
9876                               (mail-header-subject
9877                                (gnus-data-header (car data))))
9878                            (gnus-simplify-subject-re
9879                             (mail-header-subject
9880                              (gnus-data-header (car data)))))))
9881         (push (gnus-data-number (car data)) articles))
9882       (unless (and (setq data (cdr data))
9883                    (> (gnus-data-level (car data)) top-level))
9884         (setq data nil)))
9885     ;; Return the list of articles.
9886     (nreverse articles)))
9887
9888 (defun gnus-summary-rethread-current ()
9889   "Rethread the thread the current article is part of."
9890   (interactive)
9891   (let* ((gnus-show-threads t)
9892          (article (gnus-summary-article-number))
9893          (id (mail-header-id (gnus-summary-article-header)))
9894          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9895     (unless id
9896       (error "No article on the current line"))
9897     (gnus-rebuild-thread id)
9898     (gnus-summary-goto-subject article)))
9899
9900 (defun gnus-summary-reparent-thread ()
9901   "Make the current article child of the marked (or previous) article.
9902
9903 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9904 is non-nil or the Subject: of both articles are the same."
9905   (interactive)
9906   (unless (not (gnus-group-read-only-p))
9907     (error "The current newsgroup does not support article editing"))
9908   (unless (<= (length gnus-newsgroup-processable) 1)
9909     (error "No more than one article may be marked"))
9910   (save-window-excursion
9911     (let ((gnus-article-buffer " *reparent*")
9912           (current-article (gnus-summary-article-number))
9913           ;; First grab the marked article, otherwise one line up.
9914           (parent-article (if (not (null gnus-newsgroup-processable))
9915                               (car gnus-newsgroup-processable)
9916                             (save-excursion
9917                               (if (eq (forward-line -1) 0)
9918                                   (gnus-summary-article-number)
9919                                 (error "Beginning of summary buffer"))))))
9920       (unless (not (eq current-article parent-article))
9921         (error "An article may not be self-referential"))
9922       (let ((message-id (mail-header-id
9923                          (gnus-summary-article-header parent-article))))
9924         (unless (and message-id (not (equal message-id "")))
9925           (error "No message-id in desired parent"))
9926         (gnus-with-article current-article
9927           (save-restriction
9928             (goto-char (point-min))
9929             (message-narrow-to-head)
9930             (if (re-search-forward "^References: " nil t)
9931                 (progn
9932                   (re-search-forward "^[^ \t]" nil t)
9933                   (forward-line -1)
9934                   (end-of-line)
9935                   (insert " " message-id))
9936               (insert "References: " message-id "\n"))))
9937         (set-buffer gnus-summary-buffer)
9938         (gnus-summary-unmark-all-processable)
9939         (gnus-summary-update-article current-article)
9940         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9941             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9942         (gnus-summary-rethread-current)
9943         (gnus-message 3 "Article %d is now the child of article %d"
9944                       current-article parent-article)))))
9945
9946 (defun gnus-summary-toggle-threads (&optional arg)
9947   "Toggle showing conversation threads.
9948 If ARG is positive number, turn showing conversation threads on."
9949   (interactive "P")
9950   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9951     (setq gnus-show-threads
9952           (if (null arg) (not gnus-show-threads)
9953             (> (prefix-numeric-value arg) 0)))
9954     (gnus-summary-prepare)
9955     (gnus-summary-goto-subject current)
9956     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9957     (gnus-summary-position-point)))
9958
9959 (defun gnus-summary-show-all-threads ()
9960   "Show all threads."
9961   (interactive)
9962   (save-excursion
9963     (let ((buffer-read-only nil))
9964       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9965   (gnus-summary-position-point))
9966
9967 (defun gnus-summary-show-thread ()
9968   "Show thread subtrees.
9969 Returns nil if no thread was there to be shown."
9970   (interactive)
9971   (let ((buffer-read-only nil)
9972         (orig (point))
9973         ;; first goto end then to beg, to have point at beg after let
9974         (end (progn (end-of-line) (point)))
9975         (beg (progn (beginning-of-line) (point))))
9976     (prog1
9977         ;; Any hidden lines here?
9978         (search-forward "\r" end t)
9979       (subst-char-in-region beg end ?\^M ?\n t)
9980       (goto-char orig)
9981       (gnus-summary-position-point))))
9982
9983 (defun gnus-summary-maybe-hide-threads ()
9984   "If requested, hide the threads that should be hidden."
9985   (when (and gnus-show-threads
9986              gnus-thread-hide-subtree)
9987     (gnus-summary-hide-all-threads
9988      (if (or (consp gnus-thread-hide-subtree)
9989              (gnus-functionp gnus-thread-hide-subtree))
9990          (gnus-make-predicate gnus-thread-hide-subtree)
9991        nil))))
9992
9993 ;;; Hiding predicates.
9994
9995 (defun gnus-article-unread-p (header)
9996   (memq (mail-header-number header) gnus-newsgroup-unreads))
9997
9998 (defun gnus-article-unseen-p (header)
9999   (memq (mail-header-number header) gnus-newsgroup-unseen))
10000
10001 (defun gnus-map-articles (predicate articles)
10002   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10003   (apply 'gnus-or (mapcar predicate
10004                           (mapcar 'gnus-summary-article-header articles))))
10005
10006 (defun gnus-summary-hide-all-threads (&optional predicate)
10007   "Hide all thread subtrees.
10008 If PREDICATE is supplied, threads that satisfy this predicate
10009 will not be hidden."
10010   (interactive)
10011   (save-excursion
10012     (goto-char (point-min))
10013     (let ((end nil))
10014       (while (not end)
10015         (when (or (not predicate)
10016                   (gnus-map-articles
10017                    predicate (gnus-summary-article-children)))
10018             (gnus-summary-hide-thread))
10019         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10020   (gnus-summary-position-point))
10021
10022 (defun gnus-summary-hide-thread ()
10023   "Hide thread subtrees.
10024 If PREDICATE is supplied, threads that satisfy this predicate
10025 will not be hidden.
10026 Returns nil if no threads were there to be hidden."
10027   (interactive)
10028   (let ((buffer-read-only nil)
10029         (start (point))
10030         (article (gnus-summary-article-number)))
10031     (goto-char start)
10032     ;; Go forward until either the buffer ends or the subthread
10033     ;; ends.
10034     (when (and (not (eobp))
10035                (or (zerop (gnus-summary-next-thread 1 t))
10036                    (goto-char (point-max))))
10037       (prog1
10038           (if (and (> (point) start)
10039                    (search-backward "\n" start t))
10040               (progn
10041                 (subst-char-in-region start (point) ?\n ?\^M)
10042                 (gnus-summary-goto-subject article))
10043             (goto-char start)
10044             nil)))))
10045
10046 (defun gnus-summary-go-to-next-thread (&optional previous)
10047   "Go to the same level (or less) next thread.
10048 If PREVIOUS is non-nil, go to previous thread instead.
10049 Return the article number moved to, or nil if moving was impossible."
10050   (let ((level (gnus-summary-thread-level))
10051         (way (if previous -1 1))
10052         (beg (point)))
10053     (forward-line way)
10054     (while (and (not (eobp))
10055                 (< level (gnus-summary-thread-level)))
10056       (forward-line way))
10057     (if (eobp)
10058         (progn
10059           (goto-char beg)
10060           nil)
10061       (setq beg (point))
10062       (prog1
10063           (gnus-summary-article-number)
10064         (goto-char beg)))))
10065
10066 (defun gnus-summary-next-thread (n &optional silent)
10067   "Go to the same level next N'th thread.
10068 If N is negative, search backward instead.
10069 Returns the difference between N and the number of skips actually
10070 done.
10071
10072 If SILENT, don't output messages."
10073   (interactive "p")
10074   (let ((backward (< n 0))
10075         (n (abs n)))
10076     (while (and (> n 0)
10077                 (gnus-summary-go-to-next-thread backward))
10078       (decf n))
10079     (unless silent
10080       (gnus-summary-position-point))
10081     (when (and (not silent) (/= 0 n))
10082       (gnus-message 7 "No more threads"))
10083     n))
10084
10085 (defun gnus-summary-prev-thread (n)
10086   "Go to the same level previous N'th thread.
10087 Returns the difference between N and the number of skips actually
10088 done."
10089   (interactive "p")
10090   (gnus-summary-next-thread (- n)))
10091
10092 (defun gnus-summary-go-down-thread ()
10093   "Go down one level in the current thread."
10094   (let ((children (gnus-summary-article-children)))
10095     (when children
10096       (gnus-summary-goto-subject (car children)))))
10097
10098 (defun gnus-summary-go-up-thread ()
10099   "Go up one level in the current thread."
10100   (let ((parent (gnus-summary-article-parent)))
10101     (when parent
10102       (gnus-summary-goto-subject parent))))
10103
10104 (defun gnus-summary-down-thread (n)
10105   "Go down thread N steps.
10106 If N is negative, go up instead.
10107 Returns the difference between N and how many steps down that were
10108 taken."
10109   (interactive "p")
10110   (let ((up (< n 0))
10111         (n (abs n)))
10112     (while (and (> n 0)
10113                 (if up (gnus-summary-go-up-thread)
10114                   (gnus-summary-go-down-thread)))
10115       (setq n (1- n)))
10116     (gnus-summary-position-point)
10117     (when (/= 0 n)
10118       (gnus-message 7 "Can't go further"))
10119     n))
10120
10121 (defun gnus-summary-up-thread (n)
10122   "Go up thread N steps.
10123 If N is negative, go down instead.
10124 Returns the difference between N and how many steps down that were
10125 taken."
10126   (interactive "p")
10127   (gnus-summary-down-thread (- n)))
10128
10129 (defun gnus-summary-top-thread ()
10130   "Go to the top of the thread."
10131   (interactive)
10132   (while (gnus-summary-go-up-thread))
10133   (gnus-summary-article-number))
10134
10135 (defun gnus-summary-kill-thread (&optional unmark)
10136   "Mark articles under current thread as read.
10137 If the prefix argument is positive, remove any kinds of marks.
10138 If the prefix argument is negative, tick articles instead."
10139   (interactive "P")
10140   (when unmark
10141     (setq unmark (prefix-numeric-value unmark)))
10142   (let ((articles (gnus-summary-articles-in-thread)))
10143     (save-excursion
10144       ;; Expand the thread.
10145       (gnus-summary-show-thread)
10146       ;; Mark all the articles.
10147       (while articles
10148         (gnus-summary-goto-subject (car articles))
10149         (cond ((null unmark)
10150                (gnus-summary-mark-article-as-read gnus-killed-mark))
10151               ((> unmark 0)
10152                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10153               (t
10154                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10155         (setq articles (cdr articles))))
10156     ;; Hide killed subtrees.
10157     (and (null unmark)
10158          gnus-thread-hide-killed
10159          (gnus-summary-hide-thread))
10160     ;; If marked as read, go to next unread subject.
10161     (when (null unmark)
10162       ;; Go to next unread subject.
10163       (gnus-summary-next-subject 1 t)))
10164   (gnus-set-mode-line 'summary))
10165
10166 ;; Summary sorting commands
10167
10168 (defun gnus-summary-sort-by-number (&optional reverse)
10169   "Sort the summary buffer by article number.
10170 Argument REVERSE means reverse order."
10171   (interactive "P")
10172   (gnus-summary-sort 'number reverse))
10173
10174 (defun gnus-summary-sort-by-author (&optional reverse)
10175   "Sort the summary buffer by author name alphabetically.
10176 If `case-fold-search' is non-nil, case of letters is ignored.
10177 Argument REVERSE means reverse order."
10178   (interactive "P")
10179   (gnus-summary-sort 'author reverse))
10180
10181 (defun gnus-summary-sort-by-subject (&optional reverse)
10182   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10183 If `case-fold-search' is non-nil, case of letters is ignored.
10184 Argument REVERSE means reverse order."
10185   (interactive "P")
10186   (gnus-summary-sort 'subject reverse))
10187
10188 (defun gnus-summary-sort-by-date (&optional reverse)
10189   "Sort the summary buffer by date.
10190 Argument REVERSE means reverse order."
10191   (interactive "P")
10192   (gnus-summary-sort 'date reverse))
10193
10194 (defun gnus-summary-sort-by-score (&optional reverse)
10195   "Sort the summary buffer by score.
10196 Argument REVERSE means reverse order."
10197   (interactive "P")
10198   (gnus-summary-sort 'score reverse))
10199
10200 (defun gnus-summary-sort-by-lines (&optional reverse)
10201   "Sort the summary buffer by the number of lines.
10202 Argument REVERSE means reverse order."
10203   (interactive "P")
10204   (gnus-summary-sort 'lines reverse))
10205
10206 (defun gnus-summary-sort-by-chars (&optional reverse)
10207   "Sort the summary buffer by article length.
10208 Argument REVERSE means reverse order."
10209   (interactive "P")
10210   (gnus-summary-sort 'chars reverse))
10211
10212 (defun gnus-summary-sort-by-original (&optional reverse)
10213   "Sort the summary buffer using the default sorting method.
10214 Argument REVERSE means reverse order."
10215   (interactive "P")
10216   (let* ((buffer-read-only)
10217          (gnus-summary-prepare-hook nil))
10218     ;; We do the sorting by regenerating the threads.
10219     (gnus-summary-prepare)
10220     ;; Hide subthreads if needed.
10221     (gnus-summary-maybe-hide-threads)))
10222
10223 (defun gnus-summary-sort (predicate reverse)
10224   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10225   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10226          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10227          (gnus-thread-sort-functions
10228           (if (not reverse)
10229               thread
10230             `(lambda (t1 t2)
10231                (,thread t2 t1))))
10232          (gnus-sort-gathered-threads-function
10233           gnus-thread-sort-functions)
10234          (gnus-article-sort-functions
10235           (if (not reverse)
10236               article
10237             `(lambda (t1 t2)
10238                (,article t2 t1))))
10239          (buffer-read-only)
10240          (gnus-summary-prepare-hook nil))
10241     ;; We do the sorting by regenerating the threads.
10242     (gnus-summary-prepare)
10243     ;; Hide subthreads if needed.
10244     (gnus-summary-maybe-hide-threads)))
10245
10246 ;; Summary saving commands.
10247
10248 (defun gnus-summary-save-article (&optional n not-saved)
10249   "Save the current article using the default saver function.
10250 If N is a positive number, save the N next articles.
10251 If N is a negative number, save the N previous articles.
10252 If N is nil and any articles have been marked with the process mark,
10253 save those articles instead.
10254 The variable `gnus-default-article-saver' specifies the saver function."
10255   (interactive "P")
10256   (let* ((articles (gnus-summary-work-articles n))
10257          (save-buffer (save-excursion
10258                         (nnheader-set-temp-buffer " *Gnus Save*")))
10259          (num (length articles))
10260          header file)
10261     (dolist (article articles)
10262       (setq header (gnus-summary-article-header article))
10263       (if (not (vectorp header))
10264           ;; This is a pseudo-article.
10265           (if (assq 'name header)
10266               (gnus-copy-file (cdr (assq 'name header)))
10267             (gnus-message 1 "Article %d is unsaveable" article))
10268         ;; This is a real article.
10269         (save-window-excursion
10270           (let ((gnus-display-mime-function nil)
10271                 (gnus-article-prepare-hook nil))
10272             (gnus-summary-select-article t nil nil article)))
10273         (save-excursion
10274           (set-buffer save-buffer)
10275           (erase-buffer)
10276           (insert-buffer-substring gnus-original-article-buffer))
10277         (setq file (gnus-article-save save-buffer file num))
10278         (gnus-summary-remove-process-mark article)
10279         (unless not-saved
10280           (gnus-summary-set-saved-mark article))))
10281     (gnus-kill-buffer save-buffer)
10282     (gnus-summary-position-point)
10283     (gnus-set-mode-line 'summary)
10284     n))
10285
10286 (defun gnus-summary-pipe-output (&optional arg)
10287   "Pipe the current article to a subprocess.
10288 If N is a positive number, pipe the N next articles.
10289 If N is a negative number, pipe the N previous articles.
10290 If N is nil and any articles have been marked with the process mark,
10291 pipe those articles instead."
10292   (interactive "P")
10293   (require 'gnus-art)
10294   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
10295     (gnus-summary-save-article arg t))
10296   (let ((buffer (get-buffer "*Shell Command Output*")))
10297     (if (and buffer
10298              (with-current-buffer buffer (> (point-max) (point-min))))
10299         (gnus-configure-windows 'pipe))))
10300
10301 (defun gnus-summary-save-article-mail (&optional arg)
10302   "Append the current article to an mail file.
10303 If N is a positive number, save the N next articles.
10304 If N is a negative number, save the N previous articles.
10305 If N is nil and any articles have been marked with the process mark,
10306 save those articles instead."
10307   (interactive "P")
10308   (require 'gnus-art)
10309   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10310     (gnus-summary-save-article arg)))
10311
10312 (defun gnus-summary-save-article-rmail (&optional arg)
10313   "Append the current article to an rmail file.
10314 If N is a positive number, save the N next articles.
10315 If N is a negative number, save the N previous articles.
10316 If N is nil and any articles have been marked with the process mark,
10317 save those articles instead."
10318   (interactive "P")
10319   (require 'gnus-art)
10320   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10321     (gnus-summary-save-article arg)))
10322
10323 (defun gnus-summary-save-article-file (&optional arg)
10324   "Append the current article to a file.
10325 If N is a positive number, save the N next articles.
10326 If N is a negative number, save the N previous articles.
10327 If N is nil and any articles have been marked with the process mark,
10328 save those articles instead."
10329   (interactive "P")
10330   (require 'gnus-art)
10331   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10332     (gnus-summary-save-article arg)))
10333
10334 (defun gnus-summary-write-article-file (&optional arg)
10335   "Write the current article to a file, deleting the previous file.
10336 If N is a positive number, save the N next articles.
10337 If N is a negative number, save the N previous articles.
10338 If N is nil and any articles have been marked with the process mark,
10339 save those articles instead."
10340   (interactive "P")
10341   (require 'gnus-art)
10342   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10343     (gnus-summary-save-article arg)))
10344
10345 (defun gnus-summary-save-article-body-file (&optional arg)
10346   "Append the current article body to a file.
10347 If N is a positive number, save the N next articles.
10348 If N is a negative number, save the N previous articles.
10349 If N is nil and any articles have been marked with the process mark,
10350 save those articles instead."
10351   (interactive "P")
10352   (require 'gnus-art)
10353   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10354     (gnus-summary-save-article arg)))
10355
10356 (defun gnus-summary-muttprint (&optional arg)
10357   "Print the current article using Muttprint.
10358 If N is a positive number, save the N next articles.
10359 If N is a negative number, save the N previous articles.
10360 If N is nil and any articles have been marked with the process mark,
10361 save those articles instead."
10362   (interactive "P")
10363   (require 'gnus-art)
10364   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10365     (gnus-summary-save-article arg t)))
10366
10367 (defun gnus-summary-pipe-message (program)
10368   "Pipe the current article through PROGRAM."
10369   (interactive "sProgram: ")
10370   (gnus-summary-select-article)
10371   (let ((mail-header-separator ""))
10372     (gnus-eval-in-buffer-window gnus-article-buffer
10373       (save-restriction
10374         (widen)
10375         (let ((start (window-start))
10376               buffer-read-only)
10377           (message-pipe-buffer-body program)
10378           (set-window-start (get-buffer-window (current-buffer)) start))))))
10379
10380 (defun gnus-get-split-value (methods)
10381   "Return a value based on the split METHODS."
10382   (let (split-name method result match)
10383     (when methods
10384       (save-excursion
10385         (set-buffer gnus-original-article-buffer)
10386         (save-restriction
10387           (nnheader-narrow-to-headers)
10388           (while (and methods (not split-name))
10389             (goto-char (point-min))
10390             (setq method (pop methods))
10391             (setq match (car method))
10392             (when (cond
10393                    ((stringp match)
10394                     ;; Regular expression.
10395                     (ignore-errors
10396                       (re-search-forward match nil t)))
10397                    ((gnus-functionp match)
10398                     ;; Function.
10399                     (save-restriction
10400                       (widen)
10401                       (setq result (funcall match gnus-newsgroup-name))))
10402                    ((consp match)
10403                     ;; Form.
10404                     (save-restriction
10405                       (widen)
10406                       (setq result (eval match)))))
10407               (setq split-name (cdr method))
10408               (cond ((stringp result)
10409                      (push (expand-file-name
10410                             result gnus-article-save-directory)
10411                            split-name))
10412                     ((consp result)
10413                      (setq split-name (append result split-name)))))))))
10414     (nreverse split-name)))
10415
10416 (defun gnus-valid-move-group-p (group)
10417   (and (boundp group)
10418        (symbol-name group)
10419        (symbol-value group)
10420        (gnus-get-function (gnus-find-method-for-group
10421                            (symbol-name group)) 'request-accept-article t)))
10422
10423 (defun gnus-read-move-group-name (prompt default articles prefix)
10424   "Read a group name."
10425   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10426          (minibuffer-confirm-incomplete nil) ; XEmacs
10427          (prom
10428           (format "%s %s to:"
10429                   prompt
10430                   (if (> (length articles) 1)
10431                       (format "these %d articles" (length articles))
10432                     "this article")))
10433          (to-newsgroup
10434           (cond
10435            ((null split-name)
10436             (gnus-completing-read-with-default
10437              default prom
10438              gnus-active-hashtb
10439              'gnus-valid-move-group-p
10440              nil prefix
10441              'gnus-group-history))
10442            ((= 1 (length split-name))
10443             (gnus-completing-read-with-default
10444              (car split-name) prom
10445              gnus-active-hashtb
10446              'gnus-valid-move-group-p
10447              nil nil
10448              'gnus-group-history))
10449            (t
10450             (gnus-completing-read-with-default
10451              nil prom
10452              (mapcar (lambda (el) (list el))
10453                      (nreverse split-name))
10454              nil nil nil
10455              'gnus-group-history))))
10456          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10457     (when to-newsgroup
10458       (if (or (string= to-newsgroup "")
10459               (string= to-newsgroup prefix))
10460           (setq to-newsgroup default))
10461       (unless to-newsgroup
10462         (error "No group name entered"))
10463       (or (gnus-active to-newsgroup)
10464           (gnus-activate-group to-newsgroup nil nil to-method)
10465           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10466                                      to-newsgroup))
10467               (or (and (gnus-request-create-group to-newsgroup to-method)
10468                        (gnus-activate-group
10469                         to-newsgroup nil nil to-method)
10470                        (gnus-subscribe-group to-newsgroup))
10471                   (error "Couldn't create group %s" to-newsgroup)))
10472           (error "No such group: %s" to-newsgroup)))
10473     to-newsgroup))
10474
10475 (defun gnus-summary-save-parts (type dir n &optional reverse)
10476   "Save parts matching TYPE to DIR.
10477 If REVERSE, save parts that do not match TYPE."
10478   (interactive
10479    (list (read-string "Save parts of type: "
10480                       (or (car gnus-summary-save-parts-type-history)
10481                           gnus-summary-save-parts-default-mime)
10482                       'gnus-summary-save-parts-type-history)
10483          (setq gnus-summary-save-parts-last-directory
10484                (read-file-name "Save to directory: "
10485                                gnus-summary-save-parts-last-directory
10486                                nil t))
10487          current-prefix-arg))
10488   (gnus-summary-iterate n
10489     (let ((gnus-display-mime-function nil)
10490           (gnus-inhibit-treatment t))
10491       (gnus-summary-select-article))
10492     (save-excursion
10493       (set-buffer gnus-article-buffer)
10494       (let ((handles (or gnus-article-mime-handles
10495                          (mm-dissect-buffer nil gnus-article-loose-mime)
10496                          (mm-uu-dissect))))
10497         (when handles
10498           (gnus-summary-save-parts-1 type dir handles reverse)
10499           (unless gnus-article-mime-handles ;; Don't destroy this case.
10500             (mm-destroy-parts handles)))))))
10501
10502 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10503   (if (stringp (car handle))
10504       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10505               (cdr handle))
10506     (when (if reverse
10507               (not (string-match type (mm-handle-media-type handle)))
10508             (string-match type (mm-handle-media-type handle)))
10509       (let ((file (expand-file-name
10510                    (file-name-nondirectory
10511                     (or
10512                      (mail-content-type-get
10513                       (mm-handle-disposition handle) 'filename)
10514                      (concat gnus-newsgroup-name
10515                              "." (number-to-string
10516                                   (cdr gnus-article-current)))))
10517                    dir)))
10518         (unless (file-exists-p file)
10519           (mm-save-part-to-file handle file))))))
10520
10521 ;; Summary extract commands
10522
10523 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10524   (let ((buffer-read-only nil)
10525         (article (gnus-summary-article-number))
10526         after-article b e)
10527     (unless (gnus-summary-goto-subject article)
10528       (error "No such article: %d" article))
10529     (gnus-summary-position-point)
10530     ;; If all commands are to be bunched up on one line, we collect
10531     ;; them here.
10532     (unless gnus-view-pseudos-separately
10533       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10534             files action)
10535         (while ps
10536           (setq action (cdr (assq 'action (car ps))))
10537           (setq files (list (cdr (assq 'name (car ps)))))
10538           (while (and ps (cdr ps)
10539                       (string= (or action "1")
10540                                (or (cdr (assq 'action (cadr ps))) "2")))
10541             (push (cdr (assq 'name (cadr ps))) files)
10542             (setcdr ps (cddr ps)))
10543           (when files
10544             (when (not (string-match "%s" action))
10545               (push " " files))
10546             (push " " files)
10547             (when (assq 'execute (car ps))
10548               (setcdr (assq 'execute (car ps))
10549                       (funcall (if (string-match "%s" action)
10550                                    'format 'concat)
10551                                action
10552                                (mapconcat
10553                                 (lambda (f)
10554                                   (if (equal f " ")
10555                                       f
10556                                     (gnus-quote-arg-for-sh-or-csh f)))
10557                                 files " ")))))
10558           (setq ps (cdr ps)))))
10559     (if (and gnus-view-pseudos (not not-view))
10560         (while pslist
10561           (when (assq 'execute (car pslist))
10562             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10563                                   (eq gnus-view-pseudos 'not-confirm)))
10564           (setq pslist (cdr pslist)))
10565       (save-excursion
10566         (while pslist
10567           (setq after-article (or (cdr (assq 'article (car pslist)))
10568                                   (gnus-summary-article-number)))
10569           (gnus-summary-goto-subject after-article)
10570           (forward-line 1)
10571           (setq b (point))
10572           (insert "    " (file-name-nondirectory
10573                           (cdr (assq 'name (car pslist))))
10574                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10575           (setq e (point))
10576           (forward-line -1)             ; back to `b'
10577           (gnus-add-text-properties
10578            b (1- e) (list 'gnus-number gnus-reffed-article-number
10579                           gnus-mouse-face-prop gnus-mouse-face))
10580           (gnus-data-enter
10581            after-article gnus-reffed-article-number
10582            gnus-unread-mark b (car pslist) 0 (- e b))
10583           (setq gnus-newsgroup-unreads
10584                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
10585                                          gnus-reffed-article-number))
10586           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10587           (setq pslist (cdr pslist)))))))
10588
10589 (defun gnus-pseudos< (p1 p2)
10590   (let ((c1 (cdr (assq 'action p1)))
10591         (c2 (cdr (assq 'action p2))))
10592     (and c1 c2 (string< c1 c2))))
10593
10594 (defun gnus-request-pseudo-article (props)
10595   (cond ((assq 'execute props)
10596          (gnus-execute-command (cdr (assq 'execute props)))))
10597   (let ((gnus-current-article (gnus-summary-article-number)))
10598     (gnus-run-hooks 'gnus-mark-article-hook)))
10599
10600 (defun gnus-execute-command (command &optional automatic)
10601   (save-excursion
10602     (gnus-article-setup-buffer)
10603     (set-buffer gnus-article-buffer)
10604     (setq buffer-read-only nil)
10605     (let ((command (if automatic command
10606                      (read-string "Command: " (cons command 0)))))
10607       (erase-buffer)
10608       (insert "$ " command "\n\n")
10609       (if gnus-view-pseudo-asynchronously
10610           (start-process "gnus-execute" (current-buffer) shell-file-name
10611                          shell-command-switch command)
10612         (call-process shell-file-name nil t nil
10613                       shell-command-switch command)))))
10614
10615 ;; Summary kill commands.
10616
10617 (defun gnus-summary-edit-global-kill (article)
10618   "Edit the \"global\" kill file."
10619   (interactive (list (gnus-summary-article-number)))
10620   (gnus-group-edit-global-kill article))
10621
10622 (defun gnus-summary-edit-local-kill ()
10623   "Edit a local kill file applied to the current newsgroup."
10624   (interactive)
10625   (setq gnus-current-headers (gnus-summary-article-header))
10626   (gnus-group-edit-local-kill
10627    (gnus-summary-article-number) gnus-newsgroup-name))
10628
10629 ;;; Header reading.
10630
10631 (defun gnus-read-header (id &optional header)
10632   "Read the headers of article ID and enter them into the Gnus system."
10633   (let ((group gnus-newsgroup-name)
10634         (gnus-override-method
10635          (or
10636           gnus-override-method
10637           (and (gnus-news-group-p gnus-newsgroup-name)
10638                (car (gnus-refer-article-methods)))))
10639         where)
10640     ;; First we check to see whether the header in question is already
10641     ;; fetched.
10642     (if (stringp id)
10643         ;; This is a Message-ID.
10644         (setq header (or header (gnus-id-to-header id)))
10645       ;; This is an article number.
10646       (setq header (or header (gnus-summary-article-header id))))
10647     (if (and header
10648              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10649         ;; We have found the header.
10650         header
10651       ;; If this is a sparse article, we have to nix out its
10652       ;; previous entry in the thread hashtb.
10653       (when (and header
10654                  (gnus-summary-article-sparse-p (mail-header-number header)))
10655         (let* ((parent (gnus-parent-id (mail-header-references header)))
10656                (thread (and parent (gnus-id-to-thread parent))))
10657           (when thread
10658             (delq (assq header thread) thread))))
10659       ;; We have to really fetch the header to this article.
10660       (save-excursion
10661         (set-buffer nntp-server-buffer)
10662         (when (setq where (gnus-request-head id group))
10663           (nnheader-fold-continuation-lines)
10664           (goto-char (point-max))
10665           (insert ".\n")
10666           (goto-char (point-min))
10667           (insert "211 ")
10668           (princ (cond
10669                   ((numberp id) id)
10670                   ((cdr where) (cdr where))
10671                   (header (mail-header-number header))
10672                   (t gnus-reffed-article-number))
10673                  (current-buffer))
10674           (insert " Article retrieved.\n"))
10675         (if (or (not where)
10676                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10677             ()                          ; Malformed head.
10678           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10679             (when (and (stringp id)
10680                        (not (string= (gnus-group-real-name group)
10681                                      (car where))))
10682               ;; If we fetched by Message-ID and the article came
10683               ;; from a different group, we fudge some bogus article
10684               ;; numbers for this article.
10685               (mail-header-set-number header gnus-reffed-article-number))
10686             (save-excursion
10687               (set-buffer gnus-summary-buffer)
10688               (decf gnus-reffed-article-number)
10689               (gnus-remove-header (mail-header-number header))
10690               (push header gnus-newsgroup-headers)
10691               (setq gnus-current-headers header)
10692               (push (mail-header-number header) gnus-newsgroup-limit)))
10693           header)))))
10694
10695 (defun gnus-remove-header (number)
10696   "Remove header NUMBER from `gnus-newsgroup-headers'."
10697   (if (and gnus-newsgroup-headers
10698            (= number (mail-header-number (car gnus-newsgroup-headers))))
10699       (pop gnus-newsgroup-headers)
10700     (let ((headers gnus-newsgroup-headers))
10701       (while (and (cdr headers)
10702                   (not (= number (mail-header-number (cadr headers)))))
10703         (pop headers))
10704       (when (cdr headers)
10705         (setcdr headers (cddr headers))))))
10706
10707 ;;;
10708 ;;; summary highlights
10709 ;;;
10710
10711 (defun gnus-highlight-selected-summary ()
10712   "Highlight selected article in summary buffer."
10713   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10714   (when gnus-summary-selected-face
10715     (save-excursion
10716       (let* ((beg (progn (beginning-of-line) (point)))
10717              (end (progn (end-of-line) (point)))
10718              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10719              (from (if (get-text-property beg gnus-mouse-face-prop)
10720                        beg
10721                      (or (next-single-property-change
10722                           beg gnus-mouse-face-prop nil end)
10723                          beg)))
10724              (to
10725               (if (= from end)
10726                   (- from 2)
10727                 (or (next-single-property-change
10728                      from gnus-mouse-face-prop nil end)
10729                     end))))
10730         ;; If no mouse-face prop on line we will have to = from = end,
10731         ;; so we highlight the entire line instead.
10732         (when (= (+ to 2) from)
10733           (setq from beg)
10734           (setq to end))
10735         (if gnus-newsgroup-selected-overlay
10736             ;; Move old overlay.
10737             (gnus-move-overlay
10738              gnus-newsgroup-selected-overlay from to (current-buffer))
10739           ;; Create new overlay.
10740           (gnus-overlay-put
10741            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10742            'face gnus-summary-selected-face))))))
10743
10744 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10745 (defun gnus-summary-highlight-line ()
10746   "Highlight current line according to `gnus-summary-highlight'."
10747   (let* ((list gnus-summary-highlight)
10748          (p (point))
10749          (end (progn (end-of-line) (point)))
10750          ;; now find out where the line starts and leave point there.
10751          (beg (progn (beginning-of-line) (point)))
10752          (article (gnus-summary-article-number))
10753          (score (or (cdr (assq (or article gnus-current-article)
10754                                gnus-newsgroup-scored))
10755                     gnus-summary-default-score 0))
10756          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10757          (inhibit-read-only t))
10758     ;; Eval the cars of the lists until we find a match.
10759     (let ((default gnus-summary-default-score)
10760           (default-high gnus-summary-default-high-score)
10761           (default-low gnus-summary-default-low-score))
10762       (while (and list
10763                   (not (eval (caar list))))
10764         (setq list (cdr list))))
10765     (let ((face (cdar list)))
10766       (unless (eq face (get-text-property beg 'face))
10767         (gnus-put-text-property-excluding-characters-with-faces
10768          beg end 'face
10769          (setq face (if (boundp face) (symbol-value face) face)))
10770         (when gnus-summary-highlight-line-function
10771           (funcall gnus-summary-highlight-line-function article face))))
10772     (goto-char p)))
10773
10774 (defun gnus-update-read-articles (group unread &optional compute)
10775   "Update the list of read articles in GROUP.
10776 UNREAD is a sorted list."
10777   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10778          (entry (gnus-gethash group gnus-newsrc-hashtb))
10779          (info (nth 2 entry))
10780          (prev 1)
10781          read)
10782     (if (or (not info) (not active))
10783         ;; There is no info on this group if it was, in fact,
10784         ;; killed.  Gnus stores no information on killed groups, so
10785         ;; there's nothing to be done.
10786         ;; One could store the information somewhere temporarily,
10787         ;; perhaps...  Hmmm...
10788         ()
10789       ;; Remove any negative articles numbers.
10790       (while (and unread (< (car unread) 0))
10791         (setq unread (cdr unread)))
10792       ;; Remove any expired article numbers
10793       (while (and unread (< (car unread) (car active)))
10794         (setq unread (cdr unread)))
10795       ;; Compute the ranges of read articles by looking at the list of
10796       ;; unread articles.
10797       (while unread
10798         (when (/= (car unread) prev)
10799           (push (if (= prev (1- (car unread))) prev
10800                   (cons prev (1- (car unread))))
10801                 read))
10802         (setq prev (1+ (car unread)))
10803         (setq unread (cdr unread)))
10804       (when (<= prev (cdr active))
10805         (push (cons prev (cdr active)) read))
10806       (setq read (if (> (length read) 1) (nreverse read) read))
10807       (if compute
10808           read
10809         (save-excursion
10810           (let (setmarkundo)
10811             ;; Propagate the read marks to the backend.
10812             (when (gnus-check-backend-function 'request-set-mark group)
10813               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10814                     (add (gnus-remove-from-range read (gnus-info-read info))))
10815                 (when (or add del)
10816                   (unless (gnus-check-group group)
10817                     (error "Can't open server for %s" group))
10818                   (gnus-request-set-mark
10819                    group (delq nil (list (if add (list add 'add '(read)))
10820                                          (if del (list del 'del '(read))))))
10821                   (setq setmarkundo
10822                         `(gnus-request-set-mark
10823                           ,group
10824                           ',(delq nil (list
10825                                        (if del (list del 'add '(read)))
10826                                        (if add (list add 'del '(read))))))))))
10827             (set-buffer gnus-group-buffer)
10828             (gnus-undo-register
10829               `(progn
10830                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10831                  (gnus-info-set-read ',info ',(gnus-info-read info))
10832                  (gnus-get-unread-articles-in-group ',info
10833                                                     (gnus-active ,group))
10834                  (gnus-group-update-group ,group t)
10835                  ,setmarkundo))))
10836         ;; Enter this list into the group info.
10837         (gnus-info-set-read info read)
10838         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10839         (gnus-get-unread-articles-in-group info (gnus-active group))
10840         t))))
10841
10842 (defun gnus-offer-save-summaries ()
10843   "Offer to save all active summary buffers."
10844   (let (buffers)
10845     ;; Go through all buffers and find all summaries.
10846     (dolist (buffer (buffer-list))
10847       (when (and (setq buffer (buffer-name buffer))
10848                  (string-match "Summary" buffer)
10849                  (save-excursion
10850                    (set-buffer buffer)
10851                    ;; We check that this is, indeed, a summary buffer.
10852                    (and (eq major-mode 'gnus-summary-mode)
10853                         ;; Also make sure this isn't bogus.
10854                         gnus-newsgroup-prepared
10855                         ;; Also make sure that this isn't a
10856                         ;; dead summary buffer.
10857                         (not gnus-dead-summary-mode))))
10858         (push buffer buffers)))
10859     ;; Go through all these summary buffers and offer to save them.
10860     (when buffers
10861       (save-excursion
10862         (map-y-or-n-p
10863          "Update summary buffer %s? "
10864          (lambda (buf)
10865            (switch-to-buffer buf)
10866            (gnus-summary-exit))
10867          buffers)))))
10868
10869
10870 ;;; @ for mime-partial
10871 ;;;
10872
10873 (defun gnus-request-partial-message ()
10874   (save-excursion
10875     (let ((number (gnus-summary-article-number))
10876           (group gnus-newsgroup-name)
10877           (mother gnus-article-buffer))
10878       (set-buffer (get-buffer-create " *Partial Article*"))
10879       (erase-buffer)
10880       (setq mime-preview-buffer mother)
10881       (gnus-request-article-this-buffer number group)
10882       (mime-parse-buffer)
10883       )))
10884
10885 (autoload 'mime-combine-message/partial-pieces-automatically
10886   "mime-partial"
10887   "Internal method to combine message/partial messages automatically.")
10888
10889 (mime-add-condition
10890  'action '((type . message)(subtype . partial)
10891            (major-mode . gnus-original-article-mode)
10892            (method . mime-combine-message/partial-pieces-automatically)
10893            (summary-buffer-exp . gnus-summary-buffer)
10894            (request-partial-message-method . gnus-request-partial-message)
10895            ))
10896
10897
10898 ;;; @ for message/rfc822
10899 ;;;
10900
10901 (defun gnus-mime-extract-message/rfc822 (entity situation)
10902   "Burst a forwarded article."
10903   (save-excursion
10904     (set-buffer gnus-summary-buffer)
10905     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
10906                                    gnus-newsgroup-name 'gnus-group-history))
10907            (gnus-group-marked (list group))
10908            article info)
10909       (with-temp-buffer
10910         (mime-insert-entity-content entity)
10911         (setq article (gnus-request-accept-article group)))
10912       (when (and (consp article)
10913                  (numberp (setq article (cdr article))))
10914         (setq info (gnus-get-info group))
10915         (gnus-info-set-read info
10916                             (gnus-remove-from-range (gnus-info-read info)
10917                                                     (list article)))
10918         (when (string-equal group gnus-newsgroup-name)
10919           (forward-line 1)
10920           (let (gnus-show-threads)
10921             (gnus-summary-goto-subject article t))
10922           (gnus-summary-clear-mark-forward 1))
10923         (set-buffer gnus-group-buffer)
10924         (gnus-group-get-new-news-this-group nil t)))))
10925
10926 (mime-add-condition
10927  'action '((type . message)(subtype . rfc822)
10928            (major-mode . gnus-original-article-mode)
10929            (method . gnus-mime-extract-message/rfc822)
10930            (mode . "extract")
10931            ))
10932
10933 (mime-add-condition
10934  'action '((type . message)(subtype . news)
10935            (major-mode . gnus-original-article-mode)
10936            (method . gnus-mime-extract-message/rfc822)
10937            (mode . "extract")
10938            ))
10939
10940 (defun gnus-mime-extract-multipart (entity situation)
10941   (let ((children (mime-entity-children entity))
10942         mime-acting-situation-to-override
10943         f)
10944     (while children
10945       (mime-play-entity (car children)
10946                         (cons (assq 'mode situation)
10947                               mime-acting-situation-to-override))
10948       (setq children (cdr children)))
10949     (if (setq f (cdr (assq 'after-method
10950                            mime-acting-situation-to-override)))
10951         (eval f)
10952       )))
10953
10954 (mime-add-condition
10955  'action '((type . multipart)
10956            (method . gnus-mime-extract-multipart)
10957            (mode . "extract")
10958            )
10959  'with-default)
10960
10961
10962 ;;; @ end
10963 ;;;
10964
10965 (defun gnus-summary-setup-default-charset ()
10966   "Setup newsgroup default charset."
10967   (if (equal gnus-newsgroup-name "nndraft:drafts")
10968       (setq gnus-newsgroup-charset nil)
10969     (let* ((ignored-charsets
10970             (or gnus-newsgroup-ephemeral-ignored-charsets
10971                 (append
10972                  (and gnus-newsgroup-name
10973                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10974                  gnus-newsgroup-ignored-charsets))))
10975       (setq gnus-newsgroup-charset
10976             (or gnus-newsgroup-ephemeral-charset
10977                 (and gnus-newsgroup-name
10978                      (gnus-parameter-charset gnus-newsgroup-name))
10979                 gnus-default-charset))
10980       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10981            ignored-charsets))))
10982
10983 ;;;
10984 ;;; Mime Commands
10985 ;;;
10986
10987 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10988   "Display the current article buffer fully MIME-buttonized.
10989 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10990 treated as multipart/mixed."
10991   (interactive "P")
10992   (require 'gnus-art)
10993   (let ((gnus-unbuttonized-mime-types nil)
10994         (gnus-mime-display-multipart-as-mixed show-all-parts))
10995     (gnus-summary-show-article)))
10996
10997 (defun gnus-summary-repair-multipart (article)
10998   "Add a Content-Type header to a multipart article without one."
10999   (interactive (list (gnus-summary-article-number)))
11000   (gnus-with-article article
11001     (message-narrow-to-head)
11002     (message-remove-header "Mime-Version")
11003     (goto-char (point-max))
11004     (insert "Mime-Version: 1.0\n")
11005     (widen)
11006     (when (search-forward "\n--" nil t)
11007       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
11008         (message-narrow-to-head)
11009         (message-remove-header "Content-Type")
11010         (goto-char (point-max))
11011         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11012                         separator))
11013         (widen))))
11014   (let (gnus-mark-article-hook)
11015     (gnus-summary-select-article t t nil article)))
11016
11017 (defun gnus-summary-toggle-display-buttonized ()
11018   "Toggle the buttonizing of the article buffer."
11019   (interactive)
11020   (require 'gnus-art)
11021   (if (setq gnus-inhibit-mime-unbuttonizing
11022             (not gnus-inhibit-mime-unbuttonizing))
11023       (let ((gnus-unbuttonized-mime-types nil))
11024         (gnus-summary-show-article))
11025     (gnus-summary-show-article)))
11026
11027 ;;;
11028 ;;; Intelli-mouse commmands
11029 ;;;
11030
11031 (defun gnus-wheel-summary-scroll (event)
11032   (interactive "e")
11033   (let ((amount (if (memq 'shift (event-modifiers event))
11034                     (car gnus-wheel-scroll-amount)
11035                   (cdr gnus-wheel-scroll-amount)))
11036         (direction (- (* (static-if (featurep 'xemacs)
11037                              (event-button event)
11038                            (cond ((eq 'mouse-4 (event-basic-type event))
11039                                   4)
11040                                  ((eq 'mouse-5 (event-basic-type event))
11041                                   5)))
11042                          2) 9))
11043         edge)
11044     (gnus-summary-scroll-up (* amount direction))
11045     (when (gnus-eval-in-buffer-window gnus-article-buffer
11046             (save-restriction
11047               (widen)
11048               (and (if (< 0 direction)
11049                        (gnus-article-next-page 0)
11050                      (gnus-article-prev-page 0)
11051                      (bobp))
11052                    (if (setq edge (get-text-property
11053                                    (point-min) 'gnus-wheel-edge))
11054                        (setq edge (* edge direction))
11055                      (setq edge -1))
11056                    (or (plusp edge)
11057                        (let ((buffer-read-only nil)
11058                              (inhibit-read-only t))
11059                          (put-text-property (point-min) (point-max)
11060                                             'gnus-wheel-edge direction)
11061                          nil))
11062                    (or (> edge gnus-wheel-edge-resistance)
11063                        (let ((buffer-read-only nil)
11064                              (inhibit-read-only t))
11065                          (put-text-property (point-min) (point-max)
11066                                             'gnus-wheel-edge
11067                                             (* (1+ edge) direction))
11068                          nil))
11069                    (eq last-command 'gnus-wheel-summary-scroll))))
11070       (gnus-summary-next-article nil nil (minusp direction)))))
11071
11072 (defun gnus-wheel-install ()
11073   "Enable mouse wheel support on summary window."
11074   (when gnus-use-wheel
11075     (let ((keys
11076            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11077       (dolist (key keys)
11078         (define-key gnus-summary-mode-map key
11079           'gnus-wheel-summary-scroll)))))
11080
11081 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11082
11083 ;;;
11084 ;;; Traditional PGP commmands
11085 ;;;
11086
11087 (defun gnus-summary-decrypt-article (&optional force)
11088   "Decrypt the current article in traditional PGP way.
11089 This will have permanent effect only in mail groups.
11090 If FORCE is non-nil, allow editing of articles even in read-only
11091 groups."
11092   (interactive "P")
11093   (gnus-summary-select-article t)
11094   (gnus-eval-in-buffer-window gnus-article-buffer
11095     (save-excursion
11096       (save-restriction
11097         (widen)
11098         (goto-char (point-min))
11099         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11100           (error "Not a traditional PGP message!"))
11101         (let ((armor-start (match-beginning 0)))
11102           (if (and (pgg-decrypt-region armor-start (point-max))
11103                    (or force (not (gnus-group-read-only-p))))
11104               (let ((inhibit-read-only t)
11105                     buffer-read-only)
11106                 (delete-region armor-start
11107                                (progn
11108                                  (re-search-forward "^-+END PGP" nil t)
11109                                  (beginning-of-line 2)
11110                                  (point)))
11111                 (insert-buffer-substring pgg-output-buffer))))))))
11112
11113 (defun gnus-summary-verify-article ()
11114   "Verify the current article in traditional PGP way."
11115   (interactive)
11116   (save-excursion
11117     (set-buffer gnus-original-article-buffer)
11118     (goto-char (point-min))
11119     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11120       (error "Not a traditional PGP message!"))
11121     (re-search-forward "^-+END PGP" nil t)
11122     (beginning-of-line 2)
11123     (call-interactively (function pgg-verify-region))))
11124
11125 ;;;
11126 ;;; Generic summary marking commands
11127 ;;;
11128
11129 (defvar gnus-summary-marking-alist
11130   '((read gnus-del-mark "d")
11131     (unread gnus-unread-mark "u")
11132     (ticked gnus-ticked-mark "!")
11133     (dormant gnus-dormant-mark "?")
11134     (expirable gnus-expirable-mark "e"))
11135   "An alist of names/marks/keystrokes.")
11136
11137 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11138 (defvar gnus-summary-mark-map)
11139
11140 (defun gnus-summary-make-all-marking-commands ()
11141   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11142   (dolist (elem gnus-summary-marking-alist)
11143     (apply 'gnus-summary-make-marking-command elem)))
11144
11145 (defun gnus-summary-make-marking-command (name mark keystroke)
11146   (let ((map (make-sparse-keymap)))
11147     (define-key gnus-summary-generic-mark-map keystroke map)
11148     (dolist (lway `((next "next" next nil "n")
11149                     (next-unread "next unread" next t "N")
11150                     (prev "previous" prev nil "p")
11151                     (prev-unread "previous unread" prev t "P")
11152                     (nomove "" nil nil ,keystroke)))
11153       (let ((func (gnus-summary-make-marking-command-1
11154                    mark (car lway) lway name)))
11155         (setq func (eval func))
11156         (define-key map (nth 4 lway) func)))))
11157
11158 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11159   `(defun ,(intern
11160             (format "gnus-summary-put-mark-as-%s%s"
11161                     name (if (eq way 'nomove)
11162                              ""
11163                            (concat "-" (symbol-name way)))))
11164      (n)
11165      ,(format
11166        "Mark the current article as %s%s.
11167 If N, the prefix, then repeat N times.
11168 If N is negative, move in reverse order.
11169 The difference between N and the actual number of articles marked is
11170 returned."
11171        name (car (cdr lway)))
11172      (interactive "p")
11173      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11174
11175 (defun gnus-summary-generic-mark (n mark move unread)
11176   "Mark N articles with MARK."
11177   (unless (eq major-mode 'gnus-summary-mode)
11178     (error "This command can only be used in the summary buffer"))
11179   (gnus-summary-show-thread)
11180   (let ((nummove
11181          (cond
11182           ((eq move 'next) 1)
11183           ((eq move 'prev) -1)
11184           (t 0))))
11185     (if (zerop nummove)
11186         (setq n 1)
11187       (when (< n 0)
11188         (setq n (abs n)
11189               nummove (* -1 nummove))))
11190     (while (and (> n 0)
11191                 (gnus-summary-mark-article nil mark)
11192                 (zerop (gnus-summary-next-subject nummove unread t)))
11193       (setq n (1- n)))
11194     (when (/= 0 n)
11195       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11196     (gnus-summary-recenter)
11197     (gnus-summary-position-point)
11198     (gnus-set-mode-line 'summary)
11199     n))
11200
11201 (defun gnus-summary-insert-articles (articles)
11202   (when (setq articles
11203               (gnus-sorted-difference articles
11204                                       (mapcar (lambda (h)
11205                                                 (mail-header-number h))
11206                                               gnus-newsgroup-headers)))
11207     (setq gnus-newsgroup-headers
11208           (merge 'list
11209                  gnus-newsgroup-headers
11210                  (gnus-fetch-headers articles)
11211                  'gnus-article-sort-by-number))
11212     ;; Suppress duplicates?
11213     (when gnus-suppress-duplicates
11214       (gnus-dup-suppress-articles))
11215
11216     ;; We might want to build some more threads first.
11217     (when (and gnus-fetch-old-headers
11218                (eq gnus-headers-retrieved-by 'nov))
11219       (if (eq gnus-fetch-old-headers 'invisible)
11220           (gnus-build-all-threads)
11221         (gnus-build-old-threads)))
11222     ;; Let the Gnus agent mark articles as read.
11223     (when gnus-agent
11224       (gnus-agent-get-undownloaded-list))
11225     ;; Remove list identifiers from subject
11226     (when gnus-list-identifiers
11227       (gnus-summary-remove-list-identifiers))
11228     ;; First and last article in this newsgroup.
11229     (when gnus-newsgroup-headers
11230       (setq gnus-newsgroup-begin
11231             (mail-header-number (car gnus-newsgroup-headers))
11232             gnus-newsgroup-end
11233             (mail-header-number
11234              (gnus-last-element gnus-newsgroup-headers))))
11235     (when gnus-use-scoring
11236       (gnus-possibly-score-headers))))
11237
11238 (defun gnus-summary-insert-old-articles (&optional all)
11239   "Insert all old articles in this group.
11240 If ALL is non-nil, already read articles become readable.
11241 If ALL is a number, fetch this number of articles."
11242   (interactive "P")
11243   (prog1
11244       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11245             older len)
11246         (setq older
11247               (gnus-sorted-difference
11248                (gnus-uncompress-range (list gnus-newsgroup-active))
11249                old))
11250         (setq len (length older))
11251         (cond
11252          ((null older) nil)
11253          ((numberp all)
11254           (if (< all len)
11255               (setq older (last older all))))
11256          (all nil)
11257          (t
11258           (if (and (numberp gnus-large-newsgroup)
11259                    (> len gnus-large-newsgroup))
11260               (let* ((cursor-in-echo-area nil)
11261                      (initial (gnus-parameter-large-newsgroup-initial 
11262                                gnus-newsgroup-name))
11263                      (input
11264                       (read-string
11265                        (format
11266                         "How many articles from %s (%s %d): "
11267                         (gnus-limit-string
11268                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11269                         (if initial "max" "default")
11270                         len)
11271                        (if initial
11272                            (cons (number-to-string initial)
11273                                  0)))))
11274                 (unless (string-match "^[ \t]*$" input)
11275                   (setq all (string-to-number input))
11276                   (if (< all len)
11277                       (setq older (last older all))))))))
11278         (if (not older)
11279             (message "No old news.")
11280           (gnus-summary-insert-articles older)
11281           (gnus-summary-limit (gnus-sorted-nunion old older))))
11282     (gnus-summary-position-point)))
11283
11284 (defun gnus-summary-insert-new-articles ()
11285   "Insert all new articles in this group."
11286   (interactive)
11287   (prog1
11288       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11289             (old-active gnus-newsgroup-active)
11290             (nnmail-fetched-sources (list t))
11291             i new)
11292         (setq gnus-newsgroup-active
11293               (gnus-activate-group gnus-newsgroup-name 'scan))
11294         (setq i (1+ (cdr old-active)))
11295         (while (<= i (cdr gnus-newsgroup-active))
11296           (push i new)
11297           (incf i))
11298         (if (not new)
11299             (message "No gnus is bad news.")
11300           (setq new (nreverse new))
11301           (gnus-summary-insert-articles new)
11302           (setq gnus-newsgroup-unreads
11303                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11304           (gnus-summary-limit (gnus-sorted-nunion old new))))
11305     (gnus-summary-position-point)))
11306
11307 (gnus-summary-make-all-marking-commands)
11308
11309 (gnus-ems-redefine)
11310
11311 (provide 'gnus-sum)
11312
11313 (run-hooks 'gnus-sum-load-hook)
11314
11315 ;;; gnus-sum.el ends here