Synch with Oort Gnus.
[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
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 ;; Recursive :-(.
42 ;; (require 'gnus-art)
43 (require 'nnoo)
44 (require 'mime-view)
45
46 (eval-when-compile
47   (require 'mime-play)
48   (require 'static))
49
50 (eval-and-compile
51   (autoload 'pgg-decrypt-region "pgg" nil t)
52   (autoload 'pgg-verify-region "pgg" nil t))
53
54 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
55 (autoload 'gnus-cache-write-active "gnus-cache")
56 (autoload 'gnus-set-summary-default-charset "gnus-i18n" nil t)
57 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
58 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
59 (autoload 'mm-uu-dissect "mm-uu")
60
61 (defcustom gnus-kill-summary-on-exit t
62   "*If non-nil, kill the summary buffer when you exit from it.
63 If nil, the summary will become a \"*Dead Summary*\" buffer, and
64 it will be killed sometime later."
65   :group 'gnus-summary-exit
66   :type 'boolean)
67
68 (defcustom gnus-fetch-old-headers nil
69   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
70 If an unread article in the group refers to an older, already read (or
71 just marked as read) article, the old article will not normally be
72 displayed in the Summary buffer.  If this variable is non-nil, Gnus
73 will attempt to grab the headers to the old articles, and thereby
74 build complete threads.  If it has the value `some', only enough
75 headers to connect otherwise loose threads will be displayed.  This
76 variable can also be a number.  In that case, no more than that number
77 of old headers will be fetched.  If it has the value `invisible', all
78 old headers will be fetched, but none will be displayed.
79
80 The server has to support NOV for any of this to work."
81   :group 'gnus-thread
82   :type '(choice (const :tag "off" nil)
83                  (const some)
84                  number
85                  (sexp :menu-tag "other" t)))
86
87 (defcustom gnus-refer-thread-limit 200
88   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
89 If t, fetch all the available old headers."
90   :group 'gnus-thread
91   :type '(choice number
92                  (sexp :menu-tag "other" t)))
93
94 (defcustom gnus-summary-make-false-root 'adopt
95   "*nil means that Gnus won't gather loose threads.
96 If the root of a thread has expired or been read in a previous
97 session, the information necessary to build a complete thread has been
98 lost.  Instead of having many small sub-threads from this original thread
99 scattered all over the summary buffer, Gnus can gather them.
100
101 If non-nil, Gnus will try to gather all loose sub-threads from an
102 original thread into one large thread.
103
104 If this variable is non-nil, it should be one of `none', `adopt',
105 `dummy' or `empty'.
106
107 If this variable is `none', Gnus will not make a false root, but just
108 present the sub-threads after another.
109 If this variable is `dummy', Gnus will create a dummy root that will
110 have all the sub-threads as children.
111 If this variable is `adopt', Gnus will make one of the \"children\"
112 the parent and mark all the step-children as such.
113 If this variable is `empty', the \"children\" are printed with empty
114 subject fields.  (Or rather, they will be printed with a string
115 given by the `gnus-summary-same-subject' variable.)"
116   :group 'gnus-thread
117   :type '(choice (const :tag "off" nil)
118                  (const none)
119                  (const dummy)
120                  (const adopt)
121                  (const empty)))
122
123 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
124   "*A regexp to match subjects to be excluded from loose thread gathering.
125 As loose thread gathering is done on subjects only, that means that
126 there can be many false gatherings performed.  By rooting out certain
127 common subjects, gathering might become saner."
128   :group 'gnus-thread
129   :type 'regexp)
130
131 (defcustom gnus-summary-gather-subject-limit nil
132   "*Maximum length of subject comparisons when gathering loose threads.
133 Use nil to compare full subjects.  Setting this variable to a low
134 number will help gather threads that have been corrupted by
135 newsreaders chopping off subject lines, but it might also mean that
136 unrelated articles that have subject that happen to begin with the
137 same few characters will be incorrectly gathered.
138
139 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
140 comparing subjects."
141   :group 'gnus-thread
142   :type '(choice (const :tag "off" nil)
143                  (const fuzzy)
144                  (sexp :menu-tag "on" t)))
145
146 (defcustom gnus-simplify-subject-functions nil
147   "List of functions taking a string argument that simplify subjects.
148 The functions are applied recursively.
149
150 Useful functions to put in this list include: `gnus-simplify-subject-re',
151 `gnus-simplify-subject-fuzzy' and `gnus-simplify-whitespace'."
152   :group 'gnus-thread
153   :type '(repeat function))
154
155 (defcustom gnus-simplify-ignored-prefixes nil
156   "*Regexp, matches for which are removed from subject lines when simplifying fuzzily."
157   :group 'gnus-thread
158   :type '(choice (const :tag "off" nil)
159                  regexp))
160
161 (defcustom gnus-build-sparse-threads nil
162   "*If non-nil, fill in the gaps in threads.
163 If `some', only fill in the gaps that are needed to tie loose threads
164 together.  If `more', fill in all leaf nodes that Gnus can find.  If
165 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const some)
169                  (const more)
170                  (sexp :menu-tag "all" t)))
171
172 (defcustom gnus-summary-thread-gathering-function
173   'gnus-gather-threads-by-subject
174   "*Function used for gathering loose threads.
175 There are two pre-defined functions: `gnus-gather-threads-by-subject',
176 which only takes Subjects into consideration; and
177 `gnus-gather-threads-by-references', which compared the References
178 headers of the articles to find matches."
179   :group 'gnus-thread
180   :type '(radio (function-item gnus-gather-threads-by-subject)
181                 (function-item gnus-gather-threads-by-references)
182                 (function :tag "other")))
183
184 (defcustom gnus-summary-same-subject ""
185   "*String indicating that the current article has the same subject as the previous.
186 This variable will only be used if the value of
187 `gnus-summary-make-false-root' is `empty'."
188   :group 'gnus-summary-format
189   :type 'string)
190
191 (defcustom gnus-summary-goto-unread t
192   "*If t, many commands will go to the next unread article.
193 This applies to marking commands as well as other commands that
194 \"naturally\" select the next article, like, for instance, `SPC' at
195 the end of an article.
196
197 If nil, the marking commands do NOT go to the next unread article
198 (they go to the next article instead).  If `never', commands that
199 usually go to the next unread article, will go to the next article,
200 whether it is read or not."
201   :group 'gnus-summary-marks
202   :link '(custom-manual "(gnus)Setting Marks")
203   :type '(choice (const :tag "off" nil)
204                  (const never)
205                  (sexp :menu-tag "on" t)))
206
207 (defcustom gnus-summary-default-score 0
208   "*Default article score level.
209 All scores generated by the score files will be added to this score.
210 If this variable is nil, scoring will be disabled."
211   :group 'gnus-score-default
212   :type '(choice (const :tag "disable")
213                  integer))
214
215 (defcustom gnus-summary-default-high-score 0
216   "*Default threshold for a high scored article.
217 An article will be highlighted as high scored if its score is greater
218 than this score."
219   :group 'gnus-score-default
220   :type 'integer)
221
222 (defcustom gnus-summary-default-low-score 0
223   "*Default threshold for a low scored article.
224 An article will be highlighted as low scored if its score is smaller
225 than this score."
226   :group 'gnus-score-default
227   :type 'integer)
228
229 (defcustom gnus-summary-zcore-fuzz 0
230   "*Fuzziness factor for the zcore in the summary buffer.
231 Articles with scores closer than this to `gnus-summary-default-score'
232 will not be marked."
233   :group 'gnus-summary-format
234   :type 'integer)
235
236 (defcustom gnus-simplify-subject-fuzzy-regexp nil
237   "*Strings to be removed when doing fuzzy matches.
238 This can either be a regular expression or list of regular expressions
239 that will be removed from subject strings if fuzzy subject
240 simplification is selected."
241   :group 'gnus-thread
242   :type '(repeat regexp))
243
244 (defcustom gnus-show-threads t
245   "*If non-nil, display threads in summary mode."
246   :group 'gnus-thread
247   :type 'boolean)
248
249 (defcustom gnus-thread-hide-subtree nil
250   "*If non-nil, hide all threads initially.
251 If threads are hidden, you have to run the command
252 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
253 to expose hidden threads."
254   :group 'gnus-thread
255   :type 'boolean)
256
257 (defcustom gnus-thread-hide-killed t
258   "*If non-nil, hide killed threads automatically."
259   :group 'gnus-thread
260   :type 'boolean)
261
262 (defcustom gnus-thread-ignore-subject t
263   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
264 If nil, articles that have different subjects from their parents will
265 start separate threads."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-operation-ignore-subject t
270   "*If non-nil, subjects will be ignored when doing thread commands.
271 This affects commands like `gnus-summary-kill-thread' and
272 `gnus-summary-lower-thread'.
273
274 If this variable is nil, articles in the same thread with different
275 subjects will not be included in the operation in question.  If this
276 variable is `fuzzy', only articles that have subjects that are fuzzily
277 equal will be included."
278   :group 'gnus-thread
279   :type '(choice (const :tag "off" nil)
280                  (const fuzzy)
281                  (sexp :tag "on" t)))
282
283 (defcustom gnus-thread-indent-level 4
284   "*Number that says how much each sub-thread should be indented."
285   :group 'gnus-thread
286   :type 'integer)
287
288 (defcustom gnus-auto-extend-newsgroup t
289   "*If non-nil, extend newsgroup forward and backward when requested."
290   :group 'gnus-summary-choose
291   :type 'boolean)
292
293 (defcustom gnus-auto-select-first t
294   "*If nil, don't select the first unread article when entering a group.
295 If this variable is `best', select the highest-scored unread article
296 in the group.  If t, select the first unread article.
297
298 This variable can also be a function to place point on a likely
299 subject line.  Useful values include `gnus-summary-first-unread-subject',
300 `gnus-summary-first-unread-article' and
301 `gnus-summary-best-unread-article'.
302
303 If you want to prevent automatic selection of the first unread article
304 in some newsgroups, set the variable to nil in
305 `gnus-select-group-hook'."
306   :group 'gnus-group-select
307   :type '(choice (const :tag "none" nil)
308                  (const best)
309                  (sexp :menu-tag "first" t)
310                  (function-item gnus-summary-first-unread-subject)
311                  (function-item gnus-summary-first-unread-article)
312                  (function-item gnus-summary-best-unread-article)))
313
314 (defcustom gnus-dont-select-after-jump-to-other-group nil
315   "If non-nil, don't select the first unread article after entering the
316 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
317 it is depend on the value of `gnus-auto-select-first' whether to select
318 or not."
319   :group 'gnus-group-select
320   :type 'boolean)
321
322 (defcustom gnus-auto-select-next t
323   "*If non-nil, offer to go to the next group from the end of the previous.
324 If the value is t and the next newsgroup is empty, Gnus will exit
325 summary mode and go back to group mode.  If the value is neither nil
326 nor t, Gnus will select the following unread newsgroup.  In
327 particular, if the value is the symbol `quietly', the next unread
328 newsgroup will be selected without any confirmation, and if it is
329 `almost-quietly', the next group will be selected without any
330 confirmation if you are located on the last article in the group.
331 Finally, if this variable is `slightly-quietly', the `Z n' command
332 will go to the next group without confirmation."
333   :group 'gnus-summary-maneuvering
334   :type '(choice (const :tag "off" nil)
335                  (const quietly)
336                  (const almost-quietly)
337                  (const slightly-quietly)
338                  (sexp :menu-tag "on" t)))
339
340 (defcustom gnus-auto-select-same nil
341   "*If non-nil, select the next article with the same subject.
342 If there are no more articles with the same subject, go to
343 the first unread article."
344   :group 'gnus-summary-maneuvering
345   :type 'boolean)
346
347 (defcustom gnus-summary-check-current nil
348   "*If non-nil, consider the current article when moving.
349 The \"unread\" movement commands will stay on the same line if the
350 current article is unread."
351   :group 'gnus-summary-maneuvering
352   :type 'boolean)
353
354 (defcustom gnus-auto-center-summary t
355   "*If non-nil, always center the current summary buffer.
356 In particular, if `vertical' do only vertical recentering.  If non-nil
357 and non-`vertical', do both horizontal and vertical recentering."
358   :group 'gnus-summary-maneuvering
359   :type '(choice (const :tag "none" nil)
360                  (const vertical)
361                  (integer :tag "height")
362                  (sexp :menu-tag "both" t)))
363
364 (defcustom gnus-show-all-headers nil
365   "*If non-nil, don't hide any headers."
366   :group 'gnus-article-hiding
367   :group 'gnus-article-headers
368   :type 'boolean)
369
370 (defcustom gnus-summary-ignore-duplicates nil
371   "*If non-nil, ignore articles with identical Message-ID headers."
372   :group 'gnus-summary
373   :type 'boolean)
374
375 (defcustom gnus-single-article-buffer t
376   "*If non-nil, display all articles in the same buffer.
377 If nil, each group will get its own article buffer."
378   :group 'gnus-article-various
379   :type 'boolean)
380
381 (defcustom gnus-break-pages t
382   "*If non-nil, do page breaking on articles.
383 The page delimiter is specified by the `gnus-page-delimiter'
384 variable."
385   :group 'gnus-article-various
386   :type 'boolean)
387
388 (defcustom gnus-show-mime t
389   "*If non-nil, do mime processing of articles.
390 The articles will simply be fed to the function given by
391 `gnus-article-display-method-for-mime'."
392   :group 'gnus-article-mime
393   :type 'boolean)
394
395 (defcustom gnus-move-split-methods nil
396   "*Variable used to suggest where articles are to be moved to.
397 It uses the same syntax as the `gnus-split-methods' variable.
398 However, whereas `gnus-split-methods' specifies file names as targets,
399 this variable specifies group names."
400   :group 'gnus-summary-mail
401   :type '(repeat (choice (list :value (fun) function)
402                          (cons :value ("" "") regexp (repeat string))
403                          (sexp :value nil))))
404
405 (defcustom gnus-unread-mark ?\ ;;;Whitespace
406   "*Mark used for unread articles."
407   :group 'gnus-summary-marks
408   :type 'character)
409
410 (defcustom gnus-ticked-mark ?!
411   "*Mark used for ticked articles."
412   :group 'gnus-summary-marks
413   :type 'character)
414
415 (defcustom gnus-dormant-mark ??
416   "*Mark used for dormant articles."
417   :group 'gnus-summary-marks
418   :type 'character)
419
420 (defcustom gnus-del-mark ?r
421   "*Mark used for del'd articles."
422   :group 'gnus-summary-marks
423   :type 'character)
424
425 (defcustom gnus-read-mark ?R
426   "*Mark used for read articles."
427   :group 'gnus-summary-marks
428   :type 'character)
429
430 (defcustom gnus-expirable-mark ?E
431   "*Mark used for expirable articles."
432   :group 'gnus-summary-marks
433   :type 'character)
434
435 (defcustom gnus-killed-mark ?K
436   "*Mark used for killed articles."
437   :group 'gnus-summary-marks
438   :type 'character)
439
440 (defcustom gnus-souped-mark ?F
441   "*Mark used for souped articles."
442   :group 'gnus-summary-marks
443   :type 'character)
444
445 (defcustom gnus-kill-file-mark ?X
446   "*Mark used for articles killed by kill files."
447   :group 'gnus-summary-marks
448   :type 'character)
449
450 (defcustom gnus-low-score-mark ?Y
451   "*Mark used for articles with a low score."
452   :group 'gnus-summary-marks
453   :type 'character)
454
455 (defcustom gnus-catchup-mark ?C
456   "*Mark used for articles that are caught up."
457   :group 'gnus-summary-marks
458   :type 'character)
459
460 (defcustom gnus-replied-mark ?A
461   "*Mark used for articles that have been replied to."
462   :group 'gnus-summary-marks
463   :type 'character)
464
465 (defcustom gnus-forwarded-mark ?F
466   "*Mark used for articles that have been forwarded."
467   :group 'gnus-summary-marks
468   :type 'character)
469
470 (defcustom gnus-recent-mark ?N
471   "*Mark used for articles that are recent."
472   :group 'gnus-summary-marks
473   :type 'character)
474
475 (defcustom gnus-cached-mark ?*
476   "*Mark used for articles that are in the cache."
477   :group 'gnus-summary-marks
478   :type 'character)
479
480 (defcustom gnus-saved-mark ?S
481   "*Mark used for articles that have been saved."
482   :group 'gnus-summary-marks
483   :type 'character)
484
485 (defcustom gnus-unseen-mark ?.
486   "*Mark used for articles that haven't been seen."
487   :group 'gnus-summary-marks
488   :type 'character)
489
490 (defcustom gnus-no-mark ?\ ;;;Whitespace
491   "*Mark used for articles that have no other secondary mark."
492   :group 'gnus-summary-marks
493   :type 'character)
494
495 (defcustom gnus-ancient-mark ?O
496   "*Mark used for ancient articles."
497   :group 'gnus-summary-marks
498   :type 'character)
499
500 (defcustom gnus-sparse-mark ?Q
501   "*Mark used for sparsely reffed articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-canceled-mark ?G
506   "*Mark used for canceled articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-duplicate-mark ?M
511   "*Mark used for duplicate articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-undownloaded-mark ?@
516   "*Mark used for articles that weren't downloaded."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-downloadable-mark ?%
521   "*Mark used for articles that are to be downloaded."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-unsendable-mark ?=
526   "*Mark used for articles that won't be sent."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-score-over-mark ?+
531   "*Score mark used for articles with high scores."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-score-below-mark ?-
536   "*Score mark used for articles with low scores."
537   :group 'gnus-summary-marks
538   :type 'character)
539
540 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
541   "*There is no thread under the article."
542   :group 'gnus-summary-marks
543   :type 'character)
544
545 (defcustom gnus-not-empty-thread-mark ?=
546   "*There is a thread under the article."
547   :group 'gnus-summary-marks
548   :type 'character)
549
550 (defcustom gnus-view-pseudo-asynchronously nil
551   "*If non-nil, Gnus will view pseudo-articles asynchronously."
552   :group 'gnus-extract-view
553   :type 'boolean)
554
555 (defcustom gnus-auto-expirable-marks
556   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
557         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
558         gnus-souped-mark gnus-duplicate-mark)
559   "*The list of marks converted into expiration if a group is auto-expirable."
560   :version "21.1"
561   :group 'gnus-summary
562   :type '(repeat character))
563
564 (defcustom gnus-inhibit-user-auto-expire t
565   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
566   :version "21.1"
567   :group 'gnus-summary
568   :type 'boolean)
569
570 (defcustom gnus-view-pseudos nil
571   "*If `automatic', pseudo-articles will be viewed automatically.
572 If `not-confirm', pseudos will be viewed automatically, and the user
573 will not be asked to confirm the command."
574   :group 'gnus-extract-view
575   :type '(choice (const :tag "off" nil)
576                  (const automatic)
577                  (const not-confirm)))
578
579 (defcustom gnus-view-pseudos-separately t
580   "*If non-nil, one pseudo-article will be created for each file to be viewed.
581 If nil, all files that use the same viewing command will be given as a
582 list of parameters to that command."
583   :group 'gnus-extract-view
584   :type 'boolean)
585
586 (defcustom gnus-insert-pseudo-articles t
587   "*If non-nil, insert pseudo-articles when decoding articles."
588   :group 'gnus-extract-view
589   :type 'boolean)
590
591 (defcustom gnus-summary-dummy-line-format
592   "  %(:                          :%) %S\n"
593   "*The format specification for the dummy roots in the summary buffer.
594 It works along the same lines as a normal formatting string,
595 with some simple extensions.
596
597 %S  The subject"
598   :group 'gnus-threading
599   :type 'string)
600
601 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
602   "*The format specification for the summary mode line.
603 It works along the same lines as a normal formatting string,
604 with some simple extensions:
605
606 %G  Group name
607 %p  Unprefixed group name
608 %A  Current article number
609 %z  Current article score
610 %V  Gnus version
611 %U  Number of unread articles in the group
612 %e  Number of unselected articles in the group
613 %Z  A string with unread/unselected article counts
614 %g  Shortish group name
615 %S  Subject of the current article
616 %u  User-defined spec
617 %s  Current score file name
618 %d  Number of dormant articles
619 %r  Number of articles that have been marked as read in this session
620 %E  Number of articles expunged by the score files"
621   :group 'gnus-summary-format
622   :type 'string)
623
624 (defcustom gnus-list-identifiers nil
625   "Regexp that matches list identifiers to be removed from subject.
626 This can also be a list of regexps."
627   :version "21.1"
628   :group 'gnus-summary-format
629   :group 'gnus-article-hiding
630   :type '(choice (const :tag "none" nil)
631                  (regexp :value ".*")
632                  (repeat :value (".*") regexp)))
633
634 (defcustom gnus-summary-mark-below 0
635   "*Mark all articles with a score below this variable as read.
636 This variable is local to each summary buffer and usually set by the
637 score file."
638   :group 'gnus-score-default
639   :type 'integer)
640
641 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
642   "*List of functions used for sorting articles in the summary buffer.
643
644 Each function takes two articles and returns non-nil if the first
645 article should be sorted before the other.  If you use more than one
646 function, the primary sort function should be the last.  You should
647 probably always include `gnus-article-sort-by-number' in the list of
648 sorting functions -- preferably first.  Also note that sorting by date
649 is often much slower than sorting by number, and the sorting order is
650 very similar.  (Sorting by date means sorting by the time the message
651 was sent, sorting by number means sorting by arrival time.)
652
653 Ready-made functions include `gnus-article-sort-by-number',
654 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
655 `gnus-article-sort-by-date' and `gnus-article-sort-by-score'.
656
657 When threading is turned on, the variable `gnus-thread-sort-functions'
658 controls how articles are sorted."
659   :group 'gnus-summary-sort
660   :type '(repeat (choice (function-item gnus-article-sort-by-number)
661                          (function-item gnus-article-sort-by-author)
662                          (function-item gnus-article-sort-by-subject)
663                          (function-item gnus-article-sort-by-date)
664                          (function-item gnus-article-sort-by-score)
665                          (function :tag "other"))))
666
667 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
668   "*List of functions used for sorting threads in the summary buffer.
669 By default, threads are sorted by article number.
670
671 Each function takes two threads and returns non-nil if the first
672 thread should be sorted before the other.  If you use more than one
673 function, the primary sort function should be the last.  You should
674 probably always include `gnus-thread-sort-by-number' in the list of
675 sorting functions -- preferably first.  Also note that sorting by date
676 is often much slower than sorting by number, and the sorting order is
677 very similar.  (Sorting by date means sorting by the time the message
678 was sent, sorting by number means sorting by arrival time.)
679
680 Ready-made functions include `gnus-thread-sort-by-number',
681 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
682 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score' and
683 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
684
685 When threading is turned off, the variable
686 `gnus-article-sort-functions' controls how articles are sorted."
687   :group 'gnus-summary-sort
688   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
689                          (function-item gnus-thread-sort-by-author)
690                          (function-item gnus-thread-sort-by-subject)
691                          (function-item gnus-thread-sort-by-date)
692                          (function-item gnus-thread-sort-by-score)
693                          (function-item gnus-thread-sort-by-total-score)
694                          (function :tag "other"))))
695
696 (defcustom gnus-thread-score-function '+
697   "*Function used for calculating the total score of a thread.
698
699 The function is called with the scores of the article and each
700 subthread and should then return the score of the thread.
701
702 Some functions you can use are `+', `max', or `min'."
703   :group 'gnus-summary-sort
704   :type 'function)
705
706 (defcustom gnus-summary-expunge-below nil
707   "All articles that have a score less than this variable will be expunged.
708 This variable is local to the summary buffers."
709   :group 'gnus-score-default
710   :type '(choice (const :tag "off" nil)
711                  integer))
712
713 (defcustom gnus-thread-expunge-below nil
714   "All threads that have a total score less than this variable will be expunged.
715 See `gnus-thread-score-function' for en explanation of what a
716 \"thread score\" is.
717
718 This variable is local to the summary buffers."
719   :group 'gnus-threading
720   :group 'gnus-score-default
721   :type '(choice (const :tag "off" nil)
722                  integer))
723
724 (defcustom gnus-summary-mode-hook nil
725   "*A hook for Gnus summary mode.
726 This hook is run before any variables are set in the summary buffer."
727   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
728   :group 'gnus-summary-various
729   :type 'hook)
730
731 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
732 (when (featurep 'xemacs)
733   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
734   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
735   (add-hook 'gnus-summary-mode-hook
736             'gnus-xmas-switch-horizontal-scrollbar-off))
737
738 (defcustom gnus-summary-menu-hook nil
739   "*Hook run after the creation of the summary mode menu."
740   :group 'gnus-summary-visual
741   :type 'hook)
742
743 (defcustom gnus-summary-exit-hook nil
744   "*A hook called on exit from the summary buffer.
745 It will be called with point in the group buffer."
746   :group 'gnus-summary-exit
747   :type 'hook)
748
749 (defcustom gnus-summary-prepare-hook nil
750   "*A hook called after the summary buffer has been generated.
751 If you want to modify the summary buffer, you can use this hook."
752   :group 'gnus-summary-various
753   :type 'hook)
754
755 (defcustom gnus-summary-prepared-hook nil
756   "*A hook called as the last thing after the summary buffer has been generated."
757   :group 'gnus-summary-various
758   :type 'hook)
759
760 (defcustom gnus-summary-generate-hook nil
761   "*A hook run just before generating the summary buffer.
762 This hook is commonly used to customize threading variables and the
763 like."
764   :group 'gnus-summary-various
765   :type 'hook)
766
767 (defcustom gnus-select-group-hook nil
768   "*A hook called when a newsgroup is selected.
769
770 If you'd like to simplify subjects like the
771 `gnus-summary-next-same-subject' command does, you can use the
772 following hook:
773
774  (setq gnus-select-group-hook
775       (list
776         (lambda ()
777           (mapcar (lambda (header)
778                      (mail-header-set-subject
779                       header
780                       (gnus-simplify-subject
781                        (mail-header-subject header) 're-only)))
782                   gnus-newsgroup-headers))))"
783   :group 'gnus-group-select
784   :type 'hook)
785
786 (defcustom gnus-select-article-hook nil
787   "*A hook called when an article is selected."
788   :group 'gnus-summary-choose
789   :type 'hook)
790
791 (defcustom gnus-visual-mark-article-hook
792   (list 'gnus-highlight-selected-summary)
793   "*Hook run after selecting an article in the summary buffer.
794 It is meant to be used for highlighting the article in some way.  It
795 is not run if `gnus-visual' is nil."
796   :group 'gnus-summary-visual
797   :type 'hook)
798
799 (defcustom gnus-parse-headers-hook '(gnus-set-summary-default-charset)
800   "*A hook called before parsing the headers."
801   :group 'gnus-various
802   :type 'hook)
803
804 (defcustom gnus-exit-group-hook nil
805   "*A hook called when exiting summary mode.
806 This hook is not called from the non-updating exit commands like `Q'."
807   :group 'gnus-various
808   :type 'hook)
809
810 (defcustom gnus-summary-update-hook
811   (list 'gnus-summary-highlight-line)
812   "*A hook called when a summary line is changed.
813 The hook will not be called if `gnus-visual' is nil.
814
815 The default function `gnus-summary-highlight-line' will
816 highlight the line according to the `gnus-summary-highlight'
817 variable."
818   :group 'gnus-summary-visual
819   :type 'hook)
820
821 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
822   "*A hook called when an article is selected for the first time.
823 The hook is intended to mark an article as read (or unread)
824 automatically when it is selected."
825   :group 'gnus-summary-choose
826   :type 'hook)
827
828 (defcustom gnus-group-no-more-groups-hook nil
829   "*A hook run when returning to group mode having no more (unread) groups."
830   :group 'gnus-group-select
831   :type 'hook)
832
833 (defcustom gnus-ps-print-hook nil
834   "*A hook run before ps-printing something from Gnus."
835   :group 'gnus-summary
836   :type 'hook)
837
838 (defcustom gnus-summary-display-arrow
839   (and (fboundp 'display-graphic-p)
840        (display-graphic-p))
841   "*If non-nil, display an arrow highlighting the current article."
842   :version "21.1"
843   :group 'gnus-summary
844   :type 'boolean)
845
846 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
847   "Face used for highlighting the current article in the summary buffer."
848   :group 'gnus-summary-visual
849   :type 'face)
850
851 (defcustom gnus-summary-highlight
852   '(((= mark gnus-canceled-mark)
853      . gnus-summary-cancelled-face)
854     ((and (> score default-high)
855           (or (= mark gnus-dormant-mark)
856               (= mark gnus-ticked-mark)))
857      . gnus-summary-high-ticked-face)
858     ((and (< score default-low)
859           (or (= mark gnus-dormant-mark)
860               (= mark gnus-ticked-mark)))
861      . gnus-summary-low-ticked-face)
862     ((or (= mark gnus-dormant-mark)
863          (= mark gnus-ticked-mark))
864      . gnus-summary-normal-ticked-face)
865     ((and (> score default-high) (= mark gnus-ancient-mark))
866      . gnus-summary-high-ancient-face)
867     ((and (< score default-low) (= mark gnus-ancient-mark))
868      . gnus-summary-low-ancient-face)
869     ((= mark gnus-ancient-mark)
870      . gnus-summary-normal-ancient-face)
871     ((and (> score default-high) (= mark gnus-unread-mark))
872      . gnus-summary-high-unread-face)
873     ((and (< score default-low) (= mark gnus-unread-mark))
874      . gnus-summary-low-unread-face)
875     ((= mark gnus-unread-mark)
876      . gnus-summary-normal-unread-face)
877     ((and (> score default-high) (memq mark (list gnus-downloadable-mark
878                                                   gnus-undownloaded-mark)))
879      . gnus-summary-high-unread-face)
880     ((and (< score default-low) (memq mark (list gnus-downloadable-mark
881                                                  gnus-undownloaded-mark)))
882      . gnus-summary-low-unread-face)
883     ((and (memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
884           (memq article gnus-newsgroup-unreads))
885      . gnus-summary-normal-unread-face)
886     ((memq mark (list gnus-downloadable-mark gnus-undownloaded-mark))
887      . gnus-summary-normal-read-face)
888     ((> score default-high)
889      . gnus-summary-high-read-face)
890     ((< score default-low)
891      . gnus-summary-low-read-face)
892     (t
893      . gnus-summary-normal-read-face))
894   "*Controls the highlighting of summary buffer lines.
895
896 A list of (FORM . FACE) pairs.  When deciding how a a particular
897 summary line should be displayed, each form is evaluated.  The content
898 of the face field after the first true form is used.  You can change
899 how those summary lines are displayed, by editing the face field.
900
901 You can use the following variables in the FORM field.
902
903 score:        The article's score
904 default:      The default article score.
905 default-high: The default score for high scored articles.
906 default-low:  The default score for low scored articles.
907 below:        The score below which articles are automatically marked as read.
908 mark:         The articles mark."
909   :group 'gnus-summary-visual
910   :type '(repeat (cons (sexp :tag "Form" nil)
911                        face)))
912
913 (defcustom gnus-alter-header-function nil
914   "Function called to allow alteration of article header structures.
915 The function is called with one parameter, the article header vector,
916 which it may alter in any way.")
917
918 (defvar gnus-decode-encoded-word-function
919   (mime-find-field-decoder 'From 'nov)
920   "Variable that says which function should be used to decode a string with encoded words.")
921
922 (defcustom gnus-extra-headers nil
923   "*Extra headers to parse."
924   :version "21.1"
925   :group 'gnus-summary
926   :type '(repeat symbol))
927
928 (defcustom gnus-ignored-from-addresses
929   (and user-mail-address (regexp-quote user-mail-address))
930   "*Regexp of From headers that may be suppressed in favor of To headers."
931   :version "21.1"
932   :group 'gnus-summary
933   :type 'regexp)
934
935 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
936   "List of charsets that should be ignored.
937 When these charsets are used in the \"charset\" parameter, the
938 default charset will be used instead."
939   :version "21.1"
940   :type '(repeat symbol)
941   :group 'gnus-charset)
942
943 (gnus-define-group-parameter
944  ignored-charsets
945  :type list
946  :function-document
947  "Return the ignored charsets of GROUP."
948  :variable gnus-group-ignored-charsets-alist
949  :variable-default
950  '(("alt\\.chinese\\.text" iso-8859-1))
951  :variable-document
952  "Alist of regexps (to match group names) and charsets that should be ignored.
953 When these charsets are used in the \"charset\" parameter, the
954 default charset will be used instead."
955  :variable-group gnus-charset
956  :variable-type '(repeat (cons (regexp :tag "Group")
957                                (repeat symbol)))
958  :parameter-type '(choice :tag "Ignored charsets"
959                           :value nil
960                           (repeat (symbol)))
961  :parameter-document       "\
962 List of charsets that should be ignored.
963
964 When these charsets are used in the \"charset\" parameter, the
965 default charset will be used instead.")
966
967 (defcustom gnus-group-highlight-words-alist nil
968   "Alist of group regexps and highlight regexps.
969 This variable uses the same syntax as `gnus-emphasis-alist'."
970   :version "21.1"
971   :type '(repeat (cons (regexp :tag "Group")
972                        (repeat (list (regexp :tag "Highlight regexp")
973                                      (number :tag "Group for entire word" 0)
974                                      (number :tag "Group for displayed part" 0)
975                                      (symbol :tag "Face"
976                                              gnus-emphasis-highlight-words)))))
977   :group 'gnus-summary-visual)
978
979 (defcustom gnus-use-wheel nil
980   "Use Intelli-mouse on summary movement"
981   :type 'boolean
982   :group 'gnus-summary-maneuvering)
983
984 (defcustom gnus-wheel-scroll-amount '(5 . 1)
985   "Amount to scroll messages by spinning the mouse wheel.
986 This is actually a cons cell, where the first item is the amount to scroll
987 on a normal wheel event, and the second is the amount to scroll when the
988 wheel is moved with the shift key depressed."
989   :type '(cons (integer :tag "Shift") integer)
990   :group 'gnus-summary-maneuvering)
991
992 (defcustom gnus-wheel-edge-resistance 2
993   "How hard it should be to change the current article
994 by moving the mouse over the edge of the article window."
995   :type 'integer
996   :group 'gnus-summary-maneuvering)
997
998 (defcustom gnus-summary-show-article-charset-alist
999   nil
1000   "Alist of number and charset.
1001 The article will be shown with the charset corresponding to the
1002 numbered argument.
1003 For example: ((1 . cn-gb-2312) (2 . big5))."
1004   :version "21.1"
1005   :type '(repeat (cons (number :tag "Argument" 1)
1006                        (symbol :tag "Charset")))
1007   :group 'gnus-charset)
1008
1009 (defcustom gnus-preserve-marks t
1010   "Whether marks are preserved when moving, copying and respooling messages."
1011   :version "21.1"
1012   :type 'boolean
1013   :group 'gnus-summary-marks)
1014
1015 (defcustom gnus-alter-articles-to-read-function nil
1016   "Function to be called to alter the list of articles to be selected."
1017   :type '(choice (const nil) function)
1018   :group 'gnus-summary)
1019
1020 (defcustom gnus-orphan-score nil
1021   "*All orphans get this score added.  Set in the score file."
1022   :group 'gnus-score-default
1023   :type '(choice (const nil)
1024                  integer))
1025
1026 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1027   "*A regexp to match MIME parts when saving multiple parts of a message
1028 with gnus-summary-save-parts (X m). This regexp will be used by default
1029 when prompting the user for which type of files to save."
1030   :group 'gnus-summary
1031   :type 'regexp)
1032
1033
1034 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1035   "*A regexp to match MIME parts when saving multiple parts of a message
1036 with gnus-summary-save-parts (X m). This regexp will be used by default
1037 when prompting the user for which type of files to save."
1038   :group 'gnus-summary
1039   :type 'regexp)
1040
1041 (defcustom gnus-read-all-available-headers nil
1042   "Whether Gnus should parse all headers made available to it.
1043 This is mostly relevant for slow backends where the user may
1044 wish to widen the summary buffer to include all headers
1045 that were fetched.  Say, for nnultimate groups."
1046   :group 'gnus-summary
1047   :type '(choice boolean regexp))
1048
1049 ;;; Internal variables
1050
1051 (defvar gnus-summary-display-cache nil)
1052 (defvar gnus-article-mime-handles nil)
1053 (defvar gnus-article-decoded-p nil)
1054 (defvar gnus-article-charset nil)
1055 (defvar gnus-article-ignored-charsets nil)
1056 (defvar gnus-scores-exclude-files nil)
1057 (defvar gnus-page-broken nil)
1058 (defvar gnus-inhibit-mime-unbuttonizing nil)
1059
1060 (defvar gnus-original-article nil)
1061 (defvar gnus-article-internal-prepare-hook nil)
1062 (defvar gnus-newsgroup-process-stack nil)
1063
1064 (defvar gnus-thread-indent-array nil)
1065 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1066 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1067   "Function called to sort the articles within a thread after it has been gathered together.")
1068
1069 (defvar gnus-summary-save-parts-type-history nil)
1070 (defvar gnus-summary-save-parts-last-directory nil)
1071
1072 (defvar gnus-summary-save-parts-type-history nil)
1073 (defvar gnus-summary-save-parts-last-directory nil)
1074
1075 ;; Avoid highlighting in kill files.
1076 (defvar gnus-summary-inhibit-highlight nil)
1077 (defvar gnus-newsgroup-selected-overlay nil)
1078 (defvar gnus-inhibit-limiting nil)
1079 (defvar gnus-newsgroup-adaptive-score-file nil)
1080 (defvar gnus-current-score-file nil)
1081 (defvar gnus-current-move-group nil)
1082 (defvar gnus-current-copy-group nil)
1083 (defvar gnus-current-crosspost-group nil)
1084 (defvar gnus-newsgroup-display nil)
1085
1086 (defvar gnus-newsgroup-dependencies nil)
1087 (defvar gnus-newsgroup-adaptive nil)
1088 (defvar gnus-summary-display-article-function nil)
1089 (defvar gnus-summary-highlight-line-function nil
1090   "Function called after highlighting a summary line.")
1091
1092 (defvar gnus-summary-line-format-alist
1093   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1094     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1095     (?s gnus-tmp-subject-or-nil ?s)
1096     (?n gnus-tmp-name ?s)
1097     (?A (std11-address-string
1098          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1099     (?a (or (std11-full-name-string
1100              (car (mime-entity-read-field gnus-tmp-header 'From)))
1101             gnus-tmp-from) ?s)
1102     (?F gnus-tmp-from ?s)
1103     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1104     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1105     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1106     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1107     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1108     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1109     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1110     (?L gnus-tmp-lines ?s)
1111     (?I gnus-tmp-indentation ?s)
1112     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1113     (?R gnus-tmp-replied ?c)
1114     (?\[ gnus-tmp-opening-bracket ?c)
1115     (?\] gnus-tmp-closing-bracket ?c)
1116     (?\> (make-string gnus-tmp-level ? ) ?s)
1117     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1118     (?i gnus-tmp-score ?d)
1119     (?z gnus-tmp-score-char ?c)
1120     (?l (bbb-grouplens-score gnus-tmp-header) ?s)
1121     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1122     (?U gnus-tmp-unread ?c)
1123     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1124         ?s)
1125     (?t (gnus-summary-number-of-articles-in-thread
1126          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1127         ?d)
1128     (?e (gnus-summary-number-of-articles-in-thread
1129          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1130         ?c)
1131     (?u gnus-tmp-user-defined ?s)
1132     (?P (gnus-pick-line-number) ?d)
1133     (?B gnus-tmp-thread-tree-header-string ?s))
1134   "An alist of format specifications that can appear in summary lines.
1135 These are paired with what variables they correspond with, along with
1136 the type of the variable (string, integer, character, etc).")
1137
1138 (defvar gnus-summary-dummy-line-format-alist
1139   `((?S gnus-tmp-subject ?s)
1140     (?N gnus-tmp-number ?d)
1141     (?u gnus-tmp-user-defined ?s)))
1142
1143 (defvar gnus-summary-mode-line-format-alist
1144   `((?G gnus-tmp-group-name ?s)
1145     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1146     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1147     (?A gnus-tmp-article-number ?d)
1148     (?Z gnus-tmp-unread-and-unselected ?s)
1149     (?V gnus-version ?s)
1150     (?U gnus-tmp-unread-and-unticked ?d)
1151     (?S gnus-tmp-subject ?s)
1152     (?e gnus-tmp-unselected ?d)
1153     (?u gnus-tmp-user-defined ?s)
1154     (?d (length gnus-newsgroup-dormant) ?d)
1155     (?t (length gnus-newsgroup-marked) ?d)
1156     (?r (length gnus-newsgroup-reads) ?d)
1157     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1158     (?E gnus-newsgroup-expunged-tally ?d)
1159     (?s (gnus-current-score-file-nondirectory) ?s)))
1160
1161 (defvar gnus-last-search-regexp nil
1162   "Default regexp for article search command.")
1163
1164 (defvar gnus-summary-search-article-matched-data nil
1165   "Last matched data of article search command.  It is the local variable
1166 in `gnus-article-buffer' which consists of the list of start position,
1167 end position and text.")
1168
1169 (defvar gnus-last-shell-command nil
1170   "Default shell command on article.")
1171
1172 (defvar gnus-newsgroup-begin nil)
1173 (defvar gnus-newsgroup-end nil)
1174 (defvar gnus-newsgroup-last-rmail nil)
1175 (defvar gnus-newsgroup-last-mail nil)
1176 (defvar gnus-newsgroup-last-folder nil)
1177 (defvar gnus-newsgroup-last-file nil)
1178 (defvar gnus-newsgroup-auto-expire nil)
1179 (defvar gnus-newsgroup-active nil)
1180
1181 (defvar gnus-newsgroup-data nil)
1182 (defvar gnus-newsgroup-data-reverse nil)
1183 (defvar gnus-newsgroup-limit nil)
1184 (defvar gnus-newsgroup-limits nil)
1185
1186 (defvar gnus-newsgroup-unreads nil
1187   "List of unread articles in the current newsgroup.")
1188
1189 (defvar gnus-newsgroup-unselected nil
1190   "List of unselected unread articles in the current newsgroup.")
1191
1192 (defvar gnus-newsgroup-reads nil
1193   "Alist of read articles and article marks in the current newsgroup.")
1194
1195 (defvar gnus-newsgroup-expunged-tally nil)
1196
1197 (defvar gnus-newsgroup-marked nil
1198   "List of ticked articles in the current newsgroup (a subset of unread art).")
1199
1200 (defvar gnus-newsgroup-killed nil
1201   "List of ranges of articles that have been through the scoring process.")
1202
1203 (defvar gnus-newsgroup-cached nil
1204   "List of articles that come from the article cache.")
1205
1206 (defvar gnus-newsgroup-saved nil
1207   "List of articles that have been saved.")
1208
1209 (defvar gnus-newsgroup-kill-headers nil)
1210
1211 (defvar gnus-newsgroup-replied nil
1212   "List of articles that have been replied to in the current newsgroup.")
1213
1214 (defvar gnus-newsgroup-forwarded nil
1215   "List of articles that have been forwarded in the current newsgroup.")
1216
1217 (defvar gnus-newsgroup-recent nil
1218   "List of articles that have are recent in the current newsgroup.")
1219
1220 (defvar gnus-newsgroup-expirable nil
1221   "List of articles in the current newsgroup that can be expired.")
1222
1223 (defvar gnus-newsgroup-processable nil
1224   "List of articles in the current newsgroup that can be processed.")
1225
1226 (defvar gnus-newsgroup-downloadable nil
1227   "List of articles in the current newsgroup that can be processed.")
1228
1229 (defvar gnus-newsgroup-undownloaded nil
1230   "List of articles in the current newsgroup that haven't been downloaded..")
1231
1232 (defvar gnus-newsgroup-unsendable nil
1233   "List of articles in the current newsgroup that won't be sent.")
1234
1235 (defvar gnus-newsgroup-bookmarks nil
1236   "List of articles in the current newsgroup that have bookmarks.")
1237
1238 (defvar gnus-newsgroup-dormant nil
1239   "List of dormant articles in the current newsgroup.")
1240
1241 (defvar gnus-newsgroup-unseen nil
1242   "List of unseen articles in the current newsgroup.")
1243
1244 (defvar gnus-newsgroup-seen nil
1245   "Range of seen articles in the current newsgroup.")
1246
1247 (defvar gnus-newsgroup-articles nil
1248   "List of articles in the current newsgroup.")
1249
1250 (defvar gnus-newsgroup-scored nil
1251   "List of scored articles in the current newsgroup.")
1252
1253 (defvar gnus-newsgroup-incorporated nil
1254   "List of incorporated articles in the current newsgroup.")
1255
1256 (defvar gnus-newsgroup-headers nil
1257   "List of article headers in the current newsgroup.")
1258
1259 (defvar gnus-newsgroup-threads nil)
1260
1261 (defvar gnus-newsgroup-prepared nil
1262   "Whether the current group has been prepared properly.")
1263
1264 (defvar gnus-newsgroup-ancient nil
1265   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1266
1267 (defvar gnus-newsgroup-sparse nil)
1268
1269 (defvar gnus-current-article nil)
1270 (defvar gnus-article-current nil)
1271 (defvar gnus-current-headers nil)
1272 (defvar gnus-have-all-headers nil)
1273 (defvar gnus-last-article nil)
1274 (defvar gnus-newsgroup-history nil)
1275 (defvar gnus-newsgroup-charset nil)
1276 (defvar gnus-newsgroup-ephemeral-charset nil)
1277 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1278
1279 (defvar gnus-article-before-search nil)
1280
1281 (defconst gnus-summary-local-variables
1282   '(gnus-newsgroup-name
1283     gnus-newsgroup-begin gnus-newsgroup-end
1284     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1285     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1286     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1287     gnus-newsgroup-unselected gnus-newsgroup-marked
1288     gnus-newsgroup-reads gnus-newsgroup-saved
1289     gnus-newsgroup-replied gnus-newsgroup-forwarded
1290     gnus-newsgroup-recent
1291     gnus-newsgroup-expirable
1292     gnus-newsgroup-processable gnus-newsgroup-killed
1293     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1294     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1295     gnus-newsgroup-seen gnus-newsgroup-articles
1296     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1297     gnus-newsgroup-headers gnus-newsgroup-threads
1298     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1299     gnus-current-article gnus-current-headers gnus-have-all-headers
1300     gnus-last-article gnus-article-internal-prepare-hook
1301     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1302     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1303     gnus-thread-expunge-below
1304     gnus-score-alist gnus-current-score-file
1305     (gnus-summary-expunge-below . global)
1306     (gnus-summary-mark-below . global)
1307     (gnus-orphan-score . global)
1308     gnus-newsgroup-active gnus-scores-exclude-files
1309     gnus-newsgroup-history gnus-newsgroup-ancient
1310     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1311     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1312     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1313     (gnus-newsgroup-expunged-tally . 0)
1314     gnus-cache-removable-articles gnus-newsgroup-cached
1315     gnus-newsgroup-data gnus-newsgroup-data-reverse
1316     gnus-newsgroup-limit gnus-newsgroup-limits
1317     gnus-newsgroup-charset gnus-newsgroup-display
1318     gnus-newsgroup-incorporated)
1319   "Variables that are buffer-local to the summary buffers.")
1320
1321 (defvar gnus-newsgroup-variables nil
1322   "Variables that have separate values in the newsgroups.")
1323
1324 ;; Byte-compiler warning.
1325 (eval-when-compile (defvar gnus-article-mode-map))
1326
1327 ;; Subject simplification.
1328
1329 (defun gnus-simplify-whitespace (str)
1330   "Remove excessive whitespace from STR."
1331   (let ((mystr str))
1332     ;; Multiple spaces.
1333     (while (string-match "[ \t][ \t]+" mystr)
1334       (setq mystr (concat (substring mystr 0 (match-beginning 0))
1335                           " "
1336                           (substring mystr (match-end 0)))))
1337     ;; Leading spaces.
1338     (when (string-match "^[ \t]+" mystr)
1339       (setq mystr (substring mystr (match-end 0))))
1340     ;; Trailing spaces.
1341     (when (string-match "[ \t]+$" mystr)
1342       (setq mystr (substring mystr 0 (match-beginning 0))))
1343     mystr))
1344
1345 (defsubst gnus-simplify-subject-re (subject)
1346   "Remove \"Re:\" from subject lines."
1347   (if (string-match message-subject-re-regexp subject)
1348       (substring subject (match-end 0))
1349     subject))
1350
1351 (defun gnus-simplify-subject (subject &optional re-only)
1352   "Remove `Re:' and words in parentheses.
1353 If RE-ONLY is non-nil, strip leading `Re:'s only."
1354   (let ((case-fold-search t))           ;Ignore case.
1355     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1356     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1357       (setq subject (substring subject (match-end 0))))
1358     ;; Remove uninteresting prefixes.
1359     (when (and (not re-only)
1360                gnus-simplify-ignored-prefixes
1361                (string-match gnus-simplify-ignored-prefixes subject))
1362       (setq subject (substring subject (match-end 0))))
1363     ;; Remove words in parentheses from end.
1364     (unless re-only
1365       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1366         (setq subject (substring subject 0 (match-beginning 0)))))
1367     ;; Return subject string.
1368     subject))
1369
1370 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1371 ;; all whitespace.
1372 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1373   (goto-char (point-min))
1374   (while (re-search-forward regexp nil t)
1375     (replace-match (or newtext ""))))
1376
1377 (defun gnus-simplify-buffer-fuzzy ()
1378   "Simplify string in the buffer fuzzily.
1379 The string in the accessible portion of the current buffer is simplified.
1380 It is assumed to be a single-line subject.
1381 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1382 matter is removed.  Additional things can be deleted by setting
1383 `gnus-simplify-subject-fuzzy-regexp'."
1384   (let ((case-fold-search t)
1385         (modified-tick))
1386     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1387
1388     (while (not (eq modified-tick (buffer-modified-tick)))
1389       (setq modified-tick (buffer-modified-tick))
1390       (cond
1391        ((listp gnus-simplify-subject-fuzzy-regexp)
1392         (mapcar 'gnus-simplify-buffer-fuzzy-step
1393                 gnus-simplify-subject-fuzzy-regexp))
1394        (gnus-simplify-subject-fuzzy-regexp
1395         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1396       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1397       (gnus-simplify-buffer-fuzzy-step
1398        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1399       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1400
1401     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1402     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1403     (gnus-simplify-buffer-fuzzy-step " $")
1404     (gnus-simplify-buffer-fuzzy-step "^ +")))
1405
1406 (defun gnus-simplify-subject-fuzzy (subject)
1407   "Simplify a subject string fuzzily.
1408 See `gnus-simplify-buffer-fuzzy' for details."
1409   (save-excursion
1410     (gnus-set-work-buffer)
1411     (let ((case-fold-search t))
1412       ;; Remove uninteresting prefixes.
1413       (when (and gnus-simplify-ignored-prefixes
1414                  (string-match gnus-simplify-ignored-prefixes subject))
1415         (setq subject (substring subject (match-end 0))))
1416       (insert subject)
1417       (inline (gnus-simplify-buffer-fuzzy))
1418       (buffer-string))))
1419
1420 (defsubst gnus-simplify-subject-fully (subject)
1421   "Simplify a subject string according to gnus-summary-gather-subject-limit."
1422   (cond
1423    (gnus-simplify-subject-functions
1424     (gnus-map-function gnus-simplify-subject-functions subject))
1425    ((null gnus-summary-gather-subject-limit)
1426     (gnus-simplify-subject-re subject))
1427    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1428     (gnus-simplify-subject-fuzzy subject))
1429    ((numberp gnus-summary-gather-subject-limit)
1430     (gnus-limit-string (gnus-simplify-subject-re subject)
1431                        gnus-summary-gather-subject-limit))
1432    (t
1433     subject)))
1434
1435 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1436   "Check whether two subjects are equal.
1437 If optional argument simple-first is t, first argument is already
1438 simplified."
1439   (cond
1440    ((null simple-first)
1441     (equal (gnus-simplify-subject-fully s1)
1442            (gnus-simplify-subject-fully s2)))
1443    (t
1444     (equal s1
1445            (gnus-simplify-subject-fully s2)))))
1446
1447 (defun gnus-summary-bubble-group ()
1448   "Increase the score of the current group.
1449 This is a handy function to add to `gnus-summary-exit-hook' to
1450 increase the score of each group you read."
1451   (gnus-group-add-score gnus-newsgroup-name))
1452
1453 \f
1454 ;;;
1455 ;;; Gnus summary mode
1456 ;;;
1457
1458 (put 'gnus-summary-mode 'mode-class 'special)
1459
1460 (defvar gnus-article-commands-menu)
1461
1462 (when t
1463   ;; Non-orthogonal keys
1464
1465   (gnus-define-keys gnus-summary-mode-map
1466     " " gnus-summary-next-page
1467     "\177" gnus-summary-prev-page
1468     [delete] gnus-summary-prev-page
1469     [backspace] gnus-summary-prev-page
1470     "\r" gnus-summary-scroll-up
1471     "\M-\r" gnus-summary-scroll-down
1472     "n" gnus-summary-next-unread-article
1473     "p" gnus-summary-prev-unread-article
1474     "N" gnus-summary-next-article
1475     "P" gnus-summary-prev-article
1476     "\M-\C-n" gnus-summary-next-same-subject
1477     "\M-\C-p" gnus-summary-prev-same-subject
1478     "\M-n" gnus-summary-next-unread-subject
1479     "\M-p" gnus-summary-prev-unread-subject
1480     "." gnus-summary-first-unread-article
1481     "," gnus-summary-best-unread-article
1482     "\M-s" gnus-summary-search-article-forward
1483     "\M-r" gnus-summary-search-article-backward
1484     "<" gnus-summary-beginning-of-article
1485     ">" gnus-summary-end-of-article
1486     "j" gnus-summary-goto-article
1487     "^" gnus-summary-refer-parent-article
1488     "\M-^" gnus-summary-refer-article
1489     "u" gnus-summary-tick-article-forward
1490     "!" gnus-summary-tick-article-forward
1491     "U" gnus-summary-tick-article-backward
1492     "d" gnus-summary-mark-as-read-forward
1493     "D" gnus-summary-mark-as-read-backward
1494     "E" gnus-summary-mark-as-expirable
1495     "\M-u" gnus-summary-clear-mark-forward
1496     "\M-U" gnus-summary-clear-mark-backward
1497     "k" gnus-summary-kill-same-subject-and-select
1498     "\C-k" gnus-summary-kill-same-subject
1499     "\M-\C-k" gnus-summary-kill-thread
1500     "\M-\C-l" gnus-summary-lower-thread
1501     "e" gnus-summary-edit-article
1502     "#" gnus-summary-mark-as-processable
1503     "\M-#" gnus-summary-unmark-as-processable
1504     "\M-\C-t" gnus-summary-toggle-threads
1505     "\M-\C-s" gnus-summary-show-thread
1506     "\M-\C-h" gnus-summary-hide-thread
1507     "\M-\C-f" gnus-summary-next-thread
1508     "\M-\C-b" gnus-summary-prev-thread
1509     [(meta down)] gnus-summary-next-thread
1510     [(meta up)] gnus-summary-prev-thread
1511     "\M-\C-u" gnus-summary-up-thread
1512     "\M-\C-d" gnus-summary-down-thread
1513     "&" gnus-summary-execute-command
1514     "c" gnus-summary-catchup-and-exit
1515     "\C-w" gnus-summary-mark-region-as-read
1516     "\C-t" gnus-summary-toggle-truncation
1517     "?" gnus-summary-mark-as-dormant
1518     "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1519     "\C-c\C-s\C-n" gnus-summary-sort-by-number
1520     "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1521     "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1522     "\C-c\C-s\C-a" gnus-summary-sort-by-author
1523     "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1524     "\C-c\C-s\C-d" gnus-summary-sort-by-date
1525     "\C-c\C-s\C-i" gnus-summary-sort-by-score
1526     "\C-c\C-s\C-o" gnus-summary-sort-by-original
1527     "=" gnus-summary-expand-window
1528     "\C-x\C-s" gnus-summary-reselect-current-group
1529     "\M-g" gnus-summary-rescan-group
1530     "w" gnus-summary-stop-page-breaking
1531     "\C-c\C-r" gnus-summary-caesar-message
1532     "\M-t" gnus-summary-toggle-mime
1533     "f" gnus-summary-followup
1534     "F" gnus-summary-followup-with-original
1535     "C" gnus-summary-cancel-article
1536     "r" gnus-summary-reply
1537     "R" gnus-summary-reply-with-original
1538     "\C-c\C-f" gnus-summary-mail-forward
1539     "o" gnus-summary-save-article
1540     "\C-o" gnus-summary-save-article-mail
1541     "|" gnus-summary-pipe-output
1542     "\M-k" gnus-summary-edit-local-kill
1543     "\M-K" gnus-summary-edit-global-kill
1544     ;; "V" gnus-version
1545     "\C-c\C-d" gnus-summary-describe-group
1546     "q" gnus-summary-exit
1547     "Q" gnus-summary-exit-no-update
1548     "\C-c\C-i" gnus-info-find-node
1549     gnus-mouse-2 gnus-mouse-pick-article
1550     "m" gnus-summary-mail-other-window
1551     "a" gnus-summary-post-news
1552     "x" gnus-summary-limit-to-unread
1553     "s" gnus-summary-isearch-article
1554     "t" gnus-article-toggle-headers
1555     "g" gnus-summary-show-article
1556     "l" gnus-summary-goto-last-article
1557     "v" gnus-summary-preview-mime-message
1558     "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1559     "\C-d" gnus-summary-enter-digest-group
1560     "\M-\C-d" gnus-summary-read-document
1561     "\M-\C-e" gnus-summary-edit-parameters
1562     "\M-\C-a" gnus-summary-customize-parameters
1563     "\C-c\C-b" gnus-bug
1564     "\C-c\C-n" gnus-namazu-search
1565     "*" gnus-cache-enter-article
1566     "\M-*" gnus-cache-remove-article
1567     "\M-&" gnus-summary-universal-argument
1568     "\C-l" gnus-recenter
1569     "I" gnus-summary-increase-score
1570     "L" gnus-summary-lower-score
1571     "\M-i" gnus-symbolic-argument
1572     "h" gnus-summary-select-article-buffer
1573
1574     "V" gnus-summary-score-map
1575     "X" gnus-uu-extract-map
1576     "S" gnus-summary-send-map)
1577
1578   ;; Sort of orthogonal keymap
1579   (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1580     "t" gnus-summary-tick-article-forward
1581     "!" gnus-summary-tick-article-forward
1582     "d" gnus-summary-mark-as-read-forward
1583     "r" gnus-summary-mark-as-read-forward
1584     "c" gnus-summary-clear-mark-forward
1585     " " gnus-summary-clear-mark-forward
1586     "e" gnus-summary-mark-as-expirable
1587     "x" gnus-summary-mark-as-expirable
1588     "?" gnus-summary-mark-as-dormant
1589     "b" gnus-summary-set-bookmark
1590     "B" gnus-summary-remove-bookmark
1591     "#" gnus-summary-mark-as-processable
1592     "\M-#" gnus-summary-unmark-as-processable
1593     "S" gnus-summary-limit-include-expunged
1594     "C" gnus-summary-catchup
1595     "H" gnus-summary-catchup-to-here
1596     "h" gnus-summary-catchup-from-here
1597     "\C-c" gnus-summary-catchup-all
1598     "k" gnus-summary-kill-same-subject-and-select
1599     "K" gnus-summary-kill-same-subject
1600     "P" gnus-uu-mark-map)
1601
1602   (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1603     "c" gnus-summary-clear-above
1604     "u" gnus-summary-tick-above
1605     "m" gnus-summary-mark-above
1606     "k" gnus-summary-kill-below)
1607
1608   (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1609     "/" gnus-summary-limit-to-subject
1610     "n" gnus-summary-limit-to-articles
1611     "w" gnus-summary-pop-limit
1612     "s" gnus-summary-limit-to-subject
1613     "a" gnus-summary-limit-to-author
1614     "u" gnus-summary-limit-to-unread
1615     "m" gnus-summary-limit-to-marks
1616     "M" gnus-summary-limit-exclude-marks
1617     "v" gnus-summary-limit-to-score
1618     "*" gnus-summary-limit-include-cached
1619     "D" gnus-summary-limit-include-dormant
1620     "T" gnus-summary-limit-include-thread
1621     "d" gnus-summary-limit-exclude-dormant
1622     "t" gnus-summary-limit-to-age
1623     "x" gnus-summary-limit-to-extra
1624     "p" gnus-summary-limit-to-display-predicate
1625     "E" gnus-summary-limit-include-expunged
1626     "c" gnus-summary-limit-exclude-childless-dormant
1627     "C" gnus-summary-limit-mark-excluded-as-read
1628     "o" gnus-summary-insert-old-articles
1629     "N" gnus-summary-insert-new-articles)
1630
1631   (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1632     "n" gnus-summary-next-unread-article
1633     "p" gnus-summary-prev-unread-article
1634     "N" gnus-summary-next-article
1635     "P" gnus-summary-prev-article
1636     "\C-n" gnus-summary-next-same-subject
1637     "\C-p" gnus-summary-prev-same-subject
1638     "\M-n" gnus-summary-next-unread-subject
1639     "\M-p" gnus-summary-prev-unread-subject
1640     "f" gnus-summary-first-unread-article
1641     "b" gnus-summary-best-unread-article
1642     "j" gnus-summary-goto-article
1643     "g" gnus-summary-goto-subject
1644     "l" gnus-summary-goto-last-article
1645     "o" gnus-summary-pop-article)
1646
1647   (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1648     "k" gnus-summary-kill-thread
1649     "l" gnus-summary-lower-thread
1650     "i" gnus-summary-raise-thread
1651     "T" gnus-summary-toggle-threads
1652     "t" gnus-summary-rethread-current
1653     "^" gnus-summary-reparent-thread
1654     "s" gnus-summary-show-thread
1655     "S" gnus-summary-show-all-threads
1656     "h" gnus-summary-hide-thread
1657     "H" gnus-summary-hide-all-threads
1658     "n" gnus-summary-next-thread
1659     "p" gnus-summary-prev-thread
1660     "u" gnus-summary-up-thread
1661     "o" gnus-summary-top-thread
1662     "d" gnus-summary-down-thread
1663     "#" gnus-uu-mark-thread
1664     "\M-#" gnus-uu-unmark-thread)
1665
1666   (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1667     "g" gnus-summary-prepare
1668     "c" gnus-summary-insert-cached-articles)
1669
1670   (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1671     "c" gnus-summary-catchup-and-exit
1672     "C" gnus-summary-catchup-all-and-exit
1673     "E" gnus-summary-exit-no-update
1674     "J" gnus-summary-jump-to-other-group
1675     "Q" gnus-summary-exit
1676     "Z" gnus-summary-exit
1677     "n" gnus-summary-catchup-and-goto-next-group
1678     "R" gnus-summary-reselect-current-group
1679     "G" gnus-summary-rescan-group
1680     "N" gnus-summary-next-group
1681     "s" gnus-summary-save-newsrc
1682     "P" gnus-summary-prev-group)
1683
1684   (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1685     " " gnus-summary-next-page
1686     "n" gnus-summary-next-page
1687     "\177" gnus-summary-prev-page
1688     [delete] gnus-summary-prev-page
1689     "p" gnus-summary-prev-page
1690     "\r" gnus-summary-scroll-up
1691     "\M-\r" gnus-summary-scroll-down
1692     "<" gnus-summary-beginning-of-article
1693     ">" gnus-summary-end-of-article
1694     "b" gnus-summary-beginning-of-article
1695     "e" gnus-summary-end-of-article
1696     "^" gnus-summary-refer-parent-article
1697     "r" gnus-summary-refer-parent-article
1698     "D" gnus-summary-enter-digest-group
1699     "R" gnus-summary-refer-references
1700     "T" gnus-summary-refer-thread
1701     "g" gnus-summary-show-article
1702     "s" gnus-summary-isearch-article
1703     "P" gnus-summary-print-article
1704     "M" gnus-mailing-list-insinuate
1705     "t" gnus-article-babel)
1706
1707   (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1708     "b" gnus-article-add-buttons
1709     "B" gnus-article-add-buttons-to-head
1710     "o" gnus-article-treat-overstrike
1711     "e" gnus-article-emphasize
1712     "w" gnus-article-fill-cited-article
1713     "Q" gnus-article-fill-long-lines
1714     "C" gnus-article-capitalize-sentences
1715     "c" gnus-article-remove-cr
1716     "Z" gnus-article-decode-HZ
1717     "f" gnus-article-display-x-face
1718     "l" gnus-summary-stop-page-breaking
1719     "r" gnus-summary-caesar-message
1720     "t" gnus-article-toggle-headers
1721     "g" gnus-summary-toggle-smiley
1722     "v" gnus-summary-verbose-headers
1723     "m" gnus-summary-toggle-mime
1724     "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1725     "p" gnus-article-verify-x-pgp-sig
1726     "d" gnus-article-treat-dumbquotes
1727     "s" gnus-smiley-display)
1728
1729   (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1730     "a" gnus-article-hide
1731     "h" gnus-article-toggle-headers
1732     "b" gnus-article-hide-boring-headers
1733     "s" gnus-article-hide-signature
1734     "c" gnus-article-hide-citation
1735     "C" gnus-article-hide-citation-in-followups
1736     "l" gnus-article-hide-list-identifiers
1737     "p" gnus-article-hide-pgp
1738     "B" gnus-article-strip-banner
1739     "P" gnus-article-hide-pem
1740     "\C-c" gnus-article-hide-citation-maybe)
1741
1742   (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1743     "a" gnus-article-highlight
1744     "h" gnus-article-highlight-headers
1745     "c" gnus-article-highlight-citation
1746     "s" gnus-article-highlight-signature)
1747
1748   (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1749     "z" gnus-article-date-ut
1750     "u" gnus-article-date-ut
1751     "l" gnus-article-date-local
1752     "p" gnus-article-date-english
1753     "e" gnus-article-date-lapsed
1754     "o" gnus-article-date-original
1755     "i" gnus-article-date-iso8601
1756     "s" gnus-article-date-user)
1757
1758   (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1759     "t" gnus-article-remove-trailing-blank-lines
1760     "l" gnus-article-strip-leading-blank-lines
1761     "m" gnus-article-strip-multiple-blank-lines
1762     "a" gnus-article-strip-blank-lines
1763     "A" gnus-article-strip-all-blank-lines
1764     "s" gnus-article-strip-leading-space
1765     "e" gnus-article-strip-trailing-space
1766     "w" gnus-article-remove-leading-whitespace)
1767
1768   (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1769     "v" gnus-version
1770     "f" gnus-summary-fetch-faq
1771     "d" gnus-summary-describe-group
1772     "h" gnus-summary-describe-briefly
1773     "i" gnus-info-find-node)
1774
1775   (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1776     "e" gnus-summary-expire-articles
1777     "\M-\C-e" gnus-summary-expire-articles-now
1778     "\177" gnus-summary-delete-article
1779     [delete] gnus-summary-delete-article
1780     [backspace] gnus-summary-delete-article
1781     "m" gnus-summary-move-article
1782     "r" gnus-summary-respool-article
1783     "w" gnus-summary-edit-article
1784     "c" gnus-summary-copy-article
1785     "B" gnus-summary-crosspost-article
1786     "q" gnus-summary-respool-query
1787     "t" gnus-summary-respool-trace
1788     "i" gnus-summary-import-article
1789     "I" gnus-summary-create-article
1790     "p" gnus-summary-article-posted-p)
1791
1792   (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1793     "o" gnus-summary-save-article
1794     "m" gnus-summary-save-article-mail
1795     "F" gnus-summary-write-article-file
1796     "r" gnus-summary-save-article-rmail
1797     "f" gnus-summary-save-article-file
1798     "b" gnus-summary-save-article-body-file
1799     "h" gnus-summary-save-article-folder
1800     "v" gnus-summary-save-article-vm
1801     "p" gnus-summary-pipe-output
1802     "s" gnus-soup-add-article)
1803
1804   (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1805     "b" gnus-summary-display-buttonized
1806     "m" gnus-summary-repair-multipart
1807     "v" gnus-article-view-part
1808     "o" gnus-article-save-part
1809     "c" gnus-article-copy-part
1810     "C" gnus-article-view-part-as-charset
1811     "e" gnus-article-externalize-part
1812     "E" gnus-article-encrypt-body
1813     "i" gnus-article-inline-part
1814     "|" gnus-article-pipe-part))
1815
1816 (defvar gnus-article-post-menu nil)
1817
1818 (defun gnus-summary-make-menu-bar ()
1819   (gnus-turn-off-edit-menu 'summary)
1820
1821   (unless (boundp 'gnus-summary-misc-menu)
1822
1823     (easy-menu-define
1824      gnus-summary-kill-menu gnus-summary-mode-map ""
1825      (cons
1826       "Score"
1827       (nconc
1828        (list
1829         ["Customize" gnus-score-customize t])
1830        (gnus-make-score-map 'increase)
1831        (gnus-make-score-map 'lower)
1832        '(("Mark"
1833           ["Kill below" gnus-summary-kill-below t]
1834           ["Mark above" gnus-summary-mark-above t]
1835           ["Tick above" gnus-summary-tick-above t]
1836           ["Clear above" gnus-summary-clear-above t])
1837          ["Current score" gnus-summary-current-score t]
1838          ["Set score" gnus-summary-set-score t]
1839          ["Switch current score file..." gnus-score-change-score-file t]
1840          ["Set mark below..." gnus-score-set-mark-below t]
1841          ["Set expunge below..." gnus-score-set-expunge-below t]
1842          ["Edit current score file" gnus-score-edit-current-scores t]
1843          ["Edit score file" gnus-score-edit-file t]
1844          ["Trace score" gnus-score-find-trace t]
1845          ["Find words" gnus-score-find-favourite-words t]
1846          ["Rescore buffer" gnus-summary-rescore t]
1847          ["Increase score..." gnus-summary-increase-score t]
1848          ["Lower score..." gnus-summary-lower-score t]))))
1849
1850     ;; Define both the Article menu in the summary buffer and the equivalent
1851     ;; Commands menu in the article buffer here for consistency.
1852     (let ((innards
1853            `(("Hide"
1854               ["All" gnus-article-hide t]
1855               ["Headers" gnus-article-toggle-headers t]
1856               ["Signature" gnus-article-hide-signature t]
1857               ["Citation" gnus-article-hide-citation t]
1858               ["List identifiers" gnus-article-hide-list-identifiers t]
1859               ["PGP" gnus-article-hide-pgp t]
1860               ["Banner" gnus-article-strip-banner t]
1861               ["Boring headers" gnus-article-hide-boring-headers t])
1862              ("Highlight"
1863               ["All" gnus-article-highlight t]
1864               ["Headers" gnus-article-highlight-headers t]
1865               ["Signature" gnus-article-highlight-signature t]
1866               ["Citation" gnus-article-highlight-citation t])
1867              ("Date"
1868               ["Local" gnus-article-date-local t]
1869               ["ISO8601" gnus-article-date-iso8601 t]
1870               ["UT" gnus-article-date-ut t]
1871               ["Original" gnus-article-date-original t]
1872               ["Lapsed" gnus-article-date-lapsed t]
1873               ["User-defined" gnus-article-date-user t])
1874              ("Washing"
1875               ("Remove Blanks"
1876                ["Leading" gnus-article-strip-leading-blank-lines t]
1877                ["Multiple" gnus-article-strip-multiple-blank-lines t]
1878                ["Trailing" gnus-article-remove-trailing-blank-lines t]
1879                ["All of the above" gnus-article-strip-blank-lines t]
1880                ["All" gnus-article-strip-all-blank-lines t]
1881                ["Leading space" gnus-article-strip-leading-space t]
1882                ["Trailing space" gnus-article-strip-trailing-space t]
1883                ["Leading space in headers"
1884                 gnus-article-remove-leading-whitespace t])
1885               ["Overstrike" gnus-article-treat-overstrike t]
1886               ["Dumb quotes" gnus-article-treat-dumbquotes t]
1887               ["Emphasis" gnus-article-emphasize t]
1888               ["Word wrap" gnus-article-fill-cited-article t]
1889               ["Fill long lines" gnus-article-fill-long-lines t]
1890               ["Capitalize sentences" gnus-article-capitalize-sentences t]
1891               ["CR" gnus-article-remove-cr t]
1892               ["Show X-Face" gnus-article-display-x-face t]
1893               ["Rot 13" gnus-summary-caesar-message
1894                ,@(if (featurep 'xemacs) '(t)
1895                    '(:help "\"Caesar rotate\" article by 13"))]
1896               ["Unix pipe" gnus-summary-pipe-message t]
1897               ["Add buttons" gnus-article-add-buttons t]
1898               ["Add buttons to head" gnus-article-add-buttons-to-head t]
1899               ["Stop page breaking" gnus-summary-stop-page-breaking t]
1900               ["Toggle MIME" gnus-summary-toggle-mime t]
1901               ["Verbose header" gnus-summary-verbose-headers t]
1902               ["Toggle header" gnus-summary-toggle-header t]
1903               ["Toggle smiley" gnus-summary-toggle-smiley t]
1904               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
1905               ["HZ" gnus-article-decode-HZ t])
1906              ("Output"
1907               ["Save in default format" gnus-summary-save-article
1908                ,@(if (featurep 'xemacs) '(t)
1909                    '(:help "Save article using default method"))]
1910               ["Save in file" gnus-summary-save-article-file
1911                ,@(if (featurep 'xemacs) '(t)
1912                    '(:help "Save article in file"))]
1913               ["Save in Unix mail format" gnus-summary-save-article-mail t]
1914               ["Save in MH folder" gnus-summary-save-article-folder t]
1915               ["Save in VM folder" gnus-summary-save-article-vm t]
1916               ["Save in RMAIL mbox" gnus-summary-save-article-rmail t]
1917               ["Save body in file" gnus-summary-save-article-body-file t]
1918               ["Pipe through a filter" gnus-summary-pipe-output t]
1919               ["Add to SOUP packet" gnus-soup-add-article t]
1920               ["Print" gnus-summary-print-article t])
1921              ("Backend"
1922               ["Respool article..." gnus-summary-respool-article t]
1923               ["Move article..." gnus-summary-move-article
1924                (gnus-check-backend-function
1925                 'request-move-article gnus-newsgroup-name)]
1926               ["Copy article..." gnus-summary-copy-article t]
1927               ["Crosspost article..." gnus-summary-crosspost-article
1928                (gnus-check-backend-function
1929                 'request-replace-article gnus-newsgroup-name)]
1930               ["Import file..." gnus-summary-import-article t]
1931               ["Create article..." gnus-summary-create-article t]
1932               ["Check if posted" gnus-summary-article-posted-p t]
1933               ["Edit article" gnus-summary-edit-article
1934                (not (gnus-group-read-only-p))]
1935               ["Delete article" gnus-summary-delete-article
1936                (gnus-check-backend-function
1937                 'request-expire-articles gnus-newsgroup-name)]
1938               ["Query respool" gnus-summary-respool-query t]
1939               ["Trace respool" gnus-summary-respool-trace t]
1940               ["Delete expirable articles" gnus-summary-expire-articles-now
1941                (gnus-check-backend-function
1942                 'request-expire-articles gnus-newsgroup-name)])
1943              ("Extract"
1944               ["Uudecode" gnus-uu-decode-uu
1945                ,@(if (featurep 'xemacs) '(t)
1946                    '(:help "Decode uuencoded article(s)"))]
1947               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
1948               ["Unshar" gnus-uu-decode-unshar t]
1949               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
1950               ["Save" gnus-uu-decode-save t]
1951               ["Binhex" gnus-uu-decode-binhex t]
1952               ["Postscript" gnus-uu-decode-postscript t])
1953              ("Cache"
1954               ["Enter article" gnus-cache-enter-article t]
1955               ["Remove article" gnus-cache-remove-article t])
1956              ["Translate" gnus-article-babel t]
1957              ["Select article buffer" gnus-summary-select-article-buffer t]
1958              ["Enter digest buffer" gnus-summary-enter-digest-group t]
1959              ["Isearch article..." gnus-summary-isearch-article t]
1960              ["Beginning of the article" gnus-summary-beginning-of-article t]
1961              ["End of the article" gnus-summary-end-of-article t]
1962              ["Fetch parent of article" gnus-summary-refer-parent-article t]
1963              ["Fetch referenced articles" gnus-summary-refer-references t]
1964              ["Fetch current thread" gnus-summary-refer-thread t]
1965              ["Fetch article with id..." gnus-summary-refer-article t]
1966              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
1967              ["Redisplay" gnus-summary-show-article t]
1968              ["Raw article" gnus-summary-show-raw-article t])))
1969       (easy-menu-define
1970        gnus-summary-article-menu gnus-summary-mode-map ""
1971        (cons "Article" innards))
1972
1973       (if (not (keymapp gnus-summary-article-menu))
1974           (easy-menu-define
1975            gnus-article-commands-menu gnus-article-mode-map ""
1976            (cons "Commands" innards))
1977         ;; in Emacs, don't share menu.
1978         (setq gnus-article-commands-menu
1979               (copy-keymap gnus-summary-article-menu))
1980         (define-key gnus-article-mode-map [menu-bar commands]
1981           (cons "Commands" gnus-article-commands-menu))))
1982
1983     (easy-menu-define
1984      gnus-summary-thread-menu gnus-summary-mode-map ""
1985      '("Threads"
1986        ["Toggle threading" gnus-summary-toggle-threads t]
1987        ["Hide threads" gnus-summary-hide-all-threads t]
1988        ["Show threads" gnus-summary-show-all-threads t]
1989        ["Hide thread" gnus-summary-hide-thread t]
1990        ["Show thread" gnus-summary-show-thread t]
1991        ["Go to next thread" gnus-summary-next-thread t]
1992        ["Go to previous thread" gnus-summary-prev-thread t]
1993        ["Go down thread" gnus-summary-down-thread t]
1994        ["Go up thread" gnus-summary-up-thread t]
1995        ["Top of thread" gnus-summary-top-thread t]
1996        ["Mark thread as read" gnus-summary-kill-thread t]
1997        ["Lower thread score" gnus-summary-lower-thread t]
1998        ["Raise thread score" gnus-summary-raise-thread t]
1999        ["Rethread current" gnus-summary-rethread-current t]))
2000
2001     (easy-menu-define
2002      gnus-summary-post-menu gnus-summary-mode-map ""
2003      `("Post"
2004        ["Post an article" gnus-summary-post-news
2005         ,@(if (featurep 'xemacs) '(t)
2006             '(:help "Post an article"))]
2007        ["Followup" gnus-summary-followup
2008         ,@(if (featurep 'xemacs) '(t)
2009             '(:help "Post followup to this article"))]
2010        ["Followup and yank" gnus-summary-followup-with-original
2011         ,@(if (featurep 'xemacs) '(t)
2012             '(:help "Post followup to this article, quoting its contents"))]
2013        ["Supersede article" gnus-summary-supersede-article t]
2014        ["Cancel article" gnus-summary-cancel-article
2015         ,@(if (featurep 'xemacs) '(t)
2016             '(:help "Cancel an article you posted"))]
2017        ["Reply" gnus-summary-reply t]
2018        ["Reply and yank" gnus-summary-reply-with-original t]
2019        ["Wide reply" gnus-summary-wide-reply t]
2020        ["Wide reply and yank" gnus-summary-wide-reply-with-original
2021         ,@(if (featurep 'xemacs) '(t)
2022             '(:help "Mail a reply, quoting this article"))]
2023        ["Mail forward" gnus-summary-mail-forward t]
2024        ["Post forward" gnus-summary-post-forward t]
2025        ["Digest and mail" gnus-summary-digest-mail-forward t]
2026        ["Digest and post" gnus-summary-digest-post-forward t]
2027        ["Resend message" gnus-summary-resend-message t]
2028        ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2029        ["Send a mail" gnus-summary-mail-other-window t]
2030        ["Uuencode and post" gnus-uu-post-news
2031         ,@(if (featurep 'xemacs) '(t)
2032             '(:help "Post a uuencoded article"))]
2033        ["Followup via news" gnus-summary-followup-to-mail t]
2034        ["Followup via news and yank"
2035         gnus-summary-followup-to-mail-with-original t]
2036        ;;("Draft"
2037        ;;["Send" gnus-summary-send-draft t]
2038        ;;["Send bounced" gnus-resend-bounced-mail t])
2039        ))
2040
2041     (cond
2042      ((not (keymapp gnus-summary-post-menu))
2043       (setq gnus-article-post-menu gnus-summary-post-menu))
2044      ((not gnus-article-post-menu)
2045       ;; Don't share post menu.
2046       (setq gnus-article-post-menu
2047             (copy-keymap gnus-summary-post-menu))))
2048     (define-key gnus-article-mode-map [menu-bar post]
2049       (cons "Post" gnus-article-post-menu))
2050
2051     (easy-menu-define
2052      gnus-summary-misc-menu gnus-summary-mode-map ""
2053      `("Gnus"
2054        ("Mark Read"
2055         ["Mark as read" gnus-summary-mark-as-read-forward t]
2056         ["Mark same subject and select"
2057          gnus-summary-kill-same-subject-and-select t]
2058         ["Mark same subject" gnus-summary-kill-same-subject t]
2059         ["Catchup" gnus-summary-catchup
2060          ,@(if (featurep 'xemacs) '(t)
2061              '(:help "Mark unread articles in this group as read"))]
2062         ["Catchup all" gnus-summary-catchup-all t]
2063         ["Catchup to here" gnus-summary-catchup-to-here t]
2064         ["Catchup from here" gnus-summary-catchup-from-here t]
2065         ["Catchup region" gnus-summary-mark-region-as-read t]
2066         ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2067        ("Mark Various"
2068         ["Tick" gnus-summary-tick-article-forward t]
2069         ["Mark as dormant" gnus-summary-mark-as-dormant t]
2070         ["Remove marks" gnus-summary-clear-mark-forward t]
2071         ["Set expirable mark" gnus-summary-mark-as-expirable t]
2072         ["Set bookmark" gnus-summary-set-bookmark t]
2073         ["Remove bookmark" gnus-summary-remove-bookmark t])
2074        ("Mark Limit"
2075         ["Marks..." gnus-summary-limit-to-marks t]
2076         ["Subject..." gnus-summary-limit-to-subject t]
2077         ["Author..." gnus-summary-limit-to-author t]
2078         ["Age..." gnus-summary-limit-to-age t]
2079         ["Extra..." gnus-summary-limit-to-extra t]
2080         ["Score" gnus-summary-limit-to-score t]
2081         ["Score" gnus-summary-limit-to-display-predicate t]
2082         ["Unread" gnus-summary-limit-to-unread t]
2083         ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2084         ["Articles" gnus-summary-limit-to-articles t]
2085         ["Pop limit" gnus-summary-pop-limit t]
2086         ["Show dormant" gnus-summary-limit-include-dormant t]
2087         ["Hide childless dormant"
2088          gnus-summary-limit-exclude-childless-dormant t]
2089         ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2090         ["Hide marked" gnus-summary-limit-exclude-marks t]
2091         ["Show expunged" gnus-summary-limit-include-expunged t])
2092        ("Process Mark"
2093         ["Set mark" gnus-summary-mark-as-processable t]
2094         ["Remove mark" gnus-summary-unmark-as-processable t]
2095         ["Remove all marks" gnus-summary-unmark-all-processable t]
2096         ["Mark above" gnus-uu-mark-over t]
2097         ["Mark series" gnus-uu-mark-series t]
2098         ["Mark region" gnus-uu-mark-region t]
2099         ["Unmark region" gnus-uu-unmark-region t]
2100         ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2101         ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2102         ["Mark all" gnus-uu-mark-all t]
2103         ["Mark buffer" gnus-uu-mark-buffer t]
2104         ["Mark sparse" gnus-uu-mark-sparse t]
2105         ["Mark thread" gnus-uu-mark-thread t]
2106         ["Unmark thread" gnus-uu-unmark-thread t]
2107         ("Process Mark Sets"
2108          ["Kill" gnus-summary-kill-process-mark t]
2109          ["Yank" gnus-summary-yank-process-mark
2110           gnus-newsgroup-process-stack]
2111          ["Save" gnus-summary-save-process-mark t]))
2112        ("Scroll article"
2113         ["Page forward" gnus-summary-next-page
2114          ,@(if (featurep 'xemacs) '(t)
2115              '(:help "Show next page of article"))]
2116         ["Page backward" gnus-summary-prev-page
2117          ,@(if (featurep 'xemacs) '(t)
2118              '(:help "Show previous page of article"))]
2119         ["Line forward" gnus-summary-scroll-up t])
2120        ("Move"
2121         ["Next unread article" gnus-summary-next-unread-article t]
2122         ["Previous unread article" gnus-summary-prev-unread-article t]
2123         ["Next article" gnus-summary-next-article t]
2124         ["Previous article" gnus-summary-prev-article t]
2125         ["Next unread subject" gnus-summary-next-unread-subject t]
2126         ["Previous unread subject" gnus-summary-prev-unread-subject t]
2127         ["Next article same subject" gnus-summary-next-same-subject t]
2128         ["Previous article same subject" gnus-summary-prev-same-subject t]
2129         ["First unread article" gnus-summary-first-unread-article t]
2130         ["Best unread article" gnus-summary-best-unread-article t]
2131         ["Go to subject number..." gnus-summary-goto-subject t]
2132         ["Go to article number..." gnus-summary-goto-article t]
2133         ["Go to the last article" gnus-summary-goto-last-article t]
2134         ["Pop article off history" gnus-summary-pop-article t])
2135        ("Sort"
2136         ["Sort by number" gnus-summary-sort-by-number t]
2137         ["Sort by author" gnus-summary-sort-by-author t]
2138         ["Sort by subject" gnus-summary-sort-by-subject t]
2139         ["Sort by date" gnus-summary-sort-by-date t]
2140         ["Sort by score" gnus-summary-sort-by-score t]
2141         ["Sort by lines" gnus-summary-sort-by-lines t]
2142         ["Sort by characters" gnus-summary-sort-by-chars t]
2143         ["Original sort" gnus-summary-sort-by-original t])
2144        ("Help"
2145         ["Fetch group FAQ" gnus-summary-fetch-faq t]
2146         ["Describe group" gnus-summary-describe-group t]
2147         ["Read manual" gnus-info-find-node t])
2148        ("Modes"
2149         ["Pick and read" gnus-pick-mode t]
2150         ["Binary" gnus-binary-mode t])
2151        ("Regeneration"
2152         ["Regenerate" gnus-summary-prepare t]
2153         ["Insert cached articles" gnus-summary-insert-cached-articles t]
2154         ["Toggle threading" gnus-summary-toggle-threads t])
2155        ["See old articles" gnus-summary-insert-old-articles t]
2156        ["See new articles" gnus-summary-insert-new-articles t]
2157        ["Filter articles..." gnus-summary-execute-command t]
2158        ["Run command on subjects..." gnus-summary-universal-argument t]
2159        ["Search articles forward..." gnus-summary-search-article-forward t]
2160        ["Search articles backward..." gnus-summary-search-article-backward t]
2161        ["Toggle line truncation" gnus-summary-toggle-truncation t]
2162        ["Expand window" gnus-summary-expand-window t]
2163        ["Expire expirable articles" gnus-summary-expire-articles
2164         (gnus-check-backend-function
2165          'request-expire-articles gnus-newsgroup-name)]
2166        ["Edit local kill file" gnus-summary-edit-local-kill t]
2167        ["Edit main kill file" gnus-summary-edit-global-kill t]
2168        ["Edit group parameters" gnus-summary-edit-parameters t]
2169        ["Customize group parameters" gnus-summary-customize-parameters t]
2170        ["Send a bug report" gnus-bug t]
2171        ("Exit"
2172         ["Catchup and exit" gnus-summary-catchup-and-exit
2173          ,@(if (featurep 'xemacs) '(t)
2174              '(:help "Mark unread articles in this group as read, then exit"))]
2175         ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2176         ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2177         ["Exit group" gnus-summary-exit
2178          ,@(if (featurep 'xemacs) '(t)
2179              '(:help "Exit current group, return to group selection mode"))]
2180         ["Exit group without updating" gnus-summary-exit-no-update t]
2181         ["Exit and goto next group" gnus-summary-next-group t]
2182         ["Exit and goto prev group" gnus-summary-prev-group t]
2183         ["Reselect group" gnus-summary-reselect-current-group t]
2184         ["Rescan group" gnus-summary-rescan-group t]
2185         ["Update dribble" gnus-summary-save-newsrc t])))
2186
2187     (gnus-run-hooks 'gnus-summary-menu-hook)))
2188
2189 (defvar gnus-summary-tool-bar-map nil)
2190
2191 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2192 (defun gnus-summary-make-tool-bar ()
2193   (if (and (fboundp 'tool-bar-add-item-from-menu)
2194            (default-value 'tool-bar-mode)
2195            (not gnus-summary-tool-bar-map))
2196       (setq gnus-summary-tool-bar-map
2197             (let ((tool-bar-map (make-sparse-keymap))
2198                   (load-path (mm-image-load-path)))
2199               (tool-bar-add-item-from-menu
2200                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2201               (tool-bar-add-item-from-menu
2202                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2203               (tool-bar-add-item-from-menu
2204                'gnus-summary-post-news "post" gnus-summary-mode-map)
2205               (tool-bar-add-item-from-menu
2206                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2207               (tool-bar-add-item-from-menu
2208                'gnus-summary-followup "followup" gnus-summary-mode-map)
2209               (tool-bar-add-item-from-menu
2210                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2211               (tool-bar-add-item-from-menu
2212                'gnus-summary-reply "reply" gnus-summary-mode-map)
2213               (tool-bar-add-item-from-menu
2214                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2215               (tool-bar-add-item-from-menu
2216                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2217               (tool-bar-add-item-from-menu
2218                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2219               (tool-bar-add-item-from-menu
2220                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2221               (tool-bar-add-item-from-menu
2222                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2223               (tool-bar-add-item-from-menu
2224                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2225               (tool-bar-add-item-from-menu
2226                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2227               (tool-bar-add-item-from-menu
2228                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2229               tool-bar-map)))
2230   (if gnus-summary-tool-bar-map
2231       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2232
2233 (defun gnus-score-set-default (var value)
2234   "A version of set that updates the GNU Emacs menu-bar."
2235   (set var value)
2236   ;; It is the message that forces the active status to be updated.
2237   (message ""))
2238
2239 (defun gnus-make-score-map (type)
2240   "Make a summary score map of type TYPE."
2241   (if t
2242       nil
2243     (let ((headers '(("author" "from" string)
2244                      ("subject" "subject" string)
2245                      ("article body" "body" string)
2246                      ("article head" "head" string)
2247                      ("xref" "xref" string)
2248                      ("extra header" "extra" string)
2249                      ("lines" "lines" number)
2250                      ("followups to author" "followup" string)))
2251           (types '((number ("less than" <)
2252                            ("greater than" >)
2253                            ("equal" =))
2254                    (string ("substring" s)
2255                            ("exact string" e)
2256                            ("fuzzy string" f)
2257                            ("regexp" r))))
2258           (perms '(("temporary" (current-time-string))
2259                    ("permanent" nil)
2260                    ("immediate" now)))
2261           header)
2262       (list
2263        (apply
2264         'nconc
2265         (list
2266          (if (eq type 'lower)
2267              "Lower score"
2268            "Increase score"))
2269         (let (outh)
2270           (while headers
2271             (setq header (car headers))
2272             (setq outh
2273                   (cons
2274                    (apply
2275                     'nconc
2276                     (list (car header))
2277                     (let ((ts (cdr (assoc (nth 2 header) types)))
2278                           outt)
2279                       (while ts
2280                         (setq outt
2281                               (cons
2282                                (apply
2283                                 'nconc
2284                                 (list (caar ts))
2285                                 (let ((ps perms)
2286                                       outp)
2287                                   (while ps
2288                                     (setq outp
2289                                           (cons
2290                                            (vector
2291                                             (caar ps)
2292                                             (list
2293                                              'gnus-summary-score-entry
2294                                              (nth 1 header)
2295                                              (if (or (string= (nth 1 header)
2296                                                               "head")
2297                                                      (string= (nth 1 header)
2298                                                               "body"))
2299                                                  ""
2300                                                (list 'gnus-summary-header
2301                                                      (nth 1 header)))
2302                                              (list 'quote (nth 1 (car ts)))
2303                                              (list 'gnus-score-delta-default
2304                                                    nil)
2305                                              (nth 1 (car ps))
2306                                              t)
2307                                             t)
2308                                            outp))
2309                                     (setq ps (cdr ps)))
2310                                   (list (nreverse outp))))
2311                                outt))
2312                         (setq ts (cdr ts)))
2313                       (list (nreverse outt))))
2314                    outh))
2315             (setq headers (cdr headers)))
2316           (list (nreverse outh))))))))
2317
2318 \f
2319
2320 (defun gnus-summary-mode (&optional group)
2321   "Major mode for reading articles.
2322
2323 All normal editing commands are switched off.
2324 \\<gnus-summary-mode-map>
2325 Each line in this buffer represents one article.  To read an
2326 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2327 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2328 respectively.
2329
2330 You can also post articles and send mail from this buffer.  To
2331 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2332 of an article, type `\\[gnus-summary-reply]'.
2333
2334 There are approx. one gazillion commands you can execute in this
2335 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2336
2337 The following commands are available:
2338
2339 \\{gnus-summary-mode-map}"
2340   (interactive)
2341   (kill-all-local-variables)
2342   (when (gnus-visual-p 'summary-menu 'menu)
2343     (gnus-summary-make-menu-bar)
2344     (gnus-summary-make-tool-bar))
2345   (gnus-summary-make-local-variables)
2346   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2347     (gnus-summary-make-local-variables))
2348   (gnus-make-thread-indent-array)
2349   (gnus-simplify-mode-line)
2350   (setq major-mode 'gnus-summary-mode)
2351   (setq mode-name "Summary")
2352   (make-local-variable 'minor-mode-alist)
2353   (use-local-map gnus-summary-mode-map)
2354   (buffer-disable-undo)
2355   (setq buffer-read-only t)             ;Disable modification
2356   (setq truncate-lines t)
2357   (setq selective-display t)
2358   (setq selective-display-ellipses t)   ;Display `...'
2359   (gnus-summary-set-display-table)
2360   (gnus-set-default-directory)
2361   (setq gnus-newsgroup-name group)
2362   (unless (gnus-news-group-p group)
2363     (setq gnus-newsgroup-incorporated
2364           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2365   (make-local-variable 'gnus-summary-line-format)
2366   (make-local-variable 'gnus-summary-line-format-spec)
2367   (make-local-variable 'gnus-summary-dummy-line-format)
2368   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2369   (make-local-variable 'gnus-summary-mark-positions)
2370   (make-local-hook 'pre-command-hook)
2371   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2372   (gnus-run-hooks 'gnus-summary-mode-hook)
2373   (turn-on-gnus-mailing-list-mode)
2374   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2375   (gnus-update-summary-mark-positions))
2376
2377 (defun gnus-summary-make-local-variables ()
2378   "Make all the local summary buffer variables."
2379   (let (global)
2380     (dolist (local gnus-summary-local-variables)
2381       (if (consp local)
2382           (progn
2383             (if (eq (cdr local) 'global)
2384                 ;; Copy the global value of the variable.
2385                 (setq global (symbol-value (car local)))
2386               ;; Use the value from the list.
2387               (setq global (eval (cdr local))))
2388             (set (make-local-variable (car local)) global))
2389         ;; Simple nil-valued local variable.
2390         (set (make-local-variable local) nil)))))
2391
2392 (defun gnus-summary-clear-local-variables ()
2393   (let ((locals gnus-summary-local-variables))
2394     (while locals
2395       (if (consp (car locals))
2396           (and (vectorp (caar locals))
2397                (set (caar locals) nil))
2398         (and (vectorp (car locals))
2399              (set (car locals) nil)))
2400       (setq locals (cdr locals)))))
2401
2402 ;; Summary data functions.
2403
2404 (defmacro gnus-data-number (data)
2405   `(car ,data))
2406
2407 (defmacro gnus-data-set-number (data number)
2408   `(setcar ,data ,number))
2409
2410 (defmacro gnus-data-mark (data)
2411   `(nth 1 ,data))
2412
2413 (defmacro gnus-data-set-mark (data mark)
2414   `(setcar (nthcdr 1 ,data) ,mark))
2415
2416 (defmacro gnus-data-pos (data)
2417   `(nth 2 ,data))
2418
2419 (defmacro gnus-data-set-pos (data pos)
2420   `(setcar (nthcdr 2 ,data) ,pos))
2421
2422 (defmacro gnus-data-header (data)
2423   `(nth 3 ,data))
2424
2425 (defmacro gnus-data-set-header (data header)
2426   `(setcar (nthcdr 3 ,data) ,header))
2427
2428 (defmacro gnus-data-level (data)
2429   `(nth 4 ,data))
2430
2431 (defmacro gnus-data-unread-p (data)
2432   `(= (nth 1 ,data) gnus-unread-mark))
2433
2434 (defmacro gnus-data-read-p (data)
2435   `(/= (nth 1 ,data) gnus-unread-mark))
2436
2437 (defmacro gnus-data-pseudo-p (data)
2438   `(consp (nth 3 ,data)))
2439
2440 (defmacro gnus-data-find (number)
2441   `(assq ,number gnus-newsgroup-data))
2442
2443 (defmacro gnus-data-find-list (number &optional data)
2444   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2445      (memq (assq ,number bdata)
2446            bdata)))
2447
2448 (defmacro gnus-data-make (number mark pos header level)
2449   `(list ,number ,mark ,pos ,header ,level))
2450
2451 (defun gnus-data-enter (after-article number mark pos header level offset)
2452   (let ((data (gnus-data-find-list after-article)))
2453     (unless data
2454       (error "No such article: %d" after-article))
2455     (setcdr data (cons (gnus-data-make number mark pos header level)
2456                        (cdr data)))
2457     (setq gnus-newsgroup-data-reverse nil)
2458     (gnus-data-update-list (cddr data) offset)))
2459
2460 (defun gnus-data-enter-list (after-article list &optional offset)
2461   (when list
2462     (let ((data (and after-article (gnus-data-find-list after-article)))
2463           (ilist list))
2464       (if (not (or data
2465                    after-article))
2466           (let ((odata gnus-newsgroup-data))
2467             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2468             (when offset
2469               (gnus-data-update-list odata offset)))
2470         ;; Find the last element in the list to be spliced into the main
2471         ;; list.
2472         (while (cdr list)
2473           (setq list (cdr list)))
2474         (if (not data)
2475             (progn
2476               (setcdr list gnus-newsgroup-data)
2477               (setq gnus-newsgroup-data ilist)
2478               (when offset
2479                 (gnus-data-update-list (cdr list) offset)))
2480           (setcdr list (cdr data))
2481           (setcdr data ilist)
2482           (when offset
2483             (gnus-data-update-list (cdr list) offset))))
2484       (setq gnus-newsgroup-data-reverse nil))))
2485
2486 (defun gnus-data-remove (article &optional offset)
2487   (let ((data gnus-newsgroup-data))
2488     (if (= (gnus-data-number (car data)) article)
2489         (progn
2490           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2491                 gnus-newsgroup-data-reverse nil)
2492           (when offset
2493             (gnus-data-update-list gnus-newsgroup-data offset)))
2494       (while (cdr data)
2495         (when (= (gnus-data-number (cadr data)) article)
2496           (setcdr data (cddr data))
2497           (when offset
2498             (gnus-data-update-list (cdr data) offset))
2499           (setq data nil
2500                 gnus-newsgroup-data-reverse nil))
2501         (setq data (cdr data))))))
2502
2503 (defmacro gnus-data-list (backward)
2504   `(if ,backward
2505        (or gnus-newsgroup-data-reverse
2506            (setq gnus-newsgroup-data-reverse
2507                  (reverse gnus-newsgroup-data)))
2508      gnus-newsgroup-data))
2509
2510 (defun gnus-data-update-list (data offset)
2511   "Add OFFSET to the POS of all data entries in DATA."
2512   (setq gnus-newsgroup-data-reverse nil)
2513   (while data
2514     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2515     (setq data (cdr data))))
2516
2517 (defun gnus-summary-article-pseudo-p (article)
2518   "Say whether this article is a pseudo article or not."
2519   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2520
2521 (defmacro gnus-summary-article-sparse-p (article)
2522   "Say whether this article is a sparse article or not."
2523   `(memq ,article gnus-newsgroup-sparse))
2524
2525 (defmacro gnus-summary-article-ancient-p (article)
2526   "Say whether this article is a sparse article or not."
2527   `(memq ,article gnus-newsgroup-ancient))
2528
2529 (defun gnus-article-parent-p (number)
2530   "Say whether this article is a parent or not."
2531   (let ((data (gnus-data-find-list number)))
2532     (and (cdr data)                     ; There has to be an article after...
2533          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2534             (gnus-data-level (nth 1 data))))))
2535
2536 (defun gnus-article-children (number)
2537   "Return a list of all children to NUMBER."
2538   (let* ((data (gnus-data-find-list number))
2539          (level (gnus-data-level (car data)))
2540          children)
2541     (setq data (cdr data))
2542     (while (and data
2543                 (= (gnus-data-level (car data)) (1+ level)))
2544       (push (gnus-data-number (car data)) children)
2545       (setq data (cdr data)))
2546     children))
2547
2548 (defmacro gnus-summary-skip-intangible ()
2549   "If the current article is intangible, then jump to a different article."
2550   '(let ((to (get-text-property (point) 'gnus-intangible)))
2551      (and to (gnus-summary-goto-subject to))))
2552
2553 (defmacro gnus-summary-article-intangible-p ()
2554   "Say whether this article is intangible or not."
2555   '(get-text-property (point) 'gnus-intangible))
2556
2557 (defun gnus-article-read-p (article)
2558   "Say whether ARTICLE is read or not."
2559   (not (or (memq article gnus-newsgroup-marked)
2560            (memq article gnus-newsgroup-unreads)
2561            (memq article gnus-newsgroup-unselected)
2562            (memq article gnus-newsgroup-dormant))))
2563
2564 ;; Some summary mode macros.
2565
2566 (defmacro gnus-summary-article-number ()
2567   "The article number of the article on the current line.
2568 If there isn's an article number here, then we return the current
2569 article number."
2570   '(progn
2571      (gnus-summary-skip-intangible)
2572      (or (get-text-property (point) 'gnus-number)
2573          (gnus-summary-last-subject))))
2574
2575 (defmacro gnus-summary-article-header (&optional number)
2576   "Return the header of article NUMBER."
2577   `(gnus-data-header (gnus-data-find
2578                       ,(or number '(gnus-summary-article-number)))))
2579
2580 (defmacro gnus-summary-thread-level (&optional number)
2581   "Return the level of thread that starts with article NUMBER."
2582   `(if (and (eq gnus-summary-make-false-root 'dummy)
2583             (get-text-property (point) 'gnus-intangible))
2584        0
2585      (gnus-data-level (gnus-data-find
2586                        ,(or number '(gnus-summary-article-number))))))
2587
2588 (defmacro gnus-summary-article-mark (&optional number)
2589   "Return the mark of article NUMBER."
2590   `(gnus-data-mark (gnus-data-find
2591                     ,(or number '(gnus-summary-article-number)))))
2592
2593 (defmacro gnus-summary-article-pos (&optional number)
2594   "Return the position of the line of article NUMBER."
2595   `(gnus-data-pos (gnus-data-find
2596                    ,(or number '(gnus-summary-article-number)))))
2597
2598 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2599 (defmacro gnus-summary-article-subject (&optional number)
2600   "Return current subject string or nil if nothing."
2601   `(let ((headers
2602           ,(if number
2603                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2604              '(gnus-data-header (assq (gnus-summary-article-number)
2605                                       gnus-newsgroup-data)))))
2606      (and headers
2607           (vectorp headers)
2608           (mail-header-subject headers))))
2609
2610 (defmacro gnus-summary-article-score (&optional number)
2611   "Return current article score."
2612   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2613                   gnus-newsgroup-scored))
2614        gnus-summary-default-score 0))
2615
2616 (defun gnus-summary-article-children (&optional number)
2617   "Return a list of article numbers that are children of article NUMBER."
2618   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2619          (level (gnus-data-level (car data)))
2620          l children)
2621     (while (and (setq data (cdr data))
2622                 (> (setq l (gnus-data-level (car data))) level))
2623       (and (= (1+ level) l)
2624            (push (gnus-data-number (car data))
2625                  children)))
2626     (nreverse children)))
2627
2628 (defun gnus-summary-article-parent (&optional number)
2629   "Return the article number of the parent of article NUMBER."
2630   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2631                                     (gnus-data-list t)))
2632          (level (gnus-data-level (car data))))
2633     (if (zerop level)
2634         ()                              ; This is a root.
2635       ;; We search until we find an article with a level less than
2636       ;; this one.  That function has to be the parent.
2637       (while (and (setq data (cdr data))
2638                   (not (< (gnus-data-level (car data)) level))))
2639       (and data (gnus-data-number (car data))))))
2640
2641 (defun gnus-unread-mark-p (mark)
2642   "Say whether MARK is the unread mark."
2643   (= mark gnus-unread-mark))
2644
2645 (defun gnus-read-mark-p (mark)
2646   "Say whether MARK is one of the marks that mark as read.
2647 This is all marks except unread, ticked, dormant, and expirable."
2648   (not (or (= mark gnus-unread-mark)
2649            (= mark gnus-ticked-mark)
2650            (= mark gnus-dormant-mark)
2651            (= mark gnus-expirable-mark))))
2652
2653 (defmacro gnus-article-mark (number)
2654   "Return the MARK of article NUMBER.
2655 This macro should only be used when computing the mark the \"first\"
2656 time; i.e., when generating the summary lines.  After that,
2657 `gnus-summary-article-mark' should be used to examine the
2658 marks of articles."
2659   `(cond
2660     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2661     ((memq ,number gnus-newsgroup-undownloaded) gnus-undownloaded-mark)
2662     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2663     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2664     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2665     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
2666     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
2667     (t (or (cdr (assq ,number gnus-newsgroup-reads))
2668            gnus-ancient-mark))))
2669
2670 ;; Saving hidden threads.
2671
2672 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
2673 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
2674
2675 (defmacro gnus-save-hidden-threads (&rest forms)
2676   "Save hidden threads, eval FORMS, and restore the hidden threads."
2677   (let ((config (make-symbol "config")))
2678     `(let ((,config (gnus-hidden-threads-configuration)))
2679        (unwind-protect
2680            (save-excursion
2681              ,@forms)
2682          (gnus-restore-hidden-threads-configuration ,config)))))
2683
2684 (defun gnus-data-compute-positions ()
2685   "Compute the positions of all articles."
2686   (setq gnus-newsgroup-data-reverse nil)
2687   (let ((data gnus-newsgroup-data))
2688     (save-excursion
2689       (gnus-save-hidden-threads
2690         (gnus-summary-show-all-threads)
2691         (goto-char (point-min))
2692         (while data
2693           (while (get-text-property (point) 'gnus-intangible)
2694             (forward-line 1))
2695           (gnus-data-set-pos (car data) (+ (point) 3))
2696           (setq data (cdr data))
2697           (forward-line 1))))))
2698
2699 (defun gnus-hidden-threads-configuration ()
2700   "Return the current hidden threads configuration."
2701   (save-excursion
2702     (let (config)
2703       (goto-char (point-min))
2704       (while (search-forward "\r" nil t)
2705         (push (1- (point)) config))
2706       config)))
2707
2708 (defun gnus-restore-hidden-threads-configuration (config)
2709   "Restore hidden threads configuration from CONFIG."
2710   (save-excursion
2711     (let (point buffer-read-only)
2712       (while (setq point (pop config))
2713         (when (and (< point (point-max))
2714                    (goto-char point)
2715                    (eq (char-after) ?\n))
2716           (subst-char-in-region point (1+ point) ?\n ?\r))))))
2717
2718 ;; Various summary mode internalish functions.
2719
2720 (defun gnus-mouse-pick-article (e)
2721   (interactive "e")
2722   (mouse-set-point e)
2723   (gnus-summary-next-page nil t))
2724
2725 (defun gnus-summary-set-display-table ()
2726   "Change the display table.
2727 Odd characters have a tendency to mess
2728 up nicely formatted displays - we make all possible glyphs
2729 display only a single character."
2730
2731   ;; We start from the standard display table, if any.
2732   (let ((table (or (copy-sequence standard-display-table)
2733                    (make-display-table)))
2734         (i 32))
2735     ;; Nix out all the control chars...
2736     (while (>= (setq i (1- i)) 0)
2737       (aset table i [??]))
2738     ;; ... but not newline and cr, of course.  (cr is necessary for the
2739     ;; selective display).
2740     (aset table ?\n nil)
2741     (aset table ?\r nil)
2742     ;; We keep TAB as well.
2743     (aset table ?\t nil)
2744     ;; We nix out any glyphs over 126 that are not set already.
2745     (let ((i 256))
2746       (while (>= (setq i (1- i)) 127)
2747         ;; Only modify if the entry is nil.
2748         (unless (aref table i)
2749           (aset table i [??]))))
2750     (setq buffer-display-table table)))
2751
2752 (defun gnus-summary-set-article-display-arrow (pos)
2753   "Update the overlay arrow to point to line at position POS."
2754   (when (and gnus-summary-display-arrow
2755              (boundp 'overlay-arrow-position)
2756              (boundp 'overlay-arrow-string))
2757     (save-excursion
2758       (goto-char pos)
2759       (beginning-of-line)
2760       (unless overlay-arrow-position
2761         (setq overlay-arrow-position (make-marker)))
2762       (setq overlay-arrow-string "=>"
2763             overlay-arrow-position (set-marker overlay-arrow-position
2764                                                (point)
2765                                                (current-buffer))))))
2766
2767 (defun gnus-summary-buffer-name (group)
2768   "Return the summary buffer name of GROUP."
2769   (concat "*Summary " group "*"))
2770
2771 (defun gnus-summary-setup-buffer (group)
2772   "Initialize summary buffer."
2773   (let ((buffer (gnus-summary-buffer-name group)))
2774     (if (get-buffer buffer)
2775         (progn
2776           (set-buffer buffer)
2777           (setq gnus-summary-buffer (current-buffer))
2778           (not gnus-newsgroup-prepared))
2779       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
2780       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
2781       (gnus-summary-mode group)
2782       (when gnus-carpal
2783         (gnus-carpal-setup-buffer 'summary))
2784       (unless gnus-single-article-buffer
2785         (make-local-variable 'gnus-article-buffer)
2786         (make-local-variable 'gnus-article-current)
2787         (make-local-variable 'gnus-original-article-buffer))
2788       (setq gnus-newsgroup-name group)
2789       ;; Set any local variables in the group parameters.
2790       (gnus-summary-set-local-parameters gnus-newsgroup-name)
2791       t)))
2792
2793 (defun gnus-set-global-variables ()
2794   "Set the global equivalents of the buffer-local variables.
2795 They are set to the latest values they had.  These reflect the summary
2796 buffer that was in action when the last article was fetched."
2797   (when (eq major-mode 'gnus-summary-mode)
2798     (setq gnus-summary-buffer (current-buffer))
2799     (let ((name gnus-newsgroup-name)
2800           (marked gnus-newsgroup-marked)
2801           (unread gnus-newsgroup-unreads)
2802           (headers gnus-current-headers)
2803           (data gnus-newsgroup-data)
2804           (summary gnus-summary-buffer)
2805           (article-buffer gnus-article-buffer)
2806           (original gnus-original-article-buffer)
2807           (gac gnus-article-current)
2808           (reffed gnus-reffed-article-number)
2809           (score-file gnus-current-score-file)
2810           (default-charset gnus-newsgroup-charset)
2811           vlist)
2812       (let ((locals gnus-newsgroup-variables))
2813         (while locals
2814           (if (consp (car locals))
2815               (push (eval (caar locals)) vlist)
2816             (push (eval (car locals)) vlist))
2817           (setq locals (cdr locals)))
2818         (setq vlist (nreverse vlist)))
2819       (save-excursion
2820         (set-buffer gnus-group-buffer)
2821         (setq gnus-newsgroup-name name
2822               gnus-newsgroup-marked marked
2823               gnus-newsgroup-unreads unread
2824               gnus-current-headers headers
2825               gnus-newsgroup-data data
2826               gnus-article-current gac
2827               gnus-summary-buffer summary
2828               gnus-article-buffer article-buffer
2829               gnus-original-article-buffer original
2830               gnus-reffed-article-number reffed
2831               gnus-current-score-file score-file
2832               gnus-newsgroup-charset default-charset)
2833         (let ((locals gnus-newsgroup-variables))
2834           (while locals
2835             (if (consp (car locals))
2836                 (set (caar locals) (pop vlist))
2837               (set (car locals) (pop vlist)))
2838             (setq locals (cdr locals))))
2839         ;; The article buffer also has local variables.
2840         (when (gnus-buffer-live-p gnus-article-buffer)
2841           (set-buffer gnus-article-buffer)
2842           (setq gnus-summary-buffer summary))))))
2843
2844 (defun gnus-summary-article-unread-p (article)
2845   "Say whether ARTICLE is unread or not."
2846   (memq article gnus-newsgroup-unreads))
2847
2848 (defun gnus-summary-first-article-p (&optional article)
2849   "Return whether ARTICLE is the first article in the buffer."
2850   (if (not (setq article (or article (gnus-summary-article-number))))
2851       nil
2852     (eq article (caar gnus-newsgroup-data))))
2853
2854 (defun gnus-summary-last-article-p (&optional article)
2855   "Return whether ARTICLE is the last article in the buffer."
2856   (if (not (setq article (or article (gnus-summary-article-number))))
2857       ;; All non-existent numbers are the last article.  :-)
2858       t
2859     (not (cdr (gnus-data-find-list article)))))
2860
2861 (defun gnus-make-thread-indent-array ()
2862   (let ((n 200))
2863     (unless (and gnus-thread-indent-array
2864                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
2865       (setq gnus-thread-indent-array (make-vector 201 "")
2866             gnus-thread-indent-array-level gnus-thread-indent-level)
2867       (while (>= n 0)
2868         (aset gnus-thread-indent-array n
2869               (make-string (* n gnus-thread-indent-level) ? ))
2870         (setq n (1- n))))))
2871
2872 (defun gnus-update-summary-mark-positions ()
2873   "Compute where the summary marks are to go."
2874   (save-excursion
2875     (when (gnus-buffer-exists-p gnus-summary-buffer)
2876       (set-buffer gnus-summary-buffer))
2877     (let ((gnus-replied-mark 129)
2878           (gnus-score-below-mark 130)
2879           (gnus-score-over-mark 130)
2880           (gnus-download-mark 131)
2881           (spec gnus-summary-line-format-spec)
2882           gnus-visual pos)
2883       (save-excursion
2884         (gnus-set-work-buffer)
2885         (let ((gnus-summary-line-format-spec spec)
2886               (gnus-newsgroup-downloadable '((0 . t))))
2887           (gnus-summary-insert-line
2888            (make-full-mail-header 0 "" "nobody"
2889                                   "05 Apr 2001 23:33:09 +0400"
2890                                   "" "" 0 0 "" nil)
2891            0 nil 128 t nil "" nil 1)
2892           (goto-char (point-min))
2893           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
2894                                              (- (point) 2)))))
2895           (goto-char (point-min))
2896           (push (cons 'replied (and (search-forward "\201" nil t)
2897                                     (- (point) 2)))
2898                 pos)
2899           (goto-char (point-min))
2900           (push (cons 'score (and (search-forward "\202" nil t) (- (point) 2)))
2901                 pos)
2902           (goto-char (point-min))
2903           (push (cons 'download
2904                       (and (search-forward "\203" nil t) (- (point) 2)))
2905                 pos)))
2906       (setq gnus-summary-mark-positions pos))))
2907
2908 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
2909   "Insert a dummy root in the summary buffer."
2910   (beginning-of-line)
2911   (gnus-add-text-properties
2912    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
2913    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
2914
2915 (defun gnus-summary-extract-address-component (from)
2916   (or (car (funcall gnus-extract-address-components from))
2917       from))
2918
2919 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
2920   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
2921                                 default-mime-charset)))
2922     ;; Is it really necessary to do this next part for each summary line?
2923     ;; Luckily, doesn't seem to slow things down much.
2924     (or
2925      (and gnus-ignored-from-addresses
2926           (string-match gnus-ignored-from-addresses gnus-tmp-from)
2927           (let ((extra-headers (mail-header-extra header))
2928                 to
2929                 newsgroups)
2930             (cond
2931              ((setq to (cdr (assq 'To extra-headers)))
2932               (concat "-> "
2933                       (gnus-summary-extract-address-component
2934                        (funcall gnus-decode-encoded-word-function to))))
2935              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
2936               (concat "=> " newsgroups)))))
2937      (gnus-summary-extract-address-component gnus-tmp-from))))
2938
2939 (defun gnus-summary-insert-line (gnus-tmp-header
2940                                  gnus-tmp-level gnus-tmp-current
2941                                  gnus-tmp-unread gnus-tmp-replied
2942                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
2943                                  &optional gnus-tmp-dummy gnus-tmp-score
2944                                  gnus-tmp-process)
2945   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
2946          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
2947          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
2948          (gnus-tmp-score-char
2949           (if (or (null gnus-summary-default-score)
2950                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
2951                       gnus-summary-zcore-fuzz))
2952               ?\ ;;;Whitespace
2953             (if (< gnus-tmp-score gnus-summary-default-score)
2954                 gnus-score-below-mark gnus-score-over-mark)))
2955          (gnus-tmp-number (mail-header-number gnus-tmp-header))
2956          (gnus-tmp-replied
2957           (cond (gnus-tmp-process gnus-process-mark)
2958                 ((memq gnus-tmp-current gnus-newsgroup-cached)
2959                  gnus-cached-mark)
2960                 (gnus-tmp-replied gnus-replied-mark)
2961                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
2962                  gnus-forwarded-mark)
2963                 ((memq gnus-tmp-current gnus-newsgroup-saved)
2964                  gnus-saved-mark)
2965                 ((memq gnus-tmp-number gnus-newsgroup-recent)
2966                  gnus-recent-mark)
2967                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
2968                  gnus-unseen-mark)
2969                 (t gnus-no-mark)))
2970          (gnus-tmp-from (mail-header-from gnus-tmp-header))
2971          (gnus-tmp-name
2972           (cond
2973            ((string-match "<[^>]+> *$" gnus-tmp-from)
2974             (let ((beg (match-beginning 0)))
2975               (or (and (string-match "^\".+\"" gnus-tmp-from)
2976                        (substring gnus-tmp-from 1 (1- (match-end 0))))
2977                   (substring gnus-tmp-from 0 beg))))
2978            ((string-match "(.+)" gnus-tmp-from)
2979             (substring gnus-tmp-from
2980                        (1+ (match-beginning 0)) (1- (match-end 0))))
2981            (t gnus-tmp-from)))
2982          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
2983          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
2984          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
2985          (buffer-read-only nil))
2986     (when (string= gnus-tmp-name "")
2987       (setq gnus-tmp-name gnus-tmp-from))
2988     (unless (numberp gnus-tmp-lines)
2989       (setq gnus-tmp-lines -1))
2990     (if (= gnus-tmp-lines -1)
2991         (setq gnus-tmp-lines "?")
2992       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
2993     (gnus-put-text-property-excluding-characters-with-faces
2994      (point)
2995      (progn (eval gnus-summary-line-format-spec) (point))
2996      'gnus-number gnus-tmp-number)
2997     (when (gnus-visual-p 'summary-highlight 'highlight)
2998       (forward-line -1)
2999       (gnus-run-hooks 'gnus-summary-update-hook)
3000       (forward-line 1))))
3001
3002 (defun gnus-summary-update-line (&optional dont-update)
3003   "Update summary line after change."
3004   (when (and gnus-summary-default-score
3005              (not gnus-summary-inhibit-highlight))
3006     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3007            (article (gnus-summary-article-number))
3008            (score (gnus-summary-article-score article)))
3009       (unless dont-update
3010         (if (and gnus-summary-mark-below
3011                  (< (gnus-summary-article-score)
3012                     gnus-summary-mark-below))
3013             ;; This article has a low score, so we mark it as read.
3014             (when (memq article gnus-newsgroup-unreads)
3015               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3016           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3017             ;; This article was previously marked as read on account
3018             ;; of a low score, but now it has risen, so we mark it as
3019             ;; unread.
3020             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3021         (gnus-summary-update-mark
3022          (if (or (null gnus-summary-default-score)
3023                  (<= (abs (- score gnus-summary-default-score))
3024                      gnus-summary-zcore-fuzz))
3025              ?\ ;;;Whitespace
3026            (if (< score gnus-summary-default-score)
3027                gnus-score-below-mark gnus-score-over-mark))
3028          'score))
3029       ;; Do visual highlighting.
3030       (when (gnus-visual-p 'summary-highlight 'highlight)
3031         (gnus-run-hooks 'gnus-summary-update-hook)))))
3032
3033 (defvar gnus-tmp-new-adopts nil)
3034
3035 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3036   "Return the number of articles in THREAD.
3037 This may be 0 in some cases -- if none of the articles in
3038 the thread are to be displayed."
3039   (let* ((number
3040           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3041           (cond
3042            ((not (listp thread))
3043             1)
3044            ((and (consp thread) (cdr thread))
3045             (apply
3046              '+ 1 (mapcar
3047                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3048            ((null thread)
3049             1)
3050            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3051             1)
3052            (t 0))))
3053     (when (and level (zerop level) gnus-tmp-new-adopts)
3054       (incf number
3055             (apply '+ (mapcar
3056                        'gnus-summary-number-of-articles-in-thread
3057                        gnus-tmp-new-adopts))))
3058     (if char
3059         (if (> number 1) gnus-not-empty-thread-mark
3060           gnus-empty-thread-mark)
3061       number)))
3062
3063 (defun gnus-summary-set-local-parameters (group)
3064   "Go through the local params of GROUP and set all variable specs in that list."
3065   (let ((params (gnus-group-find-parameter group))
3066         (vars '(quit-config))           ; Ignore quit-config.
3067         elem)
3068     (while params
3069       (setq elem (car params)
3070             params (cdr params))
3071       (and (consp elem)                 ; Has to be a cons.
3072            (consp (cdr elem))           ; The cdr has to be a list.
3073            (symbolp (car elem))         ; Has to be a symbol in there.
3074            (not (memq (car elem) vars))
3075            (ignore-errors               ; So we set it.
3076              (push (car elem) vars)
3077              (make-local-variable (car elem))
3078              (set (car elem) (eval (nth 1 elem))))))))
3079
3080 (defun gnus-summary-read-group (group &optional show-all no-article
3081                                       kill-buffer no-display backward
3082                                       select-articles)
3083   "Start reading news in newsgroup GROUP.
3084 If SHOW-ALL is non-nil, already read articles are also listed.
3085 If NO-ARTICLE is non-nil, no article is selected initially.
3086 If NO-DISPLAY, don't generate a summary buffer."
3087   (let (result)
3088     (while (and group
3089                 (null (setq result
3090                             (let ((gnus-auto-select-next nil))
3091                               (or (gnus-summary-read-group-1
3092                                    group show-all no-article
3093                                    kill-buffer no-display
3094                                    select-articles)
3095                                   (setq show-all nil
3096                                         select-articles nil)))))
3097                 (eq gnus-auto-select-next 'quietly))
3098       (set-buffer gnus-group-buffer)
3099       ;; The entry function called above goes to the next
3100       ;; group automatically, so we go two groups back
3101       ;; if we are searching for the previous group.
3102       (when backward
3103         (gnus-group-prev-unread-group 2))
3104       (if (not (equal group (gnus-group-group-name)))
3105           (setq group (gnus-group-group-name))
3106         (setq group nil)))
3107     result))
3108
3109 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3110   "Directly jump to the other GROUP from summary buffer.
3111 If SHOW-ALL is non-nil, already read articles are also listed."
3112   (interactive
3113    (if (eq gnus-summary-buffer (current-buffer))
3114        (list (completing-read
3115               "Group: " gnus-active-hashtb nil t
3116               (when (and gnus-newsgroup-name
3117                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3118                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3119               'gnus-group-history)
3120              current-prefix-arg)
3121      (error "%s must be invoked from a gnus summary buffer." this-command)))
3122   (unless (or (zerop (length group))
3123               (and gnus-newsgroup-name
3124                    (string-equal gnus-newsgroup-name group)))
3125     (gnus-summary-exit)
3126     (gnus-summary-read-group group show-all
3127                              gnus-dont-select-after-jump-to-other-group)))
3128
3129 (defun gnus-summary-read-group-1 (group show-all no-article
3130                                         kill-buffer no-display
3131                                         &optional select-articles)
3132   ;; Killed foreign groups can't be entered.
3133   ;;  (when (and (not (gnus-group-native-p group))
3134   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3135   ;;    (error "Dead non-native groups can't be entered"))
3136   (gnus-message 5 "Retrieving newsgroup: %s..."
3137                 (gnus-group-decoded-name group))
3138   (let* ((new-group (gnus-summary-setup-buffer group))
3139          (quit-config (gnus-group-quit-config group))
3140          (did-select (and new-group (gnus-select-newsgroup
3141                                      group show-all select-articles))))
3142     (cond
3143      ;; This summary buffer exists already, so we just select it.
3144      ((not new-group)
3145       (gnus-set-global-variables)
3146       (when kill-buffer
3147         (gnus-kill-or-deaden-summary kill-buffer))
3148       (gnus-configure-windows 'summary 'force)
3149       (gnus-set-mode-line 'summary)
3150       (gnus-summary-position-point)
3151       (message "")
3152       t)
3153      ;; We couldn't select this group.
3154      ((null did-select)
3155       (when (and (eq major-mode 'gnus-summary-mode)
3156                  (not (equal (current-buffer) kill-buffer)))
3157         (kill-buffer (current-buffer))
3158         (if (not quit-config)
3159             (progn
3160               ;; Update the info -- marks might need to be removed,
3161               ;; for instance.
3162               (gnus-summary-update-info)
3163               (set-buffer gnus-group-buffer)
3164               (gnus-group-jump-to-group group)
3165               (gnus-group-next-unread-group 1))
3166           (gnus-handle-ephemeral-exit quit-config)))
3167       (let ((grpinfo (gnus-get-info group)))
3168         (if (null (gnus-info-read grpinfo))
3169             (gnus-message 3 "Group %s contains no messages"
3170                           (gnus-group-decoded-name group))
3171           (gnus-message 3 "Can't select group")))
3172       nil)
3173      ;; The user did a `C-g' while prompting for number of articles,
3174      ;; so we exit this group.
3175      ((eq did-select 'quit)
3176       (and (eq major-mode 'gnus-summary-mode)
3177            (not (equal (current-buffer) kill-buffer))
3178            (kill-buffer (current-buffer)))
3179       (when kill-buffer
3180         (gnus-kill-or-deaden-summary kill-buffer))
3181       (if (not quit-config)
3182           (progn
3183             (set-buffer gnus-group-buffer)
3184             (gnus-group-jump-to-group group)
3185             (gnus-group-next-unread-group 1)
3186             (gnus-configure-windows 'group 'force))
3187         (gnus-handle-ephemeral-exit quit-config))
3188       ;; Finally signal the quit.
3189       (signal 'quit nil))
3190      ;; The group was successfully selected.
3191      (t
3192       (gnus-set-global-variables)
3193       ;; Save the active value in effect when the group was entered.
3194       (setq gnus-newsgroup-active
3195             (gnus-copy-sequence
3196              (gnus-active gnus-newsgroup-name)))
3197       ;; You can change the summary buffer in some way with this hook.
3198       (gnus-run-hooks 'gnus-select-group-hook)
3199       (gnus-update-format-specifications
3200        nil 'summary 'summary-mode 'summary-dummy)
3201       (gnus-update-summary-mark-positions)
3202       ;; Do score processing.
3203       (when gnus-use-scoring
3204         (gnus-possibly-score-headers))
3205       ;; Check whether to fill in the gaps in the threads.
3206       (when gnus-build-sparse-threads
3207         (gnus-build-sparse-threads))
3208       ;; Find the initial limit.
3209       (if gnus-show-threads
3210           (if show-all
3211               (let ((gnus-newsgroup-dormant nil))
3212                 (gnus-summary-initial-limit show-all))
3213             (gnus-summary-initial-limit show-all))
3214         ;; When untreaded, all articles are always shown.
3215         (setq gnus-newsgroup-limit
3216               (mapcar
3217                (lambda (header) (mail-header-number header))
3218                gnus-newsgroup-headers)))
3219       ;; Generate the summary buffer.
3220       (unless no-display
3221         (gnus-summary-prepare))
3222       (when gnus-use-trees
3223         (gnus-tree-open group)
3224         (setq gnus-summary-highlight-line-function
3225               'gnus-tree-highlight-article))
3226       ;; If the summary buffer is empty, but there are some low-scored
3227       ;; articles or some excluded dormants, we include these in the
3228       ;; buffer.
3229       (when (and (zerop (buffer-size))
3230                  (not no-display))
3231         (cond (gnus-newsgroup-dormant
3232                (gnus-summary-limit-include-dormant))
3233               ((and gnus-newsgroup-scored show-all)
3234                (gnus-summary-limit-include-expunged t))))
3235       ;; Function `gnus-apply-kill-file' must be called in this hook.
3236       (gnus-run-hooks 'gnus-apply-kill-hook)
3237       (if (and (zerop (buffer-size))
3238                (not no-display))
3239           (progn
3240             ;; This newsgroup is empty.
3241             (gnus-summary-catchup-and-exit nil t)
3242             (gnus-message 6 "No unread news")
3243             (when kill-buffer
3244               (gnus-kill-or-deaden-summary kill-buffer))
3245             ;; Return nil from this function.
3246             nil)
3247         ;; Hide conversation thread subtrees.  We cannot do this in
3248         ;; gnus-summary-prepare-hook since kill processing may not
3249         ;; work with hidden articles.
3250         (and gnus-show-threads
3251              gnus-thread-hide-subtree
3252              (gnus-summary-hide-all-threads))
3253         (when kill-buffer
3254           (gnus-kill-or-deaden-summary kill-buffer))
3255         ;; Show first unread article if requested.
3256         (if (and (not no-article)
3257                  (not no-display)
3258                  gnus-newsgroup-unreads
3259                  gnus-auto-select-first)
3260             (progn
3261               (gnus-configure-windows 'summary)
3262               (cond
3263                ((eq gnus-auto-select-first 'best)
3264                 (gnus-summary-best-unread-article))
3265                ((eq gnus-auto-select-first t)
3266                 (gnus-summary-first-unread-article))
3267                ((gnus-functionp gnus-auto-select-first)
3268                 (funcall gnus-auto-select-first))))
3269           ;; Don't select any articles, just move point to the first
3270           ;; article in the group.
3271           (goto-char (point-min))
3272           (gnus-summary-position-point)
3273           (gnus-configure-windows 'summary 'force)
3274           (gnus-set-mode-line 'summary))
3275         (when (get-buffer-window gnus-group-buffer t)
3276           ;; Gotta use windows, because recenter does weird stuff if
3277           ;; the current buffer ain't the displayed window.
3278           (let ((owin (selected-window)))
3279             (select-window (get-buffer-window gnus-group-buffer t))
3280             (when (gnus-group-goto-group group)
3281               (recenter))
3282             (select-window owin)))
3283         ;; Mark this buffer as "prepared".
3284         (setq gnus-newsgroup-prepared t)
3285         (gnus-run-hooks 'gnus-summary-prepared-hook)
3286         t)))))
3287
3288 (defun gnus-summary-prepare ()
3289   "Generate the summary buffer."
3290   (interactive)
3291   (let ((buffer-read-only nil))
3292     (erase-buffer)
3293     (setq gnus-newsgroup-data nil
3294           gnus-newsgroup-data-reverse nil)
3295     (gnus-run-hooks 'gnus-summary-generate-hook)
3296     ;; Generate the buffer, either with threads or without.
3297     (when gnus-newsgroup-headers
3298       (gnus-summary-prepare-threads
3299        (if gnus-show-threads
3300            (gnus-sort-gathered-threads
3301             (funcall gnus-summary-thread-gathering-function
3302                      (gnus-sort-threads
3303                       (gnus-cut-threads (gnus-make-threads)))))
3304          ;; Unthreaded display.
3305          (gnus-sort-articles gnus-newsgroup-headers))))
3306     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3307     ;; Call hooks for modifying summary buffer.
3308     (goto-char (point-min))
3309     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3310
3311 (defsubst gnus-general-simplify-subject (subject)
3312   "Simply subject by the same rules as gnus-gather-threads-by-subject."
3313   (setq subject
3314         (cond
3315          ;; Truncate the subject.
3316          (gnus-simplify-subject-functions
3317           (gnus-map-function gnus-simplify-subject-functions subject))
3318          ((numberp gnus-summary-gather-subject-limit)
3319           (setq subject (gnus-simplify-subject-re subject))
3320           (if (> (length subject) gnus-summary-gather-subject-limit)
3321               (substring subject 0 gnus-summary-gather-subject-limit)
3322             subject))
3323          ;; Fuzzily simplify it.
3324          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3325           (gnus-simplify-subject-fuzzy subject))
3326          ;; Just remove the leading "Re:".
3327          (t
3328           (gnus-simplify-subject-re subject))))
3329
3330   (if (and gnus-summary-gather-exclude-subject
3331            (string-match gnus-summary-gather-exclude-subject subject))
3332       nil                               ; This article shouldn't be gathered
3333     subject))
3334
3335 (defun gnus-summary-simplify-subject-query ()
3336   "Query where the respool algorithm would put this article."
3337   (interactive)
3338   (gnus-summary-select-article)
3339   (message "%s"
3340            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3341
3342 (defun gnus-gather-threads-by-subject (threads)
3343   "Gather threads by looking at Subject headers."
3344   (if (not gnus-summary-make-false-root)
3345       threads
3346     (let ((hashtb (gnus-make-hashtable 1024))
3347           (prev threads)
3348           (result threads)
3349           subject hthread whole-subject)
3350       (while threads
3351         (setq subject (gnus-general-simplify-subject
3352                        (setq whole-subject (mail-header-subject
3353                                             (caar threads)))))
3354         (when subject
3355           (if (setq hthread (gnus-gethash subject hashtb))
3356               (progn
3357                 ;; We enter a dummy root into the thread, if we
3358                 ;; haven't done that already.
3359                 (unless (stringp (caar hthread))
3360                   (setcar hthread (list whole-subject (car hthread))))
3361                 ;; We add this new gathered thread to this gathered
3362                 ;; thread.
3363                 (setcdr (car hthread)
3364                         (nconc (cdar hthread) (list (car threads))))
3365                 ;; Remove it from the list of threads.
3366                 (setcdr prev (cdr threads))
3367                 (setq threads prev))
3368             ;; Enter this thread into the hash table.
3369             (gnus-sethash subject threads hashtb)))
3370         (setq prev threads)
3371         (setq threads (cdr threads)))
3372       result)))
3373
3374 (defun gnus-gather-threads-by-references (threads)
3375   "Gather threads by looking at References headers."
3376   (let ((idhashtb (gnus-make-hashtable 1024))
3377         (thhashtb (gnus-make-hashtable 1024))
3378         (prev threads)
3379         (result threads)
3380         ids references id gthread gid entered ref)
3381     (while threads
3382       (when (setq references (mail-header-references (caar threads)))
3383         (setq id (mail-header-id (caar threads))
3384               ids (gnus-split-references references)
3385               entered nil)
3386         (while (setq ref (pop ids))
3387           (setq ids (delete ref ids))
3388           (if (not (setq gid (gnus-gethash ref idhashtb)))
3389               (progn
3390                 (gnus-sethash ref id idhashtb)
3391                 (gnus-sethash id threads thhashtb))
3392             (setq gthread (gnus-gethash gid thhashtb))
3393             (unless entered
3394               ;; We enter a dummy root into the thread, if we
3395               ;; haven't done that already.
3396               (unless (stringp (caar gthread))
3397                 (setcar gthread (list (mail-header-subject (caar gthread))
3398                                       (car gthread))))
3399               ;; We add this new gathered thread to this gathered
3400               ;; thread.
3401               (setcdr (car gthread)
3402                       (nconc (cdar gthread) (list (car threads)))))
3403             ;; Add it into the thread hash table.
3404             (gnus-sethash id gthread thhashtb)
3405             (setq entered t)
3406             ;; Remove it from the list of threads.
3407             (setcdr prev (cdr threads))
3408             (setq threads prev))))
3409       (setq prev threads)
3410       (setq threads (cdr threads)))
3411     result))
3412
3413 (defun gnus-sort-gathered-threads (threads)
3414   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3415   (let ((result threads))
3416     (while threads
3417       (when (stringp (caar threads))
3418         (setcdr (car threads)
3419                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3420       (setq threads (cdr threads)))
3421     result))
3422
3423 (defun gnus-thread-loop-p (root thread)
3424   "Say whether ROOT is in THREAD."
3425   (let ((stack (list thread))
3426         (infloop 0)
3427         th)
3428     (while (setq thread (pop stack))
3429       (setq th (cdr thread))
3430       (while (and th
3431                   (not (eq (caar th) root)))
3432         (pop th))
3433       (if th
3434           ;; We have found a loop.
3435           (let (ref-dep)
3436             (setcdr thread (delq (car th) (cdr thread)))
3437             (if (boundp (setq ref-dep (intern "none"
3438                                               gnus-newsgroup-dependencies)))
3439                 (setcdr (symbol-value ref-dep)
3440                         (nconc (cdr (symbol-value ref-dep))
3441                                (list (car th))))
3442               (set ref-dep (list nil (car th))))
3443             (setq infloop 1
3444                   stack nil))
3445         ;; Push all the subthreads onto the stack.
3446         (push (cdr thread) stack)))
3447     infloop))
3448
3449 (defun gnus-make-threads ()
3450   "Go through the dependency hashtb and find the roots.  Return all threads."
3451   (let (threads)
3452     (while (catch 'infloop
3453              (mapatoms
3454               (lambda (refs)
3455                 ;; Deal with self-referencing References loops.
3456                 (when (and (car (symbol-value refs))
3457                            (not (zerop
3458                                  (apply
3459                                   '+
3460                                   (mapcar
3461                                    (lambda (thread)
3462                                      (gnus-thread-loop-p
3463                                       (car (symbol-value refs)) thread))
3464                                    (cdr (symbol-value refs)))))))
3465                   (setq threads nil)
3466                   (throw 'infloop t))
3467                 (unless (car (symbol-value refs))
3468                   ;; These threads do not refer back to any other articles,
3469                   ;; so they're roots.
3470                   (setq threads (append (cdr (symbol-value refs)) threads))))
3471               gnus-newsgroup-dependencies)))
3472     threads))
3473
3474 ;; Build the thread tree.
3475 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3476   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3477
3478 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3479 if it was already present.
3480
3481 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3482 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3483 Message-IDs will be renamed be renamed to a unique Message-ID before
3484 being entered.
3485
3486 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3487   (let* ((id (mail-header-id header))
3488          (id-dep (and id (intern id dependencies)))
3489          ref ref-dep ref-header)
3490     ;; Enter this `header' in the `dependencies' table.
3491     (cond
3492      ((not id-dep)
3493       (setq header nil))
3494      ;; The first two cases do the normal part: enter a new `header'
3495      ;; in the `dependencies' table.
3496      ((not (boundp id-dep))
3497       (set id-dep (list header)))
3498      ((null (car (symbol-value id-dep)))
3499       (setcar (symbol-value id-dep) header))
3500
3501      ;; From here the `header' was already present in the
3502      ;; `dependencies' table.
3503      (force-new
3504       ;; Overrides an existing entry;
3505       ;; just set the header part of the entry.
3506       (setcar (symbol-value id-dep) header))
3507
3508      ;; Renames the existing `header' to a unique Message-ID.
3509      ((not gnus-summary-ignore-duplicates)
3510       ;; An article with this Message-ID has already been seen.
3511       ;; We rename the Message-ID.
3512       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3513            (list header))
3514       (mail-header-set-id header id))
3515
3516      ;; The last case ignores an existing entry, except it adds any
3517      ;; additional Xrefs (in case the two articles came from different
3518      ;; servers.
3519      ;; Also sets `header' to `nil' meaning that the `dependencies'
3520      ;; table was *not* modified.
3521      (t
3522       (mail-header-set-xref
3523        (car (symbol-value id-dep))
3524        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3525                    "")
3526                (or (mail-header-xref header) "")))
3527       (setq header nil)))
3528
3529     (when header
3530       ;; First check if that we are not creating a References loop.
3531       (setq ref (gnus-parent-id (mail-header-references header)))
3532       (while (and ref
3533                   (setq ref-dep (intern-soft ref dependencies))
3534                   (boundp ref-dep)
3535                   (setq ref-header (car (symbol-value ref-dep))))
3536         (if (string= id ref)
3537             ;; Yuk!  This is a reference loop.  Make the article be a
3538             ;; root article.
3539             (progn
3540               (mail-header-set-references (car (symbol-value id-dep)) "none")
3541               (setq ref nil))
3542           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3543       (setq ref (gnus-parent-id (mail-header-references header)))
3544       (setq ref-dep (intern (or ref "none") dependencies))
3545       (if (boundp ref-dep)
3546           (setcdr (symbol-value ref-dep)
3547                   (nconc (cdr (symbol-value ref-dep))
3548                          (list (symbol-value id-dep))))
3549         (set ref-dep (list nil (symbol-value id-dep)))))
3550     header))
3551
3552 (defun gnus-build-sparse-threads ()
3553   (let ((headers gnus-newsgroup-headers)
3554         (mail-parse-charset gnus-newsgroup-charset)
3555         (gnus-summary-ignore-duplicates t)
3556         header references generation relations
3557         subject child end new-child date)
3558     ;; First we create an alist of generations/relations, where
3559     ;; generations is how much we trust the relation, and the relation
3560     ;; is parent/child.
3561     (gnus-message 7 "Making sparse threads...")
3562     (save-excursion
3563       (nnheader-set-temp-buffer " *gnus sparse threads*")
3564       (while (setq header (pop headers))
3565         (when (and (setq references (mail-header-references header))
3566                    (not (string= references "")))
3567           (insert references)
3568           (setq child (mail-header-id header)
3569                 subject (mail-header-subject header)
3570                 date (mail-header-date header)
3571                 generation 0)
3572           (while (search-backward ">" nil t)
3573             (setq end (1+ (point)))
3574             (when (search-backward "<" nil t)
3575               (setq new-child (buffer-substring (point) end))
3576               (push (list (incf generation)
3577                           child (setq child new-child)
3578                           subject date)
3579                     relations)))
3580           (when child
3581             (push (list (1+ generation) child nil subject) relations))
3582           (erase-buffer)))
3583       (kill-buffer (current-buffer)))
3584     ;; Sort over trustworthiness.
3585     (mapcar
3586      (lambda (relation)
3587        (when (gnus-dependencies-add-header
3588               (make-full-mail-header-from-decoded-header
3589                gnus-reffed-article-number
3590                (nth 3 relation) "" (or (nth 4 relation) "")
3591                (nth 1 relation)
3592                (or (nth 2 relation) "") 0 0 "")
3593               gnus-newsgroup-dependencies nil)
3594          (push gnus-reffed-article-number gnus-newsgroup-limit)
3595          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3596          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3597                gnus-newsgroup-reads)
3598          (decf gnus-reffed-article-number)))
3599      (sort relations 'car-less-than-car))
3600     (gnus-message 7 "Making sparse threads...done")))
3601
3602 (defun gnus-build-old-threads ()
3603   ;; Look at all the articles that refer back to old articles, and
3604   ;; fetch the headers for the articles that aren't there.  This will
3605   ;; build complete threads - if the roots haven't been expired by the
3606   ;; server, that is.
3607   (let ((mail-parse-charset gnus-newsgroup-charset)
3608         id heads)
3609     (mapatoms
3610      (lambda (refs)
3611        (when (not (car (symbol-value refs)))
3612          (setq heads (cdr (symbol-value refs)))
3613          (while heads
3614            (if (memq (mail-header-number (caar heads))
3615                      gnus-newsgroup-dormant)
3616                (setq heads (cdr heads))
3617              (setq id (symbol-name refs))
3618              (while (and (setq id (gnus-build-get-header id))
3619                          (not (car (gnus-id-to-thread id)))))
3620              (setq heads nil)))))
3621      gnus-newsgroup-dependencies)))
3622
3623 ;; This function has to be called with point after the article number
3624 ;; on the beginning of the line.
3625 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
3626   (let ((eol (gnus-point-at-eol))
3627         (buffer (current-buffer))
3628         header)
3629
3630     ;; overview: [num subject from date id refs chars lines misc]
3631     (unwind-protect
3632         (progn
3633           (narrow-to-region (point) eol)
3634           (unless (eobp)
3635             (forward-char))
3636
3637           (setq header
3638                 (make-full-mail-header
3639                  number                         ; number
3640                  (nnheader-nov-field)           ; subject
3641                  (nnheader-nov-field)           ; from
3642                  (nnheader-nov-field)           ; date
3643                  (nnheader-nov-read-message-id) ; id
3644                  (nnheader-nov-field)           ; refs
3645                  (nnheader-nov-read-integer)    ; chars
3646                  (nnheader-nov-read-integer)    ; lines
3647                  (unless (eobp)
3648                    (if (looking-at "Xref: ")
3649                        (goto-char (match-end 0)))
3650                    (nnheader-nov-field))        ; Xref
3651                  (nnheader-nov-parse-extra))))  ; extra
3652
3653       (widen))
3654
3655     (when gnus-alter-header-function
3656       (funcall gnus-alter-header-function header))
3657     (gnus-dependencies-add-header header dependencies force-new)))
3658
3659 (defun gnus-build-get-header (id)
3660   "Look through the buffer of NOV lines and find the header to ID.
3661 Enter this line into the dependencies hash table, and return
3662 the id of the parent article (if any)."
3663   (let ((deps gnus-newsgroup-dependencies)
3664         found header)
3665     (prog1
3666         (save-excursion
3667           (set-buffer nntp-server-buffer)
3668           (let ((case-fold-search nil))
3669             (goto-char (point-min))
3670             (while (and (not found)
3671                         (search-forward id nil t))
3672               (beginning-of-line)
3673               (setq found (looking-at
3674                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
3675                                    (regexp-quote id))))
3676               (or found (beginning-of-line 2)))
3677             (when found
3678               (beginning-of-line)
3679               (and
3680                (setq header (gnus-nov-parse-line
3681                              (read (current-buffer)) deps))
3682                (gnus-parent-id (mail-header-references header))))))
3683       (when header
3684         (let ((number (mail-header-number header)))
3685           (push number gnus-newsgroup-limit)
3686           (push header gnus-newsgroup-headers)
3687           (if (memq number gnus-newsgroup-unselected)
3688               (progn
3689                 (push number gnus-newsgroup-unreads)
3690                 (setq gnus-newsgroup-unselected
3691                       (delq number gnus-newsgroup-unselected)))
3692             (push number gnus-newsgroup-ancient)))))))
3693
3694 (defun gnus-build-all-threads ()
3695   "Read all the headers."
3696   (let ((gnus-summary-ignore-duplicates t)
3697         (mail-parse-charset gnus-newsgroup-charset)
3698         (dependencies gnus-newsgroup-dependencies)
3699         header article)
3700     (save-excursion
3701       (set-buffer nntp-server-buffer)
3702       (let ((case-fold-search nil))
3703         (goto-char (point-min))
3704         (while (not (eobp))
3705           (ignore-errors
3706             (setq article (read (current-buffer))
3707                   header (gnus-nov-parse-line article dependencies)))
3708           (when header
3709             (save-excursion
3710               (set-buffer gnus-summary-buffer)
3711               (push header gnus-newsgroup-headers)
3712               (if (memq (setq article (mail-header-number header))
3713                         gnus-newsgroup-unselected)
3714                   (progn
3715                     (push article gnus-newsgroup-unreads)
3716                     (setq gnus-newsgroup-unselected
3717                           (delq article gnus-newsgroup-unselected)))
3718                 (push article gnus-newsgroup-ancient)))
3719             (forward-line 1)))))))
3720
3721 (defun gnus-summary-update-article-line (article header)
3722   "Update the line for ARTICLE using HEADERS."
3723   (let* ((id (mail-header-id header))
3724          (thread (gnus-id-to-thread id)))
3725     (unless thread
3726       (error "Article in no thread"))
3727     ;; Update the thread.
3728     (setcar thread header)
3729     (gnus-summary-goto-subject article)
3730     (let* ((datal (gnus-data-find-list article))
3731            (data (car datal))
3732            (length (when (cdr datal)
3733                      (- (gnus-data-pos data)
3734                         (gnus-data-pos (cadr datal)))))
3735            (buffer-read-only nil)
3736            (level (gnus-summary-thread-level)))
3737       (gnus-delete-line)
3738       (gnus-summary-insert-line
3739        header level nil (gnus-article-mark article)
3740        (memq article gnus-newsgroup-replied)
3741        (memq article gnus-newsgroup-expirable)
3742        ;; Only insert the Subject string when it's different
3743        ;; from the previous Subject string.
3744        (if (and
3745             gnus-show-threads
3746             (gnus-subject-equal
3747              (condition-case ()
3748                  (mail-header-subject
3749                   (gnus-data-header
3750                    (cadr
3751                     (gnus-data-find-list
3752                      article
3753                      (gnus-data-list t)))))
3754                ;; Error on the side of excessive subjects.
3755                (error ""))
3756              (mail-header-subject header)))
3757            ""
3758          (mail-header-subject header))
3759        nil (cdr (assq article gnus-newsgroup-scored))
3760        (memq article gnus-newsgroup-processable))
3761       (when length
3762         (gnus-data-update-list
3763          (cdr datal) (- length (- (gnus-data-pos data) (point))))))))
3764
3765 (defun gnus-summary-update-article (article &optional iheader)
3766   "Update ARTICLE in the summary buffer."
3767   (set-buffer gnus-summary-buffer)
3768   (let* ((header (gnus-summary-article-header article))
3769          (id (mail-header-id header))
3770          (data (gnus-data-find article))
3771          (thread (gnus-id-to-thread id))
3772          (references (mail-header-references header))
3773          (parent
3774           (gnus-id-to-thread
3775            (or (gnus-parent-id
3776                 (when (and references
3777                            (not (equal "" references)))
3778                   references))
3779                "none")))
3780          (buffer-read-only nil)
3781          (old (car thread)))
3782     (when thread
3783       (unless iheader
3784         (setcar thread nil)
3785         (when parent
3786           (delq thread parent)))
3787       (if (gnus-summary-insert-subject id header)
3788           ;; Set the (possibly) new article number in the data structure.
3789           (gnus-data-set-number data (gnus-id-to-article id))
3790         (setcar thread old)
3791         nil))))
3792
3793 (defun gnus-rebuild-thread (id &optional line)
3794   "Rebuild the thread containing ID.
3795 If LINE, insert the rebuilt thread starting on line LINE."
3796   (let ((buffer-read-only nil)
3797         old-pos current thread data)
3798     (if (not gnus-show-threads)
3799         (setq thread (list (car (gnus-id-to-thread id))))
3800       ;; Get the thread this article is part of.
3801       (setq thread (gnus-remove-thread id)))
3802     (setq old-pos (gnus-point-at-bol))
3803     (setq current (save-excursion
3804                     (and (re-search-backward "[\r\n]" nil t)
3805                          (gnus-summary-article-number))))
3806     ;; If this is a gathered thread, we have to go some re-gathering.
3807     (when (stringp (car thread))
3808       (let ((subject (car thread))
3809             roots thr)
3810         (setq thread (cdr thread))
3811         (while thread
3812           (unless (memq (setq thr (gnus-id-to-thread
3813                                    (gnus-root-id
3814                                     (mail-header-id (caar thread)))))
3815                         roots)
3816             (push thr roots))
3817           (setq thread (cdr thread)))
3818         ;; We now have all (unique) roots.
3819         (if (= (length roots) 1)
3820             ;; All the loose roots are now one solid root.
3821             (setq thread (car roots))
3822           (setq thread (cons subject (gnus-sort-threads roots))))))
3823     (let (threads)
3824       ;; We then insert this thread into the summary buffer.
3825       (when line
3826         (goto-char (point-min))
3827         (forward-line (1- line)))
3828       (let (gnus-newsgroup-data gnus-newsgroup-threads)
3829         (if gnus-show-threads
3830             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
3831           (gnus-summary-prepare-unthreaded thread))
3832         (setq data (nreverse gnus-newsgroup-data))
3833         (setq threads gnus-newsgroup-threads))
3834       ;; We splice the new data into the data structure.
3835       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
3836       ;;!!! then we want to insert at the beginning of the buffer.
3837       ;;!!! That happens to be true with Gnus now, but that may
3838       ;;!!! change in the future.  Perhaps.
3839       (gnus-data-enter-list
3840        (if line nil current) data (- (point) old-pos))
3841       (setq gnus-newsgroup-threads
3842             (nconc threads gnus-newsgroup-threads))
3843       (gnus-data-compute-positions))))
3844
3845 (defun gnus-number-to-header (number)
3846   "Return the header for article NUMBER."
3847   (let ((headers gnus-newsgroup-headers))
3848     (while (and headers
3849                 (not (= number (mail-header-number (car headers)))))
3850       (pop headers))
3851     (when headers
3852       (car headers))))
3853
3854 (defun gnus-parent-headers (in-headers &optional generation)
3855   "Return the headers of the GENERATIONeth parent of HEADERS."
3856   (unless generation
3857     (setq generation 1))
3858   (let ((parent t)
3859         (headers in-headers)
3860         references)
3861     (while (and parent
3862                 (not (zerop generation))
3863                 (setq references (mail-header-references headers)))
3864       (setq headers (if (and references
3865                              (setq parent (gnus-parent-id references)))
3866                         (car (gnus-id-to-thread parent))
3867                       nil))
3868       (decf generation))
3869     (and (not (eq headers in-headers))
3870          headers)))
3871
3872 (defun gnus-id-to-thread (id)
3873   "Return the (sub-)thread where ID appears."
3874   (gnus-gethash id gnus-newsgroup-dependencies))
3875
3876 (defun gnus-id-to-article (id)
3877   "Return the article number of ID."
3878   (let ((thread (gnus-id-to-thread id)))
3879     (when (and thread
3880                (car thread))
3881       (mail-header-number (car thread)))))
3882
3883 (defun gnus-id-to-header (id)
3884   "Return the article headers of ID."
3885   (car (gnus-id-to-thread id)))
3886
3887 (defun gnus-article-displayed-root-p (article)
3888   "Say whether ARTICLE is a root(ish) article."
3889   (let ((level (gnus-summary-thread-level article))
3890         (refs (mail-header-references  (gnus-summary-article-header article)))
3891         particle)
3892     (cond
3893      ((null level) nil)
3894      ((zerop level) t)
3895      ((null refs) t)
3896      ((null (gnus-parent-id refs)) t)
3897      ((and (= 1 level)
3898            (null (setq particle (gnus-id-to-article
3899                                  (gnus-parent-id refs))))
3900            (null (gnus-summary-thread-level particle)))))))
3901
3902 (defun gnus-root-id (id)
3903   "Return the id of the root of the thread where ID appears."
3904   (let (last-id prev)
3905     (while (and id (setq prev (car (gnus-id-to-thread id))))
3906       (setq last-id id
3907             id (gnus-parent-id (mail-header-references prev))))
3908     last-id))
3909
3910 (defun gnus-articles-in-thread (thread)
3911   "Return the list of articles in THREAD."
3912   (cons (mail-header-number (car thread))
3913         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
3914
3915 (defun gnus-remove-thread (id &optional dont-remove)
3916   "Remove the thread that has ID in it."
3917   (let (headers thread last-id)
3918     ;; First go up in this thread until we find the root.
3919     (setq last-id (gnus-root-id id)
3920           headers (message-flatten-list (gnus-id-to-thread last-id)))
3921     ;; We have now found the real root of this thread.  It might have
3922     ;; been gathered into some loose thread, so we have to search
3923     ;; through the threads to find the thread we wanted.
3924     (let ((threads gnus-newsgroup-threads)
3925           sub)
3926       (while threads
3927         (setq sub (car threads))
3928         (if (stringp (car sub))
3929             ;; This is a gathered thread, so we look at the roots
3930             ;; below it to find whether this article is in this
3931             ;; gathered root.
3932             (progn
3933               (setq sub (cdr sub))
3934               (while sub
3935                 (when (member (caar sub) headers)
3936                   (setq thread (car threads)
3937                         threads nil
3938                         sub nil))
3939                 (setq sub (cdr sub))))
3940           ;; It's an ordinary thread, so we check it.
3941           (when (eq (car sub) (car headers))
3942             (setq thread sub
3943                   threads nil)))
3944         (setq threads (cdr threads)))
3945       ;; If this article is in no thread, then it's a root.
3946       (if thread
3947           (unless dont-remove
3948             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
3949         (setq thread (gnus-id-to-thread last-id)))
3950       (when thread
3951         (prog1
3952             thread                      ; We return this thread.
3953           (unless dont-remove
3954             (if (stringp (car thread))
3955                 (progn
3956                   ;; If we use dummy roots, then we have to remove the
3957                   ;; dummy root as well.
3958                   (when (eq gnus-summary-make-false-root 'dummy)
3959                     ;; We go to the dummy root by going to
3960                     ;; the first sub-"thread", and then one line up.
3961                     (gnus-summary-goto-article
3962                      (mail-header-number (caadr thread)))
3963                     (forward-line -1)
3964                     (gnus-delete-line)
3965                     (gnus-data-compute-positions))
3966                   (setq thread (cdr thread))
3967                   (while thread
3968                     (gnus-remove-thread-1 (car thread))
3969                     (setq thread (cdr thread))))
3970               (gnus-remove-thread-1 thread))))))))
3971
3972 (defun gnus-remove-thread-1 (thread)
3973   "Remove the thread THREAD recursively."
3974   (let ((number (mail-header-number (pop thread)))
3975         d)
3976     (setq thread (reverse thread))
3977     (while thread
3978       (gnus-remove-thread-1 (pop thread)))
3979     (when (setq d (gnus-data-find number))
3980       (goto-char (gnus-data-pos d))
3981       (gnus-summary-show-thread)
3982       (gnus-data-remove
3983        number
3984        (- (gnus-point-at-bol)
3985           (prog1
3986               (1+ (gnus-point-at-eol))
3987             (gnus-delete-line)))))))
3988
3989 (defun gnus-sort-threads-1 (threads func)
3990   (sort (mapcar (lambda (thread)
3991                   (cons (car thread)
3992                         (and (cdr thread)
3993                              (gnus-sort-threads-1 (cdr thread) func))))
3994                 threads) func))
3995
3996 (defun gnus-sort-threads (threads)
3997   "Sort THREADS."
3998   (if (not gnus-thread-sort-functions)
3999       threads
4000     (gnus-message 8 "Sorting threads...")
4001     (prog1
4002         (gnus-sort-threads-1
4003          threads
4004          (gnus-make-sort-function gnus-thread-sort-functions))
4005       (gnus-message 8 "Sorting threads...done"))))
4006
4007 (defun gnus-sort-articles (articles)
4008   "Sort ARTICLES."
4009   (when gnus-article-sort-functions
4010     (gnus-message 7 "Sorting articles...")
4011     (prog1
4012         (setq gnus-newsgroup-headers
4013               (sort articles (gnus-make-sort-function
4014                               gnus-article-sort-functions)))
4015       (gnus-message 7 "Sorting articles...done"))))
4016
4017 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4018 (defmacro gnus-thread-header (thread)
4019   "Return header of first article in THREAD.
4020 Note that THREAD must never, ever be anything else than a variable -
4021 using some other form will lead to serious barfage."
4022   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4023   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4024   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4025         (vector thread) 2))
4026
4027 (defsubst gnus-article-sort-by-number (h1 h2)
4028   "Sort articles by article number."
4029   (< (mail-header-number h1)
4030      (mail-header-number h2)))
4031
4032 (defun gnus-thread-sort-by-number (h1 h2)
4033   "Sort threads by root article number."
4034   (gnus-article-sort-by-number
4035    (gnus-thread-header h1) (gnus-thread-header h2)))
4036
4037 (defsubst gnus-article-sort-by-lines (h1 h2)
4038   "Sort articles by article Lines header."
4039   (< (mail-header-lines h1)
4040      (mail-header-lines h2)))
4041
4042 (defun gnus-thread-sort-by-lines (h1 h2)
4043   "Sort threads by root article Lines header."
4044   (gnus-article-sort-by-lines
4045    (gnus-thread-header h1) (gnus-thread-header h2)))
4046
4047 (defsubst gnus-article-sort-by-chars (h1 h2)
4048   "Sort articles by octet length."
4049   (< (mail-header-chars h1)
4050      (mail-header-chars h2)))
4051
4052 (defun gnus-thread-sort-by-chars (h1 h2)
4053   "Sort threads by root article octet length."
4054   (gnus-article-sort-by-chars
4055    (gnus-thread-header h1) (gnus-thread-header h2)))
4056
4057 (defsubst gnus-article-sort-by-author (h1 h2)
4058   "Sort articles by root author."
4059   (string-lessp
4060    (let ((addr (car (mime-entity-read-field h1 'From))))
4061      (or (std11-full-name-string addr)
4062          (std11-address-string addr)
4063          ""))
4064    (let ((addr (car (mime-entity-read-field h2 'From))))
4065      (or (std11-full-name-string addr)
4066          (std11-address-string addr)
4067          ""))
4068    ))
4069
4070 (defun gnus-thread-sort-by-author (h1 h2)
4071   "Sort threads by root author."
4072   (gnus-article-sort-by-author
4073    (gnus-thread-header h1)  (gnus-thread-header h2)))
4074
4075 (defsubst gnus-article-sort-by-subject (h1 h2)
4076   "Sort articles by root subject."
4077   (string-lessp
4078    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4079    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4080
4081 (defun gnus-thread-sort-by-subject (h1 h2)
4082   "Sort threads by root subject."
4083   (gnus-article-sort-by-subject
4084    (gnus-thread-header h1) (gnus-thread-header h2)))
4085
4086 (defsubst gnus-article-sort-by-date (h1 h2)
4087   "Sort articles by root article date."
4088   (time-less-p
4089    (gnus-date-get-time (mail-header-date h1))
4090    (gnus-date-get-time (mail-header-date h2))))
4091
4092 (defun gnus-thread-sort-by-date (h1 h2)
4093   "Sort threads by root article date."
4094   (gnus-article-sort-by-date
4095    (gnus-thread-header h1) (gnus-thread-header h2)))
4096
4097 (defsubst gnus-article-sort-by-score (h1 h2)
4098   "Sort articles by root article score.
4099 Unscored articles will be counted as having a score of zero."
4100   (> (or (cdr (assq (mail-header-number h1)
4101                     gnus-newsgroup-scored))
4102          gnus-summary-default-score 0)
4103      (or (cdr (assq (mail-header-number h2)
4104                     gnus-newsgroup-scored))
4105          gnus-summary-default-score 0)))
4106
4107 (defun gnus-thread-sort-by-score (h1 h2)
4108   "Sort threads by root article score."
4109   (gnus-article-sort-by-score
4110    (gnus-thread-header h1) (gnus-thread-header h2)))
4111
4112 (defun gnus-thread-sort-by-total-score (h1 h2)
4113   "Sort threads by the sum of all scores in the thread.
4114 Unscored articles will be counted as having a score of zero."
4115   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4116
4117 (defun gnus-thread-total-score (thread)
4118   ;; This function find the total score of THREAD.
4119   (cond ((null thread)
4120          0)
4121         ((consp thread)
4122          (if (stringp (car thread))
4123              (apply gnus-thread-score-function 0
4124                     (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4125            (gnus-thread-total-score-1 thread)))
4126         (t
4127          (gnus-thread-total-score-1 (list thread)))))
4128
4129 (defun gnus-thread-total-score-1 (root)
4130   ;; This function find the total score of the thread below ROOT.
4131   (setq root (car root))
4132   (apply gnus-thread-score-function
4133          (or (append
4134               (mapcar 'gnus-thread-total-score
4135                       (cdr (gnus-id-to-thread (mail-header-id root))))
4136               (when (> (mail-header-number root) 0)
4137                 (list (or (cdr (assq (mail-header-number root)
4138                                      gnus-newsgroup-scored))
4139                           gnus-summary-default-score 0))))
4140              (list gnus-summary-default-score)
4141              '(0))))
4142
4143 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4144 (defvar gnus-tmp-prev-subject nil)
4145 (defvar gnus-tmp-false-parent nil)
4146 (defvar gnus-tmp-root-expunged nil)
4147 (defvar gnus-tmp-dummy-line nil)
4148
4149 (eval-when-compile (defvar gnus-tmp-header))
4150 (defun gnus-extra-header (type &optional header)
4151   "Return the extra header of TYPE."
4152   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4153       ""))
4154
4155 (defvar gnus-tmp-thread-tree-header-string "")
4156
4157 (defvar gnus-sum-thread-tree-root "> "
4158   "With %B spec, used for the root of a thread.
4159 If nil, use subject instead.")
4160 (defvar gnus-sum-thread-tree-single-indent ""
4161   "With %B spec, used for a thread with just one message.
4162 If nil, use subject instead.")
4163 (defvar gnus-sum-thread-tree-vertical "| "
4164   "With %B spec, used for drawing a vertical line.")
4165 (defvar gnus-sum-thread-tree-indent "  "
4166   "With %B spec, used for indenting.")
4167 (defvar gnus-sum-thread-tree-leaf-with-other "+-> "
4168   "With %B spec, used for a leaf with brothers.")
4169 (defvar gnus-sum-thread-tree-single-leaf "\\-> "
4170   "With %B spec, used for a leaf without brothers.")
4171
4172 (defun gnus-summary-prepare-threads (threads)
4173   "Prepare summary buffer from THREADS and indentation LEVEL.
4174 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4175 or a straight list of headers."
4176   (gnus-message 7 "Generating summary...")
4177
4178   (setq gnus-newsgroup-threads threads)
4179   (beginning-of-line)
4180
4181   (let ((gnus-tmp-level 0)
4182         (default-score (or gnus-summary-default-score 0))
4183         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4184         thread number subject stack state gnus-tmp-gathered beg-match
4185         new-roots gnus-tmp-new-adopts thread-end
4186         gnus-tmp-header gnus-tmp-unread
4187         gnus-tmp-replied gnus-tmp-subject-or-nil
4188         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4189         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4190         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4191         tree-stack)
4192
4193     (setq gnus-tmp-prev-subject nil)
4194
4195     (if (vectorp (car threads))
4196         ;; If this is a straight (sic) list of headers, then a
4197         ;; threaded summary display isn't required, so we just create
4198         ;; an unthreaded one.
4199         (gnus-summary-prepare-unthreaded threads)
4200
4201       ;; Do the threaded display.
4202
4203       (while (or threads stack gnus-tmp-new-adopts new-roots)
4204
4205         (if (and (= gnus-tmp-level 0)
4206                  (or (not stack)
4207                      (= (caar stack) 0))
4208                  (not gnus-tmp-false-parent)
4209                  (or gnus-tmp-new-adopts new-roots))
4210             (if gnus-tmp-new-adopts
4211                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4212                       thread (list (car gnus-tmp-new-adopts))
4213                       gnus-tmp-header (caar thread)
4214                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4215               (when new-roots
4216                 (setq thread (list (car new-roots))
4217                       gnus-tmp-header (caar thread)
4218                       new-roots (cdr new-roots))))
4219
4220           (if threads
4221               ;; If there are some threads, we do them before the
4222               ;; threads on the stack.
4223               (setq thread threads
4224                     gnus-tmp-header (caar thread))
4225             ;; There were no current threads, so we pop something off
4226             ;; the stack.
4227             (setq state (car stack)
4228                   gnus-tmp-level (car state)
4229                   tree-stack (cadr state)
4230                   thread (caddr state)
4231                   stack (cdr stack)
4232                   gnus-tmp-header (caar thread))))
4233
4234         (setq gnus-tmp-false-parent nil)
4235         (setq gnus-tmp-root-expunged nil)
4236         (setq thread-end nil)
4237
4238         (if (stringp gnus-tmp-header)
4239             ;; The header is a dummy root.
4240             (cond
4241              ((eq gnus-summary-make-false-root 'adopt)
4242               ;; We let the first article adopt the rest.
4243               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4244                                                (cddar thread)))
4245               (setq gnus-tmp-gathered
4246                     (nconc (mapcar
4247                             (lambda (h) (mail-header-number (car h)))
4248                             (cddar thread))
4249                            gnus-tmp-gathered))
4250               (setq thread (cons (list (caar thread)
4251                                        (cadar thread))
4252                                  (cdr thread)))
4253               (setq gnus-tmp-level -1
4254                     gnus-tmp-false-parent t))
4255              ((eq gnus-summary-make-false-root 'empty)
4256               ;; We print adopted articles with empty subject fields.
4257               (setq gnus-tmp-gathered
4258                     (nconc (mapcar
4259                             (lambda (h) (mail-header-number (car h)))
4260                             (cddar thread))
4261                            gnus-tmp-gathered))
4262               (setq gnus-tmp-level -1))
4263              ((eq gnus-summary-make-false-root 'dummy)
4264               ;; We remember that we probably want to output a dummy
4265               ;; root.
4266               (setq gnus-tmp-dummy-line gnus-tmp-header)
4267               (setq gnus-tmp-prev-subject gnus-tmp-header))
4268              (t
4269               ;; We do not make a root for the gathered
4270               ;; sub-threads at all.
4271               (setq gnus-tmp-level -1)))
4272
4273           (setq number (mail-header-number gnus-tmp-header)
4274                 subject (mail-header-subject gnus-tmp-header))
4275
4276           (cond
4277            ;; If the thread has changed subject, we might want to make
4278            ;; this subthread into a root.
4279            ((and (null gnus-thread-ignore-subject)
4280                  (not (zerop gnus-tmp-level))
4281                  gnus-tmp-prev-subject
4282                  (not (inline
4283                         (gnus-subject-equal gnus-tmp-prev-subject subject))))
4284             (setq new-roots (nconc new-roots (list (car thread)))
4285                   thread-end t
4286                   gnus-tmp-header nil))
4287            ;; If the article lies outside the current limit,
4288            ;; then we do not display it.
4289            ((not (memq number gnus-newsgroup-limit))
4290             (setq gnus-tmp-gathered
4291                   (nconc (mapcar
4292                           (lambda (h) (mail-header-number (car h)))
4293                           (cdar thread))
4294                          gnus-tmp-gathered))
4295             (setq gnus-tmp-new-adopts (if (cdar thread)
4296                                           (append gnus-tmp-new-adopts
4297                                                   (cdar thread))
4298                                         gnus-tmp-new-adopts)
4299                   thread-end t
4300                   gnus-tmp-header nil)
4301             (when (zerop gnus-tmp-level)
4302               (setq gnus-tmp-root-expunged t)))
4303            ;; Perhaps this article is to be marked as read?
4304            ((and gnus-summary-mark-below
4305                  (< (or (cdr (assq number gnus-newsgroup-scored))
4306                         default-score)
4307                     gnus-summary-mark-below)
4308                  ;; Don't touch sparse articles.
4309                  (not (gnus-summary-article-sparse-p number))
4310                  (not (gnus-summary-article-ancient-p number)))
4311             (setq gnus-newsgroup-unreads
4312                   (delq number gnus-newsgroup-unreads))
4313             (if gnus-newsgroup-auto-expire
4314                 (push number gnus-newsgroup-expirable)
4315               (push (cons number gnus-low-score-mark)
4316                     gnus-newsgroup-reads))))
4317
4318           (when gnus-tmp-header
4319             ;; We may have an old dummy line to output before this
4320             ;; article.
4321             (when (and gnus-tmp-dummy-line
4322                        (gnus-subject-equal
4323                         gnus-tmp-dummy-line
4324                         (mail-header-subject gnus-tmp-header)))
4325               (gnus-summary-insert-dummy-line
4326                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4327               (setq gnus-tmp-dummy-line nil))
4328
4329             ;; Compute the mark.
4330             (setq gnus-tmp-unread (gnus-article-mark number))
4331
4332             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4333                                   gnus-tmp-header gnus-tmp-level)
4334                   gnus-newsgroup-data)
4335
4336             ;; Actually insert the line.
4337             (setq
4338              gnus-tmp-subject-or-nil
4339              (cond
4340               ((and gnus-thread-ignore-subject
4341                     gnus-tmp-prev-subject
4342                     (not (inline (gnus-subject-equal
4343                                   gnus-tmp-prev-subject subject))))
4344                subject)
4345               ((zerop gnus-tmp-level)
4346                (if (and (eq gnus-summary-make-false-root 'empty)
4347                         (memq number gnus-tmp-gathered)
4348                         gnus-tmp-prev-subject
4349                         (inline (gnus-subject-equal
4350                                  gnus-tmp-prev-subject subject)))
4351                    gnus-summary-same-subject
4352                  subject))
4353               (t gnus-summary-same-subject)))
4354             (if (and (eq gnus-summary-make-false-root 'adopt)
4355                      (= gnus-tmp-level 1)
4356                      (memq number gnus-tmp-gathered))
4357                 (setq gnus-tmp-opening-bracket ?\<
4358                       gnus-tmp-closing-bracket ?\>)
4359               (setq gnus-tmp-opening-bracket ?\[
4360                     gnus-tmp-closing-bracket ?\]))
4361             (setq
4362              gnus-tmp-indentation
4363              (aref gnus-thread-indent-array gnus-tmp-level)
4364              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4365              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4366                                 gnus-summary-default-score 0)
4367              gnus-tmp-score-char
4368              (if (or (null gnus-summary-default-score)
4369                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4370                          gnus-summary-zcore-fuzz))
4371                  ?\ ;;;Whitespace
4372                (if (< gnus-tmp-score gnus-summary-default-score)
4373                    gnus-score-below-mark gnus-score-over-mark))
4374              gnus-tmp-replied
4375              (cond ((memq number gnus-newsgroup-processable)
4376                     gnus-process-mark)
4377                    ((memq number gnus-newsgroup-cached)
4378                     gnus-cached-mark)
4379                    ((memq number gnus-newsgroup-replied)
4380                     gnus-replied-mark)
4381                    ((memq number gnus-newsgroup-forwarded)
4382                     gnus-forwarded-mark)
4383                    ((memq number gnus-newsgroup-saved)
4384                     gnus-saved-mark)
4385                    ((memq number gnus-newsgroup-recent)
4386                     gnus-recent-mark)
4387                    ((memq number gnus-newsgroup-unseen)
4388                     gnus-unseen-mark)
4389                    (t gnus-no-mark))
4390              gnus-tmp-from (mail-header-from gnus-tmp-header)
4391              gnus-tmp-name
4392              (cond
4393               ((string-match "<[^>]+> *$" gnus-tmp-from)
4394                (setq beg-match (match-beginning 0))
4395                (or (and (string-match "^\".+\"" gnus-tmp-from)
4396                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4397                    (substring gnus-tmp-from 0 beg-match)))
4398               ((string-match "(.+)" gnus-tmp-from)
4399                (substring gnus-tmp-from
4400                           (1+ (match-beginning 0)) (1- (match-end 0))))
4401               (t gnus-tmp-from))
4402              gnus-tmp-thread-tree-header-string
4403              (cond
4404               ((not gnus-show-threads) "")
4405               ((zerop gnus-tmp-level)
4406                (if (cdar thread)
4407                    (or gnus-sum-thread-tree-root subject)
4408                  (or gnus-sum-thread-tree-single-indent subject)))
4409               (t
4410                (concat (apply 'concat
4411                               (mapcar (lambda (item)
4412                                         (if (= item 1)
4413                                             gnus-sum-thread-tree-vertical
4414                                           gnus-sum-thread-tree-indent))
4415                                       (cdr (reverse tree-stack))))
4416                        (if (nth 1 thread)
4417                            gnus-sum-thread-tree-leaf-with-other
4418                          gnus-sum-thread-tree-single-leaf)))))
4419             (when (string= gnus-tmp-name "")
4420               (setq gnus-tmp-name gnus-tmp-from))
4421             (unless (numberp gnus-tmp-lines)
4422               (setq gnus-tmp-lines -1))
4423             (if (= gnus-tmp-lines -1)
4424                 (setq gnus-tmp-lines "?")
4425               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4426             (gnus-put-text-property
4427              (point)
4428              (progn (eval gnus-summary-line-format-spec) (point))
4429              'gnus-number number)
4430             (when gnus-visual-p
4431               (forward-line -1)
4432               (gnus-run-hooks 'gnus-summary-update-hook)
4433               (forward-line 1))
4434
4435             (setq gnus-tmp-prev-subject subject)))
4436
4437         (when (nth 1 thread)
4438           (push (list (max 0 gnus-tmp-level)
4439                       (copy-list tree-stack)
4440                       (nthcdr 1 thread))
4441                 stack))
4442         (push (if (nth 1 thread) 1 0) tree-stack)
4443         (incf gnus-tmp-level)
4444         (setq threads (if thread-end nil (cdar thread)))
4445         (unless threads
4446           (setq gnus-tmp-level 0)))))
4447   (gnus-message 7 "Generating summary...done"))
4448
4449 (defun gnus-summary-prepare-unthreaded (headers)
4450   "Generate an unthreaded summary buffer based on HEADERS."
4451   (let (header number mark)
4452
4453     (beginning-of-line)
4454
4455     (while headers
4456       ;; We may have to root out some bad articles...
4457       (when (memq (setq number (mail-header-number
4458                                 (setq header (pop headers))))
4459                   gnus-newsgroup-limit)
4460         ;; Mark article as read when it has a low score.
4461         (when (and gnus-summary-mark-below
4462                    (< (or (cdr (assq number gnus-newsgroup-scored))
4463                           gnus-summary-default-score 0)
4464                       gnus-summary-mark-below)
4465                    (not (gnus-summary-article-ancient-p number)))
4466           (setq gnus-newsgroup-unreads
4467                 (delq number gnus-newsgroup-unreads))
4468           (if gnus-newsgroup-auto-expire
4469               (push number gnus-newsgroup-expirable)
4470             (push (cons number gnus-low-score-mark)
4471                   gnus-newsgroup-reads)))
4472
4473         (setq mark (gnus-article-mark number))
4474         (push (gnus-data-make number mark (1+ (point)) header 0)
4475               gnus-newsgroup-data)
4476         (gnus-summary-insert-line
4477          header 0 number
4478          mark (memq number gnus-newsgroup-replied)
4479          (memq number gnus-newsgroup-expirable)
4480          (mail-header-subject header) nil
4481          (cdr (assq number gnus-newsgroup-scored))
4482          (memq number gnus-newsgroup-processable))))))
4483
4484 (defun gnus-summary-remove-list-identifiers ()
4485   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4486   (let ((regexp (if (consp gnus-list-identifiers)
4487                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4488                   gnus-list-identifiers))
4489         changed subject)
4490     (when regexp
4491       (dolist (header gnus-newsgroup-headers)
4492         (setq subject (mail-header-subject header)
4493               changed nil)
4494         (while (string-match
4495                 (concat "^\\(R[Ee]: +\\)*\\(" regexp " *\\)")
4496                 subject)
4497           (setq subject
4498                 (concat (substring subject 0 (match-beginning 2))
4499                         (substring subject (match-end 0)))
4500                 changed t))
4501         (when (and changed
4502                    (string-match
4503                     "^\\(\\(R[Ee]: +\\)+\\)R[Ee]: +" subject))
4504           (setq subject
4505                 (concat (substring subject 0 (match-beginning 1))
4506                         (substring subject (match-end 1)))))
4507         (when changed
4508           (mail-header-set-subject header subject))))))
4509
4510 (defun gnus-fetch-headers (articles)
4511   "Fetch headers of ARTICLES."
4512   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4513     (gnus-message 5 "Fetching headers for %s..." name)
4514     (prog1
4515         (if (eq 'nov
4516                 (setq gnus-headers-retrieved-by
4517                       (gnus-retrieve-headers
4518                        articles gnus-newsgroup-name
4519                        ;; We might want to fetch old headers, but
4520                        ;; not if there is only 1 article.
4521                        (and (or (and
4522                                  (not (eq gnus-fetch-old-headers 'some))
4523                                  (not (numberp gnus-fetch-old-headers)))
4524                                 (> (length articles) 1))
4525                             gnus-fetch-old-headers))))
4526             (gnus-get-newsgroup-headers-xover
4527              articles nil nil gnus-newsgroup-name t)
4528           (gnus-get-newsgroup-headers))
4529       (gnus-message 5 "Fetching headers for %s...done" name))))
4530
4531 (defun gnus-select-newsgroup (group &optional read-all select-articles)
4532   "Select newsgroup GROUP.
4533 If READ-ALL is non-nil, all articles in the group are selected.
4534 If SELECT-ARTICLES, only select those articles from GROUP."
4535   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
4536          ;;!!! Dirty hack; should be removed.
4537          (gnus-summary-ignore-duplicates
4538           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
4539               t
4540             gnus-summary-ignore-duplicates))
4541          (info (nth 2 entry))
4542          articles fetched-articles cached)
4543
4544     (unless (gnus-check-server
4545              (set (make-local-variable 'gnus-current-select-method)
4546                   (gnus-find-method-for-group group)))
4547       (error "Couldn't open server"))
4548
4549     (or (and entry (not (eq (car entry) t))) ; Either it's active...
4550         (gnus-activate-group group)     ; Or we can activate it...
4551         (progn                          ; Or we bug out.
4552           (when (equal major-mode 'gnus-summary-mode)
4553             (kill-buffer (current-buffer)))
4554           (error "Couldn't activate group %s: %s"
4555                  group (gnus-status-message group))))
4556
4557     (unless (gnus-request-group group t)
4558       (when (equal major-mode 'gnus-summary-mode)
4559         (kill-buffer (current-buffer)))
4560       (error "Couldn't request group %s: %s"
4561              group (gnus-status-message group)))
4562
4563     (setq gnus-newsgroup-name group
4564           gnus-newsgroup-unselected nil
4565           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
4566
4567     (let ((display (gnus-group-find-parameter group 'display)))
4568       (setq gnus-newsgroup-display
4569             (cond
4570              ((not (zerop (or (car-safe read-all) 0)))
4571               ;; The user entered the group with C-u SPC/RET, let's show
4572               ;; all articles.
4573               'gnus-not-ignore)
4574              ((eq display 'all)
4575               'gnus-not-ignore)
4576              ((arrayp display)
4577               (gnus-summary-display-make-predicate (mapcar 'identity display)))
4578              (t
4579               nil))))
4580
4581     (gnus-summary-setup-default-charset)
4582
4583     ;; Kludge to avoid having cached articles nixed out in virtual groups.
4584     (when (gnus-virtual-group-p group)
4585       (setq cached gnus-newsgroup-cached))
4586
4587     (setq gnus-newsgroup-unreads
4588           (gnus-set-difference
4589            (gnus-set-difference gnus-newsgroup-unreads gnus-newsgroup-marked)
4590            gnus-newsgroup-dormant))
4591
4592     (setq gnus-newsgroup-processable nil)
4593
4594     (gnus-update-read-articles group gnus-newsgroup-unreads)
4595
4596     ;; Adjust and set lists of article marks.
4597     (when info
4598       (gnus-adjust-marked-articles info))
4599
4600     (if (setq articles select-articles)
4601         (setq gnus-newsgroup-unselected
4602               (gnus-sorted-intersection
4603                gnus-newsgroup-unreads
4604                (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4605       (setq articles (gnus-articles-to-read group read-all)))
4606
4607     (cond
4608      ((null articles)
4609       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
4610       'quit)
4611      ((eq articles 0) nil)
4612      (t
4613       ;; Init the dependencies hash table.
4614       (setq gnus-newsgroup-dependencies
4615             (gnus-make-hashtable (length articles)))
4616       (gnus-set-global-variables)
4617       ;; Retrieve the headers and read them in.
4618       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
4619
4620       ;; Kludge to avoid having cached articles nixed out in virtual groups.
4621       (when cached
4622         (setq gnus-newsgroup-cached cached))
4623
4624       ;; Suppress duplicates?
4625       (when gnus-suppress-duplicates
4626         (gnus-dup-suppress-articles))
4627
4628       ;; Set the initial limit.
4629       (setq gnus-newsgroup-limit (copy-sequence articles))
4630       ;; Remove canceled articles from the list of unread articles.
4631       (setq fetched-articles
4632             (mapcar (lambda (headers) (mail-header-number headers))
4633                     gnus-newsgroup-headers))
4634       (setq gnus-newsgroup-articles fetched-articles)
4635       (setq gnus-newsgroup-unreads
4636             (gnus-set-sorted-intersection
4637              gnus-newsgroup-unreads fetched-articles))
4638
4639       (let ((marks (assq 'seen (gnus-info-marks info))))
4640         ;; The `seen' marks are treated specially.
4641         (when (setq gnus-newsgroup-seen (cdr marks))
4642           (dolist (article gnus-newsgroup-articles)
4643             (unless (gnus-member-of-range
4644                      article gnus-newsgroup-seen)
4645               (push article gnus-newsgroup-unseen)))))
4646
4647       ;; Removed marked articles that do not exist.
4648       (gnus-update-missing-marks
4649        (gnus-sorted-complement fetched-articles articles))
4650       ;; We might want to build some more threads first.
4651       (when (and gnus-fetch-old-headers
4652                  (eq gnus-headers-retrieved-by 'nov))
4653         (if (eq gnus-fetch-old-headers 'invisible)
4654             (gnus-build-all-threads)
4655           (gnus-build-old-threads)))
4656       ;; Let the Gnus agent mark articles as read.
4657       (when gnus-agent
4658         (gnus-agent-get-undownloaded-list))
4659       ;; Remove list identifiers from subject
4660       (when gnus-list-identifiers
4661         (gnus-summary-remove-list-identifiers))
4662       ;; Check whether auto-expire is to be done in this group.
4663       (setq gnus-newsgroup-auto-expire
4664             (gnus-group-auto-expirable-p group))
4665       ;; Set up the article buffer now, if necessary.
4666       (unless gnus-single-article-buffer
4667         (gnus-article-setup-buffer))
4668       ;; First and last article in this newsgroup.
4669       (when gnus-newsgroup-headers
4670         (setq gnus-newsgroup-begin
4671               (mail-header-number (car gnus-newsgroup-headers))
4672               gnus-newsgroup-end
4673               (mail-header-number
4674                (gnus-last-element gnus-newsgroup-headers))))
4675       ;; GROUP is successfully selected.
4676       (or gnus-newsgroup-headers t)))))
4677
4678 (defun gnus-summary-display-make-predicate (display)
4679   (require 'gnus-agent)
4680   (when (= (length display) 1)
4681     (setq display (car display)))
4682   (unless gnus-summary-display-cache
4683     (dolist (elem (append (list (cons 'read 'read)
4684                                 (cons 'unseen 'unseen))
4685                           gnus-article-mark-lists))
4686       (push (cons (cdr elem)
4687                   (gnus-byte-compile
4688                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
4689             gnus-summary-display-cache)))
4690   (let ((gnus-category-predicate-alist gnus-summary-display-cache))
4691     (gnus-get-predicate display)))
4692
4693 ;; Uses the dynamically bound `number' variable.
4694 (defvar number)
4695 (defun gnus-article-marked-p (type &optional article)
4696   (let ((article (or article number)))
4697     (cond
4698      ((eq type 'tick)
4699       (memq article gnus-newsgroup-marked))
4700      ((eq type 'unsend)
4701       (memq article gnus-newsgroup-unsendable))
4702      ((eq type 'undownload)
4703       (memq article gnus-newsgroup-undownloaded))
4704      ((eq type 'download)
4705       (memq article gnus-newsgroup-downloadable))
4706      ((eq type 'unread)
4707       (memq article gnus-newsgroup-unreads))
4708      ((eq type 'read)
4709       (memq article gnus-newsgroup-reads))
4710      ((eq type 'dormant)
4711       (memq article gnus-newsgroup-dormant) )
4712      ((eq type 'expire)
4713       (memq article gnus-newsgroup-expirable))
4714      ((eq type 'reply)
4715       (memq article gnus-newsgroup-replied))
4716      ((eq type 'killed)
4717       (memq article gnus-newsgroup-killed))
4718      ((eq type 'bookmark)
4719       (assq article gnus-newsgroup-bookmarks))
4720      ((eq type 'score)
4721       (assq article gnus-newsgroup-scored))
4722      ((eq type 'save)
4723       (memq article gnus-newsgroup-saved))
4724      ((eq type 'cache)
4725       (memq article gnus-newsgroup-cached))
4726      ((eq type 'forward)
4727       (memq article gnus-newsgroup-forwarded))
4728      ((eq type 'seen)
4729       (not (memq article gnus-newsgroup-unseen)))
4730      ((eq type 'recent)
4731       (memq article gnus-newsgroup-recent))
4732      (t t))))
4733
4734 (defun gnus-articles-to-read (group &optional read-all)
4735   "Find out what articles the user wants to read."
4736   (let* ((articles
4737           ;; Select all articles if `read-all' is non-nil, or if there
4738           ;; are no unread articles.
4739           (if (or read-all
4740                   (and (zerop (length gnus-newsgroup-marked))
4741                        (zerop (length gnus-newsgroup-unreads)))
4742                   (eq gnus-newsgroup-display 'gnus-not-ignore))
4743               ;; We want to select the headers for all the articles in
4744               ;; the group, so we select either all the active
4745               ;; articles in the group, or (if that's nil), the
4746               ;; articles in the cache.
4747               (or
4748                (gnus-uncompress-range (gnus-active group))
4749                (gnus-cache-articles-in-group group))
4750             ;; Select only the "normal" subset of articles.
4751             (sort (append gnus-newsgroup-dormant gnus-newsgroup-marked
4752                           (copy-sequence gnus-newsgroup-unreads))
4753                   '<)))
4754          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
4755          (scored (length scored-list))
4756          (number (length articles))
4757          (marked (+ (length gnus-newsgroup-marked)
4758                     (length gnus-newsgroup-dormant)))
4759          (select
4760           (cond
4761            ((numberp read-all)
4762             read-all)
4763            (t
4764             (condition-case ()
4765                 (cond
4766                  ((and (or (<= scored marked) (= scored number))
4767                        (natnump gnus-large-newsgroup)
4768                        (> number gnus-large-newsgroup))
4769                   (let* ((cursor-in-echo-area nil)
4770                          (input
4771                           (read-from-minibuffer
4772                            (format
4773                             "How many articles from %s (max %d): "
4774                             (gnus-limit-string
4775                              (gnus-group-decoded-name gnus-newsgroup-name)
4776                              35)
4777                             number)
4778                            (cons (number-to-string gnus-large-newsgroup)
4779                                  0))))
4780                     (if (string-match "^[ \t]*$" input)
4781                         number
4782                       input)))
4783                  ((and (> scored marked) (< scored number)
4784                        (> (- scored number) 20))
4785                   (let ((input
4786                          (read-string
4787                           (format "%s %s (%d scored, %d total): "
4788                                   "How many articles from"
4789                                   (gnus-group-decoded-name group)
4790                                   scored number))))
4791                     (if (string-match "^[ \t]*$" input)
4792                         number input)))
4793                  (t number))
4794               (quit
4795                (message "Quit getting the articles to read")
4796                nil))))))
4797     (setq select (if (stringp select) (string-to-number select) select))
4798     (if (or (null select) (zerop select))
4799         select
4800       (if (and (not (zerop scored)) (<= (abs select) scored))
4801           (progn
4802             (setq articles (sort scored-list '<))
4803             (setq number (length articles)))
4804         (setq articles (copy-sequence articles)))
4805
4806       (when (< (abs select) number)
4807         (if (< select 0)
4808             ;; Select the N oldest articles.
4809             (setcdr (nthcdr (1- (abs select)) articles) nil)
4810           ;; Select the N most recent articles.
4811           (setq articles (nthcdr (- number select) articles))))
4812       (setq gnus-newsgroup-unselected
4813             (gnus-sorted-intersection
4814              gnus-newsgroup-unreads
4815              (gnus-sorted-complement gnus-newsgroup-unreads articles)))
4816       (when gnus-alter-articles-to-read-function
4817         (setq gnus-newsgroup-unreads
4818               (sort
4819                (funcall gnus-alter-articles-to-read-function
4820                         gnus-newsgroup-name gnus-newsgroup-unreads)
4821                '<)))
4822       articles)))
4823
4824 (defun gnus-killed-articles (killed articles)
4825   (let (out)
4826     (while articles
4827       (when (inline (gnus-member-of-range (car articles) killed))
4828         (push (car articles) out))
4829       (setq articles (cdr articles)))
4830     out))
4831
4832 (defun gnus-uncompress-marks (marks)
4833   "Uncompress the mark ranges in MARKS."
4834   (let ((uncompressed '(score bookmark))
4835         out)
4836     (while marks
4837       (if (memq (caar marks) uncompressed)
4838           (push (car marks) out)
4839         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
4840       (setq marks (cdr marks)))
4841     out))
4842
4843 (defun gnus-article-mark-to-type (mark)
4844   "Return the type of MARK."
4845   (or (cadr (assq mark gnus-article-special-mark-lists))
4846       'list))
4847
4848 (defun gnus-article-unpropagatable-p (mark)
4849   "Return whether MARK should be propagated to backend."
4850   (memq mark gnus-article-unpropagated-mark-lists))
4851
4852 (defun gnus-adjust-marked-articles (info)
4853   "Set all article lists and remove all marks that are no longer valid."
4854   (let* ((marked-lists (gnus-info-marks info))
4855          (active (gnus-active (gnus-info-group info)))
4856          (min (car active))
4857          (max (cdr active))
4858          (types gnus-article-mark-lists)
4859          marks var articles article mark mark-type)
4860
4861     (dolist (marks marked-lists)
4862       (setq mark (car marks)
4863             mark-type (gnus-article-mark-to-type mark)
4864             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
4865
4866       ;; We set the variable according to the type of the marks list,
4867       ;; and then adjust the marks to a subset of the active articles.
4868       (cond
4869        ;; Adjust "simple" lists.
4870        ((eq mark-type 'list)
4871         (set var (setq articles (gnus-uncompress-range (cdr marks))))
4872         (when (memq mark '(tick dormant expire reply save))
4873           (while articles
4874             (when (or (< (setq article (pop articles)) min) (> article max))
4875               (set var (delq article (symbol-value var)))))))
4876        ;; Adjust assocs.
4877        ((eq mark-type 'tuple)
4878         (set var (setq articles (cdr marks)))
4879         (when (not (listp (cdr (symbol-value var))))
4880           (set var (list (symbol-value var))))
4881         (when (not (listp (cdr articles)))
4882           (setq articles (list articles)))
4883         (while articles
4884           (when (or (not (consp (setq article (pop articles))))
4885                     (< (car article) min)
4886                     (> (car article) max))
4887             (set var (delq article (symbol-value var))))))
4888        ((eq mark-type 'range)
4889         (cond
4890          ((eq mark 'seen))))))))
4891
4892 (defun gnus-update-missing-marks (missing)
4893   "Go through the list of MISSING articles and remove them from the mark lists."
4894   (when missing
4895     (let (var m)
4896       ;; Go through all types.
4897       (dolist (elem gnus-article-mark-lists)
4898         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
4899           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
4900           (when (symbol-value var)
4901             ;; This list has articles.  So we delete all missing
4902             ;; articles from it.
4903             (setq m missing)
4904             (while m
4905               (set var (delq (pop m) (symbol-value var))))))))))
4906
4907 (defun gnus-update-marks ()
4908   "Enter the various lists of marked articles into the newsgroup info list."
4909   (let ((types gnus-article-mark-lists)
4910         (info (gnus-get-info gnus-newsgroup-name))
4911         type list newmarked symbol delta-marks)
4912     (when info
4913       ;; Add all marks lists to the list of marks lists.
4914       (while (setq type (pop types))
4915         (setq list (symbol-value
4916                     (setq symbol
4917                           (intern (format "gnus-newsgroup-%s" (car type))))))
4918
4919         (when list
4920           ;; Get rid of the entries of the articles that have the
4921           ;; default score.
4922           (when (and (eq (cdr type) 'score)
4923                      gnus-save-score
4924                      list)
4925             (let* ((arts list)
4926                    (prev (cons nil list))
4927                    (all prev))
4928               (while arts
4929                 (if (or (not (consp (car arts)))
4930                         (= (cdar arts) gnus-summary-default-score))
4931                     (setcdr prev (cdr arts))
4932                   (setq prev arts))
4933                 (setq arts (cdr arts)))
4934               (setq list (cdr all)))))
4935
4936         (when (eq (cdr type) 'seen)
4937           (setq list
4938                 (if list
4939                     (gnus-add-to-range list gnus-newsgroup-unseen)
4940                   (gnus-compress-sequence gnus-newsgroup-articles))))
4941
4942         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
4943           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
4944
4945         (when (and (gnus-check-backend-function
4946                     'request-set-mark gnus-newsgroup-name)
4947                    (not (gnus-article-unpropagatable-p (cdr type))))
4948           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
4949                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
4950                  (add (gnus-remove-from-range
4951                        (gnus-copy-sequence list) old)))
4952             (when add
4953               (push (list add 'add (list (cdr type))) delta-marks))
4954             (when del
4955               (push (list del 'del (list (cdr type))) delta-marks))))
4956
4957         (when list
4958           (push (cons (cdr type) list) newmarked)))
4959
4960       (when delta-marks
4961         (unless (gnus-check-group gnus-newsgroup-name)
4962           (error "Can't open server for %s" gnus-newsgroup-name))
4963         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
4964
4965       ;; Enter these new marks into the info of the group.
4966       (if (nthcdr 3 info)
4967           (setcar (nthcdr 3 info) newmarked)
4968         ;; Add the marks lists to the end of the info.
4969         (when newmarked
4970           (setcdr (nthcdr 2 info) (list newmarked))))
4971
4972       ;; Cut off the end of the info if there's nothing else there.
4973       (let ((i 5))
4974         (while (and (> i 2)
4975                     (not (nth i info)))
4976           (when (nthcdr (decf i) info)
4977             (setcdr (nthcdr i info) nil)))))))
4978
4979 (defun gnus-set-mode-line (where)
4980   "Set the mode line of the article or summary buffers.
4981 If WHERE is `summary', the summary mode line format will be used."
4982   ;; Is this mode line one we keep updated?
4983   (when (and (memq where gnus-updated-mode-lines)
4984              (symbol-value
4985               (intern (format "gnus-%s-mode-line-format-spec" where))))
4986     (let (mode-string)
4987       (save-excursion
4988         ;; We evaluate this in the summary buffer since these
4989         ;; variables are buffer-local to that buffer.
4990         (set-buffer gnus-summary-buffer)
4991         ;; We bind all these variables that are used in the `eval' form
4992         ;; below.
4993         (let* ((mformat (symbol-value
4994                          (intern
4995                           (format "gnus-%s-mode-line-format-spec" where))))
4996                (gnus-tmp-group-name (gnus-group-decoded-name
4997                                      gnus-newsgroup-name))
4998                (gnus-tmp-article-number (or gnus-current-article 0))
4999                (gnus-tmp-unread gnus-newsgroup-unreads)
5000                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5001                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5002                (gnus-tmp-unread-and-unselected
5003                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5004                             (zerop gnus-tmp-unselected))
5005                        "")
5006                       ((zerop gnus-tmp-unselected)
5007                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5008                       (t (format "{%d(+%d) more}"
5009                                  gnus-tmp-unread-and-unticked
5010                                  gnus-tmp-unselected))))
5011                (gnus-tmp-subject
5012                 (if (and gnus-current-headers
5013                          (vectorp gnus-current-headers))
5014                     (gnus-mode-string-quote
5015                      (mail-header-subject gnus-current-headers))
5016                   ""))
5017                bufname-length max-len
5018                gnus-tmp-header);; passed as argument to any user-format-funcs
5019           (setq mode-string (eval mformat))
5020           (setq bufname-length (if (string-match "%b" mode-string)
5021                                    (- (length
5022                                        (buffer-name
5023                                         (if (eq where 'summary)
5024                                             nil
5025                                           (get-buffer gnus-article-buffer))))
5026                                       2)
5027                                  0))
5028           (setq max-len (max 4 (if gnus-mode-non-string-length
5029                                    (- (window-width)
5030                                       gnus-mode-non-string-length
5031                                       bufname-length)
5032                                  (length mode-string))))
5033           ;; We might have to chop a bit of the string off...
5034           (when (> (length mode-string) max-len)
5035             (setq mode-string
5036                   (concat (gnus-truncate-string mode-string (- max-len 3))
5037                           "...")))
5038           ;; Pad the mode string a bit.
5039           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5040       ;; Update the mode line.
5041       (setq mode-line-buffer-identification
5042             (gnus-mode-line-buffer-identification (list mode-string)))
5043       (set-buffer-modified-p t))))
5044
5045 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5046   "Go through the HEADERS list and add all Xrefs to a hash table.
5047 The resulting hash table is returned, or nil if no Xrefs were found."
5048   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5049          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5050          (xref-hashtb (gnus-make-hashtable))
5051          start group entry number xrefs header)
5052     (while headers
5053       (setq header (pop headers))
5054       (when (and (setq xrefs (mail-header-xref header))
5055                  (not (memq (setq number (mail-header-number header))
5056                             unreads)))
5057         (setq start 0)
5058         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5059           (setq start (match-end 0))
5060           (setq group (if prefix
5061                           (concat prefix (substring xrefs (match-beginning 1)
5062                                                     (match-end 1)))
5063                         (substring xrefs (match-beginning 1) (match-end 1))))
5064           (setq number
5065                 (string-to-int (substring xrefs (match-beginning 2)
5066                                           (match-end 2))))
5067           (if (setq entry (gnus-gethash group xref-hashtb))
5068               (setcdr entry (cons number (cdr entry)))
5069             (gnus-sethash group (cons number nil) xref-hashtb)))))
5070     (and start xref-hashtb)))
5071
5072 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5073   "Look through all the headers and mark the Xrefs as read."
5074   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5075         name entry info xref-hashtb idlist method nth4)
5076     (save-excursion
5077       (set-buffer gnus-group-buffer)
5078       (when (setq xref-hashtb
5079                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5080         (mapatoms
5081          (lambda (group)
5082            (unless (string= from-newsgroup (setq name (symbol-name group)))
5083              (setq idlist (symbol-value group))
5084              ;; Dead groups are not updated.
5085              (and (prog1
5086                       (setq entry (gnus-gethash name gnus-newsrc-hashtb)
5087                             info (nth 2 entry))
5088                     (when (stringp (setq nth4 (gnus-info-method info)))
5089                       (setq nth4 (gnus-server-to-method nth4))))
5090                   ;; Only do the xrefs if the group has the same
5091                   ;; select method as the group we have just read.
5092                   (or (gnus-methods-equal-p
5093                        nth4 (gnus-find-method-for-group from-newsgroup))
5094                       virtual
5095                       (equal nth4 (setq method (gnus-find-method-for-group
5096                                                 from-newsgroup)))
5097                       (and (equal (car nth4) (car method))
5098                            (equal (nth 1 nth4) (nth 1 method))))
5099                   gnus-use-cross-reference
5100                   (or (not (eq gnus-use-cross-reference t))
5101                       virtual
5102                       ;; Only do cross-references on subscribed
5103                       ;; groups, if that is what is wanted.
5104                       (<= (gnus-info-level info) gnus-level-subscribed))
5105                   (gnus-group-make-articles-read name idlist))))
5106          xref-hashtb)))))
5107
5108 (defun gnus-compute-read-articles (group articles)
5109   (let* ((entry (gnus-gethash group gnus-newsrc-hashtb))
5110          (info (nth 2 entry))
5111          (active (gnus-active group))
5112          ninfo)
5113     (when entry
5114       ;; First peel off all invalid article numbers.
5115       (when active
5116         (let ((ids articles)
5117               id first)
5118           (while (setq id (pop ids))
5119             (when (and first (> id (cdr active)))
5120               ;; We'll end up in this situation in one particular
5121               ;; obscure situation.  If you re-scan a group and get
5122               ;; a new article that is cross-posted to a different
5123               ;; group that has not been re-scanned, you might get
5124               ;; crossposted article that has a higher number than
5125               ;; Gnus believes possible.  So we re-activate this
5126               ;; group as well.  This might mean doing the
5127               ;; crossposting thingy will *increase* the number
5128               ;; of articles in some groups.  Tsk, tsk.
5129               (setq active (or (gnus-activate-group group) active)))
5130             (when (or (> id (cdr active))
5131                       (< id (car active)))
5132               (setq articles (delq id articles))))))
5133       ;; If the read list is nil, we init it.
5134       (if (and active
5135                (null (gnus-info-read info))
5136                (> (car active) 1))
5137           (setq ninfo (cons 1 (1- (car active))))
5138         (setq ninfo (gnus-info-read info)))
5139       ;; Then we add the read articles to the range.
5140       (gnus-add-to-range
5141        ninfo (setq articles (sort articles '<))))))
5142
5143 (defun gnus-group-make-articles-read (group articles)
5144   "Update the info of GROUP to say that ARTICLES are read."
5145   (let* ((num 0)
5146          (entry (gnus-gethash group gnus-newsrc-hashtb))
5147          (info (nth 2 entry))
5148          (active (gnus-active group))
5149          range)
5150     (when entry
5151       (setq range (gnus-compute-read-articles group articles))
5152       (save-excursion
5153         (set-buffer gnus-group-buffer)
5154         (gnus-undo-register
5155           `(progn
5156              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5157              (gnus-info-set-read ',info ',(gnus-info-read info))
5158              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5159              (gnus-group-update-group ,group t))))
5160       ;; Add the read articles to the range.
5161       (gnus-info-set-read info range)
5162       (gnus-request-set-mark group (list (list range 'add '(read))))
5163       ;; Then we have to re-compute how many unread
5164       ;; articles there are in this group.
5165       (when active
5166         (cond
5167          ((not range)
5168           (setq num (- (1+ (cdr active)) (car active))))
5169          ((not (listp (cdr range)))
5170           (setq num (- (cdr active) (- (1+ (cdr range))
5171                                        (car range)))))
5172          (t
5173           (while range
5174             (if (numberp (car range))
5175                 (setq num (1+ num))
5176               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5177             (setq range (cdr range)))
5178           (setq num (- (cdr active) num))))
5179         ;; Update the number of unread articles.
5180         (setcar entry num)
5181         ;; Update the group buffer.
5182         (gnus-group-update-group group t)))))
5183
5184 (defvar gnus-newsgroup-none-id 0)
5185
5186 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5187   (let ((cur nntp-server-buffer)
5188         (dependencies
5189          (or dependencies
5190              (save-excursion (set-buffer gnus-summary-buffer)
5191                              gnus-newsgroup-dependencies)))
5192         headers id end ref
5193         (mail-parse-charset gnus-newsgroup-charset)
5194         (mail-parse-ignored-charsets
5195          (save-excursion (condition-case nil
5196                              (set-buffer gnus-summary-buffer)
5197                            (error))
5198                          gnus-newsgroup-ignored-charsets)))
5199     (save-excursion
5200       (set-buffer nntp-server-buffer)
5201       ;; Translate all TAB characters into SPACE characters.
5202       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5203       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5204       (gnus-run-hooks 'gnus-parse-headers-hook)
5205       (let ((case-fold-search t)
5206             in-reply-to header p lines chars ctype)
5207         (goto-char (point-min))
5208         ;; Search to the beginning of the next header.  Error messages
5209         ;; do not begin with 2 or 3.
5210         (while (re-search-forward "^[23][0-9]+ " nil t)
5211           (setq id nil
5212                 ref nil)
5213           ;; This implementation of this function, with nine
5214           ;; search-forwards instead of the one re-search-forward and
5215           ;; a case (which basically was the old function) is actually
5216           ;; about twice as fast, even though it looks messier.  You
5217           ;; can't have everything, I guess.  Speed and elegance
5218           ;; doesn't always go hand in hand.
5219           (setq
5220            header
5221            (make-full-mail-header
5222             ;; Number.
5223             (prog1
5224                 (read cur)
5225               (end-of-line)
5226               (setq p (point))
5227               (narrow-to-region (point)
5228                                 (or (and (search-forward "\n.\n" nil t)
5229                                          (- (point) 2))
5230                                     (point))))
5231             ;; Subject.
5232             (progn
5233               (goto-char p)
5234               (if (search-forward "\nsubject:" nil t)
5235                   (nnheader-header-value)
5236                 "(none)"))
5237             ;; From.
5238             (progn
5239               (goto-char p)
5240               (if (search-forward "\nfrom:" nil t)
5241                   (nnheader-header-value)
5242                 "(nobody)"))
5243             ;; Date.
5244             (progn
5245               (goto-char p)
5246               (if (search-forward "\ndate:" nil t)
5247                   (nnheader-header-value) ""))
5248             ;; Message-ID.
5249             (progn
5250               (goto-char p)
5251               (setq id (if (re-search-forward
5252                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5253                            ;; We do it this way to make sure the Message-ID
5254                            ;; is (somewhat) syntactically valid.
5255                            (buffer-substring (match-beginning 1)
5256                                              (match-end 1))
5257                          ;; If there was no message-id, we just fake one
5258                          ;; to make subsequent routines simpler.
5259                          (nnheader-generate-fake-message-id))))
5260             ;; References.
5261             (progn
5262               (goto-char p)
5263               (if (search-forward "\nreferences:" nil t)
5264                   (progn
5265                     (setq end (point))
5266                     (prog1
5267                         (nnheader-header-value)
5268                       (setq ref
5269                             (buffer-substring
5270                              (progn
5271                                ;; (end-of-line)
5272                                (search-backward ">" end t)
5273                                (1+ (point)))
5274                              (progn
5275                                (search-backward "<" end t)
5276                                (point))))))
5277                 ;; Get the references from the in-reply-to header if there
5278                 ;; were no references and the in-reply-to header looks
5279                 ;; promising.
5280                 (if (and (search-forward "\nin-reply-to:" nil t)
5281                          (setq in-reply-to (nnheader-header-value))
5282                          (string-match "<[^>]+>" in-reply-to))
5283                     (let (ref2)
5284                       (setq ref (substring in-reply-to (match-beginning 0)
5285                                            (match-end 0)))
5286                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5287                         (setq ref2 (substring in-reply-to (match-beginning 0)
5288                                               (match-end 0)))
5289                         (when (> (length ref2) (length ref))
5290                           (setq ref ref2)))
5291                       ref)
5292                   (setq ref nil))))
5293             ;; Chars.
5294             (progn
5295               (goto-char p)
5296               (if (search-forward "\nchars: " nil t)
5297                   (if (numberp (setq chars (ignore-errors (read cur))))
5298                       chars -1)
5299                 -1))
5300             ;; Lines.
5301             (progn
5302               (goto-char p)
5303               (if (search-forward "\nlines: " nil t)
5304                   (if (numberp (setq lines (ignore-errors (read cur))))
5305                       lines -1)
5306                 -1))
5307             ;; Xref.
5308             (progn
5309               (goto-char p)
5310               (and (search-forward "\nxref:" nil t)
5311                    (nnheader-header-value)))
5312             ;; Extra.
5313             (when gnus-extra-headers
5314               (let ((extra gnus-extra-headers)
5315                     out)
5316                 (while extra
5317                   (goto-char p)
5318                   (when (search-forward
5319                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5320                     (push (cons (car extra) (nnheader-header-value)) out))
5321                   (pop extra))
5322                 out))))
5323           (goto-char p)
5324           (if (and (search-forward "\ncontent-type: " nil t)
5325                    (setq ctype (nnheader-header-value)))
5326               (mime-entity-set-content-type-internal
5327                header (mime-parse-Content-Type ctype)))
5328           (when (equal id ref)
5329             (setq ref nil))
5330
5331           (when gnus-alter-header-function
5332             (funcall gnus-alter-header-function header)
5333             (setq id (mail-header-id header)
5334                   ref (gnus-parent-id (mail-header-references header))))
5335
5336           (when (setq header
5337                       (gnus-dependencies-add-header
5338                        header dependencies force-new))
5339             (push header headers))
5340           (goto-char (point-max))
5341           (widen))
5342         (nreverse headers)))))
5343
5344 ;; Goes through the xover lines and returns a list of vectors
5345 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5346                                                   force-new dependencies
5347                                                   group also-fetch-heads)
5348   "Parse the news overview data in the server buffer.
5349 Return a list of headers that match SEQUENCE (see
5350 `nntp-retrieve-headers')."
5351   ;; Get the Xref when the users reads the articles since most/some
5352   ;; NNTP servers do not include Xrefs when using XOVER.
5353   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5354   (let ((mail-parse-charset gnus-newsgroup-charset)
5355         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5356         (cur nntp-server-buffer)
5357         (dependencies (or dependencies gnus-newsgroup-dependencies))
5358         (allp (cond
5359                ((eq gnus-read-all-available-headers t)
5360                 t)
5361                ((stringp gnus-read-all-available-headers)
5362                 (string-match gnus-read-all-available-headers group))
5363                (t
5364                 nil)))
5365         number headers header)
5366     (save-excursion
5367       (set-buffer nntp-server-buffer)
5368       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5369       ;; Allow the user to mangle the headers before parsing them.
5370       (gnus-run-hooks 'gnus-parse-headers-hook)
5371       (goto-char (point-min))
5372       (while (not (eobp))
5373         (condition-case ()
5374             (while (and (or sequence allp)
5375                         (not (eobp)))
5376               (setq number (read cur))
5377               (when (not allp)
5378                 (while (and sequence
5379                             (< (car sequence) number))
5380                   (setq sequence (cdr sequence))))
5381               (when (and (or allp
5382                              (and sequence
5383                                   (eq number (car sequence))))
5384                          (progn
5385                            (setq sequence (cdr sequence))
5386                            (setq header (inline
5387                                           (gnus-nov-parse-line
5388                                            number dependencies force-new)))))
5389                 (push header headers))
5390               (forward-line 1))
5391           (error
5392            (gnus-error 4 "Strange nov line (%d)"
5393                        (count-lines (point-min) (point)))))
5394         (forward-line 1))
5395       ;; A common bug in inn is that if you have posted an article and
5396       ;; then retrieves the active file, it will answer correctly --
5397       ;; the new article is included.  However, a NOV entry for the
5398       ;; article may not have been generated yet, so this may fail.
5399       ;; We work around this problem by retrieving the last few
5400       ;; headers using HEAD.
5401       (if (or (not also-fetch-heads)
5402               (not sequence))
5403           ;; We (probably) got all the headers.
5404           (nreverse headers)
5405         (let ((gnus-nov-is-evil t))
5406           (nconc
5407            (nreverse headers)
5408            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5409              (gnus-get-newsgroup-headers))))))))
5410
5411 (defun gnus-article-get-xrefs ()
5412   "Fill in the Xref value in `gnus-current-headers', if necessary.
5413 This is meant to be called in `gnus-article-internal-prepare-hook'."
5414   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5415                                  gnus-current-headers)))
5416     (or (not gnus-use-cross-reference)
5417         (not headers)
5418         (and (mail-header-xref headers)
5419              (not (string= (mail-header-xref headers) "")))
5420         (let ((case-fold-search t)
5421               xref)
5422           (save-restriction
5423             (nnheader-narrow-to-headers)
5424             (goto-char (point-min))
5425             (when (or (and (not (eobp))
5426                            (eq (downcase (char-after)) ?x)
5427                            (looking-at "Xref:"))
5428                       (search-forward "\nXref:" nil t))
5429               (goto-char (1+ (match-end 0)))
5430               (setq xref (buffer-substring (point)
5431                                            (progn (end-of-line) (point))))
5432               (mail-header-set-xref headers xref)))))))
5433
5434 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5435   "Find article ID and insert the summary line for that article.
5436 OLD-HEADER can either be a header or a line number to insert
5437 the subject line on."
5438   (let* ((line (and (numberp old-header) old-header))
5439          (old-header (and (vectorp old-header) old-header))
5440          (header (cond ((and old-header use-old-header)
5441                         old-header)
5442                        ((and (numberp id)
5443                              (gnus-number-to-header id))
5444                         (gnus-number-to-header id))
5445                        (t
5446                         (gnus-read-header id))))
5447          (number (and (numberp id) id))
5448          d)
5449     (when header
5450       ;; Rebuild the thread that this article is part of and go to the
5451       ;; article we have fetched.
5452       (when (and (not gnus-show-threads)
5453                  old-header)
5454         (when (and number
5455                    (setq d (gnus-data-find (mail-header-number old-header))))
5456           (goto-char (gnus-data-pos d))
5457           (gnus-data-remove
5458            number
5459            (- (gnus-point-at-bol)
5460               (prog1
5461                   (1+ (gnus-point-at-eol))
5462                 (gnus-delete-line))))))
5463       (when old-header
5464         (mail-header-set-number header (mail-header-number old-header)))
5465       (setq gnus-newsgroup-sparse
5466             (delq (setq number (mail-header-number header))
5467                   gnus-newsgroup-sparse))
5468       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
5469       (push number gnus-newsgroup-limit)
5470       (gnus-rebuild-thread (mail-header-id header) line)
5471       (gnus-summary-goto-subject number nil t))
5472     (when (and (numberp number)
5473                (> number 0))
5474       ;; We have to update the boundaries even if we can't fetch the
5475       ;; article if ID is a number -- so that the next `P' or `N'
5476       ;; command will fetch the previous (or next) article even
5477       ;; if the one we tried to fetch this time has been canceled.
5478       (when (> number gnus-newsgroup-end)
5479         (setq gnus-newsgroup-end number))
5480       (when (< number gnus-newsgroup-begin)
5481         (setq gnus-newsgroup-begin number))
5482       (setq gnus-newsgroup-unselected
5483             (delq number gnus-newsgroup-unselected)))
5484     ;; Report back a success?
5485     (and header (mail-header-number header))))
5486
5487 ;;; Process/prefix in the summary buffer
5488
5489 (defun gnus-summary-work-articles (n)
5490   "Return a list of articles to be worked upon.
5491 The prefix argument, the list of process marked articles, and the
5492 current article will be taken into consideration."
5493   (save-excursion
5494     (set-buffer gnus-summary-buffer)
5495     (cond
5496      (n
5497       ;; A numerical prefix has been given.
5498       (setq n (prefix-numeric-value n))
5499       (let ((backward (< n 0))
5500             (n (abs (prefix-numeric-value n)))
5501             articles article)
5502         (save-excursion
5503           (while
5504               (and (> n 0)
5505                    (push (setq article (gnus-summary-article-number))
5506                          articles)
5507                    (if backward
5508                        (gnus-summary-find-prev nil article)
5509                      (gnus-summary-find-next nil article)))
5510             (decf n)))
5511         (nreverse articles)))
5512      ((and (gnus-region-active-p) (mark))
5513       (message "region active")
5514       ;; Work on the region between point and mark.
5515       (let ((max (max (point) (mark)))
5516             articles article)
5517         (save-excursion
5518           (goto-char (min (point) (mark)))
5519           (while
5520               (and
5521                (push (setq article (gnus-summary-article-number)) articles)
5522                (gnus-summary-find-next nil article)
5523                (< (point) max)))
5524           (nreverse articles))))
5525      (gnus-newsgroup-processable
5526       ;; There are process-marked articles present.
5527       ;; Save current state.
5528       (gnus-summary-save-process-mark)
5529       ;; Return the list.
5530       (reverse gnus-newsgroup-processable))
5531      (t
5532       ;; Just return the current article.
5533       (list (gnus-summary-article-number))))))
5534
5535 (defmacro gnus-summary-iterate (arg &rest forms)
5536   "Iterate over the process/prefixed articles and do FORMS.
5537 ARG is the interactive prefix given to the command.  FORMS will be
5538 executed with point over the summary line of the articles."
5539   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
5540     `(let ((,articles (gnus-summary-work-articles ,arg)))
5541        (while ,articles
5542          (gnus-summary-goto-subject (car ,articles))
5543          ,@forms
5544          (pop ,articles)))))
5545
5546 (put 'gnus-summary-iterate 'lisp-indent-function 1)
5547 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
5548
5549 (defun gnus-summary-save-process-mark ()
5550   "Push the current set of process marked articles on the stack."
5551   (interactive)
5552   (push (copy-sequence gnus-newsgroup-processable)
5553         gnus-newsgroup-process-stack))
5554
5555 (defun gnus-summary-kill-process-mark ()
5556   "Push the current set of process marked articles on the stack and unmark."
5557   (interactive)
5558   (gnus-summary-save-process-mark)
5559   (gnus-summary-unmark-all-processable))
5560
5561 (defun gnus-summary-yank-process-mark ()
5562   "Pop the last process mark state off the stack and restore it."
5563   (interactive)
5564   (unless gnus-newsgroup-process-stack
5565     (error "Empty mark stack"))
5566   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
5567
5568 (defun gnus-summary-process-mark-set (set)
5569   "Make SET into the current process marked articles."
5570   (gnus-summary-unmark-all-processable)
5571   (while set
5572     (gnus-summary-set-process-mark (pop set))))
5573
5574 ;;; Searching and stuff
5575
5576 (defun gnus-summary-search-group (&optional backward use-level)
5577   "Search for next unread newsgroup.
5578 If optional argument BACKWARD is non-nil, search backward instead."
5579   (save-excursion
5580     (set-buffer gnus-group-buffer)
5581     (when (gnus-group-search-forward
5582            backward nil (if use-level (gnus-group-group-level) nil))
5583       (gnus-group-group-name))))
5584
5585 (defun gnus-summary-best-group (&optional exclude-group)
5586   "Find the name of the best unread group.
5587 If EXCLUDE-GROUP, do not go to this group."
5588   (save-excursion
5589     (set-buffer gnus-group-buffer)
5590     (save-excursion
5591       (gnus-group-best-unread-group exclude-group))))
5592
5593 (defun gnus-summary-find-next (&optional unread article backward undownloaded)
5594   (if backward (gnus-summary-find-prev)
5595     (let* ((dummy (gnus-summary-article-intangible-p))
5596            (article (or article (gnus-summary-article-number)))
5597            (arts (gnus-data-find-list article))
5598            result)
5599       (when (and (not dummy)
5600                  (or (not gnus-summary-check-current)
5601                      (not unread)
5602                      (not (gnus-data-unread-p (car arts)))))
5603         (setq arts (cdr arts)))
5604       (when (setq result
5605                   (if unread
5606                       (progn
5607                         (while arts
5608                           (when (or (and undownloaded
5609                                          (eq gnus-undownloaded-mark
5610                                              (gnus-data-mark (car arts))))
5611                                     (gnus-data-unread-p (car arts)))
5612                             (setq result (car arts)
5613                                   arts nil))
5614                           (setq arts (cdr arts)))
5615                         result)
5616                     (car arts)))
5617         (goto-char (gnus-data-pos result))
5618         (gnus-data-number result)))))
5619
5620 (defun gnus-summary-find-prev (&optional unread article)
5621   (let* ((eobp (eobp))
5622          (article (or article (gnus-summary-article-number)))
5623          (arts (gnus-data-find-list article (gnus-data-list 'rev)))
5624          result)
5625     (when (and (not eobp)
5626                (or (not gnus-summary-check-current)
5627                    (not unread)
5628                    (not (gnus-data-unread-p (car arts)))))
5629       (setq arts (cdr arts)))
5630     (when (setq result
5631                 (if unread
5632                     (progn
5633                       (while arts
5634                         (when (gnus-data-unread-p (car arts))
5635                           (setq result (car arts)
5636                                 arts nil))
5637                         (setq arts (cdr arts)))
5638                       result)
5639                   (car arts)))
5640       (goto-char (gnus-data-pos result))
5641       (gnus-data-number result))))
5642
5643 (defun gnus-summary-find-subject (subject &optional unread backward article)
5644   (let* ((simp-subject (gnus-simplify-subject-fully subject))
5645          (article (or article (gnus-summary-article-number)))
5646          (articles (gnus-data-list backward))
5647          (arts (gnus-data-find-list article articles))
5648          result)
5649     (when (or (not gnus-summary-check-current)
5650               (not unread)
5651               (not (gnus-data-unread-p (car arts))))
5652       (setq arts (cdr arts)))
5653     (while arts
5654       (and (or (not unread)
5655                (gnus-data-unread-p (car arts)))
5656            (vectorp (gnus-data-header (car arts)))
5657            (gnus-subject-equal
5658             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
5659            (setq result (car arts)
5660                  arts nil))
5661       (setq arts (cdr arts)))
5662     (and result
5663          (goto-char (gnus-data-pos result))
5664          (gnus-data-number result))))
5665
5666 (defun gnus-summary-search-forward (&optional unread subject backward)
5667   "Search forward for an article.
5668 If UNREAD, look for unread articles.  If SUBJECT, look for
5669 articles with that subject.  If BACKWARD, search backward instead."
5670   (cond (subject (gnus-summary-find-subject subject unread backward))
5671         (backward (gnus-summary-find-prev unread))
5672         (t (gnus-summary-find-next unread))))
5673
5674 (defun gnus-recenter (&optional n)
5675   "Center point in window and redisplay frame.
5676 Also do horizontal recentering."
5677   (interactive "P")
5678   (when (and gnus-auto-center-summary
5679              (not (eq gnus-auto-center-summary 'vertical)))
5680     (gnus-horizontal-recenter))
5681   (recenter n))
5682
5683 (defun gnus-summary-recenter ()
5684   "Center point in the summary window.
5685 If `gnus-auto-center-summary' is nil, or the article buffer isn't
5686 displayed, no centering will be performed."
5687   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
5688   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
5689   (interactive)
5690   (let* ((top (cond ((< (window-height) 4) 0)
5691                     ((< (window-height) 7) 1)
5692                     (t (if (numberp gnus-auto-center-summary)
5693                            gnus-auto-center-summary
5694                          2))))
5695          (height (1- (window-height)))
5696          (bottom (save-excursion (goto-char (point-max))
5697                                  (forward-line (- height))
5698                                  (point)))
5699          (window (get-buffer-window (current-buffer))))
5700     ;; The user has to want it.
5701     (when gnus-auto-center-summary
5702       (when (get-buffer-window gnus-article-buffer)
5703         ;; Only do recentering when the article buffer is displayed,
5704         ;; Set the window start to either `bottom', which is the biggest
5705         ;; possible valid number, or the second line from the top,
5706         ;; whichever is the least.
5707         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
5708           (if (> bottom top-pos)
5709               ;; Keep the second line from the top visible
5710               (set-window-start window top-pos t)
5711             ;; Try to keep the bottom line visible; if it's partially
5712             ;; obscured, either scroll one more line to make it fully
5713             ;; visible, or revert to using TOP-POS.
5714             (save-excursion
5715               (goto-char (point-max))
5716               (forward-line -1)
5717               (let ((last-line-start (point)))
5718                 (goto-char bottom)
5719                 (set-window-start window (point) t)
5720                 (when (not (pos-visible-in-window-p last-line-start window))
5721                   (forward-line 1)
5722                   (set-window-start window (min (point) top-pos) t)))))))
5723       ;; Do horizontal recentering while we're at it.
5724       (when (and (get-buffer-window (current-buffer) t)
5725                  (not (eq gnus-auto-center-summary 'vertical)))
5726         (let ((selected (selected-window)))
5727           (select-window (get-buffer-window (current-buffer) t))
5728           (gnus-summary-position-point)
5729           (gnus-horizontal-recenter)
5730           (select-window selected))))))
5731
5732 (defun gnus-summary-jump-to-group (newsgroup)
5733   "Move point to NEWSGROUP in group mode buffer."
5734   ;; Keep update point of group mode buffer if visible.
5735   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
5736       (save-window-excursion
5737         ;; Take care of tree window mode.
5738         (when (get-buffer-window gnus-group-buffer)
5739           (pop-to-buffer gnus-group-buffer))
5740         (gnus-group-jump-to-group newsgroup))
5741     (save-excursion
5742       ;; Take care of tree window mode.
5743       (if (get-buffer-window gnus-group-buffer)
5744           (pop-to-buffer gnus-group-buffer)
5745         (set-buffer gnus-group-buffer))
5746       (gnus-group-jump-to-group newsgroup))))
5747
5748 ;; This function returns a list of article numbers based on the
5749 ;; difference between the ranges of read articles in this group and
5750 ;; the range of active articles.
5751 (defun gnus-list-of-unread-articles (group)
5752   (let* ((read (gnus-info-read (gnus-get-info group)))
5753          (active (or (gnus-active group) (gnus-activate-group group)))
5754          (last (cdr active))
5755          first nlast unread)
5756     ;; If none are read, then all are unread.
5757     (if (not read)
5758         (setq first (car active))
5759       ;; If the range of read articles is a single range, then the
5760       ;; first unread article is the article after the last read
5761       ;; article.  Sounds logical, doesn't it?
5762       (if (and (not (listp (cdr read)))
5763                (or (< (car read) (car active))
5764                    (progn (setq read (list read))
5765                           nil)))
5766           (setq first (max (car active) (1+ (cdr read))))
5767         ;; `read' is a list of ranges.
5768         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
5769                                   (caar read)))
5770                   1)
5771           (setq first (car active)))
5772         (while read
5773           (when first
5774             (while (< first nlast)
5775               (push first unread)
5776               (setq first (1+ first))))
5777           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
5778           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
5779           (setq read (cdr read)))))
5780     ;; And add the last unread articles.
5781     (while (<= first last)
5782       (push first unread)
5783       (setq first (1+ first)))
5784     ;; Return the list of unread articles.
5785     (delq 0 (nreverse unread))))
5786
5787 (defun gnus-list-of-read-articles (group)
5788   "Return a list of unread, unticked and non-dormant articles."
5789   (let* ((info (gnus-get-info group))
5790          (marked (gnus-info-marks info))
5791          (active (gnus-active group)))
5792     (and info active
5793          (gnus-set-difference
5794           (gnus-sorted-complement
5795            (gnus-uncompress-range active)
5796            (gnus-list-of-unread-articles group))
5797           (append
5798            (gnus-uncompress-range (cdr (assq 'dormant marked)))
5799            (gnus-uncompress-range (cdr (assq 'tick marked))))))))
5800
5801 ;; Various summary commands
5802
5803 (defun gnus-summary-select-article-buffer ()
5804   "Reconfigure windows to show article buffer."
5805   (interactive)
5806   (if (not (gnus-buffer-live-p gnus-article-buffer))
5807       (error "There is no article buffer for this summary buffer")
5808     (gnus-configure-windows 'article)
5809     (select-window (get-buffer-window gnus-article-buffer))))
5810
5811 (defun gnus-summary-universal-argument (arg)
5812   "Perform any operation on all articles that are process/prefixed."
5813   (interactive "P")
5814   (let ((articles (gnus-summary-work-articles arg))
5815         func article)
5816     (if (eq
5817          (setq
5818           func
5819           (key-binding
5820            (read-key-sequence
5821             (substitute-command-keys
5822              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
5823          'undefined)
5824         (gnus-error 1 "Undefined key")
5825       (save-excursion
5826         (while articles
5827           (gnus-summary-goto-subject (setq article (pop articles)))
5828           (let (gnus-newsgroup-processable)
5829             (command-execute func))
5830           (gnus-summary-remove-process-mark article)))))
5831   (gnus-summary-position-point))
5832
5833 (defun gnus-summary-toggle-truncation (&optional arg)
5834   "Toggle truncation of summary lines.
5835 With arg, turn line truncation on iff arg is positive."
5836   (interactive "P")
5837   (setq truncate-lines
5838         (if (null arg) (not truncate-lines)
5839           (> (prefix-numeric-value arg) 0)))
5840   (redraw-display))
5841
5842 (defun gnus-summary-reselect-current-group (&optional all rescan)
5843   "Exit and then reselect the current newsgroup.
5844 The prefix argument ALL means to select all articles."
5845   (interactive "P")
5846   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
5847     (error "Ephemeral groups can't be reselected"))
5848   (let ((current-subject (gnus-summary-article-number))
5849         (group gnus-newsgroup-name))
5850     (setq gnus-newsgroup-begin nil)
5851     (gnus-summary-exit)
5852     ;; We have to adjust the point of group mode buffer because
5853     ;; point was moved to the next unread newsgroup by exiting.
5854     (gnus-summary-jump-to-group group)
5855     (when rescan
5856       (save-excursion
5857         (save-window-excursion
5858           ;; Don't show group contents.
5859           (set-window-start (selected-window) (point-max))
5860           (gnus-group-get-new-news-this-group 1))))
5861     (gnus-group-read-group all t)
5862     (gnus-summary-goto-subject current-subject nil t)))
5863
5864 (defun gnus-summary-rescan-group (&optional all)
5865   "Exit the newsgroup, ask for new articles, and select the newsgroup."
5866   (interactive "P")
5867   (gnus-summary-reselect-current-group all t))
5868
5869 (defun gnus-summary-update-info (&optional non-destructive)
5870   (save-excursion
5871     (let ((group gnus-newsgroup-name))
5872       (when group
5873         (when gnus-newsgroup-kill-headers
5874           (setq gnus-newsgroup-killed
5875                 (gnus-compress-sequence
5876                  (nconc
5877                   (gnus-set-sorted-intersection
5878                    (gnus-uncompress-range gnus-newsgroup-killed)
5879                    (setq gnus-newsgroup-unselected
5880                          (sort gnus-newsgroup-unselected '<)))
5881                   (setq gnus-newsgroup-unreads
5882                         (sort gnus-newsgroup-unreads '<)))
5883                  t)))
5884         (unless (listp (cdr gnus-newsgroup-killed))
5885           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
5886         (let ((headers gnus-newsgroup-headers))
5887           ;; Set the new ranges of read articles.
5888           (save-excursion
5889             (set-buffer gnus-group-buffer)
5890             (gnus-undo-force-boundary))
5891           (gnus-update-read-articles
5892            group (append gnus-newsgroup-unreads gnus-newsgroup-unselected))
5893           ;; Set the current article marks.
5894           (let ((gnus-newsgroup-scored
5895                  (if (and (not gnus-save-score)
5896                           (not non-destructive))
5897                      nil
5898                    gnus-newsgroup-scored)))
5899             (save-excursion
5900               (gnus-update-marks)))
5901           ;; Do the cross-ref thing.
5902           (when gnus-use-cross-reference
5903             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
5904           ;; Do not switch windows but change the buffer to work.
5905           (set-buffer gnus-group-buffer)
5906           (unless (gnus-ephemeral-group-p group)
5907             (gnus-group-update-group group)))))))
5908
5909 (defun gnus-summary-save-newsrc (&optional force)
5910   "Save the current number of read/marked articles in the dribble buffer.
5911 The dribble buffer will then be saved.
5912 If FORCE (the prefix), also save the .newsrc file(s)."
5913   (interactive "P")
5914   (gnus-summary-update-info t)
5915   (if force
5916       (gnus-save-newsrc-file)
5917     (gnus-dribble-save)))
5918
5919 (defun gnus-summary-exit (&optional temporary)
5920   "Exit reading current newsgroup, and then return to group selection mode.
5921 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
5922   (interactive)
5923   (gnus-set-global-variables)
5924   (gnus-kill-save-kill-buffer)
5925   (gnus-async-halt-prefetch)
5926   (let* ((group gnus-newsgroup-name)
5927          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
5928          (mode major-mode)
5929          (group-point nil)
5930          (buf (current-buffer)))
5931     (unless quit-config
5932       ;; Do adaptive scoring, and possibly save score files.
5933       (when gnus-newsgroup-adaptive
5934         (gnus-score-adaptive))
5935       (when gnus-use-scoring
5936         (gnus-score-save)))
5937     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
5938     ;; If we have several article buffers, we kill them at exit.
5939     (unless gnus-single-article-buffer
5940       (gnus-kill-buffer gnus-original-article-buffer)
5941       (setq gnus-article-current nil))
5942     (when gnus-use-cache
5943       (gnus-cache-possibly-remove-articles)
5944       (gnus-cache-save-buffers))
5945     (gnus-async-prefetch-remove-group group)
5946     (when gnus-suppress-duplicates
5947       (gnus-dup-enter-articles))
5948     (when gnus-use-trees
5949       (gnus-tree-close group))
5950     (when gnus-use-cache
5951       (gnus-cache-write-active))
5952     ;; Remove entries for this group.
5953     (nnmail-purge-split-history (gnus-group-real-name group))
5954     ;; Make all changes in this group permanent.
5955     (unless quit-config
5956       (gnus-run-hooks 'gnus-exit-group-hook)
5957       (gnus-summary-update-info))
5958     (gnus-close-group group)
5959     ;; Make sure where we were, and go to next newsgroup.
5960     (set-buffer gnus-group-buffer)
5961     (unless quit-config
5962       (gnus-group-jump-to-group group))
5963     (gnus-run-hooks 'gnus-summary-exit-hook)
5964     (unless (or quit-config
5965                 ;; If this group has disappeared from the summary
5966                 ;; buffer, don't skip forwards.
5967                 (not (string= group (gnus-group-group-name))))
5968       (gnus-group-next-unread-group 1))
5969     (setq group-point (point))
5970     (if temporary
5971         nil                             ;Nothing to do.
5972       ;; If we have several article buffers, we kill them at exit.
5973       (unless gnus-single-article-buffer
5974         (gnus-kill-buffer gnus-article-buffer)
5975         (gnus-kill-buffer gnus-original-article-buffer)
5976         (setq gnus-article-current nil))
5977       (set-buffer buf)
5978       (if (not gnus-kill-summary-on-exit)
5979           (progn
5980             (gnus-deaden-summary)
5981             (setq mode nil))
5982         ;; We set all buffer-local variables to nil.  It is unclear why
5983         ;; this is needed, but if we don't, buffer-local variables are
5984         ;; not garbage-collected, it seems.  This would the lead to en
5985         ;; ever-growing Emacs.
5986         (gnus-summary-clear-local-variables)
5987         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5988           (gnus-summary-clear-local-variables))
5989         (when (get-buffer gnus-article-buffer)
5990           (bury-buffer gnus-article-buffer))
5991         ;; We clear the global counterparts of the buffer-local
5992         ;; variables as well, just to be on the safe side.
5993         (set-buffer gnus-group-buffer)
5994         (gnus-summary-clear-local-variables)
5995         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
5996           (gnus-summary-clear-local-variables)))
5997       (setq gnus-current-select-method gnus-select-method)
5998       (pop-to-buffer gnus-group-buffer)
5999       (if (not quit-config)
6000           (progn
6001             (goto-char group-point)
6002             (gnus-configure-windows 'group 'force)
6003             (unless (pos-visible-in-window-p)
6004               (forward-line (/ (static-if (featurep 'xemacs)
6005                                    (window-displayed-height)
6006                                  (1- (window-height)))
6007                                -2))
6008               (set-window-start (selected-window) (point))
6009               (goto-char group-point)))
6010         (gnus-handle-ephemeral-exit quit-config))
6011       ;; Return to group mode buffer.
6012       (when (eq mode 'gnus-summary-mode)
6013         (gnus-kill-buffer buf))
6014       ;; Clear the current group name.
6015       (unless quit-config
6016         (setq gnus-newsgroup-name nil)))))
6017
6018 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6019 (defun gnus-summary-exit-no-update (&optional no-questions)
6020   "Quit reading current newsgroup without updating read article info."
6021   (interactive)
6022   (let* ((group gnus-newsgroup-name)
6023          (quit-config (gnus-group-quit-config group)))
6024     (when (or no-questions
6025               gnus-expert-user
6026               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6027       (gnus-async-halt-prefetch)
6028       (mapcar 'funcall
6029               (delq 'gnus-summary-expire-articles
6030                     (copy-sequence gnus-summary-prepare-exit-hook)))
6031       ;; If we have several article buffers, we kill them at exit.
6032       (unless gnus-single-article-buffer
6033         (gnus-kill-buffer gnus-article-buffer)
6034         (gnus-kill-buffer gnus-original-article-buffer)
6035         (setq gnus-article-current nil))
6036       (if (not gnus-kill-summary-on-exit)
6037           (gnus-deaden-summary)
6038         (gnus-close-group group)
6039         (gnus-summary-clear-local-variables)
6040         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6041           (gnus-summary-clear-local-variables))
6042         (set-buffer gnus-group-buffer)
6043         (gnus-summary-clear-local-variables)
6044         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6045           (gnus-summary-clear-local-variables))
6046         (when (get-buffer gnus-summary-buffer)
6047           (kill-buffer gnus-summary-buffer)))
6048       (unless gnus-single-article-buffer
6049         (setq gnus-article-current nil))
6050       (when gnus-use-trees
6051         (gnus-tree-close group))
6052       (gnus-async-prefetch-remove-group group)
6053       (when (get-buffer gnus-article-buffer)
6054         (bury-buffer gnus-article-buffer))
6055       ;; Return to the group buffer.
6056       (gnus-configure-windows 'group 'force)
6057       ;; Clear the current group name.
6058       (setq gnus-newsgroup-name nil)
6059       (when (equal (gnus-group-group-name) group)
6060         (gnus-group-next-unread-group 1))
6061       (when quit-config
6062         (gnus-handle-ephemeral-exit quit-config)))))
6063
6064 (defun gnus-handle-ephemeral-exit (quit-config)
6065   "Handle movement when leaving an ephemeral group.
6066 The state which existed when entering the ephemeral is reset."
6067   (if (not (buffer-name (car quit-config)))
6068       (gnus-configure-windows 'group 'force)
6069     (set-buffer (car quit-config))
6070     (cond ((eq major-mode 'gnus-summary-mode)
6071            (gnus-set-global-variables))
6072           ((eq major-mode 'gnus-article-mode)
6073            (save-excursion
6074              ;; The `gnus-summary-buffer' variable may point
6075              ;; to the old summary buffer when using a single
6076              ;; article buffer.
6077              (unless (gnus-buffer-live-p gnus-summary-buffer)
6078                (set-buffer gnus-group-buffer))
6079              (set-buffer gnus-summary-buffer)
6080              (gnus-set-global-variables))))
6081     (if (or (eq (cdr quit-config) 'article)
6082             (eq (cdr quit-config) 'pick))
6083         (progn
6084           ;; The current article may be from the ephemeral group
6085           ;; thus it is best that we reload this article
6086           (gnus-summary-show-article)
6087           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6088               (gnus-configure-windows 'pick 'force)
6089             (gnus-configure-windows (cdr quit-config) 'force)))
6090       (gnus-configure-windows (cdr quit-config) 'force))
6091     (when (eq major-mode 'gnus-summary-mode)
6092       (gnus-summary-next-subject 1 nil t)
6093       (gnus-summary-recenter)
6094       (gnus-summary-position-point))))
6095
6096 (defun gnus-summary-preview-mime-message ()
6097   "MIME decode and play this message."
6098   (interactive)
6099   (let ((gnus-break-pages nil)
6100         (gnus-show-mime t))
6101     (gnus-summary-select-article gnus-show-all-headers t))
6102   (select-window (get-buffer-window gnus-article-buffer)))
6103
6104 ;;; Dead summaries.
6105
6106 (defvar gnus-dead-summary-mode-map nil)
6107
6108 (unless gnus-dead-summary-mode-map
6109   (setq gnus-dead-summary-mode-map (make-keymap))
6110   (suppress-keymap gnus-dead-summary-mode-map)
6111   (substitute-key-definition
6112    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6113   (let ((keys '("\C-d" "\r" "\177" [delete])))
6114     (while keys
6115       (define-key gnus-dead-summary-mode-map
6116         (pop keys) 'gnus-summary-wake-up-the-dead))))
6117
6118 (defvar gnus-dead-summary-mode nil
6119   "Minor mode for Gnus summary buffers.")
6120
6121 (defun gnus-dead-summary-mode (&optional arg)
6122   "Minor mode for Gnus summary buffers."
6123   (interactive "P")
6124   (when (eq major-mode 'gnus-summary-mode)
6125     (make-local-variable 'gnus-dead-summary-mode)
6126     (setq gnus-dead-summary-mode
6127           (if (null arg) (not gnus-dead-summary-mode)
6128             (> (prefix-numeric-value arg) 0)))
6129     (when gnus-dead-summary-mode
6130       (gnus-add-minor-mode
6131        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6132
6133 (defun gnus-deaden-summary ()
6134   "Make the current summary buffer into a dead summary buffer."
6135   ;; Kill any previous dead summary buffer.
6136   (when (and gnus-dead-summary
6137              (buffer-name gnus-dead-summary))
6138     (save-excursion
6139       (set-buffer gnus-dead-summary)
6140       (when gnus-dead-summary-mode
6141         (kill-buffer (current-buffer)))))
6142   ;; Make this the current dead summary.
6143   (setq gnus-dead-summary (current-buffer))
6144   (gnus-dead-summary-mode 1)
6145   (let ((name (buffer-name)))
6146     (when (string-match "Summary" name)
6147       (rename-buffer
6148        (concat (substring name 0 (match-beginning 0)) "Dead "
6149                (substring name (match-beginning 0)))
6150        t)
6151       (bury-buffer))))
6152
6153 (defun gnus-kill-or-deaden-summary (buffer)
6154   "Kill or deaden the summary BUFFER."
6155   (save-excursion
6156     (when (and (buffer-name buffer)
6157                (not gnus-single-article-buffer))
6158       (save-excursion
6159         (set-buffer buffer)
6160         (gnus-kill-buffer gnus-article-buffer)
6161         (gnus-kill-buffer gnus-original-article-buffer)))
6162     (cond (gnus-kill-summary-on-exit
6163            (when (and gnus-use-trees
6164                       (gnus-buffer-exists-p buffer))
6165              (save-excursion
6166                (set-buffer buffer)
6167                (gnus-tree-close gnus-newsgroup-name)))
6168            (gnus-kill-buffer buffer))
6169           ((gnus-buffer-exists-p buffer)
6170            (save-excursion
6171              (set-buffer buffer)
6172              (gnus-deaden-summary))))))
6173
6174 (defun gnus-summary-wake-up-the-dead (&rest args)
6175   "Wake up the dead summary buffer."
6176   (interactive)
6177   (gnus-dead-summary-mode -1)
6178   (let ((name (buffer-name)))
6179     (when (string-match "Dead " name)
6180       (rename-buffer
6181        (concat (substring name 0 (match-beginning 0))
6182                (substring name (match-end 0)))
6183        t)))
6184   (gnus-message 3 "This dead summary is now alive again"))
6185
6186 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6187 (defun gnus-summary-fetch-faq (&optional faq-dir)
6188   "Fetch the FAQ for the current group.
6189 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6190 in."
6191   (interactive
6192    (list
6193     (when current-prefix-arg
6194       (completing-read
6195        "Faq dir: " (and (listp gnus-group-faq-directory)
6196                         (mapcar (lambda (file) (list file))
6197                                 gnus-group-faq-directory))))))
6198   (let (gnus-faq-buffer)
6199     (when (setq gnus-faq-buffer
6200                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6201       (gnus-configure-windows 'summary-faq))))
6202
6203 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6204 (defun gnus-summary-describe-group (&optional force)
6205   "Describe the current newsgroup."
6206   (interactive "P")
6207   (gnus-group-describe-group force gnus-newsgroup-name))
6208
6209 (defun gnus-summary-describe-briefly ()
6210   "Describe summary mode commands briefly."
6211   (interactive)
6212   (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")))
6213
6214 ;; Walking around group mode buffer from summary mode.
6215
6216 (defun gnus-summary-next-group (&optional no-article target-group backward)
6217   "Exit current newsgroup and then select next unread newsgroup.
6218 If prefix argument NO-ARTICLE is non-nil, no article is selected
6219 initially.  If NEXT-GROUP, go to this group.  If BACKWARD, go to
6220 previous group instead."
6221   (interactive "P")
6222   ;; Stop pre-fetching.
6223   (gnus-async-halt-prefetch)
6224   (let ((current-group gnus-newsgroup-name)
6225         (current-buffer (current-buffer))
6226         entered)
6227     ;; First we semi-exit this group to update Xrefs and all variables.
6228     ;; We can't do a real exit, because the window conf must remain
6229     ;; the same in case the user is prompted for info, and we don't
6230     ;; want the window conf to change before that...
6231     (gnus-summary-exit t)
6232     (while (not entered)
6233       ;; Then we find what group we are supposed to enter.
6234       (set-buffer gnus-group-buffer)
6235       (gnus-group-jump-to-group current-group)
6236       (setq target-group
6237             (or target-group
6238                 (if (eq gnus-keep-same-level 'best)
6239                     (gnus-summary-best-group gnus-newsgroup-name)
6240                   (gnus-summary-search-group backward gnus-keep-same-level))))
6241       (if (not target-group)
6242           ;; There are no further groups, so we return to the group
6243           ;; buffer.
6244           (progn
6245             (gnus-message 5 "Returning to the group buffer")
6246             (setq entered t)
6247             (when (gnus-buffer-live-p current-buffer)
6248               (set-buffer current-buffer)
6249               (gnus-summary-exit))
6250             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6251         ;; We try to enter the target group.
6252         (gnus-group-jump-to-group target-group)
6253         (let ((unreads (gnus-group-group-unread)))
6254           (if (and (or (eq t unreads)
6255                        (and unreads (not (zerop unreads))))
6256                    (gnus-summary-read-group
6257                     target-group nil no-article
6258                     (and (buffer-name current-buffer) current-buffer)
6259                     nil backward))
6260               (setq entered t)
6261             (setq current-group target-group
6262                   target-group nil)))))))
6263
6264 (defun gnus-summary-prev-group (&optional no-article)
6265   "Exit current newsgroup and then select previous unread newsgroup.
6266 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6267   (interactive "P")
6268   (gnus-summary-next-group no-article nil t))
6269
6270 ;; Walking around summary lines.
6271
6272 (defun gnus-summary-first-subject (&optional unread undownloaded)
6273   "Go to the first unread subject.
6274 If UNREAD is non-nil, go to the first unread article.
6275 Returns the article selected or nil if there are no unread articles."
6276   (interactive "P")
6277   (prog1
6278       (cond
6279        ;; Empty summary.
6280        ((null gnus-newsgroup-data)
6281         (gnus-message 3 "No articles in the group")
6282         nil)
6283        ;; Pick the first article.
6284        ((not unread)
6285         (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6286         (gnus-data-number (car gnus-newsgroup-data)))
6287        ;; No unread articles.
6288        ((null gnus-newsgroup-unreads)
6289         (gnus-message 3 "No more unread articles")
6290         nil)
6291        ;; Find the first unread article.
6292        (t
6293         (let ((data gnus-newsgroup-data))
6294           (while (and data
6295                       (and (not (and undownloaded
6296                                      (eq gnus-undownloaded-mark
6297                                          (gnus-data-mark (car data)))))
6298                            (not (gnus-data-unread-p (car data)))))
6299             (setq data (cdr data)))
6300           (when data
6301             (goto-char (gnus-data-pos (car data)))
6302             (gnus-data-number (car data))))))
6303     (gnus-summary-position-point)))
6304
6305 (defun gnus-summary-next-subject (n &optional unread dont-display)
6306   "Go to next N'th summary line.
6307 If N is negative, go to the previous N'th subject line.
6308 If UNREAD is non-nil, only unread articles are selected.
6309 The difference between N and the actual number of steps taken is
6310 returned."
6311   (interactive "p")
6312   (let ((backward (< n 0))
6313         (n (abs n)))
6314     (while (and (> n 0)
6315                 (if backward
6316                     (gnus-summary-find-prev unread)
6317                   (gnus-summary-find-next unread)))
6318       (unless (zerop (setq n (1- n)))
6319         (gnus-summary-show-thread)))
6320     (when (/= 0 n)
6321       (gnus-message 7 "No more%s articles"
6322                     (if unread " unread" "")))
6323     (unless dont-display
6324       (gnus-summary-recenter)
6325       (gnus-summary-position-point))
6326     n))
6327
6328 (defun gnus-summary-next-unread-subject (n)
6329   "Go to next N'th unread summary line."
6330   (interactive "p")
6331   (gnus-summary-next-subject n t))
6332
6333 (defun gnus-summary-prev-subject (n &optional unread)
6334   "Go to previous N'th summary line.
6335 If optional argument UNREAD is non-nil, only unread article is selected."
6336   (interactive "p")
6337   (gnus-summary-next-subject (- n) unread))
6338
6339 (defun gnus-summary-prev-unread-subject (n)
6340   "Go to previous N'th unread summary line."
6341   (interactive "p")
6342   (gnus-summary-next-subject (- n) t))
6343
6344 (defun gnus-summary-goto-subject (article &optional force silent)
6345   "Go the subject line of ARTICLE.
6346 If FORCE, also allow jumping to articles not currently shown."
6347   (interactive "nArticle number: ")
6348   (let ((b (point))
6349         (data (gnus-data-find article)))
6350     ;; We read in the article if we have to.
6351     (and (not data)
6352          force
6353          (gnus-summary-insert-subject
6354           article
6355           (if (or (numberp force) (vectorp force)) force)
6356           t)
6357          (setq data (gnus-data-find article)))
6358     (goto-char b)
6359     (if (not data)
6360         (progn
6361           (unless silent
6362             (gnus-message 3 "Can't find article %d" article))
6363           nil)
6364       (let ((pt (gnus-data-pos data)))
6365         (goto-char pt)
6366         (gnus-summary-set-article-display-arrow pt))
6367       (gnus-summary-position-point)
6368       article)))
6369
6370 ;; Walking around summary lines with displaying articles.
6371
6372 (defun gnus-summary-expand-window (&optional arg)
6373   "Make the summary buffer take up the entire Emacs frame.
6374 Given a prefix, will force an `article' buffer configuration."
6375   (interactive "P")
6376   (if arg
6377       (gnus-configure-windows 'article 'force)
6378     (gnus-configure-windows 'summary 'force)))
6379
6380 (defun gnus-summary-display-article (article &optional all-header)
6381   "Display ARTICLE in article buffer."
6382   (when (gnus-buffer-live-p gnus-article-buffer)
6383     (with-current-buffer gnus-article-buffer
6384       (set-buffer-multibyte t)))
6385   (gnus-set-global-variables)
6386   (when (gnus-buffer-live-p gnus-article-buffer)
6387     (with-current-buffer gnus-article-buffer
6388       (setq gnus-article-charset gnus-newsgroup-charset)
6389       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)))
6390   (if (null article)
6391       nil
6392     (prog1
6393         (if gnus-summary-display-article-function
6394             (funcall gnus-summary-display-article-function article all-header)
6395           (gnus-article-prepare article all-header))
6396       (with-current-buffer gnus-article-buffer
6397         (set (make-local-variable 'gnus-summary-search-article-matched-data)
6398              nil))
6399       (gnus-run-hooks 'gnus-select-article-hook)
6400       (when (and gnus-current-article
6401                  (not (zerop gnus-current-article)))
6402         (gnus-summary-goto-subject gnus-current-article))
6403       (gnus-summary-recenter)
6404       (when (and gnus-use-trees gnus-show-threads)
6405         (gnus-possibly-generate-tree article)
6406         (gnus-highlight-selected-tree article))
6407       ;; Successfully display article.
6408       (gnus-article-set-window-start
6409        (cdr (assq article gnus-newsgroup-bookmarks))))))
6410
6411 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
6412   "Select the current article.
6413 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
6414 non-nil, the article will be re-fetched even if it already present in
6415 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
6416 be displayed."
6417   ;; Make sure we are in the summary buffer to work around bbdb bug.
6418   (unless (eq major-mode 'gnus-summary-mode)
6419     (set-buffer gnus-summary-buffer))
6420   (let ((article (or article (gnus-summary-article-number)))
6421         (all-headers (not (not all-headers))) ;Must be T or NIL.
6422         gnus-summary-display-article-function)
6423     (and (not pseudo)
6424          (gnus-summary-article-pseudo-p article)
6425          (error "This is a pseudo-article"))
6426     (save-excursion
6427       (set-buffer gnus-summary-buffer)
6428       (if (or (and gnus-single-article-buffer
6429                    (or (null gnus-current-article)
6430                        (null gnus-article-current)
6431                        (null (get-buffer gnus-article-buffer))
6432                        (not (eq article (cdr gnus-article-current)))
6433                        (not (equal (car gnus-article-current)
6434                                    gnus-newsgroup-name))))
6435               (and (not gnus-single-article-buffer)
6436                    (or (null gnus-current-article)
6437                        (not (eq gnus-current-article article))))
6438               force)
6439           ;; The requested article is different from the current article.
6440           (progn
6441             (gnus-summary-display-article article all-headers)
6442             (when (or all-headers gnus-show-all-headers)
6443               (gnus-article-show-all-headers))
6444             (gnus-article-set-window-start
6445              (cdr (assq article gnus-newsgroup-bookmarks)))
6446             article)
6447         (when (or all-headers gnus-show-all-headers)
6448           (gnus-article-show-all-headers))
6449         'old))))
6450
6451 (defun gnus-summary-force-verify-and-decrypt ()
6452   (interactive)
6453   (let ((mm-verify-option 'known)
6454         (mm-decrypt-option 'known))
6455     (gnus-summary-select-article nil 'force)))
6456
6457 (defun gnus-summary-set-current-mark (&optional current-mark)
6458   "Obsolete function."
6459   nil)
6460
6461 (defun gnus-summary-next-article (&optional unread subject backward push)
6462   "Select the next article.
6463 If UNREAD, only unread articles are selected.
6464 If SUBJECT, only articles with SUBJECT are selected.
6465 If BACKWARD, the previous article is selected instead of the next."
6466   (interactive "P")
6467   (cond
6468    ;; Is there such an article?
6469    ((and (gnus-summary-search-forward unread subject backward)
6470          (or (gnus-summary-display-article (gnus-summary-article-number))
6471              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
6472     (gnus-summary-position-point))
6473    ;; If not, we try the first unread, if that is wanted.
6474    ((and subject
6475          gnus-auto-select-same
6476          (gnus-summary-first-unread-article))
6477     (gnus-summary-position-point)
6478     (gnus-message 6 "Wrapped"))
6479    ;; Try to get next/previous article not displayed in this group.
6480    ((and gnus-auto-extend-newsgroup
6481          (not unread) (not subject))
6482     (gnus-summary-goto-article
6483      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
6484      nil (count-lines (point-min) (point))))
6485    ;; Go to next/previous group.
6486    (t
6487     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
6488       (gnus-summary-jump-to-group gnus-newsgroup-name))
6489     (let ((cmd last-command-char)
6490           (point
6491            (save-excursion
6492              (set-buffer gnus-group-buffer)
6493              (point)))
6494           (group
6495            (if (eq gnus-keep-same-level 'best)
6496                (gnus-summary-best-group gnus-newsgroup-name)
6497              (gnus-summary-search-group backward gnus-keep-same-level))))
6498       ;; For some reason, the group window gets selected.  We change
6499       ;; it back.
6500       (select-window (get-buffer-window (current-buffer)))
6501       ;; Select next unread newsgroup automagically.
6502       (cond
6503        ((or (not gnus-auto-select-next)
6504             (not cmd))
6505         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
6506        ((or (eq gnus-auto-select-next 'quietly)
6507             (and (eq gnus-auto-select-next 'slightly-quietly)
6508                  push)
6509             (and (eq gnus-auto-select-next 'almost-quietly)
6510                  (gnus-summary-last-article-p)))
6511         ;; Select quietly.
6512         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
6513             (gnus-summary-exit)
6514           (gnus-message 7 "No more%s articles (%s)..."
6515                         (if unread " unread" "")
6516                         (if group (concat "selecting " group)
6517                           "exiting"))
6518           (gnus-summary-next-group nil group backward)))
6519        (t
6520         (when (gnus-key-press-event-p last-input-event)
6521           (gnus-summary-walk-group-buffer
6522            gnus-newsgroup-name cmd unread backward point))))))))
6523
6524 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
6525   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
6526                       (?\C-p (gnus-group-prev-unread-group 1))))
6527         (cursor-in-echo-area t)
6528         keve key group ended)
6529     (save-excursion
6530       (set-buffer gnus-group-buffer)
6531       (goto-char start)
6532       (setq group
6533             (if (eq gnus-keep-same-level 'best)
6534                 (gnus-summary-best-group gnus-newsgroup-name)
6535               (gnus-summary-search-group backward gnus-keep-same-level))))
6536     (while (not ended)
6537       (gnus-message
6538        5 "No more%s articles%s" (if unread " unread" "")
6539        (if (and group
6540                 (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
6541            (format " (Type %s for %s [%s])"
6542                    (single-key-description cmd) group
6543                    (car (gnus-gethash group gnus-newsrc-hashtb)))
6544          (format " (Type %s to exit %s)"
6545                  (single-key-description cmd)
6546                  gnus-newsgroup-name)))
6547       ;; Confirm auto selection.
6548       (setq key (car (setq keve (gnus-read-event-char))))
6549       (setq ended t)
6550       (cond
6551        ((assq key keystrokes)
6552         (let ((obuf (current-buffer)))
6553           (switch-to-buffer gnus-group-buffer)
6554           (when group
6555             (gnus-group-jump-to-group group))
6556           (eval (cadr (assq key keystrokes)))
6557           (setq group (gnus-group-group-name))
6558           (switch-to-buffer obuf))
6559         (setq ended nil))
6560        ((equal key cmd)
6561         (if (or (not group)
6562                 (gnus-ephemeral-group-p gnus-newsgroup-name))
6563             (gnus-summary-exit)
6564           (gnus-summary-next-group nil group backward)))
6565        (t
6566         (push (cdr keve) unread-command-events))))))
6567
6568 (defun gnus-summary-next-unread-article ()
6569   "Select unread article after current one."
6570   (interactive)
6571   (gnus-summary-next-article
6572    (or (not (eq gnus-summary-goto-unread 'never))
6573        (gnus-summary-last-article-p (gnus-summary-article-number)))
6574    (and gnus-auto-select-same
6575         (gnus-summary-article-subject))))
6576
6577 (defun gnus-summary-prev-article (&optional unread subject)
6578   "Select the article after the current one.
6579 If UNREAD is non-nil, only unread articles are selected."
6580   (interactive "P")
6581   (gnus-summary-next-article unread subject t))
6582
6583 (defun gnus-summary-prev-unread-article ()
6584   "Select unread article before current one."
6585   (interactive)
6586   (gnus-summary-prev-article
6587    (or (not (eq gnus-summary-goto-unread 'never))
6588        (gnus-summary-first-article-p (gnus-summary-article-number)))
6589    (and gnus-auto-select-same
6590         (gnus-summary-article-subject))))
6591
6592 (defun gnus-summary-next-page (&optional lines circular)
6593   "Show next page of the selected article.
6594 If at the end of the current article, select the next article.
6595 LINES says how many lines should be scrolled up.
6596
6597 If CIRCULAR is non-nil, go to the start of the article instead of
6598 selecting the next article when reaching the end of the current
6599 article."
6600   (interactive "P")
6601   (setq gnus-summary-buffer (current-buffer))
6602   (gnus-set-global-variables)
6603   (let ((article (gnus-summary-article-number))
6604         (article-window (get-buffer-window gnus-article-buffer t))
6605         endp)
6606     ;; If the buffer is empty, we have no article.
6607     (unless article
6608       (error "No article to select"))
6609     (gnus-configure-windows 'article)
6610     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
6611         (if (and (eq gnus-summary-goto-unread 'never)
6612                  (not (gnus-summary-last-article-p article)))
6613             (gnus-summary-next-article)
6614           (gnus-summary-next-unread-article))
6615       (if (or (null gnus-current-article)
6616               (null gnus-article-current)
6617               (/= article (cdr gnus-article-current))
6618               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6619           ;; Selected subject is different from current article's.
6620           (gnus-summary-display-article article)
6621         (when article-window
6622           (gnus-eval-in-buffer-window gnus-article-buffer
6623             (setq endp (gnus-article-next-page lines)))
6624           (when endp
6625             (cond (circular
6626                    (gnus-summary-beginning-of-article))
6627                   (lines
6628                    (gnus-message 3 "End of message"))
6629                   ((null lines)
6630                    (if (and (eq gnus-summary-goto-unread 'never)
6631                             (not (gnus-summary-last-article-p article)))
6632                        (gnus-summary-next-article)
6633                      (gnus-summary-next-unread-article))))))))
6634     (gnus-summary-recenter)
6635     (gnus-summary-position-point)))
6636
6637 (defun gnus-summary-prev-page (&optional lines move)
6638   "Show previous page of selected article.
6639 Argument LINES specifies lines to be scrolled down.
6640 If MOVE, move to the previous unread article if point is at
6641 the beginning of the buffer."
6642   (interactive "P")
6643   (let ((article (gnus-summary-article-number))
6644         (article-window (get-buffer-window gnus-article-buffer t))
6645         endp)
6646     (gnus-configure-windows 'article)
6647     (if (or (null gnus-current-article)
6648             (null gnus-article-current)
6649             (/= article (cdr gnus-article-current))
6650             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
6651         ;; Selected subject is different from current article's.
6652         (gnus-summary-display-article article)
6653       (gnus-summary-recenter)
6654       (when article-window
6655         (gnus-eval-in-buffer-window gnus-article-buffer
6656           (setq endp (gnus-article-prev-page lines)))
6657         (when (and move endp)
6658           (cond (lines
6659                  (gnus-message 3 "Beginning of message"))
6660                 ((null lines)
6661                  (if (and (eq gnus-summary-goto-unread 'never)
6662                           (not (gnus-summary-first-article-p article)))
6663                      (gnus-summary-prev-article)
6664                    (gnus-summary-prev-unread-article))))))))
6665   (gnus-summary-position-point))
6666
6667 (defun gnus-summary-prev-page-or-article (&optional lines)
6668   "Show previous page of selected article.
6669 Argument LINES specifies lines to be scrolled down.
6670 If at the beginning of the article, go to the next article."
6671   (interactive "P")
6672   (gnus-summary-prev-page lines t))
6673
6674 (defun gnus-summary-scroll-up (lines)
6675   "Scroll up (or down) one line current article.
6676 Argument LINES specifies lines to be scrolled up (or down if negative)."
6677   (interactive "p")
6678   (gnus-configure-windows 'article)
6679   (gnus-summary-show-thread)
6680   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
6681     (gnus-eval-in-buffer-window gnus-article-buffer
6682       (cond ((> lines 0)
6683              (when (gnus-article-next-page lines)
6684                (gnus-message 3 "End of message")))
6685             ((< lines 0)
6686              (gnus-article-prev-page (- lines))))))
6687   (gnus-summary-recenter)
6688   (gnus-summary-position-point))
6689
6690 (defun gnus-summary-scroll-down (lines)
6691   "Scroll down (or up) one line current article.
6692 Argument LINES specifies lines to be scrolled down (or up if negative)."
6693   (interactive "p")
6694   (gnus-summary-scroll-up (- lines)))
6695
6696 (defun gnus-summary-next-same-subject ()
6697   "Select next article which has the same subject as current one."
6698   (interactive)
6699   (gnus-summary-next-article nil (gnus-summary-article-subject)))
6700
6701 (defun gnus-summary-prev-same-subject ()
6702   "Select previous article which has the same subject as current one."
6703   (interactive)
6704   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
6705
6706 (defun gnus-summary-next-unread-same-subject ()
6707   "Select next unread article which has the same subject as current one."
6708   (interactive)
6709   (gnus-summary-next-article t (gnus-summary-article-subject)))
6710
6711 (defun gnus-summary-prev-unread-same-subject ()
6712   "Select previous unread article which has the same subject as current one."
6713   (interactive)
6714   (gnus-summary-prev-article t (gnus-summary-article-subject)))
6715
6716 (defun gnus-summary-first-unread-article ()
6717   "Select the first unread article.
6718 Return nil if there are no unread articles."
6719   (interactive)
6720   (prog1
6721       (when (gnus-summary-first-subject t)
6722         (gnus-summary-show-thread)
6723         (gnus-summary-first-subject t)
6724         (gnus-summary-display-article (gnus-summary-article-number)))
6725     (gnus-summary-position-point)))
6726
6727 (defun gnus-summary-first-unread-subject ()
6728   "Place the point on the subject line of the first unread article.
6729 Return nil if there are no unread articles."
6730   (interactive)
6731   (prog1
6732       (when (gnus-summary-first-subject t)
6733         (gnus-summary-show-thread)
6734         (gnus-summary-first-subject t))
6735     (gnus-summary-position-point)))
6736
6737 (defun gnus-summary-first-article ()
6738   "Select the first article.
6739 Return nil if there are no articles."
6740   (interactive)
6741   (prog1
6742       (when (gnus-summary-first-subject)
6743         (gnus-summary-show-thread)
6744         (gnus-summary-first-subject)
6745         (gnus-summary-display-article (gnus-summary-article-number)))
6746     (gnus-summary-position-point)))
6747
6748 (defun gnus-summary-best-unread-article ()
6749   "Select the unread article with the highest score."
6750   (interactive)
6751   (let ((best -1000000)
6752         (data gnus-newsgroup-data)
6753         article score)
6754     (while data
6755       (and (gnus-data-unread-p (car data))
6756            (> (setq score
6757                     (gnus-summary-article-score (gnus-data-number (car data))))
6758               best)
6759            (setq best score
6760                  article (gnus-data-number (car data))))
6761       (setq data (cdr data)))
6762     (prog1
6763         (if article
6764             (gnus-summary-goto-article article)
6765           (error "No unread articles"))
6766       (gnus-summary-position-point))))
6767
6768 (defun gnus-summary-last-subject ()
6769   "Go to the last displayed subject line in the group."
6770   (let ((article (gnus-data-number (car (gnus-data-list t)))))
6771     (when article
6772       (gnus-summary-goto-subject article))))
6773
6774 (defun gnus-summary-goto-article (article &optional all-headers force)
6775   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
6776 If ALL-HEADERS is non-nil, no header lines are hidden.
6777 If FORCE, go to the article even if it isn't displayed.  If FORCE
6778 is a number, it is the line the article is to be displayed on."
6779   (interactive
6780    (list
6781     (completing-read
6782      "Article number or Message-ID: "
6783      (mapcar (lambda (number) (list (int-to-string number)))
6784              gnus-newsgroup-limit))
6785     current-prefix-arg
6786     t))
6787   (prog1
6788       (if (and (stringp article)
6789                (string-match "@" article))
6790           (gnus-summary-refer-article article)
6791         (when (stringp article)
6792           (setq article (string-to-number article)))
6793         (if (gnus-summary-goto-subject article force)
6794             (gnus-summary-display-article article all-headers)
6795           (gnus-message 4 "Couldn't go to article %s" article) nil))
6796     (gnus-summary-position-point)))
6797
6798 (defun gnus-summary-goto-last-article ()
6799   "Go to the previously read article."
6800   (interactive)
6801   (prog1
6802       (when gnus-last-article
6803         (gnus-summary-goto-article gnus-last-article nil t))
6804     (gnus-summary-position-point)))
6805
6806 (defun gnus-summary-pop-article (number)
6807   "Pop one article off the history and go to the previous.
6808 NUMBER articles will be popped off."
6809   (interactive "p")
6810   (let (to)
6811     (setq gnus-newsgroup-history
6812           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
6813     (if to
6814         (gnus-summary-goto-article (car to) nil t)
6815       (error "Article history empty")))
6816   (gnus-summary-position-point))
6817
6818 ;; Summary commands and functions for limiting the summary buffer.
6819
6820 (defun gnus-summary-limit-to-articles (n)
6821   "Limit the summary buffer to the next N articles.
6822 If not given a prefix, use the process marked articles instead."
6823   (interactive "P")
6824   (prog1
6825       (let ((articles (gnus-summary-work-articles n)))
6826         (setq gnus-newsgroup-processable nil)
6827         (gnus-summary-limit articles))
6828     (gnus-summary-position-point)))
6829
6830 (defun gnus-summary-pop-limit (&optional total)
6831   "Restore the previous limit.
6832 If given a prefix, remove all limits."
6833   (interactive "P")
6834   (when total
6835     (setq gnus-newsgroup-limits
6836           (list (mapcar (lambda (h) (mail-header-number h))
6837                         gnus-newsgroup-headers))))
6838   (unless gnus-newsgroup-limits
6839     (error "No limit to pop"))
6840   (prog1
6841       (gnus-summary-limit nil 'pop)
6842     (gnus-summary-position-point)))
6843
6844 (defun gnus-summary-limit-to-subject (subject &optional header)
6845   "Limit the summary buffer to articles that have subjects that match a regexp."
6846   (interactive "sLimit to subject (regexp): ")
6847   (unless header
6848     (setq header "subject"))
6849   (when (not (equal "" subject))
6850     (prog1
6851         (let ((articles (gnus-summary-find-matching
6852                          (or header "subject") subject 'all)))
6853           (unless articles
6854             (error "Found no matches for \"%s\"" subject))
6855           (gnus-summary-limit articles))
6856       (gnus-summary-position-point))))
6857
6858 (defun gnus-summary-limit-to-author (from)
6859   "Limit the summary buffer to articles that have authors that match a regexp."
6860   (interactive "sLimit to author (regexp): ")
6861   (gnus-summary-limit-to-subject from "from"))
6862
6863 (defun gnus-summary-limit-to-age (age &optional younger-p)
6864   "Limit the summary buffer to articles that are older than (or equal) AGE days.
6865 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
6866 articles that are younger than AGE days."
6867   (interactive
6868    (let ((younger current-prefix-arg)
6869          (days-got nil)
6870          days)
6871      (while (not days-got)
6872        (setq days (if younger
6873                       (read-string "Limit to articles within (in days): ")
6874                     (read-string "Limit to articles older than (in days): ")))
6875        (when (> (length days) 0)
6876          (setq days (read days)))
6877        (if (numberp days)
6878            (setq days-got t)
6879          (message "Please enter a number.")
6880          (sleep-for 1)))
6881      (list days younger)))
6882   (prog1
6883       (let ((data gnus-newsgroup-data)
6884             (cutoff (days-to-time age))
6885             articles d date is-younger)
6886         (while (setq d (pop data))
6887           (when (and (vectorp (gnus-data-header d))
6888                      (setq date (mail-header-date (gnus-data-header d))))
6889             (setq is-younger (time-less-p
6890                               (time-since (condition-case ()
6891                                               (date-to-time date)
6892                                             (error '(0 0))))
6893                               cutoff))
6894             (when (if younger-p
6895                       is-younger
6896                     (not is-younger))
6897               (push (gnus-data-number d) articles))))
6898         (gnus-summary-limit (nreverse articles)))
6899     (gnus-summary-position-point)))
6900
6901 (defun gnus-summary-limit-to-extra (header regexp)
6902   "Limit the summary buffer to articles that match an 'extra' header."
6903   (interactive
6904    (let ((header
6905           (intern
6906            (gnus-completing-read
6907             (symbol-name (car gnus-extra-headers))
6908             "Limit extra header:"
6909             (mapcar (lambda (x)
6910                       (cons (symbol-name x) x))
6911                     gnus-extra-headers)
6912             nil
6913             t))))
6914      (list header
6915            (read-string (format "Limit to header %s (regexp): " header)))))
6916   (when (not (equal "" regexp))
6917     (prog1
6918         (let ((articles (gnus-summary-find-matching
6919                          (cons 'extra header) regexp 'all)))
6920           (unless articles
6921             (error "Found no matches for \"%s\"" regexp))
6922           (gnus-summary-limit articles))
6923       (gnus-summary-position-point))))
6924
6925 (defun gnus-summary-limit-to-display-predicate ()
6926   "Limit the summary buffer to the predicated in the `display' group parameter."
6927   (interactive)
6928   (unless gnus-newsgroup-display
6929     (error "There is no `diplay' group parameter"))
6930   (let (articles)
6931     (dolist (number gnus-newsgroup-articles)
6932       (when (funcall gnus-newsgroup-display)
6933         (push number articles)))
6934     (gnus-summary-limit articles))
6935   (gnus-summary-position-point))
6936
6937 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6938 (make-obsolete
6939  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
6940
6941 (defun gnus-summary-limit-to-unread (&optional all)
6942   "Limit the summary buffer to articles that are not marked as read.
6943 If ALL is non-nil, limit strictly to unread articles."
6944   (interactive "P")
6945   (if all
6946       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
6947     (gnus-summary-limit-to-marks
6948      ;; Concat all the marks that say that an article is read and have
6949      ;; those removed.
6950      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
6951            gnus-killed-mark gnus-kill-file-mark
6952            gnus-low-score-mark gnus-expirable-mark
6953            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
6954            gnus-duplicate-mark gnus-souped-mark)
6955      'reverse)))
6956
6957 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
6958 (make-obsolete 'gnus-summary-delete-marked-with
6959                'gnus-summary-limit-exlude-marks)
6960
6961 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
6962   "Exclude articles that are marked with MARKS (e.g. \"DK\").
6963 If REVERSE, limit the summary buffer to articles that are marked
6964 with MARKS.  MARKS can either be a string of marks or a list of marks.
6965 Returns how many articles were removed."
6966   (interactive "sMarks: ")
6967   (gnus-summary-limit-to-marks marks t))
6968
6969 (defun gnus-summary-limit-to-marks (marks &optional reverse)
6970   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
6971 If REVERSE (the prefix), limit the summary buffer to articles that are
6972 not marked with MARKS.  MARKS can either be a string of marks or a
6973 list of marks.
6974 Returns how many articles were removed."
6975   (interactive "sMarks: \nP")
6976   (prog1
6977       (let ((data gnus-newsgroup-data)
6978             (marks (if (listp marks) marks
6979                      (append marks nil))) ; Transform to list.
6980             articles)
6981         (while data
6982           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
6983                   (memq (gnus-data-mark (car data)) marks))
6984             (push (gnus-data-number (car data)) articles))
6985           (setq data (cdr data)))
6986         (gnus-summary-limit articles))
6987     (gnus-summary-position-point)))
6988
6989 (defun gnus-summary-limit-to-score (&optional score)
6990   "Limit to articles with score at or above SCORE."
6991   (interactive "P")
6992   (setq score (if score
6993                   (prefix-numeric-value score)
6994                 (or gnus-summary-default-score 0)))
6995   (let ((data gnus-newsgroup-data)
6996         articles)
6997     (while data
6998       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
6999                 score)
7000         (push (gnus-data-number (car data)) articles))
7001       (setq data (cdr data)))
7002     (prog1
7003         (gnus-summary-limit articles)
7004       (gnus-summary-position-point))))
7005
7006 (defun gnus-summary-limit-include-thread (id)
7007   "Display all the hidden articles that is in the thread with ID in it.
7008 When called interactively, ID is the Message-ID of the current
7009 article."
7010   (interactive (list (mail-header-id (gnus-summary-article-header))))
7011   (let ((articles (gnus-articles-in-thread
7012                    (gnus-id-to-thread (gnus-root-id id)))))
7013     (prog1
7014         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7015       (gnus-summary-limit-include-matching-articles
7016        "subject"
7017        (regexp-quote (gnus-simplify-subject-re
7018                       (mail-header-subject (gnus-id-to-header id)))))
7019       (gnus-summary-position-point))))
7020
7021 (defun gnus-summary-limit-include-matching-articles (header regexp)
7022   "Display all the hidden articles that have HEADERs that match REGEXP."
7023   (interactive (list (read-string "Match on header: ")
7024                      (read-string "Regexp: ")))
7025   (let ((articles (gnus-find-matching-articles header regexp)))
7026     (prog1
7027         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7028       (gnus-summary-position-point))))
7029
7030 (defun gnus-summary-limit-include-dormant ()
7031   "Display all the hidden articles that are marked as dormant.
7032 Note that this command only works on a subset of the articles currently
7033 fetched for this group."
7034   (interactive)
7035   (unless gnus-newsgroup-dormant
7036     (error "There are no dormant articles in this group"))
7037   (prog1
7038       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7039     (gnus-summary-position-point)))
7040
7041 (defun gnus-summary-limit-exclude-dormant ()
7042   "Hide all dormant articles."
7043   (interactive)
7044   (prog1
7045       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7046     (gnus-summary-position-point)))
7047
7048 (defun gnus-summary-limit-exclude-childless-dormant ()
7049   "Hide all dormant articles that have no children."
7050   (interactive)
7051   (let ((data (gnus-data-list t))
7052         articles d children)
7053     ;; Find all articles that are either not dormant or have
7054     ;; children.
7055     (while (setq d (pop data))
7056       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7057                 (and (setq children
7058                            (gnus-article-children (gnus-data-number d)))
7059                      (let (found)
7060                        (while children
7061                          (when (memq (car children) articles)
7062                            (setq children nil
7063                                  found t))
7064                          (pop children))
7065                        found)))
7066         (push (gnus-data-number d) articles)))
7067     ;; Do the limiting.
7068     (prog1
7069         (gnus-summary-limit articles)
7070       (gnus-summary-position-point))))
7071
7072 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7073   "Mark all unread excluded articles as read.
7074 If ALL, mark even excluded ticked and dormants as read."
7075   (interactive "P")
7076   (let ((articles (gnus-sorted-complement
7077                    (sort
7078                     (mapcar (lambda (h) (mail-header-number h))
7079                             gnus-newsgroup-headers)
7080                     '<)
7081                    (sort gnus-newsgroup-limit '<)))
7082         article)
7083     (setq gnus-newsgroup-unreads
7084           (gnus-intersection gnus-newsgroup-unreads gnus-newsgroup-limit))
7085     (if all
7086         (setq gnus-newsgroup-dormant nil
7087               gnus-newsgroup-marked nil
7088               gnus-newsgroup-reads
7089               (nconc
7090                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7091                gnus-newsgroup-reads))
7092       (while (setq article (pop articles))
7093         (unless (or (memq article gnus-newsgroup-dormant)
7094                     (memq article gnus-newsgroup-marked))
7095           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7096
7097 (defun gnus-summary-limit (articles &optional pop)
7098   (if pop
7099       ;; We pop the previous limit off the stack and use that.
7100       (setq articles (car gnus-newsgroup-limits)
7101             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7102     ;; We use the new limit, so we push the old limit on the stack.
7103     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7104   ;; Set the limit.
7105   (setq gnus-newsgroup-limit articles)
7106   (let ((total (length gnus-newsgroup-data))
7107         (data (gnus-data-find-list (gnus-summary-article-number)))
7108         (gnus-summary-mark-below nil)   ; Inhibit this.
7109         found)
7110     ;; This will do all the work of generating the new summary buffer
7111     ;; according to the new limit.
7112     (gnus-summary-prepare)
7113     ;; Hide any threads, possibly.
7114     (and gnus-show-threads
7115          gnus-thread-hide-subtree
7116          (gnus-summary-hide-all-threads))
7117     ;; Try to return to the article you were at, or one in the
7118     ;; neighborhood.
7119     (when data
7120       ;; We try to find some article after the current one.
7121       (while data
7122         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7123           (setq data nil
7124                 found t))
7125         (setq data (cdr data))))
7126     (unless found
7127       ;; If there is no data, that means that we were after the last
7128       ;; article.  The same goes when we can't find any articles
7129       ;; after the current one.
7130       (goto-char (point-max))
7131       (gnus-summary-find-prev))
7132     (gnus-set-mode-line 'summary)
7133     ;; We return how many articles were removed from the summary
7134     ;; buffer as a result of the new limit.
7135     (- total (length gnus-newsgroup-data))))
7136
7137 (defsubst gnus-invisible-cut-children (threads)
7138   (let ((num 0))
7139     (while threads
7140       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7141         (incf num))
7142       (pop threads))
7143     (< num 2)))
7144
7145 (defsubst gnus-cut-thread (thread)
7146   "Go forwards in the thread until we find an article that we want to display."
7147   (when (or (eq gnus-fetch-old-headers 'some)
7148             (eq gnus-fetch-old-headers 'invisible)
7149             (numberp gnus-fetch-old-headers)
7150             (eq gnus-build-sparse-threads 'some)
7151             (eq gnus-build-sparse-threads 'more))
7152     ;; Deal with old-fetched headers and sparse threads.
7153     (while (and
7154             thread
7155             (or
7156              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7157              (gnus-summary-article-ancient-p
7158               (mail-header-number (car thread))))
7159             (if (or (<= (length (cdr thread)) 1)
7160                     (eq gnus-fetch-old-headers 'invisible))
7161                 (setq gnus-newsgroup-limit
7162                       (delq (mail-header-number (car thread))
7163                             gnus-newsgroup-limit)
7164                       thread (cadr thread))
7165               (when (gnus-invisible-cut-children (cdr thread))
7166                 (let ((th (cdr thread)))
7167                   (while th
7168                     (if (memq (mail-header-number (caar th))
7169                               gnus-newsgroup-limit)
7170                         (setq thread (car th)
7171                               th nil)
7172                       (setq th (cdr th))))))))))
7173   thread)
7174
7175 (defun gnus-cut-threads (threads)
7176   "Cut off all uninteresting articles from the beginning of threads."
7177   (when (or (eq gnus-fetch-old-headers 'some)
7178             (eq gnus-fetch-old-headers 'invisible)
7179             (numberp gnus-fetch-old-headers)
7180             (eq gnus-build-sparse-threads 'some)
7181             (eq gnus-build-sparse-threads 'more))
7182     (let ((th threads))
7183       (while th
7184         (setcar th (gnus-cut-thread (car th)))
7185         (setq th (cdr th)))))
7186   ;; Remove nixed out threads.
7187   (delq nil threads))
7188
7189 (defun gnus-summary-initial-limit (&optional show-if-empty)
7190   "Figure out what the initial limit is supposed to be on group entry.
7191 This entails weeding out unwanted dormants, low-scored articles,
7192 fetch-old-headers verbiage, and so on."
7193   ;; Most groups have nothing to remove.
7194   (if (or gnus-inhibit-limiting
7195           (and (null gnus-newsgroup-dormant)
7196                (eq gnus-newsgroup-display 'gnus-not-ignore)
7197                (not (eq gnus-fetch-old-headers 'some))
7198                (not (numberp gnus-fetch-old-headers))
7199                (not (eq gnus-fetch-old-headers 'invisible))
7200                (null gnus-summary-expunge-below)
7201                (not (eq gnus-build-sparse-threads 'some))
7202                (not (eq gnus-build-sparse-threads 'more))
7203                (null gnus-thread-expunge-below)
7204                (not gnus-use-nocem)))
7205       ()                                ; Do nothing.
7206     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7207     (setq gnus-newsgroup-limit nil)
7208     (mapatoms
7209      (lambda (node)
7210        (unless (car (symbol-value node))
7211          ;; These threads have no parents -- they are roots.
7212          (let ((nodes (cdr (symbol-value node)))
7213                thread)
7214            (while nodes
7215              (if (and gnus-thread-expunge-below
7216                       (< (gnus-thread-total-score (car nodes))
7217                          gnus-thread-expunge-below))
7218                  (gnus-expunge-thread (pop nodes))
7219                (setq thread (pop nodes))
7220                (gnus-summary-limit-children thread))))))
7221      gnus-newsgroup-dependencies)
7222     ;; If this limitation resulted in an empty group, we might
7223     ;; pop the previous limit and use it instead.
7224     (when (and (not gnus-newsgroup-limit)
7225                show-if-empty)
7226       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7227     gnus-newsgroup-limit))
7228
7229 (defun gnus-summary-limit-children (thread)
7230   "Return 1 if this subthread is visible and 0 if it is not."
7231   ;; First we get the number of visible children to this thread.  This
7232   ;; is done by recursing down the thread using this function, so this
7233   ;; will really go down to a leaf article first, before slowly
7234   ;; working its way up towards the root.
7235   (when thread
7236     (let ((children
7237            (if (cdr thread)
7238                (apply '+ (mapcar 'gnus-summary-limit-children
7239                                  (cdr thread)))
7240              0))
7241           (number (mail-header-number (car thread)))
7242           score)
7243       (if (and
7244            (not (memq number gnus-newsgroup-marked))
7245            (or
7246             ;; If this article is dormant and has absolutely no visible
7247             ;; children, then this article isn't visible.
7248             (and (memq number gnus-newsgroup-dormant)
7249                  (zerop children))
7250             ;; If this is "fetch-old-headered" and there is no
7251             ;; visible children, then we don't want this article.
7252             (and (or (eq gnus-fetch-old-headers 'some)
7253                      (numberp gnus-fetch-old-headers))
7254                  (gnus-summary-article-ancient-p number)
7255                  (zerop children))
7256             ;; If this is "fetch-old-headered" and `invisible', then
7257             ;; we don't want this article.
7258             (and (eq gnus-fetch-old-headers 'invisible)
7259                  (gnus-summary-article-ancient-p number))
7260             ;; If this is a sparsely inserted article with no children,
7261             ;; we don't want it.
7262             (and (eq gnus-build-sparse-threads 'some)
7263                  (gnus-summary-article-sparse-p number)
7264                  (zerop children))
7265             ;; If we use expunging, and this article is really
7266             ;; low-scored, then we don't want this article.
7267             (when (and gnus-summary-expunge-below
7268                        (< (setq score
7269                                 (or (cdr (assq number gnus-newsgroup-scored))
7270                                     gnus-summary-default-score))
7271                           gnus-summary-expunge-below))
7272               ;; We increase the expunge-tally here, but that has
7273               ;; nothing to do with the limits, really.
7274               (incf gnus-newsgroup-expunged-tally)
7275               ;; We also mark as read here, if that's wanted.
7276               (when (and gnus-summary-mark-below
7277                          (< score gnus-summary-mark-below))
7278                 (setq gnus-newsgroup-unreads
7279                       (delq number gnus-newsgroup-unreads))
7280                 (if gnus-newsgroup-auto-expire
7281                     (push number gnus-newsgroup-expirable)
7282                   (push (cons number gnus-low-score-mark)
7283                         gnus-newsgroup-reads)))
7284               t)
7285             ;; Do the `display' group parameter.
7286             (and gnus-newsgroup-display
7287                  (not (funcall gnus-newsgroup-display)))
7288             ;; Check NoCeM things.
7289             (if (and gnus-use-nocem
7290                      (gnus-nocem-unwanted-article-p
7291                       (mail-header-id (car thread))))
7292                 (progn
7293                   (setq gnus-newsgroup-unreads
7294                         (delq number gnus-newsgroup-unreads))
7295                   t))))
7296           ;; Nope, invisible article.
7297           0
7298         ;; Ok, this article is to be visible, so we add it to the limit
7299         ;; and return 1.
7300         (push number gnus-newsgroup-limit)
7301         1))))
7302
7303 (defun gnus-expunge-thread (thread)
7304   "Mark all articles in THREAD as read."
7305   (let* ((number (mail-header-number (car thread))))
7306     (incf gnus-newsgroup-expunged-tally)
7307     ;; We also mark as read here, if that's wanted.
7308     (setq gnus-newsgroup-unreads
7309           (delq number gnus-newsgroup-unreads))
7310     (if gnus-newsgroup-auto-expire
7311         (push number gnus-newsgroup-expirable)
7312       (push (cons number gnus-low-score-mark)
7313             gnus-newsgroup-reads)))
7314   ;; Go recursively through all subthreads.
7315   (mapcar 'gnus-expunge-thread (cdr thread)))
7316
7317 ;; Summary article oriented commands
7318
7319 (defun gnus-summary-refer-parent-article (n)
7320   "Refer parent article N times.
7321 If N is negative, go to ancestor -N instead.
7322 The difference between N and the number of articles fetched is returned."
7323   (interactive "p")
7324   (let ((skip 1)
7325         error header ref)
7326     (when (not (natnump n))
7327       (setq skip (abs n)
7328             n 1))
7329     (while (and (> n 0)
7330                 (not error))
7331       (setq header (gnus-summary-article-header))
7332       (if (and (eq (mail-header-number header)
7333                    (cdr gnus-article-current))
7334                (equal gnus-newsgroup-name
7335                       (car gnus-article-current)))
7336           ;; If we try to find the parent of the currently
7337           ;; displayed article, then we take a look at the actual
7338           ;; References header, since this is slightly more
7339           ;; reliable than the References field we got from the
7340           ;; server.
7341           (save-excursion
7342             (set-buffer gnus-original-article-buffer)
7343             (nnheader-narrow-to-headers)
7344             (unless (setq ref (message-fetch-field "references"))
7345               (setq ref (message-fetch-field "in-reply-to")))
7346             (widen))
7347         (setq ref
7348               ;; It's not the current article, so we take a bet on
7349               ;; the value we got from the server.
7350               (mail-header-references header)))
7351       (if (and ref
7352                (not (equal ref "")))
7353           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
7354             (gnus-message 1 "Couldn't find parent"))
7355         (gnus-message 1 "No references in article %d"
7356                       (gnus-summary-article-number))
7357         (setq error t))
7358       (decf n))
7359     (gnus-summary-position-point)
7360     n))
7361
7362 (defun gnus-summary-refer-references ()
7363   "Fetch all articles mentioned in the References header.
7364 Return the number of articles fetched."
7365   (interactive)
7366   (let ((ref (mail-header-references (gnus-summary-article-header)))
7367         (current (gnus-summary-article-number))
7368         (n 0))
7369     (if (or (not ref)
7370             (equal ref ""))
7371         (error "No References in the current article")
7372       ;; For each Message-ID in the References header...
7373       (while (string-match "<[^>]*>" ref)
7374         (incf n)
7375         ;; ... fetch that article.
7376         (gnus-summary-refer-article
7377          (prog1 (match-string 0 ref)
7378            (setq ref (substring ref (match-end 0))))))
7379       (gnus-summary-goto-subject current)
7380       (gnus-summary-position-point)
7381       n)))
7382
7383 (defun gnus-summary-refer-thread (&optional limit)
7384   "Fetch all articles in the current thread.
7385 If LIMIT (the numerical prefix), fetch that many old headers instead
7386 of what's specified by the `gnus-refer-thread-limit' variable."
7387   (interactive "P")
7388   (let ((id (mail-header-id (gnus-summary-article-header)))
7389         (limit (if limit (prefix-numeric-value limit)
7390                  gnus-refer-thread-limit)))
7391     ;; We want to fetch LIMIT *old* headers, but we also have to
7392     ;; re-fetch all the headers in the current buffer, because many of
7393     ;; them may be undisplayed.  So we adjust LIMIT.
7394     (when (numberp limit)
7395       (incf limit (- gnus-newsgroup-end gnus-newsgroup-begin)))
7396     (unless (eq gnus-fetch-old-headers 'invisible)
7397       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
7398       ;; Retrieve the headers and read them in.
7399       (if (eq (gnus-retrieve-headers
7400                (list gnus-newsgroup-end) gnus-newsgroup-name limit)
7401               'nov)
7402           (gnus-build-all-threads)
7403         (error "Can't fetch thread from backends that don't support NOV"))
7404       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
7405     (gnus-summary-limit-include-thread id)))
7406
7407 (defun gnus-summary-refer-article (message-id)
7408   "Fetch an article specified by MESSAGE-ID."
7409   (interactive "sMessage-ID: ")
7410   (when (and (stringp message-id)
7411              (not (zerop (length message-id))))
7412     ;; Construct the correct Message-ID if necessary.
7413     ;; Suggested by tale@pawl.rpi.edu.
7414     (unless (string-match "^<" message-id)
7415       (setq message-id (concat "<" message-id)))
7416     (unless (string-match ">$" message-id)
7417       (setq message-id (concat message-id ">")))
7418     (let* ((header (gnus-id-to-header message-id))
7419            (sparse (and header
7420                         (gnus-summary-article-sparse-p
7421                          (mail-header-number header))
7422                         (memq (mail-header-number header)
7423                               gnus-newsgroup-limit)))
7424            number)
7425       (cond
7426        ;; If the article is present in the buffer we just go to it.
7427        ((and header
7428              (or (not (gnus-summary-article-sparse-p
7429                        (mail-header-number header)))
7430                  sparse))
7431         (prog1
7432             (gnus-summary-goto-article
7433              (mail-header-number header) nil t)
7434           (when sparse
7435             (gnus-summary-update-article (mail-header-number header)))))
7436        (t
7437         ;; We fetch the article.
7438         (catch 'found
7439           (dolist (gnus-override-method (gnus-refer-article-methods))
7440             (gnus-check-server gnus-override-method)
7441             ;; Fetch the header, and display the article.
7442             (when (setq number (gnus-summary-insert-subject message-id))
7443               (gnus-summary-select-article nil nil nil number)
7444               (throw 'found t)))
7445           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
7446
7447 (defun gnus-refer-article-methods ()
7448   "Return a list of referrable methods."
7449   (cond
7450    ;; No method, so we default to current and native.
7451    ((null gnus-refer-article-method)
7452     (list gnus-current-select-method gnus-select-method))
7453    ;; Current.
7454    ((eq 'current gnus-refer-article-method)
7455     (list gnus-current-select-method))
7456    ;; List of select methods.
7457    ((not (and (symbolp (car gnus-refer-article-method))
7458               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
7459     (let (out)
7460       (dolist (method gnus-refer-article-method)
7461         (push (if (eq 'current method)
7462                   gnus-current-select-method
7463                 method)
7464               out))
7465       (nreverse out)))
7466    ;; One single select method.
7467    (t
7468     (list gnus-refer-article-method))))
7469
7470 (defun gnus-summary-edit-parameters ()
7471   "Edit the group parameters of the current group."
7472   (interactive)
7473   (gnus-group-edit-group gnus-newsgroup-name 'params))
7474
7475 (defun gnus-summary-customize-parameters ()
7476   "Customize the group parameters of the current group."
7477   (interactive)
7478   (gnus-group-customize gnus-newsgroup-name))
7479
7480 (defun gnus-summary-enter-digest-group (&optional force)
7481   "Enter an nndoc group based on the current article.
7482 If FORCE, force a digest interpretation.  If not, try
7483 to guess what the document format is."
7484   (interactive "P")
7485   (let ((conf gnus-current-window-configuration))
7486     (save-excursion
7487       (gnus-summary-select-article))
7488     (setq gnus-current-window-configuration conf)
7489     (let* ((name (format "%s-%d"
7490                          (gnus-group-prefixed-name
7491                           gnus-newsgroup-name (list 'nndoc ""))
7492                          (save-excursion
7493                            (set-buffer gnus-summary-buffer)
7494                            gnus-current-article)))
7495            (ogroup gnus-newsgroup-name)
7496            (params (append (gnus-info-params (gnus-get-info ogroup))
7497                            (list (cons 'to-group ogroup))
7498                            (list (cons 'save-article-group ogroup))))
7499            (case-fold-search t)
7500            (buf (current-buffer))
7501            dig to-address)
7502       (save-excursion
7503         (set-buffer gnus-original-article-buffer)
7504         ;; Have the digest group inherit the main mail address of
7505         ;; the parent article.
7506         (when (setq to-address (or (message-fetch-field "reply-to")
7507                                    (message-fetch-field "from")))
7508           (setq params (append
7509                         (list (cons 'to-address
7510                                     (funcall gnus-decode-encoded-word-function
7511                                              to-address))))))
7512         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
7513         (insert-buffer-substring gnus-original-article-buffer)
7514         ;; Remove lines that may lead nndoc to misinterpret the
7515         ;; document type.
7516         (narrow-to-region
7517          (goto-char (point-min))
7518          (or (search-forward "\n\n" nil t) (point)))
7519         (goto-char (point-min))
7520         (delete-matching-lines "^Path:\\|^From ")
7521         (widen))
7522       (unwind-protect
7523           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
7524                     (gnus-newsgroup-ephemeral-ignored-charsets
7525                      gnus-newsgroup-ignored-charsets))
7526                 (gnus-group-read-ephemeral-group
7527                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
7528                               (nndoc-article-type
7529                                ,(if force 'mbox 'guess))) t))
7530               ;; Make all postings to this group go to the parent group.
7531               (nconc (gnus-info-params (gnus-get-info name))
7532                      params)
7533             ;; Couldn't select this doc group.
7534             (switch-to-buffer buf)
7535             (gnus-set-global-variables)
7536             (gnus-configure-windows 'summary)
7537             (gnus-message 3 "Article couldn't be entered?"))
7538         (kill-buffer dig)))))
7539
7540 (defun gnus-summary-read-document (n)
7541   "Open a new group based on the current article(s).
7542 This will allow you to read digests and other similar
7543 documents as newsgroups.
7544 Obeys the standard process/prefix convention."
7545   (interactive "P")
7546   (let* ((articles (gnus-summary-work-articles n))
7547          (ogroup gnus-newsgroup-name)
7548          (params (append (gnus-info-params (gnus-get-info ogroup))
7549                          (list (cons 'to-group ogroup))))
7550          article group egroup groups vgroup)
7551     (while (setq article (pop articles))
7552       (setq group (format "%s-%d" gnus-newsgroup-name article))
7553       (gnus-summary-remove-process-mark article)
7554       (when (gnus-summary-display-article article)
7555         (save-excursion
7556           (with-temp-buffer
7557             (insert-buffer-substring gnus-original-article-buffer)
7558             ;; Remove some headers that may lead nndoc to make
7559             ;; the wrong guess.
7560             (message-narrow-to-head)
7561             (goto-char (point-min))
7562             (delete-matching-lines "^\\(Path\\):\\|^From ")
7563             (widen)
7564             (if (setq egroup
7565                       (gnus-group-read-ephemeral-group
7566                        group `(nndoc ,group (nndoc-address ,(current-buffer))
7567                                      (nndoc-article-type guess))
7568                        t nil t))
7569                 (progn
7570                   ;; Make all postings to this group go to the parent group.
7571                   (nconc (gnus-info-params (gnus-get-info egroup))
7572                          params)
7573                   (push egroup groups))
7574               ;; Couldn't select this doc group.
7575               (gnus-error 3 "Article couldn't be entered"))))))
7576     ;; Now we have selected all the documents.
7577     (cond
7578      ((not groups)
7579       (error "None of the articles could be interpreted as documents"))
7580      ((gnus-group-read-ephemeral-group
7581        (setq vgroup (format
7582                      "nnvirtual:%s-%s" gnus-newsgroup-name
7583                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
7584        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
7585        t
7586        (cons (current-buffer) 'summary)))
7587      (t
7588       (error "Couldn't select virtual nndoc group")))))
7589
7590 (defun gnus-summary-isearch-article (&optional regexp-p)
7591   "Do incremental search forward on the current article.
7592 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
7593   (interactive "P")
7594   (let* ((gnus-inhibit-treatment t)
7595          (old (gnus-summary-select-article)))
7596     (gnus-configure-windows 'article)
7597     (gnus-eval-in-buffer-window gnus-article-buffer
7598       (save-restriction
7599         (widen)
7600         (when (eq 'old old)
7601           (gnus-article-show-all-headers))
7602         (goto-char (point-min))
7603         (isearch-forward regexp-p)))))
7604
7605 (defun gnus-summary-search-article-forward (regexp &optional backward)
7606   "Search for an article containing REGEXP forward.
7607 If BACKWARD, search backward instead."
7608   (interactive
7609    (list (read-string
7610           (format "Search article %s (regexp%s): "
7611                   (if current-prefix-arg "backward" "forward")
7612                   (if gnus-last-search-regexp
7613                       (concat ", default " gnus-last-search-regexp)
7614                     "")))
7615          current-prefix-arg))
7616   (if (string-equal regexp "")
7617       (setq regexp (or gnus-last-search-regexp ""))
7618     (setq gnus-last-search-regexp regexp)
7619     (setq gnus-article-before-search gnus-current-article))
7620   ;; Intentionally set gnus-last-article.
7621   (setq gnus-last-article gnus-article-before-search)
7622   (let ((gnus-last-article gnus-last-article))
7623     (if (gnus-summary-search-article regexp backward)
7624         (gnus-summary-show-thread)
7625       (error "Search failed: \"%s\"" regexp))))
7626
7627 (defun gnus-summary-search-article-backward (regexp)
7628   "Search for an article containing REGEXP backward."
7629   (interactive
7630    (list (read-string
7631           (format "Search article backward (regexp%s): "
7632                   (if gnus-last-search-regexp
7633                       (concat ", default " gnus-last-search-regexp)
7634                     "")))))
7635   (gnus-summary-search-article-forward regexp 'backward))
7636
7637 (eval-when-compile
7638   (defmacro gnus-summary-search-article-position-point (regexp backward)
7639     "Dehighlight the last matched text and goto the beginning position."
7640     (` (if (and gnus-summary-search-article-matched-data
7641                 (let ((text (caddr gnus-summary-search-article-matched-data))
7642                       (inhibit-read-only t)
7643                       buffer-read-only)
7644                   (delete-region
7645                    (goto-char (car gnus-summary-search-article-matched-data))
7646                    (cadr gnus-summary-search-article-matched-data))
7647                   (insert text)
7648                   (string-match (, regexp) text)))
7649            (if (, backward) (beginning-of-line) (end-of-line))
7650          (goto-char (if (, backward) (point-max) (point-min))))))
7651
7652   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
7653     "Place point where X-Face image is displayed."
7654     (if (featurep 'xemacs)
7655         (` (let ((end (if (search-forward "\n\n" nil t)
7656                           (goto-char (1- (point)))
7657                         (point-min)))
7658                  extent)
7659              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
7660              (unless (and (re-search-forward "^From:" end t)
7661                           (setq extent (extent-at (point)))
7662                           (extent-begin-glyph extent))
7663                (goto-char (, opoint)))))
7664       (` (let ((end (if (search-forward "\n\n" nil t)
7665                         (goto-char (1- (point)))
7666                       (point-min)))
7667                (start (or (search-backward "\n\n" nil t) (point-min))))
7668            (goto-char
7669             (or (text-property-any start end 'x-face-image t);; x-face-e21
7670                 (text-property-any start end 'x-face-mule-bitmap-image t)
7671                 (, opoint)))))))
7672
7673   (defmacro gnus-summary-search-article-highlight-matched-text
7674     (backward treated x-face)
7675     "Highlight matched text in the function `gnus-summary-search-article'."
7676     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
7677              (end (set-marker (make-marker) (match-end 0)))
7678              (inhibit-read-only t)
7679              buffer-read-only)
7680          (unless treated
7681            (let ((,@
7682                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
7683                     (mapcar
7684                      (lambda (item) (setq items (delq item items)))
7685                      '(gnus-treat-buttonize
7686                        gnus-treat-fill-article
7687                        gnus-treat-fill-long-lines
7688                        gnus-treat-emphasize
7689                        gnus-treat-highlight-headers
7690                        gnus-treat-highlight-citation
7691                        gnus-treat-highlight-signature
7692                        gnus-treat-overstrike
7693                        gnus-treat-display-xface
7694                        gnus-treat-buttonize-head
7695                        gnus-treat-decode-article-as-default-mime-charset))
7696                     (static-if (featurep 'xemacs)
7697                         items
7698                       (cons '(x-face-mule-delete-x-face-field
7699                               (quote never))
7700                             items))))
7701                  (gnus-treat-display-xface
7702                   (when (, x-face) gnus-treat-display-xface)))
7703              (gnus-article-prepare-mime-display)))
7704          (goto-char (if (, backward) start end))
7705          (when (, x-face)
7706            (gnus-summary-search-article-highlight-goto-x-face (point)))
7707          (setq gnus-summary-search-article-matched-data
7708                (list start end (buffer-substring start end)))
7709          (unless (eq start end);; matched text has been deleted. :-<
7710            (put-text-property start end 'face
7711                               (or (find-face 'isearch)
7712                                   'secondary-selection))))))
7713   )
7714
7715 (defun gnus-summary-search-article (regexp &optional backward)
7716   "Search for an article containing REGEXP.
7717 Optional argument BACKWARD means do search for backward.
7718 `gnus-select-article-hook' is not called during the search."
7719   ;; We have to require this here to make sure that the following
7720   ;; dynamic binding isn't shadowed by autoloading.
7721   (require 'gnus-async)
7722   (require 'gnus-art)
7723   (let ((gnus-select-article-hook nil)  ;Disable hook.
7724         (gnus-article-prepare-hook nil)
7725         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
7726         (gnus-use-article-prefetch nil)
7727         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
7728         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
7729         (sum (current-buffer))
7730         (found nil)
7731         point treated)
7732     (gnus-save-hidden-threads
7733       (static-if (featurep 'xemacs)
7734           (let ((gnus-inhibit-treatment t))
7735             (setq treated (eq 'old (gnus-summary-select-article)))
7736             (when (and treated
7737                        (not (and (gnus-buffer-live-p gnus-article-buffer)
7738                                  (window-live-p (get-buffer-window
7739                                                  gnus-article-buffer t)))))
7740               (gnus-summary-select-article nil t)
7741               (setq treated nil)))
7742         (let ((gnus-inhibit-treatment t)
7743               (x-face-mule-delete-x-face-field 'never))
7744           (setq treated (eq 'old (gnus-summary-select-article)))
7745           (when (and treated
7746                      (not
7747                       (and (gnus-buffer-live-p gnus-article-buffer)
7748                            (window-live-p (get-buffer-window
7749                                            gnus-article-buffer t))
7750                            (or (not (string-match "^\\^X-Face:" regexp))
7751                                (with-current-buffer gnus-article-buffer
7752                                  gnus-summary-search-article-matched-data)))))
7753             (gnus-summary-select-article nil t)
7754             (setq treated nil))))
7755       (set-buffer gnus-article-buffer)
7756       (widen)
7757       (if treated
7758           (progn
7759             (gnus-article-show-all-headers)
7760             (gnus-summary-search-article-position-point regexp backward))
7761         (goto-char (if backward (point-max) (point-min))))
7762       (while (not found)
7763         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
7764         (if (if backward
7765                 (re-search-backward regexp nil t)
7766               (re-search-forward regexp nil t))
7767             ;; We found the regexp.
7768             (progn
7769               (gnus-summary-search-article-highlight-matched-text
7770                backward treated (string-match "^\\^X-Face:" regexp))
7771               (setq found 'found)
7772               (forward-line
7773                (/ (- 2 (window-height
7774                         (get-buffer-window gnus-article-buffer t)))
7775                   2))
7776               (set-window-start
7777                (get-buffer-window (current-buffer))
7778                (point))
7779               (set-buffer sum)
7780               (setq point (point)))
7781           ;; We didn't find it, so we go to the next article.
7782           (set-buffer sum)
7783           (setq found 'not)
7784           (while (eq found 'not)
7785             (if (not (if backward (gnus-summary-find-prev)
7786                        (gnus-summary-find-next)))
7787                 ;; No more articles.
7788                 (setq found t)
7789               ;; Select the next article and adjust point.
7790               (unless (gnus-summary-article-sparse-p
7791                        (gnus-summary-article-number))
7792                 (setq found nil)
7793                 (let ((gnus-inhibit-treatment t))
7794                   (gnus-summary-select-article))
7795                 (setq treated nil)
7796                 (set-buffer gnus-article-buffer)
7797                 (widen)
7798                 (goto-char (if backward (point-max) (point-min))))))))
7799       (gnus-message 7 ""))
7800     ;; Return whether we found the regexp.
7801     (when (eq found 'found)
7802       (goto-char point)
7803       (gnus-summary-show-thread)
7804       (gnus-summary-goto-subject gnus-current-article)
7805       (gnus-summary-position-point)
7806       t)))
7807
7808 (defun gnus-find-matching-articles (header regexp)
7809   "Return a list of all articles that match REGEXP on HEADER.
7810 This search includes all articles in the current group that Gnus has
7811 fetched headers for, whether they are displayed or not."
7812   (let ((articles nil)
7813         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
7814         (case-fold-search t))
7815     (dolist (header gnus-newsgroup-headers)
7816       (when (string-match regexp (funcall func header))
7817         (push (mail-header-number header) articles)))
7818     (nreverse articles)))
7819
7820 (defun gnus-summary-find-matching (header regexp &optional backward unread
7821                                           not-case-fold)
7822   "Return a list of all articles that match REGEXP on HEADER.
7823 The search stars on the current article and goes forwards unless
7824 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
7825 If UNREAD is non-nil, only unread articles will
7826 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
7827 in the comparisons."
7828   (let ((case-fold-search (not not-case-fold))
7829         articles d func)
7830     (if (consp header)
7831         (if (eq (car header) 'extra)
7832             (setq func
7833                   `(lambda (h)
7834                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
7835                          "")))
7836           (error "%s is an invalid header" header))
7837       (unless (fboundp (intern (concat "mail-header-" header)))
7838         (error "%s is not a valid header" header))
7839       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
7840     (dolist (d (if (eq backward 'all)
7841                    gnus-newsgroup-data
7842                  (gnus-data-find-list
7843                   (gnus-summary-article-number)
7844                   (gnus-data-list backward))))
7845       (when (and (or (not unread)       ; We want all articles...
7846                      (gnus-data-unread-p d)) ; Or just unreads.
7847                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
7848                  (string-match regexp
7849                                (funcall func (gnus-data-header d)))) ; Match.
7850         (push (gnus-data-number d) articles))) ; Success!
7851     (nreverse articles)))
7852
7853 (defun gnus-summary-execute-command (header regexp command &optional backward)
7854   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
7855 If HEADER is an empty string (or nil), the match is done on the entire
7856 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
7857   (interactive
7858    (list (let ((completion-ignore-case t))
7859            (completing-read
7860             "Header name: "
7861             (mapcar (lambda (header) (list (format "%s" header)))
7862                     (append
7863                      '("Number" "Subject" "From" "Lines" "Date"
7864                        "Message-ID" "Xref" "References" "Body")
7865                      gnus-extra-headers))
7866             nil 'require-match))
7867          (read-string "Regexp: ")
7868          (read-key-sequence "Command: ")
7869          current-prefix-arg))
7870   (when (equal header "Body")
7871     (setq header ""))
7872   ;; Hidden thread subtrees must be searched as well.
7873   (gnus-summary-show-all-threads)
7874   ;; We don't want to change current point nor window configuration.
7875   (save-excursion
7876     (save-window-excursion
7877       (gnus-message 6 "Executing %s..." (key-description command))
7878       ;; We'd like to execute COMMAND interactively so as to give arguments.
7879       (gnus-execute header regexp
7880                     `(call-interactively ',(key-binding command))
7881                     backward)
7882       (gnus-message 6 "Executing %s...done" (key-description command)))))
7883
7884 (defun gnus-summary-beginning-of-article ()
7885   "Scroll the article back to the beginning."
7886   (interactive)
7887   (gnus-summary-select-article)
7888   (gnus-configure-windows 'article)
7889   (gnus-eval-in-buffer-window gnus-article-buffer
7890     (widen)
7891     (goto-char (point-min))
7892     (when gnus-page-broken
7893       (gnus-narrow-to-page))))
7894
7895 (defun gnus-summary-end-of-article ()
7896   "Scroll to the end of the article."
7897   (interactive)
7898   (gnus-summary-select-article)
7899   (gnus-configure-windows 'article)
7900   (gnus-eval-in-buffer-window gnus-article-buffer
7901     (widen)
7902     (goto-char (point-max))
7903     (recenter -3)
7904     (when gnus-page-broken
7905       (gnus-narrow-to-page))))
7906
7907 (defun gnus-summary-print-article (&optional filename n)
7908   "Generate and print a PostScript image of the N next (mail) articles.
7909
7910 If N is negative, print the N previous articles.  If N is nil and articles
7911 have been marked with the process mark, print these instead.
7912
7913 If the optional first argument FILENAME is nil, send the image to the
7914 printer.  If FILENAME is a string, save the PostScript image in a file with
7915 that name.  If FILENAME is a number, prompt the user for the name of the file
7916 to save in."
7917   (interactive (list (ps-print-preprint current-prefix-arg)))
7918   (dolist (article (gnus-summary-work-articles n))
7919     (gnus-summary-select-article nil nil 'pseudo article)
7920     (gnus-eval-in-buffer-window gnus-article-buffer
7921       (let ((buffer (generate-new-buffer " *print*")))
7922         (unwind-protect
7923             (progn
7924               (copy-to-buffer buffer (point-min) (point-max))
7925               (set-buffer buffer)
7926               (gnus-article-delete-invisible-text)
7927               (when (gnus-visual-p 'article-highlight 'highlight)
7928                 ;; Copy-to-buffer doesn't copy overlay.  So redo
7929                 ;; highlight.
7930                 (let ((gnus-article-buffer buffer))
7931                   (gnus-article-highlight-citation t)
7932                   (gnus-article-highlight-signature)))
7933               (let ((ps-left-header
7934                      (list
7935                       (concat "("
7936                               (mail-header-subject gnus-current-headers) ")")
7937                       (concat "("
7938                               (mail-header-from gnus-current-headers) ")")))
7939                     (ps-right-header
7940                      (list
7941                       "/pagenumberstring load"
7942                       (concat "("
7943                               (mail-header-date gnus-current-headers) ")"))))
7944                 (gnus-run-hooks 'gnus-ps-print-hook)
7945                 (save-excursion
7946                   (if window-system
7947                       (ps-spool-buffer-with-faces)
7948                     (ps-spool-buffer)))))
7949           (kill-buffer buffer))))
7950     (gnus-summary-remove-process-mark article))
7951   (ps-despool filename))
7952
7953 (defun gnus-summary-show-article (&optional arg)
7954   "Force re-fetching of the current article.
7955 If ARG (the prefix) is a number, show the article with the charset
7956 defined in `gnus-summary-show-article-charset-alist', or the charset
7957 input.
7958 If ARG (the prefix) is non-nil and not a number, show the raw article
7959 without any article massaging functions being run."
7960   (interactive "P")
7961   (cond
7962    ((numberp arg)
7963     (gnus-summary-show-article t)
7964     (let ((gnus-newsgroup-charset
7965            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
7966                (mm-read-coding-system
7967                 "View as charset: "
7968                 (save-excursion
7969                   (set-buffer gnus-article-buffer)
7970                   (let ((coding-systems
7971                          (detect-coding-region (point) (point-max))))
7972                     (or (car-safe coding-systems)
7973                         coding-systems))))))
7974           (gnus-newsgroup-ignored-charsets 'gnus-all))
7975       (gnus-summary-select-article nil 'force)
7976       (let ((deps gnus-newsgroup-dependencies)
7977             head header)
7978         (save-excursion
7979           (set-buffer gnus-original-article-buffer)
7980           (save-restriction
7981             (message-narrow-to-head)
7982             (setq head (buffer-string)))
7983           (with-temp-buffer
7984             (insert (format "211 %d Article retrieved.\n"
7985                             (cdr gnus-article-current)))
7986             (insert head)
7987             (insert ".\n")
7988             (let ((nntp-server-buffer (current-buffer)))
7989               (setq header (car (gnus-get-newsgroup-headers deps t))))))
7990         (gnus-data-set-header
7991          (gnus-data-find (cdr gnus-article-current))
7992          header)
7993         (gnus-summary-update-article-line
7994          (cdr gnus-article-current) header)
7995         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
7996           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
7997    ((not arg)
7998     ;; Select the article the normal way.
7999     (gnus-summary-select-article nil 'force))
8000    (t
8001     ;; We have to require this here to make sure that the following
8002     ;; dynamic binding isn't shadowed by autoloading.
8003     (require 'gnus-async)
8004     (require 'gnus-art)
8005     ;; Bind the article treatment functions to nil.
8006     (let ((gnus-have-all-headers t)
8007           gnus-article-prepare-hook
8008           gnus-article-decode-hook
8009           gnus-break-pages
8010           gnus-show-mime
8011           (gnus-inhibit-treatment t))
8012       (gnus-summary-select-article nil 'force))))
8013   (gnus-summary-goto-subject gnus-current-article)
8014   (gnus-summary-position-point))
8015
8016 (defun gnus-summary-show-raw-article ()
8017   "Show the raw article without any article massaging functions being run."
8018   (interactive)
8019   (gnus-summary-show-article t))
8020
8021 (defun gnus-summary-verbose-headers (&optional arg)
8022   "Toggle permanent full header display.
8023 If ARG is a positive number, turn header display on.
8024 If ARG is a negative number, turn header display off."
8025   (interactive "P")
8026   (setq gnus-show-all-headers
8027         (cond ((or (not (numberp arg))
8028                    (zerop arg))
8029                (not gnus-show-all-headers))
8030               ((natnump arg)
8031                t)))
8032   (gnus-summary-show-article))
8033
8034 (defun gnus-summary-toggle-header (&optional arg)
8035   "Show the headers if they are hidden, or hide them if they are shown.
8036 If ARG is a positive number, show the entire header.
8037 If ARG is a negative number, hide the unwanted header lines."
8038   (interactive "P")
8039   (save-excursion
8040     (set-buffer gnus-article-buffer)
8041     (save-restriction
8042       (let* ((buffer-read-only nil)
8043              (inhibit-point-motion-hooks t)
8044              hidden e)
8045         (setq hidden
8046               (if (numberp arg)
8047                   (>= arg 0)
8048                 (save-restriction
8049                   (article-narrow-to-head)
8050                   (gnus-article-hidden-text-p 'headers))))
8051         (goto-char (point-min))
8052         (when (search-forward "\n\n" nil t)
8053           (delete-region (point-min) (1- (point))))
8054         (goto-char (point-min))
8055         (save-excursion
8056           (set-buffer gnus-original-article-buffer)
8057           (goto-char (point-min))
8058           (setq e (1- (or (search-forward "\n\n" nil t) (point-max)))))
8059         (insert-buffer-substring gnus-original-article-buffer 1 e)
8060         (save-restriction
8061           (narrow-to-region (point-min) (point))
8062           (article-decode-encoded-words)
8063           (if  hidden
8064               (let ((gnus-treat-hide-headers nil)
8065                     (gnus-treat-hide-boring-headers nil))
8066                 (setq gnus-article-wash-types
8067                       (delq 'headers gnus-article-wash-types))
8068                 (gnus-treat-article 'head))
8069             (gnus-treat-article 'head)))
8070         (gnus-set-mode-line 'article)))))
8071
8072 (defun gnus-summary-show-all-headers ()
8073   "Make all header lines visible."
8074   (interactive)
8075   (gnus-summary-toggle-header 1))
8076
8077 (defun gnus-summary-toggle-mime (&optional arg)
8078   "Toggle MIME processing.
8079 If ARG is a positive number, turn MIME processing on."
8080   (interactive "P")
8081   (setq gnus-show-mime
8082         (if (null arg)
8083             (not gnus-show-mime)
8084           (> (prefix-numeric-value arg) 0)))
8085   (gnus-summary-select-article t 'force))
8086
8087 (defun gnus-summary-caesar-message (&optional arg)
8088   "Caesar rotate the current article by 13.
8089 The numerical prefix specifies how many places to rotate each letter
8090 forward."
8091   (interactive "P")
8092   (gnus-summary-select-article)
8093   (let ((mail-header-separator ""))
8094     (gnus-eval-in-buffer-window gnus-article-buffer
8095       (save-restriction
8096         (widen)
8097         (let ((start (window-start))
8098               buffer-read-only)
8099           (message-caesar-buffer-body arg)
8100           (set-window-start (get-buffer-window (current-buffer)) start))))))
8101
8102 (defun gnus-summary-stop-page-breaking ()
8103   "Stop page breaking in the current article."
8104   (interactive)
8105   (gnus-summary-select-article)
8106   (gnus-eval-in-buffer-window gnus-article-buffer
8107     (widen)
8108     (when (gnus-visual-p 'page-marker)
8109       (let ((buffer-read-only nil))
8110         (gnus-remove-text-with-property 'gnus-prev)
8111         (gnus-remove-text-with-property 'gnus-next))
8112       (setq gnus-page-broken nil))))
8113
8114 (defun gnus-summary-move-article (&optional n to-newsgroup
8115                                             select-method action)
8116   "Move the current article to a different newsgroup.
8117 If N is a positive number, move the N next articles.
8118 If N is a negative number, move the N previous articles.
8119 If N is nil and any articles have been marked with the process mark,
8120 move those articles instead.
8121 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8122 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8123 re-spool using this method.
8124
8125 For this function to work, both the current newsgroup and the
8126 newsgroup that you want to move to have to support the `request-move'
8127 and `request-accept' functions.
8128
8129 ACTION can be either `move' (the default), `crosspost' or `copy'."
8130   (interactive "P")
8131   (unless action
8132     (setq action 'move))
8133   ;; Check whether the source group supports the required functions.
8134   (cond ((and (eq action 'move)
8135               (not (gnus-check-backend-function
8136                     'request-move-article gnus-newsgroup-name)))
8137          (error "The current group does not support article moving"))
8138         ((and (eq action 'crosspost)
8139               (not (gnus-check-backend-function
8140                     'request-replace-article gnus-newsgroup-name)))
8141          (error "The current group does not support article editing")))
8142   (let ((articles (gnus-summary-work-articles n))
8143         (prefix (if (gnus-check-backend-function
8144                      'request-move-article gnus-newsgroup-name)
8145                     (gnus-group-real-prefix gnus-newsgroup-name)
8146                   ""))
8147         (names '((move "Move" "Moving")
8148                  (copy "Copy" "Copying")
8149                  (crosspost "Crosspost" "Crossposting")))
8150         (copy-buf (save-excursion
8151                     (nnheader-set-temp-buffer " *copy article*")))
8152         (default-marks gnus-article-mark-lists)
8153         (no-expire-marks (delete '(expirable . expire)
8154                                  (copy-sequence gnus-article-mark-lists)))
8155         art-group to-method new-xref article to-groups)
8156     (unless (assq action names)
8157       (error "Unknown action %s" action))
8158     ;; Read the newsgroup name.
8159     (when (and (not to-newsgroup)
8160                (not select-method))
8161       (setq to-newsgroup
8162             (gnus-read-move-group-name
8163              (cadr (assq action names))
8164              (symbol-value (intern (format "gnus-current-%s-group" action)))
8165              articles prefix))
8166       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8167     (setq to-method (or select-method
8168                         (gnus-server-to-method
8169                          (gnus-group-method to-newsgroup))))
8170     ;; Check the method we are to move this article to...
8171     (unless (gnus-check-backend-function
8172              'request-accept-article (car to-method))
8173       (error "%s does not support article copying" (car to-method)))
8174     (unless (gnus-check-server to-method)
8175       (error "Can't open server %s" (car to-method)))
8176     (gnus-message 6 "%s to %s: %s..."
8177                   (caddr (assq action names))
8178                   (or (car select-method) to-newsgroup) articles)
8179     (while articles
8180       (setq article (pop articles))
8181       (setq
8182        art-group
8183        (cond
8184         ;; Move the article.
8185         ((eq action 'move)
8186          ;; Remove this article from future suppression.
8187          (gnus-dup-unsuppress-article article)
8188          (gnus-request-move-article
8189           article                       ; Article to move
8190           gnus-newsgroup-name           ; From newsgroup
8191           (nth 1 (gnus-find-method-for-group
8192                   gnus-newsgroup-name)) ; Server
8193           (list 'gnus-request-accept-article
8194                 to-newsgroup (list 'quote select-method)
8195                 (not articles) t)       ; Accept form
8196           (not articles)))              ; Only save nov last time
8197         ;; Copy the article.
8198         ((eq action 'copy)
8199          (save-excursion
8200            (set-buffer copy-buf)
8201            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8202              (gnus-request-accept-article
8203               to-newsgroup select-method (not articles) t))))
8204         ;; Crosspost the article.
8205         ((eq action 'crosspost)
8206          (let ((xref (message-tokenize-header
8207                       (mail-header-xref (gnus-summary-article-header article))
8208                       " ")))
8209            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8210                                   ":" article))
8211            (unless xref
8212              (setq xref (list (system-name))))
8213            (setq new-xref
8214                  (concat
8215                   (mapconcat 'identity
8216                              (delete "Xref:" (delete new-xref xref))
8217                              " ")
8218                   " " new-xref))
8219            (save-excursion
8220              (set-buffer copy-buf)
8221              ;; First put the article in the destination group.
8222              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8223              (when (consp (setq art-group
8224                                 (gnus-request-accept-article
8225                                  to-newsgroup select-method (not articles))))
8226                (setq new-xref (concat new-xref " " (car art-group)
8227                                       ":" (cdr art-group)))
8228                ;; Now we have the new Xrefs header, so we insert
8229                ;; it and replace the new article.
8230                (nnheader-replace-header "Xref" new-xref)
8231                (gnus-request-replace-article
8232                 (cdr art-group) to-newsgroup (current-buffer))
8233                art-group))))))
8234       (cond
8235        ((not art-group)
8236         (gnus-message 1 "Couldn't %s article %s: %s"
8237                       (cadr (assq action names)) article
8238                       (nnheader-get-report (car to-method))))
8239        ((eq art-group 'junk)
8240         (when (eq action 'move)
8241           (gnus-summary-mark-article article gnus-canceled-mark)
8242           (gnus-message 4 "Deleted article %s" article)))
8243        (t
8244         (let* ((pto-group (gnus-group-prefixed-name
8245                            (car art-group) to-method))
8246                (entry
8247                 (gnus-gethash pto-group gnus-newsrc-hashtb))
8248                (info (nth 2 entry))
8249                (to-group (gnus-info-group info))
8250                to-marks)
8251           ;; Update the group that has been moved to.
8252           (when (and info
8253                      (memq action '(move copy)))
8254             (unless (member to-group to-groups)
8255               (push to-group to-groups))
8256
8257             (unless (memq article gnus-newsgroup-unreads)
8258               (push 'read to-marks)
8259               (gnus-info-set-read
8260                info (gnus-add-to-range (gnus-info-read info)
8261                                        (list (cdr art-group)))))
8262
8263             ;; See whether the article is to be put in the cache.
8264             (let ((marks (if (gnus-group-auto-expirable-p to-group)
8265                              default-marks
8266                            no-expire-marks))
8267                   (to-article (cdr art-group)))
8268
8269               ;; Enter the article into the cache in the new group,
8270               ;; if that is required.
8271               (when gnus-use-cache
8272                 (gnus-cache-possibly-enter-article
8273                  to-group to-article
8274                  (let ((header (copy-sequence
8275                                 (gnus-summary-article-header article))))
8276                    (mail-header-set-number header to-article)
8277                    header)
8278                  (memq article gnus-newsgroup-marked)
8279                  (memq article gnus-newsgroup-dormant)
8280                  (memq article gnus-newsgroup-unreads)))
8281
8282               (when gnus-preserve-marks
8283                 ;; Copy any marks over to the new group.
8284                 (when (and (equal to-group gnus-newsgroup-name)
8285                            (not (memq article gnus-newsgroup-unreads)))
8286                   ;; Mark this article as read in this group.
8287                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
8288                   (setcdr (gnus-active to-group) to-article)
8289                   (setcdr gnus-newsgroup-active to-article))
8290
8291                 (while marks
8292                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
8293                     (when (memq article (symbol-value
8294                                          (intern (format "gnus-newsgroup-%s"
8295                                                          (caar marks)))))
8296                       (push (cdar marks) to-marks)
8297                       ;; If the other group is the same as this group,
8298                       ;; then we have to add the mark to the list.
8299                       (when (equal to-group gnus-newsgroup-name)
8300                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
8301                              (cons to-article
8302                                    (symbol-value
8303                                     (intern (format "gnus-newsgroup-%s"
8304                                                     (caar marks)))))))
8305                       ;; Copy the marks to other group.
8306                       (gnus-add-marked-articles
8307                        to-group (cdar marks) (list to-article) info)))
8308                   (setq marks (cdr marks)))
8309
8310                 (gnus-request-set-mark to-group (list (list (list to-article)
8311                                                             'add
8312                                                             to-marks))))
8313
8314               (gnus-dribble-enter
8315                (concat "(gnus-group-set-info '"
8316                        (gnus-prin1-to-string (gnus-get-info to-group))
8317                        ")"))))
8318
8319           ;; Update the Xref header in this article to point to
8320           ;; the new crossposted article we have just created.
8321           (when (eq action 'crosspost)
8322             (save-excursion
8323               (set-buffer copy-buf)
8324               (gnus-request-article-this-buffer article gnus-newsgroup-name)
8325               (nnheader-replace-header "Xref" new-xref)
8326               (gnus-request-replace-article
8327                article gnus-newsgroup-name (current-buffer)))))
8328
8329         ;;;!!!Why is this necessary?
8330         (set-buffer gnus-summary-buffer)
8331
8332         (gnus-summary-goto-subject article)
8333         (when (eq action 'move)
8334           (gnus-summary-mark-article article gnus-canceled-mark))))
8335       (gnus-summary-remove-process-mark article))
8336     ;; Re-activate all groups that have been moved to.
8337     (save-excursion
8338       (set-buffer gnus-group-buffer)
8339       (let ((gnus-group-marked to-groups))
8340         (gnus-group-get-new-news-this-group nil t)))
8341
8342     (gnus-kill-buffer copy-buf)
8343     (gnus-summary-position-point)
8344     (gnus-set-mode-line 'summary)))
8345
8346 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
8347   "Move the current article to a different newsgroup.
8348 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8349 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8350 re-spool using this method."
8351   (interactive "P")
8352   (gnus-summary-move-article n to-newsgroup select-method 'copy))
8353
8354 (defun gnus-summary-crosspost-article (&optional n)
8355   "Crosspost the current article to some other group."
8356   (interactive "P")
8357   (gnus-summary-move-article n nil nil 'crosspost))
8358
8359 (defcustom gnus-summary-respool-default-method nil
8360   "Default method for respooling an article.
8361 If nil, use to the current newsgroup method."
8362   :type '(choice (gnus-select-method :value (nnml ""))
8363                  (const nil))
8364   :group 'gnus-summary-mail)
8365
8366 (defun gnus-summary-respool-article (&optional n method)
8367   "Respool the current article.
8368 The article will be squeezed through the mail spooling process again,
8369 which means that it will be put in some mail newsgroup or other
8370 depending on `nnmail-split-methods'.
8371 If N is a positive number, respool the N next articles.
8372 If N is a negative number, respool the N previous articles.
8373 If N is nil and any articles have been marked with the process mark,
8374 respool those articles instead.
8375
8376 Respooling can be done both from mail groups and \"real\" newsgroups.
8377 In the former case, the articles in question will be moved from the
8378 current group into whatever groups they are destined to.  In the
8379 latter case, they will be copied into the relevant groups."
8380   (interactive
8381    (list current-prefix-arg
8382          (let* ((methods (gnus-methods-using 'respool))
8383                 (methname
8384                  (symbol-name (or gnus-summary-respool-default-method
8385                                   (car (gnus-find-method-for-group
8386                                         gnus-newsgroup-name)))))
8387                 (method
8388                  (gnus-completing-read
8389                   methname "What backend do you want to use when respooling?"
8390                   methods nil t nil 'gnus-mail-method-history))
8391                 ms)
8392            (cond
8393             ((zerop (length (setq ms (gnus-servers-using-backend
8394                                       (intern method)))))
8395              (list (intern method) ""))
8396             ((= 1 (length ms))
8397              (car ms))
8398             (t
8399              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
8400                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
8401                            ms-alist))))))))
8402   (unless method
8403     (error "No method given for respooling"))
8404   (if (assoc (symbol-name
8405               (car (gnus-find-method-for-group gnus-newsgroup-name)))
8406              (gnus-methods-using 'respool))
8407       (gnus-summary-move-article n nil method)
8408     (gnus-summary-copy-article n nil method)))
8409
8410 (defun gnus-summary-import-article (file &optional edit)
8411   "Import an arbitrary file into a mail newsgroup."
8412   (interactive "fImport file: \nP")
8413   (let ((group gnus-newsgroup-name)
8414         (now (current-time))
8415         atts lines group-art)
8416     (unless (gnus-check-backend-function 'request-accept-article group)
8417       (error "%s does not support article importing" group))
8418     (or (file-readable-p file)
8419         (not (file-regular-p file))
8420         (error "Can't read %s" file))
8421     (save-excursion
8422       (set-buffer (gnus-get-buffer-create " *import file*"))
8423       (erase-buffer)
8424       (nnheader-insert-file-contents file)
8425       (goto-char (point-min))
8426       (if (nnheader-article-p)
8427           (save-restriction
8428             (goto-char (point-min))
8429             (search-forward "\n\n" nil t)
8430             (narrow-to-region (point-min) (1- (point)))
8431             (goto-char (point-min))
8432             (unless (re-search-forward "^date:" nil t)
8433               (goto-char (point-max))
8434               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
8435         ;; This doesn't look like an article, so we fudge some headers.
8436         (setq atts (file-attributes file)
8437               lines (count-lines (point-min) (point-max)))
8438         (insert "From: " (read-string "From: ") "\n"
8439                 "Subject: " (read-string "Subject: ") "\n"
8440                 "Date: " (message-make-date (nth 5 atts)) "\n"
8441                 "Message-ID: " (message-make-message-id) "\n"
8442                 "Lines: " (int-to-string lines) "\n"
8443                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
8444       (setq group-art (gnus-request-accept-article group nil t))
8445       (kill-buffer (current-buffer)))
8446     (setq gnus-newsgroup-active (gnus-activate-group group))
8447     (forward-line 1)
8448     (gnus-summary-goto-article (cdr group-art) nil t)
8449     (when edit
8450       (gnus-summary-edit-article))))
8451
8452 (defun gnus-summary-create-article ()
8453   "Create an article in a mail newsgroup."
8454   (interactive)
8455   (let ((group gnus-newsgroup-name)
8456         (now (current-time))
8457         group-art)
8458     (unless (gnus-check-backend-function 'request-accept-article group)
8459       (error "%s does not support article importing" group))
8460     (save-excursion
8461       (set-buffer (gnus-get-buffer-create " *import file*"))
8462       (erase-buffer)
8463       (goto-char (point-min))
8464       ;; This doesn't look like an article, so we fudge some headers.
8465       (insert "From: " (read-string "From: ") "\n"
8466               "Subject: " (read-string "Subject: ") "\n"
8467               "Date: " (message-make-date now) "\n"
8468               "Message-ID: " (message-make-message-id) "\n")
8469       (setq group-art (gnus-request-accept-article group nil t))
8470       (kill-buffer (current-buffer)))
8471     (setq gnus-newsgroup-active (gnus-activate-group group))
8472     (forward-line 1)
8473     (gnus-summary-goto-article (cdr group-art) nil t)
8474     (gnus-summary-edit-article)))
8475
8476 (defun gnus-summary-article-posted-p ()
8477   "Say whether the current (mail) article is available from news as well.
8478 This will be the case if the article has both been mailed and posted."
8479   (interactive)
8480   (let ((id (mail-header-references (gnus-summary-article-header)))
8481         (gnus-override-method (car (gnus-refer-article-methods))))
8482     (if (gnus-request-head id "")
8483         (gnus-message 2 "The current message was found on %s"
8484                       gnus-override-method)
8485       (gnus-message 2 "The current message couldn't be found on %s"
8486                     gnus-override-method)
8487       nil)))
8488
8489 (defun gnus-summary-expire-articles (&optional now)
8490   "Expire all articles that are marked as expirable in the current group."
8491   (interactive)
8492   (when (gnus-check-backend-function
8493          'request-expire-articles gnus-newsgroup-name)
8494     ;; This backend supports expiry.
8495     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
8496            (expirable (if total
8497                           (progn
8498                             ;; We need to update the info for
8499                             ;; this group for `gnus-list-of-read-articles'
8500                             ;; to give us the right answer.
8501                             (gnus-run-hooks 'gnus-exit-group-hook)
8502                             (gnus-summary-update-info)
8503                             (gnus-list-of-read-articles gnus-newsgroup-name))
8504                         (setq gnus-newsgroup-expirable
8505                               (sort gnus-newsgroup-expirable '<))))
8506            (expiry-wait (if now 'immediate
8507                           (gnus-group-find-parameter
8508                            gnus-newsgroup-name 'expiry-wait)))
8509            (nnmail-expiry-target
8510             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
8511                 nnmail-expiry-target))
8512            es)
8513       (when expirable
8514         ;; There are expirable articles in this group, so we run them
8515         ;; through the expiry process.
8516         (gnus-message 6 "Expiring articles...")
8517         (unless (gnus-check-group gnus-newsgroup-name)
8518           (error "Can't open server for %s" gnus-newsgroup-name))
8519         ;; The list of articles that weren't expired is returned.
8520         (save-excursion
8521           (if expiry-wait
8522               (let ((nnmail-expiry-wait-function nil)
8523                     (nnmail-expiry-wait expiry-wait))
8524                 (setq es (gnus-request-expire-articles
8525                           expirable gnus-newsgroup-name)))
8526             (setq es (gnus-request-expire-articles
8527                       expirable gnus-newsgroup-name)))
8528           (unless total
8529             (setq gnus-newsgroup-expirable es))
8530           ;; We go through the old list of expirable, and mark all
8531           ;; really expired articles as nonexistent.
8532           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
8533             (let ((gnus-use-cache nil))
8534               (while expirable
8535                 (unless (memq (car expirable) es)
8536                   (when (gnus-data-find (car expirable))
8537                     (gnus-summary-mark-article
8538                      (car expirable) gnus-canceled-mark)))
8539                 (setq expirable (cdr expirable))))))
8540         (gnus-message 6 "Expiring articles...done")))))
8541
8542 (defun gnus-summary-expire-articles-now ()
8543   "Expunge all expirable articles in the current group.
8544 This means that *all* articles that are marked as expirable will be
8545 deleted forever, right now."
8546   (interactive)
8547   (or gnus-expert-user
8548       (gnus-yes-or-no-p
8549        "Are you really, really, really sure you want to delete all these messages? ")
8550       (error "Phew!"))
8551   (gnus-summary-expire-articles t))
8552
8553 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
8554 (defun gnus-summary-delete-article (&optional n)
8555   "Delete the N next (mail) articles.
8556 This command actually deletes articles.  This is not a marking
8557 command.  The article will disappear forever from your life, never to
8558 return.
8559 If N is negative, delete backwards.
8560 If N is nil and articles have been marked with the process mark,
8561 delete these instead."
8562   (interactive "P")
8563   (unless (gnus-check-backend-function 'request-expire-articles
8564                                        gnus-newsgroup-name)
8565     (error "The current newsgroup does not support article deletion"))
8566   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
8567     (error "Couldn't open server"))
8568   ;; Compute the list of articles to delete.
8569   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
8570         not-deleted)
8571     (if (and gnus-novice-user
8572              (not (gnus-yes-or-no-p
8573                    (format "Do you really want to delete %s forever? "
8574                            (if (> (length articles) 1)
8575                                (format "these %s articles" (length articles))
8576                              "this article")))))
8577         ()
8578       ;; Delete the articles.
8579       (setq not-deleted (gnus-request-expire-articles
8580                          articles gnus-newsgroup-name 'force))
8581       (while articles
8582         (gnus-summary-remove-process-mark (car articles))
8583         ;; The backend might not have been able to delete the article
8584         ;; after all.
8585         (unless (memq (car articles) not-deleted)
8586           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
8587         (setq articles (cdr articles)))
8588       (when not-deleted
8589         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
8590     (gnus-summary-position-point)
8591     (gnus-set-mode-line 'summary)
8592     not-deleted))
8593
8594 (defun gnus-summary-edit-article (&optional force)
8595   "Edit the current article.
8596 This will have permanent effect only in mail groups.
8597 If FORCE is non-nil, allow editing of articles even in read-only
8598 groups."
8599   (interactive "P")
8600   (save-excursion
8601     (set-buffer gnus-summary-buffer)
8602     (let ((mail-parse-charset gnus-newsgroup-charset)
8603           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
8604       (gnus-set-global-variables)
8605       (when (and (not force)
8606                  (gnus-group-read-only-p))
8607         (error "The current newsgroup does not support article editing"))
8608       (gnus-summary-show-article t)
8609       (gnus-article-edit-article
8610        'ignore
8611        `(lambda (no-highlight)
8612           (let ((mail-parse-charset ',gnus-newsgroup-charset)
8613                 (message-options message-options)
8614                 (message-options-set-recipient)
8615                 (mail-parse-ignored-charsets
8616                  ',gnus-newsgroup-ignored-charsets))
8617             (gnus-summary-edit-article-done
8618              ,(or (mail-header-references gnus-current-headers) "")
8619              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
8620
8621 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
8622
8623 (defun gnus-summary-edit-article-done (&optional references read-only buffer
8624                                                  no-highlight)
8625   "Make edits to the current article permanent."
8626   (interactive)
8627   (save-excursion
8628     ;; The buffer restriction contains the entire article if it exists.
8629     (when (article-goto-body)
8630       (let ((lines (count-lines (point) (point-max)))
8631             (length (- (point-max) (point)))
8632             (case-fold-search t)
8633             (body (copy-marker (point))))
8634         (goto-char (point-min))
8635         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
8636           (delete-region (match-beginning 1) (match-end 1))
8637           (insert (number-to-string length)))
8638         (goto-char (point-min))
8639         (when (re-search-forward
8640                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
8641           (delete-region (match-beginning 1) (match-end 1))
8642           (insert (number-to-string length)))
8643         (goto-char (point-min))
8644         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
8645           (delete-region (match-beginning 1) (match-end 1))
8646           (insert (number-to-string lines))))))
8647   ;; Replace the article.
8648   (let ((buf (current-buffer)))
8649     (with-temp-buffer
8650       (insert-buffer-substring buf)
8651
8652       (if (and (not read-only)
8653                (not (gnus-request-replace-article
8654                      (cdr gnus-article-current) (car gnus-article-current)
8655                      (current-buffer) t)))
8656           (error "Couldn't replace article")
8657         ;; Update the summary buffer.
8658         (if (and references
8659                  (equal (message-tokenize-header references " ")
8660                         (message-tokenize-header
8661                          (or (message-fetch-field "references") "") " ")))
8662             ;; We only have to update this line.
8663             (save-excursion
8664               (save-restriction
8665                 (message-narrow-to-head)
8666                 (let ((head (buffer-string))
8667                       header)
8668                   (with-temp-buffer
8669                     (insert (format "211 %d Article retrieved.\n"
8670                                     (cdr gnus-article-current)))
8671                     (insert head)
8672                     (insert ".\n")
8673                     (let ((nntp-server-buffer (current-buffer)))
8674                       (setq header (car (gnus-get-newsgroup-headers
8675                                          (save-excursion
8676                                            (set-buffer gnus-summary-buffer)
8677                                            gnus-newsgroup-dependencies)
8678                                          t))))
8679                     (save-excursion
8680                       (set-buffer gnus-summary-buffer)
8681                       (gnus-data-set-header
8682                        (gnus-data-find (cdr gnus-article-current))
8683                        header)
8684                       (gnus-summary-update-article-line
8685                        (cdr gnus-article-current) header)
8686                       (if (gnus-summary-goto-subject
8687                            (cdr gnus-article-current) nil t)
8688                           (gnus-summary-update-secondary-mark
8689                            (cdr gnus-article-current))))))))
8690           ;; Update threads.
8691           (set-buffer (or buffer gnus-summary-buffer))
8692           (gnus-summary-update-article (cdr gnus-article-current))
8693           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8694               (gnus-summary-update-secondary-mark
8695                (cdr gnus-article-current))))
8696         ;; Prettify the article buffer again.
8697         (unless no-highlight
8698           (save-excursion
8699             (set-buffer gnus-article-buffer)
8700             ;;;!!! Fix this -- article should be rehighlighted.
8701             ;;;(gnus-run-hooks 'gnus-article-display-hook)
8702             (set-buffer gnus-original-article-buffer)
8703             (gnus-request-article
8704              (cdr gnus-article-current)
8705              (car gnus-article-current) (current-buffer))))
8706         ;; Prettify the summary buffer line.
8707         (when (gnus-visual-p 'summary-highlight 'highlight)
8708           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
8709
8710 (defun gnus-summary-edit-wash (key)
8711   "Perform editing command KEY in the article buffer."
8712   (interactive
8713    (list
8714     (progn
8715       (message "%s" (concat (this-command-keys) "- "))
8716       (read-char))))
8717   (message "")
8718   (gnus-summary-edit-article)
8719   (execute-kbd-macro (concat (this-command-keys) key))
8720   (gnus-article-edit-done))
8721
8722 (defun gnus-summary-toggle-smiley (&optional arg)
8723   "Toggle the display of smilies as small graphical icons."
8724   (interactive "P")
8725   (save-excursion
8726     (set-buffer gnus-article-buffer)
8727     (gnus-smiley-display arg)))
8728
8729 ;;; Respooling
8730
8731 (defun gnus-summary-respool-query (&optional silent trace)
8732   "Query where the respool algorithm would put this article."
8733   (interactive)
8734   (let (gnus-mark-article-hook)
8735     (gnus-summary-select-article)
8736     (save-excursion
8737       (set-buffer gnus-original-article-buffer)
8738       (save-restriction
8739         (message-narrow-to-head)
8740         (let ((groups (nnmail-article-group 'identity trace)))
8741           (unless silent
8742             (if groups
8743                 (message "This message would go to %s"
8744                          (mapconcat 'car groups ", "))
8745               (message "This message would go to no groups"))
8746             groups))))))
8747
8748 (defun gnus-summary-respool-trace ()
8749   "Trace where the respool algorithm would put this article.
8750 Display a buffer showing all fancy splitting patterns which matched."
8751   (interactive)
8752   (gnus-summary-respool-query nil t))
8753
8754 ;; Summary marking commands.
8755
8756 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
8757   "Mark articles which has the same subject as read, and then select the next.
8758 If UNMARK is positive, remove any kind of mark.
8759 If UNMARK is negative, tick articles."
8760   (interactive "P")
8761   (when unmark
8762     (setq unmark (prefix-numeric-value unmark)))
8763   (let ((count
8764          (gnus-summary-mark-same-subject
8765           (gnus-summary-article-subject) unmark)))
8766     ;; Select next unread article.  If auto-select-same mode, should
8767     ;; select the first unread article.
8768     (gnus-summary-next-article t (and gnus-auto-select-same
8769                                       (gnus-summary-article-subject)))
8770     (gnus-message 7 "%d article%s marked as %s"
8771                   count (if (= count 1) " is" "s are")
8772                   (if unmark "unread" "read"))))
8773
8774 (defun gnus-summary-kill-same-subject (&optional unmark)
8775   "Mark articles which has the same subject as read.
8776 If UNMARK is positive, remove any kind of mark.
8777 If UNMARK is negative, tick articles."
8778   (interactive "P")
8779   (when unmark
8780     (setq unmark (prefix-numeric-value unmark)))
8781   (let ((count
8782          (gnus-summary-mark-same-subject
8783           (gnus-summary-article-subject) unmark)))
8784     ;; If marked as read, go to next unread subject.
8785     (when (null unmark)
8786       ;; Go to next unread subject.
8787       (gnus-summary-next-subject 1 t))
8788     (gnus-message 7 "%d articles are marked as %s"
8789                   count (if unmark "unread" "read"))))
8790
8791 (defun gnus-summary-mark-same-subject (subject &optional unmark)
8792   "Mark articles with same SUBJECT as read, and return marked number.
8793 If optional argument UNMARK is positive, remove any kinds of marks.
8794 If optional argument UNMARK is negative, mark articles as unread instead."
8795   (let ((count 1))
8796     (save-excursion
8797       (cond
8798        ((null unmark)                   ; Mark as read.
8799         (while (and
8800                 (progn
8801                   (gnus-summary-mark-article-as-read gnus-killed-mark)
8802                   (gnus-summary-show-thread) t)
8803                 (gnus-summary-find-subject subject))
8804           (setq count (1+ count))))
8805        ((> unmark 0)                    ; Tick.
8806         (while (and
8807                 (progn
8808                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
8809                   (gnus-summary-show-thread) t)
8810                 (gnus-summary-find-subject subject))
8811           (setq count (1+ count))))
8812        (t                               ; Mark as unread.
8813         (while (and
8814                 (progn
8815                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
8816                   (gnus-summary-show-thread) t)
8817                 (gnus-summary-find-subject subject))
8818           (setq count (1+ count)))))
8819       (gnus-set-mode-line 'summary)
8820       ;; Return the number of marked articles.
8821       count)))
8822
8823 (defun gnus-summary-mark-as-processable (n &optional unmark)
8824   "Set the process mark on the next N articles.
8825 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
8826 the process mark instead.  The difference between N and the actual
8827 number of articles marked is returned."
8828   (interactive "P")
8829   (if (and (null n) (gnus-region-active-p))
8830       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
8831     (setq n (prefix-numeric-value n))
8832     (let ((backward (< n 0))
8833           (n (abs n)))
8834       (while (and
8835               (> n 0)
8836               (if unmark
8837                   (gnus-summary-remove-process-mark
8838                    (gnus-summary-article-number))
8839                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
8840               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
8841         (setq n (1- n)))
8842       (when (/= 0 n)
8843         (gnus-message 7 "No more articles"))
8844       (gnus-summary-recenter)
8845       (gnus-summary-position-point)
8846       n)))
8847
8848 (defun gnus-summary-unmark-as-processable (n)
8849   "Remove the process mark from the next N articles.
8850 If N is negative, unmark backward instead.  The difference between N and
8851 the actual number of articles unmarked is returned."
8852   (interactive "P")
8853   (gnus-summary-mark-as-processable n t))
8854
8855 (defun gnus-summary-unmark-all-processable ()
8856   "Remove the process mark from all articles."
8857   (interactive)
8858   (save-excursion
8859     (while gnus-newsgroup-processable
8860       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
8861   (gnus-summary-position-point))
8862
8863 (defun gnus-summary-add-mark (article type)
8864   "Mark ARTICLE with a mark of TYPE."
8865   (let ((vtype (car (assq type gnus-article-mark-lists)))
8866         var)
8867     (if (not vtype)
8868         (error "No such mark type: %s" type)
8869       (setq var (intern (format "gnus-newsgroup-%s" type)))
8870       (set var (cons article (symbol-value var)))
8871       (if (memq type '(processable cached replied forwarded recent saved))
8872           (gnus-summary-update-secondary-mark article)
8873         ;;; !!! This is bogus.  We should find out what primary
8874         ;;; !!! mark we want to set.
8875         (gnus-summary-update-mark gnus-del-mark 'unread)))))
8876
8877 (defun gnus-summary-mark-as-expirable (n)
8878   "Mark N articles forward as expirable.
8879 If N is negative, mark backward instead.  The difference between N and
8880 the actual number of articles marked is returned."
8881   (interactive "p")
8882   (gnus-summary-mark-forward n gnus-expirable-mark))
8883
8884 (defun gnus-summary-mark-article-as-replied (article)
8885   "Mark ARTICLE as replied to and update the summary line.
8886 ARTICLE can also be a list of articles."
8887   (interactive (list (gnus-summary-article-number)))
8888   (let ((articles (if (listp article) article (list article))))
8889     (dolist (article articles)
8890       (push article gnus-newsgroup-replied)
8891       (let ((buffer-read-only nil))
8892         (when (gnus-summary-goto-subject article nil t)
8893           (gnus-summary-update-secondary-mark article))))))
8894
8895 (defun gnus-summary-mark-article-as-forwarded (article)
8896   "Mark ARTICLE as forwarded and update the summary line.
8897 ARTICLE can also be a list of articles."
8898   (let ((articles (if (listp article) article (list article))))
8899     (dolist (article articles)
8900       (push article gnus-newsgroup-forwarded)
8901       (let ((buffer-read-only nil))
8902         (when (gnus-summary-goto-subject article nil t)
8903           (gnus-summary-update-secondary-mark article))))))
8904
8905 (defun gnus-summary-set-bookmark (article)
8906   "Set a bookmark in current article."
8907   (interactive (list (gnus-summary-article-number)))
8908   (when (or (not (get-buffer gnus-article-buffer))
8909             (not gnus-current-article)
8910             (not gnus-article-current)
8911             (not (equal gnus-newsgroup-name (car gnus-article-current))))
8912     (error "No current article selected"))
8913   ;; Remove old bookmark, if one exists.
8914   (let ((old (assq article gnus-newsgroup-bookmarks)))
8915     (when old
8916       (setq gnus-newsgroup-bookmarks
8917             (delq old gnus-newsgroup-bookmarks))))
8918   ;; Set the new bookmark, which is on the form
8919   ;; (article-number . line-number-in-body).
8920   (push
8921    (cons article
8922          (save-excursion
8923            (set-buffer gnus-article-buffer)
8924            (count-lines
8925             (min (point)
8926                  (save-excursion
8927                    (goto-char (point-min))
8928                    (search-forward "\n\n" nil t)
8929                    (point)))
8930             (point))))
8931    gnus-newsgroup-bookmarks)
8932   (gnus-message 6 "A bookmark has been added to the current article."))
8933
8934 (defun gnus-summary-remove-bookmark (article)
8935   "Remove the bookmark from the current article."
8936   (interactive (list (gnus-summary-article-number)))
8937   ;; Remove old bookmark, if one exists.
8938   (let ((old (assq article gnus-newsgroup-bookmarks)))
8939     (if old
8940         (progn
8941           (setq gnus-newsgroup-bookmarks
8942                 (delq old gnus-newsgroup-bookmarks))
8943           (gnus-message 6 "Removed bookmark."))
8944       (gnus-message 6 "No bookmark in current article."))))
8945
8946 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
8947 (defun gnus-summary-mark-as-dormant (n)
8948   "Mark N articles forward as dormant.
8949 If N is negative, mark backward instead.  The difference between N and
8950 the actual number of articles marked is returned."
8951   (interactive "p")
8952   (gnus-summary-mark-forward n gnus-dormant-mark))
8953
8954 (defun gnus-summary-set-process-mark (article)
8955   "Set the process mark on ARTICLE and update the summary line."
8956   (setq gnus-newsgroup-processable
8957         (cons article
8958               (delq article gnus-newsgroup-processable)))
8959   (when (gnus-summary-goto-subject article)
8960     (gnus-summary-show-thread)
8961     (gnus-summary-goto-subject article)
8962     (gnus-summary-update-secondary-mark article)))
8963
8964 (defun gnus-summary-remove-process-mark (article)
8965   "Remove the process mark from ARTICLE and update the summary line."
8966   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
8967   (when (gnus-summary-goto-subject article)
8968     (gnus-summary-show-thread)
8969     (gnus-summary-goto-subject article)
8970     (gnus-summary-update-secondary-mark article)))
8971
8972 (defun gnus-summary-set-saved-mark (article)
8973   "Set the process mark on ARTICLE and update the summary line."
8974   (push article gnus-newsgroup-saved)
8975   (when (gnus-summary-goto-subject article)
8976     (gnus-summary-update-secondary-mark article)))
8977
8978 (defun gnus-summary-mark-forward (n &optional mark no-expire)
8979   "Mark N articles as read forwards.
8980 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
8981 The difference between N and the actual number of articles marked is
8982 returned.
8983 Iff NO-EXPIRE, auto-expiry will be inhibited."
8984   (interactive "p")
8985   (gnus-summary-show-thread)
8986   (let ((backward (< n 0))
8987         (gnus-summary-goto-unread
8988          (and gnus-summary-goto-unread
8989               (not (eq gnus-summary-goto-unread 'never))
8990               (not (memq mark (list gnus-unread-mark
8991                                     gnus-ticked-mark gnus-dormant-mark)))))
8992         (n (abs n))
8993         (mark (or mark gnus-del-mark)))
8994     (while (and (> n 0)
8995                 (gnus-summary-mark-article nil mark no-expire)
8996                 (zerop (gnus-summary-next-subject
8997                         (if backward -1 1)
8998                         (and gnus-summary-goto-unread
8999                              (not (eq gnus-summary-goto-unread 'never)))
9000                         t)))
9001       (setq n (1- n)))
9002     (when (/= 0 n)
9003       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9004     (gnus-summary-recenter)
9005     (gnus-summary-position-point)
9006     (gnus-set-mode-line 'summary)
9007     n))
9008
9009 (defun gnus-summary-mark-article-as-read (mark)
9010   "Mark the current article quickly as read with MARK."
9011   (let ((article (gnus-summary-article-number)))
9012     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9013     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9014     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9015     (push (cons article mark) gnus-newsgroup-reads)
9016     ;; Possibly remove from cache, if that is used.
9017     (when gnus-use-cache
9018       (gnus-cache-enter-remove-article article))
9019     ;; Allow the backend to change the mark.
9020     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9021     ;; Check for auto-expiry.
9022     (when (and gnus-newsgroup-auto-expire
9023                (memq mark gnus-auto-expirable-marks))
9024       (setq mark gnus-expirable-mark)
9025       ;; Let the backend know about the mark change.
9026       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9027       (push article gnus-newsgroup-expirable))
9028     ;; Set the mark in the buffer.
9029     (gnus-summary-update-mark mark 'unread)
9030     t))
9031
9032 (defun gnus-summary-mark-article-as-unread (mark)
9033   "Mark the current article quickly as unread with MARK."
9034   (let* ((article (gnus-summary-article-number))
9035          (old-mark (gnus-summary-article-mark article)))
9036     ;; Allow the backend to change the mark.
9037     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9038     (if (eq mark old-mark)
9039         t
9040       (if (<= article 0)
9041           (progn
9042             (gnus-error 1 "Can't mark negative article numbers")
9043             nil)
9044         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9045         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9046         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9047         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9048         (cond ((= mark gnus-ticked-mark)
9049                (push article gnus-newsgroup-marked))
9050               ((= mark gnus-dormant-mark)
9051                (push article gnus-newsgroup-dormant))
9052               (t
9053                (push article gnus-newsgroup-unreads)))
9054         (gnus-pull article gnus-newsgroup-reads)
9055
9056         ;; See whether the article is to be put in the cache.
9057         (and gnus-use-cache
9058              (vectorp (gnus-summary-article-header article))
9059              (save-excursion
9060                (gnus-cache-possibly-enter-article
9061                 gnus-newsgroup-name article
9062                 (gnus-summary-article-header article)
9063                 (= mark gnus-ticked-mark)
9064                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9065
9066         ;; Fix the mark.
9067         (gnus-summary-update-mark mark 'unread)
9068         t))))
9069
9070 (defun gnus-summary-mark-article (&optional article mark no-expire)
9071   "Mark ARTICLE with MARK.  MARK can be any character.
9072 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9073 `??' (dormant) and `?E' (expirable).
9074 If MARK is nil, then the default character `?r' is used.
9075 If ARTICLE is nil, then the article on the current line will be
9076 marked.
9077 Iff NO-EXPIRE, auto-expiry will be inhibited."
9078   ;; The mark might be a string.
9079   (when (stringp mark)
9080     (setq mark (aref mark 0)))
9081   ;; If no mark is given, then we check auto-expiring.
9082   (when (null mark)
9083     (setq mark gnus-del-mark))
9084   (when (and (not no-expire)
9085              gnus-newsgroup-auto-expire
9086              (memq mark gnus-auto-expirable-marks))
9087     (setq mark gnus-expirable-mark))
9088   (let ((article (or article (gnus-summary-article-number)))
9089         (old-mark (gnus-summary-article-mark article)))
9090     ;; Allow the backend to change the mark.
9091     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9092     (if (eq mark old-mark)
9093         t
9094       (unless article
9095         (error "No article on current line"))
9096       (if (not (if (or (= mark gnus-unread-mark)
9097                        (= mark gnus-ticked-mark)
9098                        (= mark gnus-dormant-mark))
9099                    (gnus-mark-article-as-unread article mark)
9100                  (gnus-mark-article-as-read article mark)))
9101           t
9102         ;; See whether the article is to be put in the cache.
9103         (and gnus-use-cache
9104              (not (= mark gnus-canceled-mark))
9105              (vectorp (gnus-summary-article-header article))
9106              (save-excursion
9107                (gnus-cache-possibly-enter-article
9108                 gnus-newsgroup-name article
9109                 (gnus-summary-article-header article)
9110                 (= mark gnus-ticked-mark)
9111                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9112
9113         (when (gnus-summary-goto-subject article nil t)
9114           (let ((buffer-read-only nil))
9115             (gnus-summary-show-thread)
9116             ;; Fix the mark.
9117             (gnus-summary-update-mark mark 'unread)
9118             t))))))
9119
9120 (defun gnus-summary-update-secondary-mark (article)
9121   "Update the secondary (read, process, cache) mark."
9122   (gnus-summary-update-mark
9123    (cond ((memq article gnus-newsgroup-processable)
9124           gnus-process-mark)
9125          ((memq article gnus-newsgroup-cached)
9126           gnus-cached-mark)
9127          ((memq article gnus-newsgroup-replied)
9128           gnus-replied-mark)
9129          ((memq article gnus-newsgroup-forwarded)
9130           gnus-forwarded-mark)
9131          ((memq article gnus-newsgroup-saved)
9132           gnus-saved-mark)
9133          ((memq article gnus-newsgroup-recent)
9134           gnus-recent-mark)
9135          ((memq article gnus-newsgroup-unseen)
9136           gnus-unseen-mark)
9137          (t gnus-no-mark))
9138    'replied)
9139   (when (gnus-visual-p 'summary-highlight 'highlight)
9140     (gnus-run-hooks 'gnus-summary-update-hook))
9141   t)
9142
9143 (defun gnus-summary-update-mark (mark type)
9144   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9145         (buffer-read-only nil))
9146     (re-search-backward "[\n\r]" (gnus-point-at-bol) 'move-to-limit)
9147     (when forward
9148       (when (looking-at "\r")
9149         (incf forward))
9150       (when (<= (+ forward (point)) (point-max))
9151         ;; Go to the right position on the line.
9152         (goto-char (+ forward (point)))
9153         ;; Replace the old mark with the new mark.
9154         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
9155         ;; Optionally update the marks by some user rule.
9156         (when (eq type 'unread)
9157           (gnus-data-set-mark
9158            (gnus-data-find (gnus-summary-article-number)) mark)
9159           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
9160
9161 (defun gnus-mark-article-as-read (article &optional mark)
9162   "Enter ARTICLE in the pertinent lists and remove it from others."
9163   ;; Make the article expirable.
9164   (let ((mark (or mark gnus-del-mark)))
9165     (if (= mark gnus-expirable-mark)
9166         (push article gnus-newsgroup-expirable)
9167       (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)))
9168     ;; Remove from unread and marked lists.
9169     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9170     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9171     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9172     (push (cons article mark) gnus-newsgroup-reads)
9173     ;; Possibly remove from cache, if that is used.
9174     (when gnus-use-cache
9175       (gnus-cache-enter-remove-article article))
9176     t))
9177
9178 (defun gnus-mark-article-as-unread (article &optional mark)
9179   "Enter ARTICLE in the pertinent lists and remove it from others."
9180   (let ((mark (or mark gnus-ticked-mark)))
9181     (if (<= article 0)
9182         (progn
9183           (gnus-error 1 "Can't mark negative article numbers")
9184           nil)
9185       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
9186             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
9187             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
9188             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9189
9190       ;; Unsuppress duplicates?
9191       (when gnus-suppress-duplicates
9192         (gnus-dup-unsuppress-article article))
9193
9194       (cond ((= mark gnus-ticked-mark)
9195              (push article gnus-newsgroup-marked))
9196             ((= mark gnus-dormant-mark)
9197              (push article gnus-newsgroup-dormant))
9198             (t
9199              (push article gnus-newsgroup-unreads)))
9200       (gnus-pull article gnus-newsgroup-reads)
9201       t)))
9202
9203 (defalias 'gnus-summary-mark-as-unread-forward
9204   'gnus-summary-tick-article-forward)
9205 (make-obsolete 'gnus-summary-mark-as-unread-forward
9206                'gnus-summary-tick-article-forward)
9207 (defun gnus-summary-tick-article-forward (n)
9208   "Tick N articles forwards.
9209 If N is negative, tick backwards instead.
9210 The difference between N and the number of articles ticked is returned."
9211   (interactive "p")
9212   (gnus-summary-mark-forward n gnus-ticked-mark))
9213
9214 (defalias 'gnus-summary-mark-as-unread-backward
9215   'gnus-summary-tick-article-backward)
9216 (make-obsolete 'gnus-summary-mark-as-unread-backward
9217                'gnus-summary-tick-article-backward)
9218 (defun gnus-summary-tick-article-backward (n)
9219   "Tick N articles backwards.
9220 The difference between N and the number of articles ticked is returned."
9221   (interactive "p")
9222   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
9223
9224 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9225 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
9226 (defun gnus-summary-tick-article (&optional article clear-mark)
9227   "Mark current article as unread.
9228 Optional 1st argument ARTICLE specifies article number to be marked as unread.
9229 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
9230   (interactive)
9231   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
9232                                        gnus-ticked-mark)))
9233
9234 (defun gnus-summary-mark-as-read-forward (n)
9235   "Mark N articles as read forwards.
9236 If N is negative, mark backwards instead.
9237 The difference between N and the actual number of articles marked is
9238 returned."
9239   (interactive "p")
9240   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
9241
9242 (defun gnus-summary-mark-as-read-backward (n)
9243   "Mark the N articles as read backwards.
9244 The difference between N and the actual number of articles marked is
9245 returned."
9246   (interactive "p")
9247   (gnus-summary-mark-forward
9248    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
9249
9250 (defun gnus-summary-mark-as-read (&optional article mark)
9251   "Mark current article as read.
9252 ARTICLE specifies the article to be marked as read.
9253 MARK specifies a string to be inserted at the beginning of the line."
9254   (gnus-summary-mark-article article mark))
9255
9256 (defun gnus-summary-clear-mark-forward (n)
9257   "Clear marks from N articles forward.
9258 If N is negative, clear backward instead.
9259 The difference between N and the number of marks cleared is returned."
9260   (interactive "p")
9261   (gnus-summary-mark-forward n gnus-unread-mark))
9262
9263 (defun gnus-summary-clear-mark-backward (n)
9264   "Clear marks from N articles backward.
9265 The difference between N and the number of marks cleared is returned."
9266   (interactive "p")
9267   (gnus-summary-mark-forward (- n) gnus-unread-mark))
9268
9269 (defun gnus-summary-mark-unread-as-read ()
9270   "Intended to be used by `gnus-summary-mark-article-hook'."
9271   (when (memq gnus-current-article gnus-newsgroup-unreads)
9272     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
9273
9274 (defun gnus-summary-mark-read-and-unread-as-read ()
9275   "Intended to be used by `gnus-summary-mark-article-hook'."
9276   (let ((mark (gnus-summary-article-mark)))
9277     (when (or (gnus-unread-mark-p mark)
9278               (gnus-read-mark-p mark))
9279       (gnus-summary-mark-article gnus-current-article gnus-read-mark))))
9280
9281 (defun gnus-summary-mark-unread-as-ticked ()
9282   "Intended to be used by `gnus-summary-mark-article-hook'."
9283   (when (memq gnus-current-article gnus-newsgroup-unreads)
9284     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
9285
9286 (defun gnus-summary-mark-region-as-read (point mark all)
9287   "Mark all unread articles between point and mark as read.
9288 If given a prefix, mark all articles between point and mark as read,
9289 even ticked and dormant ones."
9290   (interactive "r\nP")
9291   (save-excursion
9292     (let (article)
9293       (goto-char point)
9294       (beginning-of-line)
9295       (while (and
9296               (< (point) mark)
9297               (progn
9298                 (when (or all
9299                           (memq (setq article (gnus-summary-article-number))
9300                                 gnus-newsgroup-unreads))
9301                   (gnus-summary-mark-article article gnus-del-mark))
9302                 t)
9303               (gnus-summary-find-next))))))
9304
9305 (defun gnus-summary-mark-below (score mark)
9306   "Mark articles with score less than SCORE with MARK."
9307   (interactive "P\ncMark: ")
9308   (setq score (if score
9309                   (prefix-numeric-value score)
9310                 (or gnus-summary-default-score 0)))
9311   (save-excursion
9312     (set-buffer gnus-summary-buffer)
9313     (goto-char (point-min))
9314     (while
9315         (progn
9316           (and (< (gnus-summary-article-score) score)
9317                (gnus-summary-mark-article nil mark))
9318           (gnus-summary-find-next)))))
9319
9320 (defun gnus-summary-kill-below (&optional score)
9321   "Mark articles with score below SCORE as read."
9322   (interactive "P")
9323   (gnus-summary-mark-below score gnus-killed-mark))
9324
9325 (defun gnus-summary-clear-above (&optional score)
9326   "Clear all marks from articles with score above SCORE."
9327   (interactive "P")
9328   (gnus-summary-mark-above score gnus-unread-mark))
9329
9330 (defun gnus-summary-tick-above (&optional score)
9331   "Tick all articles with score above SCORE."
9332   (interactive "P")
9333   (gnus-summary-mark-above score gnus-ticked-mark))
9334
9335 (defun gnus-summary-mark-above (score mark)
9336   "Mark articles with score over SCORE with MARK."
9337   (interactive "P\ncMark: ")
9338   (setq score (if score
9339                   (prefix-numeric-value score)
9340                 (or gnus-summary-default-score 0)))
9341   (save-excursion
9342     (set-buffer gnus-summary-buffer)
9343     (goto-char (point-min))
9344     (while (and (progn
9345                   (when (> (gnus-summary-article-score) score)
9346                     (gnus-summary-mark-article nil mark))
9347                   t)
9348                 (gnus-summary-find-next)))))
9349
9350 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9351 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
9352 (defun gnus-summary-limit-include-expunged (&optional no-error)
9353   "Display all the hidden articles that were expunged for low scores."
9354   (interactive)
9355   (let ((buffer-read-only nil))
9356     (let ((scored gnus-newsgroup-scored)
9357           headers h)
9358       (while scored
9359         (unless (gnus-summary-article-header (caar scored))
9360           (and (setq h (gnus-number-to-header (caar scored)))
9361                (< (cdar scored) gnus-summary-expunge-below)
9362                (push h headers)))
9363         (setq scored (cdr scored)))
9364       (if (not headers)
9365           (when (not no-error)
9366             (error "No expunged articles hidden"))
9367         (goto-char (point-min))
9368         (push gnus-newsgroup-limit gnus-newsgroup-limits)
9369         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
9370         (mapcar (lambda (x) (push (mail-header-number x)
9371                                   gnus-newsgroup-limit))
9372                 headers)
9373         (gnus-summary-prepare-unthreaded (nreverse headers))
9374         (goto-char (point-min))
9375         (gnus-summary-position-point)
9376         t))))
9377
9378 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
9379   "Mark all unread articles in this newsgroup as read.
9380 If prefix argument ALL is non-nil, ticked and dormant articles will
9381 also be marked as read.
9382 If QUIETLY is non-nil, no questions will be asked.
9383 If TO-HERE is non-nil, it should be a point in the buffer.  All
9384 articles before (after, if REVERSE is set) this point will be marked as read.
9385 Note that this function will only catch up the unread article
9386 in the current summary buffer limitation.
9387 The number of articles marked as read is returned."
9388   (interactive "P")
9389   (prog1
9390       (save-excursion
9391         (when (or quietly
9392                   (not gnus-interactive-catchup) ;Without confirmation?
9393                   gnus-expert-user
9394                   (gnus-y-or-n-p
9395                    (if all
9396                        "Mark absolutely all articles as read? "
9397                      "Mark all unread articles as read? ")))
9398           (if (and not-mark
9399                    (not gnus-newsgroup-adaptive)
9400                    (not gnus-newsgroup-auto-expire)
9401                    (not gnus-suppress-duplicates)
9402                    (or (not gnus-use-cache)
9403                        (eq gnus-use-cache 'passive)))
9404               (progn
9405                 (when all
9406                   (setq gnus-newsgroup-marked nil
9407                         gnus-newsgroup-dormant nil))
9408                 (setq gnus-newsgroup-unreads gnus-newsgroup-downloadable))
9409             ;; We actually mark all articles as canceled, which we
9410             ;; have to do when using auto-expiry or adaptive scoring.
9411             (gnus-summary-show-all-threads)
9412             (if (and to-here reverse)
9413                 (progn
9414                   (goto-char to-here)
9415                   (while (and
9416                           (gnus-summary-mark-article-as-read gnus-catchup-mark)
9417                           (gnus-summary-find-next (not all) nil nil t))))
9418               (when (gnus-summary-first-subject (not all) t)
9419                 (while (and
9420                         (if to-here (< (point) to-here) t)
9421                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
9422                         (gnus-summary-find-next (not all) nil nil t)))))
9423             (gnus-set-mode-line 'summary))
9424           t))
9425     (gnus-summary-position-point)))
9426
9427 (defun gnus-summary-catchup-to-here (&optional all)
9428   "Mark all unticked articles before the current one as read.
9429 If ALL is non-nil, also mark ticked and dormant articles as read."
9430   (interactive "P")
9431   (save-excursion
9432     (gnus-save-hidden-threads
9433       (let ((beg (point)))
9434         ;; We check that there are unread articles.
9435         (when (or all (gnus-summary-find-prev))
9436           (gnus-summary-catchup all t beg)))))
9437   (gnus-summary-position-point))
9438
9439 (defun gnus-summary-catchup-from-here (&optional all)
9440   "Mark all unticked articles after the current one as read.
9441 If ALL is non-nil, also mark ticked and dormant articles as read."
9442   (interactive "P")
9443   (save-excursion
9444     (gnus-save-hidden-threads
9445       (let ((beg (point)))
9446         ;; We check that there are unread articles.
9447         (when (or all (gnus-summary-find-next))
9448           (gnus-summary-catchup all t beg nil t)))))
9449   (gnus-summary-position-point))
9450
9451 (defun gnus-summary-catchup-all (&optional quietly)
9452   "Mark all articles in this newsgroup as read."
9453   (interactive "P")
9454   (gnus-summary-catchup t quietly))
9455
9456 (defun gnus-summary-catchup-and-exit (&optional all quietly)
9457   "Mark all unread articles in this group as read, then exit.
9458 If prefix argument ALL is non-nil, all articles are marked as read.
9459 If QUIETLY is non-nil, no questions will be asked."
9460   (interactive "P")
9461   (when (gnus-summary-catchup all quietly nil 'fast)
9462     ;; Select next newsgroup or exit.
9463     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
9464              (eq gnus-auto-select-next 'quietly))
9465         (gnus-summary-next-group nil)
9466       (gnus-summary-exit))))
9467
9468 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
9469   "Mark all articles in this newsgroup as read, and then exit."
9470   (interactive "P")
9471   (gnus-summary-catchup-and-exit t quietly))
9472
9473 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
9474   "Mark all articles in this group as read and select the next group.
9475 If given a prefix, mark all articles, unread as well as ticked, as
9476 read."
9477   (interactive "P")
9478   (save-excursion
9479     (gnus-summary-catchup all))
9480   (gnus-summary-next-group))
9481
9482 ;;;
9483 ;;; with article
9484 ;;;
9485
9486 (defmacro gnus-with-article (article &rest forms)
9487   "Select ARTICLE and perform FORMS in the original article buffer.
9488 Then replace the article with the result."
9489   `(progn
9490      ;; We don't want the article to be marked as read.
9491      (let (gnus-mark-article-hook)
9492        (gnus-summary-select-article t t nil ,article))
9493      (set-buffer gnus-original-article-buffer)
9494      ,@forms
9495      (if (not (gnus-check-backend-function
9496                'request-replace-article (car gnus-article-current)))
9497          (gnus-message 5 "Read-only group; not replacing")
9498        (unless (gnus-request-replace-article
9499                 ,article (car gnus-article-current)
9500                 (current-buffer) t)
9501          (error "Couldn't replace article")))
9502      ;; The cache and backlog have to be flushed somewhat.
9503      (when gnus-keep-backlog
9504        (gnus-backlog-remove-article
9505         (car gnus-article-current) (cdr gnus-article-current)))
9506      (when gnus-use-cache
9507        (gnus-cache-update-article
9508         (car gnus-article-current) (cdr gnus-article-current)))))
9509
9510 (put 'gnus-with-article 'lisp-indent-function 1)
9511 (put 'gnus-with-article 'edebug-form-spec '(form body))
9512
9513 ;; Thread-based commands.
9514
9515 (defun gnus-summary-articles-in-thread (&optional article)
9516   "Return a list of all articles in the current thread.
9517 If ARTICLE is non-nil, return all articles in the thread that starts
9518 with that article."
9519   (let* ((article (or article (gnus-summary-article-number)))
9520          (data (gnus-data-find-list article))
9521          (top-level (gnus-data-level (car data)))
9522          (top-subject
9523           (cond ((null gnus-thread-operation-ignore-subject)
9524                  (gnus-simplify-subject-re
9525                   (mail-header-subject (gnus-data-header (car data)))))
9526                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
9527                  (gnus-simplify-subject-fuzzy
9528                   (mail-header-subject (gnus-data-header (car data)))))
9529                 (t nil)))
9530          (end-point (save-excursion
9531                       (if (gnus-summary-go-to-next-thread)
9532                           (point) (point-max))))
9533          articles)
9534     (while (and data
9535                 (< (gnus-data-pos (car data)) end-point))
9536       (when (or (not top-subject)
9537                 (string= top-subject
9538                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
9539                              (gnus-simplify-subject-fuzzy
9540                               (mail-header-subject
9541                                (gnus-data-header (car data))))
9542                            (gnus-simplify-subject-re
9543                             (mail-header-subject
9544                              (gnus-data-header (car data)))))))
9545         (push (gnus-data-number (car data)) articles))
9546       (unless (and (setq data (cdr data))
9547                    (> (gnus-data-level (car data)) top-level))
9548         (setq data nil)))
9549     ;; Return the list of articles.
9550     (nreverse articles)))
9551
9552 (defun gnus-summary-rethread-current ()
9553   "Rethread the thread the current article is part of."
9554   (interactive)
9555   (let* ((gnus-show-threads t)
9556          (article (gnus-summary-article-number))
9557          (id (mail-header-id (gnus-summary-article-header)))
9558          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
9559     (unless id
9560       (error "No article on the current line"))
9561     (gnus-rebuild-thread id)
9562     (gnus-summary-goto-subject article)))
9563
9564 (defun gnus-summary-reparent-thread ()
9565   "Make the current article child of the marked (or previous) article.
9566
9567 Note that the re-threading will only work if `gnus-thread-ignore-subject'
9568 is non-nil or the Subject: of both articles are the same."
9569   (interactive)
9570   (unless (not (gnus-group-read-only-p))
9571     (error "The current newsgroup does not support article editing"))
9572   (unless (<= (length gnus-newsgroup-processable) 1)
9573     (error "No more than one article may be marked"))
9574   (save-window-excursion
9575     (let ((gnus-article-buffer " *reparent*")
9576           (current-article (gnus-summary-article-number))
9577           ;; First grab the marked article, otherwise one line up.
9578           (parent-article (if (not (null gnus-newsgroup-processable))
9579                               (car gnus-newsgroup-processable)
9580                             (save-excursion
9581                               (if (eq (forward-line -1) 0)
9582                                   (gnus-summary-article-number)
9583                                 (error "Beginning of summary buffer"))))))
9584       (unless (not (eq current-article parent-article))
9585         (error "An article may not be self-referential"))
9586       (let ((message-id (mail-header-id
9587                          (gnus-summary-article-header parent-article))))
9588         (unless (and message-id (not (equal message-id "")))
9589           (error "No message-id in desired parent"))
9590         (gnus-with-article current-article
9591           (save-restriction
9592             (goto-char (point-min))
9593             (message-narrow-to-head)
9594             (if (re-search-forward "^References: " nil t)
9595                 (progn
9596                   (re-search-forward "^[^ \t]" nil t)
9597                   (forward-line -1)
9598                   (end-of-line)
9599                   (insert " " message-id))
9600               (insert "References: " message-id "\n"))))
9601         (set-buffer gnus-summary-buffer)
9602         (gnus-summary-unmark-all-processable)
9603         (gnus-summary-update-article current-article)
9604         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9605             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
9606         (gnus-summary-rethread-current)
9607         (gnus-message 3 "Article %d is now the child of article %d"
9608                       current-article parent-article)))))
9609
9610 (defun gnus-summary-toggle-threads (&optional arg)
9611   "Toggle showing conversation threads.
9612 If ARG is positive number, turn showing conversation threads on."
9613   (interactive "P")
9614   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
9615     (setq gnus-show-threads
9616           (if (null arg) (not gnus-show-threads)
9617             (> (prefix-numeric-value arg) 0)))
9618     (gnus-summary-prepare)
9619     (gnus-summary-goto-subject current)
9620     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
9621     (gnus-summary-position-point)))
9622
9623 (defun gnus-summary-show-all-threads ()
9624   "Show all threads."
9625   (interactive)
9626   (save-excursion
9627     (let ((buffer-read-only nil))
9628       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
9629   (gnus-summary-position-point))
9630
9631 (defun gnus-summary-show-thread ()
9632   "Show thread subtrees.
9633 Returns nil if no thread was there to be shown."
9634   (interactive)
9635   (let ((buffer-read-only nil)
9636         (orig (point))
9637         ;; first goto end then to beg, to have point at beg after let
9638         (end (progn (end-of-line) (point)))
9639         (beg (progn (beginning-of-line) (point))))
9640     (prog1
9641         ;; Any hidden lines here?
9642         (search-forward "\r" end t)
9643       (subst-char-in-region beg end ?\^M ?\n t)
9644       (goto-char orig)
9645       (gnus-summary-position-point))))
9646
9647 (defun gnus-summary-hide-all-threads ()
9648   "Hide all thread subtrees."
9649   (interactive)
9650   (save-excursion
9651     (goto-char (point-min))
9652     (gnus-summary-hide-thread)
9653     (while (zerop (gnus-summary-next-thread 1 t))
9654       (gnus-summary-hide-thread)))
9655   (gnus-summary-position-point))
9656
9657 (defun gnus-summary-hide-thread ()
9658   "Hide thread subtrees.
9659 Returns nil if no threads were there to be hidden."
9660   (interactive)
9661   (let ((buffer-read-only nil)
9662         (start (point))
9663         (article (gnus-summary-article-number)))
9664     (goto-char start)
9665     ;; Go forward until either the buffer ends or the subthread
9666     ;; ends.
9667     (when (and (not (eobp))
9668                (or (zerop (gnus-summary-next-thread 1 t))
9669                    (goto-char (point-max))))
9670       (prog1
9671           (if (and (> (point) start)
9672                    (search-backward "\n" start t))
9673               (progn
9674                 (subst-char-in-region start (point) ?\n ?\^M)
9675                 (gnus-summary-goto-subject article))
9676             (goto-char start)
9677             nil)))))
9678
9679 (defun gnus-summary-go-to-next-thread (&optional previous)
9680   "Go to the same level (or less) next thread.
9681 If PREVIOUS is non-nil, go to previous thread instead.
9682 Return the article number moved to, or nil if moving was impossible."
9683   (let ((level (gnus-summary-thread-level))
9684         (way (if previous -1 1))
9685         (beg (point)))
9686     (forward-line way)
9687     (while (and (not (eobp))
9688                 (< level (gnus-summary-thread-level)))
9689       (forward-line way))
9690     (if (eobp)
9691         (progn
9692           (goto-char beg)
9693           nil)
9694       (setq beg (point))
9695       (prog1
9696           (gnus-summary-article-number)
9697         (goto-char beg)))))
9698
9699 (defun gnus-summary-next-thread (n &optional silent)
9700   "Go to the same level next N'th thread.
9701 If N is negative, search backward instead.
9702 Returns the difference between N and the number of skips actually
9703 done.
9704
9705 If SILENT, don't output messages."
9706   (interactive "p")
9707   (let ((backward (< n 0))
9708         (n (abs n)))
9709     (while (and (> n 0)
9710                 (gnus-summary-go-to-next-thread backward))
9711       (decf n))
9712     (unless silent
9713       (gnus-summary-position-point))
9714     (when (and (not silent) (/= 0 n))
9715       (gnus-message 7 "No more threads"))
9716     n))
9717
9718 (defun gnus-summary-prev-thread (n)
9719   "Go to the same level previous N'th thread.
9720 Returns the difference between N and the number of skips actually
9721 done."
9722   (interactive "p")
9723   (gnus-summary-next-thread (- n)))
9724
9725 (defun gnus-summary-go-down-thread ()
9726   "Go down one level in the current thread."
9727   (let ((children (gnus-summary-article-children)))
9728     (when children
9729       (gnus-summary-goto-subject (car children)))))
9730
9731 (defun gnus-summary-go-up-thread ()
9732   "Go up one level in the current thread."
9733   (let ((parent (gnus-summary-article-parent)))
9734     (when parent
9735       (gnus-summary-goto-subject parent))))
9736
9737 (defun gnus-summary-down-thread (n)
9738   "Go down thread N steps.
9739 If N is negative, go up instead.
9740 Returns the difference between N and how many steps down that were
9741 taken."
9742   (interactive "p")
9743   (let ((up (< n 0))
9744         (n (abs n)))
9745     (while (and (> n 0)
9746                 (if up (gnus-summary-go-up-thread)
9747                   (gnus-summary-go-down-thread)))
9748       (setq n (1- n)))
9749     (gnus-summary-position-point)
9750     (when (/= 0 n)
9751       (gnus-message 7 "Can't go further"))
9752     n))
9753
9754 (defun gnus-summary-up-thread (n)
9755   "Go up thread N steps.
9756 If N is negative, go down instead.
9757 Returns the difference between N and how many steps down that were
9758 taken."
9759   (interactive "p")
9760   (gnus-summary-down-thread (- n)))
9761
9762 (defun gnus-summary-top-thread ()
9763   "Go to the top of the thread."
9764   (interactive)
9765   (while (gnus-summary-go-up-thread))
9766   (gnus-summary-article-number))
9767
9768 (defun gnus-summary-kill-thread (&optional unmark)
9769   "Mark articles under current thread as read.
9770 If the prefix argument is positive, remove any kinds of marks.
9771 If the prefix argument is negative, tick articles instead."
9772   (interactive "P")
9773   (when unmark
9774     (setq unmark (prefix-numeric-value unmark)))
9775   (let ((articles (gnus-summary-articles-in-thread)))
9776     (save-excursion
9777       ;; Expand the thread.
9778       (gnus-summary-show-thread)
9779       ;; Mark all the articles.
9780       (while articles
9781         (gnus-summary-goto-subject (car articles))
9782         (cond ((null unmark)
9783                (gnus-summary-mark-article-as-read gnus-killed-mark))
9784               ((> unmark 0)
9785                (gnus-summary-mark-article-as-unread gnus-unread-mark))
9786               (t
9787                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
9788         (setq articles (cdr articles))))
9789     ;; Hide killed subtrees.
9790     (and (null unmark)
9791          gnus-thread-hide-killed
9792          (gnus-summary-hide-thread))
9793     ;; If marked as read, go to next unread subject.
9794     (when (null unmark)
9795       ;; Go to next unread subject.
9796       (gnus-summary-next-subject 1 t)))
9797   (gnus-set-mode-line 'summary))
9798
9799 ;; Summary sorting commands
9800
9801 (defun gnus-summary-sort-by-number (&optional reverse)
9802   "Sort the summary buffer by article number.
9803 Argument REVERSE means reverse order."
9804   (interactive "P")
9805   (gnus-summary-sort 'number reverse))
9806
9807 (defun gnus-summary-sort-by-author (&optional reverse)
9808   "Sort the summary buffer by author name alphabetically.
9809 If `case-fold-search' is non-nil, case of letters is ignored.
9810 Argument REVERSE means reverse order."
9811   (interactive "P")
9812   (gnus-summary-sort 'author reverse))
9813
9814 (defun gnus-summary-sort-by-subject (&optional reverse)
9815   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
9816 If `case-fold-search' is non-nil, case of letters is ignored.
9817 Argument REVERSE means reverse order."
9818   (interactive "P")
9819   (gnus-summary-sort 'subject reverse))
9820
9821 (defun gnus-summary-sort-by-date (&optional reverse)
9822   "Sort the summary buffer by date.
9823 Argument REVERSE means reverse order."
9824   (interactive "P")
9825   (gnus-summary-sort 'date reverse))
9826
9827 (defun gnus-summary-sort-by-score (&optional reverse)
9828   "Sort the summary buffer by score.
9829 Argument REVERSE means reverse order."
9830   (interactive "P")
9831   (gnus-summary-sort 'score reverse))
9832
9833 (defun gnus-summary-sort-by-lines (&optional reverse)
9834   "Sort the summary buffer by the number of lines.
9835 Argument REVERSE means reverse order."
9836   (interactive "P")
9837   (gnus-summary-sort 'lines reverse))
9838
9839 (defun gnus-summary-sort-by-chars (&optional reverse)
9840   "Sort the summary buffer by article length.
9841 Argument REVERSE means reverse order."
9842   (interactive "P")
9843   (gnus-summary-sort 'chars reverse))
9844
9845 (defun gnus-summary-sort-by-original (&optional reverse)
9846   "Sort the summary buffer using the default sorting method.
9847 Argument REVERSE means reverse order."
9848   (interactive "P")
9849   (let* ((buffer-read-only)
9850          (gnus-summary-prepare-hook nil))
9851     ;; We do the sorting by regenerating the threads.
9852     (gnus-summary-prepare)
9853     ;; Hide subthreads if needed.
9854     (when (and gnus-show-threads gnus-thread-hide-subtree)
9855       (gnus-summary-hide-all-threads))))
9856
9857 (defun gnus-summary-sort (predicate reverse)
9858   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
9859   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
9860          (article (intern (format "gnus-article-sort-by-%s" predicate)))
9861          (gnus-thread-sort-functions
9862           (if (not reverse)
9863               thread
9864             `(lambda (t1 t2)
9865                (,thread t2 t1))))
9866          (gnus-sort-gathered-threads-function
9867           gnus-thread-sort-functions)
9868          (gnus-article-sort-functions
9869           (if (not reverse)
9870               article
9871             `(lambda (t1 t2)
9872                (,article t2 t1))))
9873          (buffer-read-only)
9874          (gnus-summary-prepare-hook nil))
9875     ;; We do the sorting by regenerating the threads.
9876     (gnus-summary-prepare)
9877     ;; Hide subthreads if needed.
9878     (when (and gnus-show-threads gnus-thread-hide-subtree)
9879       (gnus-summary-hide-all-threads))))
9880
9881 ;; Summary saving commands.
9882
9883 (defun gnus-summary-save-article (&optional n not-saved)
9884   "Save the current article using the default saver function.
9885 If N is a positive number, save the N next articles.
9886 If N is a negative number, save the N previous articles.
9887 If N is nil and any articles have been marked with the process mark,
9888 save those articles instead.
9889 The variable `gnus-default-article-saver' specifies the saver function."
9890   (interactive "P")
9891   (let* ((articles (gnus-summary-work-articles n))
9892          (save-buffer (save-excursion
9893                         (nnheader-set-temp-buffer " *Gnus Save*")))
9894          (num (length articles))
9895          header file)
9896     (dolist (article articles)
9897       (setq header (gnus-summary-article-header article))
9898       (if (not (vectorp header))
9899           ;; This is a pseudo-article.
9900           (if (assq 'name header)
9901               (gnus-copy-file (cdr (assq 'name header)))
9902             (gnus-message 1 "Article %d is unsaveable" article))
9903         ;; This is a real article.
9904         (save-window-excursion
9905           (gnus-summary-select-article t nil nil article))
9906         (save-excursion
9907           (set-buffer save-buffer)
9908           (erase-buffer)
9909           (insert-buffer-substring gnus-original-article-buffer))
9910         (setq file (gnus-article-save save-buffer file num))
9911         (gnus-summary-remove-process-mark article)
9912         (unless not-saved
9913           (gnus-summary-set-saved-mark article))))
9914     (gnus-kill-buffer save-buffer)
9915     (gnus-summary-position-point)
9916     (gnus-set-mode-line 'summary)
9917     n))
9918
9919 (defun gnus-summary-pipe-output (&optional arg)
9920   "Pipe the current article to a subprocess.
9921 If N is a positive number, pipe the N next articles.
9922 If N is a negative number, pipe the N previous articles.
9923 If N is nil and any articles have been marked with the process mark,
9924 pipe those articles instead."
9925   (interactive "P")
9926   (require 'gnus-art)
9927   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe))
9928     (gnus-summary-save-article arg t))
9929   (let ((buffer (get-buffer "*Shell Command Output*")))
9930     (if (and buffer
9931              (with-current-buffer buffer (> (point-max) (point-min))))
9932         (gnus-configure-windows 'pipe))))
9933
9934 (defun gnus-summary-save-article-mail (&optional arg)
9935   "Append the current article to an mail file.
9936 If N is a positive number, save the N next articles.
9937 If N is a negative number, save the N previous articles.
9938 If N is nil and any articles have been marked with the process mark,
9939 save those articles instead."
9940   (interactive "P")
9941   (require 'gnus-art)
9942   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
9943     (gnus-summary-save-article arg)))
9944
9945 (defun gnus-summary-save-article-rmail (&optional arg)
9946   "Append the current article to an rmail file.
9947 If N is a positive number, save the N next articles.
9948 If N is a negative number, save the N previous articles.
9949 If N is nil and any articles have been marked with the process mark,
9950 save those articles instead."
9951   (interactive "P")
9952   (require 'gnus-art)
9953   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
9954     (gnus-summary-save-article arg)))
9955
9956 (defun gnus-summary-save-article-file (&optional arg)
9957   "Append the current article to a file.
9958 If N is a positive number, save the N next articles.
9959 If N is a negative number, save the N previous articles.
9960 If N is nil and any articles have been marked with the process mark,
9961 save those articles instead."
9962   (interactive "P")
9963   (require 'gnus-art)
9964   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
9965     (gnus-summary-save-article arg)))
9966
9967 (defun gnus-summary-write-article-file (&optional arg)
9968   "Write the current article to a file, deleting the previous file.
9969 If N is a positive number, save the N next articles.
9970 If N is a negative number, save the N previous articles.
9971 If N is nil and any articles have been marked with the process mark,
9972 save those articles instead."
9973   (interactive "P")
9974   (require 'gnus-art)
9975   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
9976     (gnus-summary-save-article arg)))
9977
9978 (defun gnus-summary-save-article-body-file (&optional arg)
9979   "Append the current article body to a file.
9980 If N is a positive number, save the N next articles.
9981 If N is a negative number, save the N previous articles.
9982 If N is nil and any articles have been marked with the process mark,
9983 save those articles instead."
9984   (interactive "P")
9985   (require 'gnus-art)
9986   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
9987     (gnus-summary-save-article arg)))
9988
9989 (defun gnus-summary-pipe-message (program)
9990   "Pipe the current article through PROGRAM."
9991   (interactive "sProgram: ")
9992   (gnus-summary-select-article)
9993   (let ((mail-header-separator ""))
9994     (gnus-eval-in-buffer-window gnus-article-buffer
9995       (save-restriction
9996         (widen)
9997         (let ((start (window-start))
9998               buffer-read-only)
9999           (message-pipe-buffer-body program)
10000           (set-window-start (get-buffer-window (current-buffer)) start))))))
10001
10002 (defun gnus-get-split-value (methods)
10003   "Return a value based on the split METHODS."
10004   (let (split-name method result match)
10005     (when methods
10006       (save-excursion
10007         (set-buffer gnus-original-article-buffer)
10008         (save-restriction
10009           (nnheader-narrow-to-headers)
10010           (while (and methods (not split-name))
10011             (goto-char (point-min))
10012             (setq method (pop methods))
10013             (setq match (car method))
10014             (when (cond
10015                    ((stringp match)
10016                     ;; Regular expression.
10017                     (ignore-errors
10018                       (re-search-forward match nil t)))
10019                    ((gnus-functionp match)
10020                     ;; Function.
10021                     (save-restriction
10022                       (widen)
10023                       (setq result (funcall match gnus-newsgroup-name))))
10024                    ((consp match)
10025                     ;; Form.
10026                     (save-restriction
10027                       (widen)
10028                       (setq result (eval match)))))
10029               (setq split-name (cdr method))
10030               (cond ((stringp result)
10031                      (push (expand-file-name
10032                             result gnus-article-save-directory)
10033                            split-name))
10034                     ((consp result)
10035                      (setq split-name (append result split-name)))))))))
10036     (nreverse split-name)))
10037
10038 (defun gnus-valid-move-group-p (group)
10039   (and (boundp group)
10040        (symbol-name group)
10041        (symbol-value group)
10042        (gnus-get-function (gnus-find-method-for-group
10043                            (symbol-name group)) 'request-accept-article t)))
10044
10045 (defun gnus-read-move-group-name (prompt default articles prefix)
10046   "Read a group name."
10047   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10048          (minibuffer-confirm-incomplete nil) ; XEmacs
10049          (prom
10050           (format "%s %s to:"
10051                   prompt
10052                   (if (> (length articles) 1)
10053                       (format "these %d articles" (length articles))
10054                     "this article")))
10055          (to-newsgroup
10056           (cond
10057            ((null split-name)
10058             (gnus-completing-read default prom
10059                                   gnus-active-hashtb
10060                                   'gnus-valid-move-group-p
10061                                   nil prefix
10062                                   'gnus-group-history))
10063            ((= 1 (length split-name))
10064             (gnus-completing-read (car split-name) prom
10065                                   gnus-active-hashtb
10066                                   'gnus-valid-move-group-p
10067                                   nil nil
10068                                   'gnus-group-history))
10069            (t
10070             (gnus-completing-read nil prom
10071                                   (mapcar (lambda (el) (list el))
10072                                           (nreverse split-name))
10073                                   nil nil nil
10074                                   'gnus-group-history))))
10075          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
10076     (when to-newsgroup
10077       (if (or (string= to-newsgroup "")
10078               (string= to-newsgroup prefix))
10079           (setq to-newsgroup default))
10080       (unless to-newsgroup
10081         (error "No group name entered"))
10082       (or (gnus-active to-newsgroup)
10083           (gnus-activate-group to-newsgroup nil nil to-method)
10084           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
10085                                      to-newsgroup))
10086               (or (and (gnus-request-create-group to-newsgroup to-method)
10087                        (gnus-activate-group
10088                         to-newsgroup nil nil to-method)
10089                        (gnus-subscribe-group to-newsgroup))
10090                   (error "Couldn't create group %s" to-newsgroup)))
10091           (error "No such group: %s" to-newsgroup)))
10092     to-newsgroup))
10093
10094 (defun gnus-summary-save-parts (type dir n &optional reverse)
10095   "Save parts matching TYPE to DIR.
10096 If REVERSE, save parts that do not match TYPE."
10097   (interactive
10098    (list (read-string "Save parts of type: "
10099                       (or (car gnus-summary-save-parts-type-history)
10100                           gnus-summary-save-parts-default-mime)
10101                       'gnus-summary-save-parts-type-history)
10102          (setq gnus-summary-save-parts-last-directory
10103                (read-file-name "Save to directory: "
10104                                gnus-summary-save-parts-last-directory
10105                                nil t))
10106          current-prefix-arg))
10107   (gnus-summary-iterate n
10108     (let ((gnus-display-mime-function nil)
10109           (gnus-inhibit-treatment t))
10110       (gnus-summary-select-article))
10111     (save-excursion
10112       (set-buffer gnus-article-buffer)
10113       (let ((handles (or gnus-article-mime-handles
10114                          (mm-dissect-buffer) (mm-uu-dissect))))
10115         (when handles
10116           (gnus-summary-save-parts-1 type dir handles reverse)
10117           (unless gnus-article-mime-handles ;; Don't destroy this case.
10118             (mm-destroy-parts handles)))))))
10119
10120 (defun gnus-summary-save-parts-1 (type dir handle reverse)
10121   (if (stringp (car handle))
10122       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
10123               (cdr handle))
10124     (when (if reverse
10125               (not (string-match type (mm-handle-media-type handle)))
10126             (string-match type (mm-handle-media-type handle)))
10127       (let ((file (expand-file-name
10128                    (file-name-nondirectory
10129                     (or
10130                      (mail-content-type-get
10131                       (mm-handle-disposition handle) 'filename)
10132                      (concat gnus-newsgroup-name
10133                              "." (number-to-string
10134                                   (cdr gnus-article-current)))))
10135                    dir)))
10136         (unless (file-exists-p file)
10137           (mm-save-part-to-file handle file))))))
10138
10139 ;; Summary extract commands
10140
10141 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
10142   (let ((buffer-read-only nil)
10143         (article (gnus-summary-article-number))
10144         after-article b e)
10145     (unless (gnus-summary-goto-subject article)
10146       (error "No such article: %d" article))
10147     (gnus-summary-position-point)
10148     ;; If all commands are to be bunched up on one line, we collect
10149     ;; them here.
10150     (unless gnus-view-pseudos-separately
10151       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
10152             files action)
10153         (while ps
10154           (setq action (cdr (assq 'action (car ps))))
10155           (setq files (list (cdr (assq 'name (car ps)))))
10156           (while (and ps (cdr ps)
10157                       (string= (or action "1")
10158                                (or (cdr (assq 'action (cadr ps))) "2")))
10159             (push (cdr (assq 'name (cadr ps))) files)
10160             (setcdr ps (cddr ps)))
10161           (when files
10162             (when (not (string-match "%s" action))
10163               (push " " files))
10164             (push " " files)
10165             (when (assq 'execute (car ps))
10166               (setcdr (assq 'execute (car ps))
10167                       (funcall (if (string-match "%s" action)
10168                                    'format 'concat)
10169                                action
10170                                (mapconcat
10171                                 (lambda (f)
10172                                   (if (equal f " ")
10173                                       f
10174                                     (gnus-quote-arg-for-sh-or-csh f)))
10175                                 files " ")))))
10176           (setq ps (cdr ps)))))
10177     (if (and gnus-view-pseudos (not not-view))
10178         (while pslist
10179           (when (assq 'execute (car pslist))
10180             (gnus-execute-command (cdr (assq 'execute (car pslist)))
10181                                   (eq gnus-view-pseudos 'not-confirm)))
10182           (setq pslist (cdr pslist)))
10183       (save-excursion
10184         (while pslist
10185           (setq after-article (or (cdr (assq 'article (car pslist)))
10186                                   (gnus-summary-article-number)))
10187           (gnus-summary-goto-subject after-article)
10188           (forward-line 1)
10189           (setq b (point))
10190           (insert "    " (file-name-nondirectory
10191                           (cdr (assq 'name (car pslist))))
10192                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
10193           (setq e (point))
10194           (forward-line -1)             ; back to `b'
10195           (gnus-add-text-properties
10196            b (1- e) (list 'gnus-number gnus-reffed-article-number
10197                           gnus-mouse-face-prop gnus-mouse-face))
10198           (gnus-data-enter
10199            after-article gnus-reffed-article-number
10200            gnus-unread-mark b (car pslist) 0 (- e b))
10201           (push gnus-reffed-article-number gnus-newsgroup-unreads)
10202           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
10203           (setq pslist (cdr pslist)))))))
10204
10205 (defun gnus-pseudos< (p1 p2)
10206   (let ((c1 (cdr (assq 'action p1)))
10207         (c2 (cdr (assq 'action p2))))
10208     (and c1 c2 (string< c1 c2))))
10209
10210 (defun gnus-request-pseudo-article (props)
10211   (cond ((assq 'execute props)
10212          (gnus-execute-command (cdr (assq 'execute props)))))
10213   (let ((gnus-current-article (gnus-summary-article-number)))
10214     (gnus-run-hooks 'gnus-mark-article-hook)))
10215
10216 (defun gnus-execute-command (command &optional automatic)
10217   (save-excursion
10218     (gnus-article-setup-buffer)
10219     (set-buffer gnus-article-buffer)
10220     (setq buffer-read-only nil)
10221     (let ((command (if automatic command
10222                      (read-string "Command: " (cons command 0)))))
10223       (erase-buffer)
10224       (insert "$ " command "\n\n")
10225       (if gnus-view-pseudo-asynchronously
10226           (start-process "gnus-execute" (current-buffer) shell-file-name
10227                          shell-command-switch command)
10228         (call-process shell-file-name nil t nil
10229                       shell-command-switch command)))))
10230
10231 ;; Summary kill commands.
10232
10233 (defun gnus-summary-edit-global-kill (article)
10234   "Edit the \"global\" kill file."
10235   (interactive (list (gnus-summary-article-number)))
10236   (gnus-group-edit-global-kill article))
10237
10238 (defun gnus-summary-edit-local-kill ()
10239   "Edit a local kill file applied to the current newsgroup."
10240   (interactive)
10241   (setq gnus-current-headers (gnus-summary-article-header))
10242   (gnus-group-edit-local-kill
10243    (gnus-summary-article-number) gnus-newsgroup-name))
10244
10245 ;;; Header reading.
10246
10247 (defun gnus-read-header (id &optional header)
10248   "Read the headers of article ID and enter them into the Gnus system."
10249   (let ((group gnus-newsgroup-name)
10250         (gnus-override-method
10251          (or
10252           gnus-override-method
10253           (and (gnus-news-group-p gnus-newsgroup-name)
10254                (car (gnus-refer-article-methods)))))
10255         where)
10256     ;; First we check to see whether the header in question is already
10257     ;; fetched.
10258     (if (stringp id)
10259         ;; This is a Message-ID.
10260         (setq header (or header (gnus-id-to-header id)))
10261       ;; This is an article number.
10262       (setq header (or header (gnus-summary-article-header id))))
10263     (if (and header
10264              (not (gnus-summary-article-sparse-p (mail-header-number header))))
10265         ;; We have found the header.
10266         header
10267       ;; If this is a sparse article, we have to nix out its
10268       ;; previous entry in the thread hashtb.
10269       (when (and header
10270                  (gnus-summary-article-sparse-p (mail-header-number header)))
10271         (let* ((parent (gnus-parent-id (mail-header-references header)))
10272                (thread (and parent (gnus-id-to-thread parent))))
10273           (when thread
10274             (delq (assq header thread) thread))))
10275       ;; We have to really fetch the header to this article.
10276       (save-excursion
10277         (set-buffer nntp-server-buffer)
10278         (when (setq where (gnus-request-head id group))
10279           (nnheader-fold-continuation-lines)
10280           (goto-char (point-max))
10281           (insert ".\n")
10282           (goto-char (point-min))
10283           (insert "211 ")
10284           (princ (cond
10285                   ((numberp id) id)
10286                   ((cdr where) (cdr where))
10287                   (header (mail-header-number header))
10288                   (t gnus-reffed-article-number))
10289                  (current-buffer))
10290           (insert " Article retrieved.\n"))
10291         (if (or (not where)
10292                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
10293             ()                          ; Malformed head.
10294           (unless (gnus-summary-article-sparse-p (mail-header-number header))
10295             (when (and (stringp id)
10296                        (not (string= (gnus-group-real-name group)
10297                                      (car where))))
10298               ;; If we fetched by Message-ID and the article came
10299               ;; from a different group, we fudge some bogus article
10300               ;; numbers for this article.
10301               (mail-header-set-number header gnus-reffed-article-number))
10302             (save-excursion
10303               (set-buffer gnus-summary-buffer)
10304               (decf gnus-reffed-article-number)
10305               (gnus-remove-header (mail-header-number header))
10306               (push header gnus-newsgroup-headers)
10307               (setq gnus-current-headers header)
10308               (push (mail-header-number header) gnus-newsgroup-limit)))
10309           header)))))
10310
10311 (defun gnus-remove-header (number)
10312   "Remove header NUMBER from `gnus-newsgroup-headers'."
10313   (if (and gnus-newsgroup-headers
10314            (= number (mail-header-number (car gnus-newsgroup-headers))))
10315       (pop gnus-newsgroup-headers)
10316     (let ((headers gnus-newsgroup-headers))
10317       (while (and (cdr headers)
10318                   (not (= number (mail-header-number (cadr headers)))))
10319         (pop headers))
10320       (when (cdr headers)
10321         (setcdr headers (cddr headers))))))
10322
10323 ;;;
10324 ;;; summary highlights
10325 ;;;
10326
10327 (defun gnus-highlight-selected-summary ()
10328   "Highlight selected article in summary buffer."
10329   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
10330   (when gnus-summary-selected-face
10331     (save-excursion
10332       (let* ((beg (progn (beginning-of-line) (point)))
10333              (end (progn (end-of-line) (point)))
10334              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
10335              (from (if (get-text-property beg gnus-mouse-face-prop)
10336                        beg
10337                      (or (next-single-property-change
10338                           beg gnus-mouse-face-prop nil end)
10339                          beg)))
10340              (to
10341               (if (= from end)
10342                   (- from 2)
10343                 (or (next-single-property-change
10344                      from gnus-mouse-face-prop nil end)
10345                     end))))
10346         ;; If no mouse-face prop on line we will have to = from = end,
10347         ;; so we highlight the entire line instead.
10348         (when (= (+ to 2) from)
10349           (setq from beg)
10350           (setq to end))
10351         (if gnus-newsgroup-selected-overlay
10352             ;; Move old overlay.
10353             (gnus-move-overlay
10354              gnus-newsgroup-selected-overlay from to (current-buffer))
10355           ;; Create new overlay.
10356           (gnus-overlay-put
10357            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
10358            'face gnus-summary-selected-face))))))
10359
10360 ;; New implementation by Christian Limpach <Christian.Limpach@nice.ch>.
10361 (defun gnus-summary-highlight-line ()
10362   "Highlight current line according to `gnus-summary-highlight'."
10363   (let* ((list gnus-summary-highlight)
10364          (p (point))
10365          (end (progn (end-of-line) (point)))
10366          ;; now find out where the line starts and leave point there.
10367          (beg (progn (beginning-of-line) (point)))
10368          (article (gnus-summary-article-number))
10369          (score (or (cdr (assq (or article gnus-current-article)
10370                                gnus-newsgroup-scored))
10371                     gnus-summary-default-score 0))
10372          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
10373          (inhibit-read-only t))
10374     ;; Eval the cars of the lists until we find a match.
10375     (let ((default gnus-summary-default-score)
10376           (default-high gnus-summary-default-high-score)
10377           (default-low gnus-summary-default-low-score))
10378       (while (and list
10379                   (not (eval (caar list))))
10380         (setq list (cdr list))))
10381     (let ((face (cdar list)))
10382       (unless (eq face (get-text-property beg 'face))
10383         (gnus-put-text-property-excluding-characters-with-faces
10384          beg end 'face
10385          (setq face (if (boundp face) (symbol-value face) face)))
10386         (when gnus-summary-highlight-line-function
10387           (funcall gnus-summary-highlight-line-function article face))))
10388     (goto-char p)))
10389
10390 (defun gnus-update-read-articles (group unread &optional compute)
10391   "Update the list of read articles in GROUP."
10392   (let* ((active (or gnus-newsgroup-active (gnus-active group)))
10393          (entry (gnus-gethash group gnus-newsrc-hashtb))
10394          (info (nth 2 entry))
10395          (prev 1)
10396          (unread (sort (copy-sequence unread) '<))
10397          read)
10398     (if (or (not info) (not active))
10399         ;; There is no info on this group if it was, in fact,
10400         ;; killed.  Gnus stores no information on killed groups, so
10401         ;; there's nothing to be done.
10402         ;; One could store the information somewhere temporarily,
10403         ;; perhaps...  Hmmm...
10404         ()
10405       ;; Remove any negative articles numbers.
10406       (while (and unread (< (car unread) 0))
10407         (setq unread (cdr unread)))
10408       ;; Remove any expired article numbers
10409       (while (and unread (< (car unread) (car active)))
10410         (setq unread (cdr unread)))
10411       ;; Compute the ranges of read articles by looking at the list of
10412       ;; unread articles.
10413       (while unread
10414         (when (/= (car unread) prev)
10415           (push (if (= prev (1- (car unread))) prev
10416                   (cons prev (1- (car unread))))
10417                 read))
10418         (setq prev (1+ (car unread)))
10419         (setq unread (cdr unread)))
10420       (when (<= prev (cdr active))
10421         (push (cons prev (cdr active)) read))
10422       (setq read (if (> (length read) 1) (nreverse read) read))
10423       (if compute
10424           read
10425         (save-excursion
10426           (let (setmarkundo)
10427             ;; Propagate the read marks to the backend.
10428             (when (gnus-check-backend-function 'request-set-mark group)
10429               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
10430                     (add (gnus-remove-from-range read (gnus-info-read info))))
10431                 (when (or add del)
10432                   (unless (gnus-check-group group)
10433                     (error "Can't open server for %s" group))
10434                   (gnus-request-set-mark
10435                    group (delq nil (list (if add (list add 'add '(read)))
10436                                          (if del (list del 'del '(read))))))
10437                   (setq setmarkundo
10438                         `(gnus-request-set-mark
10439                           ,group
10440                           ',(delq nil (list
10441                                        (if del (list del 'add '(read)))
10442                                        (if add (list add 'del '(read))))))))))
10443             (set-buffer gnus-group-buffer)
10444             (gnus-undo-register
10445               `(progn
10446                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
10447                  (gnus-info-set-read ',info ',(gnus-info-read info))
10448                  (gnus-get-unread-articles-in-group ',info
10449                                                     (gnus-active ,group))
10450                  (gnus-group-update-group ,group t)
10451                  ,setmarkundo))))
10452         ;; Enter this list into the group info.
10453         (gnus-info-set-read info read)
10454         ;; Set the number of unread articles in gnus-newsrc-hashtb.
10455         (gnus-get-unread-articles-in-group info (gnus-active group))
10456         t))))
10457
10458 (defun gnus-offer-save-summaries ()
10459   "Offer to save all active summary buffers."
10460   (let (buffers)
10461     ;; Go through all buffers and find all summaries.
10462     (dolist (buffer (buffer-list))
10463       (when (and (setq buffer (buffer-name buffer))
10464                  (string-match "Summary" buffer)
10465                  (save-excursion
10466                    (set-buffer buffer)
10467                    ;; We check that this is, indeed, a summary buffer.
10468                    (and (eq major-mode 'gnus-summary-mode)
10469                         ;; Also make sure this isn't bogus.
10470                         gnus-newsgroup-prepared
10471                         ;; Also make sure that this isn't a
10472                         ;; dead summary buffer.
10473                         (not gnus-dead-summary-mode))))
10474         (push buffer buffers)))
10475     ;; Go through all these summary buffers and offer to save them.
10476     (when buffers
10477       (save-excursion
10478         (map-y-or-n-p
10479          "Update summary buffer %s? "
10480          (lambda (buf)
10481            (switch-to-buffer buf)
10482            (gnus-summary-exit))
10483          buffers)))))
10484
10485
10486 ;;; @ for mime-partial
10487 ;;;
10488
10489 (defun gnus-request-partial-message ()
10490   (save-excursion
10491     (let ((number (gnus-summary-article-number))
10492           (group gnus-newsgroup-name)
10493           (mother gnus-article-buffer))
10494       (set-buffer (get-buffer-create " *Partial Article*"))
10495       (erase-buffer)
10496       (setq mime-preview-buffer mother)
10497       (gnus-request-article-this-buffer number group)
10498       (mime-parse-buffer)
10499       )))
10500
10501 (autoload 'mime-combine-message/partial-pieces-automatically
10502   "mime-partial"
10503   "Internal method to combine message/partial messages automatically.")
10504
10505 (mime-add-condition
10506  'action '((type . message)(subtype . partial)
10507            (major-mode . gnus-original-article-mode)
10508            (method . mime-combine-message/partial-pieces-automatically)
10509            (summary-buffer-exp . gnus-summary-buffer)
10510            (request-partial-message-method . gnus-request-partial-message)
10511            ))
10512
10513
10514 ;;; @ for message/rfc822
10515 ;;;
10516
10517 (defun gnus-mime-extract-message/rfc822 (entity situation)
10518   (let (group article num cwin swin cur)
10519     (with-temp-buffer
10520       (mime-insert-entity-content entity)
10521       (setq group (or (cdr (assq 'group situation))
10522                       (completing-read "Group: "
10523                                        gnus-active-hashtb
10524                                        nil
10525                                        (gnus-read-active-file-p)
10526                                        gnus-newsgroup-name))
10527             article (gnus-request-accept-article group)))
10528     (when (and (consp article)
10529                (numberp (setq article (cdr article))))
10530       (setq num (1+ (or (cdr (assq 'number situation)) 0))
10531             cwin (get-buffer-window (current-buffer) t))
10532       (save-window-excursion
10533         (if (setq swin (get-buffer-window gnus-summary-buffer t))
10534             (select-window swin)
10535           (set-buffer gnus-summary-buffer))
10536         (setq cur gnus-current-article)
10537         (forward-line num)
10538         (let (gnus-show-threads)
10539           (gnus-summary-goto-subject article t))
10540         (gnus-summary-clear-mark-forward 1)
10541         (gnus-summary-goto-subject cur))
10542       (when (and cwin (window-frame cwin))
10543         (select-frame (window-frame cwin)))
10544       (when (boundp 'mime-acting-situation-to-override)
10545         (set-alist 'mime-acting-situation-to-override
10546                    'group
10547                    group)
10548         (set-alist 'mime-acting-situation-to-override
10549                    'after-method
10550                    `(progn
10551                       (save-current-buffer
10552                         (set-buffer gnus-group-buffer)
10553                         (gnus-activate-group ,group))
10554                       (gnus-summary-goto-article ,cur
10555                                                  gnus-show-all-headers)))
10556         (set-alist 'mime-acting-situation-to-override
10557                    'number num)))))
10558
10559 (mime-add-condition
10560  'action '((type . message)(subtype . rfc822)
10561            (major-mode . gnus-original-article-mode)
10562            (method . gnus-mime-extract-message/rfc822)
10563            (mode . "extract")
10564            ))
10565
10566 (mime-add-condition
10567  'action '((type . message)(subtype . news)
10568            (major-mode . gnus-original-article-mode)
10569            (method . gnus-mime-extract-message/rfc822)
10570            (mode . "extract")
10571            ))
10572
10573 (defun gnus-mime-extract-multipart (entity situation)
10574   (let ((children (mime-entity-children entity))
10575         mime-acting-situation-to-override
10576         f)
10577     (while children
10578       (mime-play-entity (car children)
10579                         (cons (assq 'mode situation)
10580                               mime-acting-situation-to-override))
10581       (setq children (cdr children)))
10582     (if (setq f (cdr (assq 'after-method
10583                            mime-acting-situation-to-override)))
10584         (eval f)
10585       )))
10586
10587 (mime-add-condition
10588  'action '((type . multipart)
10589            (method . gnus-mime-extract-multipart)
10590            (mode . "extract")
10591            )
10592  'with-default)
10593
10594
10595 ;;; @ end
10596 ;;;
10597
10598 (defun gnus-summary-setup-default-charset ()
10599   "Setup newsgroup default charset."
10600   (if (equal gnus-newsgroup-name "nndraft:drafts")
10601       (setq gnus-newsgroup-charset nil)
10602     (let* ((ignored-charsets
10603             (or gnus-newsgroup-ephemeral-ignored-charsets
10604                 (append
10605                  (and gnus-newsgroup-name
10606                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
10607                  gnus-newsgroup-ignored-charsets))))
10608       (setq gnus-newsgroup-charset
10609             (or gnus-newsgroup-ephemeral-charset
10610                 (and gnus-newsgroup-name
10611                      (gnus-parameter-charset gnus-newsgroup-name))
10612                 gnus-default-charset))
10613       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
10614            ignored-charsets))))
10615
10616 ;;;
10617 ;;; Mime Commands
10618 ;;;
10619
10620 (defun gnus-summary-display-buttonized (&optional show-all-parts)
10621   "Display the current article buffer fully MIME-buttonized.
10622 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
10623 treated as multipart/mixed."
10624   (interactive "P")
10625   (require 'gnus-art)
10626   (let ((gnus-unbuttonized-mime-types nil)
10627         (gnus-mime-display-multipart-as-mixed show-all-parts))
10628     (gnus-summary-show-article)))
10629
10630 (defun gnus-summary-repair-multipart (article)
10631   "Add a Content-Type header to a multipart article without one."
10632   (interactive (list (gnus-summary-article-number)))
10633   (gnus-with-article article
10634     (message-narrow-to-head)
10635     (message-remove-header "Mime-Version")
10636     (goto-char (point-max))
10637     (insert "Mime-Version: 1.0\n")
10638     (widen)
10639     (when (search-forward "\n--" nil t)
10640       (let ((separator (buffer-substring (point) (gnus-point-at-eol))))
10641         (message-narrow-to-head)
10642         (message-remove-header "Content-Type")
10643         (goto-char (point-max))
10644         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
10645                         separator))
10646         (widen))))
10647   (let (gnus-mark-article-hook)
10648     (gnus-summary-select-article t t nil article)))
10649
10650 (defun gnus-summary-toggle-display-buttonized ()
10651   "Toggle the buttonizing of the article buffer."
10652   (interactive)
10653   (require 'gnus-art)
10654   (if (setq gnus-inhibit-mime-unbuttonizing
10655             (not gnus-inhibit-mime-unbuttonizing))
10656       (let ((gnus-unbuttonized-mime-types nil))
10657         (gnus-summary-show-article))
10658     (gnus-summary-show-article)))
10659
10660 ;;;
10661 ;;; Intelli-mouse commmands
10662 ;;;
10663
10664 (defun gnus-wheel-summary-scroll (event)
10665   (interactive "e")
10666   (let ((amount (if (memq 'shift (event-modifiers event))
10667                     (car gnus-wheel-scroll-amount)
10668                   (cdr gnus-wheel-scroll-amount)))
10669         (direction (- (* (static-if (featurep 'xemacs)
10670                              (event-button event)
10671                            (cond ((eq 'mouse-4 (event-basic-type event))
10672                                   4)
10673                                  ((eq 'mouse-5 (event-basic-type event))
10674                                   5)))
10675                          2) 9))
10676         edge)
10677     (gnus-summary-scroll-up (* amount direction))
10678     (when (gnus-eval-in-buffer-window gnus-article-buffer
10679             (save-restriction
10680               (widen)
10681               (and (if (< 0 direction)
10682                        (gnus-article-next-page 0)
10683                      (gnus-article-prev-page 0)
10684                      (bobp))
10685                    (if (setq edge (get-text-property
10686                                    (point-min) 'gnus-wheel-edge))
10687                        (setq edge (* edge direction))
10688                      (setq edge -1))
10689                    (or (plusp edge)
10690                        (let ((buffer-read-only nil)
10691                              (inhibit-read-only t))
10692                          (put-text-property (point-min) (point-max)
10693                                             'gnus-wheel-edge direction)
10694                          nil))
10695                    (or (> edge gnus-wheel-edge-resistance)
10696                        (let ((buffer-read-only nil)
10697                              (inhibit-read-only t))
10698                          (put-text-property (point-min) (point-max)
10699                                             'gnus-wheel-edge
10700                                             (* (1+ edge) direction))
10701                          nil))
10702                    (eq last-command 'gnus-wheel-summary-scroll))))
10703       (gnus-summary-next-article nil nil (minusp direction)))))
10704
10705 (defun gnus-wheel-install ()
10706   "Enable mouse wheel support on summary window."
10707   (when gnus-use-wheel
10708     (let ((keys
10709            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
10710       (dolist (key keys)
10711         (define-key gnus-summary-mode-map key
10712           'gnus-wheel-summary-scroll)))))
10713
10714 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
10715
10716 ;;;
10717 ;;; Traditional PGP commmands
10718 ;;;
10719
10720 (defun gnus-summary-decrypt-article (&optional force)
10721   "Decrypt the current article in traditional PGP way.
10722 This will have permanent effect only in mail groups.
10723 If FORCE is non-nil, allow editing of articles even in read-only
10724 groups."
10725   (interactive "P")
10726   (gnus-summary-select-article t)
10727   (gnus-eval-in-buffer-window gnus-article-buffer
10728     (save-excursion
10729       (save-restriction
10730         (widen)
10731         (goto-char (point-min))
10732         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
10733           (error "Not a traditional PGP message!"))
10734         (let ((armor-start (match-beginning 0)))
10735           (if (and (pgg-decrypt-region armor-start (point-max))
10736                    (or force (not (gnus-group-read-only-p))))
10737               (let ((inhibit-read-only t)
10738                     buffer-read-only)
10739                 (delete-region armor-start
10740                                (progn
10741                                  (re-search-forward "^-+END PGP" nil t)
10742                                  (beginning-of-line 2)
10743                                  (point)))
10744                 (insert-buffer-substring pgg-output-buffer))))))))
10745
10746 (defun gnus-summary-verify-article ()
10747   "Verify the current article in traditional PGP way."
10748   (interactive)
10749   (save-excursion
10750     (set-buffer gnus-original-article-buffer)
10751     (goto-char (point-min))
10752     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
10753       (error "Not a traditional PGP message!"))
10754     (re-search-forward "^-+END PGP" nil t)
10755     (beginning-of-line 2)
10756     (call-interactively (function pgg-verify-region))))
10757
10758 ;;;
10759 ;;; Generic summary marking commands
10760 ;;;
10761
10762 (defvar gnus-summary-marking-alist
10763   '((read gnus-del-mark "d")
10764     (unread gnus-unread-mark "u")
10765     (ticked gnus-ticked-mark "!")
10766     (dormant gnus-dormant-mark "?")
10767     (expirable gnus-expirable-mark "e"))
10768   "An alist of names/marks/keystrokes.")
10769
10770 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
10771 (defvar gnus-summary-mark-map)
10772
10773 (defun gnus-summary-make-all-marking-commands ()
10774   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
10775   (dolist (elem gnus-summary-marking-alist)
10776     (apply 'gnus-summary-make-marking-command elem)))
10777
10778 (defun gnus-summary-make-marking-command (name mark keystroke)
10779   (let ((map (make-sparse-keymap)))
10780     (define-key gnus-summary-generic-mark-map keystroke map)
10781     (dolist (lway `((next "next" next nil "n")
10782                     (next-unread "next unread" next t "N")
10783                     (prev "previous" prev nil "p")
10784                     (prev-unread "previous unread" prev t "P")
10785                     (nomove "" nil nil ,keystroke)))
10786       (let ((func (gnus-summary-make-marking-command-1
10787                    mark (car lway) lway name)))
10788         (setq func (eval func))
10789         (define-key map (nth 4 lway) func)))))
10790
10791 (defun gnus-summary-make-marking-command-1 (mark way lway name)
10792   `(defun ,(intern
10793             (format "gnus-summary-put-mark-as-%s%s"
10794                     name (if (eq way 'nomove)
10795                              ""
10796                            (concat "-" (symbol-name way)))))
10797      (n)
10798      ,(format
10799        "Mark the current article as %s%s.
10800 If N, the prefix, then repeat N times.
10801 If N is negative, move in reverse order.
10802 The difference between N and the actual number of articles marked is
10803 returned."
10804        name (car (cdr lway)))
10805      (interactive "p")
10806      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
10807
10808 (defun gnus-summary-generic-mark (n mark move unread)
10809   "Mark N articles with MARK."
10810   (unless (eq major-mode 'gnus-summary-mode)
10811     (error "This command can only be used in the summary buffer"))
10812   (gnus-summary-show-thread)
10813   (let ((nummove
10814          (cond
10815           ((eq move 'next) 1)
10816           ((eq move 'prev) -1)
10817           (t 0))))
10818     (if (zerop nummove)
10819         (setq n 1)
10820       (when (< n 0)
10821         (setq n (abs n)
10822               nummove (* -1 nummove))))
10823     (while (and (> n 0)
10824                 (gnus-summary-mark-article nil mark)
10825                 (zerop (gnus-summary-next-subject nummove unread t)))
10826       (setq n (1- n)))
10827     (when (/= 0 n)
10828       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10829     (gnus-summary-recenter)
10830     (gnus-summary-position-point)
10831     (gnus-set-mode-line 'summary)
10832     n))
10833
10834 (defun gnus-summary-insert-articles (articles)
10835   (when (setq articles
10836               (gnus-set-difference articles
10837                                    (mapcar (lambda (h) (mail-header-number h))
10838                                            gnus-newsgroup-headers)))
10839     (setq gnus-newsgroup-headers
10840           (merge 'list
10841                  gnus-newsgroup-headers
10842                  (gnus-fetch-headers articles)
10843                  'gnus-article-sort-by-number))
10844     ;; Suppress duplicates?
10845     (when gnus-suppress-duplicates
10846       (gnus-dup-suppress-articles))
10847
10848     ;; We might want to build some more threads first.
10849     (when (and gnus-fetch-old-headers
10850                (eq gnus-headers-retrieved-by 'nov))
10851       (if (eq gnus-fetch-old-headers 'invisible)
10852           (gnus-build-all-threads)
10853         (gnus-build-old-threads)))
10854     ;; Let the Gnus agent mark articles as read.
10855     (when gnus-agent
10856       (gnus-agent-get-undownloaded-list))
10857     ;; Remove list identifiers from subject
10858     (when gnus-list-identifiers
10859       (gnus-summary-remove-list-identifiers))
10860     ;; First and last article in this newsgroup.
10861     (when gnus-newsgroup-headers
10862       (setq gnus-newsgroup-begin
10863             (mail-header-number (car gnus-newsgroup-headers))
10864             gnus-newsgroup-end
10865             (mail-header-number
10866              (gnus-last-element gnus-newsgroup-headers))))
10867     (when gnus-use-scoring
10868       (gnus-possibly-score-headers))))
10869
10870 (defun gnus-summary-insert-old-articles (&optional all)
10871   "Insert all old articles in this group.
10872 If ALL is non-nil, already read articles become readable.
10873 If ALL is a number, fetch this number of articles."
10874   (interactive "P")
10875   (prog1
10876       (let ((old (mapcar 'car gnus-newsgroup-data))
10877             (i (car gnus-newsgroup-active))
10878             older len)
10879         (while (<= i (cdr gnus-newsgroup-active))
10880           (or (memq i old) (push i older))
10881           (incf i))
10882         (setq len (length older))
10883         (cond
10884          ((null older) nil)
10885          ((numberp all)
10886           (if (< all len)
10887               (setq older (subseq older 0 all))))
10888          (all nil)
10889          (t
10890           (if (and (numberp gnus-large-newsgroup)
10891                    (> len gnus-large-newsgroup))
10892               (let ((input
10893                      (read-string
10894                       (format
10895                        "How many articles from %s (default %d): "
10896                        (gnus-limit-string
10897                         (gnus-group-decoded-name gnus-newsgroup-name) 35)
10898                        len))))
10899                 (unless (string-match "^[ \t]*$" input)
10900                   (setq all (string-to-number input))
10901                   (if (< all len)
10902                       (setq older (subseq older 0 all))))))))
10903         (if (not older)
10904             (message "No old news.")
10905           (gnus-summary-insert-articles older)
10906           (gnus-summary-limit (gnus-union older old))))
10907     (gnus-summary-position-point)))
10908
10909 (defun gnus-summary-insert-new-articles ()
10910   "Insert all new articles in this group."
10911   (interactive)
10912   (prog1
10913       (let ((old (mapcar 'car gnus-newsgroup-data))
10914             (old-active gnus-newsgroup-active)
10915             (nnmail-fetched-sources (list t))
10916             i new)
10917         (setq gnus-newsgroup-active
10918               (gnus-activate-group gnus-newsgroup-name 'scan))
10919         (setq i (1+ (cdr old-active)))
10920         (while (<= i (cdr gnus-newsgroup-active))
10921           (push i new)
10922           (incf i))
10923         (if (not new)
10924             (message "No gnus is bad news.")
10925           (setq new (nreverse new))
10926           (gnus-summary-insert-articles new)
10927           (setq gnus-newsgroup-unreads
10928                 (append gnus-newsgroup-unreads new))
10929           (gnus-summary-limit (gnus-union old new))))
10930     (gnus-summary-position-point)))
10931
10932 (gnus-summary-make-all-marking-commands)
10933
10934 (gnus-ems-redefine)
10935
10936 (provide 'gnus-sum)
10937
10938 (run-hooks 'gnus-sum-load-hook)
10939
10940 ;;; gnus-sum.el ends here