Synch to No Gnus 200412231849.
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Semi-gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
64
65 (defcustom gnus-kill-summary-on-exit t
66   "*If non-nil, kill the summary buffer when you exit from it.
67 If nil, the summary will become a \"*Dead Summary*\" buffer, and
68 it will be killed sometime later."
69   :group 'gnus-summary-exit
70   :type 'boolean)
71
72 (defcustom gnus-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is t, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const :tag "on" t)
88                  (const some)
89                  (const invisible)
90                  number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-refer-thread-limit 200
94   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
95 If t, fetch all the available old headers."
96   :group 'gnus-thread
97   :type '(choice number
98                  (sexp :menu-tag "other" t)))
99
100 (defcustom gnus-summary-make-false-root 'adopt
101   "*nil means that Gnus won't gather loose threads.
102 If the root of a thread has expired or been read in a previous
103 session, the information necessary to build a complete thread has been
104 lost.  Instead of having many small sub-threads from this original thread
105 scattered all over the summary buffer, Gnus can gather them.
106
107 If non-nil, Gnus will try to gather all loose sub-threads from an
108 original thread into one large thread.
109
110 If this variable is non-nil, it should be one of `none', `adopt',
111 `dummy' or `empty'.
112
113 If this variable is `none', Gnus will not make a false root, but just
114 present the sub-threads after another.
115 If this variable is `dummy', Gnus will create a dummy root that will
116 have all the sub-threads as children.
117 If this variable is `adopt', Gnus will make one of the \"children\"
118 the parent and mark all the step-children as such.
119 If this variable is `empty', the \"children\" are printed with empty
120 subject fields.  (Or rather, they will be printed with a string
121 given by the `gnus-summary-same-subject' variable.)"
122   :group 'gnus-thread
123   :type '(choice (const :tag "off" nil)
124                  (const none)
125                  (const dummy)
126                  (const adopt)
127                  (const empty)))
128
129 (defcustom gnus-summary-make-false-root-always nil
130   "Always make a false dummy root."
131   :version "21.4"
132   :group 'gnus-thread
133   :type 'boolean)
134
135 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
136   "*A regexp to match subjects to be excluded from loose thread gathering.
137 As loose thread gathering is done on subjects only, that means that
138 there can be many false gatherings performed.  By rooting out certain
139 common subjects, gathering might become saner."
140   :group 'gnus-thread
141   :type 'regexp)
142
143 (defcustom gnus-summary-gather-subject-limit nil
144   "*Maximum length of subject comparisons when gathering loose threads.
145 Use nil to compare full subjects.  Setting this variable to a low
146 number will help gather threads that have been corrupted by
147 newsreaders chopping off subject lines, but it might also mean that
148 unrelated articles that have subject that happen to begin with the
149 same few characters will be incorrectly gathered.
150
151 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
152 comparing subjects."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const fuzzy)
156                  (sexp :menu-tag "on" t)))
157
158 (defcustom gnus-simplify-subject-functions nil
159   "List of functions taking a string argument that simplify subjects.
160 The functions are applied recursively.
161
162 Useful functions to put in this list include:
163 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
164 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
165   :group 'gnus-thread
166   :type '(repeat function))
167
168 (defcustom gnus-simplify-ignored-prefixes nil
169   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  regexp))
173
174 (defcustom gnus-build-sparse-threads nil
175   "*If non-nil, fill in the gaps in threads.
176 If `some', only fill in the gaps that are needed to tie loose threads
177 together.  If `more', fill in all leaf nodes that Gnus can find.  If
178 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  (const some)
182                  (const more)
183                  (sexp :menu-tag "all" t)))
184
185 (defcustom gnus-summary-thread-gathering-function
186   'gnus-gather-threads-by-subject
187   "*Function used for gathering loose threads.
188 There are two pre-defined functions: `gnus-gather-threads-by-subject',
189 which only takes Subjects into consideration; and
190 `gnus-gather-threads-by-references', which compared the References
191 headers of the articles to find matches."
192   :group 'gnus-thread
193   :type '(radio (function-item gnus-gather-threads-by-subject)
194                 (function-item gnus-gather-threads-by-references)
195                 (function :tag "other")))
196
197 (defcustom gnus-summary-same-subject ""
198   "*String indicating that the current article has the same subject as the previous.
199 This variable will only be used if the value of
200 `gnus-summary-make-false-root' is `empty'."
201   :group 'gnus-summary-format
202   :type 'string)
203
204 (defcustom gnus-summary-goto-unread t
205   "*If t, many commands will go to the next unread article.
206 This applies to marking commands as well as other commands that
207 \"naturally\" select the next article, like, for instance, `SPC' at
208 the end of an article.
209
210 If nil, the marking commands do NOT go to the next unread article
211 \(they go to the next article instead).  If `never', commands that
212 usually go to the next unread article, will go to the next article,
213 whether it is read or not."
214   :group 'gnus-summary-marks
215   :link '(custom-manual "(gnus)Setting Marks")
216   :type '(choice (const :tag "off" nil)
217                  (const never)
218                  (sexp :menu-tag "on" t)))
219
220 (defcustom gnus-summary-default-score 0
221   "*Default article score level.
222 All scores generated by the score files will be added to this score.
223 If this variable is nil, scoring will be disabled."
224   :group 'gnus-score-default
225   :type '(choice (const :tag "disable")
226                  integer))
227
228 (defcustom gnus-summary-default-high-score 0
229   "*Default threshold for a high scored article.
230 An article will be highlighted as high scored if its score is greater
231 than this score."
232   :version "21.4"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-default-low-score 0
237   "*Default threshold for a low scored article.
238 An article will be highlighted as low scored if its score is smaller
239 than this score."
240   :version "21.4"
241   :group 'gnus-score-default
242   :type 'integer)
243
244 (defcustom gnus-summary-zcore-fuzz 0
245   "*Fuzziness factor for the zcore in the summary buffer.
246 Articles with scores closer than this to `gnus-summary-default-score'
247 will not be marked."
248   :group 'gnus-summary-format
249   :type 'integer)
250
251 (defcustom gnus-simplify-subject-fuzzy-regexp nil
252   "*Strings to be removed when doing fuzzy matches.
253 This can either be a regular expression or list of regular expressions
254 that will be removed from subject strings if fuzzy subject
255 simplification is selected."
256   :group 'gnus-thread
257   :type '(repeat regexp))
258
259 (defcustom gnus-show-threads t
260   "*If non-nil, display threads in summary mode."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-hide-subtree nil
265   "*If non-nil, hide all threads initially.
266 This can be a predicate specifier which says which threads to hide.
267 If threads are hidden, you have to run the command
268 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
269 to expose hidden threads."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), 'unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "21.4"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "21.4"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "21.4"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "21.4"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "21.4"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "21.4"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "21.4"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "21.4"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
808 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
809 `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date',
811 `gnus-thread-sort-by-random', and
812 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat 
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-subject)
822                    (function-item gnus-thread-sort-by-date)
823                    (function-item gnus-thread-sort-by-score)
824                    (function-item gnus-thread-sort-by-most-recent-number)
825                    (function-item gnus-thread-sort-by-most-recent-date)
826                    (function-item gnus-thread-sort-by-random)
827                    (function-item gnus-thread-sort-by-total-score)
828                    (function :tag "other"))
829            (boolean :tag "Reverse order"))))
830
831 (defcustom gnus-thread-score-function '+
832   "*Function used for calculating the total score of a thread.
833
834 The function is called with the scores of the article and each
835 subthread and should then return the score of the thread.
836
837 Some functions you can use are `+', `max', or `min'."
838   :group 'gnus-summary-sort
839   :type 'function)
840
841 (defcustom gnus-summary-expunge-below nil
842   "All articles that have a score less than this variable will be expunged.
843 This variable is local to the summary buffers."
844   :group 'gnus-score-default
845   :type '(choice (const :tag "off" nil)
846                  integer))
847
848 (defcustom gnus-thread-expunge-below nil
849   "All threads that have a total score less than this variable will be expunged.
850 See `gnus-thread-score-function' for en explanation of what a
851 \"thread score\" is.
852
853 This variable is local to the summary buffers."
854   :group 'gnus-threading
855   :group 'gnus-score-default
856   :type '(choice (const :tag "off" nil)
857                  integer))
858
859 (defcustom gnus-summary-mode-hook nil
860   "*A hook for Gnus summary mode.
861 This hook is run before any variables are set in the summary buffer."
862   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
867 (when (featurep 'xemacs)
868   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
870   (add-hook 'gnus-summary-mode-hook
871             'gnus-xmas-switch-horizontal-scrollbar-off))
872
873 (defcustom gnus-summary-menu-hook nil
874   "*Hook run after the creation of the summary mode menu."
875   :group 'gnus-summary-visual
876   :type 'hook)
877
878 (defcustom gnus-summary-exit-hook nil
879   "*A hook called on exit from the summary buffer.
880 It will be called with point in the group buffer."
881   :group 'gnus-summary-exit
882   :type 'hook)
883
884 (defcustom gnus-summary-prepare-hook nil
885   "*A hook called after the summary buffer has been generated.
886 If you want to modify the summary buffer, you can use this hook."
887   :group 'gnus-summary-various
888   :type 'hook)
889
890 (defcustom gnus-summary-prepared-hook nil
891   "*A hook called as the last thing after the summary buffer has been generated."
892   :group 'gnus-summary-various
893   :type 'hook)
894
895 (defcustom gnus-summary-generate-hook nil
896   "*A hook run just before generating the summary buffer.
897 This hook is commonly used to customize threading variables and the
898 like."
899   :group 'gnus-summary-various
900   :type 'hook)
901
902 (defcustom gnus-select-group-hook nil
903   "*A hook called when a newsgroup is selected.
904
905 If you'd like to simplify subjects like the
906 `gnus-summary-next-same-subject' command does, you can use the
907 following hook:
908
909  (add-hook gnus-select-group-hook
910            (lambda ()
911              (mapcar (lambda (header)
912                        (mail-header-set-subject
913                         header
914                         (gnus-simplify-subject
915                          (mail-header-subject header) 're-only)))
916                      gnus-newsgroup-headers)))"
917   :group 'gnus-group-select
918   :type 'hook)
919
920 (defcustom gnus-select-article-hook nil
921   "*A hook called when an article is selected."
922   :group 'gnus-summary-choose
923   :options '(gnus-agent-fetch-selected-article)
924   :type 'hook)
925
926 (defcustom gnus-visual-mark-article-hook
927   (list 'gnus-highlight-selected-summary)
928   "*Hook run after selecting an article in the summary buffer.
929 It is meant to be used for highlighting the article in some way.  It
930 is not run if `gnus-visual' is nil."
931   :group 'gnus-summary-visual
932   :type 'hook)
933
934 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
935   "*A hook called before parsing the headers."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-exit-group-hook nil
940   "*A hook called when exiting summary mode.
941 This hook is not called from the non-updating exit commands like `Q'."
942   :group 'gnus-various
943   :type 'hook)
944
945 (defcustom gnus-summary-update-hook
946   (list 'gnus-summary-highlight-line)
947   "*A hook called when a summary line is changed.
948 The hook will not be called if `gnus-visual' is nil.
949
950 The default function `gnus-summary-highlight-line' will
951 highlight the line according to the `gnus-summary-highlight'
952 variable."
953   :group 'gnus-summary-visual
954   :type 'hook)
955
956 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
957   "*A hook called when an article is selected for the first time.
958 The hook is intended to mark an article as read (or unread)
959 automatically when it is selected."
960   :group 'gnus-summary-choose
961   :type 'hook)
962
963 (defcustom gnus-group-no-more-groups-hook nil
964   "*A hook run when returning to group mode having no more (unread) groups."
965   :group 'gnus-group-select
966   :type 'hook)
967
968 (defcustom gnus-ps-print-hook nil
969   "*A hook run before ps-printing something from Gnus."
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-article-move-hook nil
974   "*A hook called after an article is moved, copied, respooled, or crossposted."
975   :version "21.4"
976   :group 'gnus-summary
977   :type 'hook)
978
979 (defcustom gnus-summary-article-delete-hook nil
980   "*A hook called after an article is deleted."
981   :version "21.4"
982   :group 'gnus-summary
983   :type 'hook)
984
985 (defcustom gnus-summary-article-expire-hook nil
986   "*A hook called after an article is expired."
987   :version "21.4"
988   :group 'gnus-summary
989   :type 'hook)
990
991 (defcustom gnus-summary-display-arrow
992   (and (fboundp 'display-graphic-p)
993        (display-graphic-p))
994   "*If non-nil, display an arrow highlighting the current article."
995   :version "21.4"
996   :group 'gnus-summary
997   :type 'boolean)
998
999 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
1000   "Face used for highlighting the current article in the summary buffer."
1001   :group 'gnus-summary-visual
1002   :type 'face)
1003
1004 (defvar gnus-tmp-downloaded nil)
1005
1006 (defcustom gnus-summary-highlight
1007   '(((eq mark gnus-canceled-mark)
1008      . gnus-summary-cancelled-face)
1009     ((and uncached (> score default-high))
1010      . gnus-summary-high-undownloaded-face)
1011     ((and uncached (< score default-low))
1012      . gnus-summary-low-undownloaded-face)
1013     (uncached
1014      . gnus-summary-normal-undownloaded-face)
1015     ((and (> score default-high)
1016           (or (eq mark gnus-dormant-mark)
1017               (eq mark gnus-ticked-mark)))
1018      . gnus-summary-high-ticked-face)
1019     ((and (< score default-low)
1020           (or (eq mark gnus-dormant-mark)
1021               (eq mark gnus-ticked-mark)))
1022      . gnus-summary-low-ticked-face)
1023     ((or (eq mark gnus-dormant-mark)
1024          (eq mark gnus-ticked-mark))
1025      . gnus-summary-normal-ticked-face)
1026     ((and (> score default-high) (eq mark gnus-ancient-mark))
1027      . gnus-summary-high-ancient-face)
1028     ((and (< score default-low) (eq mark gnus-ancient-mark))
1029      . gnus-summary-low-ancient-face)
1030     ((eq mark gnus-ancient-mark)
1031      . gnus-summary-normal-ancient-face)
1032     ((and (> score default-high) (eq mark gnus-unread-mark))
1033      . gnus-summary-high-unread-face)
1034     ((and (< score default-low) (eq mark gnus-unread-mark))
1035      . gnus-summary-low-unread-face)
1036     ((eq mark gnus-unread-mark)
1037      . gnus-summary-normal-unread-face)
1038     ((> score default-high)
1039      . gnus-summary-high-read-face)
1040     ((< score default-low)
1041      . gnus-summary-low-read-face)
1042     (t
1043      . gnus-summary-normal-read-face))
1044   "*Controls the highlighting of summary buffer lines.
1045
1046 A list of (FORM . FACE) pairs.  When deciding how a a particular
1047 summary line should be displayed, each form is evaluated.  The content
1048 of the face field after the first true form is used.  You can change
1049 how those summary lines are displayed, by editing the face field.
1050
1051 You can use the following variables in the FORM field.
1052
1053 score:        The article's score
1054 default:      The default article score.
1055 default-high: The default score for high scored articles.
1056 default-low:  The default score for low scored articles.
1057 below:        The score below which articles are automatically marked as read.
1058 mark:         The article's mark.
1059 uncached:     Non-nil if the article is uncached."
1060   :group 'gnus-summary-visual
1061   :type '(repeat (cons (sexp :tag "Form" nil)
1062                        face)))
1063
1064 (defcustom gnus-alter-header-function nil
1065   "Function called to allow alteration of article header structures.
1066 The function is called with one parameter, the article header vector,
1067 which it may alter in any way."
1068   :type '(choice (const :tag "None" nil)
1069                  function)
1070   :group 'gnus-summary)
1071
1072 (defvar gnus-decode-encoded-word-function
1073   (mime-find-field-decoder 'From 'nov)
1074   "Variable that says which function should be used to decode a string with encoded words.")
1075
1076 (defcustom gnus-extra-headers '(To Newsgroups)
1077   "*Extra headers to parse."
1078   :version "21.1"
1079   :group 'gnus-summary
1080   :type '(repeat symbol))
1081
1082 (defcustom gnus-ignored-from-addresses
1083   (and user-mail-address (regexp-quote user-mail-address))
1084   "*Regexp of From headers that may be suppressed in favor of To headers."
1085   :version "21.1"
1086   :group 'gnus-summary
1087   :type 'regexp)
1088
1089 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1090   "List of charsets that should be ignored.
1091 When these charsets are used in the \"charset\" parameter, the
1092 default charset will be used instead."
1093   :version "21.1"
1094   :type '(repeat symbol)
1095   :group 'gnus-charset)
1096
1097 (gnus-define-group-parameter
1098  ignored-charsets
1099  :type list
1100  :function-document
1101  "Return the ignored charsets of GROUP."
1102  :variable gnus-group-ignored-charsets-alist
1103  :variable-default
1104  '(("alt\\.chinese\\.text" iso-8859-1))
1105  :variable-document
1106  "Alist of regexps (to match group names) and charsets that should be ignored.
1107 When these charsets are used in the \"charset\" parameter, the
1108 default charset will be used instead."
1109  :variable-group gnus-charset
1110  :variable-type '(repeat (cons (regexp :tag "Group")
1111                                (repeat symbol)))
1112  :parameter-type '(choice :tag "Ignored charsets"
1113                           :value nil
1114                           (repeat (symbol)))
1115  :parameter-document       "\
1116 List of charsets that should be ignored.
1117
1118 When these charsets are used in the \"charset\" parameter, the
1119 default charset will be used instead.")
1120
1121 (defcustom gnus-group-highlight-words-alist nil
1122   "Alist of group regexps and highlight regexps.
1123 This variable uses the same syntax as `gnus-emphasis-alist'."
1124   :version "21.1"
1125   :type '(repeat (cons (regexp :tag "Group")
1126                        (repeat (list (regexp :tag "Highlight regexp")
1127                                      (number :tag "Group for entire word" 0)
1128                                      (number :tag "Group for displayed part" 0)
1129                                      (symbol :tag "Face"
1130                                              gnus-emphasis-highlight-words)))))
1131   :group 'gnus-summary-visual)
1132
1133 (defcustom gnus-use-wheel nil
1134   "Use Intelli-mouse on summary movement"
1135   :type 'boolean
1136   :group 'gnus-summary-maneuvering)
1137
1138 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1139   "Amount to scroll messages by spinning the mouse wheel.
1140 This is actually a cons cell, where the first item is the amount to scroll
1141 on a normal wheel event, and the second is the amount to scroll when the
1142 wheel is moved with the shift key depressed."
1143   :type '(cons (integer :tag "Shift") integer)
1144   :group 'gnus-summary-maneuvering)
1145
1146 (defcustom gnus-wheel-edge-resistance 2
1147   "How hard it should be to change the current article
1148 by moving the mouse over the edge of the article window."
1149   :type 'integer
1150   :group 'gnus-summary-maneuvering)
1151
1152 (defcustom gnus-summary-show-article-charset-alist
1153   nil
1154   "Alist of number and charset.
1155 The article will be shown with the charset corresponding to the
1156 numbered argument.
1157 For example: ((1 . cn-gb-2312) (2 . big5))."
1158   :version "21.1"
1159   :type '(repeat (cons (number :tag "Argument" 1)
1160                        (symbol :tag "Charset")))
1161   :group 'gnus-charset)
1162
1163 (defcustom gnus-preserve-marks t
1164   "Whether marks are preserved when moving, copying and respooling messages."
1165   :version "21.1"
1166   :type 'boolean
1167   :group 'gnus-summary-marks)
1168
1169 (defcustom gnus-alter-articles-to-read-function nil
1170   "Function to be called to alter the list of articles to be selected."
1171   :type '(choice (const nil) function)
1172   :group 'gnus-summary)
1173
1174 (defcustom gnus-orphan-score nil
1175   "*All orphans get this score added.  Set in the score file."
1176   :group 'gnus-score-default
1177   :type '(choice (const nil)
1178                  integer))
1179
1180 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1181   "*A regexp to match MIME parts when saving multiple parts of a
1182 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1183 This regexp will be used by default when prompting the user for which
1184 type of files to save."
1185   :group 'gnus-summary
1186   :type 'regexp)
1187
1188 (defcustom gnus-read-all-available-headers nil
1189   "Whether Gnus should parse all headers made available to it.
1190 This is mostly relevant for slow back ends where the user may
1191 wish to widen the summary buffer to include all headers
1192 that were fetched.  Say, for nnultimate groups."
1193   :version "21.4"
1194   :group 'gnus-summary
1195   :type '(choice boolean regexp))
1196
1197 (defcustom gnus-summary-muttprint-program "muttprint"
1198   "Command (and optional arguments) used to run Muttprint."
1199   :version "21.4"
1200   :group 'gnus-summary
1201   :type 'string)
1202
1203 (defcustom gnus-article-loose-mime t
1204   "If non-nil, don't require MIME-Version header.
1205 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1206 supply the MIME-Version header or deliberately strip it from the mail.
1207 If non-nil (the default), Gnus will treat some articles as MIME
1208 even if the MIME-Version header is missing."
1209   :version "21.4"
1210   :type 'boolean
1211   :group 'gnus-article-mime)
1212
1213 (defcustom gnus-article-emulate-mime t
1214   "If non-nil, use MIME emulation for uuencode and the like.
1215 This means that Gnus will search message bodies for text that look
1216 like uuencoded bits, yEncoded bits, and so on, and present that using
1217 the normal Gnus MIME machinery."
1218   :version "21.4"
1219   :type 'boolean
1220   :group 'gnus-article-mime)
1221
1222 ;;; Internal variables
1223
1224 (defvar gnus-summary-display-cache nil)
1225 (defvar gnus-article-mime-handles nil)
1226 (defvar gnus-article-decoded-p nil)
1227 (defvar gnus-article-charset nil)
1228 (defvar gnus-article-ignored-charsets nil)
1229 (defvar gnus-scores-exclude-files nil)
1230 (defvar gnus-page-broken nil)
1231
1232 (defvar gnus-original-article nil)
1233 (defvar gnus-article-internal-prepare-hook nil)
1234 (defvar gnus-newsgroup-process-stack nil)
1235
1236 (defvar gnus-thread-indent-array nil)
1237 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1238 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1239   "Function called to sort the articles within a thread after it has been gathered together.")
1240
1241 (defvar gnus-summary-save-parts-type-history nil)
1242 (defvar gnus-summary-save-parts-last-directory nil)
1243
1244 ;; Avoid highlighting in kill files.
1245 (defvar gnus-summary-inhibit-highlight nil)
1246 (defvar gnus-newsgroup-selected-overlay nil)
1247 (defvar gnus-inhibit-limiting nil)
1248 (defvar gnus-newsgroup-adaptive-score-file nil)
1249 (defvar gnus-current-score-file nil)
1250 (defvar gnus-current-move-group nil)
1251 (defvar gnus-current-copy-group nil)
1252 (defvar gnus-current-crosspost-group nil)
1253 (defvar gnus-newsgroup-display nil)
1254
1255 (defvar gnus-newsgroup-dependencies nil)
1256 (defvar gnus-newsgroup-adaptive nil)
1257 (defvar gnus-summary-display-article-function nil)
1258 (defvar gnus-summary-highlight-line-function nil
1259   "Function called after highlighting a summary line.")
1260
1261 (defvar gnus-summary-line-format-alist
1262   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1263     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1264     (?s gnus-tmp-subject-or-nil ?s)
1265     (?n gnus-tmp-name ?s)
1266     (?A (std11-address-string
1267          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1268     (?a (or (std11-full-name-string
1269              (car (mime-entity-read-field gnus-tmp-header 'From)))
1270             gnus-tmp-from) ?s)
1271     (?F gnus-tmp-from ?s)
1272     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1273     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1274     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1275     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1276     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1277     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1278     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1279     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1280     (?L gnus-tmp-lines ?s)
1281     (?O gnus-tmp-downloaded ?c)
1282     (?I gnus-tmp-indentation ?s)
1283     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1284     (?R gnus-tmp-replied ?c)
1285     (?\[ gnus-tmp-opening-bracket ?c)
1286     (?\] gnus-tmp-closing-bracket ?c)
1287     (?\> (make-string gnus-tmp-level ? ) ?s)
1288     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1289     (?i gnus-tmp-score ?d)
1290     (?z gnus-tmp-score-char ?c)
1291     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1292     (?U gnus-tmp-unread ?c)
1293     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1294         ?s)
1295     (?t (gnus-summary-number-of-articles-in-thread
1296          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1297         ?d)
1298     (?e (gnus-summary-number-of-articles-in-thread
1299          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1300         ?c)
1301     (?u gnus-tmp-user-defined ?s)
1302     (?P (gnus-pick-line-number) ?d)
1303     (?B gnus-tmp-thread-tree-header-string ?s)
1304     (user-date (gnus-user-date
1305                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1306   "An alist of format specifications that can appear in summary lines.
1307 These are paired with what variables they correspond with, along with
1308 the type of the variable (string, integer, character, etc).")
1309
1310 (defvar gnus-summary-dummy-line-format-alist
1311   `((?S gnus-tmp-subject ?s)
1312     (?N gnus-tmp-number ?d)
1313     (?u gnus-tmp-user-defined ?s)))
1314
1315 (defvar gnus-summary-mode-line-format-alist
1316   `((?G gnus-tmp-group-name ?s)
1317     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1318     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1319     (?A gnus-tmp-article-number ?d)
1320     (?Z gnus-tmp-unread-and-unselected ?s)
1321     (?V gnus-version ?s)
1322     (?U gnus-tmp-unread-and-unticked ?d)
1323     (?S gnus-tmp-subject ?s)
1324     (?e gnus-tmp-unselected ?d)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?d (length gnus-newsgroup-dormant) ?d)
1327     (?t (length gnus-newsgroup-marked) ?d)
1328     (?h (length gnus-newsgroup-spam-marked) ?d)
1329     (?r (length gnus-newsgroup-reads) ?d)
1330     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1331     (?E gnus-newsgroup-expunged-tally ?d)
1332     (?s (gnus-current-score-file-nondirectory) ?s)))
1333
1334 (defvar gnus-last-search-regexp nil
1335   "Default regexp for article search command.")
1336
1337 (defvar gnus-summary-search-article-matched-data nil
1338   "Last matched data of article search command.  It is the local variable
1339 in `gnus-article-buffer' which consists of the list of start position,
1340 end position and text.")
1341
1342 (defvar gnus-last-shell-command nil
1343   "Default shell command on article.")
1344
1345 (defvar gnus-newsgroup-agentized nil
1346   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1347 (defvar gnus-newsgroup-begin nil)
1348 (defvar gnus-newsgroup-end nil)
1349 (defvar gnus-newsgroup-last-rmail nil)
1350 (defvar gnus-newsgroup-last-mail nil)
1351 (defvar gnus-newsgroup-last-folder nil)
1352 (defvar gnus-newsgroup-last-file nil)
1353 (defvar gnus-newsgroup-auto-expire nil)
1354 (defvar gnus-newsgroup-active nil)
1355
1356 (defvar gnus-newsgroup-data nil)
1357 (defvar gnus-newsgroup-data-reverse nil)
1358 (defvar gnus-newsgroup-limit nil)
1359 (defvar gnus-newsgroup-limits nil)
1360 (defvar gnus-summary-use-undownloaded-faces nil)
1361
1362 (defvar gnus-newsgroup-unreads nil
1363   "Sorted list of unread articles in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-unselected nil
1366   "Sorted list of unselected unread articles in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-reads nil
1369   "Alist of read articles and article marks in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expunged-tally nil)
1372
1373 (defvar gnus-newsgroup-marked nil
1374   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1375
1376 (defvar gnus-newsgroup-spam-marked nil
1377   "List of ranges of articles that have been marked as spam.")
1378
1379 (defvar gnus-newsgroup-killed nil
1380   "List of ranges of articles that have been through the scoring process.")
1381
1382 (defvar gnus-newsgroup-cached nil
1383   "Sorted list of articles that come from the article cache.")
1384
1385 (defvar gnus-newsgroup-saved nil
1386   "List of articles that have been saved.")
1387
1388 (defvar gnus-newsgroup-kill-headers nil)
1389
1390 (defvar gnus-newsgroup-replied nil
1391   "List of articles that have been replied to in the current newsgroup.")
1392
1393 (defvar gnus-newsgroup-forwarded nil
1394   "List of articles that have been forwarded in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-recent nil
1397   "List of articles that have are recent in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-expirable nil
1400   "Sorted list of articles in the current newsgroup that can be expired.")
1401
1402 (defvar gnus-newsgroup-processable nil
1403   "List of articles in the current newsgroup that can be processed.")
1404
1405 (defvar gnus-newsgroup-downloadable nil
1406   "Sorted list of articles in the current newsgroup that can be processed.")
1407
1408 (defvar gnus-newsgroup-unfetched nil
1409   "Sorted list of articles in the current newsgroup whose headers have
1410 not been fetched into the agent.
1411
1412 This list will always be a subset of gnus-newsgroup-undownloaded.")
1413
1414 (defvar gnus-newsgroup-undownloaded nil
1415   "List of articles in the current newsgroup that haven't been downloaded.")
1416
1417 (defvar gnus-newsgroup-unsendable nil
1418   "List of articles in the current newsgroup that won't be sent.")
1419
1420 (defvar gnus-newsgroup-bookmarks nil
1421   "List of articles in the current newsgroup that have bookmarks.")
1422
1423 (defvar gnus-newsgroup-dormant nil
1424   "Sorted list of dormant articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-unseen nil
1427   "List of unseen articles in the current newsgroup.")
1428
1429 (defvar gnus-newsgroup-seen nil
1430   "Range of seen articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-articles nil
1433   "List of articles in the current newsgroup.")
1434
1435 (defvar gnus-newsgroup-scored nil
1436   "List of scored articles in the current newsgroup.")
1437
1438 (defvar gnus-newsgroup-incorporated nil
1439   "List of incorporated articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-headers nil
1442   "List of article headers in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-threads nil)
1445
1446 (defvar gnus-newsgroup-prepared nil
1447   "Whether the current group has been prepared properly.")
1448
1449 (defvar gnus-newsgroup-ancient nil
1450   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-sparse nil)
1453
1454 (defvar gnus-current-article nil)
1455 (defvar gnus-article-current nil)
1456 (defvar gnus-current-headers nil)
1457 (defvar gnus-have-all-headers nil)
1458 (defvar gnus-last-article nil)
1459 (defvar gnus-newsgroup-history nil)
1460 (defvar gnus-newsgroup-charset nil)
1461 (defvar gnus-newsgroup-ephemeral-charset nil)
1462 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1463
1464 (defvar gnus-article-before-search nil)
1465
1466 (defvar gnus-summary-local-variables
1467   '(gnus-newsgroup-name
1468     gnus-newsgroup-begin gnus-newsgroup-end
1469     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1470     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1471     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1472     gnus-newsgroup-unselected gnus-newsgroup-marked
1473     gnus-newsgroup-spam-marked
1474     gnus-newsgroup-reads gnus-newsgroup-saved
1475     gnus-newsgroup-replied gnus-newsgroup-forwarded
1476     gnus-newsgroup-recent
1477     gnus-newsgroup-expirable
1478     gnus-newsgroup-processable gnus-newsgroup-killed
1479     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1480     gnus-newsgroup-unfetched
1481     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1482     gnus-newsgroup-seen gnus-newsgroup-articles
1483     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1484     gnus-newsgroup-headers gnus-newsgroup-threads
1485     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1486     gnus-current-article gnus-current-headers gnus-have-all-headers
1487     gnus-last-article gnus-article-internal-prepare-hook
1488     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1489     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1490     gnus-thread-expunge-below
1491     gnus-score-alist gnus-current-score-file
1492     (gnus-summary-expunge-below . global)
1493     (gnus-summary-mark-below . global)
1494     (gnus-orphan-score . global)
1495     gnus-newsgroup-active gnus-scores-exclude-files
1496     gnus-newsgroup-history gnus-newsgroup-ancient
1497     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1498     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1499     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1500     (gnus-newsgroup-expunged-tally . 0)
1501     gnus-cache-removable-articles gnus-newsgroup-cached
1502     gnus-newsgroup-data gnus-newsgroup-data-reverse
1503     gnus-newsgroup-limit gnus-newsgroup-limits
1504     gnus-newsgroup-charset gnus-newsgroup-display
1505     gnus-summary-use-undownloaded-faces
1506     gnus-newsgroup-incorporated)
1507   "Variables that are buffer-local to the summary buffers.")
1508
1509 (defvar gnus-newsgroup-variables nil
1510   "A list of variables that have separate values in different newsgroups.
1511 A list of newsgroup (summary buffer) local variables, or cons of
1512 variables and their default expressions to be evalled (when the default
1513 values are not nil), that should be made global while the summary buffer
1514 is active.
1515
1516 Note: The default expressions will be evaluated (using function `eval')
1517 before assignment to the local variable rather than just assigned to it.
1518 If the default expression is the symbol `global', that symbol will not
1519 be evaluated but the global value of the local variable will be used
1520 instead.
1521
1522 These variables can be used to set variables in the group parameters
1523 while still allowing them to affect operations done in other buffers.
1524 For example:
1525
1526 \(setq gnus-newsgroup-variables
1527      '(message-use-followup-to
1528        (gnus-visible-headers .
1529          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1530 ")
1531
1532 ;; Byte-compiler warning.
1533 (eval-when-compile
1534   ;; Bind features so that require will believe that gnus-sum has
1535   ;; already been loaded (avoids infinite recursion)
1536   (let ((features (cons 'gnus-sum features)))
1537     ;; Several of the declarations in gnus-sum are needed to load the
1538     ;; following files. Right now, these definitions have been
1539     ;; compiled but not defined (evaluated).  We could either do a
1540     ;; eval-and-compile about all of the declarations or evaluate the
1541     ;; source file.
1542     (if (boundp 'gnus-newsgroup-variables)
1543         nil
1544       (load "gnus-sum.el" t t t))
1545     (require 'gnus)
1546     (require 'gnus-art)))
1547
1548 ;; Subject simplification.
1549
1550 (defun gnus-simplify-whitespace (str)
1551   "Remove excessive whitespace from STR."
1552   ;; Multiple spaces.
1553   (while (string-match "[ \t][ \t]+" str)
1554     (setq str (concat (substring str 0 (match-beginning 0))
1555                         " "
1556                         (substring str (match-end 0)))))
1557   ;; Leading spaces.
1558   (when (string-match "^[ \t]+" str)
1559     (setq str (substring str (match-end 0))))
1560   ;; Trailing spaces.
1561   (when (string-match "[ \t]+$" str)
1562     (setq str (substring str 0 (match-beginning 0))))
1563   str)
1564
1565 (defun gnus-simplify-all-whitespace (str)
1566   "Remove all whitespace from STR."
1567   (while (string-match "[ \t\n]+" str)
1568     (setq str (replace-match "" nil nil str)))
1569   str)
1570
1571 (defsubst gnus-simplify-subject-re (subject)
1572   "Remove \"Re:\" from subject lines."
1573   (if (string-match message-subject-re-regexp subject)
1574       (substring subject (match-end 0))
1575     subject))
1576
1577 (defun gnus-simplify-subject (subject &optional re-only)
1578   "Remove `Re:' and words in parentheses.
1579 If RE-ONLY is non-nil, strip leading `Re:'s only."
1580   (let ((case-fold-search t))           ;Ignore case.
1581     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1582     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1583       (setq subject (substring subject (match-end 0))))
1584     ;; Remove uninteresting prefixes.
1585     (when (and (not re-only)
1586                gnus-simplify-ignored-prefixes
1587                (string-match gnus-simplify-ignored-prefixes subject))
1588       (setq subject (substring subject (match-end 0))))
1589     ;; Remove words in parentheses from end.
1590     (unless re-only
1591       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1592         (setq subject (substring subject 0 (match-beginning 0)))))
1593     ;; Return subject string.
1594     subject))
1595
1596 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1597 ;; all whitespace.
1598 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1599   (goto-char (point-min))
1600   (while (re-search-forward regexp nil t)
1601     (replace-match (or newtext ""))))
1602
1603 (defun gnus-simplify-buffer-fuzzy ()
1604   "Simplify string in the buffer fuzzily.
1605 The string in the accessible portion of the current buffer is simplified.
1606 It is assumed to be a single-line subject.
1607 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1608 matter is removed.  Additional things can be deleted by setting
1609 `gnus-simplify-subject-fuzzy-regexp'."
1610   (let ((case-fold-search t)
1611         (modified-tick))
1612     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1613
1614     (while (not (eq modified-tick (buffer-modified-tick)))
1615       (setq modified-tick (buffer-modified-tick))
1616       (cond
1617        ((listp gnus-simplify-subject-fuzzy-regexp)
1618         (mapcar 'gnus-simplify-buffer-fuzzy-step
1619                 gnus-simplify-subject-fuzzy-regexp))
1620        (gnus-simplify-subject-fuzzy-regexp
1621         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1622       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1623       (gnus-simplify-buffer-fuzzy-step
1624        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1625       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1626
1627     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1628     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1629     (gnus-simplify-buffer-fuzzy-step " $")
1630     (gnus-simplify-buffer-fuzzy-step "^ +")))
1631
1632 (defun gnus-simplify-subject-fuzzy (subject)
1633   "Simplify a subject string fuzzily.
1634 See `gnus-simplify-buffer-fuzzy' for details."
1635   (save-excursion
1636     (gnus-set-work-buffer)
1637     (let ((case-fold-search t))
1638       ;; Remove uninteresting prefixes.
1639       (when (and gnus-simplify-ignored-prefixes
1640                  (string-match gnus-simplify-ignored-prefixes subject))
1641         (setq subject (substring subject (match-end 0))))
1642       (insert subject)
1643       (inline (gnus-simplify-buffer-fuzzy))
1644       (buffer-string))))
1645
1646 (defsubst gnus-simplify-subject-fully (subject)
1647   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1648   (cond
1649    (gnus-simplify-subject-functions
1650     (gnus-map-function gnus-simplify-subject-functions subject))
1651    ((null gnus-summary-gather-subject-limit)
1652     (gnus-simplify-subject-re subject))
1653    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1654     (gnus-simplify-subject-fuzzy subject))
1655    ((numberp gnus-summary-gather-subject-limit)
1656     (gnus-limit-string (gnus-simplify-subject-re subject)
1657                        gnus-summary-gather-subject-limit))
1658    (t
1659     subject)))
1660
1661 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1662   "Check whether two subjects are equal.
1663 If optional argument SIMPLE-FIRST is t, first argument is already
1664 simplified."
1665   (cond
1666    ((null simple-first)
1667     (equal (gnus-simplify-subject-fully s1)
1668            (gnus-simplify-subject-fully s2)))
1669    (t
1670     (equal s1
1671            (gnus-simplify-subject-fully s2)))))
1672
1673 (defun gnus-summary-bubble-group ()
1674   "Increase the score of the current group.
1675 This is a handy function to add to `gnus-summary-exit-hook' to
1676 increase the score of each group you read."
1677   (gnus-group-add-score gnus-newsgroup-name))
1678
1679 \f
1680 ;;;
1681 ;;; Gnus summary mode
1682 ;;;
1683
1684 (put 'gnus-summary-mode 'mode-class 'special)
1685
1686 (defvar gnus-article-commands-menu)
1687
1688 ;; Non-orthogonal keys
1689
1690 (gnus-define-keys gnus-summary-mode-map
1691   " " gnus-summary-next-page
1692   "\177" gnus-summary-prev-page
1693   [delete] gnus-summary-prev-page
1694   [backspace] gnus-summary-prev-page
1695   "\r" gnus-summary-scroll-up
1696   "\M-\r" gnus-summary-scroll-down
1697   "n" gnus-summary-next-unread-article
1698   "p" gnus-summary-prev-unread-article
1699   "N" gnus-summary-next-article
1700   "P" gnus-summary-prev-article
1701   "\M-\C-n" gnus-summary-next-same-subject
1702   "\M-\C-p" gnus-summary-prev-same-subject
1703   "\M-n" gnus-summary-next-unread-subject
1704   "\M-p" gnus-summary-prev-unread-subject
1705   "." gnus-summary-first-unread-article
1706   "," gnus-summary-best-unread-article
1707   "\M-s" gnus-summary-search-article-forward
1708   "\M-r" gnus-summary-search-article-backward
1709   "<" gnus-summary-beginning-of-article
1710   ">" gnus-summary-end-of-article
1711   "j" gnus-summary-goto-article
1712   "^" gnus-summary-refer-parent-article
1713   "\M-^" gnus-summary-refer-article
1714   "u" gnus-summary-tick-article-forward
1715   "!" gnus-summary-tick-article-forward
1716   "U" gnus-summary-tick-article-backward
1717   "d" gnus-summary-mark-as-read-forward
1718   "D" gnus-summary-mark-as-read-backward
1719   "E" gnus-summary-mark-as-expirable
1720   "\M-u" gnus-summary-clear-mark-forward
1721   "\M-U" gnus-summary-clear-mark-backward
1722   "k" gnus-summary-kill-same-subject-and-select
1723   "\C-k" gnus-summary-kill-same-subject
1724   "\M-\C-k" gnus-summary-kill-thread
1725   "\M-\C-l" gnus-summary-lower-thread
1726   "e" gnus-summary-edit-article
1727   "#" gnus-summary-mark-as-processable
1728   "\M-#" gnus-summary-unmark-as-processable
1729   "\M-\C-t" gnus-summary-toggle-threads
1730   "\M-\C-s" gnus-summary-show-thread
1731   "\M-\C-h" gnus-summary-hide-thread
1732   "\M-\C-f" gnus-summary-next-thread
1733   "\M-\C-b" gnus-summary-prev-thread
1734   [(meta down)] gnus-summary-next-thread
1735   [(meta up)] gnus-summary-prev-thread
1736   "\M-\C-u" gnus-summary-up-thread
1737   "\M-\C-d" gnus-summary-down-thread
1738   "&" gnus-summary-execute-command
1739   "c" gnus-summary-catchup-and-exit
1740   "\C-w" gnus-summary-mark-region-as-read
1741   "\C-t" gnus-summary-toggle-truncation
1742   "?" gnus-summary-mark-as-dormant
1743   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1744   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1745   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1746   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1747   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1748   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1749   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1750   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1751   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1752   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1753   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1754   "=" gnus-summary-expand-window
1755   "\C-x\C-s" gnus-summary-reselect-current-group
1756   "\M-g" gnus-summary-rescan-group
1757   "w" gnus-summary-stop-page-breaking
1758   "\C-c\C-r" gnus-summary-caesar-message
1759   "\M-t" gnus-summary-toggle-mime
1760   "f" gnus-summary-followup
1761   "F" gnus-summary-followup-with-original
1762   "C" gnus-summary-cancel-article
1763   "r" gnus-summary-reply
1764   "R" gnus-summary-reply-with-original
1765   "\C-c\C-f" gnus-summary-mail-forward
1766   "o" gnus-summary-save-article
1767   "\C-o" gnus-summary-save-article-mail
1768   "|" gnus-summary-pipe-output
1769   "\M-k" gnus-summary-edit-local-kill
1770   "\M-K" gnus-summary-edit-global-kill
1771   ;; "V" gnus-version
1772   "\C-c\C-d" gnus-summary-describe-group
1773   "q" gnus-summary-exit
1774   "Q" gnus-summary-exit-no-update
1775   "\C-c\C-i" gnus-info-find-node
1776   gnus-mouse-2 gnus-mouse-pick-article
1777   "m" gnus-summary-mail-other-window
1778   "a" gnus-summary-post-news
1779   "i" gnus-summary-news-other-window
1780   "x" gnus-summary-limit-to-unread
1781   "s" gnus-summary-isearch-article
1782   "t" gnus-summary-toggle-header
1783   "g" gnus-summary-show-article
1784   "l" gnus-summary-goto-last-article
1785   "v" gnus-summary-preview-mime-message
1786   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1787   "\C-d" gnus-summary-enter-digest-group
1788   "\M-\C-d" gnus-summary-read-document
1789   "\M-\C-e" gnus-summary-edit-parameters
1790   "\M-\C-a" gnus-summary-customize-parameters
1791   "\C-c\C-b" gnus-bug
1792   "\C-c\C-n" gnus-namazu-search
1793   "*" gnus-cache-enter-article
1794   "\M-*" gnus-cache-remove-article
1795   "\M-&" gnus-summary-universal-argument
1796   "\C-l" gnus-recenter
1797   "I" gnus-summary-increase-score
1798   "L" gnus-summary-lower-score
1799   "\M-i" gnus-symbolic-argument
1800   "h" gnus-summary-select-article-buffer
1801
1802   "V" gnus-summary-score-map
1803   "X" gnus-uu-extract-map
1804   "S" gnus-summary-send-map)
1805
1806   ;; Sort of orthogonal keymap
1807 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1808   "t" gnus-summary-tick-article-forward
1809   "!" gnus-summary-tick-article-forward
1810   "d" gnus-summary-mark-as-read-forward
1811   "r" gnus-summary-mark-as-read-forward
1812   "c" gnus-summary-clear-mark-forward
1813   " " gnus-summary-clear-mark-forward
1814   "e" gnus-summary-mark-as-expirable
1815   "x" gnus-summary-mark-as-expirable
1816   "?" gnus-summary-mark-as-dormant
1817   "b" gnus-summary-set-bookmark
1818   "B" gnus-summary-remove-bookmark
1819   "#" gnus-summary-mark-as-processable
1820   "\M-#" gnus-summary-unmark-as-processable
1821   "S" gnus-summary-limit-include-expunged
1822   "C" gnus-summary-catchup
1823   "H" gnus-summary-catchup-to-here
1824   "h" gnus-summary-catchup-from-here
1825   "\C-c" gnus-summary-catchup-all
1826   "k" gnus-summary-kill-same-subject-and-select
1827   "K" gnus-summary-kill-same-subject
1828   "P" gnus-uu-mark-map)
1829
1830 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1831   "c" gnus-summary-clear-above
1832   "u" gnus-summary-tick-above
1833   "m" gnus-summary-mark-above
1834   "k" gnus-summary-kill-below)
1835
1836 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1837   "/" gnus-summary-limit-to-subject
1838   "n" gnus-summary-limit-to-articles
1839   "w" gnus-summary-pop-limit
1840   "s" gnus-summary-limit-to-subject
1841   "a" gnus-summary-limit-to-author
1842   "u" gnus-summary-limit-to-unread
1843   "m" gnus-summary-limit-to-marks
1844   "M" gnus-summary-limit-exclude-marks
1845   "v" gnus-summary-limit-to-score
1846   "*" gnus-summary-limit-include-cached
1847   "D" gnus-summary-limit-include-dormant
1848   "T" gnus-summary-limit-include-thread
1849   "d" gnus-summary-limit-exclude-dormant
1850   "t" gnus-summary-limit-to-age
1851   "." gnus-summary-limit-to-unseen
1852   "x" gnus-summary-limit-to-extra
1853   "p" gnus-summary-limit-to-display-predicate
1854   "E" gnus-summary-limit-include-expunged
1855   "c" gnus-summary-limit-exclude-childless-dormant
1856   "C" gnus-summary-limit-mark-excluded-as-read
1857   "o" gnus-summary-insert-old-articles
1858   "N" gnus-summary-insert-new-articles
1859   "r" gnus-summary-limit-to-replied
1860   "R" gnus-summary-limit-to-recipient)
1861
1862 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1863   "n" gnus-summary-next-unread-article
1864   "p" gnus-summary-prev-unread-article
1865   "N" gnus-summary-next-article
1866   "P" gnus-summary-prev-article
1867   "\C-n" gnus-summary-next-same-subject
1868   "\C-p" gnus-summary-prev-same-subject
1869   "\M-n" gnus-summary-next-unread-subject
1870   "\M-p" gnus-summary-prev-unread-subject
1871   "f" gnus-summary-first-unread-article
1872   "b" gnus-summary-best-unread-article
1873   "j" gnus-summary-goto-article
1874   "g" gnus-summary-goto-subject
1875   "l" gnus-summary-goto-last-article
1876   "o" gnus-summary-pop-article)
1877
1878 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1879   "k" gnus-summary-kill-thread
1880   "l" gnus-summary-lower-thread
1881   "i" gnus-summary-raise-thread
1882   "T" gnus-summary-toggle-threads
1883   "t" gnus-summary-rethread-current
1884   "^" gnus-summary-reparent-thread
1885   "s" gnus-summary-show-thread
1886   "S" gnus-summary-show-all-threads
1887   "h" gnus-summary-hide-thread
1888   "H" gnus-summary-hide-all-threads
1889   "n" gnus-summary-next-thread
1890   "p" gnus-summary-prev-thread
1891   "u" gnus-summary-up-thread
1892   "o" gnus-summary-top-thread
1893   "d" gnus-summary-down-thread
1894   "#" gnus-uu-mark-thread
1895   "\M-#" gnus-uu-unmark-thread)
1896
1897 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1898   "g" gnus-summary-prepare
1899   "c" gnus-summary-insert-cached-articles
1900   "d" gnus-summary-insert-dormant-articles)
1901
1902 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1903   "c" gnus-summary-catchup-and-exit
1904   "C" gnus-summary-catchup-all-and-exit
1905   "E" gnus-summary-exit-no-update
1906   "J" gnus-summary-jump-to-other-group
1907   "Q" gnus-summary-exit
1908   "Z" gnus-summary-exit
1909   "n" gnus-summary-catchup-and-goto-next-group
1910   "R" gnus-summary-reselect-current-group
1911   "G" gnus-summary-rescan-group
1912   "N" gnus-summary-next-group
1913   "s" gnus-summary-save-newsrc
1914   "P" gnus-summary-prev-group)
1915
1916 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1917   " " gnus-summary-next-page
1918   "n" gnus-summary-next-page
1919   "\177" gnus-summary-prev-page
1920   [delete] gnus-summary-prev-page
1921   "p" gnus-summary-prev-page
1922   "\r" gnus-summary-scroll-up
1923   "\M-\r" gnus-summary-scroll-down
1924   "<" gnus-summary-beginning-of-article
1925   ">" gnus-summary-end-of-article
1926   "b" gnus-summary-beginning-of-article
1927   "e" gnus-summary-end-of-article
1928   "^" gnus-summary-refer-parent-article
1929   "r" gnus-summary-refer-parent-article
1930   "D" gnus-summary-enter-digest-group
1931   "R" gnus-summary-refer-references
1932   "T" gnus-summary-refer-thread
1933   "g" gnus-summary-show-article
1934   "s" gnus-summary-isearch-article
1935   "P" gnus-summary-print-article
1936   "M" gnus-mailing-list-insinuate
1937   "t" gnus-article-babel)
1938
1939 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1940   "b" gnus-article-add-buttons
1941   "B" gnus-article-add-buttons-to-head
1942   "o" gnus-article-treat-overstrike
1943   "e" gnus-article-emphasize
1944   "w" gnus-article-fill-cited-article
1945   "Q" gnus-article-fill-long-lines
1946   "C" gnus-article-capitalize-sentences
1947   "c" gnus-article-remove-cr
1948   "Z" gnus-article-decode-HZ
1949   "A" gnus-article-treat-ansi-sequences
1950   "h" gnus-article-wash-html
1951   "u" gnus-article-unsplit-urls
1952   "f" gnus-article-display-x-face
1953   "l" gnus-summary-stop-page-breaking
1954   "r" gnus-summary-caesar-message
1955   "m" gnus-summary-morse-message
1956   "t" gnus-summary-toggle-header
1957   "g" gnus-treat-smiley
1958   "v" gnus-summary-verbose-headers
1959   "m" gnus-summary-toggle-mime
1960   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1961   "p" gnus-article-verify-x-pgp-sig
1962   "d" gnus-article-treat-dumbquotes)
1963
1964 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1965   ;; mnemonic: deuglif*Y*
1966   "u" gnus-article-outlook-unwrap-lines
1967   "a" gnus-article-outlook-repair-attribution
1968   "c" gnus-article-outlook-rearrange-citation
1969   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1970
1971 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1972   "a" gnus-article-hide
1973   "h" gnus-article-hide-headers
1974   "b" gnus-article-hide-boring-headers
1975   "s" gnus-article-hide-signature
1976   "c" gnus-article-hide-citation
1977   "C" gnus-article-hide-citation-in-followups
1978   "l" gnus-article-hide-list-identifiers
1979   "B" gnus-article-strip-banner
1980   "P" gnus-article-hide-pem
1981   "\C-c" gnus-article-hide-citation-maybe)
1982
1983 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1984   "a" gnus-article-highlight
1985   "h" gnus-article-highlight-headers
1986   "c" gnus-article-highlight-citation
1987   "s" gnus-article-highlight-signature)
1988
1989 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1990   "f" gnus-article-treat-fold-headers
1991   "u" gnus-article-treat-unfold-headers
1992   "n" gnus-article-treat-fold-newsgroups)
1993
1994 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1995   "x" gnus-article-display-x-face
1996   "d" gnus-article-display-face
1997   "s" gnus-treat-smiley
1998   "D" gnus-article-remove-images
1999   "f" gnus-treat-from-picon
2000   "m" gnus-treat-mail-picon
2001   "n" gnus-treat-newsgroups-picon)
2002
2003 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2004   "z" gnus-article-date-ut
2005   "u" gnus-article-date-ut
2006   "l" gnus-article-date-local
2007   "p" gnus-article-date-english
2008   "e" gnus-article-date-lapsed
2009   "o" gnus-article-date-original
2010   "i" gnus-article-date-iso8601
2011   "s" gnus-article-date-user)
2012
2013 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2014   "t" gnus-article-remove-trailing-blank-lines
2015   "l" gnus-article-strip-leading-blank-lines
2016   "m" gnus-article-strip-multiple-blank-lines
2017   "a" gnus-article-strip-blank-lines
2018   "A" gnus-article-strip-all-blank-lines
2019   "s" gnus-article-strip-leading-space
2020   "e" gnus-article-strip-trailing-space
2021   "w" gnus-article-remove-leading-whitespace)
2022
2023 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2024   "v" gnus-version
2025   "f" gnus-summary-fetch-faq
2026   "d" gnus-summary-describe-group
2027   "h" gnus-summary-describe-briefly
2028   "i" gnus-info-find-node
2029   "c" gnus-group-fetch-charter
2030   "C" gnus-group-fetch-control)
2031
2032 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2033   "e" gnus-summary-expire-articles
2034   "\M-\C-e" gnus-summary-expire-articles-now
2035   "\177" gnus-summary-delete-article
2036   [delete] gnus-summary-delete-article
2037   [backspace] gnus-summary-delete-article
2038   "m" gnus-summary-move-article
2039   "r" gnus-summary-respool-article
2040   "w" gnus-summary-edit-article
2041   "c" gnus-summary-copy-article
2042   "B" gnus-summary-crosspost-article
2043   "q" gnus-summary-respool-query
2044   "t" gnus-summary-respool-trace
2045   "i" gnus-summary-import-article
2046   "I" gnus-summary-create-article
2047   "p" gnus-summary-article-posted-p)
2048
2049 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2050   "o" gnus-summary-save-article
2051   "m" gnus-summary-save-article-mail
2052   "F" gnus-summary-write-article-file
2053   "r" gnus-summary-save-article-rmail
2054   "f" gnus-summary-save-article-file
2055   "b" gnus-summary-save-article-body-file
2056   "h" gnus-summary-save-article-folder
2057   "v" gnus-summary-save-article-vm
2058   "p" gnus-summary-pipe-output
2059   "P" gnus-summary-muttprint
2060   "s" gnus-soup-add-article)
2061
2062 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2063   "b" gnus-summary-display-buttonized
2064   "m" gnus-summary-repair-multipart
2065   "v" gnus-article-view-part
2066   "o" gnus-article-save-part
2067   "c" gnus-article-copy-part
2068   "C" gnus-article-view-part-as-charset
2069   "e" gnus-article-view-part-externally
2070   "E" gnus-article-encrypt-body
2071   "i" gnus-article-inline-part
2072   "|" gnus-article-pipe-part)
2073
2074 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2075   "p" gnus-summary-mark-as-processable
2076   "u" gnus-summary-unmark-as-processable
2077   "U" gnus-summary-unmark-all-processable
2078   "v" gnus-uu-mark-over
2079   "s" gnus-uu-mark-series
2080   "r" gnus-uu-mark-region
2081   "g" gnus-uu-unmark-region
2082   "R" gnus-uu-mark-by-regexp
2083   "G" gnus-uu-unmark-by-regexp
2084   "t" gnus-uu-mark-thread
2085   "T" gnus-uu-unmark-thread
2086   "a" gnus-uu-mark-all
2087   "b" gnus-uu-mark-buffer
2088   "S" gnus-uu-mark-sparse
2089   "k" gnus-summary-kill-process-mark
2090   "y" gnus-summary-yank-process-mark
2091   "w" gnus-summary-save-process-mark
2092   "i" gnus-uu-invert-processable)
2093
2094 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2095   ;;"x" gnus-uu-extract-any
2096   "m" gnus-summary-save-parts
2097   "u" gnus-uu-decode-uu
2098   "U" gnus-uu-decode-uu-and-save
2099   "s" gnus-uu-decode-unshar
2100   "S" gnus-uu-decode-unshar-and-save
2101   "o" gnus-uu-decode-save
2102   "O" gnus-uu-decode-save
2103   "b" gnus-uu-decode-binhex
2104   "B" gnus-uu-decode-binhex
2105   "p" gnus-uu-decode-postscript
2106   "P" gnus-uu-decode-postscript-and-save)
2107
2108 (gnus-define-keys
2109     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2110   "u" gnus-uu-decode-uu-view
2111   "U" gnus-uu-decode-uu-and-save-view
2112   "s" gnus-uu-decode-unshar-view
2113   "S" gnus-uu-decode-unshar-and-save-view
2114   "o" gnus-uu-decode-save-view
2115   "O" gnus-uu-decode-save-view
2116   "b" gnus-uu-decode-binhex-view
2117   "B" gnus-uu-decode-binhex-view
2118   "p" gnus-uu-decode-postscript-view
2119   "P" gnus-uu-decode-postscript-and-save-view)
2120
2121 (defvar gnus-article-post-menu nil)
2122
2123 (defconst gnus-summary-menu-maxlen 20)
2124
2125 (defun gnus-summary-menu-split (menu)
2126   ;; If we have lots of elements, divide them into groups of 20
2127   ;; and make a pane (or submenu) for each one.
2128   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2129       (let ((menu menu) sublists next
2130             (i 1))
2131         (while menu
2132           ;; Pull off the next gnus-summary-menu-maxlen elements
2133           ;; and make them the next element of sublist.
2134           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2135           (if next
2136               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2137                       nil))
2138           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2139                                              (aref (car (last menu)) 0)) menu)
2140                                sublists))
2141           (setq i (1+ i))
2142           (setq menu next))
2143         (nreverse sublists))
2144     ;; Few elements--put them all in one pane.
2145     menu))
2146
2147 (defun gnus-summary-make-menu-bar ()
2148   (gnus-turn-off-edit-menu 'summary)
2149
2150   (unless (boundp 'gnus-summary-misc-menu)
2151
2152     (easy-menu-define
2153       gnus-summary-kill-menu gnus-summary-mode-map ""
2154       (cons
2155        "Score"
2156        (nconc
2157         (list
2158          ["Customize" gnus-score-customize t])
2159         (gnus-make-score-map 'increase)
2160         (gnus-make-score-map 'lower)
2161         '(("Mark"
2162            ["Kill below" gnus-summary-kill-below t]
2163            ["Mark above" gnus-summary-mark-above t]
2164            ["Tick above" gnus-summary-tick-above t]
2165            ["Clear above" gnus-summary-clear-above t])
2166           ["Current score" gnus-summary-current-score t]
2167           ["Set score" gnus-summary-set-score t]
2168           ["Switch current score file..." gnus-score-change-score-file t]
2169           ["Set mark below..." gnus-score-set-mark-below t]
2170           ["Set expunge below..." gnus-score-set-expunge-below t]
2171           ["Edit current score file" gnus-score-edit-current-scores t]
2172           ["Edit score file" gnus-score-edit-file t]
2173           ["Trace score" gnus-score-find-trace t]
2174           ["Find words" gnus-score-find-favourite-words t]
2175           ["Rescore buffer" gnus-summary-rescore t]
2176           ["Increase score..." gnus-summary-increase-score t]
2177           ["Lower score..." gnus-summary-lower-score t]))))
2178
2179     ;; Define both the Article menu in the summary buffer and the
2180     ;; equivalent Commands menu in the article buffer here for
2181     ;; consistency.
2182     (let ((innards
2183            `(("Hide"
2184               ["All" gnus-article-hide t]
2185               ["Headers" gnus-article-hide-headers t]
2186               ["Signature" gnus-article-hide-signature t]
2187               ["Citation" gnus-article-hide-citation t]
2188               ["List identifiers" gnus-article-hide-list-identifiers t]
2189               ["Banner" gnus-article-strip-banner t]
2190               ["Boring headers" gnus-article-hide-boring-headers t])
2191              ("Highlight"
2192               ["All" gnus-article-highlight t]
2193               ["Headers" gnus-article-highlight-headers t]
2194               ["Signature" gnus-article-highlight-signature t]
2195               ["Citation" gnus-article-highlight-citation t])
2196              ("Date"
2197               ["Local" gnus-article-date-local t]
2198               ["ISO8601" gnus-article-date-iso8601 t]
2199               ["UT" gnus-article-date-ut t]
2200               ["Original" gnus-article-date-original t]
2201               ["Lapsed" gnus-article-date-lapsed t]
2202               ["User-defined" gnus-article-date-user t])
2203              ("Display"
2204               ["Remove images" gnus-article-remove-images t]
2205               ["Toggle smiley" gnus-treat-smiley t]
2206               ["Show X-Face" gnus-article-display-x-face t]
2207               ["Show picons in From" gnus-treat-from-picon t]
2208               ["Show picons in mail headers" gnus-treat-mail-picon t]
2209               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2210               ("View as different encoding"
2211                ,@(gnus-summary-menu-split
2212                   (mapcar
2213                    (lambda (cs)
2214                      ;; Since easymenu under Emacs doesn't allow
2215                      ;; lambda forms for menu commands, we should
2216                      ;; provide intern'ed function symbols.
2217                      (let ((command (intern (format "\
2218 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2219                        (fset command
2220                              `(lambda ()
2221                                 (interactive)
2222                                 (let ((gnus-summary-show-article-charset-alist
2223                                        '((1 . ,cs))))
2224                                   (gnus-summary-show-article 1))))
2225                        `[,(symbol-name cs) ,command t]))
2226                    (sort (if (fboundp 'coding-system-list)
2227                              (coding-system-list)
2228                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2229                            )
2230                          'string<)))))
2231              ("Washing"
2232               ("Remove Blanks"
2233                ["Leading" gnus-article-strip-leading-blank-lines t]
2234                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2235                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2236                ["All of the above" gnus-article-strip-blank-lines t]
2237                ["All" gnus-article-strip-all-blank-lines t]
2238                ["Leading space" gnus-article-strip-leading-space t]
2239                ["Trailing space" gnus-article-strip-trailing-space t]
2240                ["Leading space in headers"
2241                 gnus-article-remove-leading-whitespace t])
2242               ["Overstrike" gnus-article-treat-overstrike t]
2243               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2244               ["Emphasis" gnus-article-emphasize t]
2245               ["Word wrap" gnus-article-fill-cited-article t]
2246               ["Fill long lines" gnus-article-fill-long-lines t]
2247               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2248               ["Remove CR" gnus-article-remove-cr t]
2249               ["Rot 13" gnus-summary-caesar-message
2250                ,@(if (featurep 'xemacs) '(t)
2251                    '(:help "\"Caesar rotate\" article by 13"))]
2252               ["Morse decode" gnus-summary-morse-message t]
2253               ["Unix pipe..." gnus-summary-pipe-message t]
2254               ["Add buttons" gnus-article-add-buttons t]
2255               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2256               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2257               ["Toggle MIME" gnus-summary-toggle-mime t]
2258               ["Verbose header" gnus-summary-verbose-headers t]
2259               ["Toggle header" gnus-summary-toggle-header t]
2260               ["Unfold headers" gnus-article-treat-unfold-headers t]
2261               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2262               ["Html" gnus-article-wash-html t]
2263               ["Unsplit URLs" gnus-article-unsplit-urls t]
2264               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2265               ["Decode HZ" gnus-article-decode-HZ t]
2266               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2267               ("(Outlook) Deuglify"
2268                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2269                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2270                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2271                ["Full (Outlook) deuglify"
2272                 gnus-article-outlook-deuglify-article t])
2273               )
2274              ("Output"
2275               ["Save in default format..." gnus-summary-save-article
2276                ,@(if (featurep 'xemacs) '(t)
2277                    '(:help "Save article using default method"))]
2278               ["Save in file..." gnus-summary-save-article-file
2279                ,@(if (featurep 'xemacs) '(t)
2280                    '(:help "Save article in file"))]
2281               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2282               ["Save in MH folder..." gnus-summary-save-article-folder t]
2283               ["Save in VM folder..." gnus-summary-save-article-vm t]
2284               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2285               ["Save body in file..." gnus-summary-save-article-body-file t]
2286               ["Pipe through a filter..." gnus-summary-pipe-output t]
2287               ["Add to SOUP packet" gnus-soup-add-article t]
2288               ["Print with Muttprint..." gnus-summary-muttprint t]
2289               ["Print" gnus-summary-print-article
2290                ,@(if (featurep 'xemacs) '(t)
2291                    '(:help "Generate and print a PostScript image"))])
2292              ("Copy, move,... (Backend)"
2293               ,@(if (featurep 'xemacs) nil
2294                   '(:help "Copying, moving, expiring articles..."))
2295               ["Respool article..." gnus-summary-respool-article t]
2296               ["Move article..." gnus-summary-move-article
2297                (gnus-check-backend-function
2298                 'request-move-article gnus-newsgroup-name)]
2299               ["Copy article..." gnus-summary-copy-article t]
2300               ["Crosspost article..." gnus-summary-crosspost-article
2301                (gnus-check-backend-function
2302                 'request-replace-article gnus-newsgroup-name)]
2303               ["Import file..." gnus-summary-import-article
2304                (gnus-check-backend-function
2305                 'request-accept-article gnus-newsgroup-name)]
2306               ["Create article..." gnus-summary-create-article
2307                (gnus-check-backend-function
2308                 'request-accept-article gnus-newsgroup-name)]
2309               ["Check if posted" gnus-summary-article-posted-p t]
2310               ["Edit article" gnus-summary-edit-article
2311                (not (gnus-group-read-only-p))]
2312               ["Delete article" gnus-summary-delete-article
2313                (gnus-check-backend-function
2314                 'request-expire-articles gnus-newsgroup-name)]
2315               ["Query respool" gnus-summary-respool-query t]
2316               ["Trace respool" gnus-summary-respool-trace t]
2317               ["Delete expirable articles" gnus-summary-expire-articles-now
2318                (gnus-check-backend-function
2319                 'request-expire-articles gnus-newsgroup-name)])
2320              ("Extract"
2321               ["Uudecode" gnus-uu-decode-uu
2322                ,@(if (featurep 'xemacs) '(t)
2323                    '(:help "Decode uuencoded article(s)"))]
2324               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2325               ["Unshar" gnus-uu-decode-unshar t]
2326               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2327               ["Save" gnus-uu-decode-save t]
2328               ["Binhex" gnus-uu-decode-binhex t]
2329               ["Postscript" gnus-uu-decode-postscript t])
2330              ("Cache"
2331               ["Enter article" gnus-cache-enter-article t]
2332               ["Remove article" gnus-cache-remove-article t])
2333              ["Translate" gnus-article-babel t]
2334              ["Select article buffer" gnus-summary-select-article-buffer t]
2335              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2336              ["Isearch article..." gnus-summary-isearch-article t]
2337              ["Beginning of the article" gnus-summary-beginning-of-article t]
2338              ["End of the article" gnus-summary-end-of-article t]
2339              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2340              ["Fetch referenced articles" gnus-summary-refer-references t]
2341              ["Fetch current thread" gnus-summary-refer-thread t]
2342              ["Fetch article with id..." gnus-summary-refer-article t]
2343              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2344              ["Redisplay" gnus-summary-show-article t]
2345              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2346       (easy-menu-define
2347         gnus-summary-article-menu gnus-summary-mode-map ""
2348         (cons "Article" innards))
2349
2350       (if (not (keymapp gnus-summary-article-menu))
2351           (easy-menu-define
2352             gnus-article-commands-menu gnus-article-mode-map ""
2353             (cons "Commands" innards))
2354         ;; in Emacs, don't share menu.
2355         (setq gnus-article-commands-menu
2356               (copy-keymap gnus-summary-article-menu))
2357         (define-key gnus-article-mode-map [menu-bar commands]
2358           (cons "Commands" gnus-article-commands-menu))))
2359
2360     (easy-menu-define
2361       gnus-summary-thread-menu gnus-summary-mode-map ""
2362       '("Threads"
2363         ["Find all messages in thread" gnus-summary-refer-thread t]
2364         ["Toggle threading" gnus-summary-toggle-threads t]
2365         ["Hide threads" gnus-summary-hide-all-threads t]
2366         ["Show threads" gnus-summary-show-all-threads t]
2367         ["Hide thread" gnus-summary-hide-thread t]
2368         ["Show thread" gnus-summary-show-thread t]
2369         ["Go to next thread" gnus-summary-next-thread t]
2370         ["Go to previous thread" gnus-summary-prev-thread t]
2371         ["Go down thread" gnus-summary-down-thread t]
2372         ["Go up thread" gnus-summary-up-thread t]
2373         ["Top of thread" gnus-summary-top-thread t]
2374         ["Mark thread as read" gnus-summary-kill-thread t]
2375         ["Lower thread score" gnus-summary-lower-thread t]
2376         ["Raise thread score" gnus-summary-raise-thread t]
2377         ["Rethread current" gnus-summary-rethread-current t]))
2378
2379     (easy-menu-define
2380       gnus-summary-post-menu gnus-summary-mode-map ""
2381       `("Post"
2382         ["Send a message (mail or news)" gnus-summary-post-news
2383          ,@(if (featurep 'xemacs) '(t)
2384              '(:help "Compose a new message (mail or news)"))]
2385         ["Followup" gnus-summary-followup
2386          ,@(if (featurep 'xemacs) '(t)
2387              '(:help "Post followup to this article"))]
2388         ["Followup and yank" gnus-summary-followup-with-original
2389          ,@(if (featurep 'xemacs) '(t)
2390              '(:help "Post followup to this article, quoting its contents"))]
2391         ["Supersede article" gnus-summary-supersede-article t]
2392         ["Cancel article" gnus-summary-cancel-article
2393          ,@(if (featurep 'xemacs) '(t)
2394              '(:help "Cancel an article you posted"))]
2395         ["Reply" gnus-summary-reply t]
2396         ["Reply and yank" gnus-summary-reply-with-original t]
2397         ["Wide reply" gnus-summary-wide-reply t]
2398         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2399          ,@(if (featurep 'xemacs) '(t)
2400              '(:help "Mail a reply, quoting this article"))]
2401         ["Very wide reply" gnus-summary-very-wide-reply t]
2402         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2403          ,@(if (featurep 'xemacs) '(t)
2404              '(:help "Mail a very wide reply, quoting this article"))]
2405         ["Mail forward" gnus-summary-mail-forward t]
2406         ["Post forward" gnus-summary-post-forward t]
2407         ["Digest and mail" gnus-summary-digest-mail-forward t]
2408         ["Digest and post" gnus-summary-digest-post-forward t]
2409         ["Resend message" gnus-summary-resend-message t]
2410         ["Resend message edit" gnus-summary-resend-message-edit t]
2411         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2412         ["Send a mail" gnus-summary-mail-other-window t]
2413         ["Create a local message" gnus-summary-news-other-window t]
2414         ["Uuencode and post" gnus-uu-post-news
2415          ,@(if (featurep 'xemacs) '(t)
2416              '(:help "Post a uuencoded article"))]
2417         ["Followup via news" gnus-summary-followup-to-mail t]
2418         ["Followup via news and yank"
2419          gnus-summary-followup-to-mail-with-original t]
2420         ;;("Draft"
2421         ;;["Send" gnus-summary-send-draft t]
2422         ;;["Send bounced" gnus-resend-bounced-mail t])
2423         ))
2424
2425     (cond
2426      ((not (keymapp gnus-summary-post-menu))
2427       (setq gnus-article-post-menu gnus-summary-post-menu))
2428      ((not gnus-article-post-menu)
2429       ;; Don't share post menu.
2430       (setq gnus-article-post-menu
2431             (copy-keymap gnus-summary-post-menu))))
2432     (define-key gnus-article-mode-map [menu-bar post]
2433       (cons "Post" gnus-article-post-menu))
2434
2435     (easy-menu-define
2436       gnus-summary-misc-menu gnus-summary-mode-map ""
2437       `("Gnus"
2438         ("Mark Read"
2439          ["Mark as read" gnus-summary-mark-as-read-forward t]
2440          ["Mark same subject and select"
2441           gnus-summary-kill-same-subject-and-select t]
2442          ["Mark same subject" gnus-summary-kill-same-subject t]
2443          ["Catchup" gnus-summary-catchup
2444           ,@(if (featurep 'xemacs) '(t)
2445               '(:help "Mark unread articles in this group as read"))]
2446          ["Catchup all" gnus-summary-catchup-all t]
2447          ["Catchup to here" gnus-summary-catchup-to-here t]
2448          ["Catchup from here" gnus-summary-catchup-from-here t]
2449          ["Catchup region" gnus-summary-mark-region-as-read
2450           (gnus-mark-active-p)]
2451          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2452         ("Mark Various"
2453          ["Tick" gnus-summary-tick-article-forward t]
2454          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2455          ["Remove marks" gnus-summary-clear-mark-forward t]
2456          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2457          ["Set bookmark" gnus-summary-set-bookmark t]
2458          ["Remove bookmark" gnus-summary-remove-bookmark t])
2459         ("Limit to"
2460          ["Marks..." gnus-summary-limit-to-marks t]
2461          ["Subject..." gnus-summary-limit-to-subject t]
2462          ["Author..." gnus-summary-limit-to-author t]
2463          ["Recipient..." gnus-summary-limit-to-recipient t]
2464          ["Age..." gnus-summary-limit-to-age t]
2465          ["Extra..." gnus-summary-limit-to-extra t]
2466          ["Score..." gnus-summary-limit-to-score t]
2467          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2468          ["Unread" gnus-summary-limit-to-unread t]
2469          ["Unseen" gnus-summary-limit-to-unseen t]
2470          ["Replied" gnus-summary-limit-to-replied t]
2471          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2472          ["Next articles" gnus-summary-limit-to-articles t]
2473          ["Pop limit" gnus-summary-pop-limit t]
2474          ["Show dormant" gnus-summary-limit-include-dormant t]
2475          ["Hide childless dormant"
2476           gnus-summary-limit-exclude-childless-dormant t]
2477          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2478          ["Hide marked" gnus-summary-limit-exclude-marks t]
2479          ["Show expunged" gnus-summary-limit-include-expunged t])
2480         ("Process Mark"
2481          ["Set mark" gnus-summary-mark-as-processable t]
2482          ["Remove mark" gnus-summary-unmark-as-processable t]
2483          ["Remove all marks" gnus-summary-unmark-all-processable t]
2484          ["Invert marks" gnus-uu-invert-processable t]
2485          ["Mark above" gnus-uu-mark-over t]
2486          ["Mark series" gnus-uu-mark-series t]
2487          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2488          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2489          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2490          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2491          ["Mark all" gnus-uu-mark-all t]
2492          ["Mark buffer" gnus-uu-mark-buffer t]
2493          ["Mark sparse" gnus-uu-mark-sparse t]
2494          ["Mark thread" gnus-uu-mark-thread t]
2495          ["Unmark thread" gnus-uu-unmark-thread t]
2496          ("Process Mark Sets"
2497           ["Kill" gnus-summary-kill-process-mark t]
2498           ["Yank" gnus-summary-yank-process-mark
2499            gnus-newsgroup-process-stack]
2500           ["Save" gnus-summary-save-process-mark t]
2501           ["Run command on marked..." gnus-summary-universal-argument t]))
2502         ("Scroll article"
2503          ["Page forward" gnus-summary-next-page
2504           ,@(if (featurep 'xemacs) '(t)
2505               '(:help "Show next page of article"))]
2506          ["Page backward" gnus-summary-prev-page
2507           ,@(if (featurep 'xemacs) '(t)
2508               '(:help "Show previous page of article"))]
2509          ["Line forward" gnus-summary-scroll-up t])
2510         ("Move"
2511          ["Next unread article" gnus-summary-next-unread-article t]
2512          ["Previous unread article" gnus-summary-prev-unread-article t]
2513          ["Next article" gnus-summary-next-article t]
2514          ["Previous article" gnus-summary-prev-article t]
2515          ["Next unread subject" gnus-summary-next-unread-subject t]
2516          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2517          ["Next article same subject" gnus-summary-next-same-subject t]
2518          ["Previous article same subject" gnus-summary-prev-same-subject t]
2519          ["First unread article" gnus-summary-first-unread-article t]
2520          ["Best unread article" gnus-summary-best-unread-article t]
2521          ["Go to subject number..." gnus-summary-goto-subject t]
2522          ["Go to article number..." gnus-summary-goto-article t]
2523          ["Go to the last article" gnus-summary-goto-last-article t]
2524          ["Pop article off history" gnus-summary-pop-article t])
2525         ("Sort"
2526          ["Sort by number" gnus-summary-sort-by-number t]
2527          ["Sort by author" gnus-summary-sort-by-author t]
2528          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2529          ["Sort by subject" gnus-summary-sort-by-subject t]
2530          ["Sort by date" gnus-summary-sort-by-date t]
2531          ["Sort by score" gnus-summary-sort-by-score t]
2532          ["Sort by lines" gnus-summary-sort-by-lines t]
2533          ["Sort by characters" gnus-summary-sort-by-chars t]
2534          ["Randomize" gnus-summary-sort-by-random t]
2535          ["Original sort" gnus-summary-sort-by-original t])
2536         ("Help"
2537          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2538          ["Describe group" gnus-summary-describe-group t]
2539          ["Fetch charter" gnus-group-fetch-charter
2540           ,@(if (featurep 'xemacs) nil
2541               '(:help "Display the charter of the current group"))]
2542          ["Fetch control message" gnus-group-fetch-control
2543           ,@(if (featurep 'xemacs) nil
2544               '(:help "Display the archived control message for the current group"))]
2545          ["Read manual" gnus-info-find-node t])
2546         ("Modes"
2547          ["Pick and read" gnus-pick-mode t]
2548          ["Binary" gnus-binary-mode t])
2549         ("Regeneration"
2550          ["Regenerate" gnus-summary-prepare t]
2551          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2552          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2553          ["Toggle threading" gnus-summary-toggle-threads t])
2554         ["See old articles" gnus-summary-insert-old-articles t]
2555         ["See new articles" gnus-summary-insert-new-articles t]
2556         ["Filter articles..." gnus-summary-execute-command t]
2557         ["Run command on articles..." gnus-summary-universal-argument t]
2558         ["Search articles forward..." gnus-summary-search-article-forward t]
2559         ["Search articles backward..." gnus-summary-search-article-backward t]
2560         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2561         ["Expand window" gnus-summary-expand-window t]
2562         ["Expire expirable articles" gnus-summary-expire-articles
2563          (gnus-check-backend-function
2564           'request-expire-articles gnus-newsgroup-name)]
2565         ["Edit local kill file" gnus-summary-edit-local-kill t]
2566         ["Edit main kill file" gnus-summary-edit-global-kill t]
2567         ["Edit group parameters" gnus-summary-edit-parameters t]
2568         ["Customize group parameters" gnus-summary-customize-parameters t]
2569         ["Send a bug report" gnus-bug t]
2570         ("Exit"
2571          ["Catchup and exit" gnus-summary-catchup-and-exit
2572           ,@(if (featurep 'xemacs) '(t)
2573               '(:help "Mark unread articles in this group as read, then exit"))]
2574          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2575          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2576          ["Exit group" gnus-summary-exit
2577           ,@(if (featurep 'xemacs) '(t)
2578               '(:help "Exit current group, return to group selection mode"))]
2579          ["Exit group without updating" gnus-summary-exit-no-update t]
2580          ["Exit and goto next group" gnus-summary-next-group t]
2581          ["Exit and goto prev group" gnus-summary-prev-group t]
2582          ["Reselect group" gnus-summary-reselect-current-group t]
2583          ["Rescan group" gnus-summary-rescan-group t]
2584          ["Update dribble" gnus-summary-save-newsrc t])))
2585
2586     (gnus-run-hooks 'gnus-summary-menu-hook)))
2587
2588 (defvar gnus-summary-tool-bar-map nil)
2589
2590 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2591 (defun gnus-summary-make-tool-bar ()
2592   (if (and (fboundp 'tool-bar-add-item-from-menu)
2593            (default-value 'tool-bar-mode)
2594            (not gnus-summary-tool-bar-map))
2595       (setq gnus-summary-tool-bar-map
2596             (let ((tool-bar-map (make-sparse-keymap))
2597                   (load-path (mm-image-load-path)))
2598               (tool-bar-add-item-from-menu
2599                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2600               (tool-bar-add-item-from-menu
2601                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2602               (tool-bar-add-item-from-menu
2603                'gnus-summary-post-news "post" gnus-summary-mode-map)
2604               (tool-bar-add-item-from-menu
2605                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2606               (tool-bar-add-item-from-menu
2607                'gnus-summary-followup "followup" gnus-summary-mode-map)
2608               (tool-bar-add-item-from-menu
2609                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2610               (tool-bar-add-item-from-menu
2611                'gnus-summary-reply "reply" gnus-summary-mode-map)
2612               (tool-bar-add-item-from-menu
2613                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2614               (tool-bar-add-item-from-menu
2615                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2616               (tool-bar-add-item-from-menu
2617                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2618               (tool-bar-add-item-from-menu
2619                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2620               (tool-bar-add-item-from-menu
2621                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2622               (tool-bar-add-item-from-menu
2623                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2624               (tool-bar-add-item-from-menu
2625                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2626               (tool-bar-add-item-from-menu
2627                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2628               (tool-bar-add-item-from-menu
2629                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2630               tool-bar-map)))
2631   (if gnus-summary-tool-bar-map
2632       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2633
2634 (defun gnus-score-set-default (var value)
2635   "A version of set that updates the GNU Emacs menu-bar."
2636   (set var value)
2637   ;; It is the message that forces the active status to be updated.
2638   (message ""))
2639
2640 (defun gnus-make-score-map (type)
2641   "Make a summary score map of type TYPE."
2642   (if t
2643       nil
2644     (let ((headers '(("author" "from" string)
2645                      ("subject" "subject" string)
2646                      ("article body" "body" string)
2647                      ("article head" "head" string)
2648                      ("xref" "xref" string)
2649                      ("extra header" "extra" string)
2650                      ("lines" "lines" number)
2651                      ("followups to author" "followup" string)))
2652           (types '((number ("less than" <)
2653                            ("greater than" >)
2654                            ("equal" =))
2655                    (string ("substring" s)
2656                            ("exact string" e)
2657                            ("fuzzy string" f)
2658                            ("regexp" r))))
2659           (perms '(("temporary" (current-time-string))
2660                    ("permanent" nil)
2661                    ("immediate" now)))
2662           header)
2663       (list
2664        (apply
2665         'nconc
2666         (list
2667          (if (eq type 'lower)
2668              "Lower score"
2669            "Increase score"))
2670         (let (outh)
2671           (while headers
2672             (setq header (car headers))
2673             (setq outh
2674                   (cons
2675                    (apply
2676                     'nconc
2677                     (list (car header))
2678                     (let ((ts (cdr (assoc (nth 2 header) types)))
2679                           outt)
2680                       (while ts
2681                         (setq outt
2682                               (cons
2683                                (apply
2684                                 'nconc
2685                                 (list (caar ts))
2686                                 (let ((ps perms)
2687                                       outp)
2688                                   (while ps
2689                                     (setq outp
2690                                           (cons
2691                                            (vector
2692                                             (caar ps)
2693                                             (list
2694                                              'gnus-summary-score-entry
2695                                              (nth 1 header)
2696                                              (if (or (string= (nth 1 header)
2697                                                               "head")
2698                                                      (string= (nth 1 header)
2699                                                               "body"))
2700                                                  ""
2701                                                (list 'gnus-summary-header
2702                                                      (nth 1 header)))
2703                                              (list 'quote (nth 1 (car ts)))
2704                                              (list 'gnus-score-delta-default
2705                                                    nil)
2706                                              (nth 1 (car ps))
2707                                              t)
2708                                             t)
2709                                            outp))
2710                                     (setq ps (cdr ps)))
2711                                   (list (nreverse outp))))
2712                                outt))
2713                         (setq ts (cdr ts)))
2714                       (list (nreverse outt))))
2715                    outh))
2716             (setq headers (cdr headers)))
2717           (list (nreverse outh))))))))
2718
2719 \f
2720
2721 (defun gnus-summary-mode (&optional group)
2722   "Major mode for reading articles.
2723
2724 All normal editing commands are switched off.
2725 \\<gnus-summary-mode-map>
2726 Each line in this buffer represents one article.  To read an
2727 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2728 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2729 respectively.
2730
2731 You can also post articles and send mail from this buffer.  To
2732 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2733 of an article, type `\\[gnus-summary-reply]'.
2734
2735 There are approx. one gazillion commands you can execute in this
2736 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2737
2738 The following commands are available:
2739
2740 \\{gnus-summary-mode-map}"
2741   (interactive)
2742   (kill-all-local-variables)
2743   (when (gnus-visual-p 'summary-menu 'menu)
2744     (gnus-summary-make-menu-bar)
2745     (gnus-summary-make-tool-bar))
2746   (gnus-summary-make-local-variables)
2747   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2748     (gnus-summary-make-local-variables))
2749   (gnus-make-thread-indent-array)
2750   (gnus-simplify-mode-line)
2751   (setq major-mode 'gnus-summary-mode)
2752   (setq mode-name "Summary")
2753   (make-local-variable 'minor-mode-alist)
2754   (use-local-map gnus-summary-mode-map)
2755   (buffer-disable-undo)
2756   (setq buffer-read-only t              ;Disable modification
2757         show-trailing-whitespace nil)
2758   (setq truncate-lines t)
2759   (setq selective-display t)
2760   (setq selective-display-ellipses t)   ;Display `...'
2761   (gnus-summary-set-display-table)
2762   (gnus-set-default-directory)
2763   (setq gnus-newsgroup-name group)
2764   (unless (gnus-news-group-p group)
2765     (setq gnus-newsgroup-incorporated
2766           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2767   (make-local-variable 'gnus-summary-line-format)
2768   (make-local-variable 'gnus-summary-line-format-spec)
2769   (make-local-variable 'gnus-summary-dummy-line-format)
2770   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2771   (make-local-variable 'gnus-summary-mark-positions)
2772   (gnus-make-local-hook 'pre-command-hook)
2773   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2774   (gnus-run-hooks 'gnus-summary-mode-hook)
2775   (turn-on-gnus-mailing-list-mode)
2776   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2777   (gnus-update-summary-mark-positions))
2778
2779 (defun gnus-summary-make-local-variables ()
2780   "Make all the local summary buffer variables."
2781   (let (global)
2782     (dolist (local gnus-summary-local-variables)
2783       (if (consp local)
2784           (progn
2785             (if (eq (cdr local) 'global)
2786                 ;; Copy the global value of the variable.
2787                 (setq global (symbol-value (car local)))
2788               ;; Use the value from the list.
2789               (setq global (eval (cdr local))))
2790             (set (make-local-variable (car local)) global))
2791         ;; Simple nil-valued local variable.
2792         (set (make-local-variable local) nil)))))
2793
2794 (defun gnus-summary-clear-local-variables ()
2795   (let ((locals gnus-summary-local-variables))
2796     (while locals
2797       (if (consp (car locals))
2798           (and (symbolp (caar locals))
2799                (set (caar locals) nil))
2800         (and (symbolp (car locals))
2801              (set (car locals) nil)))
2802       (setq locals (cdr locals)))))
2803
2804 ;; Summary data functions.
2805
2806 (defmacro gnus-data-number (data)
2807   `(car ,data))
2808
2809 (defmacro gnus-data-set-number (data number)
2810   `(setcar ,data ,number))
2811
2812 (defmacro gnus-data-mark (data)
2813   `(nth 1 ,data))
2814
2815 (defmacro gnus-data-set-mark (data mark)
2816   `(setcar (nthcdr 1 ,data) ,mark))
2817
2818 (defmacro gnus-data-pos (data)
2819   `(nth 2 ,data))
2820
2821 (defmacro gnus-data-set-pos (data pos)
2822   `(setcar (nthcdr 2 ,data) ,pos))
2823
2824 (defmacro gnus-data-header (data)
2825   `(nth 3 ,data))
2826
2827 (defmacro gnus-data-set-header (data header)
2828   `(setcar (nthcdr 3 ,data) ,header))
2829
2830 (defmacro gnus-data-level (data)
2831   `(nth 4 ,data))
2832
2833 (defmacro gnus-data-unread-p (data)
2834   `(= (nth 1 ,data) gnus-unread-mark))
2835
2836 (defmacro gnus-data-read-p (data)
2837   `(/= (nth 1 ,data) gnus-unread-mark))
2838
2839 (defmacro gnus-data-pseudo-p (data)
2840   `(consp (nth 3 ,data)))
2841
2842 (defmacro gnus-data-find (number)
2843   `(assq ,number gnus-newsgroup-data))
2844
2845 (defmacro gnus-data-find-list (number &optional data)
2846   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2847      (memq (assq ,number bdata)
2848            bdata)))
2849
2850 (defmacro gnus-data-make (number mark pos header level)
2851   `(list ,number ,mark ,pos ,header ,level))
2852
2853 (defun gnus-data-enter (after-article number mark pos header level offset)
2854   (let ((data (gnus-data-find-list after-article)))
2855     (unless data
2856       (error "No such article: %d" after-article))
2857     (setcdr data (cons (gnus-data-make number mark pos header level)
2858                        (cdr data)))
2859     (setq gnus-newsgroup-data-reverse nil)
2860     (gnus-data-update-list (cddr data) offset)))
2861
2862 (defun gnus-data-enter-list (after-article list &optional offset)
2863   (when list
2864     (let ((data (and after-article (gnus-data-find-list after-article)))
2865           (ilist list))
2866       (if (not (or data
2867                    after-article))
2868           (let ((odata gnus-newsgroup-data))
2869             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2870             (when offset
2871               (gnus-data-update-list odata offset)))
2872         ;; Find the last element in the list to be spliced into the main
2873         ;; list.
2874         (setq list (last list))
2875         (if (not data)
2876             (progn
2877               (setcdr list gnus-newsgroup-data)
2878               (setq gnus-newsgroup-data ilist)
2879               (when offset
2880                 (gnus-data-update-list (cdr list) offset)))
2881           (setcdr list (cdr data))
2882           (setcdr data ilist)
2883           (when offset
2884             (gnus-data-update-list (cdr list) offset))))
2885       (setq gnus-newsgroup-data-reverse nil))))
2886
2887 (defun gnus-data-remove (article &optional offset)
2888   (let ((data gnus-newsgroup-data))
2889     (if (= (gnus-data-number (car data)) article)
2890         (progn
2891           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2892                 gnus-newsgroup-data-reverse nil)
2893           (when offset
2894             (gnus-data-update-list gnus-newsgroup-data offset)))
2895       (while (cdr data)
2896         (when (= (gnus-data-number (cadr data)) article)
2897           (setcdr data (cddr data))
2898           (when offset
2899             (gnus-data-update-list (cdr data) offset))
2900           (setq data nil
2901                 gnus-newsgroup-data-reverse nil))
2902         (setq data (cdr data))))))
2903
2904 (defmacro gnus-data-list (backward)
2905   `(if ,backward
2906        (or gnus-newsgroup-data-reverse
2907            (setq gnus-newsgroup-data-reverse
2908                  (reverse gnus-newsgroup-data)))
2909      gnus-newsgroup-data))
2910
2911 (defun gnus-data-update-list (data offset)
2912   "Add OFFSET to the POS of all data entries in DATA."
2913   (setq gnus-newsgroup-data-reverse nil)
2914   (while data
2915     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2916     (setq data (cdr data))))
2917
2918 (defun gnus-summary-article-pseudo-p (article)
2919   "Say whether this article is a pseudo article or not."
2920   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2921
2922 (defmacro gnus-summary-article-sparse-p (article)
2923   "Say whether this article is a sparse article or not."
2924   `(memq ,article gnus-newsgroup-sparse))
2925
2926 (defmacro gnus-summary-article-ancient-p (article)
2927   "Say whether this article is a sparse article or not."
2928   `(memq ,article gnus-newsgroup-ancient))
2929
2930 (defun gnus-article-parent-p (number)
2931   "Say whether this article is a parent or not."
2932   (let ((data (gnus-data-find-list number)))
2933     (and (cdr data)                     ; There has to be an article after...
2934          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2935             (gnus-data-level (nth 1 data))))))
2936
2937 (defun gnus-article-children (number)
2938   "Return a list of all children to NUMBER."
2939   (let* ((data (gnus-data-find-list number))
2940          (level (gnus-data-level (car data)))
2941          children)
2942     (setq data (cdr data))
2943     (while (and data
2944                 (= (gnus-data-level (car data)) (1+ level)))
2945       (push (gnus-data-number (car data)) children)
2946       (setq data (cdr data)))
2947     children))
2948
2949 (defmacro gnus-summary-skip-intangible ()
2950   "If the current article is intangible, then jump to a different article."
2951   '(let ((to (get-text-property (point) 'gnus-intangible)))
2952      (and to (gnus-summary-goto-subject to))))
2953
2954 (defmacro gnus-summary-article-intangible-p ()
2955   "Say whether this article is intangible or not."
2956   '(get-text-property (point) 'gnus-intangible))
2957
2958 (defun gnus-article-read-p (article)
2959   "Say whether ARTICLE is read or not."
2960   (not (or (memq article gnus-newsgroup-marked)
2961            (memq article gnus-newsgroup-spam-marked)
2962            (memq article gnus-newsgroup-unreads)
2963            (memq article gnus-newsgroup-unselected)
2964            (memq article gnus-newsgroup-dormant))))
2965
2966 ;; Some summary mode macros.
2967
2968 (defmacro gnus-summary-article-number ()
2969   "The article number of the article on the current line.
2970 If there isn't an article number here, then we return the current
2971 article number."
2972   '(progn
2973      (gnus-summary-skip-intangible)
2974      (or (get-text-property (point) 'gnus-number)
2975          (gnus-summary-last-subject))))
2976
2977 (defmacro gnus-summary-article-header (&optional number)
2978   "Return the header of article NUMBER."
2979   `(gnus-data-header (gnus-data-find
2980                       ,(or number '(gnus-summary-article-number)))))
2981
2982 (defmacro gnus-summary-thread-level (&optional number)
2983   "Return the level of thread that starts with article NUMBER."
2984   `(if (and (eq gnus-summary-make-false-root 'dummy)
2985             (get-text-property (point) 'gnus-intangible))
2986        0
2987      (gnus-data-level (gnus-data-find
2988                        ,(or number '(gnus-summary-article-number))))))
2989
2990 (defmacro gnus-summary-article-mark (&optional number)
2991   "Return the mark of article NUMBER."
2992   `(gnus-data-mark (gnus-data-find
2993                     ,(or number '(gnus-summary-article-number)))))
2994
2995 (defmacro gnus-summary-article-pos (&optional number)
2996   "Return the position of the line of article NUMBER."
2997   `(gnus-data-pos (gnus-data-find
2998                    ,(or number '(gnus-summary-article-number)))))
2999
3000 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3001 (defmacro gnus-summary-article-subject (&optional number)
3002   "Return current subject string or nil if nothing."
3003   `(let ((headers
3004           ,(if number
3005                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3006              '(gnus-data-header (assq (gnus-summary-article-number)
3007                                       gnus-newsgroup-data)))))
3008      (and headers
3009           (vectorp headers)
3010           (mail-header-subject headers))))
3011
3012 (defmacro gnus-summary-article-score (&optional number)
3013   "Return current article score."
3014   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3015                   gnus-newsgroup-scored))
3016        gnus-summary-default-score 0))
3017
3018 (defun gnus-summary-article-children (&optional number)
3019   "Return a list of article numbers that are children of article NUMBER."
3020   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3021          (level (gnus-data-level (car data)))
3022          l children)
3023     (while (and (setq data (cdr data))
3024                 (> (setq l (gnus-data-level (car data))) level))
3025       (and (= (1+ level) l)
3026            (push (gnus-data-number (car data))
3027                  children)))
3028     (nreverse children)))
3029
3030 (defun gnus-summary-article-parent (&optional number)
3031   "Return the article number of the parent of article NUMBER."
3032   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3033                                     (gnus-data-list t)))
3034          (level (gnus-data-level (car data))))
3035     (if (zerop level)
3036         ()                              ; This is a root.
3037       ;; We search until we find an article with a level less than
3038       ;; this one.  That function has to be the parent.
3039       (while (and (setq data (cdr data))
3040                   (not (< (gnus-data-level (car data)) level))))
3041       (and data (gnus-data-number (car data))))))
3042
3043 (defun gnus-unread-mark-p (mark)
3044   "Say whether MARK is the unread mark."
3045   (= mark gnus-unread-mark))
3046
3047 (defun gnus-read-mark-p (mark)
3048   "Say whether MARK is one of the marks that mark as read.
3049 This is all marks except unread, ticked, dormant, and expirable."
3050   (not (or (= mark gnus-unread-mark)
3051            (= mark gnus-ticked-mark)
3052            (= mark gnus-spam-mark)
3053            (= mark gnus-dormant-mark)
3054            (= mark gnus-expirable-mark))))
3055
3056 (defmacro gnus-article-mark (number)
3057   "Return the MARK of article NUMBER.
3058 This macro should only be used when computing the mark the \"first\"
3059 time; i.e., when generating the summary lines.  After that,
3060 `gnus-summary-article-mark' should be used to examine the
3061 marks of articles."
3062   `(cond
3063     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3064     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3065     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3066     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3067     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3068     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3069     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3070     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3071            gnus-ancient-mark))))
3072
3073 ;; Saving hidden threads.
3074
3075 (defmacro gnus-save-hidden-threads (&rest forms)
3076   "Save hidden threads, eval FORMS, and restore the hidden threads."
3077   (let ((config (make-symbol "config")))
3078     `(let ((,config (gnus-hidden-threads-configuration)))
3079        (unwind-protect
3080            (save-excursion
3081              ,@forms)
3082          (gnus-restore-hidden-threads-configuration ,config)))))
3083 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3084 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3085
3086 (defun gnus-data-compute-positions ()
3087   "Compute the positions of all articles."
3088   (setq gnus-newsgroup-data-reverse nil)
3089   (let ((data gnus-newsgroup-data))
3090     (save-excursion
3091       (gnus-save-hidden-threads
3092         (gnus-summary-show-all-threads)
3093         (goto-char (point-min))
3094         (while data
3095           (while (get-text-property (point) 'gnus-intangible)
3096             (forward-line 1))
3097           (gnus-data-set-pos (car data) (+ (point) 3))
3098           (setq data (cdr data))
3099           (forward-line 1))))))
3100
3101 (defun gnus-hidden-threads-configuration ()
3102   "Return the current hidden threads configuration."
3103   (save-excursion
3104     (let (config)
3105       (goto-char (point-min))
3106       (while (search-forward "\r" nil t)
3107         (push (1- (point)) config))
3108       config)))
3109
3110 (defun gnus-restore-hidden-threads-configuration (config)
3111   "Restore hidden threads configuration from CONFIG."
3112   (save-excursion
3113     (let (point buffer-read-only)
3114       (while (setq point (pop config))
3115         (when (and (< point (point-max))
3116                    (goto-char point)
3117                    (eq (char-after) ?\n))
3118           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3119
3120 ;; Various summary mode internalish functions.
3121
3122 (defun gnus-mouse-pick-article (e)
3123   (interactive "e")
3124   (mouse-set-point e)
3125   (gnus-summary-next-page nil t))
3126
3127 (defun gnus-summary-set-display-table ()
3128   "Change the display table.
3129 Odd characters have a tendency to mess
3130 up nicely formatted displays - we make all possible glyphs
3131 display only a single character."
3132
3133   ;; We start from the standard display table, if any.
3134   (let ((table (or (copy-sequence standard-display-table)
3135                    (make-display-table)))
3136         (i 32))
3137     ;; Nix out all the control chars...
3138     (while (>= (setq i (1- i)) 0)
3139       (aset table i [??]))
3140     ;; ... but not newline and cr, of course.  (cr is necessary for the
3141     ;; selective display).
3142     (aset table ?\n nil)
3143     (aset table ?\r nil)
3144     ;; We keep TAB as well.
3145     (aset table ?\t nil)
3146     ;; We nix out any glyphs over 126 that are not set already.
3147     (let ((i 256))
3148       (while (>= (setq i (1- i)) 127)
3149         ;; Only modify if the entry is nil.
3150         (unless (aref table i)
3151           (aset table i [??]))))
3152     (setq buffer-display-table table)))
3153
3154 (defun gnus-summary-set-article-display-arrow (pos)
3155   "Update the overlay arrow to point to line at position POS."
3156   (when (and gnus-summary-display-arrow
3157              (boundp 'overlay-arrow-position)
3158              (boundp 'overlay-arrow-string))
3159     (save-excursion
3160       (goto-char pos)
3161       (beginning-of-line)
3162       (unless overlay-arrow-position
3163         (setq overlay-arrow-position (make-marker)))
3164       (setq overlay-arrow-string "=>"
3165             overlay-arrow-position (set-marker overlay-arrow-position
3166                                                (point)
3167                                                (current-buffer))))))
3168
3169 (defun gnus-summary-setup-buffer (group)
3170   "Initialize summary buffer."
3171   (let ((buffer (gnus-summary-buffer-name group))
3172         (dead-name (concat "*Dead Summary "
3173                            (gnus-group-decoded-name group) "*")))
3174     ;; If a dead summary buffer exists, we kill it.
3175     (when (gnus-buffer-live-p dead-name)
3176       (gnus-kill-buffer dead-name))
3177     (if (get-buffer buffer)
3178         (progn
3179           (set-buffer buffer)
3180           (setq gnus-summary-buffer (current-buffer))
3181           (not gnus-newsgroup-prepared))
3182       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3183       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3184       (gnus-summary-mode group)
3185       (when gnus-carpal
3186         (gnus-carpal-setup-buffer 'summary))
3187       (unless gnus-single-article-buffer
3188         (make-local-variable 'gnus-article-buffer)
3189         (make-local-variable 'gnus-article-current)
3190         (make-local-variable 'gnus-original-article-buffer))
3191       (setq gnus-newsgroup-name group)
3192       ;; Set any local variables in the group parameters.
3193       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3194       t)))
3195
3196 (defun gnus-set-global-variables ()
3197   "Set the global equivalents of the buffer-local variables.
3198 They are set to the latest values they had.  These reflect the summary
3199 buffer that was in action when the last article was fetched."
3200   (when (eq major-mode 'gnus-summary-mode)
3201     (setq gnus-summary-buffer (current-buffer))
3202     (let ((name gnus-newsgroup-name)
3203           (marked gnus-newsgroup-marked)
3204           (spam gnus-newsgroup-spam-marked)
3205           (unread gnus-newsgroup-unreads)
3206           (headers gnus-current-headers)
3207           (data gnus-newsgroup-data)
3208           (summary gnus-summary-buffer)
3209           (article-buffer gnus-article-buffer)
3210           (original gnus-original-article-buffer)
3211           (gac gnus-article-current)
3212           (reffed gnus-reffed-article-number)
3213           (score-file gnus-current-score-file)
3214           (default-charset gnus-newsgroup-charset)
3215           vlist)
3216       (let ((locals gnus-newsgroup-variables))
3217         (while locals
3218           (if (consp (car locals))
3219               (push (eval (caar locals)) vlist)
3220             (push (eval (car locals)) vlist))
3221           (setq locals (cdr locals)))
3222         (setq vlist (nreverse vlist)))
3223       (with-current-buffer gnus-group-buffer
3224         (setq gnus-newsgroup-name name
3225               gnus-newsgroup-marked marked
3226               gnus-newsgroup-spam-marked spam
3227               gnus-newsgroup-unreads unread
3228               gnus-current-headers headers
3229               gnus-newsgroup-data data
3230               gnus-article-current gac
3231               gnus-summary-buffer summary
3232               gnus-article-buffer article-buffer
3233               gnus-original-article-buffer original
3234               gnus-reffed-article-number reffed
3235               gnus-current-score-file score-file
3236               gnus-newsgroup-charset default-charset)
3237         (let ((locals gnus-newsgroup-variables))
3238           (while locals
3239             (if (consp (car locals))
3240                 (set (caar locals) (pop vlist))
3241               (set (car locals) (pop vlist)))
3242             (setq locals (cdr locals))))
3243         ;; The article buffer also has local variables.
3244         (when (gnus-buffer-live-p gnus-article-buffer)
3245           (set-buffer gnus-article-buffer)
3246           (setq gnus-summary-buffer summary))))))
3247
3248 (defun gnus-summary-article-unread-p (article)
3249   "Say whether ARTICLE is unread or not."
3250   (memq article gnus-newsgroup-unreads))
3251
3252 (defun gnus-summary-first-article-p (&optional article)
3253   "Return whether ARTICLE is the first article in the buffer."
3254   (if (not (setq article (or article (gnus-summary-article-number))))
3255       nil
3256     (eq article (caar gnus-newsgroup-data))))
3257
3258 (defun gnus-summary-last-article-p (&optional article)
3259   "Return whether ARTICLE is the last article in the buffer."
3260   (if (not (setq article (or article (gnus-summary-article-number))))
3261       ;; All non-existent numbers are the last article.  :-)
3262       t
3263     (not (cdr (gnus-data-find-list article)))))
3264
3265 (defun gnus-make-thread-indent-array ()
3266   (let ((n 200))
3267     (unless (and gnus-thread-indent-array
3268                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3269       (setq gnus-thread-indent-array (make-vector 201 "")
3270             gnus-thread-indent-array-level gnus-thread-indent-level)
3271       (while (>= n 0)
3272         (aset gnus-thread-indent-array n
3273               (make-string (* n gnus-thread-indent-level) ? ))
3274         (setq n (1- n))))))
3275
3276 (defun gnus-update-summary-mark-positions ()
3277   "Compute where the summary marks are to go."
3278   (save-excursion
3279     (when (gnus-buffer-exists-p gnus-summary-buffer)
3280       (set-buffer gnus-summary-buffer))
3281     (let ((spec gnus-summary-line-format-spec)
3282           pos)
3283       (save-excursion
3284         (gnus-set-work-buffer)
3285         (let ((gnus-tmp-unread ?Z)
3286               (gnus-replied-mark ?Z)
3287               (gnus-score-below-mark ?Z)
3288               (gnus-score-over-mark ?Z)
3289               (gnus-undownloaded-mark ?Z)
3290               (gnus-summary-line-format-spec spec)
3291               (gnus-newsgroup-downloadable '(0))
3292               (header
3293                (make-full-mail-header
3294                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3295               case-fold-search ignores)
3296           ;; Here, all marks are bound to Z.
3297           (gnus-summary-insert-line header
3298                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3299           (goto-char (point-min))
3300           ;; Memorize the positions of the same characters as dummy marks.
3301           (while (re-search-forward "[A-D]" nil t)
3302             (push (point) ignores))
3303           (erase-buffer)
3304           ;; We use A-D as dummy marks in order to know column positions
3305           ;; where marks should be inserted.
3306           (setq gnus-tmp-unread ?A
3307                 gnus-replied-mark ?B
3308                 gnus-score-below-mark ?C
3309                 gnus-score-over-mark ?C
3310                 gnus-undownloaded-mark ?D)
3311           (gnus-summary-insert-line header
3312                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3313           ;; Ignore characters which aren't dummy marks.
3314           (dolist (p ignores)
3315             (delete-region (goto-char (1- p)) p)
3316             (insert ?Z))
3317           (goto-char (point-min))
3318           (setq pos (list (cons 'unread
3319                                 (and (search-forward "A" nil t)
3320                                      (- (point) (point-min) 1)))))
3321           (goto-char (point-min))
3322           (push (cons 'replied (and (search-forward "B" nil t)
3323                                     (- (point) (point-min) 1)))
3324                 pos)
3325           (goto-char (point-min))
3326           (push (cons 'score (and (search-forward "C" nil t)
3327                                   (- (point) (point-min) 1)))
3328                 pos)
3329           (goto-char (point-min))
3330           (push (cons 'download (and (search-forward "D" nil t)
3331                                      (- (point) (point-min) 1)))
3332                 pos)))
3333       (setq gnus-summary-mark-positions pos))))
3334
3335 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3336   "Insert a dummy root in the summary buffer."
3337   (beginning-of-line)
3338   (gnus-add-text-properties
3339    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3340    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3341
3342 (defun gnus-summary-extract-address-component (from)
3343   (or (car (funcall gnus-extract-address-components from))
3344       from))
3345
3346 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3347   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3348                                 default-mime-charset)))
3349     ;; Is it really necessary to do this next part for each summary line?
3350     ;; Luckily, doesn't seem to slow things down much.
3351     (or
3352      (and gnus-ignored-from-addresses
3353           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3354           (let ((extra-headers (mail-header-extra header))
3355                 to
3356                 newsgroups)
3357             (cond
3358              ((setq to (cdr (assq 'To extra-headers)))
3359               (concat "-> "
3360                       (inline
3361                         (gnus-summary-extract-address-component
3362                          (funcall gnus-decode-encoded-word-function to)))))
3363              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3364               (concat "=> " newsgroups)))))
3365      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3366
3367 (defun gnus-summary-insert-line (gnus-tmp-header
3368                                  gnus-tmp-level gnus-tmp-current
3369                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3370                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3371                                  &optional gnus-tmp-dummy gnus-tmp-score
3372                                  gnus-tmp-process)
3373   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3374          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3375          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3376          (gnus-tmp-score-char
3377           (if (or (null gnus-summary-default-score)
3378                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3379                       gnus-summary-zcore-fuzz))
3380               ?\ ;;;Whitespace
3381             (if (< gnus-tmp-score gnus-summary-default-score)
3382                 gnus-score-below-mark gnus-score-over-mark)))
3383          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3384          (gnus-tmp-replied
3385           (cond (gnus-tmp-process gnus-process-mark)
3386                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3387                  gnus-cached-mark)
3388                 (gnus-tmp-replied gnus-replied-mark)
3389                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3390                  gnus-forwarded-mark)
3391                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3392                  gnus-saved-mark)
3393                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3394                  gnus-recent-mark)
3395                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3396                  gnus-unseen-mark)
3397                 (t gnus-no-mark)))
3398          (gnus-tmp-downloaded
3399           (cond (undownloaded
3400                  gnus-undownloaded-mark)
3401                 (gnus-newsgroup-agentized
3402                  gnus-downloaded-mark)
3403                 (t
3404                  gnus-no-mark)))
3405          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3406          (gnus-tmp-name
3407           (cond
3408            ((string-match "<[^>]+> *$" gnus-tmp-from)
3409             (let ((beg (match-beginning 0)))
3410               (or (and (string-match "^\".+\"" gnus-tmp-from)
3411                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3412                   (substring gnus-tmp-from 0 beg))))
3413            ((string-match "(.+)" gnus-tmp-from)
3414             (substring gnus-tmp-from
3415                        (1+ (match-beginning 0)) (1- (match-end 0))))
3416            (t gnus-tmp-from)))
3417          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3418          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3419          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3420          (buffer-read-only nil))
3421     (when (string= gnus-tmp-name "")
3422       (setq gnus-tmp-name gnus-tmp-from))
3423     (unless (numberp gnus-tmp-lines)
3424       (setq gnus-tmp-lines -1))
3425     (if (= gnus-tmp-lines -1)
3426         (setq gnus-tmp-lines "?")
3427       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3428     (gnus-put-text-property-excluding-characters-with-faces
3429      (point)
3430      (progn (eval gnus-summary-line-format-spec) (point))
3431      'gnus-number gnus-tmp-number)
3432     (when (gnus-visual-p 'summary-highlight 'highlight)
3433       (forward-line -1)
3434       (gnus-run-hooks 'gnus-summary-update-hook)
3435       (forward-line 1))))
3436
3437 (defun gnus-summary-update-line (&optional dont-update)
3438   "Update summary line after change."
3439   (when (and gnus-summary-default-score
3440              (not gnus-summary-inhibit-highlight))
3441     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3442            (article (gnus-summary-article-number))
3443            (score (gnus-summary-article-score article)))
3444       (unless dont-update
3445         (if (and gnus-summary-mark-below
3446                  (< (gnus-summary-article-score)
3447                     gnus-summary-mark-below))
3448             ;; This article has a low score, so we mark it as read.
3449             (when (memq article gnus-newsgroup-unreads)
3450               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3451           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3452             ;; This article was previously marked as read on account
3453             ;; of a low score, but now it has risen, so we mark it as
3454             ;; unread.
3455             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3456         (gnus-summary-update-mark
3457          (if (or (null gnus-summary-default-score)
3458                  (<= (abs (- score gnus-summary-default-score))
3459                      gnus-summary-zcore-fuzz))
3460              ?\ ;;;Whitespace
3461            (if (< score gnus-summary-default-score)
3462                gnus-score-below-mark gnus-score-over-mark))
3463          'score))
3464       ;; Do visual highlighting.
3465       (when (gnus-visual-p 'summary-highlight 'highlight)
3466         (gnus-run-hooks 'gnus-summary-update-hook)))))
3467
3468 (defvar gnus-tmp-new-adopts nil)
3469
3470 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3471   "Return the number of articles in THREAD.
3472 This may be 0 in some cases -- if none of the articles in
3473 the thread are to be displayed."
3474   (let* ((number
3475           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3476           (cond
3477            ((not (listp thread))
3478             1)
3479            ((and (consp thread) (cdr thread))
3480             (apply
3481              '+ 1 (mapcar
3482                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3483            ((null thread)
3484             1)
3485            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3486             1)
3487            (t 0))))
3488     (when (and level (zerop level) gnus-tmp-new-adopts)
3489       (incf number
3490             (apply '+ (mapcar
3491                        'gnus-summary-number-of-articles-in-thread
3492                        gnus-tmp-new-adopts))))
3493     (if char
3494         (if (> number 1) gnus-not-empty-thread-mark
3495           gnus-empty-thread-mark)
3496       number)))
3497
3498 (defsubst gnus-summary-line-message-size (head)
3499   "Return pretty-printed version of message size.
3500 This function is intended to be used in
3501 `gnus-summary-line-format-alist'."
3502   (let ((c (or (mail-header-chars head) -1)))
3503     (cond ((< c 0) "n/a")               ; chars not available
3504           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3505           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3506           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3507           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3508
3509
3510 (defun gnus-summary-set-local-parameters (group)
3511   "Go through the local params of GROUP and set all variable specs in that list."
3512   (let ((vars '(quit-config)))          ; Ignore quit-config.
3513     (dolist (elem (gnus-group-find-parameter group))
3514       (and (consp elem)                 ; Has to be a cons.
3515            (consp (cdr elem))           ; The cdr has to be a list.
3516            (symbolp (car elem))         ; Has to be a symbol in there.
3517            (not (memq (car elem) vars))
3518            (ignore-errors               ; So we set it.
3519              (push (car elem) vars)
3520              (make-local-variable (car elem))
3521              (set (car elem) (eval (nth 1 elem))))))))
3522
3523 (defun gnus-summary-read-group (group &optional show-all no-article
3524                                       kill-buffer no-display backward
3525                                       select-articles)
3526   "Start reading news in newsgroup GROUP.
3527 If SHOW-ALL is non-nil, already read articles are also listed.
3528 If NO-ARTICLE is non-nil, no article is selected initially.
3529 If NO-DISPLAY, don't generate a summary buffer."
3530   (let (result)
3531     (while (and group
3532                 (null (setq result
3533                             (let ((gnus-auto-select-next nil))
3534                               (or (gnus-summary-read-group-1
3535                                    group show-all no-article
3536                                    kill-buffer no-display
3537                                    select-articles)
3538                                   (setq show-all nil
3539                                         select-articles nil)))))
3540                 (eq gnus-auto-select-next 'quietly))
3541       (set-buffer gnus-group-buffer)
3542       ;; The entry function called above goes to the next
3543       ;; group automatically, so we go two groups back
3544       ;; if we are searching for the previous group.
3545       (when backward
3546         (gnus-group-prev-unread-group 2))
3547       (if (not (equal group (gnus-group-group-name)))
3548           (setq group (gnus-group-group-name))
3549         (setq group nil)))
3550     result))
3551
3552 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3553   "Directly jump to the other GROUP from summary buffer.
3554 If SHOW-ALL is non-nil, already read articles are also listed."
3555   (interactive
3556    (if (eq gnus-summary-buffer (current-buffer))
3557        (list (completing-read
3558               "Group: " gnus-active-hashtb nil t
3559               (when (and gnus-newsgroup-name
3560                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3561                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3562               'gnus-group-history)
3563              current-prefix-arg)
3564      (error "%s must be invoked from a gnus summary buffer." this-command)))
3565   (unless (or (zerop (length group))
3566               (and gnus-newsgroup-name
3567                    (string-equal gnus-newsgroup-name group)))
3568     (gnus-summary-exit)
3569     (gnus-summary-read-group group show-all
3570                              gnus-dont-select-after-jump-to-other-group)))
3571
3572 (defun gnus-summary-read-group-1 (group show-all no-article
3573                                         kill-buffer no-display
3574                                         &optional select-articles)
3575   ;; Killed foreign groups can't be entered.
3576   ;;  (when (and (not (gnus-group-native-p group))
3577   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3578   ;;    (error "Dead non-native groups can't be entered"))
3579   (gnus-message 5 "Retrieving newsgroup: %s..."
3580                 (gnus-group-decoded-name group))
3581   (let* ((new-group (gnus-summary-setup-buffer group))
3582          (quit-config (gnus-group-quit-config group))
3583          (did-select (and new-group (gnus-select-newsgroup
3584                                      group show-all select-articles))))
3585     (cond
3586      ;; This summary buffer exists already, so we just select it.
3587      ((not new-group)
3588       (gnus-set-global-variables)
3589       (when kill-buffer
3590         (gnus-kill-or-deaden-summary kill-buffer))
3591       (gnus-configure-windows 'summary 'force)
3592       (gnus-set-mode-line 'summary)
3593       (gnus-summary-position-point)
3594       (message "")
3595       t)
3596      ;; We couldn't select this group.
3597      ((null did-select)
3598       (when (and (eq major-mode 'gnus-summary-mode)
3599                  (not (equal (current-buffer) kill-buffer)))
3600         (kill-buffer (current-buffer))
3601         (if (not quit-config)
3602             (progn
3603               ;; Update the info -- marks might need to be removed,
3604               ;; for instance.
3605               (gnus-summary-update-info)
3606               (set-buffer gnus-group-buffer)
3607               (gnus-group-jump-to-group group)
3608               (gnus-group-next-unread-group 1))
3609           (gnus-handle-ephemeral-exit quit-config)))
3610       (let ((grpinfo (gnus-get-info group)))
3611         (if (null (gnus-info-read grpinfo))
3612             (gnus-message 3 "Group %s contains no messages"
3613                           (gnus-group-decoded-name group))
3614           (gnus-message 3 "Can't select group")))
3615       nil)
3616      ;; The user did a `C-g' while prompting for number of articles,
3617      ;; so we exit this group.
3618      ((eq did-select 'quit)
3619       (and (eq major-mode 'gnus-summary-mode)
3620            (not (equal (current-buffer) kill-buffer))
3621            (kill-buffer (current-buffer)))
3622       (when kill-buffer
3623         (gnus-kill-or-deaden-summary kill-buffer))
3624       (if (not quit-config)
3625           (progn
3626             (set-buffer gnus-group-buffer)
3627             (gnus-group-jump-to-group group)
3628             (gnus-group-next-unread-group 1)
3629             (gnus-configure-windows 'group 'force))
3630         (gnus-handle-ephemeral-exit quit-config))
3631       ;; Finally signal the quit.
3632       (signal 'quit nil))
3633      ;; The group was successfully selected.
3634      (t
3635       (gnus-set-global-variables)
3636       ;; Save the active value in effect when the group was entered.
3637       (setq gnus-newsgroup-active
3638             (gnus-copy-sequence
3639              (gnus-active gnus-newsgroup-name)))
3640       ;; You can change the summary buffer in some way with this hook.
3641       (gnus-run-hooks 'gnus-select-group-hook)
3642       (when (memq 'summary (gnus-update-format-specifications
3643                             nil 'summary 'summary-mode 'summary-dummy))
3644         ;; The format specification for the summary line was updated,
3645         ;; so we need to update the mark positions as well.
3646         (gnus-update-summary-mark-positions))
3647       ;; Do score processing.
3648       (when gnus-use-scoring
3649         (gnus-possibly-score-headers))
3650       ;; Check whether to fill in the gaps in the threads.
3651       (when gnus-build-sparse-threads
3652         (gnus-build-sparse-threads))
3653       ;; Find the initial limit.
3654       (if show-all
3655           (let ((gnus-newsgroup-dormant nil))
3656             (gnus-summary-initial-limit show-all))
3657         (gnus-summary-initial-limit show-all))
3658       ;; Generate the summary buffer.
3659       (unless no-display
3660         (gnus-summary-prepare))
3661       (when gnus-use-trees
3662         (gnus-tree-open group)
3663         (setq gnus-summary-highlight-line-function
3664               'gnus-tree-highlight-article))
3665       ;; If the summary buffer is empty, but there are some low-scored
3666       ;; articles or some excluded dormants, we include these in the
3667       ;; buffer.
3668       (when (and (zerop (buffer-size))
3669                  (not no-display))
3670         (cond (gnus-newsgroup-dormant
3671                (gnus-summary-limit-include-dormant))
3672               ((and gnus-newsgroup-scored show-all)
3673                (gnus-summary-limit-include-expunged t))))
3674       ;; Function `gnus-apply-kill-file' must be called in this hook.
3675       (gnus-run-hooks 'gnus-apply-kill-hook)
3676       (if (and (zerop (buffer-size))
3677                (not no-display))
3678           (progn
3679             ;; This newsgroup is empty.
3680             (gnus-summary-catchup-and-exit nil t)
3681             (gnus-message 6 "No unread news")
3682             (when kill-buffer
3683               (gnus-kill-or-deaden-summary kill-buffer))
3684             ;; Return nil from this function.
3685             nil)
3686         ;; Hide conversation thread subtrees.  We cannot do this in
3687         ;; gnus-summary-prepare-hook since kill processing may not
3688         ;; work with hidden articles.
3689         (gnus-summary-maybe-hide-threads)
3690         (when kill-buffer
3691           (gnus-kill-or-deaden-summary kill-buffer))
3692         (gnus-summary-auto-select-subject)
3693         ;; Show first unread article if requested.
3694         (if (and (not no-article)
3695                  (not no-display)
3696                  gnus-newsgroup-unreads
3697                  gnus-auto-select-first)
3698             (progn
3699               (gnus-configure-windows 'summary)
3700               (let ((art (gnus-summary-article-number)))
3701                 (unless (and (not gnus-plugged)
3702                              (or (memq art gnus-newsgroup-undownloaded)
3703                                  (memq art gnus-newsgroup-downloadable)))
3704                   (gnus-summary-goto-article art))))
3705           ;; Don't select any articles.
3706           (gnus-summary-position-point)
3707           (gnus-configure-windows 'summary 'force)
3708           (gnus-set-mode-line 'summary))
3709         (when (and gnus-auto-center-group
3710                    (get-buffer-window gnus-group-buffer t))
3711           ;; Gotta use windows, because recenter does weird stuff if
3712           ;; the current buffer ain't the displayed window.
3713           (let ((owin (selected-window)))
3714             (select-window (get-buffer-window gnus-group-buffer t))
3715             (when (gnus-group-goto-group group)
3716               (recenter))
3717             (select-window owin)))
3718         ;; Mark this buffer as "prepared".
3719         (setq gnus-newsgroup-prepared t)
3720         (gnus-run-hooks 'gnus-summary-prepared-hook)
3721         (unless (gnus-ephemeral-group-p group)
3722           (gnus-group-update-group group))
3723         t)))))
3724
3725 (defun gnus-summary-auto-select-subject ()
3726   "Select the subject line on initial group entry."
3727   (goto-char (point-min))
3728   (cond
3729    ((eq gnus-auto-select-subject 'best)
3730     (gnus-summary-best-unread-subject))
3731    ((eq gnus-auto-select-subject 'unread)
3732     (gnus-summary-first-unread-subject))
3733    ((eq gnus-auto-select-subject 'unseen)
3734     (gnus-summary-first-unseen-subject))
3735    ((eq gnus-auto-select-subject 'unseen-or-unread)
3736     (gnus-summary-first-unseen-or-unread-subject))
3737    ((eq gnus-auto-select-subject 'first)
3738     ;; Do nothing.
3739     )
3740    ((functionp gnus-auto-select-subject)
3741     (funcall gnus-auto-select-subject))))
3742
3743 (defun gnus-summary-prepare ()
3744   "Generate the summary buffer."
3745   (interactive)
3746   (let ((buffer-read-only nil))
3747     (erase-buffer)
3748     (setq gnus-newsgroup-data nil
3749           gnus-newsgroup-data-reverse nil)
3750     (gnus-run-hooks 'gnus-summary-generate-hook)
3751     ;; Generate the buffer, either with threads or without.
3752     (when gnus-newsgroup-headers
3753       (gnus-summary-prepare-threads
3754        (if gnus-show-threads
3755            (gnus-sort-gathered-threads
3756             (funcall gnus-summary-thread-gathering-function
3757                      (gnus-sort-threads
3758                       (gnus-cut-threads (gnus-make-threads)))))
3759          ;; Unthreaded display.
3760          (gnus-sort-articles gnus-newsgroup-headers))))
3761     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3762     ;; Call hooks for modifying summary buffer.
3763     (goto-char (point-min))
3764     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3765
3766 (defsubst gnus-general-simplify-subject (subject)
3767   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3768   (setq subject
3769         (cond
3770          ;; Truncate the subject.
3771          (gnus-simplify-subject-functions
3772           (gnus-map-function gnus-simplify-subject-functions subject))
3773          ((numberp gnus-summary-gather-subject-limit)
3774           (setq subject (gnus-simplify-subject-re subject))
3775           (if (> (length subject) gnus-summary-gather-subject-limit)
3776               (substring subject 0 gnus-summary-gather-subject-limit)
3777             subject))
3778          ;; Fuzzily simplify it.
3779          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3780           (gnus-simplify-subject-fuzzy subject))
3781          ;; Just remove the leading "Re:".
3782          (t
3783           (gnus-simplify-subject-re subject))))
3784
3785   (if (and gnus-summary-gather-exclude-subject
3786            (string-match gnus-summary-gather-exclude-subject subject))
3787       nil                               ; This article shouldn't be gathered
3788     subject))
3789
3790 (defun gnus-summary-simplify-subject-query ()
3791   "Query where the respool algorithm would put this article."
3792   (interactive)
3793   (gnus-summary-select-article)
3794   (message "%s"
3795            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3796
3797 (defun gnus-gather-threads-by-subject (threads)
3798   "Gather threads by looking at Subject headers."
3799   (if (not gnus-summary-make-false-root)
3800       threads
3801     (let ((hashtb (gnus-make-hashtable 1024))
3802           (prev threads)
3803           (result threads)
3804           subject hthread whole-subject)
3805       (while threads
3806         (setq subject (gnus-general-simplify-subject
3807                        (setq whole-subject (mail-header-subject
3808                                             (caar threads)))))
3809         (when subject
3810           (if (setq hthread (gnus-gethash subject hashtb))
3811               (progn
3812                 ;; We enter a dummy root into the thread, if we
3813                 ;; haven't done that already.
3814                 (unless (stringp (caar hthread))
3815                   (setcar hthread (list whole-subject (car hthread))))
3816                 ;; We add this new gathered thread to this gathered
3817                 ;; thread.
3818                 (setcdr (car hthread)
3819                         (nconc (cdar hthread) (list (car threads))))
3820                 ;; Remove it from the list of threads.
3821                 (setcdr prev (cdr threads))
3822                 (setq threads prev))
3823             ;; Enter this thread into the hash table.
3824             (gnus-sethash subject
3825                           (if gnus-summary-make-false-root-always
3826                               (progn
3827                                 ;; If you want a dummy root above all
3828                                 ;; threads...
3829                                 (setcar threads (list whole-subject
3830                                                       (car threads)))
3831                                 threads)
3832                             threads)
3833                           hashtb)))
3834         (setq prev threads)
3835         (setq threads (cdr threads)))
3836       result)))
3837
3838 (defun gnus-gather-threads-by-references (threads)
3839   "Gather threads by looking at References headers."
3840   (let ((idhashtb (gnus-make-hashtable 1024))
3841         (thhashtb (gnus-make-hashtable 1024))
3842         (prev threads)
3843         (result threads)
3844         ids references id gthread gid entered ref)
3845     (while threads
3846       (when (setq references (mail-header-references (caar threads)))
3847         (setq id (mail-header-id (caar threads))
3848               ids (inline (gnus-split-references references))
3849               entered nil)
3850         (while (setq ref (pop ids))
3851           (setq ids (delete ref ids))
3852           (if (not (setq gid (gnus-gethash ref idhashtb)))
3853               (progn
3854                 (gnus-sethash ref id idhashtb)
3855                 (gnus-sethash id threads thhashtb))
3856             (setq gthread (gnus-gethash gid thhashtb))
3857             (unless entered
3858               ;; We enter a dummy root into the thread, if we
3859               ;; haven't done that already.
3860               (unless (stringp (caar gthread))
3861                 (setcar gthread (list (mail-header-subject (caar gthread))
3862                                       (car gthread))))
3863               ;; We add this new gathered thread to this gathered
3864               ;; thread.
3865               (setcdr (car gthread)
3866                       (nconc (cdar gthread) (list (car threads)))))
3867             ;; Add it into the thread hash table.
3868             (gnus-sethash id gthread thhashtb)
3869             (setq entered t)
3870             ;; Remove it from the list of threads.
3871             (setcdr prev (cdr threads))
3872             (setq threads prev))))
3873       (setq prev threads)
3874       (setq threads (cdr threads)))
3875     result))
3876
3877 (defun gnus-sort-gathered-threads (threads)
3878   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3879   (let ((result threads))
3880     (while threads
3881       (when (stringp (caar threads))
3882         (setcdr (car threads)
3883                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3884       (setq threads (cdr threads)))
3885     result))
3886
3887 (defun gnus-thread-loop-p (root thread)
3888   "Say whether ROOT is in THREAD."
3889   (let ((stack (list thread))
3890         (infloop 0)
3891         th)
3892     (while (setq thread (pop stack))
3893       (setq th (cdr thread))
3894       (while (and th
3895                   (not (eq (caar th) root)))
3896         (pop th))
3897       (if th
3898           ;; We have found a loop.
3899           (let (ref-dep)
3900             (setcdr thread (delq (car th) (cdr thread)))
3901             (if (boundp (setq ref-dep (intern "none"
3902                                               gnus-newsgroup-dependencies)))
3903                 (setcdr (symbol-value ref-dep)
3904                         (nconc (cdr (symbol-value ref-dep))
3905                                (list (car th))))
3906               (set ref-dep (list nil (car th))))
3907             (setq infloop 1
3908                   stack nil))
3909         ;; Push all the subthreads onto the stack.
3910         (push (cdr thread) stack)))
3911     infloop))
3912
3913 (defun gnus-make-threads ()
3914   "Go through the dependency hashtb and find the roots.  Return all threads."
3915   (let (threads)
3916     (while (catch 'infloop
3917              (mapatoms
3918               (lambda (refs)
3919                 ;; Deal with self-referencing References loops.
3920                 (when (and (car (symbol-value refs))
3921                            (not (zerop
3922                                  (apply
3923                                   '+
3924                                   (mapcar
3925                                    (lambda (thread)
3926                                      (gnus-thread-loop-p
3927                                       (car (symbol-value refs)) thread))
3928                                    (cdr (symbol-value refs)))))))
3929                   (setq threads nil)
3930                   (throw 'infloop t))
3931                 (unless (car (symbol-value refs))
3932                   ;; These threads do not refer back to any other articles,
3933                   ;; so they're roots.
3934                   (setq threads (append (cdr (symbol-value refs)) threads))))
3935               gnus-newsgroup-dependencies)))
3936     threads))
3937
3938 ;; Build the thread tree.
3939 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3940   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3941
3942 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3943 if it was already present.
3944
3945 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3946 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3947 Message-IDs will be renamed to a unique Message-ID before being
3948 entered.
3949
3950 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3951   (let* ((id (mail-header-id header))
3952          (id-dep (and id (intern id dependencies)))
3953          parent-id ref ref-dep ref-header replaced)
3954     ;; Enter this `header' in the `dependencies' table.
3955     (cond
3956      ((not id-dep)
3957       (setq header nil))
3958      ;; The first two cases do the normal part: enter a new `header'
3959      ;; in the `dependencies' table.
3960      ((not (boundp id-dep))
3961       (set id-dep (list header)))
3962      ((null (car (symbol-value id-dep)))
3963       (setcar (symbol-value id-dep) header))
3964
3965      ;; From here the `header' was already present in the
3966      ;; `dependencies' table.
3967      (force-new
3968       ;; Overrides an existing entry;
3969       ;; just set the header part of the entry.
3970       (setcar (symbol-value id-dep) header)
3971       (setq replaced t))
3972
3973      ;; Renames the existing `header' to a unique Message-ID.
3974      ((not gnus-summary-ignore-duplicates)
3975       ;; An article with this Message-ID has already been seen.
3976       ;; We rename the Message-ID.
3977       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3978            (list header))
3979       (mail-header-set-id header id))
3980
3981      ;; The last case ignores an existing entry, except it adds any
3982      ;; additional Xrefs (in case the two articles came from different
3983      ;; servers.
3984      ;; Also sets `header' to `nil' meaning that the `dependencies'
3985      ;; table was *not* modified.
3986      (t
3987       (mail-header-set-xref
3988        (car (symbol-value id-dep))
3989        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3990                    "")
3991                (or (mail-header-xref header) "")))
3992       (setq header nil)))
3993
3994     (when (and header (not replaced))
3995       ;; First check that we are not creating a References loop.
3996       (setq parent-id (gnus-parent-id (mail-header-references header)))
3997       (setq ref parent-id)
3998       (while (and ref
3999                   (setq ref-dep (intern-soft ref dependencies))
4000                   (boundp ref-dep)
4001                   (setq ref-header (car (symbol-value ref-dep))))
4002         (if (string= id ref)
4003             ;; Yuk!  This is a reference loop.  Make the article be a
4004             ;; root article.
4005             (progn
4006               (mail-header-set-references (car (symbol-value id-dep)) "none")
4007               (setq ref nil)
4008               (setq parent-id nil))
4009           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4010       (setq ref-dep (intern (or parent-id "none") dependencies))
4011       (if (boundp ref-dep)
4012           (setcdr (symbol-value ref-dep)
4013                   (nconc (cdr (symbol-value ref-dep))
4014                          (list (symbol-value id-dep))))
4015         (set ref-dep (list nil (symbol-value id-dep)))))
4016     header))
4017
4018 (defun gnus-extract-message-id-from-in-reply-to (string)
4019   (if (string-match "<[^>]+>" string)
4020       (substring string (match-beginning 0) (match-end 0))
4021     nil))
4022
4023 (defun gnus-build-sparse-threads ()
4024   (let ((headers gnus-newsgroup-headers)
4025         (mail-parse-charset gnus-newsgroup-charset)
4026         (gnus-summary-ignore-duplicates t)
4027         header references generation relations
4028         subject child end new-child date)
4029     ;; First we create an alist of generations/relations, where
4030     ;; generations is how much we trust the relation, and the relation
4031     ;; is parent/child.
4032     (gnus-message 7 "Making sparse threads...")
4033     (save-excursion
4034       (nnheader-set-temp-buffer " *gnus sparse threads*")
4035       (while (setq header (pop headers))
4036         (when (and (setq references (mail-header-references header))
4037                    (not (string= references "")))
4038           (insert references)
4039           (setq child (mail-header-id header)
4040                 subject (mail-header-subject header)
4041                 date (mail-header-date header)
4042                 generation 0)
4043           (while (search-backward ">" nil t)
4044             (setq end (1+ (point)))
4045             (when (search-backward "<" nil t)
4046               (setq new-child (buffer-substring (point) end))
4047               (push (list (incf generation)
4048                           child (setq child new-child)
4049                           subject date)
4050                     relations)))
4051           (when child
4052             (push (list (1+ generation) child nil subject) relations))
4053           (erase-buffer)))
4054       (kill-buffer (current-buffer)))
4055     ;; Sort over trustworthiness.
4056     (mapcar
4057      (lambda (relation)
4058        (when (gnus-dependencies-add-header
4059               (make-full-mail-header-from-decoded-header
4060                gnus-reffed-article-number
4061                (nth 3 relation) "" (or (nth 4 relation) "")
4062                (nth 1 relation)
4063                (or (nth 2 relation) "") 0 0 "")
4064               gnus-newsgroup-dependencies nil)
4065          (push gnus-reffed-article-number gnus-newsgroup-limit)
4066          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4067          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4068                gnus-newsgroup-reads)
4069          (decf gnus-reffed-article-number)))
4070      (sort relations 'car-less-than-car))
4071     (gnus-message 7 "Making sparse threads...done")))
4072
4073 (defun gnus-build-old-threads ()
4074   ;; Look at all the articles that refer back to old articles, and
4075   ;; fetch the headers for the articles that aren't there.  This will
4076   ;; build complete threads - if the roots haven't been expired by the
4077   ;; server, that is.
4078   (let ((mail-parse-charset gnus-newsgroup-charset)
4079         id heads)
4080     (mapatoms
4081      (lambda (refs)
4082        (when (not (car (symbol-value refs)))
4083          (setq heads (cdr (symbol-value refs)))
4084          (while heads
4085            (if (memq (mail-header-number (caar heads))
4086                      gnus-newsgroup-dormant)
4087                (setq heads (cdr heads))
4088              (setq id (symbol-name refs))
4089              (while (and (setq id (gnus-build-get-header id))
4090                          (not (car (gnus-id-to-thread id)))))
4091              (setq heads nil)))))
4092      gnus-newsgroup-dependencies)))
4093
4094 (defsubst gnus-remove-odd-characters (string)
4095   "Translate STRING into something that doesn't contain weird characters."
4096   (mm-subst-char-in-string
4097    ?\r ?\-
4098    (mm-subst-char-in-string ?\n ?\- string t) t))
4099
4100 ;; This function has to be called with point after the article number
4101 ;; on the beginning of the line.
4102 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4103   (let ((eol (point-at-eol))
4104         (buffer (current-buffer))
4105         header references in-reply-to)
4106
4107     ;; overview: [num subject from date id refs chars lines misc]
4108     (unwind-protect
4109         (progn
4110           (narrow-to-region (point) eol)
4111           (unless (eobp)
4112             (forward-char))
4113
4114           (setq header
4115                 (make-full-mail-header
4116                  number                         ; number
4117                  (nnheader-nov-field)           ; subject
4118                  (nnheader-nov-field)           ; from
4119                  (nnheader-nov-field)           ; date
4120                  (nnheader-nov-read-message-id number)  ; id
4121                  (setq references (nnheader-nov-field)) ; refs
4122                  (nnheader-nov-read-integer)    ; chars
4123                  (nnheader-nov-read-integer)    ; lines
4124                  (unless (eobp)
4125                    (if (looking-at "Xref: ")
4126                        (goto-char (match-end 0)))
4127                    (nnheader-nov-field))        ; Xref
4128                  (nnheader-nov-parse-extra))))  ; extra
4129
4130       (widen))
4131
4132     (when (and (string= references "")
4133                (setq in-reply-to (mail-header-extra header))
4134                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4135       (mail-header-set-references
4136        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4137
4138     (when gnus-alter-header-function
4139       (funcall gnus-alter-header-function header))
4140     (gnus-dependencies-add-header header dependencies force-new)))
4141
4142 (defun gnus-build-get-header (id)
4143   "Look through the buffer of NOV lines and find the header to ID.
4144 Enter this line into the dependencies hash table, and return
4145 the id of the parent article (if any)."
4146   (let ((deps gnus-newsgroup-dependencies)
4147         found header)
4148     (prog1
4149         (save-excursion
4150           (set-buffer nntp-server-buffer)
4151           (let ((case-fold-search nil))
4152             (goto-char (point-min))
4153             (while (and (not found)
4154                         (search-forward id nil t))
4155               (beginning-of-line)
4156               (setq found (looking-at
4157                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4158                                    (regexp-quote id))))
4159               (or found (beginning-of-line 2)))
4160             (when found
4161               (beginning-of-line)
4162               (and
4163                (setq header (gnus-nov-parse-line
4164                              (read (current-buffer)) deps))
4165                (gnus-parent-id (mail-header-references header))))))
4166       (when header
4167         (let ((number (mail-header-number header)))
4168           (push number gnus-newsgroup-limit)
4169           (push header gnus-newsgroup-headers)
4170           (if (memq number gnus-newsgroup-unselected)
4171               (progn
4172                 (setq gnus-newsgroup-unreads
4173                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4174                                                number))
4175                 (setq gnus-newsgroup-unselected
4176                       (delq number gnus-newsgroup-unselected)))
4177             (push number gnus-newsgroup-ancient)))))))
4178
4179 (defun gnus-build-all-threads ()
4180   "Read all the headers."
4181   (let ((gnus-summary-ignore-duplicates t)
4182         (mail-parse-charset gnus-newsgroup-charset)
4183         (dependencies gnus-newsgroup-dependencies)
4184         header article)
4185     (save-excursion
4186       (set-buffer nntp-server-buffer)
4187       (let ((case-fold-search nil))
4188         (goto-char (point-min))
4189         (while (not (eobp))
4190           (ignore-errors
4191             (setq article (read (current-buffer))
4192                   header (gnus-nov-parse-line article dependencies)))
4193           (when header
4194             (with-current-buffer gnus-summary-buffer
4195               (push header gnus-newsgroup-headers)
4196               (if (memq (setq article (mail-header-number header))
4197                         gnus-newsgroup-unselected)
4198                   (progn
4199                     (setq gnus-newsgroup-unreads
4200                           (gnus-add-to-sorted-list
4201                            gnus-newsgroup-unreads article))
4202                     (setq gnus-newsgroup-unselected
4203                           (delq article gnus-newsgroup-unselected)))
4204                 (push article gnus-newsgroup-ancient)))
4205             (forward-line 1)))))))
4206
4207 (defun gnus-summary-update-article-line (article header)
4208   "Update the line for ARTICLE using HEADER."
4209   (let* ((id (mail-header-id header))
4210          (thread (gnus-id-to-thread id)))
4211     (unless thread
4212       (error "Article in no thread"))
4213     ;; Update the thread.
4214     (setcar thread header)
4215     (gnus-summary-goto-subject article)
4216     (let* ((datal (gnus-data-find-list article))
4217            (data (car datal))
4218            (buffer-read-only nil)
4219            (level (gnus-summary-thread-level)))
4220       (gnus-delete-line)
4221       (let ((inserted (- (point)
4222                          (progn
4223                            (gnus-summary-insert-line
4224                             header level nil
4225                             (memq article gnus-newsgroup-undownloaded)
4226                             (gnus-article-mark article)
4227                             (memq article gnus-newsgroup-replied)
4228                             (memq article gnus-newsgroup-expirable)
4229                             ;; Only insert the Subject string when it's different
4230                             ;; from the previous Subject string.
4231                             (if (and
4232                                  gnus-show-threads
4233                                  (gnus-subject-equal
4234                                   (condition-case ()
4235                                       (mail-header-subject
4236                                        (gnus-data-header
4237                                         (cadr
4238                                          (gnus-data-find-list
4239                                           article
4240                                           (gnus-data-list t)))))
4241                                     ;; Error on the side of excessive subjects.
4242                                     (error ""))
4243                                   (mail-header-subject header)))
4244                                 ""
4245                               (mail-header-subject header))
4246                             nil (cdr (assq article gnus-newsgroup-scored))
4247                             (memq article gnus-newsgroup-processable))
4248                            (point)))))
4249         (when (cdr datal)
4250           (gnus-data-update-list
4251            (cdr datal)
4252            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4253
4254 (defun gnus-summary-update-article (article &optional iheader)
4255   "Update ARTICLE in the summary buffer."
4256   (set-buffer gnus-summary-buffer)
4257   (let* ((header (gnus-summary-article-header article))
4258          (id (mail-header-id header))
4259          (data (gnus-data-find article))
4260          (thread (gnus-id-to-thread id))
4261          (references (mail-header-references header))
4262          (parent
4263           (gnus-id-to-thread
4264            (or (gnus-parent-id
4265                 (when (and references
4266                            (not (equal "" references)))
4267                   references))
4268                "none")))
4269          (buffer-read-only nil)
4270          (old (car thread)))
4271     (when thread
4272       (unless iheader
4273         (setcar thread nil)
4274         (when parent
4275           (delq thread parent)))
4276       (if (gnus-summary-insert-subject id header)
4277           ;; Set the (possibly) new article number in the data structure.
4278           (gnus-data-set-number data (gnus-id-to-article id))
4279         (setcar thread old)
4280         nil))))
4281
4282 (defun gnus-rebuild-thread (id &optional line)
4283   "Rebuild the thread containing ID.
4284 If LINE, insert the rebuilt thread starting on line LINE."
4285   (let ((buffer-read-only nil)
4286         old-pos current thread data)
4287     (if (not gnus-show-threads)
4288         (setq thread (list (car (gnus-id-to-thread id))))
4289       ;; Get the thread this article is part of.
4290       (setq thread (gnus-remove-thread id)))
4291     (setq old-pos (point-at-bol))
4292     (setq current (save-excursion
4293                     (and (re-search-backward "[\r\n]" nil t)
4294                          (gnus-summary-article-number))))
4295     ;; If this is a gathered thread, we have to go some re-gathering.
4296     (when (stringp (car thread))
4297       (let ((subject (car thread))
4298             roots thr)
4299         (setq thread (cdr thread))
4300         (while thread
4301           (unless (memq (setq thr (gnus-id-to-thread
4302                                    (gnus-root-id
4303                                     (mail-header-id (caar thread)))))
4304                         roots)
4305             (push thr roots))
4306           (setq thread (cdr thread)))
4307         ;; We now have all (unique) roots.
4308         (if (= (length roots) 1)
4309             ;; All the loose roots are now one solid root.
4310             (setq thread (car roots))
4311           (setq thread (cons subject (gnus-sort-threads roots))))))
4312     (let (threads)
4313       ;; We then insert this thread into the summary buffer.
4314       (when line
4315         (goto-char (point-min))
4316         (forward-line (1- line)))
4317       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4318         (if gnus-show-threads
4319             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4320           (gnus-summary-prepare-unthreaded thread))
4321         (setq data (nreverse gnus-newsgroup-data))
4322         (setq threads gnus-newsgroup-threads))
4323       ;; We splice the new data into the data structure.
4324       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4325       ;;!!! then we want to insert at the beginning of the buffer.
4326       ;;!!! That happens to be true with Gnus now, but that may
4327       ;;!!! change in the future.  Perhaps.
4328       (gnus-data-enter-list
4329        (if line nil current) data (- (point) old-pos))
4330       (setq gnus-newsgroup-threads
4331             (nconc threads gnus-newsgroup-threads))
4332       (gnus-data-compute-positions))))
4333
4334 (defun gnus-number-to-header (number)
4335   "Return the header for article NUMBER."
4336   (let ((headers gnus-newsgroup-headers))
4337     (while (and headers
4338                 (not (= number (mail-header-number (car headers)))))
4339       (pop headers))
4340     (when headers
4341       (car headers))))
4342
4343 (defun gnus-parent-headers (in-headers &optional generation)
4344   "Return the headers of the GENERATIONeth parent of HEADERS."
4345   (unless generation
4346     (setq generation 1))
4347   (let ((parent t)
4348         (headers in-headers)
4349         references)
4350     (while (and parent
4351                 (not (zerop generation))
4352                 (setq references (mail-header-references headers)))
4353       (setq headers (if (and references
4354                              (setq parent (gnus-parent-id references)))
4355                         (car (gnus-id-to-thread parent))
4356                       nil))
4357       (decf generation))
4358     (and (not (eq headers in-headers))
4359          headers)))
4360
4361 (defun gnus-id-to-thread (id)
4362   "Return the (sub-)thread where ID appears."
4363   (gnus-gethash id gnus-newsgroup-dependencies))
4364
4365 (defun gnus-id-to-article (id)
4366   "Return the article number of ID."
4367   (let ((thread (gnus-id-to-thread id)))
4368     (when (and thread
4369                (car thread))
4370       (mail-header-number (car thread)))))
4371
4372 (defun gnus-id-to-header (id)
4373   "Return the article headers of ID."
4374   (car (gnus-id-to-thread id)))
4375
4376 (defun gnus-article-displayed-root-p (article)
4377   "Say whether ARTICLE is a root(ish) article."
4378   (let ((level (gnus-summary-thread-level article))
4379         (refs (mail-header-references  (gnus-summary-article-header article)))
4380         particle)
4381     (cond
4382      ((null level) nil)
4383      ((zerop level) t)
4384      ((null refs) t)
4385      ((null (gnus-parent-id refs)) t)
4386      ((and (= 1 level)
4387            (null (setq particle (gnus-id-to-article
4388                                  (gnus-parent-id refs))))
4389            (null (gnus-summary-thread-level particle)))))))
4390
4391 (defun gnus-root-id (id)
4392   "Return the id of the root of the thread where ID appears."
4393   (let (last-id prev)
4394     (while (and id (setq prev (car (gnus-id-to-thread id))))
4395       (setq last-id id
4396             id (gnus-parent-id (mail-header-references prev))))
4397     last-id))
4398
4399 (defun gnus-articles-in-thread (thread)
4400   "Return the list of articles in THREAD."
4401   (cons (mail-header-number (car thread))
4402         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4403
4404 (defun gnus-remove-thread (id &optional dont-remove)
4405   "Remove the thread that has ID in it."
4406   (let (headers thread last-id)
4407     ;; First go up in this thread until we find the root.
4408     (setq last-id (gnus-root-id id)
4409           headers (message-flatten-list (gnus-id-to-thread last-id)))
4410     ;; We have now found the real root of this thread.  It might have
4411     ;; been gathered into some loose thread, so we have to search
4412     ;; through the threads to find the thread we wanted.
4413     (let ((threads gnus-newsgroup-threads)
4414           sub)
4415       (while threads
4416         (setq sub (car threads))
4417         (if (stringp (car sub))
4418             ;; This is a gathered thread, so we look at the roots
4419             ;; below it to find whether this article is in this
4420             ;; gathered root.
4421             (progn
4422               (setq sub (cdr sub))
4423               (while sub
4424                 (when (member (caar sub) headers)
4425                   (setq thread (car threads)
4426                         threads nil
4427                         sub nil))
4428                 (setq sub (cdr sub))))
4429           ;; It's an ordinary thread, so we check it.
4430           (when (eq (car sub) (car headers))
4431             (setq thread sub
4432                   threads nil)))
4433         (setq threads (cdr threads)))
4434       ;; If this article is in no thread, then it's a root.
4435       (if thread
4436           (unless dont-remove
4437             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4438         (setq thread (gnus-id-to-thread last-id)))
4439       (when thread
4440         (prog1
4441             thread                      ; We return this thread.
4442           (unless dont-remove
4443             (if (stringp (car thread))
4444                 (progn
4445                   ;; If we use dummy roots, then we have to remove the
4446                   ;; dummy root as well.
4447                   (when (eq gnus-summary-make-false-root 'dummy)
4448                     ;; We go to the dummy root by going to
4449                     ;; the first sub-"thread", and then one line up.
4450                     (gnus-summary-goto-article
4451                      (mail-header-number (caadr thread)))
4452                     (forward-line -1)
4453                     (gnus-delete-line)
4454                     (gnus-data-compute-positions))
4455                   (setq thread (cdr thread))
4456                   (while thread
4457                     (gnus-remove-thread-1 (car thread))
4458                     (setq thread (cdr thread))))
4459               (gnus-remove-thread-1 thread))))))))
4460
4461 (defun gnus-remove-thread-1 (thread)
4462   "Remove the thread THREAD recursively."
4463   (let ((number (mail-header-number (pop thread)))
4464         d)
4465     (setq thread (reverse thread))
4466     (while thread
4467       (gnus-remove-thread-1 (pop thread)))
4468     (when (setq d (gnus-data-find number))
4469       (goto-char (gnus-data-pos d))
4470       (gnus-summary-show-thread)
4471       (gnus-data-remove
4472        number
4473        (- (point-at-bol)
4474           (prog1
4475               (1+ (point-at-eol))
4476             (gnus-delete-line)))))))
4477
4478 (defun gnus-sort-threads-1 (threads func)
4479   (sort (mapcar (lambda (thread)
4480                   (cons (car thread)
4481                         (and (cdr thread)
4482                              (gnus-sort-threads-1 (cdr thread) func))))
4483                 threads) func))
4484
4485 (defun gnus-sort-threads (threads)
4486   "Sort THREADS."
4487   (if (not gnus-thread-sort-functions)
4488       threads
4489     (gnus-message 8 "Sorting threads...")
4490     (let ((max-lisp-eval-depth 5000))
4491       (prog1 (gnus-sort-threads-1
4492          threads
4493          (gnus-make-sort-function gnus-thread-sort-functions))
4494         (gnus-message 8 "Sorting threads...done")))))
4495
4496 (defun gnus-sort-articles (articles)
4497   "Sort ARTICLES."
4498   (when gnus-article-sort-functions
4499     (gnus-message 7 "Sorting articles...")
4500     (prog1
4501         (setq gnus-newsgroup-headers
4502               (sort articles (gnus-make-sort-function
4503                               gnus-article-sort-functions)))
4504       (gnus-message 7 "Sorting articles...done"))))
4505
4506 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4507 (defmacro gnus-thread-header (thread)
4508   "Return header of first article in THREAD.
4509 Note that THREAD must never, ever be anything else than a variable -
4510 using some other form will lead to serious barfage."
4511   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4512   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4513   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4514         (vector thread) 2))
4515
4516 (defsubst gnus-article-sort-by-number (h1 h2)
4517   "Sort articles by article number."
4518   (< (mail-header-number h1)
4519      (mail-header-number h2)))
4520
4521 (defun gnus-thread-sort-by-number (h1 h2)
4522   "Sort threads by root article number."
4523   (gnus-article-sort-by-number
4524    (gnus-thread-header h1) (gnus-thread-header h2)))
4525
4526 (defsubst gnus-article-sort-by-random (h1 h2)
4527   "Sort articles by article number."
4528   (zerop (random 2)))
4529
4530 (defun gnus-thread-sort-by-random (h1 h2)
4531   "Sort threads by root article number."
4532   (gnus-article-sort-by-random
4533    (gnus-thread-header h1) (gnus-thread-header h2)))
4534
4535 (defsubst gnus-article-sort-by-lines (h1 h2)
4536   "Sort articles by article Lines header."
4537   (< (mail-header-lines h1)
4538      (mail-header-lines h2)))
4539
4540 (defun gnus-thread-sort-by-lines (h1 h2)
4541   "Sort threads by root article Lines header."
4542   (gnus-article-sort-by-lines
4543    (gnus-thread-header h1) (gnus-thread-header h2)))
4544
4545 (defsubst gnus-article-sort-by-chars (h1 h2)
4546   "Sort articles by octet length."
4547   (< (mail-header-chars h1)
4548      (mail-header-chars h2)))
4549
4550 (defun gnus-thread-sort-by-chars (h1 h2)
4551   "Sort threads by root article octet length."
4552   (gnus-article-sort-by-chars
4553    (gnus-thread-header h1) (gnus-thread-header h2)))
4554
4555 (defsubst gnus-article-sort-by-author (h1 h2)
4556   "Sort articles by root author."
4557   (string-lessp
4558    (let ((addr (car (mime-entity-read-field h1 'From))))
4559      (or (std11-full-name-string addr)
4560          (std11-address-string addr)
4561          ""))
4562    (let ((addr (car (mime-entity-read-field h2 'From))))
4563      (or (std11-full-name-string addr)
4564          (std11-address-string addr)
4565          ""))
4566    ))
4567
4568 (defun gnus-thread-sort-by-author (h1 h2)
4569   "Sort threads by root author."
4570   (gnus-article-sort-by-author
4571    (gnus-thread-header h1)  (gnus-thread-header h2)))
4572
4573 (defsubst gnus-article-sort-by-recipient (h1 h2)
4574   "Sort articles by recipient."
4575   (string-lessp
4576    (let ((extract (funcall
4577                    gnus-extract-address-components
4578                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4579      (or (car extract) (cadr extract)))
4580    (let ((extract (funcall
4581                    gnus-extract-address-components
4582                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4583      (or (car extract) (cadr extract)))))
4584
4585 (defsubst gnus-article-sort-by-subject (h1 h2)
4586   "Sort articles by root subject."
4587   (string-lessp
4588    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4589    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4590
4591 (defun gnus-thread-sort-by-subject (h1 h2)
4592   "Sort threads by root subject."
4593   (gnus-article-sort-by-subject
4594    (gnus-thread-header h1) (gnus-thread-header h2)))
4595
4596 (defsubst gnus-article-sort-by-date (h1 h2)
4597   "Sort articles by root article date."
4598   (time-less-p
4599    (gnus-date-get-time (mail-header-date h1))
4600    (gnus-date-get-time (mail-header-date h2))))
4601
4602 (defun gnus-thread-sort-by-date (h1 h2)
4603   "Sort threads by root article date."
4604   (gnus-article-sort-by-date
4605    (gnus-thread-header h1) (gnus-thread-header h2)))
4606
4607 (defsubst gnus-article-sort-by-score (h1 h2)
4608   "Sort articles by root article score.
4609 Unscored articles will be counted as having a score of zero."
4610   (> (or (cdr (assq (mail-header-number h1)
4611                     gnus-newsgroup-scored))
4612          gnus-summary-default-score 0)
4613      (or (cdr (assq (mail-header-number h2)
4614                     gnus-newsgroup-scored))
4615          gnus-summary-default-score 0)))
4616
4617 (defun gnus-thread-sort-by-score (h1 h2)
4618   "Sort threads by root article score."
4619   (gnus-article-sort-by-score
4620    (gnus-thread-header h1) (gnus-thread-header h2)))
4621
4622 (defun gnus-thread-sort-by-total-score (h1 h2)
4623   "Sort threads by the sum of all scores in the thread.
4624 Unscored articles will be counted as having a score of zero."
4625   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4626
4627 (defun gnus-thread-total-score (thread)
4628   ;; This function find the total score of THREAD.
4629   (cond
4630    ((null thread)
4631     0)
4632    ((consp thread)
4633     (if (stringp (car thread))
4634         (apply gnus-thread-score-function 0
4635                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4636       (gnus-thread-total-score-1 thread)))
4637    (t
4638     (gnus-thread-total-score-1 (list thread)))))
4639
4640 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4641   "Sort threads such that the thread with the most recently arrived article comes first."
4642   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4643
4644 (defun gnus-thread-highest-number (thread)
4645   "Return the highest article number in THREAD."
4646   (apply 'max (mapcar (lambda (header)
4647                         (mail-header-number header))
4648                       (message-flatten-list thread))))
4649
4650 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4651   "Sort threads such that the thread with the most recently dated article comes first."
4652   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4653
4654 (defun gnus-thread-latest-date (thread)
4655   "Return the highest article date in THREAD."
4656   (let ((previous-time 0))
4657     (apply 'max
4658            (mapcar
4659             (lambda (header)
4660               (setq previous-time
4661                     (condition-case ()
4662                         (time-to-seconds (mail-header-parse-date
4663                                           (mail-header-date header)))
4664                       (error previous-time))))
4665             (sort
4666              (message-flatten-list thread)
4667              (lambda (h1 h2)
4668                (< (mail-header-number h1)
4669                   (mail-header-number h2))))))))
4670
4671 (defun gnus-thread-total-score-1 (root)
4672   ;; This function find the total score of the thread below ROOT.
4673   (setq root (car root))
4674   (apply gnus-thread-score-function
4675          (or (append
4676               (mapcar 'gnus-thread-total-score
4677                       (cdr (gnus-id-to-thread (mail-header-id root))))
4678               (when (> (mail-header-number root) 0)
4679                 (list (or (cdr (assq (mail-header-number root)
4680                                      gnus-newsgroup-scored))
4681                           gnus-summary-default-score 0))))
4682              (list gnus-summary-default-score)
4683              '(0))))
4684
4685 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4686 (defvar gnus-tmp-prev-subject nil)
4687 (defvar gnus-tmp-false-parent nil)
4688 (defvar gnus-tmp-root-expunged nil)
4689 (defvar gnus-tmp-dummy-line nil)
4690
4691 (eval-when-compile (defvar gnus-tmp-header))
4692 (defun gnus-extra-header (type &optional header)
4693   "Return the extra header of TYPE."
4694   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4695       ""))
4696
4697 (defvar gnus-tmp-thread-tree-header-string "")
4698
4699 (defcustom gnus-sum-thread-tree-root "> "
4700   "With %B spec, used for the root of a thread.
4701 If nil, use subject instead."
4702   :version "21.4"
4703   :type '(radio (const :format "%v  " nil) string)
4704   :group 'gnus-thread)
4705 (defcustom gnus-sum-thread-tree-false-root "> "
4706   "With %B spec, used for a false root of a thread.
4707 If nil, use subject instead."
4708   :version "21.4"
4709   :type '(radio (const :format "%v  " nil) string)
4710   :group 'gnus-thread)
4711 (defcustom gnus-sum-thread-tree-single-indent ""
4712   "With %B spec, used for a thread with just one message.
4713 If nil, use subject instead."
4714   :version "21.4"
4715   :type '(radio (const :format "%v  " nil) string)
4716   :group 'gnus-thread)
4717 (defcustom gnus-sum-thread-tree-vertical "| "
4718   "With %B spec, used for drawing a vertical line."
4719   :version "21.4"
4720   :type 'string
4721   :group 'gnus-thread)
4722 (defcustom gnus-sum-thread-tree-indent "  "
4723   "With %B spec, used for indenting."
4724   :version "21.4"
4725   :type 'string
4726   :group 'gnus-thread)
4727 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4728   "With %B spec, used for a leaf with brothers."
4729   :version "21.4"
4730   :type 'string
4731   :group 'gnus-thread)
4732 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4733   "With %B spec, used for a leaf without brothers."
4734   :version "21.4"
4735   :type 'string
4736   :group 'gnus-thread)
4737
4738 (defun gnus-summary-prepare-threads (threads)
4739   "Prepare summary buffer from THREADS and indentation LEVEL.
4740 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4741 or a straight list of headers."
4742   (gnus-message 7 "Generating summary...")
4743
4744   (setq gnus-newsgroup-threads threads)
4745   (beginning-of-line)
4746
4747   (let ((gnus-tmp-level 0)
4748         (default-score (or gnus-summary-default-score 0))
4749         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4750         (building-line-count gnus-summary-display-while-building)
4751         (building-count (integerp gnus-summary-display-while-building))
4752         thread number subject stack state gnus-tmp-gathered beg-match
4753         new-roots gnus-tmp-new-adopts thread-end simp-subject
4754         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4755         gnus-tmp-replied gnus-tmp-subject-or-nil
4756         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4757         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4758         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4759         tree-stack)
4760
4761     (setq gnus-tmp-prev-subject nil
4762           gnus-tmp-thread-tree-header-string "")
4763
4764     (if (vectorp (car threads))
4765         ;; If this is a straight (sic) list of headers, then a
4766         ;; threaded summary display isn't required, so we just create
4767         ;; an unthreaded one.
4768         (gnus-summary-prepare-unthreaded threads)
4769
4770       ;; Do the threaded display.
4771
4772       (if gnus-summary-display-while-building
4773           (switch-to-buffer (buffer-name)))
4774       (while (or threads stack gnus-tmp-new-adopts new-roots)
4775
4776         (if (and (= gnus-tmp-level 0)
4777                  (or (not stack)
4778                      (= (caar stack) 0))
4779                  (not gnus-tmp-false-parent)
4780                  (or gnus-tmp-new-adopts new-roots))
4781             (if gnus-tmp-new-adopts
4782                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4783                       thread (list (car gnus-tmp-new-adopts))
4784                       gnus-tmp-header (caar thread)
4785                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4786               (when new-roots
4787                 (setq thread (list (car new-roots))
4788                       gnus-tmp-header (caar thread)
4789                       new-roots (cdr new-roots))))
4790
4791           (if threads
4792               ;; If there are some threads, we do them before the
4793               ;; threads on the stack.
4794               (setq thread threads
4795                     gnus-tmp-header (caar thread))
4796             ;; There were no current threads, so we pop something off
4797             ;; the stack.
4798             (setq state (car stack)
4799                   gnus-tmp-level (car state)
4800                   tree-stack (cadr state)
4801                   thread (caddr state)
4802                   stack (cdr stack)
4803                   gnus-tmp-header (caar thread))))
4804
4805         (setq gnus-tmp-false-parent nil)
4806         (setq gnus-tmp-root-expunged nil)
4807         (setq thread-end nil)
4808
4809         (if (stringp gnus-tmp-header)
4810             ;; The header is a dummy root.
4811             (cond
4812              ((eq gnus-summary-make-false-root 'adopt)
4813               ;; We let the first article adopt the rest.
4814               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4815                                                (cddar thread)))
4816               (setq gnus-tmp-gathered
4817                     (nconc (mapcar
4818                             (lambda (h) (mail-header-number (car h)))
4819                             (cddar thread))
4820                            gnus-tmp-gathered))
4821               (setq thread (cons (list (caar thread)
4822                                        (cadar thread))
4823                                  (cdr thread)))
4824               (setq gnus-tmp-level -1
4825                     gnus-tmp-false-parent t))
4826              ((eq gnus-summary-make-false-root 'empty)
4827               ;; We print adopted articles with empty subject fields.
4828               (setq gnus-tmp-gathered
4829                     (nconc (mapcar
4830                             (lambda (h) (mail-header-number (car h)))
4831                             (cddar thread))
4832                            gnus-tmp-gathered))
4833               (setq gnus-tmp-level -1))
4834              ((eq gnus-summary-make-false-root 'dummy)
4835               ;; We remember that we probably want to output a dummy
4836               ;; root.
4837               (setq gnus-tmp-dummy-line gnus-tmp-header)
4838               (setq gnus-tmp-prev-subject gnus-tmp-header))
4839              (t
4840               ;; We do not make a root for the gathered
4841               ;; sub-threads at all.
4842               (setq gnus-tmp-level -1)))
4843
4844           (setq number (mail-header-number gnus-tmp-header)
4845                 subject (mail-header-subject gnus-tmp-header)
4846                 simp-subject (gnus-simplify-subject-fully subject))
4847
4848           (cond
4849            ;; If the thread has changed subject, we might want to make
4850            ;; this subthread into a root.
4851            ((and (null gnus-thread-ignore-subject)
4852                  (not (zerop gnus-tmp-level))
4853                  gnus-tmp-prev-subject
4854                  (not (string= gnus-tmp-prev-subject simp-subject)))
4855             (setq new-roots (nconc new-roots (list (car thread)))
4856                   thread-end t
4857                   gnus-tmp-header nil))
4858            ;; If the article lies outside the current limit,
4859            ;; then we do not display it.
4860            ((not (memq number gnus-newsgroup-limit))
4861             (setq gnus-tmp-gathered
4862                   (nconc (mapcar
4863                           (lambda (h) (mail-header-number (car h)))
4864                           (cdar thread))
4865                          gnus-tmp-gathered))
4866             (setq gnus-tmp-new-adopts (if (cdar thread)
4867                                           (append gnus-tmp-new-adopts
4868                                                   (cdar thread))
4869                                         gnus-tmp-new-adopts)
4870                   thread-end t
4871                   gnus-tmp-header nil)
4872             (when (zerop gnus-tmp-level)
4873               (setq gnus-tmp-root-expunged t)))
4874            ;; Perhaps this article is to be marked as read?
4875            ((and gnus-summary-mark-below
4876                  (< (or (cdr (assq number gnus-newsgroup-scored))
4877                         default-score)
4878                     gnus-summary-mark-below)
4879                  ;; Don't touch sparse articles.
4880                  (not (gnus-summary-article-sparse-p number))
4881                  (not (gnus-summary-article-ancient-p number)))
4882             (setq gnus-newsgroup-unreads
4883                   (delq number gnus-newsgroup-unreads))
4884             (if gnus-newsgroup-auto-expire
4885                 (setq gnus-newsgroup-expirable
4886                       (gnus-add-to-sorted-list
4887                        gnus-newsgroup-expirable number))
4888               (push (cons number gnus-low-score-mark)
4889                     gnus-newsgroup-reads))))
4890
4891           (when gnus-tmp-header
4892             ;; We may have an old dummy line to output before this
4893             ;; article.
4894             (when (and gnus-tmp-dummy-line
4895                        (gnus-subject-equal
4896                         gnus-tmp-dummy-line
4897                         (mail-header-subject gnus-tmp-header)))
4898               (gnus-summary-insert-dummy-line
4899                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4900               (setq gnus-tmp-dummy-line nil))
4901
4902             ;; Compute the mark.
4903             (setq gnus-tmp-unread (gnus-article-mark number))
4904
4905             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4906                                   gnus-tmp-header gnus-tmp-level)
4907                   gnus-newsgroup-data)
4908
4909             ;; Actually insert the line.
4910             (setq
4911              gnus-tmp-subject-or-nil
4912              (cond
4913               ((and gnus-thread-ignore-subject
4914                     gnus-tmp-prev-subject
4915                     (not (string= gnus-tmp-prev-subject simp-subject)))
4916                subject)
4917               ((zerop gnus-tmp-level)
4918                (if (and (eq gnus-summary-make-false-root 'empty)
4919                         (memq number gnus-tmp-gathered)
4920                         gnus-tmp-prev-subject
4921                         (string= gnus-tmp-prev-subject simp-subject))
4922                    gnus-summary-same-subject
4923                  subject))
4924               (t gnus-summary-same-subject)))
4925             (if (and (eq gnus-summary-make-false-root 'adopt)
4926                      (= gnus-tmp-level 1)
4927                      (memq number gnus-tmp-gathered))
4928                 (setq gnus-tmp-opening-bracket ?\<
4929                       gnus-tmp-closing-bracket ?\>)
4930               (setq gnus-tmp-opening-bracket ?\[
4931                     gnus-tmp-closing-bracket ?\]))
4932             (setq
4933              gnus-tmp-indentation
4934              (aref gnus-thread-indent-array gnus-tmp-level)
4935              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4936              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4937                                 gnus-summary-default-score 0)
4938              gnus-tmp-score-char
4939              (if (or (null gnus-summary-default-score)
4940                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4941                          gnus-summary-zcore-fuzz))
4942                  ?\ ;;;Whitespace
4943                (if (< gnus-tmp-score gnus-summary-default-score)
4944                    gnus-score-below-mark gnus-score-over-mark))
4945              gnus-tmp-replied
4946              (cond ((memq number gnus-newsgroup-processable)
4947                     gnus-process-mark)
4948                    ((memq number gnus-newsgroup-cached)
4949                     gnus-cached-mark)
4950                    ((memq number gnus-newsgroup-replied)
4951                     gnus-replied-mark)
4952                    ((memq number gnus-newsgroup-forwarded)
4953                     gnus-forwarded-mark)
4954                    ((memq number gnus-newsgroup-saved)
4955                     gnus-saved-mark)
4956                    ((memq number gnus-newsgroup-recent)
4957                     gnus-recent-mark)
4958                    ((memq number gnus-newsgroup-unseen)
4959                     gnus-unseen-mark)
4960                    (t gnus-no-mark))
4961              gnus-tmp-downloaded
4962              (cond ((memq number gnus-newsgroup-undownloaded)
4963                     gnus-undownloaded-mark)
4964                    (gnus-newsgroup-agentized
4965                     gnus-downloaded-mark)
4966                    (t
4967                     gnus-no-mark))
4968              gnus-tmp-from (mail-header-from gnus-tmp-header)
4969              gnus-tmp-name
4970              (cond
4971               ((string-match "<[^>]+> *$" gnus-tmp-from)
4972                (setq beg-match (match-beginning 0))
4973                (or (and (string-match "^\".+\"" gnus-tmp-from)
4974                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4975                    (substring gnus-tmp-from 0 beg-match)))
4976               ((string-match "(.+)" gnus-tmp-from)
4977                (substring gnus-tmp-from
4978                           (1+ (match-beginning 0)) (1- (match-end 0))))
4979               (t gnus-tmp-from))
4980
4981              ;; Do the %B string
4982              gnus-tmp-thread-tree-header-string
4983              (cond
4984               ((not gnus-show-threads) "")
4985               ((zerop gnus-tmp-level)
4986                (cond ((cdar thread)
4987                       (or gnus-sum-thread-tree-root subject))
4988                      (gnus-tmp-new-adopts
4989                       (or gnus-sum-thread-tree-false-root subject))
4990                      (t
4991                       (or gnus-sum-thread-tree-single-indent subject))))
4992               (t
4993                (concat (apply 'concat
4994                               (mapcar (lambda (item)
4995                                         (if (= item 1)
4996                                             gnus-sum-thread-tree-vertical
4997                                           gnus-sum-thread-tree-indent))
4998                                       (cdr (reverse tree-stack))))
4999                        (if (nth 1 thread)
5000                            gnus-sum-thread-tree-leaf-with-other
5001                          gnus-sum-thread-tree-single-leaf)))))
5002             (when (string= gnus-tmp-name "")
5003               (setq gnus-tmp-name gnus-tmp-from))
5004             (unless (numberp gnus-tmp-lines)
5005               (setq gnus-tmp-lines -1))
5006             (if (= gnus-tmp-lines -1)
5007                 (setq gnus-tmp-lines "?")
5008               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5009               (gnus-put-text-property
5010              (point)
5011              (progn (eval gnus-summary-line-format-spec) (point))
5012                'gnus-number number)
5013             (when gnus-visual-p
5014               (forward-line -1)
5015               (gnus-run-hooks 'gnus-summary-update-hook)
5016               (forward-line 1))
5017
5018             (setq gnus-tmp-prev-subject simp-subject)))
5019
5020         (when (nth 1 thread)
5021           (push (list (max 0 gnus-tmp-level)
5022                       (copy-sequence tree-stack)
5023                       (nthcdr 1 thread))
5024                 stack))
5025         (push (if (nth 1 thread) 1 0) tree-stack)
5026         (incf gnus-tmp-level)
5027         (setq threads (if thread-end nil (cdar thread)))
5028         (if gnus-summary-display-while-building
5029             (if building-count
5030                 (progn
5031                   ;; use a set frequency
5032                   (setq building-line-count (1- building-line-count))
5033                   (when (= building-line-count 0)
5034                     (sit-for 0)
5035                     (setq building-line-count
5036                           gnus-summary-display-while-building)))
5037               ;; always
5038               (sit-for 0)))
5039         (unless threads
5040           (setq gnus-tmp-level 0)))))
5041   (gnus-message 7 "Generating summary...done"))
5042
5043 (defun gnus-summary-prepare-unthreaded (headers)
5044   "Generate an unthreaded summary buffer based on HEADERS."
5045   (let (header number mark)
5046
5047     (beginning-of-line)
5048
5049     (while headers
5050       ;; We may have to root out some bad articles...
5051       (when (memq (setq number (mail-header-number
5052                                 (setq header (pop headers))))
5053                   gnus-newsgroup-limit)
5054         ;; Mark article as read when it has a low score.
5055         (when (and gnus-summary-mark-below
5056                    (< (or (cdr (assq number gnus-newsgroup-scored))
5057                           gnus-summary-default-score 0)
5058                       gnus-summary-mark-below)
5059                    (not (gnus-summary-article-ancient-p number)))
5060           (setq gnus-newsgroup-unreads
5061                 (delq number gnus-newsgroup-unreads))
5062           (if gnus-newsgroup-auto-expire
5063               (push number gnus-newsgroup-expirable)
5064             (push (cons number gnus-low-score-mark)
5065                   gnus-newsgroup-reads)))
5066
5067         (setq mark (gnus-article-mark number))
5068         (push (gnus-data-make number mark (1+ (point)) header 0)
5069               gnus-newsgroup-data)
5070         (gnus-summary-insert-line
5071          header 0 number
5072          (memq number gnus-newsgroup-undownloaded)
5073          mark (memq number gnus-newsgroup-replied)
5074          (memq number gnus-newsgroup-expirable)
5075          (mail-header-subject header) nil
5076          (cdr (assq number gnus-newsgroup-scored))
5077          (memq number gnus-newsgroup-processable))))))
5078
5079 (defun gnus-summary-remove-list-identifiers ()
5080   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5081   (let ((regexp (if (consp gnus-list-identifiers)
5082                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5083                   gnus-list-identifiers))
5084         changed subject)
5085     (when regexp
5086       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5087       (dolist (header gnus-newsgroup-headers)
5088         (setq subject (mail-header-subject header)
5089               changed nil)
5090         (while (string-match regexp subject)
5091           (setq subject
5092                 (concat (substring subject 0 (match-beginning 1))
5093                         (substring subject (match-end 0)))
5094                 changed t))
5095         (when changed
5096           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5097             (setq subject
5098                   (concat (substring subject 0 (match-beginning 1))
5099                           (substring subject (match-end 1)))))
5100           (mail-header-set-subject header subject))))))
5101
5102 (defun gnus-fetch-headers (articles)
5103   "Fetch headers of ARTICLES."
5104   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5105     (gnus-message 5 "Fetching headers for %s..." name)
5106     (prog1
5107         (if (eq 'nov
5108                 (setq gnus-headers-retrieved-by
5109                       (gnus-retrieve-headers
5110                        articles gnus-newsgroup-name
5111                        ;; We might want to fetch old headers, but
5112                        ;; not if there is only 1 article.
5113                        (and (or (and
5114                                  (not (eq gnus-fetch-old-headers 'some))
5115                                  (not (numberp gnus-fetch-old-headers)))
5116                                 (> (length articles) 1))
5117                             gnus-fetch-old-headers))))
5118             (gnus-get-newsgroup-headers-xover
5119              articles nil nil gnus-newsgroup-name t)
5120           (gnus-get-newsgroup-headers))
5121       (gnus-message 5 "Fetching headers for %s...done" name))))
5122
5123 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5124   "Select newsgroup GROUP.
5125 If READ-ALL is non-nil, all articles in the group are selected.
5126 If SELECT-ARTICLES, only select those articles from GROUP."
5127   (let* ((entry (gnus-group-entry group))
5128          ;;!!! Dirty hack; should be removed.
5129          (gnus-summary-ignore-duplicates
5130           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5131               t
5132             gnus-summary-ignore-duplicates))
5133          (info (nth 2 entry))
5134          articles fetched-articles cached)
5135
5136     (unless (gnus-check-server
5137              (set (make-local-variable 'gnus-current-select-method)
5138                   (gnus-find-method-for-group group)))
5139       (error "Couldn't open server"))
5140
5141     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5142         (gnus-activate-group group)     ; Or we can activate it...
5143         (progn                          ; Or we bug out.
5144           (when (equal major-mode 'gnus-summary-mode)
5145             (gnus-kill-buffer (current-buffer)))
5146           (error "Couldn't activate group %s: %s"
5147                  group (gnus-status-message group))))
5148
5149     (unless (gnus-request-group group t)
5150       (when (equal major-mode 'gnus-summary-mode)
5151         (gnus-kill-buffer (current-buffer)))
5152       (error "Couldn't request group %s: %s"
5153              group (gnus-status-message group)))
5154
5155     (when gnus-agent
5156       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5157       
5158       (setq gnus-summary-use-undownloaded-faces
5159             (gnus-agent-find-parameter
5160              group
5161              'agent-enable-undownloaded-faces)))
5162
5163     (setq gnus-newsgroup-name group
5164           gnus-newsgroup-unselected nil
5165           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5166
5167     (let ((display (gnus-group-find-parameter group 'display)))
5168       (setq gnus-newsgroup-display
5169             (cond
5170              ((not (zerop (or (car-safe read-all) 0)))
5171               ;; The user entered the group with C-u SPC/RET, let's show
5172               ;; all articles.
5173               'gnus-not-ignore)
5174              ((eq display 'all)
5175               'gnus-not-ignore)
5176              ((arrayp display)
5177               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5178              ((numberp display)
5179               ;; The following is probably the "correct" solution, but
5180               ;; it makes Gnus fetch all headers and then limit the
5181               ;; articles (which is slow), so instead we hack the
5182               ;; select-articles parameter instead. -- Simon Josefsson
5183               ;; <jas@kth.se>
5184               ;;
5185               ;; (gnus-byte-compile
5186               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5187               ;;                         display)))))
5188               (setq select-articles
5189                     (gnus-uncompress-range
5190                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5191                              (if (> tmp 0)
5192                                  tmp
5193                                1))
5194                            (cdr (gnus-active group)))))
5195               nil)
5196              (t
5197               nil))))
5198
5199     (gnus-summary-setup-default-charset)
5200
5201     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5202     (when (gnus-virtual-group-p group)
5203       (setq cached gnus-newsgroup-cached))
5204
5205     (setq gnus-newsgroup-unreads
5206           (gnus-sorted-ndifference
5207            (gnus-sorted-ndifference gnus-newsgroup-unreads
5208                                     gnus-newsgroup-marked)
5209            gnus-newsgroup-dormant))
5210
5211     (setq gnus-newsgroup-processable nil)
5212
5213     (gnus-update-read-articles group gnus-newsgroup-unreads)
5214
5215     ;; Adjust and set lists of article marks.
5216     (when info
5217       (gnus-adjust-marked-articles info))
5218     (if (setq articles select-articles)
5219         (setq gnus-newsgroup-unselected
5220               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5221       (setq articles (gnus-articles-to-read group read-all)))
5222
5223     (cond
5224      ((null articles)
5225       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5226       'quit)
5227      ((eq articles 0) nil)
5228      (t
5229       ;; Init the dependencies hash table.
5230       (setq gnus-newsgroup-dependencies
5231             (gnus-make-hashtable (length articles)))
5232       (gnus-set-global-variables)
5233       ;; Retrieve the headers and read them in.
5234
5235       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5236
5237       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5238       (when cached
5239         (setq gnus-newsgroup-cached cached))
5240
5241       ;; Suppress duplicates?
5242       (when gnus-suppress-duplicates
5243         (gnus-dup-suppress-articles))
5244
5245       ;; Set the initial limit.
5246       (setq gnus-newsgroup-limit (copy-sequence articles))
5247       ;; Remove canceled articles from the list of unread articles.
5248       (setq fetched-articles
5249             (mapcar (lambda (headers) (mail-header-number headers))
5250                     gnus-newsgroup-headers))
5251       (setq gnus-newsgroup-articles fetched-articles)
5252       (setq gnus-newsgroup-unreads
5253             (gnus-sorted-nintersection
5254              gnus-newsgroup-unreads fetched-articles))
5255       (gnus-compute-unseen-list)
5256
5257       ;; Removed marked articles that do not exist.
5258       (gnus-update-missing-marks
5259        (gnus-sorted-difference articles fetched-articles))
5260       ;; We might want to build some more threads first.
5261       (when (and gnus-fetch-old-headers
5262                  (eq gnus-headers-retrieved-by 'nov))
5263         (if (eq gnus-fetch-old-headers 'invisible)
5264             (gnus-build-all-threads)
5265           (gnus-build-old-threads)))
5266       ;; Let the Gnus agent mark articles as read.
5267       (when gnus-agent
5268         (gnus-agent-get-undownloaded-list))
5269       ;; Remove list identifiers from subject
5270       (when gnus-list-identifiers
5271         (gnus-summary-remove-list-identifiers))
5272       ;; Check whether auto-expire is to be done in this group.
5273       (setq gnus-newsgroup-auto-expire
5274             (gnus-group-auto-expirable-p group))
5275       ;; Set up the article buffer now, if necessary.
5276       (unless gnus-single-article-buffer
5277         (gnus-article-setup-buffer))
5278       ;; First and last article in this newsgroup.
5279       (when gnus-newsgroup-headers
5280         (setq gnus-newsgroup-begin
5281               (mail-header-number (car gnus-newsgroup-headers))
5282               gnus-newsgroup-end
5283               (mail-header-number
5284                (gnus-last-element gnus-newsgroup-headers))))
5285       ;; GROUP is successfully selected.
5286       (or gnus-newsgroup-headers t)))))
5287
5288 (defun gnus-compute-unseen-list ()
5289   ;; The `seen' marks are treated specially.
5290   (if (not gnus-newsgroup-seen)
5291       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5292     (setq gnus-newsgroup-unseen
5293           (gnus-inverse-list-range-intersection
5294            gnus-newsgroup-articles gnus-newsgroup-seen))))
5295
5296 (defun gnus-summary-display-make-predicate (display)
5297   (require 'gnus-agent)
5298   (when (= (length display) 1)
5299     (setq display (car display)))
5300   (unless gnus-summary-display-cache
5301     (dolist (elem (append '((unread . unread)
5302                             (read . read)
5303                             (unseen . unseen))
5304                           gnus-article-mark-lists))
5305       (push (cons (cdr elem)
5306                   (gnus-byte-compile
5307                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5308             gnus-summary-display-cache)))
5309   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5310         (gnus-category-predicate-cache gnus-summary-display-cache))
5311     (gnus-get-predicate display)))
5312
5313 ;; Uses the dynamically bound `number' variable.
5314 (eval-when-compile
5315   (defvar number))
5316 (defun gnus-article-marked-p (type &optional article)
5317   (let ((article (or article number)))
5318     (cond
5319      ((eq type 'tick)
5320       (memq article gnus-newsgroup-marked))
5321      ((eq type 'spam)
5322       (memq article gnus-newsgroup-spam-marked))
5323      ((eq type 'unsend)
5324       (memq article gnus-newsgroup-unsendable))
5325      ((eq type 'undownload)
5326       (memq article gnus-newsgroup-undownloaded))
5327      ((eq type 'download)
5328       (memq article gnus-newsgroup-downloadable))
5329      ((eq type 'unread)
5330       (memq article gnus-newsgroup-unreads))
5331      ((eq type 'read)
5332       (memq article gnus-newsgroup-reads))
5333      ((eq type 'dormant)
5334       (memq article gnus-newsgroup-dormant) )
5335      ((eq type 'expire)
5336       (memq article gnus-newsgroup-expirable))
5337      ((eq type 'reply)
5338       (memq article gnus-newsgroup-replied))
5339      ((eq type 'killed)
5340       (memq article gnus-newsgroup-killed))
5341      ((eq type 'bookmark)
5342       (assq article gnus-newsgroup-bookmarks))
5343      ((eq type 'score)
5344       (assq article gnus-newsgroup-scored))
5345      ((eq type 'save)
5346       (memq article gnus-newsgroup-saved))
5347      ((eq type 'cache)
5348       (memq article gnus-newsgroup-cached))
5349      ((eq type 'forward)
5350       (memq article gnus-newsgroup-forwarded))
5351      ((eq type 'seen)
5352       (not (memq article gnus-newsgroup-unseen)))
5353      ((eq type 'recent)
5354       (memq article gnus-newsgroup-recent))
5355      (t t))))
5356
5357 (defun gnus-articles-to-read (group &optional read-all)
5358   "Find out what articles the user wants to read."
5359   (let* ((articles
5360           ;; Select all articles if `read-all' is non-nil, or if there
5361           ;; are no unread articles.
5362           (if (or read-all
5363                   (and (zerop (length gnus-newsgroup-marked))
5364                        (zerop (length gnus-newsgroup-unreads)))
5365                   ;; Fetch all if the predicate is non-nil.
5366                   gnus-newsgroup-display)
5367               ;; We want to select the headers for all the articles in
5368               ;; the group, so we select either all the active
5369               ;; articles in the group, or (if that's nil), the
5370               ;; articles in the cache.
5371               (or
5372                (gnus-uncompress-range (gnus-active group))
5373                (gnus-cache-articles-in-group group))
5374             ;; Select only the "normal" subset of articles.
5375             (gnus-sorted-nunion
5376              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5377              gnus-newsgroup-unreads)))
5378          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5379          (scored (length scored-list))
5380          (number (length articles))
5381          (marked (+ (length gnus-newsgroup-marked)
5382                     (length gnus-newsgroup-dormant)))
5383          (select
5384           (cond
5385            ((numberp read-all)
5386             read-all)
5387            ((numberp gnus-newsgroup-display)
5388             gnus-newsgroup-display)
5389            (t
5390             (condition-case ()
5391                 (cond
5392                  ((and (or (<= scored marked) (= scored number))
5393                        (numberp gnus-large-newsgroup)
5394                        (> number gnus-large-newsgroup))
5395                   (let* ((cursor-in-echo-area nil)
5396                          (initial (gnus-parameter-large-newsgroup-initial
5397                                    gnus-newsgroup-name))
5398                          (input
5399                           (read-string
5400                            (format
5401                             "How many articles from %s (%s %d): "
5402                             (gnus-limit-string
5403                              (gnus-group-decoded-name gnus-newsgroup-name)
5404                              35)
5405                             (if initial "max" "default")
5406                             number)
5407                            (if initial
5408                                (cons (number-to-string initial)
5409                                      0)))))
5410                     (if (string-match "^[ \t]*$" input) number input)))
5411                  ((and (> scored marked) (< scored number)
5412                        (> (- scored number) 20))
5413                   (let ((input
5414                          (read-string
5415                           (format "%s %s (%d scored, %d total): "
5416                                   "How many articles from"
5417                                   (gnus-group-decoded-name group)
5418                                   scored number))))
5419                     (if (string-match "^[ \t]*$" input)
5420                         number input)))
5421                  (t number))
5422               (quit
5423                (message "Quit getting the articles to read")
5424                nil))))))
5425     (setq select (if (stringp select) (string-to-number select) select))
5426     (if (or (null select) (zerop select))
5427         select
5428       (if (and (not (zerop scored)) (<= (abs select) scored))
5429           (progn
5430             (setq articles (sort scored-list '<))
5431             (setq number (length articles)))
5432         (setq articles (copy-sequence articles)))
5433
5434       (when (< (abs select) number)
5435         (if (< select 0)
5436             ;; Select the N oldest articles.
5437             (setcdr (nthcdr (1- (abs select)) articles) nil)
5438           ;; Select the N most recent articles.
5439           (setq articles (nthcdr (- number select) articles))))
5440       (setq gnus-newsgroup-unselected
5441             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5442       (when gnus-alter-articles-to-read-function
5443         (setq articles
5444               (sort
5445                (funcall gnus-alter-articles-to-read-function
5446                         gnus-newsgroup-name articles)
5447                '<)))
5448       articles)))
5449
5450 (defun gnus-killed-articles (killed articles)
5451   (let (out)
5452     (while articles
5453       (when (inline (gnus-member-of-range (car articles) killed))
5454         (push (car articles) out))
5455       (setq articles (cdr articles)))
5456     out))
5457
5458 (defun gnus-uncompress-marks (marks)
5459   "Uncompress the mark ranges in MARKS."
5460   (let ((uncompressed '(score bookmark))
5461         out)
5462     (while marks
5463       (if (memq (caar marks) uncompressed)
5464           (push (car marks) out)
5465         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5466       (setq marks (cdr marks)))
5467     out))
5468
5469 (defun gnus-article-mark-to-type (mark)
5470   "Return the type of MARK."
5471   (or (cadr (assq mark gnus-article-special-mark-lists))
5472       'list))
5473
5474 (defun gnus-article-unpropagatable-p (mark)
5475   "Return whether MARK should be propagated to back end."
5476   (memq mark gnus-article-unpropagated-mark-lists))
5477
5478 (defun gnus-adjust-marked-articles (info)
5479   "Set all article lists and remove all marks that are no longer valid."
5480   (let* ((marked-lists (gnus-info-marks info))
5481          (active (gnus-active (gnus-info-group info)))
5482          (min (car active))
5483          (max (cdr active))
5484          (types gnus-article-mark-lists)
5485          marks var articles article mark mark-type
5486          bgn end)
5487
5488     (dolist (marks marked-lists)
5489       (setq mark (car marks)
5490             mark-type (gnus-article-mark-to-type mark)
5491             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5492
5493       ;; We set the variable according to the type of the marks list,
5494       ;; and then adjust the marks to a subset of the active articles.
5495       (cond
5496        ;; Adjust "simple" lists - compressed yet unsorted
5497        ((eq mark-type 'list)
5498         ;; Simultaneously uncompress and clip to active range
5499         ;; See gnus-uncompress-range for a description of possible marks
5500         (let (l lh)
5501           (if (not (cadr marks))
5502               (set var nil)
5503             (setq articles (if (numberp (cddr marks))
5504                                (list (cdr marks))
5505                              (cdr marks))
5506                   lh (cons nil nil)
5507                   l lh)
5508
5509             (while (setq article (pop articles))
5510               (cond ((consp article)
5511                      (setq bgn (max (car article) min)
5512                            end (min (cdr article) max))
5513                      (while (<= bgn end)
5514                        (setq l (setcdr l (cons bgn nil))
5515                              bgn (1+ bgn))))
5516                     ((and (<= min article)
5517                           (>= max article))
5518                      (setq l (setcdr l (cons article nil))))))
5519             (set var (cdr lh)))))
5520        ;; Adjust assocs.
5521        ((eq mark-type 'tuple)
5522         (set var (setq articles (cdr marks)))
5523         (when (not (listp (cdr (symbol-value var))))
5524           (set var (list (symbol-value var))))
5525         (when (not (listp (cdr articles)))
5526           (setq articles (list articles)))
5527         (while articles
5528           (when (or (not (consp (setq article (pop articles))))
5529                     (< (car article) min)
5530                     (> (car article) max))
5531             (set var (delq article (symbol-value var))))))
5532        ;; Adjust ranges (sloppily).
5533        ((eq mark-type 'range)
5534         (cond
5535          ((eq mark 'seen)
5536           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5537           ;; It should be (seen (NUM1 . NUM2)).
5538           (when (numberp (cddr marks))
5539             (setcdr marks (list (cdr marks))))
5540           (setq articles (cdr marks))
5541           (while (and articles
5542                       (or (and (consp (car articles))
5543                                (> min (cdar articles)))
5544                           (and (numberp (car articles))
5545                                (> min (car articles)))))
5546             (pop articles))
5547           (set var articles))))))))
5548
5549 (defun gnus-update-missing-marks (missing)
5550   "Go through the list of MISSING articles and remove them from the mark lists."
5551   (when missing
5552     (let (var m)
5553       ;; Go through all types.
5554       (dolist (elem gnus-article-mark-lists)
5555         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5556           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5557           (when (symbol-value var)
5558             ;; This list has articles.  So we delete all missing
5559             ;; articles from it.
5560             (setq m missing)
5561             (while m
5562               (set var (delq (pop m) (symbol-value var))))))))))
5563
5564 (defun gnus-update-marks ()
5565   "Enter the various lists of marked articles into the newsgroup info list."
5566   (let ((types gnus-article-mark-lists)
5567         (info (gnus-get-info gnus-newsgroup-name))
5568         type list newmarked symbol delta-marks)
5569     (when info
5570       ;; Add all marks lists to the list of marks lists.
5571       (while (setq type (pop types))
5572         (setq list (symbol-value
5573                     (setq symbol
5574                           (intern (format "gnus-newsgroup-%s" (car type))))))
5575
5576         (when list
5577           ;; Get rid of the entries of the articles that have the
5578           ;; default score.
5579           (when (and (eq (cdr type) 'score)
5580                      gnus-save-score
5581                      list)
5582             (let* ((arts list)
5583                    (prev (cons nil list))
5584                    (all prev))
5585               (while arts
5586                 (if (or (not (consp (car arts)))
5587                         (= (cdar arts) gnus-summary-default-score))
5588                     (setcdr prev (cdr arts))
5589                   (setq prev arts))
5590                 (setq arts (cdr arts)))
5591               (setq list (cdr all)))))
5592
5593         (when (eq (cdr type) 'seen)
5594           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5595
5596         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5597           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5598
5599         (when (and (gnus-check-backend-function
5600                     'request-set-mark gnus-newsgroup-name)
5601                    (not (gnus-article-unpropagatable-p (cdr type))))
5602           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5603                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5604                  (add (gnus-remove-from-range
5605                        (gnus-copy-sequence list) old)))
5606             (when add
5607               (push (list add 'add (list (cdr type))) delta-marks))
5608             (when del
5609               (push (list del 'del (list (cdr type))) delta-marks))))
5610
5611         (when list
5612           (push (cons (cdr type) list) newmarked)))
5613
5614       (when delta-marks
5615         (unless (gnus-check-group gnus-newsgroup-name)
5616           (error "Can't open server for %s" gnus-newsgroup-name))
5617         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5618
5619       ;; Enter these new marks into the info of the group.
5620       (if (nthcdr 3 info)
5621           (setcar (nthcdr 3 info) newmarked)
5622         ;; Add the marks lists to the end of the info.
5623         (when newmarked
5624           (setcdr (nthcdr 2 info) (list newmarked))))
5625
5626       ;; Cut off the end of the info if there's nothing else there.
5627       (let ((i 5))
5628         (while (and (> i 2)
5629                     (not (nth i info)))
5630           (when (nthcdr (decf i) info)
5631             (setcdr (nthcdr i info) nil)))))))
5632
5633 (defun gnus-set-mode-line (where)
5634   "Set the mode line of the article or summary buffers.
5635 If WHERE is `summary', the summary mode line format will be used."
5636   ;; Is this mode line one we keep updated?
5637   (when (and (memq where gnus-updated-mode-lines)
5638              (symbol-value
5639               (intern (format "gnus-%s-mode-line-format-spec" where))))
5640     (let (mode-string)
5641       (save-excursion
5642         ;; We evaluate this in the summary buffer since these
5643         ;; variables are buffer-local to that buffer.
5644         (set-buffer gnus-summary-buffer)
5645         ;; We bind all these variables that are used in the `eval' form
5646         ;; below.
5647         (let* ((mformat (symbol-value
5648                          (intern
5649                           (format "gnus-%s-mode-line-format-spec" where))))
5650                (gnus-tmp-group-name (gnus-group-decoded-name
5651                                      gnus-newsgroup-name))
5652                (gnus-tmp-article-number (or gnus-current-article 0))
5653                (gnus-tmp-unread gnus-newsgroup-unreads)
5654                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5655                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5656                (gnus-tmp-unread-and-unselected
5657                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5658                             (zerop gnus-tmp-unselected))
5659                        "")
5660                       ((zerop gnus-tmp-unselected)
5661                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5662                       (t (format "{%d(+%d) more}"
5663                                  gnus-tmp-unread-and-unticked
5664                                  gnus-tmp-unselected))))
5665                (gnus-tmp-subject
5666                 (if (and gnus-current-headers
5667                          (vectorp gnus-current-headers))
5668                     (gnus-mode-string-quote
5669                      (mail-header-subject gnus-current-headers))
5670                   ""))
5671                bufname-length max-len
5672                gnus-tmp-header);; passed as argument to any user-format-funcs
5673           (setq mode-string (eval mformat))
5674           (setq bufname-length (if (string-match "%b" mode-string)
5675                                    (- (length
5676                                        (buffer-name
5677                                         (if (eq where 'summary)
5678                                             nil
5679                                           (get-buffer gnus-article-buffer))))
5680                                       2)
5681                                  0))
5682           (setq max-len (max 4 (if gnus-mode-non-string-length
5683                                    (- (window-width)
5684                                       gnus-mode-non-string-length
5685                                       bufname-length)
5686                                  (length mode-string))))
5687           ;; We might have to chop a bit of the string off...
5688           (when (> (length mode-string) max-len)
5689             (setq mode-string
5690                   (concat (gnus-truncate-string mode-string (- max-len 3))
5691                           "...")))
5692           ;; Pad the mode string a bit.
5693           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5694       ;; Update the mode line.
5695       (setq mode-line-buffer-identification
5696             (gnus-mode-line-buffer-identification (list mode-string)))
5697       (set-buffer-modified-p t))))
5698
5699 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5700   "Go through the HEADERS list and add all Xrefs to a hash table.
5701 The resulting hash table is returned, or nil if no Xrefs were found."
5702   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5703          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5704          (xref-hashtb (gnus-make-hashtable))
5705          start group entry number xrefs header)
5706     (while headers
5707       (setq header (pop headers))
5708       (when (and (setq xrefs (mail-header-xref header))
5709                  (not (memq (setq number (mail-header-number header))
5710                             unreads)))
5711         (setq start 0)
5712         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5713           (setq start (match-end 0))
5714           (setq group (if prefix
5715                           (concat prefix (substring xrefs (match-beginning 1)
5716                                                     (match-end 1)))
5717                         (substring xrefs (match-beginning 1) (match-end 1))))
5718           (setq number
5719                 (string-to-int (substring xrefs (match-beginning 2)
5720                                           (match-end 2))))
5721           (if (setq entry (gnus-gethash group xref-hashtb))
5722               (setcdr entry (cons number (cdr entry)))
5723             (gnus-sethash group (cons number nil) xref-hashtb)))))
5724     (and start xref-hashtb)))
5725
5726 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5727   "Look through all the headers and mark the Xrefs as read."
5728   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5729         name info xref-hashtb idlist method nth4)
5730     (save-excursion
5731       (set-buffer gnus-group-buffer)
5732       (when (setq xref-hashtb
5733                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5734         (mapatoms
5735          (lambda (group)
5736            (unless (string= from-newsgroup (setq name (symbol-name group)))
5737              (setq idlist (symbol-value group))
5738              ;; Dead groups are not updated.
5739              (and (prog1
5740                       (setq info (gnus-get-info name))
5741                     (when (stringp (setq nth4 (gnus-info-method info)))
5742                       (setq nth4 (gnus-server-to-method nth4))))
5743                   ;; Only do the xrefs if the group has the same
5744                   ;; select method as the group we have just read.
5745                   (or (gnus-methods-equal-p
5746                        nth4 (gnus-find-method-for-group from-newsgroup))
5747                       virtual
5748                       (equal nth4 (setq method (gnus-find-method-for-group
5749                                                 from-newsgroup)))
5750                       (and (equal (car nth4) (car method))
5751                            (equal (nth 1 nth4) (nth 1 method))))
5752                   gnus-use-cross-reference
5753                   (or (not (eq gnus-use-cross-reference t))
5754                       virtual
5755                       ;; Only do cross-references on subscribed
5756                       ;; groups, if that is what is wanted.
5757                       (<= (gnus-info-level info) gnus-level-subscribed))
5758                   (gnus-group-make-articles-read name idlist))))
5759          xref-hashtb)))))
5760
5761 (defun gnus-compute-read-articles (group articles)
5762   (let* ((entry (gnus-group-entry group))
5763          (info (nth 2 entry))
5764          (active (gnus-active group))
5765          ninfo)
5766     (when entry
5767       ;; First peel off all invalid article numbers.
5768       (when active
5769         (let ((ids articles)
5770               id first)
5771           (while (setq id (pop ids))
5772             (when (and first (> id (cdr active)))
5773               ;; We'll end up in this situation in one particular
5774               ;; obscure situation.  If you re-scan a group and get
5775               ;; a new article that is cross-posted to a different
5776               ;; group that has not been re-scanned, you might get
5777               ;; crossposted article that has a higher number than
5778               ;; Gnus believes possible.  So we re-activate this
5779               ;; group as well.  This might mean doing the
5780               ;; crossposting thingy will *increase* the number
5781               ;; of articles in some groups.  Tsk, tsk.
5782               (setq active (or (gnus-activate-group group) active)))
5783             (when (or (> id (cdr active))
5784                       (< id (car active)))
5785               (setq articles (delq id articles))))))
5786       ;; If the read list is nil, we init it.
5787       (if (and active
5788                (null (gnus-info-read info))
5789                (> (car active) 1))
5790           (setq ninfo (cons 1 (1- (car active))))
5791         (setq ninfo (gnus-info-read info)))
5792       ;; Then we add the read articles to the range.
5793       (gnus-add-to-range
5794        ninfo (setq articles (sort articles '<))))))
5795
5796 (defun gnus-group-make-articles-read (group articles)
5797   "Update the info of GROUP to say that ARTICLES are read."
5798   (let* ((num 0)
5799          (entry (gnus-group-entry group))
5800          (info (nth 2 entry))
5801          (active (gnus-active group))
5802          range)
5803     (when entry
5804       (setq range (gnus-compute-read-articles group articles))
5805       (with-current-buffer gnus-group-buffer
5806         (gnus-undo-register
5807           `(progn
5808              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5809              (gnus-info-set-read ',info ',(gnus-info-read info))
5810              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5811              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5812              (gnus-group-update-group ,group t))))
5813       ;; Add the read articles to the range.
5814       (gnus-info-set-read info range)
5815       (gnus-request-set-mark group (list (list range 'add '(read))))
5816       ;; Then we have to re-compute how many unread
5817       ;; articles there are in this group.
5818       (when active
5819         (cond
5820          ((not range)
5821           (setq num (- (1+ (cdr active)) (car active))))
5822          ((not (listp (cdr range)))
5823           (setq num (- (cdr active) (- (1+ (cdr range))
5824                                        (car range)))))
5825          (t
5826           (while range
5827             (if (numberp (car range))
5828                 (setq num (1+ num))
5829               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5830             (setq range (cdr range)))
5831           (setq num (- (cdr active) num))))
5832         ;; Update the number of unread articles.
5833         (setcar entry num)
5834         ;; Update the group buffer.
5835         (unless (gnus-ephemeral-group-p group)
5836           (gnus-group-update-group group t))))))
5837
5838 (defvar gnus-newsgroup-none-id 0)
5839
5840 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5841   (let ((cur nntp-server-buffer)
5842         (dependencies
5843          (or dependencies
5844              (with-current-buffer gnus-summary-buffer
5845                gnus-newsgroup-dependencies)))
5846         headers id end ref number
5847         (mail-parse-charset gnus-newsgroup-charset)
5848         (mail-parse-ignored-charsets
5849          (save-excursion (condition-case nil
5850                              (set-buffer gnus-summary-buffer)
5851                            (error))
5852                          gnus-newsgroup-ignored-charsets)))
5853     (save-excursion
5854       (set-buffer nntp-server-buffer)
5855       ;; Translate all TAB characters into SPACE characters.
5856       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5857       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5858       (ietf-drums-unfold-fws)
5859       (gnus-run-hooks 'gnus-parse-headers-hook)
5860       (let ((case-fold-search t)
5861             in-reply-to header p lines chars ctype)
5862         (goto-char (point-min))
5863         ;; Search to the beginning of the next header.  Error messages
5864         ;; do not begin with 2 or 3.
5865         (while (re-search-forward "^[23][0-9]+ " nil t)
5866           (setq id nil
5867                 ref nil)
5868           ;; This implementation of this function, with nine
5869           ;; search-forwards instead of the one re-search-forward and
5870           ;; a case (which basically was the old function) is actually
5871           ;; about twice as fast, even though it looks messier.  You
5872           ;; can't have everything, I guess.  Speed and elegance
5873           ;; doesn't always go hand in hand.
5874           (setq
5875            header
5876            (make-full-mail-header
5877             ;; Number.
5878             (prog1
5879                 (setq number (read cur))
5880               (end-of-line)
5881               (setq p (point))
5882               (narrow-to-region (point)
5883                                 (or (and (search-forward "\n.\n" nil t)
5884                                          (- (point) 2))
5885                                     (point))))
5886             ;; Subject.
5887             (progn
5888               (goto-char p)
5889               (if (search-forward "\nsubject:" nil t)
5890                   (nnheader-header-value)
5891                 "(none)"))
5892             ;; From.
5893             (progn
5894               (goto-char p)
5895               (if (search-forward "\nfrom:" nil t)
5896                   (nnheader-header-value)
5897                 "(nobody)"))
5898             ;; Date.
5899             (progn
5900               (goto-char p)
5901               (if (search-forward "\ndate:" nil t)
5902                   (nnheader-header-value) ""))
5903             ;; Message-ID.
5904             (progn
5905               (goto-char p)
5906               (setq id (if (re-search-forward
5907                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5908                            ;; We do it this way to make sure the Message-ID
5909                            ;; is (somewhat) syntactically valid.
5910                            (buffer-substring (match-beginning 1)
5911                                              (match-end 1))
5912                          ;; If there was no message-id, we just fake one
5913                          ;; to make subsequent routines simpler.
5914                          (nnheader-generate-fake-message-id number))))
5915             ;; References.
5916             (progn
5917               (goto-char p)
5918               (if (search-forward "\nreferences:" nil t)
5919                   (progn
5920                     (setq end (point))
5921                     (prog1
5922                         (nnheader-header-value)
5923                       (setq ref
5924                             (buffer-substring
5925                              (progn
5926                                ;; (end-of-line)
5927                                (search-backward ">" end t)
5928                                (1+ (point)))
5929                              (progn
5930                                (search-backward "<" end t)
5931                                (point))))))
5932                 ;; Get the references from the in-reply-to header if there
5933                 ;; were no references and the in-reply-to header looks
5934                 ;; promising.
5935                 (if (and (search-forward "\nin-reply-to:" nil t)
5936                          (setq in-reply-to (nnheader-header-value))
5937                          (string-match "<[^>]+>" in-reply-to))
5938                     (let (ref2)
5939                       (setq ref (substring in-reply-to (match-beginning 0)
5940                                            (match-end 0)))
5941                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5942                         (setq ref2 (substring in-reply-to (match-beginning 0)
5943                                               (match-end 0)))
5944                         (when (> (length ref2) (length ref))
5945                           (setq ref ref2)))
5946                       ref)
5947                   (setq ref nil))))
5948             ;; Chars.
5949             (progn
5950               (goto-char p)
5951               (if (search-forward "\nchars: " nil t)
5952                   (if (numberp (setq chars (ignore-errors (read cur))))
5953                       chars -1)
5954                 -1))
5955             ;; Lines.
5956             (progn
5957               (goto-char p)
5958               (if (search-forward "\nlines: " nil t)
5959                   (if (numberp (setq lines (ignore-errors (read cur))))
5960                       lines -1)
5961                 -1))
5962             ;; Xref.
5963             (progn
5964               (goto-char p)
5965               (and (search-forward "\nxref:" nil t)
5966                    (nnheader-header-value)))
5967             ;; Extra.
5968             (when gnus-extra-headers
5969               (let ((extra gnus-extra-headers)
5970                     out)
5971                 (while extra
5972                   (goto-char p)
5973                   (when (search-forward
5974                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5975                     (push (cons (car extra) (nnheader-header-value)) out))
5976                   (pop extra))
5977                 out))))
5978           (goto-char p)
5979           (if (and (search-forward "\ncontent-type: " nil t)
5980                    (setq ctype (nnheader-header-value)))
5981               (mime-entity-set-content-type-internal
5982                header (mime-parse-Content-Type ctype)))
5983           (when (equal id ref)
5984             (setq ref nil))
5985
5986           (when gnus-alter-header-function
5987             (funcall gnus-alter-header-function header)
5988             (setq id (mail-header-id header)
5989                   ref (gnus-parent-id (mail-header-references header))))
5990
5991           (when (setq header
5992                       (gnus-dependencies-add-header
5993                        header dependencies force-new))
5994             (push header headers))
5995           (goto-char (point-max))
5996           (widen))
5997         (nreverse headers)))))
5998
5999 ;; Goes through the xover lines and returns a list of vectors
6000 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6001                                                   force-new dependencies
6002                                                   group also-fetch-heads)
6003   "Parse the news overview data in the server buffer.
6004 Return a list of headers that match SEQUENCE (see
6005 `nntp-retrieve-headers')."
6006   ;; Get the Xref when the users reads the articles since most/some
6007   ;; NNTP servers do not include Xrefs when using XOVER.
6008   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6009   (let ((mail-parse-charset gnus-newsgroup-charset)
6010         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6011         (cur nntp-server-buffer)
6012         (dependencies (or dependencies gnus-newsgroup-dependencies))
6013         (allp (cond
6014                ((eq gnus-read-all-available-headers t)
6015                 t)
6016                ((stringp gnus-read-all-available-headers)
6017                 (string-match gnus-read-all-available-headers group))
6018                (t
6019                 nil)))
6020         number headers header)
6021     (save-excursion
6022       (set-buffer nntp-server-buffer)
6023       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6024       ;; Allow the user to mangle the headers before parsing them.
6025       (gnus-run-hooks 'gnus-parse-headers-hook)
6026       (goto-char (point-min))
6027       (gnus-parse-without-error
6028         (while (and (or sequence allp)
6029                     (not (eobp)))
6030           (setq number (read cur))
6031           (when (not allp)
6032             (while (and sequence
6033                         (< (car sequence) number))
6034               (setq sequence (cdr sequence))))
6035           (when (and (or allp
6036                          (and sequence
6037                               (eq number (car sequence))))
6038                      (progn
6039                        (setq sequence (cdr sequence))
6040                        (setq header (inline
6041                                       (gnus-nov-parse-line
6042                                        number dependencies force-new)))))
6043             (push header headers))
6044           (forward-line 1)))
6045       ;; A common bug in inn is that if you have posted an article and
6046       ;; then retrieves the active file, it will answer correctly --
6047       ;; the new article is included.  However, a NOV entry for the
6048       ;; article may not have been generated yet, so this may fail.
6049       ;; We work around this problem by retrieving the last few
6050       ;; headers using HEAD.
6051       (if (or (not also-fetch-heads)
6052               (not sequence))
6053           ;; We (probably) got all the headers.
6054           (nreverse headers)
6055         (let ((gnus-nov-is-evil t))
6056           (nconc
6057            (nreverse headers)
6058            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6059              (gnus-get-newsgroup-headers))))))))
6060
6061 (defun gnus-article-get-xrefs ()
6062   "Fill in the Xref value in `gnus-current-headers', if necessary.
6063 This is meant to be called in `gnus-article-internal-prepare-hook'."
6064   (let ((headers (with-current-buffer gnus-summary-buffer
6065                    gnus-current-headers)))
6066     (or (not gnus-use-cross-reference)
6067         (not headers)
6068         (and (mail-header-xref headers)
6069              (not (string= (mail-header-xref headers) "")))
6070         (let ((case-fold-search t)
6071               xref)
6072           (save-restriction
6073             (nnheader-narrow-to-headers)
6074             (goto-char (point-min))
6075             (when (or (and (not (eobp))
6076                            (eq (downcase (char-after)) ?x)
6077                            (looking-at "Xref:"))
6078                       (search-forward "\nXref:" nil t))
6079               (goto-char (1+ (match-end 0)))
6080               (setq xref (buffer-substring (point) (point-at-eol)))
6081               (mail-header-set-xref headers xref)))))))
6082
6083 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6084   "Find article ID and insert the summary line for that article.
6085 OLD-HEADER can either be a header or a line number to insert
6086 the subject line on."
6087   (let* ((line (and (numberp old-header) old-header))
6088          (old-header (and (vectorp old-header) old-header))
6089          (header (cond ((and old-header use-old-header)
6090                         old-header)
6091                        ((and (numberp id)
6092                              (gnus-number-to-header id))
6093                         (gnus-number-to-header id))
6094                        (t
6095                         (gnus-read-header id))))
6096          (number (and (numberp id) id))
6097          d)
6098     (when header
6099       ;; Rebuild the thread that this article is part of and go to the
6100       ;; article we have fetched.
6101       (when (and (not gnus-show-threads)
6102                  old-header)
6103         (when (and number
6104                    (setq d (gnus-data-find (mail-header-number old-header))))
6105           (goto-char (gnus-data-pos d))
6106           (gnus-data-remove
6107            number
6108            (- (point-at-bol)
6109               (prog1
6110                   (1+ (point-at-eol))
6111                 (gnus-delete-line))))))
6112       ;; Remove list identifiers from subject.
6113       (when gnus-list-identifiers
6114         (let ((gnus-newsgroup-headers (list header)))
6115           (gnus-summary-remove-list-identifiers)))
6116       (when old-header
6117         (mail-header-set-number header (mail-header-number old-header)))
6118       (setq gnus-newsgroup-sparse
6119             (delq (setq number (mail-header-number header))
6120                   gnus-newsgroup-sparse))
6121       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6122       (push number gnus-newsgroup-limit)
6123       (gnus-rebuild-thread (mail-header-id header) line)
6124       (gnus-summary-goto-subject number nil t))
6125     (when (and (numberp number)
6126                (> number 0))
6127       ;; We have to update the boundaries even if we can't fetch the
6128       ;; article if ID is a number -- so that the next `P' or `N'
6129       ;; command will fetch the previous (or next) article even
6130       ;; if the one we tried to fetch this time has been canceled.
6131       (when (> number gnus-newsgroup-end)
6132         (setq gnus-newsgroup-end number))
6133       (when (< number gnus-newsgroup-begin)
6134         (setq gnus-newsgroup-begin number))
6135       (setq gnus-newsgroup-unselected
6136             (delq number gnus-newsgroup-unselected)))
6137     ;; Report back a success?
6138     (and header (mail-header-number header))))
6139
6140 ;;; Process/prefix in the summary buffer
6141
6142 (defun gnus-summary-work-articles (n)
6143   "Return a list of articles to be worked upon.
6144 The prefix argument, the list of process marked articles, and the
6145 current article will be taken into consideration."
6146   (save-excursion
6147     (set-buffer gnus-summary-buffer)
6148     (cond
6149      (n
6150       ;; A numerical prefix has been given.
6151       (setq n (prefix-numeric-value n))
6152       (let ((backward (< n 0))
6153             (n (abs (prefix-numeric-value n)))
6154             articles article)
6155         (save-excursion
6156           (while
6157               (and (> n 0)
6158                    (push (setq article (gnus-summary-article-number))
6159                          articles)
6160                    (if backward
6161                        (gnus-summary-find-prev nil article)
6162                      (gnus-summary-find-next nil article)))
6163             (decf n)))
6164         (nreverse articles)))
6165      ((and (gnus-region-active-p) (mark))
6166       (message "region active")
6167       ;; Work on the region between point and mark.
6168       (let ((max (max (point) (mark)))
6169             articles article)
6170         (save-excursion
6171           (goto-char (min (point) (mark)))
6172           (while
6173               (and
6174                (push (setq article (gnus-summary-article-number)) articles)
6175                (gnus-summary-find-next nil article)
6176                (< (point) max)))
6177           (nreverse articles))))
6178      (gnus-newsgroup-processable
6179       ;; There are process-marked articles present.
6180       ;; Save current state.
6181       (gnus-summary-save-process-mark)
6182       ;; Return the list.
6183       (reverse gnus-newsgroup-processable))
6184      (t
6185       ;; Just return the current article.
6186       (list (gnus-summary-article-number))))))
6187
6188 (defmacro gnus-summary-iterate (arg &rest forms)
6189   "Iterate over the process/prefixed articles and do FORMS.
6190 ARG is the interactive prefix given to the command.  FORMS will be
6191 executed with point over the summary line of the articles."
6192   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6193     `(let ((,articles (gnus-summary-work-articles ,arg)))
6194        (while ,articles
6195          (gnus-summary-goto-subject (car ,articles))
6196          ,@forms
6197          (pop ,articles)))))
6198
6199 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6200 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6201
6202 (defun gnus-summary-save-process-mark ()
6203   "Push the current set of process marked articles on the stack."
6204   (interactive)
6205   (push (copy-sequence gnus-newsgroup-processable)
6206         gnus-newsgroup-process-stack))
6207
6208 (defun gnus-summary-kill-process-mark ()
6209   "Push the current set of process marked articles on the stack and unmark."
6210   (interactive)
6211   (gnus-summary-save-process-mark)
6212   (gnus-summary-unmark-all-processable))
6213
6214 (defun gnus-summary-yank-process-mark ()
6215   "Pop the last process mark state off the stack and restore it."
6216   (interactive)
6217   (unless gnus-newsgroup-process-stack
6218     (error "Empty mark stack"))
6219   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6220
6221 (defun gnus-summary-process-mark-set (set)
6222   "Make SET into the current process marked articles."
6223   (gnus-summary-unmark-all-processable)
6224   (mapc 'gnus-summary-set-process-mark set))
6225
6226 ;;; Searching and stuff
6227
6228 (defun gnus-summary-search-group (&optional backward use-level)
6229   "Search for next unread newsgroup.
6230 If optional argument BACKWARD is non-nil, search backward instead."
6231   (save-excursion
6232     (set-buffer gnus-group-buffer)
6233     (when (gnus-group-search-forward
6234            backward nil (if use-level (gnus-group-group-level) nil))
6235       (gnus-group-group-name))))
6236
6237 (defun gnus-summary-best-group (&optional exclude-group)
6238   "Find the name of the best unread group.
6239 If EXCLUDE-GROUP, do not go to this group."
6240   (with-current-buffer gnus-group-buffer
6241     (save-excursion
6242       (gnus-group-best-unread-group exclude-group))))
6243
6244 (defun gnus-summary-find-next (&optional unread article backward)
6245   (if backward
6246       (gnus-summary-find-prev unread article)
6247     (let* ((dummy (gnus-summary-article-intangible-p))
6248            (article (or article (gnus-summary-article-number)))
6249            (data (gnus-data-find-list article))
6250            result)
6251       (when (and (not dummy)
6252                  (or (not gnus-summary-check-current)
6253                      (not unread)
6254                      (not (gnus-data-unread-p (car data)))))
6255         (setq data (cdr data)))
6256       (when (setq result
6257                   (if unread
6258                       (progn
6259                         (while data
6260                           (unless (memq (gnus-data-number (car data))
6261                                         (cond
6262                                          ((eq gnus-auto-goto-ignores
6263                                               'always-undownloaded)
6264                                           gnus-newsgroup-undownloaded)
6265                                          (gnus-plugged
6266                                           nil)
6267                                          ((eq gnus-auto-goto-ignores
6268                                               'unfetched)
6269                                           gnus-newsgroup-unfetched)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'undownloaded)
6272                                           gnus-newsgroup-undownloaded)))
6273                             (when (gnus-data-unread-p (car data))
6274                               (setq result (car data)
6275                                     data nil)))
6276                           (setq data (cdr data)))
6277                         result)
6278                     (car data)))
6279         (goto-char (gnus-data-pos result))
6280         (gnus-data-number result)))))
6281
6282 (defun gnus-summary-find-prev (&optional unread article)
6283   (let* ((eobp (eobp))
6284          (article (or article (gnus-summary-article-number)))
6285          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6286          result)
6287     (when (and (not eobp)
6288                (or (not gnus-summary-check-current)
6289                    (not unread)
6290                    (not (gnus-data-unread-p (car data)))))
6291       (setq data (cdr data)))
6292     (when (setq result
6293                 (if unread
6294                     (progn
6295                       (while data
6296                         (unless (memq (gnus-data-number (car data))
6297                                       (cond
6298                                        ((eq gnus-auto-goto-ignores
6299                                             'always-undownloaded)
6300                                         gnus-newsgroup-undownloaded)
6301                                        (gnus-plugged
6302                                         nil)
6303                                        ((eq gnus-auto-goto-ignores
6304                                             'unfetched)
6305                                         gnus-newsgroup-unfetched)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'undownloaded)
6308                                         gnus-newsgroup-undownloaded)))
6309                           (when (gnus-data-unread-p (car data))
6310                             (setq result (car data)
6311                                   data nil)))
6312                         (setq data (cdr data)))
6313                       result)
6314                   (car data)))
6315       (goto-char (gnus-data-pos result))
6316       (gnus-data-number result))))
6317
6318 (defun gnus-summary-find-subject (subject &optional unread backward article)
6319   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6320          (article (or article (gnus-summary-article-number)))
6321          (articles (gnus-data-list backward))
6322          (arts (gnus-data-find-list article articles))
6323          result)
6324     (when (or (not gnus-summary-check-current)
6325               (not unread)
6326               (not (gnus-data-unread-p (car arts))))
6327       (setq arts (cdr arts)))
6328     (while arts
6329       (and (or (not unread)
6330                (gnus-data-unread-p (car arts)))
6331            (vectorp (gnus-data-header (car arts)))
6332            (gnus-subject-equal
6333             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6334            (setq result (car arts)
6335                  arts nil))
6336       (setq arts (cdr arts)))
6337     (and result
6338          (goto-char (gnus-data-pos result))
6339          (gnus-data-number result))))
6340
6341 (defun gnus-summary-search-forward (&optional unread subject backward)
6342   "Search forward for an article.
6343 If UNREAD, look for unread articles.  If SUBJECT, look for
6344 articles with that subject.  If BACKWARD, search backward instead."
6345   (cond (subject (gnus-summary-find-subject subject unread backward))
6346         (backward (gnus-summary-find-prev unread))
6347         (t (gnus-summary-find-next unread))))
6348
6349 (defun gnus-recenter (&optional n)
6350   "Center point in window and redisplay frame.
6351 Also do horizontal recentering."
6352   (interactive "P")
6353   (when (and gnus-auto-center-summary
6354              (not (eq gnus-auto-center-summary 'vertical)))
6355     (gnus-horizontal-recenter))
6356   (recenter n))
6357
6358 (defun gnus-summary-recenter ()
6359   "Center point in the summary window.
6360 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6361 displayed, no centering will be performed."
6362   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6363   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6364   (interactive)
6365   ;; The user has to want it.
6366   (when gnus-auto-center-summary
6367     (let* ((top (cond ((< (window-height) 4) 0)
6368                       ((< (window-height) 7) 1)
6369                       (t (if (numberp gnus-auto-center-summary)
6370                              gnus-auto-center-summary
6371                            (/ (1- (window-height)) 2)))))
6372            (height (1- (window-height)))
6373            (bottom (save-excursion (goto-char (point-max))
6374                                    (forward-line (- height))
6375                                    (point)))
6376            (window (get-buffer-window (current-buffer))))
6377       (when (get-buffer-window gnus-article-buffer)
6378         ;; Only do recentering when the article buffer is displayed,
6379         ;; Set the window start to either `bottom', which is the biggest
6380         ;; possible valid number, or the second line from the top,
6381         ;; whichever is the least.
6382         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6383           (if (> bottom top-pos)
6384               ;; Keep the second line from the top visible
6385               (set-window-start window top-pos t)
6386             ;; Try to keep the bottom line visible; if it's partially
6387             ;; obscured, either scroll one more line to make it fully
6388             ;; visible, or revert to using TOP-POS.
6389             (save-excursion
6390               (goto-char (point-max))
6391               (forward-line -1)
6392               (let ((last-line-start (point)))
6393                 (goto-char bottom)
6394                 (set-window-start window (point) t)
6395                 (when (not (pos-visible-in-window-p last-line-start window))
6396                   (forward-line 1)
6397                   (set-window-start window (min (point) top-pos) t)))))))
6398       ;; Do horizontal recentering while we're at it.
6399       (when (and (get-buffer-window (current-buffer) t)
6400                  (not (eq gnus-auto-center-summary 'vertical)))
6401         (let ((selected (selected-window)))
6402           (select-window (get-buffer-window (current-buffer) t))
6403           (gnus-summary-position-point)
6404           (gnus-horizontal-recenter)
6405           (select-window selected))))))
6406
6407 (defun gnus-summary-jump-to-group (newsgroup)
6408   "Move point to NEWSGROUP in group mode buffer."
6409   ;; Keep update point of group mode buffer if visible.
6410   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6411       (save-window-excursion
6412         ;; Take care of tree window mode.
6413         (when (get-buffer-window gnus-group-buffer)
6414           (pop-to-buffer gnus-group-buffer))
6415         (gnus-group-jump-to-group newsgroup))
6416     (save-excursion
6417       ;; Take care of tree window mode.
6418       (if (get-buffer-window gnus-group-buffer)
6419           (pop-to-buffer gnus-group-buffer)
6420         (set-buffer gnus-group-buffer))
6421       (gnus-group-jump-to-group newsgroup))))
6422
6423 ;; This function returns a list of article numbers based on the
6424 ;; difference between the ranges of read articles in this group and
6425 ;; the range of active articles.
6426 (defun gnus-list-of-unread-articles (group)
6427   (let* ((read (gnus-info-read (gnus-get-info group)))
6428          (active (or (gnus-active group) (gnus-activate-group group)))
6429          (last (cdr active))
6430          first nlast unread)
6431     ;; If none are read, then all are unread.
6432     (if (not read)
6433         (setq first (car active))
6434       ;; If the range of read articles is a single range, then the
6435       ;; first unread article is the article after the last read
6436       ;; article.  Sounds logical, doesn't it?
6437       (if (and (not (listp (cdr read)))
6438                (or (< (car read) (car active))
6439                    (progn (setq read (list read))
6440                           nil)))
6441           (setq first (max (car active) (1+ (cdr read))))
6442         ;; `read' is a list of ranges.
6443         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6444                                   (caar read)))
6445                   1)
6446           (setq first (car active)))
6447         (while read
6448           (when first
6449             (while (< first nlast)
6450               (setq unread (cons first unread)
6451                     first (1+ first))))
6452           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6453           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6454           (setq read (cdr read)))))
6455     ;; And add the last unread articles.
6456     (while (<= first last)
6457       (setq unread (cons first unread)
6458             first (1+ first)))
6459     ;; Return the list of unread articles.
6460     (delq 0 (nreverse unread))))
6461
6462 (defun gnus-list-of-read-articles (group)
6463   "Return a list of unread, unticked and non-dormant articles."
6464   (let* ((info (gnus-get-info group))
6465          (marked (gnus-info-marks info))
6466          (active (gnus-active group)))
6467     (and info active
6468          (gnus-list-range-difference
6469           (gnus-list-range-difference
6470            (gnus-sorted-complement
6471             (gnus-uncompress-range active)
6472             (gnus-list-of-unread-articles group))
6473            (cdr (assq 'dormant marked)))
6474           (cdr (assq 'tick marked))))))
6475
6476 ;; This function returns a sequence of article numbers based on the
6477 ;; difference between the ranges of read articles in this group and
6478 ;; the range of active articles.
6479 (defun gnus-sequence-of-unread-articles (group)
6480   (let* ((read (gnus-info-read (gnus-get-info group)))
6481          (active (or (gnus-active group) (gnus-activate-group group)))
6482          (last (cdr active))
6483          first nlast unread)
6484     ;; If none are read, then all are unread.
6485     (if (not read)
6486         (setq first (car active))
6487       ;; If the range of read articles is a single range, then the
6488       ;; first unread article is the article after the last read
6489       ;; article.  Sounds logical, doesn't it?
6490       (if (and (not (listp (cdr read)))
6491                (or (< (car read) (car active))
6492                    (progn (setq read (list read))
6493                           nil)))
6494           (setq first (max (car active) (1+ (cdr read))))
6495         ;; `read' is a list of ranges.
6496         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6497                                   (caar read)))
6498                   1)
6499           (setq first (car active)))
6500         (while read
6501           (when first
6502             (push (cons first nlast) unread))
6503           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6504           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6505           (setq read (cdr read)))))
6506     ;; And add the last unread articles.
6507     (cond ((< first last)
6508            (push (cons first last) unread))
6509           ((= first last)
6510            (push first unread)))
6511     ;; Return the sequence of unread articles.
6512     (delq 0 (nreverse unread))))
6513
6514 ;; Various summary commands
6515
6516 (defun gnus-summary-select-article-buffer ()
6517   "Reconfigure windows to show article buffer."
6518   (interactive)
6519   (if (not (gnus-buffer-live-p gnus-article-buffer))
6520       (error "There is no article buffer for this summary buffer")
6521     (gnus-configure-windows 'article)
6522     (select-window (get-buffer-window gnus-article-buffer))))
6523
6524 (defun gnus-summary-universal-argument (arg)
6525   "Perform any operation on all articles that are process/prefixed."
6526   (interactive "P")
6527   (let ((articles (gnus-summary-work-articles arg))
6528         func article)
6529     (if (eq
6530          (setq
6531           func
6532           (key-binding
6533            (read-key-sequence
6534             (substitute-command-keys
6535              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6536          'undefined)
6537         (gnus-error 1 "Undefined key")
6538       (save-excursion
6539         (while articles
6540           (gnus-summary-goto-subject (setq article (pop articles)))
6541           (let (gnus-newsgroup-processable)
6542             (command-execute func))
6543           (gnus-summary-remove-process-mark article)))))
6544   (gnus-summary-position-point))
6545
6546 (defun gnus-summary-toggle-truncation (&optional arg)
6547   "Toggle truncation of summary lines.
6548 With ARG, turn line truncation on if ARG is positive."
6549   (interactive "P")
6550   (setq truncate-lines
6551         (if (null arg) (not truncate-lines)
6552           (> (prefix-numeric-value arg) 0)))
6553   (redraw-display))
6554
6555 (defun gnus-summary-find-for-reselect ()
6556   "Return the number of an article to stay on across a reselect.
6557 The current article is considered, then following articles, then previous
6558 articles.  An article is sought which is not cancelled and isn't a temporary
6559 insertion from another group.  If there's no such then return a dummy 0."
6560   (let (found)
6561     (dolist (rev '(nil t))
6562       (unless found      ; don't demand the reverse list if we don't need it
6563         (let ((data (gnus-data-find-list
6564                      (gnus-summary-article-number) (gnus-data-list rev))))
6565           (while (and data (not found))
6566             (if (and (< 0 (gnus-data-number (car data)))
6567                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6568                 (setq found (gnus-data-number (car data))))
6569             (setq data (cdr data))))))
6570     (or found 0)))
6571
6572 (defun gnus-summary-reselect-current-group (&optional all rescan)
6573   "Exit and then reselect the current newsgroup.
6574 The prefix argument ALL means to select all articles."
6575   (interactive "P")
6576   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6577     (error "Ephemeral groups can't be reselected"))
6578   (let ((current-subject (gnus-summary-find-for-reselect))
6579         (group gnus-newsgroup-name))
6580     (setq gnus-newsgroup-begin nil)
6581     (gnus-summary-exit nil 'leave-hidden)
6582     ;; We have to adjust the point of group mode buffer because
6583     ;; point was moved to the next unread newsgroup by exiting.
6584     (gnus-summary-jump-to-group group)
6585     (when rescan
6586       (save-excursion
6587         (save-window-excursion
6588           ;; Don't show group contents.
6589           (set-window-start (selected-window) (point-max))
6590           (gnus-group-get-new-news-this-group 1))))
6591     (gnus-group-read-group all t)
6592     (gnus-summary-goto-subject current-subject nil t)))
6593
6594 (defun gnus-summary-rescan-group (&optional all)
6595   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6596   (interactive "P")
6597   (gnus-summary-reselect-current-group all t))
6598
6599 (defun gnus-summary-update-info (&optional non-destructive)
6600   (save-excursion
6601     (let ((group gnus-newsgroup-name))
6602       (when group
6603         (when gnus-newsgroup-kill-headers
6604           (setq gnus-newsgroup-killed
6605                 (gnus-compress-sequence
6606                  (gnus-sorted-union
6607                   (gnus-list-range-intersection
6608                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6609                   gnus-newsgroup-unreads)
6610                  t)))
6611         (unless (listp (cdr gnus-newsgroup-killed))
6612           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6613         (let ((headers gnus-newsgroup-headers))
6614           ;; Set the new ranges of read articles.
6615           (with-current-buffer gnus-group-buffer
6616             (gnus-undo-force-boundary))
6617           (gnus-update-read-articles
6618            group (gnus-sorted-union
6619                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6620           ;; Set the current article marks.
6621           (let ((gnus-newsgroup-scored
6622                  (if (and (not gnus-save-score)
6623                           (not non-destructive))
6624                      nil
6625                    gnus-newsgroup-scored)))
6626             (save-excursion
6627               (gnus-update-marks)))
6628           ;; Do the cross-ref thing.
6629           (when gnus-use-cross-reference
6630             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6631           ;; Do not switch windows but change the buffer to work.
6632           (set-buffer gnus-group-buffer)
6633           (unless (gnus-ephemeral-group-p group)
6634             (gnus-group-update-group group)))))))
6635
6636 (defun gnus-summary-save-newsrc (&optional force)
6637   "Save the current number of read/marked articles in the dribble buffer.
6638 The dribble buffer will then be saved.
6639 If FORCE (the prefix), also save the .newsrc file(s)."
6640   (interactive "P")
6641   (gnus-summary-update-info t)
6642   (if force
6643       (gnus-save-newsrc-file)
6644     (gnus-dribble-save)))
6645
6646 (defun gnus-summary-exit (&optional temporary leave-hidden)
6647   "Exit reading current newsgroup, and then return to group selection mode.
6648 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6649   (interactive)
6650   (gnus-set-global-variables)
6651   (gnus-kill-save-kill-buffer)
6652   (gnus-async-halt-prefetch)
6653   (let* ((group gnus-newsgroup-name)
6654          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6655          (gnus-group-is-exiting-p t)
6656          (mode major-mode)
6657          (group-point nil)
6658          (buf (current-buffer)))
6659     (unless quit-config
6660       ;; Do adaptive scoring, and possibly save score files.
6661       (when gnus-newsgroup-adaptive
6662         (gnus-score-adaptive))
6663       (when gnus-use-scoring
6664         (gnus-score-save)))
6665     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6666     ;; If we have several article buffers, we kill them at exit.
6667     (unless gnus-single-article-buffer
6668       (gnus-kill-buffer gnus-original-article-buffer)
6669       (setq gnus-article-current nil))
6670     (when gnus-use-cache
6671       (gnus-cache-possibly-remove-articles)
6672       (gnus-cache-save-buffers))
6673     (gnus-async-prefetch-remove-group group)
6674     (when gnus-suppress-duplicates
6675       (gnus-dup-enter-articles))
6676     (when gnus-use-trees
6677       (gnus-tree-close group))
6678     (when gnus-use-cache
6679       (gnus-cache-write-active))
6680     ;; Remove entries for this group.
6681     (nnmail-purge-split-history (gnus-group-real-name group))
6682     ;; Make all changes in this group permanent.
6683     (unless quit-config
6684       (gnus-run-hooks 'gnus-exit-group-hook)
6685       (gnus-summary-update-info))
6686     (gnus-close-group group)
6687     ;; Make sure where we were, and go to next newsgroup.
6688     (set-buffer gnus-group-buffer)
6689     (unless quit-config
6690       (gnus-group-jump-to-group group))
6691     (gnus-run-hooks 'gnus-summary-exit-hook)
6692     (unless (or quit-config
6693                 ;; If this group has disappeared from the summary
6694                 ;; buffer, don't skip forwards.
6695                 (not (string= group (gnus-group-group-name))))
6696       (gnus-group-next-unread-group 1))
6697     (setq group-point (point))
6698     (if temporary
6699         nil                             ;Nothing to do.
6700       ;; If we have several article buffers, we kill them at exit.
6701       (unless gnus-single-article-buffer
6702         (gnus-kill-buffer gnus-article-buffer)
6703         (gnus-kill-buffer gnus-original-article-buffer)
6704         (setq gnus-article-current nil))
6705       (set-buffer buf)
6706       (if (not gnus-kill-summary-on-exit)
6707           (progn
6708             (gnus-deaden-summary)
6709             (setq mode nil))
6710         ;; We set all buffer-local variables to nil.  It is unclear why
6711         ;; this is needed, but if we don't, buffer-local variables are
6712         ;; not garbage-collected, it seems.  This would the lead to en
6713         ;; ever-growing Emacs.
6714         (gnus-summary-clear-local-variables)
6715         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6716           (gnus-summary-clear-local-variables))
6717         (when (get-buffer gnus-article-buffer)
6718           (bury-buffer gnus-article-buffer))
6719         ;; Return to group mode buffer.
6720         (when (eq mode 'gnus-summary-mode)
6721           (gnus-kill-buffer buf)))
6722       (setq gnus-current-select-method gnus-select-method)
6723       (set-buffer gnus-group-buffer)
6724       (if quit-config
6725           (gnus-handle-ephemeral-exit quit-config)
6726         (goto-char group-point)
6727         (unless leave-hidden
6728           (gnus-configure-windows 'group 'force))
6729         (unless (pos-visible-in-window-p)
6730           (forward-line (/ (static-if (featurep 'xemacs)
6731                                       (window-displayed-height)
6732                                       (1- (window-height)))
6733                            -2))
6734           (set-window-start (selected-window) (point))
6735           (goto-char group-point)))
6736       ;; Clear the current group name.
6737       (unless quit-config
6738         (setq gnus-newsgroup-name nil)))))
6739
6740 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6741 (defun gnus-summary-exit-no-update (&optional no-questions)
6742   "Quit reading current newsgroup without updating read article info."
6743   (interactive)
6744   (let* ((group gnus-newsgroup-name)
6745          (gnus-group-is-exiting-p t)
6746          (gnus-group-is-exiting-without-update-p t)
6747          (quit-config (gnus-group-quit-config group)))
6748     (when (or no-questions
6749               gnus-expert-user
6750               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6751       (gnus-async-halt-prefetch)
6752       (run-hooks 'gnus-summary-prepare-exit-hook)
6753       ;; If we have several article buffers, we kill them at exit.
6754       (unless gnus-single-article-buffer
6755         (gnus-kill-buffer gnus-article-buffer)
6756         (gnus-kill-buffer gnus-original-article-buffer)
6757         (setq gnus-article-current nil))
6758       (if (not gnus-kill-summary-on-exit)
6759           (gnus-deaden-summary)
6760         (gnus-close-group group)
6761         (gnus-summary-clear-local-variables)
6762         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6763           (gnus-summary-clear-local-variables))
6764         (gnus-kill-buffer gnus-summary-buffer))
6765       (unless gnus-single-article-buffer
6766         (setq gnus-article-current nil))
6767       (when gnus-use-trees
6768         (gnus-tree-close group))
6769       (gnus-async-prefetch-remove-group group)
6770       (when (get-buffer gnus-article-buffer)
6771         (bury-buffer gnus-article-buffer))
6772       ;; Return to the group buffer.
6773       (gnus-configure-windows 'group 'force)
6774       ;; Clear the current group name.
6775       (setq gnus-newsgroup-name nil)
6776       (unless (gnus-ephemeral-group-p group)
6777         (gnus-group-update-group group))
6778       (when (equal (gnus-group-group-name) group)
6779         (gnus-group-next-unread-group 1))
6780       (when quit-config
6781         (gnus-handle-ephemeral-exit quit-config)))))
6782
6783 (defun gnus-handle-ephemeral-exit (quit-config)
6784   "Handle movement when leaving an ephemeral group.
6785 The state which existed when entering the ephemeral is reset."
6786   (if (not (buffer-name (car quit-config)))
6787       (gnus-configure-windows 'group 'force)
6788     (set-buffer (car quit-config))
6789     (cond ((eq major-mode 'gnus-summary-mode)
6790            (gnus-set-global-variables))
6791           ((eq major-mode 'gnus-article-mode)
6792            (save-excursion
6793              ;; The `gnus-summary-buffer' variable may point
6794              ;; to the old summary buffer when using a single
6795              ;; article buffer.
6796              (unless (gnus-buffer-live-p gnus-summary-buffer)
6797                (set-buffer gnus-group-buffer))
6798              (set-buffer gnus-summary-buffer)
6799              (gnus-set-global-variables))))
6800     (if (or (eq (cdr quit-config) 'article)
6801             (eq (cdr quit-config) 'pick))
6802         (progn
6803           ;; The current article may be from the ephemeral group
6804           ;; thus it is best that we reload this article
6805           ;;
6806           ;; If we're exiting from a large digest, this can be
6807           ;; extremely slow.  So, it's better not to reload it. -- jh.
6808           ;;(gnus-summary-show-article)
6809           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6810               (gnus-configure-windows 'pick 'force)
6811             (gnus-configure-windows (cdr quit-config) 'force)))
6812       (gnus-configure-windows (cdr quit-config) 'force))
6813     (when (eq major-mode 'gnus-summary-mode)
6814       (gnus-summary-next-subject 1 nil t)
6815       (gnus-summary-recenter)
6816       (gnus-summary-position-point))))
6817
6818 (defun gnus-summary-preview-mime-message ()
6819   "MIME decode and play this message."
6820   (interactive)
6821   (let ((gnus-break-pages nil)
6822         (gnus-show-mime t))
6823     (gnus-summary-select-article gnus-show-all-headers t))
6824   (let ((w (get-buffer-window gnus-article-buffer)))
6825     (when w
6826       (select-window (get-buffer-window gnus-article-buffer)))))
6827
6828 ;;; Dead summaries.
6829
6830 (defvar gnus-dead-summary-mode-map nil)
6831
6832 (unless gnus-dead-summary-mode-map
6833   (setq gnus-dead-summary-mode-map (make-keymap))
6834   (suppress-keymap gnus-dead-summary-mode-map)
6835   (substitute-key-definition
6836    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6837   (dolist (key '("\C-d" "\r" "\177" [delete]))
6838     (define-key gnus-dead-summary-mode-map
6839       key 'gnus-summary-wake-up-the-dead))
6840   (dolist (key '("q" "Q"))
6841     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6842
6843 (defvar gnus-dead-summary-mode nil
6844   "Minor mode for Gnus summary buffers.")
6845
6846 (defun gnus-dead-summary-mode (&optional arg)
6847   "Minor mode for Gnus summary buffers."
6848   (interactive "P")
6849   (when (eq major-mode 'gnus-summary-mode)
6850     (make-local-variable 'gnus-dead-summary-mode)
6851     (setq gnus-dead-summary-mode
6852           (if (null arg) (not gnus-dead-summary-mode)
6853             (> (prefix-numeric-value arg) 0)))
6854     (when gnus-dead-summary-mode
6855       (add-minor-mode
6856        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6857
6858 (defun gnus-deaden-summary ()
6859   "Make the current summary buffer into a dead summary buffer."
6860   ;; Kill any previous dead summary buffer.
6861   (when (and gnus-dead-summary
6862              (buffer-name gnus-dead-summary))
6863     (with-current-buffer gnus-dead-summary
6864       (when gnus-dead-summary-mode
6865         (kill-buffer (current-buffer)))))
6866   ;; Make this the current dead summary.
6867   (setq gnus-dead-summary (current-buffer))
6868   (gnus-dead-summary-mode 1)
6869   (let ((name (buffer-name)))
6870     (when (string-match "Summary" name)
6871       (rename-buffer
6872        (concat (substring name 0 (match-beginning 0)) "Dead "
6873                (substring name (match-beginning 0)))
6874        t)
6875       (bury-buffer))))
6876
6877 (defun gnus-kill-or-deaden-summary (buffer)
6878   "Kill or deaden the summary BUFFER."
6879   (save-excursion
6880     (when (and (buffer-name buffer)
6881                (not gnus-single-article-buffer))
6882       (with-current-buffer buffer
6883         (gnus-kill-buffer gnus-article-buffer)
6884         (gnus-kill-buffer gnus-original-article-buffer)))
6885     (cond
6886      ;; Kill the buffer.
6887      (gnus-kill-summary-on-exit
6888       (when (and gnus-use-trees
6889                  (gnus-buffer-exists-p buffer))
6890         (save-excursion
6891           (set-buffer buffer)
6892           (gnus-tree-close gnus-newsgroup-name)))
6893       (gnus-kill-buffer buffer))
6894      ;; Deaden the buffer.
6895      ((gnus-buffer-exists-p buffer)
6896       (save-excursion
6897         (set-buffer buffer)
6898         (gnus-deaden-summary))))))
6899
6900 (defun gnus-summary-wake-up-the-dead (&rest args)
6901   "Wake up the dead summary buffer."
6902   (interactive)
6903   (gnus-dead-summary-mode -1)
6904   (let ((name (buffer-name)))
6905     (when (string-match "Dead " name)
6906       (rename-buffer
6907        (concat (substring name 0 (match-beginning 0))
6908                (substring name (match-end 0)))
6909        t)))
6910   (gnus-message 3 "This dead summary is now alive again"))
6911
6912 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6913 (defun gnus-summary-fetch-faq (&optional faq-dir)
6914   "Fetch the FAQ for the current group.
6915 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6916 in."
6917   (interactive
6918    (list
6919     (when current-prefix-arg
6920       (completing-read
6921        "FAQ dir: " (and (listp gnus-group-faq-directory)
6922                         (mapcar 'list
6923                                 gnus-group-faq-directory))))))
6924   (let (gnus-faq-buffer)
6925     (when (setq gnus-faq-buffer
6926                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6927       (gnus-configure-windows 'summary-faq))))
6928
6929 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6930 (defun gnus-summary-describe-group (&optional force)
6931   "Describe the current newsgroup."
6932   (interactive "P")
6933   (gnus-group-describe-group force gnus-newsgroup-name))
6934
6935 (defun gnus-summary-describe-briefly ()
6936   "Describe summary mode commands briefly."
6937   (interactive)
6938   (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")))
6939
6940 ;; Walking around group mode buffer from summary mode.
6941
6942 (defun gnus-summary-next-group (&optional no-article target-group backward)
6943   "Exit current newsgroup and then select next unread newsgroup.
6944 If prefix argument NO-ARTICLE is non-nil, no article is selected
6945 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6946 previous group instead."
6947   (interactive "P")
6948   ;; Stop pre-fetching.
6949   (gnus-async-halt-prefetch)
6950   (let ((current-group gnus-newsgroup-name)
6951         (current-buffer (current-buffer))
6952         entered)
6953     ;; First we semi-exit this group to update Xrefs and all variables.
6954     ;; We can't do a real exit, because the window conf must remain
6955     ;; the same in case the user is prompted for info, and we don't
6956     ;; want the window conf to change before that...
6957     (gnus-summary-exit t)
6958     (while (not entered)
6959       ;; Then we find what group we are supposed to enter.
6960       (set-buffer gnus-group-buffer)
6961       (gnus-group-jump-to-group current-group)
6962       (setq target-group
6963             (or target-group
6964                 (if (eq gnus-keep-same-level 'best)
6965                     (gnus-summary-best-group gnus-newsgroup-name)
6966                   (gnus-summary-search-group backward gnus-keep-same-level))))
6967       (if (not target-group)
6968           ;; There are no further groups, so we return to the group
6969           ;; buffer.
6970           (progn
6971             (gnus-message 5 "Returning to the group buffer")
6972             (setq entered t)
6973             (when (gnus-buffer-live-p current-buffer)
6974               (set-buffer current-buffer)
6975               (gnus-summary-exit))
6976             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6977         ;; We try to enter the target group.
6978         (gnus-group-jump-to-group target-group)
6979         (let ((unreads (gnus-group-group-unread)))
6980           (if (and (or (eq t unreads)
6981                        (and unreads (not (zerop unreads))))
6982                    (gnus-summary-read-group
6983                     target-group nil no-article
6984                     (and (buffer-name current-buffer) current-buffer)
6985                     nil backward))
6986               (setq entered t)
6987             (setq current-group target-group
6988                   target-group nil)))))))
6989
6990 (defun gnus-summary-prev-group (&optional no-article)
6991   "Exit current newsgroup and then select previous unread newsgroup.
6992 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6993   (interactive "P")
6994   (gnus-summary-next-group no-article nil t))
6995
6996 ;; Walking around summary lines.
6997
6998 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6999   "Go to the first subject satisfying any non-nil constraint.
7000 If UNREAD is non-nil, the article should be unread.
7001 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7002 If UNSEEN is non-nil, the article should be unseen.
7003 Returns the article selected or nil if there are no matching articles."
7004   (interactive "P")
7005   (cond
7006    ;; Empty summary.
7007    ((null gnus-newsgroup-data)
7008     (gnus-message 3 "No articles in the group")
7009     nil)
7010    ;; Pick the first article.
7011    ((not (or unread undownloaded unseen))
7012     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7013     (gnus-data-number (car gnus-newsgroup-data)))
7014    ;; Find the first unread article.
7015    (t
7016     (let ((data gnus-newsgroup-data))
7017       (while (and data
7018                   (let ((num (gnus-data-number (car data))))
7019                     (or (memq num gnus-newsgroup-unfetched)
7020                         (not (or (and unread
7021                                       (memq num gnus-newsgroup-unreads))
7022                                  (and undownloaded
7023                                       (memq num gnus-newsgroup-undownloaded))
7024                                  (and unseen
7025                                       (memq num gnus-newsgroup-unseen)))))))
7026         (setq data (cdr data)))
7027       (prog1
7028           (if data
7029               (progn
7030                 (goto-char (gnus-data-pos (car data)))
7031                 (gnus-data-number (car data)))
7032             (gnus-message 3 "No more%s articles"
7033                           (let* ((r (when unread " unread"))
7034                                  (d (when undownloaded " undownloaded"))
7035                                  (s (when unseen " unseen"))
7036                                  (l (delq nil (list r d s))))
7037                             (cond ((= 3 (length l))
7038                                    (concat r "," d ", or" s))
7039                                   ((= 2 (length l))
7040                                    (concat (car l) ", or" (cadr l)))
7041                                   ((= 1 (length l))
7042                                    (car l))
7043                                   (t
7044                                    ""))))
7045             nil
7046             )
7047         (gnus-summary-position-point))))))
7048
7049 (defun gnus-summary-next-subject (n &optional unread dont-display)
7050   "Go to next N'th summary line.
7051 If N is negative, go to the previous N'th subject line.
7052 If UNREAD is non-nil, only unread articles are selected.
7053 The difference between N and the actual number of steps taken is
7054 returned."
7055   (interactive "p")
7056   (let ((backward (< n 0))
7057         (n (abs n)))
7058     (while (and (> n 0)
7059                 (if backward
7060                     (gnus-summary-find-prev unread)
7061                   (gnus-summary-find-next unread)))
7062       (unless (zerop (setq n (1- n)))
7063         (gnus-summary-show-thread)))
7064     (when (/= 0 n)
7065       (gnus-message 7 "No more%s articles"
7066                     (if unread " unread" "")))
7067     (unless dont-display
7068       (gnus-summary-recenter)
7069       (gnus-summary-position-point))
7070     n))
7071
7072 (defun gnus-summary-next-unread-subject (n)
7073   "Go to next N'th unread summary line."
7074   (interactive "p")
7075   (gnus-summary-next-subject n t))
7076
7077 (defun gnus-summary-prev-subject (n &optional unread)
7078   "Go to previous N'th summary line.
7079 If optional argument UNREAD is non-nil, only unread article is selected."
7080   (interactive "p")
7081   (gnus-summary-next-subject (- n) unread))
7082
7083 (defun gnus-summary-prev-unread-subject (n)
7084   "Go to previous N'th unread summary line."
7085   (interactive "p")
7086   (gnus-summary-next-subject (- n) t))
7087
7088 (defun gnus-summary-goto-subjects (articles)
7089   "Insert the subject header for ARTICLES in the current buffer."
7090   (save-excursion
7091     (dolist (article articles)
7092       (gnus-summary-goto-subject article t)))
7093   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7094   (gnus-summary-position-point))
7095  
7096 (defun gnus-summary-goto-subject (article &optional force silent)
7097   "Go the subject line of ARTICLE.
7098 If FORCE, also allow jumping to articles not currently shown."
7099   (interactive "nArticle number: ")
7100   (unless (numberp article)
7101     (error "Article %s is not a number" article))
7102   (let ((b (point))
7103         (data (gnus-data-find article)))
7104     ;; We read in the article if we have to.
7105     (and (not data)
7106          force
7107          (gnus-summary-insert-subject
7108           article
7109           (if (or (numberp force) (vectorp force)) force)
7110           t)
7111          (setq data (gnus-data-find article)))
7112     (goto-char b)
7113     (if (not data)
7114         (progn
7115           (unless silent
7116             (gnus-message 3 "Can't find article %d" article))
7117           nil)
7118       (let ((pt (gnus-data-pos data)))
7119         (goto-char pt)
7120         (gnus-summary-set-article-display-arrow pt))
7121       (gnus-summary-position-point)
7122       article)))
7123
7124 ;; Walking around summary lines with displaying articles.
7125
7126 (defun gnus-summary-expand-window (&optional arg)
7127   "Make the summary buffer take up the entire Emacs frame.
7128 Given a prefix, will force an `article' buffer configuration."
7129   (interactive "P")
7130   (if arg
7131       (gnus-configure-windows 'article 'force)
7132     (gnus-configure-windows 'summary 'force)))
7133
7134 (defun gnus-summary-display-article (article &optional all-header)
7135   "Display ARTICLE in article buffer."
7136   (when (gnus-buffer-live-p gnus-article-buffer)
7137     (with-current-buffer gnus-article-buffer
7138       (set-buffer-multibyte t)))
7139   (gnus-set-global-variables)
7140   (when (gnus-buffer-live-p gnus-article-buffer)
7141     (with-current-buffer gnus-article-buffer
7142       (setq gnus-article-charset gnus-newsgroup-charset)
7143       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7144       (set-buffer-multibyte t)))
7145   (if (null article)
7146       nil
7147     (prog1
7148         (if gnus-summary-display-article-function
7149             (funcall gnus-summary-display-article-function article all-header)
7150           (gnus-article-prepare article all-header))
7151       (with-current-buffer gnus-article-buffer
7152         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7153              nil))
7154       (gnus-run-hooks 'gnus-select-article-hook)
7155       (when (and gnus-current-article
7156                  (not (zerop gnus-current-article)))
7157         (gnus-summary-goto-subject gnus-current-article))
7158       (gnus-summary-recenter)
7159       (when (and gnus-use-trees gnus-show-threads)
7160         (gnus-possibly-generate-tree article)
7161         (gnus-highlight-selected-tree article))
7162       ;; Successfully display article.
7163       (gnus-article-set-window-start
7164        (cdr (assq article gnus-newsgroup-bookmarks))))))
7165
7166 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7167   "Select the current article.
7168 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7169 non-nil, the article will be re-fetched even if it already present in
7170 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7171 be displayed."
7172   ;; Make sure we are in the summary buffer to work around bbdb bug.
7173   (unless (eq major-mode 'gnus-summary-mode)
7174     (set-buffer gnus-summary-buffer))
7175   (let ((article (or article (gnus-summary-article-number)))
7176         (all-headers (not (not all-headers))) ;Must be T or NIL.
7177         gnus-summary-display-article-function)
7178     (and (not pseudo)
7179          (gnus-summary-article-pseudo-p article)
7180          (error "This is a pseudo-article"))
7181     (save-excursion
7182       (set-buffer gnus-summary-buffer)
7183       (if (or (and gnus-single-article-buffer
7184                    (or (null gnus-current-article)
7185                        (null gnus-article-current)
7186                        (null (get-buffer gnus-article-buffer))
7187                        (not (eq article (cdr gnus-article-current)))
7188                        (not (equal (car gnus-article-current)
7189                                    gnus-newsgroup-name))))
7190               (and (not gnus-single-article-buffer)
7191                    (or (null gnus-current-article)
7192                        (not (eq gnus-current-article article))))
7193               force)
7194           ;; The requested article is different from the current article.
7195           (progn
7196             (gnus-summary-display-article article all-headers)
7197             (gnus-article-set-window-start
7198              (cdr (assq article gnus-newsgroup-bookmarks)))
7199             article)
7200         'old))))
7201
7202 (defun gnus-summary-force-verify-and-decrypt ()
7203   "Display buttons for signed/encrypted parts and verify/decrypt them."
7204   (interactive)
7205   (let ((mm-verify-option 'known)
7206         (mm-decrypt-option 'known)
7207         (gnus-article-emulate-mime t)
7208         (gnus-buttonized-mime-types (append (list "multipart/signed"
7209                                                   "multipart/encrypted")
7210                                             gnus-buttonized-mime-types)))
7211     (gnus-summary-select-article nil 'force)))
7212
7213 (defun gnus-summary-set-current-mark (&optional current-mark)
7214   "Obsolete function."
7215   nil)
7216
7217 (defun gnus-summary-next-article (&optional unread subject backward push)
7218   "Select the next article.
7219 If UNREAD, only unread articles are selected.
7220 If SUBJECT, only articles with SUBJECT are selected.
7221 If BACKWARD, the previous article is selected instead of the next."
7222   (interactive "P")
7223   (cond
7224    ;; Is there such an article?
7225    ((and (gnus-summary-search-forward unread subject backward)
7226          (or (gnus-summary-display-article (gnus-summary-article-number))
7227              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7228     (gnus-summary-position-point))
7229    ;; If not, we try the first unread, if that is wanted.
7230    ((and subject
7231          gnus-auto-select-same
7232          (gnus-summary-first-unread-article))
7233     (gnus-summary-position-point)
7234     (gnus-message 6 "Wrapped"))
7235    ;; Try to get next/previous article not displayed in this group.
7236    ((and gnus-auto-extend-newsgroup
7237          (not unread) (not subject))
7238     (gnus-summary-goto-article
7239      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7240      nil (count-lines (point-min) (point))))
7241    ;; Go to next/previous group.
7242    (t
7243     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7244       (gnus-summary-jump-to-group gnus-newsgroup-name))
7245     (let ((cmd last-command-char)
7246           (point
7247            (with-current-buffer gnus-group-buffer
7248              (point)))
7249           (group
7250            (if (eq gnus-keep-same-level 'best)
7251                (gnus-summary-best-group gnus-newsgroup-name)
7252              (gnus-summary-search-group backward gnus-keep-same-level))))
7253       ;; For some reason, the group window gets selected.  We change
7254       ;; it back.
7255       (select-window (get-buffer-window (current-buffer)))
7256       ;; Select next unread newsgroup automagically.
7257       (cond
7258        ((or (not gnus-auto-select-next)
7259             (not cmd))
7260         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7261        ((or (eq gnus-auto-select-next 'quietly)
7262             (and (eq gnus-auto-select-next 'slightly-quietly)
7263                  push)
7264             (and (eq gnus-auto-select-next 'almost-quietly)
7265                  (gnus-summary-last-article-p)))
7266         ;; Select quietly.
7267         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7268             (gnus-summary-exit)
7269           (gnus-message 7 "No more%s articles (%s)..."
7270                         (if unread " unread" "")
7271                         (if group (concat "selecting " group)
7272                           "exiting"))
7273           (gnus-summary-next-group nil group backward)))
7274        (t
7275         (when (gnus-key-press-event-p last-input-event)
7276           (gnus-summary-walk-group-buffer
7277            gnus-newsgroup-name cmd unread backward point))))))))
7278
7279 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7280   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7281                       (?\C-p (gnus-group-prev-unread-group 1))))
7282         (cursor-in-echo-area t)
7283         keve key group ended prompt)
7284     (save-excursion
7285       (set-buffer gnus-group-buffer)
7286       (goto-char start)
7287       (setq group
7288             (if (eq gnus-keep-same-level 'best)
7289                 (gnus-summary-best-group gnus-newsgroup-name)
7290               (gnus-summary-search-group backward gnus-keep-same-level))))
7291     (while (not ended)
7292       (setq prompt
7293             (format
7294              "No more%s articles%s " (if unread " unread" "")
7295              (if (and group
7296                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7297                  (format " (Type %s for %s [%s])"
7298                          (single-key-description cmd) group
7299                          (gnus-group-unread group))
7300                (format " (Type %s to exit %s)"
7301                        (single-key-description cmd)
7302                        gnus-newsgroup-name))))
7303       ;; Confirm auto selection.
7304       (setq key (car (setq keve (gnus-read-event-char prompt)))
7305             ended t)
7306       (cond
7307        ((assq key keystrokes)
7308         (let ((obuf (current-buffer)))
7309           (switch-to-buffer gnus-group-buffer)
7310           (when group
7311             (gnus-group-jump-to-group group))
7312           (eval (cadr (assq key keystrokes)))
7313           (setq group (gnus-group-group-name))
7314           (switch-to-buffer obuf))
7315         (setq ended nil))
7316        ((equal key cmd)
7317         (if (or (not group)
7318                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7319             (gnus-summary-exit)
7320           (gnus-summary-next-group nil group backward)))
7321        (t
7322         (push (cdr keve) unread-command-events))))))
7323
7324 (defun gnus-summary-next-unread-article ()
7325   "Select unread article after current one."
7326   (interactive)
7327   (gnus-summary-next-article
7328    (or (not (eq gnus-summary-goto-unread 'never))
7329        (gnus-summary-last-article-p (gnus-summary-article-number)))
7330    (and gnus-auto-select-same
7331         (gnus-summary-article-subject))))
7332
7333 (defun gnus-summary-prev-article (&optional unread subject)
7334   "Select the article after the current one.
7335 If UNREAD is non-nil, only unread articles are selected."
7336   (interactive "P")
7337   (gnus-summary-next-article unread subject t))
7338
7339 (defun gnus-summary-prev-unread-article ()
7340   "Select unread article before current one."
7341   (interactive)
7342   (gnus-summary-prev-article
7343    (or (not (eq gnus-summary-goto-unread 'never))
7344        (gnus-summary-first-article-p (gnus-summary-article-number)))
7345    (and gnus-auto-select-same
7346         (gnus-summary-article-subject))))
7347
7348 (defun gnus-summary-next-page (&optional lines circular stop)
7349   "Show next page of the selected article.
7350 If at the end of the current article, select the next article.
7351 LINES says how many lines should be scrolled up.
7352
7353 If CIRCULAR is non-nil, go to the start of the article instead of
7354 selecting the next article when reaching the end of the current
7355 article.
7356
7357 If STOP is non-nil, just stop when reaching the end of the message.
7358
7359 Also see the variable `gnus-article-skip-boring'."
7360   (interactive "P")
7361   (setq gnus-summary-buffer (current-buffer))
7362   (gnus-set-global-variables)
7363   (let ((article (gnus-summary-article-number))
7364         (article-window (get-buffer-window gnus-article-buffer t))
7365         endp)
7366     ;; If the buffer is empty, we have no article.
7367     (unless article
7368       (error "No article to select"))
7369     (gnus-configure-windows 'article)
7370     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7371         (if (and (eq gnus-summary-goto-unread 'never)
7372                  (not (gnus-summary-last-article-p article)))
7373             (gnus-summary-next-article)
7374           (gnus-summary-next-unread-article))
7375       (if (or (null gnus-current-article)
7376               (null gnus-article-current)
7377               (/= article (cdr gnus-article-current))
7378               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7379           ;; Selected subject is different from current article's.
7380           (gnus-summary-display-article article)
7381         (when article-window
7382           (gnus-eval-in-buffer-window gnus-article-buffer
7383             (setq endp (or (gnus-article-next-page lines)
7384                            (gnus-article-only-boring-p))))
7385           (when endp
7386             (cond (stop
7387                    (gnus-message 3 "End of message"))
7388                   (circular
7389                    (gnus-summary-beginning-of-article))
7390                   (lines
7391                    (gnus-message 3 "End of message"))
7392                   ((null lines)
7393                    (if (and (eq gnus-summary-goto-unread 'never)
7394                             (not (gnus-summary-last-article-p article)))
7395                        (gnus-summary-next-article)
7396                      (gnus-summary-next-unread-article))))))))
7397     (gnus-summary-recenter)
7398     (gnus-summary-position-point)))
7399
7400 (defun gnus-summary-prev-page (&optional lines move)
7401   "Show previous page of selected article.
7402 Argument LINES specifies lines to be scrolled down.
7403 If MOVE, move to the previous unread article if point is at
7404 the beginning of the buffer."
7405   (interactive "P")
7406   (let ((article (gnus-summary-article-number))
7407         (article-window (get-buffer-window gnus-article-buffer t))
7408         endp)
7409     (gnus-configure-windows 'article)
7410     (if (or (null gnus-current-article)
7411             (null gnus-article-current)
7412             (/= article (cdr gnus-article-current))
7413             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7414         ;; Selected subject is different from current article's.
7415         (gnus-summary-display-article article)
7416       (gnus-summary-recenter)
7417       (when article-window
7418         (gnus-eval-in-buffer-window gnus-article-buffer
7419           (setq endp (gnus-article-prev-page lines)))
7420         (when (and move endp)
7421           (cond (lines
7422                  (gnus-message 3 "Beginning of message"))
7423                 ((null lines)
7424                  (if (and (eq gnus-summary-goto-unread 'never)
7425                           (not (gnus-summary-first-article-p article)))
7426                      (gnus-summary-prev-article)
7427                    (gnus-summary-prev-unread-article))))))))
7428   (gnus-summary-position-point))
7429
7430 (defun gnus-summary-prev-page-or-article (&optional lines)
7431   "Show previous page of selected article.
7432 Argument LINES specifies lines to be scrolled down.
7433 If at the beginning of the article, go to the next article."
7434   (interactive "P")
7435   (gnus-summary-prev-page lines t))
7436
7437 (defun gnus-summary-scroll-up (lines)
7438   "Scroll up (or down) one line current article.
7439 Argument LINES specifies lines to be scrolled up (or down if negative)."
7440   (interactive "p")
7441   (gnus-configure-windows 'article)
7442   (gnus-summary-show-thread)
7443   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7444     (gnus-eval-in-buffer-window gnus-article-buffer
7445       (cond ((> lines 0)
7446              (when (gnus-article-next-page lines)
7447                (gnus-message 3 "End of message")))
7448             ((< lines 0)
7449              (gnus-article-prev-page (- lines))))))
7450   (gnus-summary-recenter)
7451   (gnus-summary-position-point))
7452
7453 (defun gnus-summary-scroll-down (lines)
7454   "Scroll down (or up) one line current article.
7455 Argument LINES specifies lines to be scrolled down (or up if negative)."
7456   (interactive "p")
7457   (gnus-summary-scroll-up (- lines)))
7458
7459 (defun gnus-summary-next-same-subject ()
7460   "Select next article which has the same subject as current one."
7461   (interactive)
7462   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7463
7464 (defun gnus-summary-prev-same-subject ()
7465   "Select previous article which has the same subject as current one."
7466   (interactive)
7467   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7468
7469 (defun gnus-summary-next-unread-same-subject ()
7470   "Select next unread article which has the same subject as current one."
7471   (interactive)
7472   (gnus-summary-next-article t (gnus-summary-article-subject)))
7473
7474 (defun gnus-summary-prev-unread-same-subject ()
7475   "Select previous unread article which has the same subject as current one."
7476   (interactive)
7477   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7478
7479 (defun gnus-summary-first-unread-article ()
7480   "Select the first unread article.
7481 Return nil if there are no unread articles."
7482   (interactive)
7483   (prog1
7484       (when (gnus-summary-first-subject t)
7485         (gnus-summary-show-thread)
7486         (gnus-summary-first-subject t)
7487         (gnus-summary-display-article (gnus-summary-article-number)))
7488     (gnus-summary-position-point)))
7489
7490 (defun gnus-summary-first-unread-subject ()
7491   "Place the point on the subject line of the first unread article.
7492 Return nil if there are no unread articles."
7493   (interactive)
7494   (prog1
7495       (when (gnus-summary-first-subject t)
7496         (gnus-summary-show-thread)
7497         (gnus-summary-first-subject t))
7498     (gnus-summary-position-point)))
7499
7500 (defun gnus-summary-first-unseen-subject ()
7501   "Place the point on the subject line of the first unseen article.
7502 Return nil if there are no unseen articles."
7503   (interactive)
7504   (prog1
7505       (when (gnus-summary-first-subject nil nil t)
7506         (gnus-summary-show-thread)
7507         (gnus-summary-first-subject nil nil t))
7508     (gnus-summary-position-point)))
7509
7510 (defun gnus-summary-first-unseen-or-unread-subject ()
7511   "Place the point on the subject line of the first unseen article or,
7512 if all article have been seen, on the subject line of the first unread
7513 article."
7514   (interactive)
7515   (prog1
7516       (unless (when (gnus-summary-first-subject nil nil t)
7517                 (gnus-summary-show-thread)
7518                 (gnus-summary-first-subject nil nil t))
7519         (when (gnus-summary-first-subject t)
7520           (gnus-summary-show-thread)
7521           (gnus-summary-first-subject t)))
7522     (gnus-summary-position-point)))
7523
7524 (defun gnus-summary-first-article ()
7525   "Select the first article.
7526 Return nil if there are no articles."
7527   (interactive)
7528   (prog1
7529       (when (gnus-summary-first-subject)
7530         (gnus-summary-show-thread)
7531         (gnus-summary-first-subject)
7532         (gnus-summary-display-article (gnus-summary-article-number)))
7533     (gnus-summary-position-point)))
7534
7535 (defun gnus-summary-best-unread-article (&optional arg)
7536   "Select the unread article with the highest score.
7537 If given a prefix argument, select the next unread article that has a
7538 score higher than the default score."
7539   (interactive "P")
7540   (let ((article (if arg
7541                      (gnus-summary-better-unread-subject)
7542                    (gnus-summary-best-unread-subject))))
7543     (if article
7544         (gnus-summary-goto-article article)
7545       (error "No unread articles"))))
7546
7547 (defun gnus-summary-best-unread-subject ()
7548   "Select the unread subject with the highest score."
7549   (interactive)
7550   (let ((best -1000000)
7551         (data gnus-newsgroup-data)
7552         article score)
7553     (while data
7554       (and (gnus-data-unread-p (car data))
7555            (> (setq score
7556                     (gnus-summary-article-score (gnus-data-number (car data))))
7557               best)
7558            (setq best score
7559                  article (gnus-data-number (car data))))
7560       (setq data (cdr data)))
7561     (when article
7562       (gnus-summary-goto-subject article))
7563     (gnus-summary-position-point)
7564     article))
7565
7566 (defun gnus-summary-better-unread-subject ()
7567   "Select the first unread subject that has a score over the default score."
7568   (interactive)
7569   (let ((data gnus-newsgroup-data)
7570         article score)
7571     (while (and (setq article (gnus-data-number (car data)))
7572                 (or (gnus-data-read-p (car data))
7573                     (not (> (gnus-summary-article-score article)
7574                             gnus-summary-default-score))))
7575       (setq data (cdr data)))
7576     (when article
7577       (gnus-summary-goto-subject article))
7578     (gnus-summary-position-point)
7579     article))
7580
7581 (defun gnus-summary-last-subject ()
7582   "Go to the last displayed subject line in the group."
7583   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7584     (when article
7585       (gnus-summary-goto-subject article))))
7586
7587 (defun gnus-summary-goto-article (article &optional all-headers force)
7588   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7589 If ALL-HEADERS is non-nil, no header lines are hidden.
7590 If FORCE, go to the article even if it isn't displayed.  If FORCE
7591 is a number, it is the line the article is to be displayed on."
7592   (interactive
7593    (list
7594     (completing-read
7595      "Article number or Message-ID: "
7596      (mapcar (lambda (number) (list (int-to-string number)))
7597              gnus-newsgroup-limit))
7598     current-prefix-arg
7599     t))
7600   (prog1
7601       (if (and (stringp article)
7602                (string-match "@\\|%40" article))
7603           (gnus-summary-refer-article article)
7604         (when (stringp article)
7605           (setq article (string-to-number article)))
7606         (if (gnus-summary-goto-subject article force)
7607             (gnus-summary-display-article article all-headers)
7608           (gnus-message 4 "Couldn't go to article %s" article) nil))
7609     (gnus-summary-position-point)))
7610
7611 (defun gnus-summary-goto-last-article ()
7612   "Go to the previously read article."
7613   (interactive)
7614   (prog1
7615       (when gnus-last-article
7616         (gnus-summary-goto-article gnus-last-article nil t))
7617     (gnus-summary-position-point)))
7618
7619 (defun gnus-summary-pop-article (number)
7620   "Pop one article off the history and go to the previous.
7621 NUMBER articles will be popped off."
7622   (interactive "p")
7623   (let (to)
7624     (setq gnus-newsgroup-history
7625           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7626     (if to
7627         (gnus-summary-goto-article (car to) nil t)
7628       (error "Article history empty")))
7629   (gnus-summary-position-point))
7630
7631 ;; Summary commands and functions for limiting the summary buffer.
7632
7633 (defun gnus-summary-limit-to-articles (n)
7634   "Limit the summary buffer to the next N articles.
7635 If not given a prefix, use the process marked articles instead."
7636   (interactive "P")
7637   (prog1
7638       (let ((articles (gnus-summary-work-articles n)))
7639         (setq gnus-newsgroup-processable nil)
7640         (gnus-summary-limit articles))
7641     (gnus-summary-position-point)))
7642
7643 (defun gnus-summary-pop-limit (&optional total)
7644   "Restore the previous limit.
7645 If given a prefix, remove all limits."
7646   (interactive "P")
7647   (when total
7648     (setq gnus-newsgroup-limits
7649           (list (mapcar (lambda (h) (mail-header-number h))
7650                         gnus-newsgroup-headers))))
7651   (unless gnus-newsgroup-limits
7652     (error "No limit to pop"))
7653   (prog1
7654       (gnus-summary-limit nil 'pop)
7655     (gnus-summary-position-point)))
7656
7657 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7658   "Limit the summary buffer to articles that have subjects that match a regexp.
7659 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7660   (interactive
7661    (list (read-string (if current-prefix-arg
7662                           "Exclude subject (regexp): "
7663                         "Limit to subject (regexp): "))
7664          nil current-prefix-arg))
7665   (unless header
7666     (setq header "subject"))
7667   (when (not (equal "" subject))
7668     (prog1
7669         (let ((articles (gnus-summary-find-matching
7670                          (or header "subject") subject 'all nil nil
7671                          not-matching)))
7672           (unless articles
7673             (error "Found no matches for \"%s\"" subject))
7674           (gnus-summary-limit articles))
7675       (gnus-summary-position-point))))
7676
7677 (defun gnus-summary-limit-to-author (from &optional not-matching)
7678   "Limit the summary buffer to articles that have authors that match a regexp.
7679 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7680   (interactive
7681    (list (read-string (if current-prefix-arg
7682                           "Exclude author (regexp): "
7683                         "Limit to author (regexp): "))
7684          current-prefix-arg))
7685   (gnus-summary-limit-to-subject from "from" not-matching))
7686
7687 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7688   "Limit the summary buffer to articles with the given RECIPIENT.
7689
7690 If NOT-MATCHING, exclude RECIPIENT.
7691
7692 To and Cc headers are checked.  You need to include them in
7693 `nnmail-extra-headers'."
7694   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7695   (interactive
7696    (list (read-string (format "%s recipient (regexp): "
7697                               (if current-prefix-arg "Exclude" "Limit to")))
7698          current-prefix-arg))
7699   (when (not (equal "" recipient))
7700     (prog1 (let* ((to
7701                    (if (memq 'To nnmail-extra-headers)
7702                        (gnus-summary-find-matching
7703                         (cons 'extra 'To) recipient 'all nil nil
7704                         not-matching)
7705                      (gnus-message
7706                       1 "`To' isn't present in `nnmail-extra-headers'")
7707                      (sit-for 1)
7708                      nil))
7709                   (cc
7710                    (if (memq 'Cc nnmail-extra-headers)
7711                        (gnus-summary-find-matching
7712                         (cons 'extra 'Cc) recipient 'all nil nil
7713                         not-matching)
7714                      (gnus-message
7715                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7716                      (sit-for 1)
7717                      nil))
7718                   (articles
7719                    (if not-matching
7720                        ;; We need the numbers that are in both lists:
7721                        (mapcar (lambda (a)
7722                                  (and (memq a to) a))
7723                                cc)
7724                      (nconc to cc))))
7725              (unless articles
7726                (error "Found no matches for \"%s\"" recipient))
7727              (gnus-summary-limit articles))
7728       (gnus-summary-position-point))))
7729
7730 (defun gnus-summary-limit-to-age (age &optional younger-p)
7731   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7732 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7733 articles that are younger than AGE days."
7734   (interactive
7735    (let ((younger current-prefix-arg)
7736          (days-got nil)
7737          days)
7738      (while (not days-got)
7739        (setq days (if younger
7740                       (read-string "Limit to articles younger than (in days, older when negative): ")
7741                     (read-string
7742                      "Limit to articles older than (in days, younger when negative): ")))
7743        (when (> (length days) 0)
7744          (setq days (read days)))
7745        (if (numberp days)
7746            (progn
7747              (setq days-got t)
7748              (when (< days 0)
7749                (setq younger (not younger))
7750                (setq days (* days -1))))
7751          (message "Please enter a number.")
7752          (sleep-for 1)))
7753      (list days younger)))
7754   (prog1
7755       (let ((data gnus-newsgroup-data)
7756             (cutoff (days-to-time age))
7757             articles d date is-younger)
7758         (while (setq d (pop data))
7759           (when (and (vectorp (gnus-data-header d))
7760                      (setq date (mail-header-date (gnus-data-header d))))
7761             (setq is-younger (time-less-p
7762                               (time-since (condition-case ()
7763                                               (date-to-time date)
7764                                             (error '(0 0))))
7765                               cutoff))
7766             (when (if younger-p
7767                       is-younger
7768                     (not is-younger))
7769               (push (gnus-data-number d) articles))))
7770         (gnus-summary-limit (nreverse articles)))
7771     (gnus-summary-position-point)))
7772
7773 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7774   "Limit the summary buffer to articles that match an 'extra' header."
7775   (interactive
7776    (let ((header
7777           (intern
7778            (gnus-completing-read-with-default
7779             (symbol-name (car gnus-extra-headers))
7780             (if current-prefix-arg
7781                 "Exclude extra header:"
7782               "Limit extra header:")
7783             (mapcar (lambda (x)
7784                       (cons (symbol-name x) x))
7785                     gnus-extra-headers)
7786             nil
7787             t))))
7788      (list header
7789            (read-string (format "%s header %s (regexp): "
7790                                 (if current-prefix-arg "Exclude" "Limit to")
7791                                 header))
7792            current-prefix-arg)))
7793   (when (not (equal "" regexp))
7794     (prog1
7795         (let ((articles (gnus-summary-find-matching
7796                          (cons 'extra header) regexp 'all nil nil
7797                          not-matching)))
7798           (unless articles
7799             (error "Found no matches for \"%s\"" regexp))
7800           (gnus-summary-limit articles))
7801       (gnus-summary-position-point))))
7802
7803 (defun gnus-summary-limit-to-display-predicate ()
7804   "Limit the summary buffer to the predicated in the `display' group parameter."
7805   (interactive)
7806   (unless gnus-newsgroup-display
7807     (error "There is no `display' group parameter"))
7808   (let (articles)
7809     (dolist (number gnus-newsgroup-articles)
7810       (when (funcall gnus-newsgroup-display)
7811         (push number articles)))
7812     (gnus-summary-limit articles))
7813   (gnus-summary-position-point))
7814
7815 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7816 (make-obsolete
7817  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7818
7819 (defun gnus-summary-limit-to-unread (&optional all)
7820   "Limit the summary buffer to articles that are not marked as read.
7821 If ALL is non-nil, limit strictly to unread articles."
7822   (interactive "P")
7823   (if all
7824       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7825     (gnus-summary-limit-to-marks
7826      ;; Concat all the marks that say that an article is read and have
7827      ;; those removed.
7828      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7829            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7830            gnus-low-score-mark gnus-expirable-mark
7831            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7832            gnus-duplicate-mark gnus-souped-mark)
7833      'reverse)))
7834
7835 (defun gnus-summary-limit-to-replied (&optional unreplied)
7836   "Limit the summary buffer to replied articles.
7837 If UNREPLIED (the prefix), limit to unreplied articles."
7838   (interactive "P")
7839   (if unreplied
7840       (gnus-summary-limit
7841        (gnus-set-difference gnus-newsgroup-articles
7842         gnus-newsgroup-replied))
7843     (gnus-summary-limit gnus-newsgroup-replied))
7844   (gnus-summary-position-point))
7845
7846 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7847 (make-obsolete 'gnus-summary-delete-marked-with
7848                'gnus-summary-limit-exclude-marks)
7849
7850 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7851   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7852 If REVERSE, limit the summary buffer to articles that are marked
7853 with MARKS.  MARKS can either be a string of marks or a list of marks.
7854 Returns how many articles were removed."
7855   (interactive "sMarks: ")
7856   (gnus-summary-limit-to-marks marks t))
7857
7858 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7859   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7860 If REVERSE (the prefix), limit the summary buffer to articles that are
7861 not marked with MARKS.  MARKS can either be a string of marks or a
7862 list of marks.
7863 Returns how many articles were removed."
7864   (interactive "sMarks: \nP")
7865   (prog1
7866       (let ((data gnus-newsgroup-data)
7867             (marks (if (listp marks) marks
7868                      (append marks nil))) ; Transform to list.
7869             articles)
7870         (while data
7871           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7872                   (memq (gnus-data-mark (car data)) marks))
7873             (push (gnus-data-number (car data)) articles))
7874           (setq data (cdr data)))
7875         (gnus-summary-limit articles))
7876     (gnus-summary-position-point)))
7877
7878 (defun gnus-summary-limit-to-score (score)
7879   "Limit to articles with score at or above SCORE."
7880   (interactive "NLimit to articles with score of at least: ")
7881   (let ((data gnus-newsgroup-data)
7882         articles)
7883     (while data
7884       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7885                 score)
7886         (push (gnus-data-number (car data)) articles))
7887       (setq data (cdr data)))
7888     (prog1
7889         (gnus-summary-limit articles)
7890       (gnus-summary-position-point))))
7891
7892 (defun gnus-summary-limit-to-unseen ()
7893   "Limit to unseen articles."
7894   (interactive)
7895   (prog1
7896       (gnus-summary-limit gnus-newsgroup-unseen)
7897     (gnus-summary-position-point)))
7898
7899 (defun gnus-summary-limit-include-thread (id)
7900   "Display all the hidden articles that is in the thread with ID in it.
7901 When called interactively, ID is the Message-ID of the current
7902 article."
7903   (interactive (list (mail-header-id (gnus-summary-article-header))))
7904   (let ((articles (gnus-articles-in-thread
7905                    (gnus-id-to-thread (gnus-root-id id)))))
7906     (prog1
7907         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7908       (gnus-summary-limit-include-matching-articles
7909        "subject"
7910        (regexp-quote (gnus-simplify-subject-re
7911                       (mail-header-subject (gnus-id-to-header id)))))
7912       (gnus-summary-position-point))))
7913
7914 (defun gnus-summary-limit-include-matching-articles (header regexp)
7915   "Display all the hidden articles that have HEADERs that match REGEXP."
7916   (interactive (list (read-string "Match on header: ")
7917                      (read-string "Regexp: ")))
7918   (let ((articles (gnus-find-matching-articles header regexp)))
7919     (prog1
7920         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7921       (gnus-summary-position-point))))
7922
7923 (defun gnus-summary-insert-dormant-articles ()
7924   "Insert all the dormant articles for this group into the current buffer."
7925   (interactive)
7926   (let ((gnus-verbose (max 6 gnus-verbose)))
7927     (if (not gnus-newsgroup-dormant)
7928         (gnus-message 3 "No cached articles for this group")
7929       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7930
7931 (defun gnus-summary-limit-include-dormant ()
7932   "Display all the hidden articles that are marked as dormant.
7933 Note that this command only works on a subset of the articles currently
7934 fetched for this group."
7935   (interactive)
7936   (unless gnus-newsgroup-dormant
7937     (error "There are no dormant articles in this group"))
7938   (prog1
7939       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-limit-exclude-dormant ()
7943   "Hide all dormant articles."
7944   (interactive)
7945   (prog1
7946       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7947     (gnus-summary-position-point)))
7948
7949 (defun gnus-summary-limit-exclude-childless-dormant ()
7950   "Hide all dormant articles that have no children."
7951   (interactive)
7952   (let ((data (gnus-data-list t))
7953         articles d children)
7954     ;; Find all articles that are either not dormant or have
7955     ;; children.
7956     (while (setq d (pop data))
7957       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7958                 (and (setq children
7959                            (gnus-article-children (gnus-data-number d)))
7960                      (let (found)
7961                        (while children
7962                          (when (memq (car children) articles)
7963                            (setq children nil
7964                                  found t))
7965                          (pop children))
7966                        found)))
7967         (push (gnus-data-number d) articles)))
7968     ;; Do the limiting.
7969     (prog1
7970         (gnus-summary-limit articles)
7971       (gnus-summary-position-point))))
7972
7973 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7974   "Mark all unread excluded articles as read.
7975 If ALL, mark even excluded ticked and dormants as read."
7976   (interactive "P")
7977   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7978   (let ((articles (gnus-sorted-ndifference
7979                    (sort
7980                     (mapcar (lambda (h) (mail-header-number h))
7981                             gnus-newsgroup-headers)
7982                     '<)
7983                    gnus-newsgroup-limit))
7984         article)
7985     (setq gnus-newsgroup-unreads
7986           (gnus-sorted-intersection gnus-newsgroup-unreads
7987                                     gnus-newsgroup-limit))
7988     (if all
7989         (setq gnus-newsgroup-dormant nil
7990               gnus-newsgroup-marked nil
7991               gnus-newsgroup-reads
7992               (nconc
7993                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7994                gnus-newsgroup-reads))
7995       (while (setq article (pop articles))
7996         (unless (or (memq article gnus-newsgroup-dormant)
7997                     (memq article gnus-newsgroup-marked))
7998           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7999
8000 (defun gnus-summary-limit (articles &optional pop)
8001   (if pop
8002       ;; We pop the previous limit off the stack and use that.
8003       (setq articles (car gnus-newsgroup-limits)
8004             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8005     ;; We use the new limit, so we push the old limit on the stack.
8006     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8007   ;; Set the limit.
8008   (setq gnus-newsgroup-limit articles)
8009   (let ((total (length gnus-newsgroup-data))
8010         (data (gnus-data-find-list (gnus-summary-article-number)))
8011         (gnus-summary-mark-below nil)   ; Inhibit this.
8012         found)
8013     ;; This will do all the work of generating the new summary buffer
8014     ;; according to the new limit.
8015     (gnus-summary-prepare)
8016     ;; Hide any threads, possibly.
8017     (gnus-summary-maybe-hide-threads)
8018     ;; Try to return to the article you were at, or one in the
8019     ;; neighborhood.
8020     (when data
8021       ;; We try to find some article after the current one.
8022       (while data
8023         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8024           (setq data nil
8025                 found t))
8026         (setq data (cdr data))))
8027     (unless found
8028       ;; If there is no data, that means that we were after the last
8029       ;; article.  The same goes when we can't find any articles
8030       ;; after the current one.
8031       (goto-char (point-max))
8032       (gnus-summary-find-prev))
8033     (gnus-set-mode-line 'summary)
8034     ;; We return how many articles were removed from the summary
8035     ;; buffer as a result of the new limit.
8036     (- total (length gnus-newsgroup-data))))
8037
8038 (defsubst gnus-invisible-cut-children (threads)
8039   (let ((num 0))
8040     (while threads
8041       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8042         (incf num))
8043       (pop threads))
8044     (< num 2)))
8045
8046 (defsubst gnus-cut-thread (thread)
8047   "Go forwards in the thread until we find an article that we want to display."
8048   (when (or (eq gnus-fetch-old-headers 'some)
8049             (eq gnus-fetch-old-headers 'invisible)
8050             (numberp gnus-fetch-old-headers)
8051             (eq gnus-build-sparse-threads 'some)
8052             (eq gnus-build-sparse-threads 'more))
8053     ;; Deal with old-fetched headers and sparse threads.
8054     (while (and
8055             thread
8056             (or
8057              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8058              (gnus-summary-article-ancient-p
8059               (mail-header-number (car thread))))
8060             (if (or (<= (length (cdr thread)) 1)
8061                     (eq gnus-fetch-old-headers 'invisible))
8062                 (setq gnus-newsgroup-limit
8063                       (delq (mail-header-number (car thread))
8064                             gnus-newsgroup-limit)
8065                       thread (cadr thread))
8066               (when (gnus-invisible-cut-children (cdr thread))
8067                 (let ((th (cdr thread)))
8068                   (while th
8069                     (if (memq (mail-header-number (caar th))
8070                               gnus-newsgroup-limit)
8071                         (setq thread (car th)
8072                               th nil)
8073                       (setq th (cdr th))))))))))
8074   thread)
8075
8076 (defun gnus-cut-threads (threads)
8077   "Cut off all uninteresting articles from the beginning of THREADS."
8078   (when (or (eq gnus-fetch-old-headers 'some)
8079             (eq gnus-fetch-old-headers 'invisible)
8080             (numberp gnus-fetch-old-headers)
8081             (eq gnus-build-sparse-threads 'some)
8082             (eq gnus-build-sparse-threads 'more))
8083     (let ((th threads))
8084       (while th
8085         (setcar th (gnus-cut-thread (car th)))
8086         (setq th (cdr th)))))
8087   ;; Remove nixed out threads.
8088   (delq nil threads))
8089
8090 (defun gnus-summary-initial-limit (&optional show-if-empty)
8091   "Figure out what the initial limit is supposed to be on group entry.
8092 This entails weeding out unwanted dormants, low-scored articles,
8093 fetch-old-headers verbiage, and so on."
8094   ;; Most groups have nothing to remove.
8095   (if (or gnus-inhibit-limiting
8096           (and (null gnus-newsgroup-dormant)
8097                (eq gnus-newsgroup-display 'gnus-not-ignore)
8098                (not (eq gnus-fetch-old-headers 'some))
8099                (not (numberp gnus-fetch-old-headers))
8100                (not (eq gnus-fetch-old-headers 'invisible))
8101                (null gnus-summary-expunge-below)
8102                (not (eq gnus-build-sparse-threads 'some))
8103                (not (eq gnus-build-sparse-threads 'more))
8104                (null gnus-thread-expunge-below)
8105                (not gnus-use-nocem)))
8106       ()                                ; Do nothing.
8107     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8108     (setq gnus-newsgroup-limit nil)
8109     (mapatoms
8110      (lambda (node)
8111        (unless (car (symbol-value node))
8112          ;; These threads have no parents -- they are roots.
8113          (let ((nodes (cdr (symbol-value node)))
8114                thread)
8115            (while nodes
8116              (if (and gnus-thread-expunge-below
8117                       (< (gnus-thread-total-score (car nodes))
8118                          gnus-thread-expunge-below))
8119                  (gnus-expunge-thread (pop nodes))
8120                (setq thread (pop nodes))
8121                (gnus-summary-limit-children thread))))))
8122      gnus-newsgroup-dependencies)
8123     ;; If this limitation resulted in an empty group, we might
8124     ;; pop the previous limit and use it instead.
8125     (when (and (not gnus-newsgroup-limit)
8126                show-if-empty)
8127       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8128     gnus-newsgroup-limit))
8129
8130 (defun gnus-summary-limit-children (thread)
8131   "Return 1 if this subthread is visible and 0 if it is not."
8132   ;; First we get the number of visible children to this thread.  This
8133   ;; is done by recursing down the thread using this function, so this
8134   ;; will really go down to a leaf article first, before slowly
8135   ;; working its way up towards the root.
8136   (when thread
8137     (let* ((max-lisp-eval-depth 5000)
8138            (children
8139            (if (cdr thread)
8140                (apply '+ (mapcar 'gnus-summary-limit-children
8141                                  (cdr thread)))
8142              0))
8143           (number (mail-header-number (car thread)))
8144           score)
8145       (if (and
8146            (not (memq number gnus-newsgroup-marked))
8147            (or
8148             ;; If this article is dormant and has absolutely no visible
8149             ;; children, then this article isn't visible.
8150             (and (memq number gnus-newsgroup-dormant)
8151                  (zerop children))
8152             ;; If this is "fetch-old-headered" and there is no
8153             ;; visible children, then we don't want this article.
8154             (and (or (eq gnus-fetch-old-headers 'some)
8155                      (numberp gnus-fetch-old-headers))
8156                  (gnus-summary-article-ancient-p number)
8157                  (zerop children))
8158             ;; If this is "fetch-old-headered" and `invisible', then
8159             ;; we don't want this article.
8160             (and (eq gnus-fetch-old-headers 'invisible)
8161                  (gnus-summary-article-ancient-p number))
8162             ;; If this is a sparsely inserted article with no children,
8163             ;; we don't want it.
8164             (and (eq gnus-build-sparse-threads 'some)
8165                  (gnus-summary-article-sparse-p number)
8166                  (zerop children))
8167             ;; If we use expunging, and this article is really
8168             ;; low-scored, then we don't want this article.
8169             (when (and gnus-summary-expunge-below
8170                        (< (setq score
8171                                 (or (cdr (assq number gnus-newsgroup-scored))
8172                                     gnus-summary-default-score))
8173                           gnus-summary-expunge-below))
8174               ;; We increase the expunge-tally here, but that has
8175               ;; nothing to do with the limits, really.
8176               (incf gnus-newsgroup-expunged-tally)
8177               ;; We also mark as read here, if that's wanted.
8178               (when (and gnus-summary-mark-below
8179                          (< score gnus-summary-mark-below))
8180                 (setq gnus-newsgroup-unreads
8181                       (delq number gnus-newsgroup-unreads))
8182                 (if gnus-newsgroup-auto-expire
8183                     (push number gnus-newsgroup-expirable)
8184                   (push (cons number gnus-low-score-mark)
8185                         gnus-newsgroup-reads)))
8186               t)
8187             ;; Do the `display' group parameter.
8188             (and gnus-newsgroup-display
8189                  (not (funcall gnus-newsgroup-display)))
8190             ;; Check NoCeM things.
8191             (when (and gnus-use-nocem
8192                        (gnus-nocem-unwanted-article-p
8193                         (mail-header-id (car thread))))
8194               (setq gnus-newsgroup-unreads
8195                     (delq number gnus-newsgroup-unreads))
8196               t)))
8197           ;; Nope, invisible article.
8198           0
8199         ;; Ok, this article is to be visible, so we add it to the limit
8200         ;; and return 1.
8201         (push number gnus-newsgroup-limit)
8202         1))))
8203
8204 (defun gnus-expunge-thread (thread)
8205   "Mark all articles in THREAD as read."
8206   (let* ((number (mail-header-number (car thread))))
8207     (incf gnus-newsgroup-expunged-tally)
8208     ;; We also mark as read here, if that's wanted.
8209     (setq gnus-newsgroup-unreads
8210           (delq number gnus-newsgroup-unreads))
8211     (if gnus-newsgroup-auto-expire
8212         (push number gnus-newsgroup-expirable)
8213       (push (cons number gnus-low-score-mark)
8214             gnus-newsgroup-reads)))
8215   ;; Go recursively through all subthreads.
8216   (mapcar 'gnus-expunge-thread (cdr thread)))
8217
8218 ;; Summary article oriented commands
8219
8220 (defun gnus-summary-refer-parent-article (n)
8221   "Refer parent article N times.
8222 If N is negative, go to ancestor -N instead.
8223 The difference between N and the number of articles fetched is returned."
8224   (interactive "p")
8225   (let ((skip 1)
8226         error header ref)
8227     (when (not (natnump n))
8228       (setq skip (abs n)
8229             n 1))
8230     (while (and (> n 0)
8231                 (not error))
8232       (setq header (gnus-summary-article-header))
8233       (if (and (eq (mail-header-number header)
8234                    (cdr gnus-article-current))
8235                (equal gnus-newsgroup-name
8236                       (car gnus-article-current)))
8237           ;; If we try to find the parent of the currently
8238           ;; displayed article, then we take a look at the actual
8239           ;; References header, since this is slightly more
8240           ;; reliable than the References field we got from the
8241           ;; server.
8242           (save-excursion
8243             (set-buffer gnus-original-article-buffer)
8244             (nnheader-narrow-to-headers)
8245             (unless (setq ref (message-fetch-field "references"))
8246               (when (setq ref (message-fetch-field "in-reply-to"))
8247                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8248             (widen))
8249         (setq ref
8250               ;; It's not the current article, so we take a bet on
8251               ;; the value we got from the server.
8252               (mail-header-references header)))
8253       (if (and ref
8254                (not (equal ref "")))
8255           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8256             (gnus-message 1 "Couldn't find parent"))
8257         (gnus-message 1 "No references in article %d"
8258                       (gnus-summary-article-number))
8259         (setq error t))
8260       (decf n))
8261     (gnus-summary-position-point)
8262     n))
8263
8264 (defun gnus-summary-refer-references ()
8265   "Fetch all articles mentioned in the References header.
8266 Return the number of articles fetched."
8267   (interactive)
8268   (let ((ref (mail-header-references (gnus-summary-article-header)))
8269         (current (gnus-summary-article-number))
8270         (n 0))
8271     (if (or (not ref)
8272             (equal ref ""))
8273         (error "No References in the current article")
8274       ;; For each Message-ID in the References header...
8275       (while (string-match "<[^>]*>" ref)
8276         (incf n)
8277         ;; ... fetch that article.
8278         (gnus-summary-refer-article
8279          (prog1 (match-string 0 ref)
8280            (setq ref (substring ref (match-end 0))))))
8281       (gnus-summary-goto-subject current)
8282       (gnus-summary-position-point)
8283       n)))
8284
8285 (defun gnus-summary-refer-thread (&optional limit)
8286   "Fetch all articles in the current thread.
8287 If LIMIT (the numerical prefix), fetch that many old headers instead
8288 of what's specified by the `gnus-refer-thread-limit' variable."
8289   (interactive "P")
8290   (let ((id (mail-header-id (gnus-summary-article-header)))
8291         (limit (if limit (prefix-numeric-value limit)
8292                  gnus-refer-thread-limit)))
8293     (unless (eq gnus-fetch-old-headers 'invisible)
8294       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8295       ;; Retrieve the headers and read them in.
8296       (if (eq (if (numberp limit)
8297                   (gnus-retrieve-headers
8298                    (list (min
8299                           (+ (mail-header-number
8300                               (gnus-summary-article-header))
8301                              limit)
8302                           gnus-newsgroup-end))
8303                    gnus-newsgroup-name (* limit 2))
8304                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8305                 ;; headers.
8306                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8307                                        gnus-newsgroup-name limit))
8308               'nov)
8309           (gnus-build-all-threads)
8310         (error "Can't fetch thread from back ends that don't support NOV"))
8311       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8312     (gnus-summary-limit-include-thread id)))
8313
8314 (defun gnus-summary-refer-article (message-id)
8315   "Fetch an article specified by MESSAGE-ID."
8316   (interactive "sMessage-ID: ")
8317   (when (and (stringp message-id)
8318              (not (zerop (length message-id))))
8319     (setq message-id (gnus-replace-in-string message-id " " ""))
8320     ;; Construct the correct Message-ID if necessary.
8321     ;; Suggested by tale@pawl.rpi.edu.
8322     (unless (string-match "^<" message-id)
8323       (setq message-id (concat "<" message-id)))
8324     (unless (string-match ">$" message-id)
8325       (setq message-id (concat message-id ">")))
8326     ;; People often post MIDs from URLs, so unhex it:
8327     (unless (string-match "@" message-id)
8328       (setq message-id (gnus-url-unhex-string message-id)))
8329     (let* ((header (gnus-id-to-header message-id))
8330            (sparse (and header
8331                         (gnus-summary-article-sparse-p
8332                          (mail-header-number header))
8333                         (memq (mail-header-number header)
8334                               gnus-newsgroup-limit)))
8335            number)
8336       (cond
8337        ;; If the article is present in the buffer we just go to it.
8338        ((and header
8339              (or (not (gnus-summary-article-sparse-p
8340                        (mail-header-number header)))
8341                  sparse))
8342         (prog1
8343             (gnus-summary-goto-article
8344              (mail-header-number header) nil t)
8345           (when sparse
8346             (gnus-summary-update-article (mail-header-number header)))))
8347        (t
8348         ;; We fetch the article.
8349         (catch 'found
8350           (dolist (gnus-override-method (gnus-refer-article-methods))
8351             (when (and (gnus-check-server gnus-override-method)
8352                        ;; Fetch the header,
8353                        (setq number (gnus-summary-insert-subject message-id)))
8354               ;; and display the article.
8355               (gnus-summary-select-article nil nil nil number)
8356               (throw 'found t)))
8357           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8358
8359 (defun gnus-refer-article-methods ()
8360   "Return a list of referable methods."
8361   (cond
8362    ;; No method, so we default to current and native.
8363    ((null gnus-refer-article-method)
8364     (list gnus-current-select-method gnus-select-method))
8365    ;; Current.
8366    ((eq 'current gnus-refer-article-method)
8367     (list gnus-current-select-method))
8368    ;; List of select methods.
8369    ((not (and (symbolp (car gnus-refer-article-method))
8370               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8371     (let (out)
8372       (dolist (method gnus-refer-article-method)
8373         (push (if (eq 'current method)
8374                   gnus-current-select-method
8375                 method)
8376               out))
8377       (nreverse out)))
8378    ;; One single select method.
8379    (t
8380     (list gnus-refer-article-method))))
8381
8382 (defun gnus-summary-edit-parameters ()
8383   "Edit the group parameters of the current group."
8384   (interactive)
8385   (gnus-group-edit-group gnus-newsgroup-name 'params))
8386
8387 (defun gnus-summary-customize-parameters ()
8388   "Customize the group parameters of the current group."
8389   (interactive)
8390   (gnus-group-customize gnus-newsgroup-name))
8391
8392 (defun gnus-summary-enter-digest-group (&optional force)
8393   "Enter an nndoc group based on the current article.
8394 If FORCE, force a digest interpretation.  If not, try
8395 to guess what the document format is."
8396   (interactive "P")
8397   (let ((conf gnus-current-window-configuration))
8398     (save-window-excursion
8399       (save-excursion
8400         (let (gnus-article-prepare-hook
8401               gnus-display-mime-function
8402               gnus-break-pages)
8403           (gnus-summary-select-article))))
8404     (setq gnus-current-window-configuration conf)
8405     (let* ((name (format "%s-%d"
8406                          (gnus-group-prefixed-name
8407                           gnus-newsgroup-name (list 'nndoc ""))
8408                          (with-current-buffer gnus-summary-buffer
8409                            gnus-current-article)))
8410            (ogroup gnus-newsgroup-name)
8411            (params (append (gnus-info-params (gnus-get-info ogroup))
8412                            (list (cons 'to-group ogroup))
8413                            (list (cons 'parent-group ogroup))
8414                            (list (cons 'save-article-group ogroup))))
8415            (case-fold-search t)
8416            (buf (current-buffer))
8417            dig to-address)
8418       (save-excursion
8419         (set-buffer gnus-original-article-buffer)
8420         ;; Have the digest group inherit the main mail address of
8421         ;; the parent article.
8422         (when (setq to-address (or (gnus-fetch-field "reply-to")
8423                                    (gnus-fetch-field "from")))
8424           (setq params (append
8425                         (list (cons 'to-address
8426                                     (funcall gnus-decode-encoded-word-function
8427                                              to-address))))))
8428         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8429         (insert-buffer-substring gnus-original-article-buffer)
8430         ;; Remove lines that may lead nndoc to misinterpret the
8431         ;; document type.
8432         (narrow-to-region
8433          (goto-char (point-min))
8434          (or (search-forward "\n\n" nil t) (point)))
8435         (goto-char (point-min))
8436         (delete-matching-lines "^Path:\\|^From ")
8437         (widen))
8438       (unwind-protect
8439           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8440                     (gnus-newsgroup-ephemeral-ignored-charsets
8441                      gnus-newsgroup-ignored-charsets))
8442                 (gnus-group-read-ephemeral-group
8443                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8444                               (nndoc-article-type
8445                                ,(if force 'mbox 'guess)))
8446                  t nil nil nil
8447                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8448                                                         "ADAPT")))))
8449               ;; Make all postings to this group go to the parent group.
8450               (nconc (gnus-info-params (gnus-get-info name))
8451                      params)
8452             ;; Couldn't select this doc group.
8453             (switch-to-buffer buf)
8454             (gnus-set-global-variables)
8455             (gnus-configure-windows 'summary)
8456             (gnus-message 3 "Article couldn't be entered?"))
8457         (kill-buffer dig)))))
8458
8459 (defun gnus-summary-read-document (n)
8460   "Open a new group based on the current article(s).
8461 This will allow you to read digests and other similar
8462 documents as newsgroups.
8463 Obeys the standard process/prefix convention."
8464   (interactive "P")
8465   (let* ((ogroup gnus-newsgroup-name)
8466          (params (append (gnus-info-params (gnus-get-info ogroup))
8467                          (list (cons 'to-group ogroup))))
8468          group egroup groups vgroup)
8469     (dolist (article (gnus-summary-work-articles n))
8470       (setq group (format "%s-%d" gnus-newsgroup-name article))
8471       (gnus-summary-remove-process-mark article)
8472       (when (gnus-summary-display-article article)
8473         (save-excursion
8474           (with-temp-buffer
8475             (insert-buffer-substring gnus-original-article-buffer)
8476             ;; Remove some headers that may lead nndoc to make
8477             ;; the wrong guess.
8478             (message-narrow-to-head)
8479             (goto-char (point-min))
8480             (delete-matching-lines "^Path:\\|^From ")
8481             (widen)
8482             (if (setq egroup
8483                       (gnus-group-read-ephemeral-group
8484                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8485                                      (nndoc-article-type guess))
8486                        t nil t))
8487                 (progn
8488                   ;; Make all postings to this group go to the parent group.
8489                   (nconc (gnus-info-params (gnus-get-info egroup))
8490                          params)
8491                   (push egroup groups))
8492               ;; Couldn't select this doc group.
8493               (gnus-error 3 "Article couldn't be entered"))))))
8494     ;; Now we have selected all the documents.
8495     (cond
8496      ((not groups)
8497       (error "None of the articles could be interpreted as documents"))
8498      ((gnus-group-read-ephemeral-group
8499        (setq vgroup (format
8500                      "nnvirtual:%s-%s" gnus-newsgroup-name
8501                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8502        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8503        t
8504        (cons (current-buffer) 'summary)))
8505      (t
8506       (error "Couldn't select virtual nndoc group")))))
8507
8508 (defun gnus-summary-isearch-article (&optional regexp-p)
8509   "Do incremental search forward on the current article.
8510 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8511   (interactive "P")
8512   (let* ((gnus-inhibit-treatment t)
8513          (old (gnus-summary-select-article)))
8514     (gnus-configure-windows 'article)
8515     (gnus-eval-in-buffer-window gnus-article-buffer
8516       (save-restriction
8517         (widen)
8518         (when (eq 'old old)
8519           (gnus-article-show-all-headers))
8520         (goto-char (point-min))
8521         (isearch-forward regexp-p)))))
8522
8523 (defun gnus-summary-search-article-forward (regexp &optional backward)
8524   "Search for an article containing REGEXP forward.
8525 If BACKWARD, search backward instead."
8526   (interactive
8527    (list (read-string
8528           (format "Search article %s (regexp%s): "
8529                   (if current-prefix-arg "backward" "forward")
8530                   (if gnus-last-search-regexp
8531                       (concat ", default " gnus-last-search-regexp)
8532                     "")))
8533          current-prefix-arg))
8534   (if (string-equal regexp "")
8535       (setq regexp (or gnus-last-search-regexp ""))
8536     (setq gnus-last-search-regexp regexp)
8537     (setq gnus-article-before-search gnus-current-article))
8538   ;; Intentionally set gnus-last-article.
8539   (setq gnus-last-article gnus-article-before-search)
8540   (let ((gnus-last-article gnus-last-article))
8541     (if (gnus-summary-search-article regexp backward)
8542         (gnus-summary-show-thread)
8543       (signal 'search-failed (list regexp)))))
8544
8545 (defun gnus-summary-search-article-backward (regexp)
8546   "Search for an article containing REGEXP backward."
8547   (interactive
8548    (list (read-string
8549           (format "Search article backward (regexp%s): "
8550                   (if gnus-last-search-regexp
8551                       (concat ", default " gnus-last-search-regexp)
8552                     "")))))
8553   (gnus-summary-search-article-forward regexp 'backward))
8554
8555 (eval-when-compile
8556   (defmacro gnus-summary-search-article-position-point (regexp backward)
8557     "Dehighlight the last matched text and goto the beginning position."
8558     (` (if (and gnus-summary-search-article-matched-data
8559                 (let ((text (caddr gnus-summary-search-article-matched-data))
8560                       (inhibit-read-only t)
8561                       buffer-read-only)
8562                   (delete-region
8563                    (goto-char (car gnus-summary-search-article-matched-data))
8564                    (cadr gnus-summary-search-article-matched-data))
8565                   (insert text)
8566                   (string-match (, regexp) text)))
8567            (if (, backward) (beginning-of-line) (end-of-line))
8568          (goto-char (if (, backward) (point-max) (point-min))))))
8569
8570   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8571     "Place point where X-Face image is displayed."
8572     (if (featurep 'xemacs)
8573         (` (let ((end (if (search-forward "\n\n" nil t)
8574                           (goto-char (1- (point)))
8575                         (point-min)))
8576                  extent)
8577              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8578              (unless (and (re-search-forward "^From:" end t)
8579                           (setq extent (extent-at (point)))
8580                           (extent-begin-glyph extent))
8581                (goto-char (, opoint)))))
8582       (` (let ((end (if (search-forward "\n\n" nil t)
8583                         (goto-char (1- (point)))
8584                       (point-min)))
8585                (start (or (search-backward "\n\n" nil t) (point-min))))
8586            (goto-char
8587             (or (text-property-any start end 'x-face-image t);; x-face-e21
8588                 (text-property-any start end 'x-face-mule-bitmap-image t)
8589                 (, opoint)))))))
8590
8591   (defmacro gnus-summary-search-article-highlight-matched-text
8592     (backward treated x-face)
8593     "Highlight matched text in the function `gnus-summary-search-article'."
8594     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8595              (end (set-marker (make-marker) (match-end 0)))
8596              (inhibit-read-only t)
8597              buffer-read-only)
8598          (unless treated
8599            (let ((,@
8600                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8601                     (mapcar
8602                      (lambda (item) (setq items (delq item items)))
8603                      '(gnus-treat-buttonize
8604                        gnus-treat-fill-article
8605                        gnus-treat-fill-long-lines
8606                        gnus-treat-emphasize
8607                        gnus-treat-highlight-headers
8608                        gnus-treat-highlight-citation
8609                        gnus-treat-highlight-signature
8610                        gnus-treat-overstrike
8611                        gnus-treat-display-x-face
8612                        gnus-treat-buttonize-head
8613                        gnus-treat-decode-article-as-default-mime-charset))
8614                     (static-if (featurep 'xemacs)
8615                         items
8616                       (cons '(x-face-mule-delete-x-face-field
8617                               (quote never))
8618                             items))))
8619                  (gnus-treat-display-x-face
8620                   (when (, x-face) gnus-treat-display-x-face)))
8621              (gnus-article-prepare-mime-display)))
8622          (goto-char (if (, backward) start end))
8623          (when (, x-face)
8624            (gnus-summary-search-article-highlight-goto-x-face (point)))
8625          (setq gnus-summary-search-article-matched-data
8626                (list start end (buffer-substring start end)))
8627          (unless (eq start end);; matched text has been deleted. :-<
8628            (put-text-property start end 'face
8629                               (or (find-face 'isearch)
8630                                   'secondary-selection))))))
8631   )
8632
8633 (defun gnus-summary-search-article (regexp &optional backward)
8634   "Search for an article containing REGEXP.
8635 Optional argument BACKWARD means do search for backward.
8636 `gnus-select-article-hook' is not called during the search."
8637   ;; We have to require this here to make sure that the following
8638   ;; dynamic binding isn't shadowed by autoloading.
8639   (require 'gnus-async)
8640   (require 'gnus-art)
8641   (let ((gnus-select-article-hook nil)  ;Disable hook.
8642         (gnus-article-prepare-hook nil)
8643         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8644         (gnus-use-article-prefetch nil)
8645         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8646         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8647         (gnus-visual nil)
8648         (gnus-keep-backlog nil)
8649         (gnus-break-pages nil)
8650         (gnus-summary-display-arrow nil)
8651         (gnus-updated-mode-lines nil)
8652         (gnus-auto-center-summary nil)
8653         (sum (current-buffer))
8654         (found nil)
8655         point treated)
8656     (gnus-save-hidden-threads
8657       (static-if (featurep 'xemacs)
8658           (let ((gnus-inhibit-treatment t))
8659             (setq treated (eq 'old (gnus-summary-select-article)))
8660             (when (and treated
8661                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8662                                  (window-live-p (get-buffer-window
8663                                                  gnus-article-buffer t)))))
8664               (gnus-summary-select-article nil t)
8665               (setq treated nil)))
8666         (let ((gnus-inhibit-treatment t)
8667               (x-face-mule-delete-x-face-field 'never))
8668           (setq treated (eq 'old (gnus-summary-select-article)))
8669           (when (and treated
8670                      (not
8671                       (and (gnus-buffer-live-p gnus-article-buffer)
8672                            (window-live-p (get-buffer-window
8673                                            gnus-article-buffer t))
8674                            (or (not (string-match "^\\^X-Face:" regexp))
8675                                (with-current-buffer gnus-article-buffer
8676                                  gnus-summary-search-article-matched-data)))))
8677             (gnus-summary-select-article nil t)
8678             (setq treated nil))))
8679       (set-buffer gnus-article-buffer)
8680       (widen)
8681       (if treated
8682           (progn
8683             (gnus-article-show-all-headers)
8684             (gnus-summary-search-article-position-point regexp backward))
8685         (goto-char (if backward (point-max) (point-min))))
8686       (while (not found)
8687         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8688         (if (if backward
8689                 (re-search-backward regexp nil t)
8690               (re-search-forward regexp nil t))
8691             ;; We found the regexp.
8692             (progn
8693               (gnus-summary-search-article-highlight-matched-text
8694                backward treated (string-match "^\\^X-Face:" regexp))
8695               (setq found 'found)
8696               (forward-line
8697                (/ (- 2 (window-height
8698                         (get-buffer-window gnus-article-buffer t)))
8699                   2))
8700               (set-window-start
8701                (get-buffer-window (current-buffer))
8702                (point))
8703               (set-buffer sum)
8704               (setq point (point)))
8705           ;; We didn't find it, so we go to the next article.
8706           (set-buffer sum)
8707           (setq found 'not)
8708           (while (eq found 'not)
8709             (if (not (if backward (gnus-summary-find-prev)
8710                        (gnus-summary-find-next)))
8711                 ;; No more articles.
8712                 (setq found t)
8713               ;; Select the next article and adjust point.
8714               (unless (gnus-summary-article-sparse-p
8715                        (gnus-summary-article-number))
8716                 (setq found nil)
8717                 (let ((gnus-inhibit-treatment t))
8718                   (gnus-summary-select-article))
8719                 (setq treated nil)
8720                 (set-buffer gnus-article-buffer)
8721                 (widen)
8722                 (goto-char (if backward (point-max) (point-min))))))))
8723       (gnus-message 7 ""))
8724     ;; Return whether we found the regexp.
8725     (when (eq found 'found)
8726       (goto-char point)
8727       (gnus-summary-show-thread)
8728       (gnus-summary-goto-subject gnus-current-article)
8729       (gnus-summary-position-point)
8730       t)))
8731
8732 (defun gnus-find-matching-articles (header regexp)
8733   "Return a list of all articles that match REGEXP on HEADER.
8734 This search includes all articles in the current group that Gnus has
8735 fetched headers for, whether they are displayed or not."
8736   (let ((articles nil)
8737         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8738         (case-fold-search t))
8739     (dolist (header gnus-newsgroup-headers)
8740       (when (string-match regexp (funcall func header))
8741         (push (mail-header-number header) articles)))
8742     (nreverse articles)))
8743
8744 (defun gnus-summary-find-matching (header regexp &optional backward unread
8745                                           not-case-fold not-matching)
8746   "Return a list of all articles that match REGEXP on HEADER.
8747 The search stars on the current article and goes forwards unless
8748 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8749 If UNREAD is non-nil, only unread articles will
8750 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8751 in the comparisons. If NOT-MATCHING, return a list of all articles that
8752 not match REGEXP on HEADER."
8753   (let ((case-fold-search (not not-case-fold))
8754         articles d func)
8755     (if (consp header)
8756         (if (eq (car header) 'extra)
8757             (setq func
8758                   `(lambda (h)
8759                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8760                          "")))
8761           (error "%s is an invalid header" header))
8762       (unless (fboundp (intern (concat "mail-header-" header)))
8763         (error "%s is not a valid header" header))
8764       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8765     (dolist (d (if (eq backward 'all)
8766                    gnus-newsgroup-data
8767                  (gnus-data-find-list
8768                   (gnus-summary-article-number)
8769                   (gnus-data-list backward))))
8770       (when (and (or (not unread)       ; We want all articles...
8771                      (gnus-data-unread-p d)) ; Or just unreads.
8772                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8773                  (if not-matching
8774                      (not (string-match
8775                            regexp
8776                            (funcall func (gnus-data-header d))))
8777                    (string-match regexp
8778                                  (funcall func (gnus-data-header d)))))
8779         (push (gnus-data-number d) articles))) ; Success!
8780     (nreverse articles)))
8781
8782 (defun gnus-summary-execute-command (header regexp command &optional backward)
8783   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8784 If HEADER is an empty string (or nil), the match is done on the entire
8785 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8786   (interactive
8787    (list (let ((completion-ignore-case t))
8788            (completing-read
8789             "Header name: "
8790             (mapcar (lambda (header) (list (format "%s" header)))
8791                     (append
8792                      '("Number" "Subject" "From" "Lines" "Date"
8793                        "Message-ID" "Xref" "References" "Body")
8794                      gnus-extra-headers))
8795             nil 'require-match))
8796          (read-string "Regexp: ")
8797          (read-key-sequence "Command: ")
8798          current-prefix-arg))
8799   (when (equal header "Body")
8800     (setq header ""))
8801   ;; Hidden thread subtrees must be searched as well.
8802   (gnus-summary-show-all-threads)
8803   ;; We don't want to change current point nor window configuration.
8804   (save-excursion
8805     (save-window-excursion
8806       (let (gnus-visual
8807             gnus-treat-strip-trailing-blank-lines
8808             gnus-treat-strip-leading-blank-lines
8809             gnus-treat-strip-multiple-blank-lines
8810             gnus-treat-hide-boring-headers
8811             gnus-treat-fold-newsgroups
8812             gnus-article-prepare-hook)
8813         (gnus-message 6 "Executing %s..." (key-description command))
8814         ;; We'd like to execute COMMAND interactively so as to give arguments.
8815         (gnus-execute header regexp
8816                       `(call-interactively ',(key-binding command))
8817                       backward)
8818         (gnus-message 6 "Executing %s...done" (key-description command))))))
8819
8820 (defun gnus-summary-beginning-of-article ()
8821   "Scroll the article back to the beginning."
8822   (interactive)
8823   (gnus-summary-select-article)
8824   (gnus-configure-windows 'article)
8825   (gnus-eval-in-buffer-window gnus-article-buffer
8826     (widen)
8827     (goto-char (point-min))
8828     (when gnus-break-pages
8829       (gnus-narrow-to-page))))
8830
8831 (defun gnus-summary-end-of-article ()
8832   "Scroll to the end of the article."
8833   (interactive)
8834   (gnus-summary-select-article)
8835   (gnus-configure-windows 'article)
8836   (gnus-eval-in-buffer-window gnus-article-buffer
8837     (widen)
8838     (goto-char (point-max))
8839     (recenter -3)
8840     (when gnus-break-pages
8841       (when (re-search-backward page-delimiter nil t)
8842         (narrow-to-region (match-end 0) (point-max)))
8843       (gnus-narrow-to-page))))
8844
8845 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8846   "Truncate to LEN and quote all \"(\"'s in STRING."
8847   (gnus-replace-in-string (if (and len (> (length string) len))
8848                               (substring string 0 len)
8849                             string)
8850                           "[()]" "\\\\\\&"))
8851
8852 (defun gnus-summary-print-article (&optional filename n)
8853   "Generate and print a PostScript image of the process-marked (mail) articles.
8854
8855 If used interactively, print the current article if none are
8856 process-marked.  With prefix arg, prompt the user for the name of the
8857 file to save in.
8858
8859 When used from Lisp, accept two optional args FILENAME and N.  N means
8860 to print the next N articles.  If N is negative, print the N previous
8861 articles.  If N is nil and articles have been marked with the process
8862 mark, print these instead.
8863
8864 If the optional first argument FILENAME is nil, send the image to the
8865 printer.  If FILENAME is a string, save the PostScript image in a file with
8866 that name.  If FILENAME is a number, prompt the user for the name of the file
8867 to save in."
8868   (interactive (list (ps-print-preprint current-prefix-arg)))
8869   (dolist (article (gnus-summary-work-articles n))
8870     (gnus-summary-select-article nil nil 'pseudo article)
8871     (gnus-eval-in-buffer-window gnus-article-buffer
8872       (gnus-print-buffer))
8873     (gnus-summary-remove-process-mark article))
8874   (ps-despool filename))
8875
8876 (defun gnus-print-buffer ()
8877   (let ((buffer (generate-new-buffer " *print*")))
8878     (unwind-protect
8879         (progn
8880           (copy-to-buffer buffer (point-min) (point-max))
8881           (set-buffer buffer)
8882           (gnus-remove-text-with-property 'gnus-decoration)
8883           (when (gnus-visual-p 'article-highlight 'highlight)
8884             ;; Copy-to-buffer doesn't copy overlay.  So redo
8885             ;; highlight.
8886             (let ((gnus-article-buffer buffer))
8887               (gnus-article-highlight-citation t)
8888               (gnus-article-highlight-signature)
8889               (gnus-article-emphasize)
8890               (gnus-article-delete-invisible-text)))
8891           (let ((ps-left-header
8892                  (list
8893                   (concat "("
8894                           (gnus-summary-print-truncate-and-quote
8895                            (mail-header-subject gnus-current-headers)
8896                            66) ")")
8897                   (concat "("
8898                           (gnus-summary-print-truncate-and-quote
8899                            (mail-header-from gnus-current-headers)
8900                            45) ")")))
8901                 (ps-right-header
8902                  (list
8903                   "/pagenumberstring load"
8904                   (concat "("
8905                           (mail-header-date gnus-current-headers) ")"))))
8906             (gnus-run-hooks 'gnus-ps-print-hook)
8907             (save-excursion
8908               (if window-system
8909                   (ps-spool-buffer-with-faces)
8910                 (ps-spool-buffer)))))
8911       (kill-buffer buffer))))
8912
8913 (defun gnus-summary-show-article (&optional arg)
8914   "Force redisplaying of the current article.
8915 If ARG (the prefix) is a number, show the article with the charset
8916 defined in `gnus-summary-show-article-charset-alist', or the charset
8917 input.
8918 If ARG (the prefix) is non-nil and not a number, show the raw article
8919 without any article massaging functions being run.  Normally, the key
8920 strokes are `C-u g'."
8921   (interactive "P")
8922   (cond
8923    ((numberp arg)
8924     (gnus-summary-show-article t)
8925     (let* ((gnus-newsgroup-charset
8926             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8927                 (mm-read-coding-system
8928                  "View as charset: " ;; actually it is coding system.
8929                  (with-current-buffer gnus-article-buffer
8930                    (mm-detect-coding-region (point) (point-max))))))
8931            (default-mime-charset gnus-newsgroup-charset)
8932            (gnus-newsgroup-ignored-charsets 'gnus-all))
8933       (gnus-summary-select-article nil 'force)
8934       (let ((deps gnus-newsgroup-dependencies)
8935             head header lines)
8936         (save-excursion
8937           (set-buffer gnus-original-article-buffer)
8938           (save-restriction
8939             (message-narrow-to-head)
8940             (setq head (buffer-string))
8941             (goto-char (point-min))
8942             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8943               (goto-char (point-max))
8944               (widen)
8945               (setq lines (1- (count-lines (point) (point-max))))))
8946           (with-temp-buffer
8947             (insert (format "211 %d Article retrieved.\n"
8948                             (cdr gnus-article-current)))
8949             (insert head)
8950             (if lines (insert (format "Lines: %d\n" lines)))
8951             (insert ".\n")
8952             (let ((nntp-server-buffer (current-buffer)))
8953               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8954         (gnus-data-set-header
8955          (gnus-data-find (cdr gnus-article-current))
8956          header)
8957         (gnus-summary-update-article-line
8958          (cdr gnus-article-current) header)
8959         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8960           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8961    ((not arg)
8962     ;; Select the article the normal way.
8963     (gnus-summary-select-article nil 'force))
8964    (t
8965     ;; We have to require this here to make sure that the following
8966     ;; dynamic binding isn't shadowed by autoloading.
8967     (require 'gnus-async)
8968     (require 'gnus-art)
8969     ;; Bind the article treatment functions to nil.
8970     (let ((gnus-have-all-headers t)
8971           gnus-article-prepare-hook
8972           gnus-article-decode-hook
8973           gnus-break-pages
8974           gnus-show-mime
8975           (gnus-inhibit-treatment t))
8976       (gnus-summary-select-article nil 'force))))
8977   (gnus-summary-goto-subject gnus-current-article)
8978   (gnus-summary-position-point))
8979
8980 (defun gnus-summary-show-raw-article ()
8981   "Show the raw article without any article massaging functions being run."
8982   (interactive)
8983   (gnus-summary-show-article t))
8984
8985 (defun gnus-summary-verbose-headers (&optional arg)
8986   "Toggle permanent full header display.
8987 If ARG is a positive number, turn header display on.
8988 If ARG is a negative number, turn header display off."
8989   (interactive "P")
8990   (setq gnus-show-all-headers
8991         (cond ((or (not (numberp arg))
8992                    (zerop arg))
8993                (not gnus-show-all-headers))
8994               ((natnump arg)
8995                t)))
8996   (gnus-summary-show-article))
8997
8998 (defun gnus-summary-toggle-header (&optional arg)
8999   "Show the headers if they are hidden, or hide them if they are shown.
9000 If ARG is a positive number, show the entire header.
9001 If ARG is a negative number, hide the unwanted header lines."
9002   (interactive "P")
9003   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9004                      (get-buffer-window gnus-article-buffer t))))
9005     (with-current-buffer gnus-article-buffer
9006       (widen)
9007       (article-narrow-to-head)
9008       (let* ((buffer-read-only nil)
9009              (inhibit-point-motion-hooks t)
9010              (hidden (if (numberp arg)
9011                          (>= arg 0)
9012                        (or (not (looking-at "[^ \t\n]+:"))
9013                            (gnus-article-hidden-text-p 'headers))))
9014              s e)
9015         (delete-region (point-min) (point-max))
9016         (with-current-buffer gnus-original-article-buffer
9017           (goto-char (setq s (point-min)))
9018           (setq e (if (search-forward "\n\n" nil t)
9019                       (1- (point))
9020                     (point-max))))
9021         (insert-buffer-substring gnus-original-article-buffer s e)
9022         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9023         ;; article-decode-encoded-words by default.
9024         (article-decode-encoded-words)
9025         (run-hooks 'gnus-article-decode-hook)
9026         (if hidden
9027             (let ((gnus-treat-hide-headers nil)
9028                   (gnus-treat-hide-boring-headers nil))
9029               (gnus-delete-wash-type 'headers)
9030               (gnus-treat-article 'head))
9031           (gnus-treat-article 'head))
9032         (widen)
9033         (if window
9034             (set-window-start window (goto-char (point-min))))
9035         (if gnus-break-pages
9036             (gnus-narrow-to-page)
9037           (when (gnus-visual-p 'page-marker)
9038             (let ((buffer-read-only nil))
9039               (gnus-remove-text-with-property 'gnus-prev)
9040               (gnus-remove-text-with-property 'gnus-next))))
9041         (gnus-set-mode-line 'article)))))
9042
9043 (defun gnus-summary-show-all-headers ()
9044   "Make all header lines visible."
9045   (interactive)
9046   (gnus-summary-toggle-header 1))
9047
9048 (defun gnus-summary-toggle-mime (&optional arg)
9049   "Toggle MIME processing.
9050 If ARG is a positive number, turn MIME processing on."
9051   (interactive "P")
9052   (setq gnus-show-mime
9053         (if (null arg)
9054             (not gnus-show-mime)
9055           (> (prefix-numeric-value arg) 0)))
9056   (gnus-summary-select-article t 'force))
9057
9058 (defun gnus-summary-caesar-message (&optional arg)
9059   "Caesar rotate the current article by 13.
9060 The numerical prefix specifies how many places to rotate each letter
9061 forward."
9062   (interactive "P")
9063   (gnus-summary-select-article)
9064   (let ((mail-header-separator ""))
9065     (gnus-eval-in-buffer-window gnus-article-buffer
9066       (save-restriction
9067         (widen)
9068         (let ((start (window-start))
9069               buffer-read-only)
9070           (message-caesar-buffer-body arg)
9071           (set-window-start (get-buffer-window (current-buffer)) start))))))
9072
9073 (autoload 'unmorse-region "morse"
9074   "Convert morse coded text in region to ordinary ASCII text."
9075   t)
9076
9077 (defun gnus-summary-morse-message (&optional arg)
9078   "Morse decode the current article."
9079   (interactive "P")
9080   (gnus-summary-select-article)
9081   (let ((mail-header-separator ""))
9082     (gnus-eval-in-buffer-window gnus-article-buffer
9083       (save-excursion
9084         (save-restriction
9085           (widen)
9086           (let ((pos (window-start))
9087                 buffer-read-only)
9088             (goto-char (point-min))
9089             (when (message-goto-body)
9090               (gnus-narrow-to-body))
9091             (goto-char (point-min))
9092             (while (search-forward "·" (point-max) t)
9093               (replace-match "."))
9094             (unmorse-region (point-min) (point-max))
9095             (widen)
9096             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9097
9098 (defun gnus-summary-stop-page-breaking ()
9099   "Stop page breaking in the current article."
9100   (interactive)
9101   (gnus-summary-select-article)
9102   (gnus-eval-in-buffer-window gnus-article-buffer
9103     (widen)
9104     (when (gnus-visual-p 'page-marker)
9105       (let ((buffer-read-only nil))
9106         (gnus-remove-text-with-property 'gnus-prev)
9107         (gnus-remove-text-with-property 'gnus-next))
9108       (setq gnus-page-broken nil))))
9109
9110 (defun gnus-summary-move-article (&optional n to-newsgroup
9111                                             select-method action)
9112   "Move the current article to a different newsgroup.
9113 If N is a positive number, move the N next articles.
9114 If N is a negative number, move the N previous articles.
9115 If N is nil and any articles have been marked with the process mark,
9116 move those articles instead.
9117 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9118 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9119 re-spool using this method.
9120
9121 When called interactively with TO-NEWSGROUP being nil, the value of
9122 the variable `gnus-move-split-methods' is used for finding a default
9123 for the target newsgroup.
9124
9125 For this function to work, both the current newsgroup and the
9126 newsgroup that you want to move to have to support the `request-move'
9127 and `request-accept' functions.
9128
9129 ACTION can be either `move' (the default), `crosspost' or `copy'."
9130   (interactive "P")
9131   (unless action
9132     (setq action 'move))
9133   ;; Check whether the source group supports the required functions.
9134   (cond ((and (eq action 'move)
9135               (not (gnus-check-backend-function
9136                     'request-move-article gnus-newsgroup-name)))
9137          (error "The current group does not support article moving"))
9138         ((and (eq action 'crosspost)
9139               (not (gnus-check-backend-function
9140                     'request-replace-article gnus-newsgroup-name)))
9141          (error "The current group does not support article editing")))
9142   (let ((articles (gnus-summary-work-articles n))
9143         (prefix (if (gnus-check-backend-function
9144                      'request-move-article gnus-newsgroup-name)
9145                     (funcall gnus-move-group-prefix-function
9146                              gnus-newsgroup-name)
9147                   ""))
9148         (names '((move "Move" "Moving")
9149                  (copy "Copy" "Copying")
9150                  (crosspost "Crosspost" "Crossposting")))
9151         (copy-buf (save-excursion
9152                     (nnheader-set-temp-buffer " *copy article*")))
9153         art-group to-method new-xref article to-groups)
9154     (unless (assq action names)
9155       (error "Unknown action %s" action))
9156     ;; Read the newsgroup name.
9157     (when (and (not to-newsgroup)
9158                (not select-method))
9159       (if (and gnus-move-split-methods
9160                (not
9161                 (and (memq gnus-current-article articles)
9162                      (gnus-buffer-live-p gnus-original-article-buffer))))
9163           ;; When `gnus-move-split-methods' is non-nil, we have to
9164           ;; select an article to give `gnus-read-move-group-name' an
9165           ;; opportunity to suggest an appropriate default.  However,
9166           ;; we needn't render or mark the article.
9167           (let ((gnus-display-mime-function nil)
9168                 (gnus-article-prepare-hook nil)
9169                 (gnus-mark-article-hook nil))
9170             (gnus-summary-select-article nil nil nil (car articles))))
9171       (setq to-newsgroup
9172             (gnus-read-move-group-name
9173              (cadr (assq action names))
9174              (symbol-value (intern (format "gnus-current-%s-group" action)))
9175              articles prefix))
9176       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9177     (setq to-method (or select-method
9178                         (gnus-server-to-method
9179                          (gnus-group-method to-newsgroup))))
9180     ;; Check the method we are to move this article to...
9181     (unless (gnus-check-backend-function
9182              'request-accept-article (car to-method))
9183       (error "%s does not support article copying" (car to-method)))
9184     (unless (gnus-check-server to-method)
9185       (error "Can't open server %s" (car to-method)))
9186     (gnus-message 6 "%s to %s: %s..."
9187                   (caddr (assq action names))
9188                   (or (car select-method) to-newsgroup) articles)
9189     (while articles
9190       (setq article (pop articles))
9191       (setq
9192        art-group
9193        (cond
9194         ;; Move the article.
9195         ((eq action 'move)
9196          ;; Remove this article from future suppression.
9197          (gnus-dup-unsuppress-article article)
9198          (gnus-request-move-article
9199           article                       ; Article to move
9200           gnus-newsgroup-name           ; From newsgroup
9201           (nth 1 (gnus-find-method-for-group
9202                   gnus-newsgroup-name)) ; Server
9203           (list 'gnus-request-accept-article
9204                 to-newsgroup (list 'quote select-method)
9205                 (not articles) t)       ; Accept form
9206           (not articles)))              ; Only save nov last time
9207         ;; Copy the article.
9208         ((eq action 'copy)
9209          (save-excursion
9210            (set-buffer copy-buf)
9211            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9212              (save-restriction
9213                (nnheader-narrow-to-headers)
9214                (dolist (hdr gnus-copy-article-ignored-headers)
9215                  (message-remove-header hdr t)))
9216              (gnus-request-accept-article
9217               to-newsgroup select-method (not articles) t))))
9218         ;; Crosspost the article.
9219         ((eq action 'crosspost)
9220          (let ((xref (message-tokenize-header
9221                       (mail-header-xref (gnus-summary-article-header article))
9222                       " ")))
9223            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9224                                   ":" (number-to-string article)))
9225            (unless xref
9226              (setq xref (list (system-name))))
9227            (setq new-xref
9228                  (concat
9229                   (mapconcat 'identity
9230                              (delete "Xref:" (delete new-xref xref))
9231                              " ")
9232                   " " new-xref))
9233            (save-excursion
9234              (set-buffer copy-buf)
9235              ;; First put the article in the destination group.
9236              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9237              (when (consp (setq art-group
9238                                 (gnus-request-accept-article
9239                                  to-newsgroup select-method (not articles))))
9240                (setq new-xref (concat new-xref " " (car art-group)
9241                                       ":"
9242                                       (number-to-string (cdr art-group))))
9243                ;; Now we have the new Xrefs header, so we insert
9244                ;; it and replace the new article.
9245                (nnheader-replace-header "Xref" new-xref)
9246                (gnus-request-replace-article
9247                 (cdr art-group) to-newsgroup (current-buffer))
9248                art-group))))))
9249       (cond
9250        ((not art-group)
9251         (gnus-message 1 "Couldn't %s article %s: %s"
9252                       (cadr (assq action names)) article
9253                       (nnheader-get-report (car to-method))))
9254        ((eq art-group 'junk)
9255         (when (eq action 'move)
9256           (gnus-summary-mark-article article gnus-canceled-mark)
9257           (gnus-message 4 "Deleted article %s" article)
9258           ;; run the delete hook
9259           (run-hook-with-args 'gnus-summary-article-delete-hook
9260                               action
9261                               (gnus-data-header
9262                                (assoc article (gnus-data-list nil)))
9263                               gnus-newsgroup-name nil
9264                               select-method)))
9265        (t
9266         (let* ((pto-group (gnus-group-prefixed-name
9267                            (car art-group) to-method))
9268                (info (gnus-get-info pto-group))
9269                (to-group (gnus-info-group info))
9270                to-marks)
9271           ;; Update the group that has been moved to.
9272           (when (and info
9273                      (memq action '(move copy)))
9274             (unless (member to-group to-groups)
9275               (push to-group to-groups))
9276
9277             (unless (memq article gnus-newsgroup-unreads)
9278               (push 'read to-marks)
9279               (gnus-info-set-read
9280                info (gnus-add-to-range (gnus-info-read info)
9281                                        (list (cdr art-group)))))
9282
9283             ;; See whether the article is to be put in the cache.
9284             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9285                              gnus-article-mark-lists
9286                            (delete '(expirable . expire)
9287                                    (copy-sequence gnus-article-mark-lists))))
9288                   (to-article (cdr art-group)))
9289
9290               ;; Enter the article into the cache in the new group,
9291               ;; if that is required.
9292               (when gnus-use-cache
9293                 (gnus-cache-possibly-enter-article
9294                  to-group to-article
9295                  (let ((header (copy-sequence
9296                                 (gnus-summary-article-header article))))
9297                    (mail-header-set-number header to-article)
9298                    header)
9299                  (memq article gnus-newsgroup-marked)
9300                  (memq article gnus-newsgroup-dormant)
9301                  (memq article gnus-newsgroup-unreads)))
9302
9303               (when gnus-preserve-marks
9304                 ;; Copy any marks over to the new group.
9305                 (when (and (equal to-group gnus-newsgroup-name)
9306                            (not (memq article gnus-newsgroup-unreads)))
9307                   ;; Mark this article as read in this group.
9308                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9309                   (setcdr (gnus-active to-group) to-article)
9310                   (setcdr gnus-newsgroup-active to-article))
9311
9312                 (while marks
9313                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9314                     (when (memq article (symbol-value
9315                                          (intern (format "gnus-newsgroup-%s"
9316                                                          (caar marks)))))
9317                       (push (cdar marks) to-marks)
9318                       ;; If the other group is the same as this group,
9319                       ;; then we have to add the mark to the list.
9320                       (when (equal to-group gnus-newsgroup-name)
9321                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9322                              (cons to-article
9323                                    (symbol-value
9324                                     (intern (format "gnus-newsgroup-%s"
9325                                                     (caar marks)))))))
9326                       ;; Copy the marks to other group.
9327                       (gnus-add-marked-articles
9328                        to-group (cdar marks) (list to-article) info)))
9329                   (setq marks (cdr marks)))
9330
9331                 (gnus-request-set-mark
9332                  to-group (list (list (list to-article) 'add to-marks))))
9333
9334               (gnus-dribble-enter
9335                (concat "(gnus-group-set-info '"
9336                        (gnus-prin1-to-string (gnus-get-info to-group))
9337                        ")"))))
9338
9339           ;; Update the Xref header in this article to point to
9340           ;; the new crossposted article we have just created.
9341           (when (eq action 'crosspost)
9342             (save-excursion
9343               (set-buffer copy-buf)
9344               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9345               (nnheader-replace-header "Xref" new-xref)
9346               (gnus-request-replace-article
9347                article gnus-newsgroup-name (current-buffer))))
9348
9349           ;; run the move/copy/crosspost/respool hook
9350           (run-hook-with-args 'gnus-summary-article-move-hook
9351                               action
9352                               (gnus-data-header
9353                                (assoc article (gnus-data-list nil)))
9354                               gnus-newsgroup-name
9355                               to-newsgroup
9356                               select-method))
9357
9358         ;;;!!!Why is this necessary?
9359         (set-buffer gnus-summary-buffer)
9360         
9361         (gnus-summary-goto-subject article)
9362         (when (eq action 'move)
9363           (gnus-summary-mark-article article gnus-canceled-mark))))
9364       (gnus-summary-remove-process-mark article))
9365     ;; Re-activate all groups that have been moved to.
9366     (save-excursion
9367       (set-buffer gnus-group-buffer)
9368       (let ((gnus-group-marked to-groups))
9369         (gnus-group-get-new-news-this-group nil t)))
9370
9371     (gnus-kill-buffer copy-buf)
9372     (gnus-summary-position-point)
9373     (gnus-set-mode-line 'summary)))
9374
9375 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9376   "Copy the current article to some other group.
9377 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9378 When called interactively, if TO-NEWSGROUP is nil, use the value of
9379 the variable `gnus-move-split-methods' for finding a default target
9380 newsgroup.
9381 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9382 re-spool using this method."
9383   (interactive "P")
9384   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9385
9386 (defun gnus-summary-crosspost-article (&optional n)
9387   "Crosspost the current article to some other group."
9388   (interactive "P")
9389   (gnus-summary-move-article n nil nil 'crosspost))
9390
9391 (defcustom gnus-summary-respool-default-method nil
9392   "Default method type for respooling an article.
9393 If nil, use to the current newsgroup method."
9394   :type 'symbol
9395   :group 'gnus-summary-mail)
9396
9397 (defcustom gnus-summary-display-while-building nil
9398   "If non-nil, show and update the summary buffer as it's being built.
9399 If the value is t, update the buffer after every line is inserted.  If
9400 the value is an integer (N), update the display every N lines."
9401   :version "21.4"
9402   :group 'gnus-thread
9403   :type '(choice (const :tag "off" nil)
9404                  number
9405                  (const :tag "frequently" t)))
9406
9407 (defun gnus-summary-respool-article (&optional n method)
9408   "Respool the current article.
9409 The article will be squeezed through the mail spooling process again,
9410 which means that it will be put in some mail newsgroup or other
9411 depending on `nnmail-split-methods'.
9412 If N is a positive number, respool the N next articles.
9413 If N is a negative number, respool the N previous articles.
9414 If N is nil and any articles have been marked with the process mark,
9415 respool those articles instead.
9416
9417 Respooling can be done both from mail groups and \"real\" newsgroups.
9418 In the former case, the articles in question will be moved from the
9419 current group into whatever groups they are destined to.  In the
9420 latter case, they will be copied into the relevant groups."
9421   (interactive
9422    (list current-prefix-arg
9423          (let* ((methods (gnus-methods-using 'respool))
9424                 (methname
9425                  (symbol-name (or gnus-summary-respool-default-method
9426                                   (car (gnus-find-method-for-group
9427                                         gnus-newsgroup-name)))))
9428                 (method
9429                  (gnus-completing-read-with-default
9430                   methname "What backend do you want to use when respooling?"
9431                   methods nil t nil 'gnus-mail-method-history))
9432                 ms)
9433            (cond
9434             ((zerop (length (setq ms (gnus-servers-using-backend
9435                                       (intern method)))))
9436              (list (intern method) ""))
9437             ((= 1 (length ms))
9438              (car ms))
9439             (t
9440              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9441                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9442                            ms-alist))))))))
9443   (unless method
9444     (error "No method given for respooling"))
9445   (if (assoc (symbol-name
9446               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9447              (gnus-methods-using 'respool))
9448       (gnus-summary-move-article n nil method)
9449     (gnus-summary-copy-article n nil method)))
9450
9451 (defun gnus-summary-import-article (file &optional edit)
9452   "Import an arbitrary file into a mail newsgroup."
9453   (interactive "fImport file: \nP")
9454   (let ((group gnus-newsgroup-name)
9455         (now (current-time))
9456         atts lines group-art)
9457     (unless (gnus-check-backend-function 'request-accept-article group)
9458       (error "%s does not support article importing" group))
9459     (or (file-readable-p file)
9460         (not (file-regular-p file))
9461         (error "Can't read %s" file))
9462     (save-excursion
9463       (set-buffer (gnus-get-buffer-create " *import file*"))
9464       (erase-buffer)
9465       (nnheader-insert-file-contents file)
9466       (goto-char (point-min))
9467       (if (nnheader-article-p)
9468           (save-restriction
9469             (goto-char (point-min))
9470             (search-forward "\n\n" nil t)
9471             (narrow-to-region (point-min) (1- (point)))
9472             (goto-char (point-min))
9473             (unless (re-search-forward "^date:" nil t)
9474               (goto-char (point-max))
9475               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9476         ;; This doesn't look like an article, so we fudge some headers.
9477         (setq atts (file-attributes file)
9478               lines (count-lines (point-min) (point-max)))
9479         (insert "From: " (read-string "From: ") "\n"
9480                 "Subject: " (read-string "Subject: ") "\n"
9481                 "Date: " (message-make-date (nth 5 atts)) "\n"
9482                 "Message-ID: " (message-make-message-id) "\n"
9483                 "Lines: " (int-to-string lines) "\n"
9484                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9485       (setq group-art (gnus-request-accept-article group nil t))
9486       (kill-buffer (current-buffer)))
9487     (setq gnus-newsgroup-active (gnus-activate-group group))
9488     (forward-line 1)
9489     (gnus-summary-goto-article (cdr group-art) nil t)
9490     (when edit
9491       (gnus-summary-edit-article))))
9492
9493 (defun gnus-summary-create-article ()
9494   "Create an article in a mail newsgroup."
9495   (interactive)
9496   (let ((group gnus-newsgroup-name)
9497         (now (current-time))
9498         group-art)
9499     (unless (gnus-check-backend-function 'request-accept-article group)
9500       (error "%s does not support article importing" group))
9501     (save-excursion
9502       (set-buffer (gnus-get-buffer-create " *import file*"))
9503       (erase-buffer)
9504       (goto-char (point-min))
9505       ;; This doesn't look like an article, so we fudge some headers.
9506       (insert "From: " (read-string "From: ") "\n"
9507               "Subject: " (read-string "Subject: ") "\n"
9508               "Date: " (message-make-date now) "\n"
9509               "Message-ID: " (message-make-message-id) "\n")
9510       (setq group-art (gnus-request-accept-article group nil t))
9511       (kill-buffer (current-buffer)))
9512     (setq gnus-newsgroup-active (gnus-activate-group group))
9513     (forward-line 1)
9514     (gnus-summary-goto-article (cdr group-art) nil t)
9515     (gnus-summary-edit-article)))
9516
9517 (defun gnus-summary-article-posted-p ()
9518   "Say whether the current (mail) article is available from news as well.
9519 This will be the case if the article has both been mailed and posted."
9520   (interactive)
9521   (let ((id (mail-header-references (gnus-summary-article-header)))
9522         (gnus-override-method (car (gnus-refer-article-methods))))
9523     (if (gnus-request-head id "")
9524         (gnus-message 2 "The current message was found on %s"
9525                       gnus-override-method)
9526       (gnus-message 2 "The current message couldn't be found on %s"
9527                     gnus-override-method)
9528       nil)))
9529
9530 (defun gnus-summary-expire-articles (&optional now)
9531   "Expire all articles that are marked as expirable in the current group."
9532   (interactive)
9533   (when (and (not gnus-group-is-exiting-without-update-p)
9534              (gnus-check-backend-function
9535               'request-expire-articles gnus-newsgroup-name))
9536     ;; This backend supports expiry.
9537     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9538            (expirable (if total
9539                           (progn
9540                             ;; We need to update the info for
9541                             ;; this group for `gnus-list-of-read-articles'
9542                             ;; to give us the right answer.
9543                             (gnus-run-hooks 'gnus-exit-group-hook)
9544                             (gnus-summary-update-info)
9545                             (gnus-list-of-read-articles gnus-newsgroup-name))
9546                         (setq gnus-newsgroup-expirable
9547                               (sort gnus-newsgroup-expirable '<))))
9548            (expiry-wait (if now 'immediate
9549                           (gnus-group-find-parameter
9550                            gnus-newsgroup-name 'expiry-wait)))
9551            (nnmail-expiry-target
9552             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9553                 nnmail-expiry-target))
9554            es)
9555       (when expirable
9556         ;; There are expirable articles in this group, so we run them
9557         ;; through the expiry process.
9558         (gnus-message 6 "Expiring articles...")
9559         (unless (gnus-check-group gnus-newsgroup-name)
9560           (error "Can't open server for %s" gnus-newsgroup-name))
9561         ;; The list of articles that weren't expired is returned.
9562         (save-excursion
9563           (if expiry-wait
9564               (let ((nnmail-expiry-wait-function nil)
9565                     (nnmail-expiry-wait expiry-wait))
9566                 (setq es (gnus-request-expire-articles
9567                           expirable gnus-newsgroup-name)))
9568             (setq es (gnus-request-expire-articles
9569                       expirable gnus-newsgroup-name)))
9570           (unless total
9571             (setq gnus-newsgroup-expirable es))
9572           ;; We go through the old list of expirable, and mark all
9573           ;; really expired articles as nonexistent.
9574           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9575             (let ((gnus-use-cache nil))
9576               (dolist (article expirable)
9577                 (when (and (not (memq article es))
9578                            (gnus-data-find article))
9579                   (gnus-summary-mark-article article gnus-canceled-mark)
9580                   (run-hook-with-args 'gnus-summary-article-expire-hook
9581                                       'delete
9582                                       (gnus-data-header
9583                                        (assoc article (gnus-data-list nil)))
9584                                       gnus-newsgroup-name
9585                                       nil
9586                                       nil))))))
9587         (gnus-message 6 "Expiring articles...done")))))
9588
9589 (defun gnus-summary-expire-articles-now ()
9590   "Expunge all expirable articles in the current group.
9591 This means that *all* articles that are marked as expirable will be
9592 deleted forever, right now."
9593   (interactive)
9594   (or gnus-expert-user
9595       (gnus-yes-or-no-p
9596        "Are you really, really, really sure you want to delete all these messages? ")
9597       (error "Phew!"))
9598   (gnus-summary-expire-articles t))
9599
9600 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9601 (defun gnus-summary-delete-article (&optional n)
9602   "Delete the N next (mail) articles.
9603 This command actually deletes articles.  This is not a marking
9604 command.  The article will disappear forever from your life, never to
9605 return.
9606
9607 If N is negative, delete backwards.
9608 If N is nil and articles have been marked with the process mark,
9609 delete these instead.
9610
9611 If `gnus-novice-user' is non-nil you will be asked for
9612 confirmation before the articles are deleted."
9613   (interactive "P")
9614   (unless (gnus-check-backend-function 'request-expire-articles
9615                                        gnus-newsgroup-name)
9616     (error "The current newsgroup does not support article deletion"))
9617   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9618     (error "Couldn't open server"))
9619   ;; Compute the list of articles to delete.
9620   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9621         (nnmail-expiry-target 'delete)
9622         not-deleted)
9623     (if (and gnus-novice-user
9624              (not (gnus-yes-or-no-p
9625                    (format "Do you really want to delete %s forever? "
9626                            (if (> (length articles) 1)
9627                                (format "these %s articles" (length articles))
9628                              "this article")))))
9629         ()
9630       ;; Delete the articles.
9631       (setq not-deleted (gnus-request-expire-articles
9632                          articles gnus-newsgroup-name 'force))
9633       (while articles
9634         (gnus-summary-remove-process-mark (car articles))
9635         ;; The backend might not have been able to delete the article
9636         ;; after all.
9637         (unless (memq (car articles) not-deleted)
9638           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9639         (let* ((article (car articles))
9640                (ghead  (gnus-data-header
9641                                     (assoc article (gnus-data-list nil)))))
9642           (run-hook-with-args 'gnus-summary-article-delete-hook
9643                               'delete ghead gnus-newsgroup-name nil
9644                               nil))
9645         (setq articles (cdr articles)))
9646       (when not-deleted
9647         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9648     (gnus-summary-position-point)
9649     (gnus-set-mode-line 'summary)
9650     not-deleted))
9651
9652 (defun gnus-summary-edit-article (&optional force)
9653   "Edit the current article.
9654 This will have permanent effect only in mail groups.
9655 If FORCE is non-nil, allow editing of articles even in read-only
9656 groups."
9657   (interactive "P")
9658   (save-excursion
9659     (set-buffer gnus-summary-buffer)
9660     (let ((mail-parse-charset gnus-newsgroup-charset)
9661           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9662       (gnus-set-global-variables)
9663       (when (and (not force)
9664                  (gnus-group-read-only-p))
9665         (error "The current newsgroup does not support article editing"))
9666       (gnus-summary-show-article t)
9667       (gnus-article-edit-article
9668        'ignore
9669        `(lambda (no-highlight)
9670           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9671                 (message-options message-options)
9672                 (message-options-set-recipient)
9673                 (mail-parse-ignored-charsets
9674                  ',gnus-newsgroup-ignored-charsets))
9675             (gnus-summary-edit-article-done
9676              ,(or (mail-header-references gnus-current-headers) "")
9677              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9678
9679 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9680
9681 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9682                                                  no-highlight)
9683   "Make edits to the current article permanent."
9684   (interactive)
9685   (save-excursion
9686     ;; The buffer restriction contains the entire article if it exists.
9687     (when (article-goto-body)
9688       (let ((lines (count-lines (point) (point-max)))
9689             (length (- (point-max) (point)))
9690             (case-fold-search t)
9691             (body (copy-marker (point))))
9692         (goto-char (point-min))
9693         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9694           (delete-region (match-beginning 1) (match-end 1))
9695           (insert (number-to-string length)))
9696         (goto-char (point-min))
9697         (when (re-search-forward
9698                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9699           (delete-region (match-beginning 1) (match-end 1))
9700           (insert (number-to-string length)))
9701         (goto-char (point-min))
9702         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9703           (delete-region (match-beginning 1) (match-end 1))
9704           (insert (number-to-string lines))))))
9705   ;; Replace the article.
9706   (let ((buf (current-buffer)))
9707     (with-temp-buffer
9708       (insert-buffer-substring buf)
9709
9710       (if (and (not read-only)
9711                (not (gnus-request-replace-article
9712                      (cdr gnus-article-current) (car gnus-article-current)
9713                      (current-buffer) t)))
9714           (error "Couldn't replace article")
9715         ;; Update the summary buffer.
9716         (if (and references
9717                  (equal (message-tokenize-header references " ")
9718                         (message-tokenize-header
9719                          (or (message-fetch-field "references") "") " ")))
9720             ;; We only have to update this line.
9721             (save-excursion
9722               (save-restriction
9723                 (message-narrow-to-head)
9724                 (let ((head (buffer-string))
9725                       header)
9726                   (with-temp-buffer
9727                     (insert (format "211 %d Article retrieved.\n"
9728                                     (cdr gnus-article-current)))
9729                     (insert head)
9730                     (insert ".\n")
9731                     (let ((nntp-server-buffer (current-buffer)))
9732                       (setq header (car (gnus-get-newsgroup-headers
9733                                          nil t))))
9734                     (save-excursion
9735                       (set-buffer gnus-summary-buffer)
9736                       (gnus-data-set-header
9737                        (gnus-data-find (cdr gnus-article-current))
9738                        header)
9739                       (gnus-summary-update-article-line
9740                        (cdr gnus-article-current) header)
9741                       (if (gnus-summary-goto-subject
9742                            (cdr gnus-article-current) nil t)
9743                           (gnus-summary-update-secondary-mark
9744                            (cdr gnus-article-current))))))))
9745           ;; Update threads.
9746           (set-buffer (or buffer gnus-summary-buffer))
9747           (gnus-summary-update-article (cdr gnus-article-current))
9748           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9749               (gnus-summary-update-secondary-mark
9750                (cdr gnus-article-current))))
9751         ;; Prettify the article buffer again.
9752         (unless no-highlight
9753           (save-excursion
9754             (set-buffer gnus-article-buffer)
9755             ;;;!!! Fix this -- article should be rehighlighted.
9756             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9757             (set-buffer gnus-original-article-buffer)
9758             (gnus-request-article
9759              (cdr gnus-article-current)
9760              (car gnus-article-current) (current-buffer))))
9761         ;; Prettify the summary buffer line.
9762         (when (gnus-visual-p 'summary-highlight 'highlight)
9763           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9764
9765 (defun gnus-summary-edit-wash (key)
9766   "Perform editing command KEY in the article buffer."
9767   (interactive
9768    (list
9769     (progn
9770       (message "%s" (concat (this-command-keys) "- "))
9771       (read-char))))
9772   (message "")
9773   (gnus-summary-edit-article)
9774   (execute-kbd-macro (concat (this-command-keys) key))
9775   (gnus-article-edit-done))
9776
9777 ;;; Respooling
9778
9779 (defun gnus-summary-respool-query (&optional silent trace)
9780   "Query where the respool algorithm would put this article."
9781   (interactive)
9782   (let (gnus-mark-article-hook)
9783     (gnus-summary-select-article)
9784     (save-excursion
9785       (set-buffer gnus-original-article-buffer)
9786       (let ((groups (nnmail-article-group 'identity trace)))
9787         (unless silent
9788           (if groups
9789               (message "This message would go to %s"
9790                        (mapconcat 'car groups ", "))
9791             (message "This message would go to no groups"))
9792           groups)))))
9793
9794 (defun gnus-summary-respool-trace ()
9795   "Trace where the respool algorithm would put this article.
9796 Display a buffer showing all fancy splitting patterns which matched."
9797   (interactive)
9798   (gnus-summary-respool-query nil t))
9799
9800 ;; Summary marking commands.
9801
9802 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9803   "Mark articles which has the same subject as read, and then select the next.
9804 If UNMARK is positive, remove any kind of mark.
9805 If UNMARK is negative, tick articles."
9806   (interactive "P")
9807   (when unmark
9808     (setq unmark (prefix-numeric-value unmark)))
9809   (let ((count
9810          (gnus-summary-mark-same-subject
9811           (gnus-summary-article-subject) unmark)))
9812     ;; Select next unread article.  If auto-select-same mode, should
9813     ;; select the first unread article.
9814     (gnus-summary-next-article t (and gnus-auto-select-same
9815                                       (gnus-summary-article-subject)))
9816     (gnus-message 7 "%d article%s marked as %s"
9817                   count (if (= count 1) " is" "s are")
9818                   (if unmark "unread" "read"))))
9819
9820 (defun gnus-summary-kill-same-subject (&optional unmark)
9821   "Mark articles which has the same subject as read.
9822 If UNMARK is positive, remove any kind of mark.
9823 If UNMARK is negative, tick articles."
9824   (interactive "P")
9825   (when unmark
9826     (setq unmark (prefix-numeric-value unmark)))
9827   (let ((count
9828          (gnus-summary-mark-same-subject
9829           (gnus-summary-article-subject) unmark)))
9830     ;; If marked as read, go to next unread subject.
9831     (when (null unmark)
9832       ;; Go to next unread subject.
9833       (gnus-summary-next-subject 1 t))
9834     (gnus-message 7 "%d articles are marked as %s"
9835                   count (if unmark "unread" "read"))))
9836
9837 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9838   "Mark articles with same SUBJECT as read, and return marked number.
9839 If optional argument UNMARK is positive, remove any kinds of marks.
9840 If optional argument UNMARK is negative, mark articles as unread instead."
9841   (let ((count 1))
9842     (save-excursion
9843       (cond
9844        ((null unmark)                   ; Mark as read.
9845         (while (and
9846                 (progn
9847                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9848                   (gnus-summary-show-thread) t)
9849                 (gnus-summary-find-subject subject))
9850           (setq count (1+ count))))
9851        ((> unmark 0)                    ; Tick.
9852         (while (and
9853                 (progn
9854                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9855                   (gnus-summary-show-thread) t)
9856                 (gnus-summary-find-subject subject))
9857           (setq count (1+ count))))
9858        (t                               ; Mark as unread.
9859         (while (and
9860                 (progn
9861                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9862                   (gnus-summary-show-thread) t)
9863                 (gnus-summary-find-subject subject))
9864           (setq count (1+ count)))))
9865       (gnus-set-mode-line 'summary)
9866       ;; Return the number of marked articles.
9867       count)))
9868
9869 (defun gnus-summary-mark-as-processable (n &optional unmark)
9870   "Set the process mark on the next N articles.
9871 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9872 the process mark instead.  The difference between N and the actual
9873 number of articles marked is returned."
9874   (interactive "P")
9875   (if (and (null n) (gnus-region-active-p))
9876       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9877     (setq n (prefix-numeric-value n))
9878     (let ((backward (< n 0))
9879           (n (abs n)))
9880       (while (and
9881               (> n 0)
9882               (if unmark
9883                   (gnus-summary-remove-process-mark
9884                    (gnus-summary-article-number))
9885                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9886               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9887         (setq n (1- n)))
9888       (when (/= 0 n)
9889         (gnus-message 7 "No more articles"))
9890       (gnus-summary-recenter)
9891       (gnus-summary-position-point)
9892       n)))
9893
9894 (defun gnus-summary-unmark-as-processable (n)
9895   "Remove the process mark from the next N articles.
9896 If N is negative, unmark backward instead.  The difference between N and
9897 the actual number of articles unmarked is returned."
9898   (interactive "P")
9899   (gnus-summary-mark-as-processable n t))
9900
9901 (defun gnus-summary-unmark-all-processable ()
9902   "Remove the process mark from all articles."
9903   (interactive)
9904   (save-excursion
9905     (while gnus-newsgroup-processable
9906       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9907   (gnus-summary-position-point))
9908
9909 (defun gnus-summary-add-mark (article type)
9910   "Mark ARTICLE with a mark of TYPE."
9911   (let ((vtype (car (assq type gnus-article-mark-lists)))
9912         var)
9913     (if (not vtype)
9914         (error "No such mark type: %s" type)
9915       (setq var (intern (format "gnus-newsgroup-%s" type)))
9916       (set var (cons article (symbol-value var)))
9917       (if (memq type '(processable cached replied forwarded recent saved))
9918           (gnus-summary-update-secondary-mark article)
9919         ;;; !!! This is bogus.  We should find out what primary
9920         ;;; !!! mark we want to set.
9921         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9922
9923 (defun gnus-summary-mark-as-expirable (n)
9924   "Mark N articles forward as expirable.
9925 If N is negative, mark backward instead.  The difference between N and
9926 the actual number of articles marked is returned."
9927   (interactive "p")
9928   (gnus-summary-mark-forward n gnus-expirable-mark))
9929
9930 (defun gnus-summary-mark-as-spam (n)
9931   "Mark N articles forward as spam.
9932 If N is negative, mark backward instead.  The difference between N and
9933 the actual number of articles marked is returned."
9934   (interactive "p")
9935   (gnus-summary-mark-forward n gnus-spam-mark))
9936
9937 (defun gnus-summary-mark-article-as-replied (article)
9938   "Mark ARTICLE as replied to and update the summary line.
9939 ARTICLE can also be a list of articles."
9940   (interactive (list (gnus-summary-article-number)))
9941   (let ((articles (if (listp article) article (list article))))
9942     (dolist (article articles)
9943       (unless (numberp article)
9944         (error "%s is not a number" article))
9945       (push article gnus-newsgroup-replied)
9946       (let ((buffer-read-only nil))
9947         (when (gnus-summary-goto-subject article nil t)
9948           (gnus-summary-update-secondary-mark article))))))
9949
9950 (defun gnus-summary-mark-article-as-forwarded (article)
9951   "Mark ARTICLE as forwarded and update the summary line.
9952 ARTICLE can also be a list of articles."
9953   (let ((articles (if (listp article) article (list article))))
9954     (dolist (article articles)
9955       (push article gnus-newsgroup-forwarded)
9956       (let ((buffer-read-only nil))
9957         (when (gnus-summary-goto-subject article nil t)
9958           (gnus-summary-update-secondary-mark article))))))
9959
9960 (defun gnus-summary-set-bookmark (article)
9961   "Set a bookmark in current article."
9962   (interactive (list (gnus-summary-article-number)))
9963   (when (or (not (get-buffer gnus-article-buffer))
9964             (not gnus-current-article)
9965             (not gnus-article-current)
9966             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9967     (error "No current article selected"))
9968   ;; Remove old bookmark, if one exists.
9969   (gnus-pull article gnus-newsgroup-bookmarks)
9970   ;; Set the new bookmark, which is on the form
9971   ;; (article-number . line-number-in-body).
9972   (push
9973    (cons article
9974          (with-current-buffer gnus-article-buffer
9975            (count-lines
9976             (min (point)
9977                  (save-excursion
9978                    (article-goto-body)
9979                    (point)))
9980             (point))))
9981    gnus-newsgroup-bookmarks)
9982   (gnus-message 6 "A bookmark has been added to the current article."))
9983
9984 (defun gnus-summary-remove-bookmark (article)
9985   "Remove the bookmark from the current article."
9986   (interactive (list (gnus-summary-article-number)))
9987   ;; Remove old bookmark, if one exists.
9988   (if (not (assq article gnus-newsgroup-bookmarks))
9989       (gnus-message 6 "No bookmark in current article.")
9990     (gnus-pull article gnus-newsgroup-bookmarks)
9991     (gnus-message 6 "Removed bookmark.")))
9992
9993 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9994 (defun gnus-summary-mark-as-dormant (n)
9995   "Mark N articles forward as dormant.
9996 If N is negative, mark backward instead.  The difference between N and
9997 the actual number of articles marked is returned."
9998   (interactive "p")
9999   (gnus-summary-mark-forward n gnus-dormant-mark))
10000
10001 (defun gnus-summary-set-process-mark (article)
10002   "Set the process mark on ARTICLE and update the summary line."
10003   (setq gnus-newsgroup-processable
10004         (cons article
10005               (delq article gnus-newsgroup-processable)))
10006   (when (gnus-summary-goto-subject article)
10007     (gnus-summary-show-thread)
10008     (gnus-summary-goto-subject article)
10009     (gnus-summary-update-secondary-mark article)))
10010
10011 (defun gnus-summary-remove-process-mark (article)
10012   "Remove the process mark from ARTICLE and update the summary line."
10013   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10014   (when (gnus-summary-goto-subject article)
10015     (gnus-summary-show-thread)
10016     (gnus-summary-goto-subject article)
10017     (gnus-summary-update-secondary-mark article)))
10018
10019 (defun gnus-summary-set-saved-mark (article)
10020   "Set the process mark on ARTICLE and update the summary line."
10021   (push article gnus-newsgroup-saved)
10022   (when (gnus-summary-goto-subject article)
10023     (gnus-summary-update-secondary-mark article)))
10024
10025 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10026   "Mark N articles as read forwards.
10027 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10028 The difference between N and the actual number of articles marked is
10029 returned.
10030 If NO-EXPIRE, auto-expiry will be inhibited."
10031   (interactive "p")
10032   (gnus-summary-show-thread)
10033   (let ((backward (< n 0))
10034         (gnus-summary-goto-unread
10035          (and gnus-summary-goto-unread
10036               (not (eq gnus-summary-goto-unread 'never))
10037               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10038                                     gnus-ticked-mark gnus-dormant-mark)))))
10039         (n (abs n))
10040         (mark (or mark gnus-del-mark)))
10041     (while (and (> n 0)
10042                 (gnus-summary-mark-article nil mark no-expire)
10043                 (zerop (gnus-summary-next-subject
10044                         (if backward -1 1)
10045                         (and gnus-summary-goto-unread
10046                              (not (eq gnus-summary-goto-unread 'never)))
10047                         t)))
10048       (setq n (1- n)))
10049     (when (/= 0 n)
10050       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10051     (gnus-summary-recenter)
10052     (gnus-summary-position-point)
10053     (gnus-set-mode-line 'summary)
10054     n))
10055
10056 (defun gnus-summary-mark-article-as-read (mark)
10057   "Mark the current article quickly as read with MARK."
10058   (let ((article (gnus-summary-article-number)))
10059     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10060     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10061     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10062     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10063     (push (cons article mark) gnus-newsgroup-reads)
10064     ;; Possibly remove from cache, if that is used.
10065     (when gnus-use-cache
10066       (gnus-cache-enter-remove-article article))
10067     ;; Allow the backend to change the mark.
10068     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10069     ;; Check for auto-expiry.
10070     (when (and gnus-newsgroup-auto-expire
10071                (memq mark gnus-auto-expirable-marks))
10072       (setq mark gnus-expirable-mark)
10073       ;; Let the backend know about the mark change.
10074       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10075       (push article gnus-newsgroup-expirable))
10076     ;; Set the mark in the buffer.
10077     (gnus-summary-update-mark mark 'unread)
10078     t))
10079
10080 (defun gnus-summary-mark-article-as-unread (mark)
10081   "Mark the current article quickly as unread with MARK."
10082   (let* ((article (gnus-summary-article-number))
10083          (old-mark (gnus-summary-article-mark article)))
10084     ;; Allow the backend to change the mark.
10085     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10086     (if (eq mark old-mark)
10087         t
10088       (if (<= article 0)
10089           (progn
10090             (gnus-error 1 "Can't mark negative article numbers")
10091             nil)
10092         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10093         (setq gnus-newsgroup-spam-marked
10094               (delq article gnus-newsgroup-spam-marked))
10095         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10096         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10097         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10098         (cond ((= mark gnus-ticked-mark)
10099                (setq gnus-newsgroup-marked
10100                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10101                                               article)))
10102               ((= mark gnus-spam-mark)
10103                (setq gnus-newsgroup-spam-marked
10104                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10105                                               article)))
10106               ((= mark gnus-dormant-mark)
10107                (setq gnus-newsgroup-dormant
10108                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10109                                               article)))
10110               (t
10111                (setq gnus-newsgroup-unreads
10112                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10113                                               article))))
10114         (gnus-pull article gnus-newsgroup-reads)
10115
10116         ;; See whether the article is to be put in the cache.
10117         (and gnus-use-cache
10118              (vectorp (gnus-summary-article-header article))
10119              (save-excursion
10120                (gnus-cache-possibly-enter-article
10121                 gnus-newsgroup-name article
10122                 (gnus-summary-article-header article)
10123                 (= mark gnus-ticked-mark)
10124                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10125
10126         ;; Fix the mark.
10127         (gnus-summary-update-mark mark 'unread)
10128         t))))
10129
10130 (defun gnus-summary-mark-article (&optional article mark no-expire)
10131   "Mark ARTICLE with MARK.  MARK can be any character.
10132 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10133 `??' (dormant) and `?E' (expirable).
10134 If MARK is nil, then the default character `?r' is used.
10135 If ARTICLE is nil, then the article on the current line will be
10136 marked.
10137 If NO-EXPIRE, auto-expiry will be inhibited."
10138   ;; The mark might be a string.
10139   (when (stringp mark)
10140     (setq mark (aref mark 0)))
10141   ;; If no mark is given, then we check auto-expiring.
10142   (when (null mark)
10143     (setq mark gnus-del-mark))
10144   (when (and (not no-expire)
10145              gnus-newsgroup-auto-expire
10146              (memq mark gnus-auto-expirable-marks))
10147     (setq mark gnus-expirable-mark))
10148   (let ((article (or article (gnus-summary-article-number)))
10149         (old-mark (gnus-summary-article-mark article)))
10150     ;; Allow the backend to change the mark.
10151     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10152     (if (eq mark old-mark)
10153         t
10154       (unless article
10155         (error "No article on current line"))
10156       (if (not (if (or (= mark gnus-unread-mark)
10157                        (= mark gnus-ticked-mark)
10158                        (= mark gnus-spam-mark)
10159                        (= mark gnus-dormant-mark))
10160                    (gnus-mark-article-as-unread article mark)
10161                  (gnus-mark-article-as-read article mark)))
10162           t
10163         ;; See whether the article is to be put in the cache.
10164         (and gnus-use-cache
10165              (not (= mark gnus-canceled-mark))
10166              (vectorp (gnus-summary-article-header article))
10167              (save-excursion
10168                (gnus-cache-possibly-enter-article
10169                 gnus-newsgroup-name article
10170                 (gnus-summary-article-header article)
10171                 (= mark gnus-ticked-mark)
10172                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10173
10174         (when (gnus-summary-goto-subject article nil t)
10175           (let ((buffer-read-only nil))
10176             (gnus-summary-show-thread)
10177             ;; Fix the mark.
10178             (gnus-summary-update-mark mark 'unread)
10179             t))))))
10180
10181 (defun gnus-summary-update-secondary-mark (article)
10182   "Update the secondary (read, process, cache) mark."
10183   (gnus-summary-update-mark
10184    (cond ((memq article gnus-newsgroup-processable)
10185           gnus-process-mark)
10186          ((memq article gnus-newsgroup-cached)
10187           gnus-cached-mark)
10188          ((memq article gnus-newsgroup-replied)
10189           gnus-replied-mark)
10190          ((memq article gnus-newsgroup-forwarded)
10191           gnus-forwarded-mark)
10192          ((memq article gnus-newsgroup-saved)
10193           gnus-saved-mark)
10194          ((memq article gnus-newsgroup-recent)
10195           gnus-recent-mark)
10196          ((memq article gnus-newsgroup-unseen)
10197           gnus-unseen-mark)
10198          (t gnus-no-mark))
10199    'replied)
10200   (when (gnus-visual-p 'summary-highlight 'highlight)
10201     (gnus-run-hooks 'gnus-summary-update-hook))
10202   t)
10203
10204 (defun gnus-summary-update-download-mark (article)
10205   "Update the download mark."
10206   (gnus-summary-update-mark
10207    (cond ((memq article gnus-newsgroup-undownloaded)
10208           gnus-undownloaded-mark)
10209          (gnus-newsgroup-agentized
10210           gnus-downloaded-mark)
10211          (t
10212           gnus-no-mark))
10213    'download)
10214   (gnus-summary-update-line t)
10215   t)
10216
10217 (defun gnus-summary-update-mark (mark type)
10218   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10219         (buffer-read-only nil))
10220     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10221     (when forward
10222       (when (looking-at "\r")
10223         (incf forward))
10224       (when (<= (+ forward (point)) (point-max))
10225         ;; Go to the right position on the line.
10226         (goto-char (+ forward (point)))
10227         ;; Replace the old mark with the new mark.
10228         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10229         ;; Optionally update the marks by some user rule.
10230         (when (eq type 'unread)
10231           (gnus-data-set-mark
10232            (gnus-data-find (gnus-summary-article-number)) mark)
10233           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10234
10235 (defun gnus-mark-article-as-read (article &optional mark)
10236   "Enter ARTICLE in the pertinent lists and remove it from others."
10237   ;; Make the article expirable.
10238   (let ((mark (or mark gnus-del-mark)))
10239     (setq gnus-newsgroup-expirable
10240           (if (= mark gnus-expirable-mark)
10241               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10242             (delq article gnus-newsgroup-expirable)))
10243     ;; Remove from unread and marked lists.
10244     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10245     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10246     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10247     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10248     (push (cons article mark) gnus-newsgroup-reads)
10249     ;; Possibly remove from cache, if that is used.
10250     (when gnus-use-cache
10251       (gnus-cache-enter-remove-article article))
10252     t))
10253
10254 (defun gnus-mark-article-as-unread (article &optional mark)
10255   "Enter ARTICLE in the pertinent lists and remove it from others."
10256   (let ((mark (or mark gnus-ticked-mark)))
10257     (if (<= article 0)
10258         (progn
10259           (gnus-error 1 "Can't mark negative article numbers")
10260           nil)
10261       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10262             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10263             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10264             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10265             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10266
10267       ;; Unsuppress duplicates?
10268       (when gnus-suppress-duplicates
10269         (gnus-dup-unsuppress-article article))
10270
10271       (cond ((= mark gnus-ticked-mark)
10272              (setq gnus-newsgroup-marked
10273                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10274             ((= mark gnus-spam-mark)
10275              (setq gnus-newsgroup-spam-marked
10276                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10277                                             article)))
10278             ((= mark gnus-dormant-mark)
10279              (setq gnus-newsgroup-dormant
10280                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10281             (t
10282              (setq gnus-newsgroup-unreads
10283                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10284       (gnus-pull article gnus-newsgroup-reads)
10285       t)))
10286
10287 (defalias 'gnus-summary-mark-as-unread-forward
10288   'gnus-summary-tick-article-forward)
10289 (make-obsolete 'gnus-summary-mark-as-unread-forward
10290                'gnus-summary-tick-article-forward)
10291 (defun gnus-summary-tick-article-forward (n)
10292   "Tick N articles forwards.
10293 If N is negative, tick backwards instead.
10294 The difference between N and the number of articles ticked is returned."
10295   (interactive "p")
10296   (gnus-summary-mark-forward n gnus-ticked-mark))
10297
10298 (defalias 'gnus-summary-mark-as-unread-backward
10299   'gnus-summary-tick-article-backward)
10300 (make-obsolete 'gnus-summary-mark-as-unread-backward
10301                'gnus-summary-tick-article-backward)
10302 (defun gnus-summary-tick-article-backward (n)
10303   "Tick N articles backwards.
10304 The difference between N and the number of articles ticked is returned."
10305   (interactive "p")
10306   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10307
10308 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10309 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10310 (defun gnus-summary-tick-article (&optional article clear-mark)
10311   "Mark current article as unread.
10312 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10313 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10314   (interactive)
10315   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10316                                        gnus-ticked-mark)))
10317
10318 (defun gnus-summary-mark-as-read-forward (n)
10319   "Mark N articles as read forwards.
10320 If N is negative, mark backwards instead.
10321 The difference between N and the actual number of articles marked is
10322 returned."
10323   (interactive "p")
10324   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10325
10326 (defun gnus-summary-mark-as-read-backward (n)
10327   "Mark the N articles as read backwards.
10328 The difference between N and the actual number of articles marked is
10329 returned."
10330   (interactive "p")
10331   (gnus-summary-mark-forward
10332    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10333
10334 (defun gnus-summary-mark-as-read (&optional article mark)
10335   "Mark current article as read.
10336 ARTICLE specifies the article to be marked as read.
10337 MARK specifies a string to be inserted at the beginning of the line."
10338   (gnus-summary-mark-article article mark))
10339
10340 (defun gnus-summary-clear-mark-forward (n)
10341   "Clear marks from N articles forward.
10342 If N is negative, clear backward instead.
10343 The difference between N and the number of marks cleared is returned."
10344   (interactive "p")
10345   (gnus-summary-mark-forward n gnus-unread-mark))
10346
10347 (defun gnus-summary-clear-mark-backward (n)
10348   "Clear marks from N articles backward.
10349 The difference between N and the number of marks cleared is returned."
10350   (interactive "p")
10351   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10352
10353 (defun gnus-summary-mark-unread-as-read ()
10354   "Intended to be used by `gnus-summary-mark-article-hook'."
10355   (when (memq gnus-current-article gnus-newsgroup-unreads)
10356     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10357
10358 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10359   "Intended to be used by `gnus-summary-mark-article-hook'."
10360   (let ((mark (gnus-summary-article-mark)))
10361     (when (or (gnus-unread-mark-p mark)
10362               (gnus-read-mark-p mark))
10363       (gnus-summary-mark-article gnus-current-article
10364                                  (or new-mark gnus-read-mark)))))
10365
10366 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10367   "Intended to be used by `gnus-summary-mark-article-hook'."
10368   (let ((mark (gnus-summary-article-mark)))
10369     (when (or (gnus-unread-mark-p mark)
10370               (gnus-read-mark-p mark))
10371       (gnus-summary-mark-article (gnus-summary-article-number)
10372                                  (or new-mark gnus-read-mark)))))
10373
10374 (defun gnus-summary-mark-unread-as-ticked ()
10375   "Intended to be used by `gnus-summary-mark-article-hook'."
10376   (when (memq gnus-current-article gnus-newsgroup-unreads)
10377     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10378
10379 (defun gnus-summary-mark-region-as-read (point mark all)
10380   "Mark all unread articles between point and mark as read.
10381 If given a prefix, mark all articles between point and mark as read,
10382 even ticked and dormant ones."
10383   (interactive "r\nP")
10384   (save-excursion
10385     (let (article)
10386       (goto-char point)
10387       (beginning-of-line)
10388       (while (and
10389               (< (point) mark)
10390               (progn
10391                 (when (or all
10392                           (memq (setq article (gnus-summary-article-number))
10393                                 gnus-newsgroup-unreads))
10394                   (gnus-summary-mark-article article gnus-del-mark))
10395                 t)
10396               (gnus-summary-find-next))))))
10397
10398 (defun gnus-summary-mark-below (score mark)
10399   "Mark articles with score less than SCORE with MARK."
10400   (interactive "P\ncMark: ")
10401   (setq score (if score
10402                   (prefix-numeric-value score)
10403                 (or gnus-summary-default-score 0)))
10404   (save-excursion
10405     (set-buffer gnus-summary-buffer)
10406     (goto-char (point-min))
10407     (while
10408         (progn
10409           (and (< (gnus-summary-article-score) score)
10410                (gnus-summary-mark-article nil mark))
10411           (gnus-summary-find-next)))))
10412
10413 (defun gnus-summary-kill-below (&optional score)
10414   "Mark articles with score below SCORE as read."
10415   (interactive "P")
10416   (gnus-summary-mark-below score gnus-killed-mark))
10417
10418 (defun gnus-summary-clear-above (&optional score)
10419   "Clear all marks from articles with score above SCORE."
10420   (interactive "P")
10421   (gnus-summary-mark-above score gnus-unread-mark))
10422
10423 (defun gnus-summary-tick-above (&optional score)
10424   "Tick all articles with score above SCORE."
10425   (interactive "P")
10426   (gnus-summary-mark-above score gnus-ticked-mark))
10427
10428 (defun gnus-summary-mark-above (score mark)
10429   "Mark articles with score over SCORE with MARK."
10430   (interactive "P\ncMark: ")
10431   (setq score (if score
10432                   (prefix-numeric-value score)
10433                 (or gnus-summary-default-score 0)))
10434   (save-excursion
10435     (set-buffer gnus-summary-buffer)
10436     (goto-char (point-min))
10437     (while (and (progn
10438                   (when (> (gnus-summary-article-score) score)
10439                     (gnus-summary-mark-article nil mark))
10440                   t)
10441                 (gnus-summary-find-next)))))
10442
10443 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10444 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10445 (defun gnus-summary-limit-include-expunged (&optional no-error)
10446   "Display all the hidden articles that were expunged for low scores."
10447   (interactive)
10448   (let ((buffer-read-only nil))
10449     (let ((scored gnus-newsgroup-scored)
10450           headers h)
10451       (while scored
10452         (unless (gnus-summary-article-header (caar scored))
10453           (and (setq h (gnus-number-to-header (caar scored)))
10454                (< (cdar scored) gnus-summary-expunge-below)
10455                (push h headers)))
10456         (setq scored (cdr scored)))
10457       (if (not headers)
10458           (when (not no-error)
10459             (error "No expunged articles hidden"))
10460         (goto-char (point-min))
10461         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10462         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10463         (mapcar (lambda (x) (push (mail-header-number x)
10464                                   gnus-newsgroup-limit))
10465                 headers)
10466         (gnus-summary-prepare-unthreaded (nreverse headers))
10467         (goto-char (point-min))
10468         (gnus-summary-position-point)
10469         t))))
10470
10471 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10472   "Mark all unread articles in this newsgroup as read.
10473 If prefix argument ALL is non-nil, ticked and dormant articles will
10474 also be marked as read.
10475 If QUIETLY is non-nil, no questions will be asked.
10476
10477 If TO-HERE is non-nil, it should be a point in the buffer.  All
10478 articles before (after, if REVERSE is set) this point will be marked
10479 as read.
10480
10481 Note that this function will only catch up the unread article
10482 in the current summary buffer limitation.
10483
10484 The number of articles marked as read is returned."
10485   (interactive "P")
10486   (prog1
10487       (save-excursion
10488         (when (or quietly
10489                   (not gnus-interactive-catchup) ;Without confirmation?
10490                   gnus-expert-user
10491                   (gnus-y-or-n-p
10492                    (if all
10493                        "Mark absolutely all articles as read? "
10494                      "Mark all unread articles as read? ")))
10495           (if (and not-mark
10496                    (not gnus-newsgroup-adaptive)
10497                    (not gnus-newsgroup-auto-expire)
10498                    (not gnus-suppress-duplicates)
10499                    (or (not gnus-use-cache)
10500                        (eq gnus-use-cache 'passive)))
10501               (progn
10502                 (when all
10503                   (setq gnus-newsgroup-marked nil
10504                         gnus-newsgroup-spam-marked nil
10505                         gnus-newsgroup-dormant nil))
10506                 (setq gnus-newsgroup-unreads
10507                       (gnus-sorted-nunion
10508                        (gnus-intersection gnus-newsgroup-unreads
10509                                           gnus-newsgroup-downloadable)
10510                        gnus-newsgroup-unfetched)))
10511             ;; We actually mark all articles as canceled, which we
10512             ;; have to do when using auto-expiry or adaptive scoring.
10513             (gnus-summary-show-all-threads)
10514             (if (and to-here reverse)
10515                 (progn
10516                   (goto-char to-here)
10517                   (gnus-summary-mark-current-read-and-unread-as-read
10518                    gnus-catchup-mark)
10519                   (while (gnus-summary-find-next (not all))
10520                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10521               (when (gnus-summary-first-subject (not all))
10522                 (while (and
10523                         (if to-here (< (point) to-here) t)
10524                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10525                         (gnus-summary-find-next (not all))))))
10526             (gnus-set-mode-line 'summary))
10527           t))
10528     (gnus-summary-position-point)))
10529
10530 (defun gnus-summary-catchup-to-here (&optional all)
10531   "Mark all unticked articles before the current one as read.
10532 If ALL is non-nil, also mark ticked and dormant articles as read."
10533   (interactive "P")
10534   (save-excursion
10535     (gnus-save-hidden-threads
10536       (let ((beg (point)))
10537         ;; We check that there are unread articles.
10538         (when (or all (gnus-summary-find-prev))
10539           (gnus-summary-catchup all t beg)))))
10540   (gnus-summary-position-point))
10541
10542 (defun gnus-summary-catchup-from-here (&optional all)
10543   "Mark all unticked articles after (and including) the current one as read.
10544 If ALL is non-nil, also mark ticked and dormant articles as read."
10545   (interactive "P")
10546   (save-excursion
10547     (gnus-save-hidden-threads
10548       (let ((beg (point)))
10549         ;; We check that there are unread articles.
10550         (when (or all (gnus-summary-find-next))
10551           (gnus-summary-catchup all t beg nil t)))))
10552   (gnus-summary-position-point))
10553
10554 (defun gnus-summary-catchup-all (&optional quietly)
10555   "Mark all articles in this newsgroup as read.
10556 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10557 instead, which marks only unread articles as read."
10558   (interactive "P")
10559   (gnus-summary-catchup t quietly))
10560
10561 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10562   "Mark all unread articles in this group as read, then exit.
10563 If prefix argument ALL is non-nil, all articles are marked as read.
10564 If QUIETLY is non-nil, no questions will be asked."
10565   (interactive "P")
10566   (when (gnus-summary-catchup all quietly nil 'fast)
10567     ;; Select next newsgroup or exit.
10568     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10569              (eq gnus-auto-select-next 'quietly))
10570         (gnus-summary-next-group nil)
10571       (gnus-summary-exit))))
10572
10573 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10574   "Mark all articles in this newsgroup as read, and then exit.
10575 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10576 instead, which marks only unread articles as read."
10577   (interactive "P")
10578   (gnus-summary-catchup-and-exit t quietly))
10579
10580 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10581   "Mark all articles in this group as read and select the next group.
10582 If given a prefix, mark all articles, unread as well as ticked, as
10583 read."
10584   (interactive "P")
10585   (save-excursion
10586     (gnus-summary-catchup all))
10587   (gnus-summary-next-group))
10588
10589 ;;;
10590 ;;; with article
10591 ;;;
10592
10593 (defmacro gnus-with-article (article &rest forms)
10594   "Select ARTICLE and perform FORMS in the original article buffer.
10595 Then replace the article with the result."
10596   `(progn
10597      ;; We don't want the article to be marked as read.
10598      (let (gnus-mark-article-hook)
10599        (gnus-summary-select-article t t nil ,article))
10600      (set-buffer gnus-original-article-buffer)
10601      ,@forms
10602      (if (not (gnus-check-backend-function
10603                'request-replace-article (car gnus-article-current)))
10604          (gnus-message 5 "Read-only group; not replacing")
10605        (unless (gnus-request-replace-article
10606                 ,article (car gnus-article-current)
10607                 (current-buffer) t)
10608          (error "Couldn't replace article")))
10609      ;; The cache and backlog have to be flushed somewhat.
10610      (when gnus-keep-backlog
10611        (gnus-backlog-remove-article
10612         (car gnus-article-current) (cdr gnus-article-current)))
10613      (when gnus-use-cache
10614        (gnus-cache-update-article
10615         (car gnus-article-current) (cdr gnus-article-current)))))
10616
10617 (put 'gnus-with-article 'lisp-indent-function 1)
10618 (put 'gnus-with-article 'edebug-form-spec '(form body))
10619
10620 ;; Thread-based commands.
10621
10622 (defun gnus-summary-articles-in-thread (&optional article)
10623   "Return a list of all articles in the current thread.
10624 If ARTICLE is non-nil, return all articles in the thread that starts
10625 with that article."
10626   (let* ((article (or article (gnus-summary-article-number)))
10627          (data (gnus-data-find-list article))
10628          (top-level (gnus-data-level (car data)))
10629          (top-subject
10630           (cond ((null gnus-thread-operation-ignore-subject)
10631                  (gnus-simplify-subject-re
10632                   (mail-header-subject (gnus-data-header (car data)))))
10633                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10634                  (gnus-simplify-subject-fuzzy
10635                   (mail-header-subject (gnus-data-header (car data)))))
10636                 (t nil)))
10637          (end-point (save-excursion
10638                       (if (gnus-summary-go-to-next-thread)
10639                           (point) (point-max))))
10640          articles)
10641     (while (and data
10642                 (< (gnus-data-pos (car data)) end-point))
10643       (when (or (not top-subject)
10644                 (string= top-subject
10645                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10646                              (gnus-simplify-subject-fuzzy
10647                               (mail-header-subject
10648                                (gnus-data-header (car data))))
10649                            (gnus-simplify-subject-re
10650                             (mail-header-subject
10651                              (gnus-data-header (car data)))))))
10652         (push (gnus-data-number (car data)) articles))
10653       (unless (and (setq data (cdr data))
10654                    (> (gnus-data-level (car data)) top-level))
10655         (setq data nil)))
10656     ;; Return the list of articles.
10657     (nreverse articles)))
10658
10659 (defun gnus-summary-rethread-current ()
10660   "Rethread the thread the current article is part of."
10661   (interactive)
10662   (let* ((gnus-show-threads t)
10663          (article (gnus-summary-article-number))
10664          (id (mail-header-id (gnus-summary-article-header)))
10665          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10666     (unless id
10667       (error "No article on the current line"))
10668     (gnus-rebuild-thread id)
10669     (gnus-summary-goto-subject article)))
10670
10671 (defun gnus-summary-reparent-thread ()
10672   "Make the current article child of the marked (or previous) article.
10673
10674 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10675 is non-nil or the Subject: of both articles are the same."
10676   (interactive)
10677   (unless (not (gnus-group-read-only-p))
10678     (error "The current newsgroup does not support article editing"))
10679   (unless (<= (length gnus-newsgroup-processable) 1)
10680     (error "No more than one article may be marked"))
10681   (save-window-excursion
10682     (let ((gnus-article-buffer " *reparent*")
10683           (current-article (gnus-summary-article-number))
10684           ;; First grab the marked article, otherwise one line up.
10685           (parent-article (if (not (null gnus-newsgroup-processable))
10686                               (car gnus-newsgroup-processable)
10687                             (save-excursion
10688                               (if (eq (forward-line -1) 0)
10689                                   (gnus-summary-article-number)
10690                                 (error "Beginning of summary buffer"))))))
10691       (unless (not (eq current-article parent-article))
10692         (error "An article may not be self-referential"))
10693       (let ((message-id (mail-header-id
10694                          (gnus-summary-article-header parent-article))))
10695         (unless (and message-id (not (equal message-id "")))
10696           (error "No message-id in desired parent"))
10697         (gnus-with-article current-article
10698           (save-restriction
10699             (goto-char (point-min))
10700             (message-narrow-to-head)
10701             (if (re-search-forward "^References: " nil t)
10702                 (progn
10703                   (re-search-forward "^[^ \t]" nil t)
10704                   (forward-line -1)
10705                   (end-of-line)
10706                   (insert " " message-id))
10707               (insert "References: " message-id "\n"))))
10708         (set-buffer gnus-summary-buffer)
10709         (gnus-summary-unmark-all-processable)
10710         (gnus-summary-update-article current-article)
10711         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10712             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10713         (gnus-summary-rethread-current)
10714         (gnus-message 3 "Article %d is now the child of article %d"
10715                       current-article parent-article)))))
10716
10717 (defun gnus-summary-toggle-threads (&optional arg)
10718   "Toggle showing conversation threads.
10719 If ARG is positive number, turn showing conversation threads on."
10720   (interactive "P")
10721   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10722     (setq gnus-show-threads
10723           (if (null arg) (not gnus-show-threads)
10724             (> (prefix-numeric-value arg) 0)))
10725     (gnus-summary-prepare)
10726     (gnus-summary-goto-subject current)
10727     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10728     (gnus-summary-position-point)))
10729
10730 (defun gnus-summary-show-all-threads ()
10731   "Show all threads."
10732   (interactive)
10733   (save-excursion
10734     (let ((buffer-read-only nil))
10735       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10736   (gnus-summary-position-point))
10737
10738 (defun gnus-summary-show-thread ()
10739   "Show thread subtrees.
10740 Returns nil if no thread was there to be shown."
10741   (interactive)
10742   (let ((buffer-read-only nil)
10743         (orig (point))
10744         (end (point-at-eol))
10745         ;; Leave point at bol
10746         (beg (progn (beginning-of-line) (point))))
10747     (prog1
10748         ;; Any hidden lines here?
10749         (search-forward "\r" end t)
10750       (subst-char-in-region beg end ?\^M ?\n t)
10751       (goto-char orig)
10752       (gnus-summary-position-point))))
10753
10754 (defun gnus-summary-maybe-hide-threads ()
10755   "If requested, hide the threads that should be hidden."
10756   (when (and gnus-show-threads
10757              gnus-thread-hide-subtree)
10758     (gnus-summary-hide-all-threads
10759      (if (or (consp gnus-thread-hide-subtree)
10760              (functionp gnus-thread-hide-subtree))
10761          (gnus-make-predicate gnus-thread-hide-subtree)
10762        nil))))
10763
10764 ;;; Hiding predicates.
10765
10766 (defun gnus-article-unread-p (header)
10767   (memq (mail-header-number header) gnus-newsgroup-unreads))
10768
10769 (defun gnus-article-unseen-p (header)
10770   (memq (mail-header-number header) gnus-newsgroup-unseen))
10771
10772 (defun gnus-map-articles (predicate articles)
10773   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10774   (apply 'gnus-or (mapcar predicate
10775                           (mapcar 'gnus-summary-article-header articles))))
10776
10777 (defun gnus-summary-hide-all-threads (&optional predicate)
10778   "Hide all thread subtrees.
10779 If PREDICATE is supplied, threads that satisfy this predicate
10780 will not be hidden."
10781   (interactive)
10782   (save-excursion
10783     (goto-char (point-min))
10784     (let ((end nil))
10785       (while (not end)
10786         (when (or (not predicate)
10787                   (gnus-map-articles
10788                    predicate (gnus-summary-article-children)))
10789             (gnus-summary-hide-thread))
10790         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10791   (gnus-summary-position-point))
10792
10793 (defun gnus-summary-hide-thread ()
10794   "Hide thread subtrees.
10795 If PREDICATE is supplied, threads that satisfy this predicate
10796 will not be hidden.
10797 Returns nil if no threads were there to be hidden."
10798   (interactive)
10799   (let ((buffer-read-only nil)
10800         (start (point))
10801         (article (gnus-summary-article-number)))
10802     (goto-char start)
10803     ;; Go forward until either the buffer ends or the subthread
10804     ;; ends.
10805     (when (and (not (eobp))
10806                (or (zerop (gnus-summary-next-thread 1 t))
10807                    (goto-char (point-max))))
10808       (prog1
10809           (if (and (> (point) start)
10810                    (search-backward "\n" start t))
10811               (progn
10812                 (subst-char-in-region start (point) ?\n ?\^M)
10813                 (gnus-summary-goto-subject article))
10814             (goto-char start)
10815             nil)))))
10816
10817 (defun gnus-summary-go-to-next-thread (&optional previous)
10818   "Go to the same level (or less) next thread.
10819 If PREVIOUS is non-nil, go to previous thread instead.
10820 Return the article number moved to, or nil if moving was impossible."
10821   (let ((level (gnus-summary-thread-level))
10822         (way (if previous -1 1))
10823         (beg (point)))
10824     (forward-line way)
10825     (while (and (not (eobp))
10826                 (< level (gnus-summary-thread-level)))
10827       (forward-line way))
10828     (if (eobp)
10829         (progn
10830           (goto-char beg)
10831           nil)
10832       (setq beg (point))
10833       (prog1
10834           (gnus-summary-article-number)
10835         (goto-char beg)))))
10836
10837 (defun gnus-summary-next-thread (n &optional silent)
10838   "Go to the same level next N'th thread.
10839 If N is negative, search backward instead.
10840 Returns the difference between N and the number of skips actually
10841 done.
10842
10843 If SILENT, don't output messages."
10844   (interactive "p")
10845   (let ((backward (< n 0))
10846         (n (abs n)))
10847     (while (and (> n 0)
10848                 (gnus-summary-go-to-next-thread backward))
10849       (decf n))
10850     (unless silent
10851       (gnus-summary-position-point))
10852     (when (and (not silent) (/= 0 n))
10853       (gnus-message 7 "No more threads"))
10854     n))
10855
10856 (defun gnus-summary-prev-thread (n)
10857   "Go to the same level previous N'th thread.
10858 Returns the difference between N and the number of skips actually
10859 done."
10860   (interactive "p")
10861   (gnus-summary-next-thread (- n)))
10862
10863 (defun gnus-summary-go-down-thread ()
10864   "Go down one level in the current thread."
10865   (let ((children (gnus-summary-article-children)))
10866     (when children
10867       (gnus-summary-goto-subject (car children)))))
10868
10869 (defun gnus-summary-go-up-thread ()
10870   "Go up one level in the current thread."
10871   (let ((parent (gnus-summary-article-parent)))
10872     (when parent
10873       (gnus-summary-goto-subject parent))))
10874
10875 (defun gnus-summary-down-thread (n)
10876   "Go down thread N steps.
10877 If N is negative, go up instead.
10878 Returns the difference between N and how many steps down that were
10879 taken."
10880   (interactive "p")
10881   (let ((up (< n 0))
10882         (n (abs n)))
10883     (while (and (> n 0)
10884                 (if up (gnus-summary-go-up-thread)
10885                   (gnus-summary-go-down-thread)))
10886       (setq n (1- n)))
10887     (gnus-summary-position-point)
10888     (when (/= 0 n)
10889       (gnus-message 7 "Can't go further"))
10890     n))
10891
10892 (defun gnus-summary-up-thread (n)
10893   "Go up thread N steps.
10894 If N is negative, go down instead.
10895 Returns the difference between N and how many steps down that were
10896 taken."
10897   (interactive "p")
10898   (gnus-summary-down-thread (- n)))
10899
10900 (defun gnus-summary-top-thread ()
10901   "Go to the top of the thread."
10902   (interactive)
10903   (while (gnus-summary-go-up-thread))
10904   (gnus-summary-article-number))
10905
10906 (defun gnus-summary-kill-thread (&optional unmark)
10907   "Mark articles under current thread as read.
10908 If the prefix argument is positive, remove any kinds of marks.
10909 If the prefix argument is negative, tick articles instead."
10910   (interactive "P")
10911   (when unmark
10912     (setq unmark (prefix-numeric-value unmark)))
10913   (let ((articles (gnus-summary-articles-in-thread)))
10914     (save-excursion
10915       ;; Expand the thread.
10916       (gnus-summary-show-thread)
10917       ;; Mark all the articles.
10918       (while articles
10919         (gnus-summary-goto-subject (car articles))
10920         (cond ((null unmark)
10921                (gnus-summary-mark-article-as-read gnus-killed-mark))
10922               ((> unmark 0)
10923                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10924               (t
10925                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10926         (setq articles (cdr articles))))
10927     ;; Hide killed subtrees.
10928     (and (null unmark)
10929          gnus-thread-hide-killed
10930          (gnus-summary-hide-thread))
10931     ;; If marked as read, go to next unread subject.
10932     (when (null unmark)
10933       ;; Go to next unread subject.
10934       (gnus-summary-next-subject 1 t)))
10935   (gnus-set-mode-line 'summary))
10936
10937 ;; Summary sorting commands
10938
10939 (defun gnus-summary-sort-by-number (&optional reverse)
10940   "Sort the summary buffer by article number.
10941 Argument REVERSE means reverse order."
10942   (interactive "P")
10943   (gnus-summary-sort 'number reverse))
10944
10945 (defun gnus-summary-sort-by-random (&optional reverse)
10946   "Randomize the order in the summary buffer.
10947 Argument REVERSE means to randomize in reverse order."
10948   (interactive "P")
10949   (gnus-summary-sort 'random reverse))
10950
10951 (defun gnus-summary-sort-by-author (&optional reverse)
10952   "Sort the summary buffer by author name alphabetically.
10953 If `case-fold-search' is non-nil, case of letters is ignored.
10954 Argument REVERSE means reverse order."
10955   (interactive "P")
10956   (gnus-summary-sort 'author reverse))
10957
10958 (defun gnus-summary-sort-by-recipient (&optional reverse)
10959   "Sort the summary buffer by recipient name alphabetically.
10960 If `case-fold-search' is non-nil, case of letters is ignored.
10961 Argument REVERSE means reverse order."
10962   (interactive "P")
10963   (gnus-summary-sort 'recipient reverse))
10964
10965 (defun gnus-summary-sort-by-subject (&optional reverse)
10966   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10967 If `case-fold-search' is non-nil, case of letters is ignored.
10968 Argument REVERSE means reverse order."
10969   (interactive "P")
10970   (gnus-summary-sort 'subject reverse))
10971
10972 (defun gnus-summary-sort-by-date (&optional reverse)
10973   "Sort the summary buffer by date.
10974 Argument REVERSE means reverse order."
10975   (interactive "P")
10976   (gnus-summary-sort 'date reverse))
10977
10978 (defun gnus-summary-sort-by-score (&optional reverse)
10979   "Sort the summary buffer by score.
10980 Argument REVERSE means reverse order."
10981   (interactive "P")
10982   (gnus-summary-sort 'score reverse))
10983
10984 (defun gnus-summary-sort-by-lines (&optional reverse)
10985   "Sort the summary buffer by the number of lines.
10986 Argument REVERSE means reverse order."
10987   (interactive "P")
10988   (gnus-summary-sort 'lines reverse))
10989
10990 (defun gnus-summary-sort-by-chars (&optional reverse)
10991   "Sort the summary buffer by article length.
10992 Argument REVERSE means reverse order."
10993   (interactive "P")
10994   (gnus-summary-sort 'chars reverse))
10995
10996 (defun gnus-summary-sort-by-original (&optional reverse)
10997   "Sort the summary buffer using the default sorting method.
10998 Argument REVERSE means reverse order."
10999   (interactive "P")
11000   (let* ((buffer-read-only)
11001          (gnus-summary-prepare-hook nil))
11002     ;; We do the sorting by regenerating the threads.
11003     (gnus-summary-prepare)
11004     ;; Hide subthreads if needed.
11005     (gnus-summary-maybe-hide-threads)))
11006
11007 (defun gnus-summary-sort (predicate reverse)
11008   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11009   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11010          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11011          (gnus-thread-sort-functions
11012           (if (not reverse)
11013               thread
11014             `(lambda (t1 t2)
11015                (,thread t2 t1))))
11016          (gnus-sort-gathered-threads-function
11017           gnus-thread-sort-functions)
11018          (gnus-article-sort-functions
11019           (if (not reverse)
11020               article
11021             `(lambda (t1 t2)
11022                (,article t2 t1))))
11023          (buffer-read-only)
11024          (gnus-summary-prepare-hook nil))
11025     ;; We do the sorting by regenerating the threads.
11026     (gnus-summary-prepare)
11027     ;; Hide subthreads if needed.
11028     (gnus-summary-maybe-hide-threads)))
11029
11030 ;; Summary saving commands.
11031
11032 (defun gnus-summary-save-article (&optional n not-saved)
11033   "Save the current article using the default saver function.
11034 If N is a positive number, save the N next articles.
11035 If N is a negative number, save the N previous articles.
11036 If N is nil and any articles have been marked with the process mark,
11037 save those articles instead.
11038 The variable `gnus-default-article-saver' specifies the saver function."
11039   (interactive "P")
11040   (let* ((articles (gnus-summary-work-articles n))
11041          (save-buffer (save-excursion
11042                         (nnheader-set-temp-buffer " *Gnus Save*")))
11043          (num (length articles))
11044          header file)
11045     (dolist (article articles)
11046       (setq header (gnus-summary-article-header article))
11047       (if (not (vectorp header))
11048           ;; This is a pseudo-article.
11049           (if (assq 'name header)
11050               (gnus-copy-file (cdr (assq 'name header)))
11051             (gnus-message 1 "Article %d is unsaveable" article))
11052         ;; This is a real article.
11053         (save-window-excursion
11054           (let ((gnus-display-mime-function nil)
11055                 (gnus-article-prepare-hook nil))
11056             (gnus-summary-select-article t nil nil article)))
11057         (save-excursion
11058           (set-buffer save-buffer)
11059           (erase-buffer)
11060           (insert-buffer-substring gnus-original-article-buffer))
11061         (setq file (gnus-article-save save-buffer file num))
11062         (gnus-summary-remove-process-mark article)
11063         (unless not-saved
11064           (gnus-summary-set-saved-mark article))))
11065     (gnus-kill-buffer save-buffer)
11066     (gnus-summary-position-point)
11067     (gnus-set-mode-line 'summary)
11068     n))
11069
11070 (defun gnus-summary-pipe-output (&optional arg headers)
11071   "Pipe the current article to a subprocess.
11072 If N is a positive number, pipe the N next articles.
11073 If N is a negative number, pipe the N previous articles.
11074 If N is nil and any articles have been marked with the process mark,
11075 pipe those articles instead.
11076 If HEADERS (the symbolic prefix), include the headers, too."
11077   (interactive (gnus-interactive "P\ny"))
11078   (require 'gnus-art)
11079   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11080         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11081     (gnus-summary-save-article arg t))
11082   (let ((buffer (get-buffer "*Shell Command Output*")))
11083     (when (and buffer
11084                (not (zerop (buffer-size buffer))))
11085       (gnus-configure-windows 'pipe))))
11086
11087 (defun gnus-summary-save-article-mail (&optional arg)
11088   "Append the current article to an mail file.
11089 If N is a positive number, save the N next articles.
11090 If N is a negative number, save the N previous articles.
11091 If N is nil and any articles have been marked with the process mark,
11092 save those articles instead."
11093   (interactive "P")
11094   (require 'gnus-art)
11095   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11096     (gnus-summary-save-article arg)))
11097
11098 (defun gnus-summary-save-article-rmail (&optional arg)
11099   "Append the current article to an rmail file.
11100 If N is a positive number, save the N next articles.
11101 If N is a negative number, save the N previous articles.
11102 If N is nil and any articles have been marked with the process mark,
11103 save those articles instead."
11104   (interactive "P")
11105   (require 'gnus-art)
11106   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11107     (gnus-summary-save-article arg)))
11108
11109 (defun gnus-summary-save-article-file (&optional arg)
11110   "Append the current article to a file.
11111 If N is a positive number, save the N next articles.
11112 If N is a negative number, save the N previous articles.
11113 If N is nil and any articles have been marked with the process mark,
11114 save those articles instead."
11115   (interactive "P")
11116   (require 'gnus-art)
11117   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11118     (gnus-summary-save-article arg)))
11119
11120 (defun gnus-summary-write-article-file (&optional arg)
11121   "Write the current article to a file, deleting the previous file.
11122 If N is a positive number, save the N next articles.
11123 If N is a negative number, save the N previous articles.
11124 If N is nil and any articles have been marked with the process mark,
11125 save those articles instead."
11126   (interactive "P")
11127   (require 'gnus-art)
11128   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11129     (gnus-summary-save-article arg)))
11130
11131 (defun gnus-summary-save-article-body-file (&optional arg)
11132   "Append the current article body to a file.
11133 If N is a positive number, save the N next articles.
11134 If N is a negative number, save the N previous articles.
11135 If N is nil and any articles have been marked with the process mark,
11136 save those articles instead."
11137   (interactive "P")
11138   (require 'gnus-art)
11139   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11140     (gnus-summary-save-article arg)))
11141
11142 (defun gnus-summary-muttprint (&optional arg)
11143   "Print the current article using Muttprint.
11144 If N is a positive number, save the N next articles.
11145 If N is a negative number, save the N previous articles.
11146 If N is nil and any articles have been marked with the process mark,
11147 save those articles instead."
11148   (interactive "P")
11149   (require 'gnus-art)
11150   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11151     (gnus-summary-save-article arg t)))
11152
11153 (defun gnus-summary-pipe-message (program)
11154   "Pipe the current article through PROGRAM."
11155   (interactive "sProgram: ")
11156   (gnus-summary-select-article)
11157   (let ((mail-header-separator ""))
11158     (gnus-eval-in-buffer-window gnus-article-buffer
11159       (save-restriction
11160         (widen)
11161         (let ((start (window-start))
11162               buffer-read-only)
11163           (message-pipe-buffer-body program)
11164           (set-window-start (get-buffer-window (current-buffer)) start))))))
11165
11166 (defun gnus-get-split-value (methods)
11167   "Return a value based on the split METHODS."
11168   (let (split-name method result match)
11169     (when methods
11170       (save-excursion
11171         (set-buffer gnus-original-article-buffer)
11172         (save-restriction
11173           (nnheader-narrow-to-headers)
11174           (while (and methods (not split-name))
11175             (goto-char (point-min))
11176             (setq method (pop methods))
11177             (setq match (car method))
11178             (when (cond
11179                    ((stringp match)
11180                     ;; Regular expression.
11181                     (ignore-errors
11182                       (re-search-forward match nil t)))
11183                    ((functionp match)
11184                     ;; Function.
11185                     (save-restriction
11186                       (widen)
11187                       (setq result (funcall match gnus-newsgroup-name))))
11188                    ((consp match)
11189                     ;; Form.
11190                     (save-restriction
11191                       (widen)
11192                       (setq result (eval match)))))
11193               (setq split-name (cdr method))
11194               (cond ((stringp result)
11195                      (push (expand-file-name
11196                             result gnus-article-save-directory)
11197                            split-name))
11198                     ((consp result)
11199                      (setq split-name (append result split-name)))))))))
11200     (nreverse split-name)))
11201
11202 (defun gnus-valid-move-group-p (group)
11203   (and (boundp group)
11204        (symbol-name group)
11205        (symbol-value group)
11206        (gnus-get-function (gnus-find-method-for-group
11207                            (symbol-name group)) 'request-accept-article t)))
11208
11209 (defun gnus-read-move-group-name (prompt default articles prefix)
11210   "Read a group name."
11211   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11212          (minibuffer-confirm-incomplete nil) ; XEmacs
11213          (prom
11214           (format "%s %s to:"
11215                   prompt
11216                   (if (> (length articles) 1)
11217                       (format "these %d articles" (length articles))
11218                     "this article")))
11219          (to-newsgroup
11220           (cond
11221            ((null split-name)
11222             (gnus-completing-read-with-default
11223              default prom
11224              gnus-active-hashtb
11225              'gnus-valid-move-group-p
11226              nil prefix
11227              'gnus-group-history))
11228            ((= 1 (length split-name))
11229             (gnus-completing-read-with-default
11230              (car split-name) prom
11231              gnus-active-hashtb
11232              'gnus-valid-move-group-p
11233              nil nil
11234              'gnus-group-history))
11235            (t
11236             (gnus-completing-read-with-default
11237              nil prom
11238              (mapcar 'list (nreverse split-name))
11239              nil nil nil
11240              'gnus-group-history))))
11241          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11242     (when to-newsgroup
11243       (if (or (string= to-newsgroup "")
11244               (string= to-newsgroup prefix))
11245           (setq to-newsgroup default))
11246       (unless to-newsgroup
11247         (error "No group name entered"))
11248       (or (gnus-active to-newsgroup)
11249           (gnus-activate-group to-newsgroup nil nil to-method)
11250           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11251                                      to-newsgroup))
11252               (or (and (gnus-request-create-group to-newsgroup to-method)
11253                        (gnus-activate-group
11254                         to-newsgroup nil nil to-method)
11255                        (gnus-subscribe-group to-newsgroup))
11256                   (error "Couldn't create group %s" to-newsgroup)))
11257           (error "No such group: %s" to-newsgroup)))
11258     to-newsgroup))
11259
11260 (defun gnus-summary-save-parts (type dir n &optional reverse)
11261   "Save parts matching TYPE to DIR.
11262 If REVERSE, save parts that do not match TYPE."
11263   (interactive
11264    (list (read-string "Save parts of type: "
11265                       (or (car gnus-summary-save-parts-type-history)
11266                           gnus-summary-save-parts-default-mime)
11267                       'gnus-summary-save-parts-type-history)
11268          (setq gnus-summary-save-parts-last-directory
11269                (read-file-name "Save to directory: "
11270                                gnus-summary-save-parts-last-directory
11271                                nil t))
11272          current-prefix-arg))
11273   (gnus-summary-iterate n
11274     (let ((gnus-display-mime-function nil)
11275           (gnus-inhibit-treatment t))
11276       (gnus-summary-select-article))
11277     (save-excursion
11278       (set-buffer gnus-article-buffer)
11279       (let ((handles (or gnus-article-mime-handles
11280                          (mm-dissect-buffer nil gnus-article-loose-mime)
11281                          (and gnus-article-emulate-mime
11282                               (mm-uu-dissect)))))
11283         (when handles
11284           (gnus-summary-save-parts-1 type dir handles reverse)
11285           (unless gnus-article-mime-handles ;; Don't destroy this case.
11286             (mm-destroy-parts handles)))))))
11287
11288 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11289   (if (stringp (car handle))
11290       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11291               (cdr handle))
11292     (when (if reverse
11293               (not (string-match type (mm-handle-media-type handle)))
11294             (string-match type (mm-handle-media-type handle)))
11295       (let ((file (expand-file-name
11296                    (gnus-map-function
11297                     mm-file-name-rewrite-functions
11298                     (file-name-nondirectory
11299                      (or
11300                       (mail-content-type-get
11301                        (mm-handle-disposition handle) 'filename)
11302                       (mail-content-type-get
11303                        (mm-handle-type handle) 'name)
11304                       (concat gnus-newsgroup-name
11305                               "." (number-to-string
11306                                    (cdr gnus-article-current))))))
11307                    dir)))
11308         (unless (file-exists-p file)
11309           (mm-save-part-to-file handle file))))))
11310
11311 ;; Summary extract commands
11312
11313 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11314   (let ((buffer-read-only nil)
11315         (article (gnus-summary-article-number))
11316         after-article b e)
11317     (unless (gnus-summary-goto-subject article)
11318       (error "No such article: %d" article))
11319     (gnus-summary-position-point)
11320     ;; If all commands are to be bunched up on one line, we collect
11321     ;; them here.
11322     (unless gnus-view-pseudos-separately
11323       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11324             files action)
11325         (while ps
11326           (setq action (cdr (assq 'action (car ps))))
11327           (setq files (list (cdr (assq 'name (car ps)))))
11328           (while (and ps (cdr ps)
11329                       (string= (or action "1")
11330                                (or (cdr (assq 'action (cadr ps))) "2")))
11331             (push (cdr (assq 'name (cadr ps))) files)
11332             (setcdr ps (cddr ps)))
11333           (when files
11334             (when (not (string-match "%s" action))
11335               (push " " files))
11336             (push " " files)
11337             (when (assq 'execute (car ps))
11338               (setcdr (assq 'execute (car ps))
11339                       (funcall (if (string-match "%s" action)
11340                                    'format 'concat)
11341                                action
11342                                (mapconcat
11343                                 (lambda (f)
11344                                   (if (equal f " ")
11345                                       f
11346                                     (shell-quote-argument f)))
11347                                 files " ")))))
11348           (setq ps (cdr ps)))))
11349     (if (and gnus-view-pseudos (not not-view))
11350         (while pslist
11351           (when (assq 'execute (car pslist))
11352             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11353                                   (eq gnus-view-pseudos 'not-confirm)))
11354           (setq pslist (cdr pslist)))
11355       (save-excursion
11356         (while pslist
11357           (setq after-article (or (cdr (assq 'article (car pslist)))
11358                                   (gnus-summary-article-number)))
11359           (gnus-summary-goto-subject after-article)
11360           (forward-line 1)
11361           (setq b (point))
11362           (insert "    " (file-name-nondirectory
11363                           (cdr (assq 'name (car pslist))))
11364                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11365           (setq e (point))
11366           (forward-line -1)             ; back to `b'
11367           (gnus-add-text-properties
11368            b (1- e) (list 'gnus-number gnus-reffed-article-number
11369                           gnus-mouse-face-prop gnus-mouse-face))
11370           (gnus-data-enter
11371            after-article gnus-reffed-article-number
11372            gnus-unread-mark b (car pslist) 0 (- e b))
11373           (setq gnus-newsgroup-unreads
11374                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11375                                          gnus-reffed-article-number))
11376           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11377           (setq pslist (cdr pslist)))))))
11378
11379 (defun gnus-pseudos< (p1 p2)
11380   (let ((c1 (cdr (assq 'action p1)))
11381         (c2 (cdr (assq 'action p2))))
11382     (and c1 c2 (string< c1 c2))))
11383
11384 (defun gnus-request-pseudo-article (props)
11385   (cond ((assq 'execute props)
11386          (gnus-execute-command (cdr (assq 'execute props)))))
11387   (let ((gnus-current-article (gnus-summary-article-number)))
11388     (gnus-run-hooks 'gnus-mark-article-hook)))
11389
11390 (defun gnus-execute-command (command &optional automatic)
11391   (save-excursion
11392     (gnus-article-setup-buffer)
11393     (set-buffer gnus-article-buffer)
11394     (setq buffer-read-only nil)
11395     (let ((command (if automatic command
11396                      (read-string "Command: " (cons command 0)))))
11397       (erase-buffer)
11398       (insert "$ " command "\n\n")
11399       (if gnus-view-pseudo-asynchronously
11400           (start-process "gnus-execute" (current-buffer) shell-file-name
11401                          shell-command-switch command)
11402         (call-process shell-file-name nil t nil
11403                       shell-command-switch command)))))
11404
11405 ;; Summary kill commands.
11406
11407 (defun gnus-summary-edit-global-kill (article)
11408   "Edit the \"global\" kill file."
11409   (interactive (list (gnus-summary-article-number)))
11410   (gnus-group-edit-global-kill article))
11411
11412 (defun gnus-summary-edit-local-kill ()
11413   "Edit a local kill file applied to the current newsgroup."
11414   (interactive)
11415   (setq gnus-current-headers (gnus-summary-article-header))
11416   (gnus-group-edit-local-kill
11417    (gnus-summary-article-number) gnus-newsgroup-name))
11418
11419 ;;; Header reading.
11420
11421 (defun gnus-read-header (id &optional header)
11422   "Read the headers of article ID and enter them into the Gnus system."
11423   (let ((group gnus-newsgroup-name)
11424         (gnus-override-method
11425          (or
11426           gnus-override-method
11427           (and (gnus-news-group-p gnus-newsgroup-name)
11428                (car (gnus-refer-article-methods)))))
11429         where)
11430     ;; First we check to see whether the header in question is already
11431     ;; fetched.
11432     (if (stringp id)
11433         ;; This is a Message-ID.
11434         (setq header (or header (gnus-id-to-header id)))
11435       ;; This is an article number.
11436       (setq header (or header (gnus-summary-article-header id))))
11437     (if (and header
11438              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11439         ;; We have found the header.
11440         header
11441       ;; We have to really fetch the header to this article.
11442       (save-excursion
11443         (set-buffer nntp-server-buffer)
11444         (when (setq where (gnus-request-head id group))
11445           (nnheader-fold-continuation-lines)
11446           (goto-char (point-max))
11447           (insert ".\n")
11448           (goto-char (point-min))
11449           (insert "211 ")
11450           (princ (cond
11451                   ((numberp id) id)
11452                   ((cdr where) (cdr where))
11453                   (header (mail-header-number header))
11454                   (t gnus-reffed-article-number))
11455                  (current-buffer))
11456           (insert " Article retrieved.\n"))
11457         (if (or (not where)
11458                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11459             ()                          ; Malformed head.
11460           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11461             (when (and (stringp id)
11462                        (not (string= (gnus-group-real-name group)
11463                                      (car where))))
11464               ;; If we fetched by Message-ID and the article came
11465               ;; from a different group, we fudge some bogus article
11466               ;; numbers for this article.
11467               (mail-header-set-number header gnus-reffed-article-number))
11468             (save-excursion
11469               (set-buffer gnus-summary-buffer)
11470               (decf gnus-reffed-article-number)
11471               (gnus-remove-header (mail-header-number header))
11472               (push header gnus-newsgroup-headers)
11473               (setq gnus-current-headers header)
11474               (push (mail-header-number header) gnus-newsgroup-limit)))
11475           header)))))
11476
11477 (defun gnus-remove-header (number)
11478   "Remove header NUMBER from `gnus-newsgroup-headers'."
11479   (if (and gnus-newsgroup-headers
11480            (= number (mail-header-number (car gnus-newsgroup-headers))))
11481       (pop gnus-newsgroup-headers)
11482     (let ((headers gnus-newsgroup-headers))
11483       (while (and (cdr headers)
11484                   (not (= number (mail-header-number (cadr headers)))))
11485         (pop headers))
11486       (when (cdr headers)
11487         (setcdr headers (cddr headers))))))
11488
11489 ;;;
11490 ;;; summary highlights
11491 ;;;
11492
11493 (defun gnus-highlight-selected-summary ()
11494   "Highlight selected article in summary buffer."
11495   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11496   (when gnus-summary-selected-face
11497     (save-excursion
11498       (let* ((beg (point-at-bol))
11499              (end (point-at-eol))
11500              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11501              (from (if (get-text-property beg gnus-mouse-face-prop)
11502                        beg
11503                      (or (next-single-property-change
11504                           beg gnus-mouse-face-prop nil end)
11505                          beg)))
11506              (to
11507               (if (= from end)
11508                   (- from 2)
11509                 (or (next-single-property-change
11510                      from gnus-mouse-face-prop nil end)
11511                     end))))
11512         ;; If no mouse-face prop on line we will have to = from = end,
11513         ;; so we highlight the entire line instead.
11514         (when (= (+ to 2) from)
11515           (setq from beg)
11516           (setq to end))
11517         (if gnus-newsgroup-selected-overlay
11518             ;; Move old overlay.
11519             (gnus-move-overlay
11520              gnus-newsgroup-selected-overlay from to (current-buffer))
11521           ;; Create new overlay.
11522           (gnus-overlay-put
11523            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11524            'face gnus-summary-selected-face))))))
11525
11526 (defvar gnus-summary-highlight-line-cached nil)
11527 (defvar gnus-summary-highlight-line-trigger nil)
11528
11529 (defun gnus-summary-highlight-line-0 ()
11530   (if (and (eq gnus-summary-highlight-line-trigger
11531                gnus-summary-highlight)
11532            gnus-summary-highlight-line-cached)
11533       gnus-summary-highlight-line-cached
11534     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11535           gnus-summary-highlight-line-cached
11536           (let* ((cond (list 'cond))
11537                  (c cond)
11538                  (list gnus-summary-highlight))
11539             (while list
11540               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11541                               nil))
11542               (setq c (cdr c)
11543                     list (cdr list)))
11544             (gnus-byte-compile (list 'lambda nil cond))))))
11545
11546 (defun gnus-summary-highlight-line ()
11547   "Highlight current line according to `gnus-summary-highlight'."
11548   (let* ((beg (point-at-bol))
11549          (article (or (gnus-summary-article-number) gnus-current-article))
11550          (score (or (cdr (assq article
11551                                gnus-newsgroup-scored))
11552                     gnus-summary-default-score 0))
11553          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11554          (inhibit-read-only t)
11555          (default gnus-summary-default-score)
11556          (default-high gnus-summary-default-high-score)
11557          (default-low gnus-summary-default-low-score)
11558          (uncached (and gnus-summary-use-undownloaded-faces
11559                         (memq article gnus-newsgroup-undownloaded)
11560                         (not (memq article gnus-newsgroup-cached)))))
11561     (let ((face (funcall (gnus-summary-highlight-line-0))))
11562       (unless (eq face (get-text-property beg 'face))
11563         (gnus-put-text-property-excluding-characters-with-faces
11564          beg (point-at-eol) 'face
11565          (setq face (if (boundp face) (symbol-value face) face)))
11566         (when gnus-summary-highlight-line-function
11567           (funcall gnus-summary-highlight-line-function article face))))))
11568
11569 (defun gnus-update-read-articles (group unread &optional compute)
11570   "Update the list of read articles in GROUP.
11571 UNREAD is a sorted list."
11572   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11573         (info (gnus-get-info group))
11574         (prev 1)
11575         read)
11576     (if (or (not info) (not active))
11577         ;; There is no info on this group if it was, in fact,
11578         ;; killed.  Gnus stores no information on killed groups, so
11579         ;; there's nothing to be done.
11580         ;; One could store the information somewhere temporarily,
11581         ;; perhaps...  Hmmm...
11582         ()
11583       ;; Remove any negative articles numbers.
11584       (while (and unread (< (car unread) 0))
11585         (setq unread (cdr unread)))
11586       ;; Remove any expired article numbers
11587       (while (and unread (< (car unread) (car active)))
11588         (setq unread (cdr unread)))
11589       ;; Compute the ranges of read articles by looking at the list of
11590       ;; unread articles.
11591       (while unread
11592         (when (/= (car unread) prev)
11593           (push (if (= prev (1- (car unread))) prev
11594                   (cons prev (1- (car unread))))
11595                 read))
11596         (setq prev (1+ (car unread)))
11597         (setq unread (cdr unread)))
11598       (when (<= prev (cdr active))
11599         (push (cons prev (cdr active)) read))
11600       (setq read (if (> (length read) 1) (nreverse read) read))
11601       (if compute
11602           read
11603         (save-excursion
11604           (let (setmarkundo)
11605             ;; Propagate the read marks to the backend.
11606             (when (gnus-check-backend-function 'request-set-mark group)
11607               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11608                     (add (gnus-remove-from-range read (gnus-info-read info))))
11609                 (when (or add del)
11610                   (unless (gnus-check-group group)
11611                     (error "Can't open server for %s" group))
11612                   (gnus-request-set-mark
11613                    group (delq nil (list (if add (list add 'add '(read)))
11614                                          (if del (list del 'del '(read))))))
11615                   (setq setmarkundo
11616                         `(gnus-request-set-mark
11617                           ,group
11618                           ',(delq nil (list
11619                                        (if del (list del 'add '(read)))
11620                                        (if add (list add 'del '(read))))))))))
11621             (set-buffer gnus-group-buffer)
11622             (gnus-undo-register
11623               `(progn
11624                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11625                  (gnus-info-set-read ',info ',(gnus-info-read info))
11626                  (gnus-get-unread-articles-in-group ',info
11627                                                     (gnus-active ,group))
11628                  (gnus-group-update-group ,group t)
11629                  ,setmarkundo))))
11630         ;; Enter this list into the group info.
11631         (gnus-info-set-read info read)
11632         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11633         (gnus-get-unread-articles-in-group info (gnus-active group))
11634         t))))
11635
11636 (defun gnus-offer-save-summaries ()
11637   "Offer to save all active summary buffers."
11638   (let (buffers)
11639     ;; Go through all buffers and find all summaries.
11640     (dolist (buffer (buffer-list))
11641       (when (and (setq buffer (buffer-name buffer))
11642                  (string-match "Summary" buffer)
11643                  (with-current-buffer buffer
11644                    ;; We check that this is, indeed, a summary buffer.
11645                    (and (eq major-mode 'gnus-summary-mode)
11646                         ;; Also make sure this isn't bogus.
11647                         gnus-newsgroup-prepared
11648                         ;; Also make sure that this isn't a
11649                         ;; dead summary buffer.
11650                         (not gnus-dead-summary-mode))))
11651         (push buffer buffers)))
11652     ;; Go through all these summary buffers and offer to save them.
11653     (when buffers
11654       (save-excursion
11655         (map-y-or-n-p
11656          "Update summary buffer %s? "
11657          (lambda (buf)
11658            (switch-to-buffer buf)
11659            (gnus-summary-exit))
11660          buffers)))))
11661
11662
11663 ;;; @ for mime-partial
11664 ;;;
11665
11666 (defun gnus-request-partial-message ()
11667   (save-excursion
11668     (let ((number (gnus-summary-article-number))
11669           (group gnus-newsgroup-name)
11670           (mother gnus-article-buffer))
11671       (set-buffer (get-buffer-create " *Partial Article*"))
11672       (erase-buffer)
11673       (setq mime-preview-buffer mother)
11674       (gnus-request-article-this-buffer number group)
11675       (mime-parse-buffer)
11676       )))
11677
11678 (autoload 'mime-combine-message/partial-pieces-automatically
11679   "mime-partial"
11680   "Internal method to combine message/partial messages automatically.")
11681
11682 (mime-add-condition
11683  'action '((type . message)(subtype . partial)
11684            (major-mode . gnus-original-article-mode)
11685            (method . mime-combine-message/partial-pieces-automatically)
11686            (summary-buffer-exp . gnus-summary-buffer)
11687            (request-partial-message-method . gnus-request-partial-message)
11688            ))
11689
11690
11691 ;;; @ for message/rfc822
11692 ;;;
11693
11694 (defun gnus-mime-extract-message/rfc822 (entity situation)
11695   "Burst a forwarded article."
11696   (save-excursion
11697     (set-buffer gnus-summary-buffer)
11698     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11699                                    gnus-newsgroup-name 'gnus-group-history))
11700            (gnus-group-marked (list group))
11701            article info)
11702       (with-temp-buffer
11703         (mime-insert-entity-content entity)
11704         (setq article (gnus-request-accept-article group)))
11705       (when (and (consp article)
11706                  (numberp (setq article (cdr article))))
11707         (setq info (gnus-get-info group))
11708         (gnus-info-set-read info
11709                             (gnus-remove-from-range (gnus-info-read info)
11710                                                     (list article)))
11711         (when (string-equal group gnus-newsgroup-name)
11712           (forward-line 1)
11713           (let (gnus-show-threads)
11714             (gnus-summary-goto-subject article t))
11715           (gnus-summary-clear-mark-forward 1))
11716         (set-buffer gnus-group-buffer)
11717         (gnus-group-get-new-news-this-group nil t)))))
11718
11719 (mime-add-condition
11720  'action '((type . message)(subtype . rfc822)
11721            (major-mode . gnus-original-article-mode)
11722            (method . gnus-mime-extract-message/rfc822)
11723            (mode . "extract")
11724            ))
11725
11726 (mime-add-condition
11727  'action '((type . message)(subtype . news)
11728            (major-mode . gnus-original-article-mode)
11729            (method . gnus-mime-extract-message/rfc822)
11730            (mode . "extract")
11731            ))
11732
11733 (defun gnus-mime-extract-multipart (entity situation)
11734   (let ((children (mime-entity-children entity))
11735         mime-acting-situation-to-override
11736         f)
11737     (while children
11738       (mime-play-entity (car children)
11739                         (cons (assq 'mode situation)
11740                               mime-acting-situation-to-override))
11741       (setq children (cdr children)))
11742     (if (setq f (cdr (assq 'after-method
11743                            mime-acting-situation-to-override)))
11744         (eval f)
11745       )))
11746
11747 (mime-add-condition
11748  'action '((type . multipart)
11749            (method . gnus-mime-extract-multipart)
11750            (mode . "extract")
11751            )
11752  'with-default)
11753
11754
11755 ;;; @ end
11756 ;;;
11757
11758 (defun gnus-summary-inherit-default-charset ()
11759   "Import `default-mime-charset' from summary buffer.
11760 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11761 of FLIM is used."
11762   (if (buffer-live-p gnus-summary-buffer)
11763       (let (d-m-c d-m-c-u)
11764         (with-current-buffer gnus-summary-buffer
11765           (setq d-m-c (if (local-variable-p 'default-mime-charset
11766                                             gnus-summary-buffer)
11767                           default-mime-charset
11768                         t)
11769                 ;; LIMIT
11770                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11771                                               gnus-summary-buffer)
11772                             (symbol-value 'default-mime-charset-unlimited)
11773                           t)))
11774         (if (eq t d-m-c)
11775             (kill-local-variable 'default-mime-charset)
11776           (set (make-local-variable 'default-mime-charset) d-m-c))
11777         (if (eq t d-m-c-u)
11778             (kill-local-variable 'default-mime-charset-unlimited)
11779           (set (make-local-variable 'default-mime-charset-unlimited)
11780                d-m-c-u)))))
11781
11782 (defun gnus-summary-setup-default-charset ()
11783   "Setup newsgroup default charset."
11784   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11785       (progn
11786         (setq gnus-newsgroup-charset nil)
11787         (set (make-local-variable 'default-mime-charset) nil)
11788         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11789           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11790     (let ((ignored-charsets
11791            (or gnus-newsgroup-ephemeral-ignored-charsets
11792                (append
11793                 (and gnus-newsgroup-name
11794                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11795                 gnus-newsgroup-ignored-charsets)))
11796           charset)
11797       (setq gnus-newsgroup-charset
11798             (or gnus-newsgroup-ephemeral-charset
11799                 (when (and gnus-newsgroup-name
11800                            (setq charset (gnus-parameter-charset
11801                                           gnus-newsgroup-name)))
11802                   (make-local-variable 'default-mime-charset)
11803                   (setq default-mime-charset charset))
11804                 gnus-default-charset))
11805       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11806            ignored-charsets))))
11807
11808 ;;;
11809 ;;; Mime Commands
11810 ;;;
11811
11812 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11813   "Display the current article buffer fully MIME-buttonized.
11814 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11815 treated as multipart/mixed."
11816   (interactive "P")
11817   (require 'gnus-art)
11818   (let ((gnus-unbuttonized-mime-types nil)
11819         (gnus-mime-display-multipart-as-mixed show-all-parts))
11820     (gnus-summary-show-article)))
11821
11822 (defun gnus-summary-repair-multipart (article)
11823   "Add a Content-Type header to a multipart article without one."
11824   (interactive (list (gnus-summary-article-number)))
11825   (gnus-with-article article
11826     (message-narrow-to-head)
11827     (message-remove-header "Mime-Version")
11828     (goto-char (point-max))
11829     (insert "Mime-Version: 1.0\n")
11830     (widen)
11831     (when (search-forward "\n--" nil t)
11832       (let ((separator (buffer-substring (point) (point-at-eol))))
11833         (message-narrow-to-head)
11834         (message-remove-header "Content-Type")
11835         (goto-char (point-max))
11836         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11837                         separator))
11838         (widen))))
11839   (let (gnus-mark-article-hook)
11840     (gnus-summary-select-article t t nil article)))
11841
11842 (defun gnus-summary-toggle-display-buttonized ()
11843   "Toggle the buttonizing of the article buffer."
11844   (interactive)
11845   (require 'gnus-art)
11846   (if (setq gnus-inhibit-mime-unbuttonizing
11847             (not gnus-inhibit-mime-unbuttonizing))
11848       (let ((gnus-unbuttonized-mime-types nil))
11849         (gnus-summary-show-article))
11850     (gnus-summary-show-article)))
11851
11852 ;;;
11853 ;;; Intelli-mouse commmands
11854 ;;;
11855
11856 (defun gnus-wheel-summary-scroll (event)
11857   (interactive "e")
11858   (let ((amount (if (memq 'shift (event-modifiers event))
11859                     (car gnus-wheel-scroll-amount)
11860                   (cdr gnus-wheel-scroll-amount)))
11861         (direction (- (* (static-if (featurep 'xemacs)
11862                              (event-button event)
11863                            (cond ((eq 'mouse-4 (event-basic-type event))
11864                                   4)
11865                                  ((eq 'mouse-5 (event-basic-type event))
11866                                   5)))
11867                          2) 9))
11868         edge)
11869     (gnus-summary-scroll-up (* amount direction))
11870     (when (gnus-eval-in-buffer-window gnus-article-buffer
11871             (save-restriction
11872               (widen)
11873               (and (if (< 0 direction)
11874                        (gnus-article-next-page 0)
11875                      (gnus-article-prev-page 0)
11876                      (bobp))
11877                    (if (setq edge (get-text-property
11878                                    (point-min) 'gnus-wheel-edge))
11879                        (setq edge (* edge direction))
11880                      (setq edge -1))
11881                    (or (plusp edge)
11882                        (let ((buffer-read-only nil)
11883                              (inhibit-read-only t))
11884                          (put-text-property (point-min) (point-max)
11885                                             'gnus-wheel-edge direction)
11886                          nil))
11887                    (or (> edge gnus-wheel-edge-resistance)
11888                        (let ((buffer-read-only nil)
11889                              (inhibit-read-only t))
11890                          (put-text-property (point-min) (point-max)
11891                                             'gnus-wheel-edge
11892                                             (* (1+ edge) direction))
11893                          nil))
11894                    (eq last-command 'gnus-wheel-summary-scroll))))
11895       (gnus-summary-next-article nil nil (minusp direction)))))
11896
11897 (defun gnus-wheel-install ()
11898   "Enable mouse wheel support on summary window."
11899   (when gnus-use-wheel
11900     (let ((keys
11901            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11902       (dolist (key keys)
11903         (define-key gnus-summary-mode-map key
11904           'gnus-wheel-summary-scroll)))))
11905
11906 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11907
11908 ;;;
11909 ;;; Traditional PGP commmands
11910 ;;;
11911
11912 (defun gnus-summary-decrypt-article (&optional force)
11913   "Decrypt the current article in traditional PGP way.
11914 This will have permanent effect only in mail groups.
11915 If FORCE is non-nil, allow editing of articles even in read-only
11916 groups."
11917   (interactive "P")
11918   (gnus-summary-select-article t)
11919   (gnus-eval-in-buffer-window gnus-article-buffer
11920     (save-excursion
11921       (save-restriction
11922         (widen)
11923         (goto-char (point-min))
11924         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11925           (error "Not a traditional PGP message!"))
11926         (let ((armor-start (match-beginning 0)))
11927           (if (and (pgg-decrypt-region armor-start (point-max))
11928                    (or force (not (gnus-group-read-only-p))))
11929               (let ((inhibit-read-only t)
11930                     buffer-read-only)
11931                 (delete-region armor-start
11932                                (progn
11933                                  (re-search-forward "^-+END PGP" nil t)
11934                                  (beginning-of-line 2)
11935                                  (point)))
11936                 (insert-buffer-substring pgg-output-buffer))))))))
11937
11938 (defun gnus-summary-verify-article ()
11939   "Verify the current article in traditional PGP way."
11940   (interactive)
11941   (save-excursion
11942     (set-buffer gnus-original-article-buffer)
11943     (goto-char (point-min))
11944     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11945       (error "Not a traditional PGP message!"))
11946     (re-search-forward "^-+END PGP" nil t)
11947     (beginning-of-line 2)
11948     (call-interactively (function pgg-verify-region))))
11949
11950 ;;;
11951 ;;; Generic summary marking commands
11952 ;;;
11953
11954 (defvar gnus-summary-marking-alist
11955   '((read gnus-del-mark "d")
11956     (unread gnus-unread-mark "u")
11957     (ticked gnus-ticked-mark "!")
11958     (dormant gnus-dormant-mark "?")
11959     (expirable gnus-expirable-mark "e"))
11960   "An alist of names/marks/keystrokes.")
11961
11962 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11963 (defvar gnus-summary-mark-map)
11964
11965 (defun gnus-summary-make-all-marking-commands ()
11966   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11967   (dolist (elem gnus-summary-marking-alist)
11968     (apply 'gnus-summary-make-marking-command elem)))
11969
11970 (defun gnus-summary-make-marking-command (name mark keystroke)
11971   (let ((map (make-sparse-keymap)))
11972     (define-key gnus-summary-generic-mark-map keystroke map)
11973     (dolist (lway `((next "next" next nil "n")
11974                     (next-unread "next unread" next t "N")
11975                     (prev "previous" prev nil "p")
11976                     (prev-unread "previous unread" prev t "P")
11977                     (nomove "" nil nil ,keystroke)))
11978       (let ((func (gnus-summary-make-marking-command-1
11979                    mark (car lway) lway name)))
11980         (setq func (eval func))
11981         (define-key map (nth 4 lway) func)))))
11982
11983 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11984   `(defun ,(intern
11985             (format "gnus-summary-put-mark-as-%s%s"
11986                     name (if (eq way 'nomove)
11987                              ""
11988                            (concat "-" (symbol-name way)))))
11989      (n)
11990      ,(format
11991        "Mark the current article as %s%s.
11992 If N, the prefix, then repeat N times.
11993 If N is negative, move in reverse order.
11994 The difference between N and the actual number of articles marked is
11995 returned."
11996        name (car (cdr lway)))
11997      (interactive "p")
11998      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11999
12000 (defun gnus-summary-generic-mark (n mark move unread)
12001   "Mark N articles with MARK."
12002   (unless (eq major-mode 'gnus-summary-mode)
12003     (error "This command can only be used in the summary buffer"))
12004   (gnus-summary-show-thread)
12005   (let ((nummove
12006          (cond
12007           ((eq move 'next) 1)
12008           ((eq move 'prev) -1)
12009           (t 0))))
12010     (if (zerop nummove)
12011         (setq n 1)
12012       (when (< n 0)
12013         (setq n (abs n)
12014               nummove (* -1 nummove))))
12015     (while (and (> n 0)
12016                 (gnus-summary-mark-article nil mark)
12017                 (zerop (gnus-summary-next-subject nummove unread t)))
12018       (setq n (1- n)))
12019     (when (/= 0 n)
12020       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12021     (gnus-summary-recenter)
12022     (gnus-summary-position-point)
12023     (gnus-set-mode-line 'summary)
12024     n))
12025
12026 (defun gnus-summary-insert-articles (articles)
12027   (when (setq articles
12028               (gnus-sorted-difference articles
12029                                       (mapcar (lambda (h)
12030                                                 (mail-header-number h))
12031                                               gnus-newsgroup-headers)))
12032     (setq gnus-newsgroup-headers
12033           (gnus-merge 'list
12034                       gnus-newsgroup-headers
12035                       (gnus-fetch-headers articles)
12036                       'gnus-article-sort-by-number))
12037     ;; Suppress duplicates?
12038     (when gnus-suppress-duplicates
12039       (gnus-dup-suppress-articles))
12040
12041     ;; We might want to build some more threads first.
12042     (when (and gnus-fetch-old-headers
12043                (eq gnus-headers-retrieved-by 'nov))
12044       (if (eq gnus-fetch-old-headers 'invisible)
12045           (gnus-build-all-threads)
12046         (gnus-build-old-threads)))
12047     ;; Let the Gnus agent mark articles as read.
12048     (when gnus-agent
12049       (gnus-agent-get-undownloaded-list))
12050     ;; Remove list identifiers from subject
12051     (when gnus-list-identifiers
12052       (gnus-summary-remove-list-identifiers))
12053     ;; First and last article in this newsgroup.
12054     (when gnus-newsgroup-headers
12055       (setq gnus-newsgroup-begin
12056             (mail-header-number (car gnus-newsgroup-headers))
12057             gnus-newsgroup-end
12058             (mail-header-number
12059              (gnus-last-element gnus-newsgroup-headers))))
12060     (when gnus-use-scoring
12061       (gnus-possibly-score-headers))))
12062
12063 (defun gnus-summary-insert-old-articles (&optional all)
12064   "Insert all old articles in this group.
12065 If ALL is non-nil, already read articles become readable.
12066 If ALL is a number, fetch this number of articles."
12067   (interactive "P")
12068   (prog1
12069       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12070             older len)
12071         (setq older
12072               ;; Some nntp servers lie about their active range.  When
12073               ;; this happens, the active range can be in the millions.
12074               ;; Use a compressed range to avoid creating a huge list.
12075               (gnus-range-difference (list gnus-newsgroup-active) old))
12076         (setq len (gnus-range-length older))
12077         (cond
12078          ((null older) nil)
12079          ((numberp all)
12080           (if (< all len)
12081               (let ((older-range (nreverse older)))
12082                 (setq older nil)
12083
12084                 (while (> all 0)
12085                   (let* ((r (pop older-range))
12086                          (min (if (numberp r) r (car r)))
12087                          (max (if (numberp r) r (cdr r))))
12088                     (while (and (<= min max)
12089                                 (> all 0))
12090                       (push max older)
12091                       (setq all (1- all)
12092                             max (1- max))))))
12093             (setq older (gnus-uncompress-range older))))
12094          (all
12095           (setq older (gnus-uncompress-range older)))
12096          (t
12097           (when (and (numberp gnus-large-newsgroup)
12098                    (> len gnus-large-newsgroup))
12099               (let* ((cursor-in-echo-area nil)
12100                      (initial (gnus-parameter-large-newsgroup-initial
12101                                gnus-newsgroup-name))
12102                      (input
12103                       (read-string
12104                        (format
12105                         "How many articles from %s (%s %d): "
12106                         (gnus-limit-string
12107                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12108                         (if initial "max" "default")
12109                         len)
12110                        (if initial
12111                            (cons (number-to-string initial)
12112                                  0)))))
12113                 (unless (string-match "^[ \t]*$" input)
12114                   (setq all (string-to-number input))
12115                   (if (< all len)
12116                       (let ((older-range (nreverse older)))
12117                         (setq older nil)
12118
12119                         (while (> all 0)
12120                           (let* ((r (pop older-range))
12121                                  (min (if (numberp r) r (car r)))
12122                                  (max (if (numberp r) r (cdr r))))
12123                             (while (and (<= min max)
12124                                         (> all 0))
12125                               (push max older)
12126                               (setq all (1- all)
12127                                     max (1- max))))))))))
12128           (setq older (gnus-uncompress-range older))))
12129         (if (not older)
12130             (message "No old news.")
12131           (gnus-summary-insert-articles older)
12132           (gnus-summary-limit (gnus-sorted-nunion old older))))
12133     (gnus-summary-position-point)))
12134
12135 (defun gnus-summary-insert-new-articles ()
12136   "Insert all new articles in this group."
12137   (interactive)
12138   (prog1
12139       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12140             (old-active gnus-newsgroup-active)
12141             (nnmail-fetched-sources (list t))
12142             i new)
12143         (setq gnus-newsgroup-active
12144               (gnus-activate-group gnus-newsgroup-name 'scan))
12145         (setq i (cdr gnus-newsgroup-active))
12146         (while (> i (cdr old-active))
12147           (push i new)
12148           (decf i))
12149         (if (not new)
12150             (message "No gnus is bad news")
12151           (gnus-summary-insert-articles new)
12152           (setq gnus-newsgroup-unreads
12153                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12154           (gnus-summary-limit (gnus-sorted-nunion old new))))
12155     (gnus-summary-position-point)))
12156
12157 (gnus-summary-make-all-marking-commands)
12158
12159 (gnus-ems-redefine)
12160
12161 (provide 'gnus-sum)
12162
12163 (run-hooks 'gnus-sum-load-hook)
12164
12165 ;; Local Variables:
12166 ;; coding: iso-8859-1
12167 ;; End:
12168
12169 ;;; gnus-sum.el ends here