7103492a159b15293598c9445bb26109714968b0
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile
30   (require 'cl)
31   (defvar tool-bar-map))
32
33 (require 'gnus)
34 (require 'gnus-group)
35 (require 'gnus-spec)
36 (require 'gnus-range)
37 (require 'gnus-int)
38 (require 'gnus-undo)
39 (require 'gnus-util)
40 (require 'mm-decode)
41 (require 'nnoo)
42
43 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
44 (autoload 'gnus-cache-write-active "gnus-cache")
45 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
46 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
47 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
48 (autoload 'mm-uu-dissect "mm-uu")
49 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
50   "Deuglify broken Outlook (Express) articles and redisplay."
51   t)
52 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
53 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
54 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
55
56 (defcustom gnus-kill-summary-on-exit t
57   "*If non-nil, kill the summary buffer when you exit from it.
58 If nil, the summary will become a \"*Dead Summary*\" buffer, and
59 it will be killed sometime later."
60   :group 'gnus-summary-exit
61   :type 'boolean)
62
63 (defcustom gnus-fetch-old-headers nil
64   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
65 If an unread article in the group refers to an older, already read (or
66 just marked as read) article, the old article will not normally be
67 displayed in the Summary buffer.  If this variable is non-nil, Gnus
68 will attempt to grab the headers to the old articles, and thereby
69 build complete threads.  If it has the value `some', only enough
70 headers to connect otherwise loose threads will be displayed.  This
71 variable can also be a number.  In that case, no more than that number
72 of old headers will be fetched.  If it has the value `invisible', all
73 old headers will be fetched, but none will be displayed.
74
75 The server has to support NOV for any of this to work."
76   :group 'gnus-thread
77   :type '(choice (const :tag "off" nil)
78                  (const some)
79                  number
80                  (sexp :menu-tag "other" t)))
81
82 (defcustom gnus-refer-thread-limit 200
83   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
84 If t, fetch all the available old headers."
85   :group 'gnus-thread
86   :type '(choice number
87                  (sexp :menu-tag "other" t)))
88
89 (defcustom gnus-summary-make-false-root 'adopt
90   "*nil means that Gnus won't gather loose threads.
91 If the root of a thread has expired or been read in a previous
92 session, the information necessary to build a complete thread has been
93 lost.  Instead of having many small sub-threads from this original thread
94 scattered all over the summary buffer, Gnus can gather them.
95
96 If non-nil, Gnus will try to gather all loose sub-threads from an
97 original thread into one large thread.
98
99 If this variable is non-nil, it should be one of `none', `adopt',
100 `dummy' or `empty'.
101
102 If this variable is `none', Gnus will not make a false root, but just
103 present the sub-threads after another.
104 If this variable is `dummy', Gnus will create a dummy root that will
105 have all the sub-threads as children.
106 If this variable is `adopt', Gnus will make one of the \"children\"
107 the parent and mark all the step-children as such.
108 If this variable is `empty', the \"children\" are printed with empty
109 subject fields.  (Or rather, they will be printed with a string
110 given by the `gnus-summary-same-subject' variable.)"
111   :group 'gnus-thread
112   :type '(choice (const :tag "off" nil)
113                  (const none)
114                  (const dummy)
115                  (const adopt)
116                  (const empty)))
117
118 (defcustom gnus-summary-make-false-root-always nil
119   "Always make a false dummy root."
120   :group 'gnus-thread
121   :type 'boolean)
122
123 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
124   "*A regexp to match subjects to be excluded from loose thread gathering.
125 As loose thread gathering is done on subjects only, that means that
126 there can be many false gatherings performed.  By rooting out certain
127 common subjects, gathering might become saner."
128   :group 'gnus-thread
129   :type 'regexp)
130
131 (defcustom gnus-summary-gather-subject-limit nil
132   "*Maximum length of subject comparisons when gathering loose threads.
133 Use nil to compare full subjects.  Setting this variable to a low
134 number will help gather threads that have been corrupted by
135 newsreaders chopping off subject lines, but it might also mean that
136 unrelated articles that have subject that happen to begin with the
137 same few characters will be incorrectly gathered.
138
139 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
140 comparing subjects."
141   :group 'gnus-thread
142   :type '(choice (const :tag "off" nil)
143                  (const fuzzy)
144                  (sexp :menu-tag "on" t)))
145
146 (defcustom gnus-simplify-subject-functions nil
147   "List of functions taking a string argument that simplify subjects.
148 The functions are applied recursively.
149
150 Useful functions to put in this list include:
151 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
152 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
153   :group 'gnus-thread
154   :type '(repeat function))
155
156 (defcustom gnus-simplify-ignored-prefixes nil
157   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
158   :group 'gnus-thread
159   :type '(choice (const :tag "off" nil)
160                  regexp))
161
162 (defcustom gnus-build-sparse-threads nil
163   "*If non-nil, fill in the gaps in threads.
164 If `some', only fill in the gaps that are needed to tie loose threads
165 together.  If `more', fill in all leaf nodes that Gnus can find.  If
166 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
167   :group 'gnus-thread
168   :type '(choice (const :tag "off" nil)
169                  (const some)
170                  (const more)
171                  (sexp :menu-tag "all" t)))
172
173 (defcustom gnus-summary-thread-gathering-function
174   'gnus-gather-threads-by-subject
175   "*Function used for gathering loose threads.
176 There are two pre-defined functions: `gnus-gather-threads-by-subject',
177 which only takes Subjects into consideration; and
178 `gnus-gather-threads-by-references', which compared the References
179 headers of the articles to find matches."
180   :group 'gnus-thread
181   :type '(radio (function-item gnus-gather-threads-by-subject)
182                 (function-item gnus-gather-threads-by-references)
183                 (function :tag "other")))
184
185 (defcustom gnus-summary-same-subject ""
186   "*String indicating that the current article has the same subject as the previous.
187 This variable will only be used if the value of
188 `gnus-summary-make-false-root' is `empty'."
189   :group 'gnus-summary-format
190   :type 'string)
191
192 (defcustom gnus-summary-goto-unread t
193   "*If t, many commands will go to the next unread article.
194 This applies to marking commands as well as other commands that
195 \"naturally\" select the next article, like, for instance, `SPC' at
196 the end of an article.
197
198 If nil, the marking commands do NOT go to the next unread article
199 \(they go to the next article instead).  If `never', commands that
200 usually go to the next unread article, will go to the next article,
201 whether it is read or not."
202   :group 'gnus-summary-marks
203   :link '(custom-manual "(gnus)Setting Marks")
204   :type '(choice (const :tag "off" nil)
205                  (const never)
206                  (sexp :menu-tag "on" t)))
207
208 (defcustom gnus-summary-default-score 0
209   "*Default article score level.
210 All scores generated by the score files will be added to this score.
211 If this variable is nil, scoring will be disabled."
212   :group 'gnus-score-default
213   :type '(choice (const :tag "disable")
214                  integer))
215
216 (defcustom gnus-summary-default-high-score 0
217   "*Default threshold for a high scored article.
218 An article will be highlighted as high scored if its score is greater
219 than this score."
220   :group 'gnus-score-default
221   :type 'integer)
222
223 (defcustom gnus-summary-default-low-score 0
224   "*Default threshold for a low scored article.
225 An article will be highlighted as low scored if its score is smaller
226 than this score."
227   :group 'gnus-score-default
228   :type 'integer)
229
230 (defcustom gnus-summary-zcore-fuzz 0
231   "*Fuzziness factor for the zcore in the summary buffer.
232 Articles with scores closer than this to `gnus-summary-default-score'
233 will not be marked."
234   :group 'gnus-summary-format
235   :type 'integer)
236
237 (defcustom gnus-simplify-subject-fuzzy-regexp nil
238   "*Strings to be removed when doing fuzzy matches.
239 This can either be a regular expression or list of regular expressions
240 that will be removed from subject strings if fuzzy subject
241 simplification is selected."
242   :group 'gnus-thread
243   :type '(repeat regexp))
244
245 (defcustom gnus-show-threads t
246   "*If non-nil, display threads in summary mode."
247   :group 'gnus-thread
248   :type 'boolean)
249
250 (defcustom gnus-thread-hide-subtree nil
251   "*If non-nil, hide all threads initially.
252 This can be a predicate specifier which says which threads to hide.
253 If threads are hidden, you have to run the command
254 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
255 to expose hidden threads."
256   :group 'gnus-thread
257   :type '(radio (sexp :format "Non-nil\n"
258                       :match (lambda (widget value)
259                                (not (or (consp value) (functionp value))))
260                       :value t)
261                 (const nil)
262                 (sexp :tag "Predicate specifier" :size 0)))
263
264 (defcustom gnus-thread-hide-killed t
265   "*If non-nil, hide killed threads automatically."
266   :group 'gnus-thread
267   :type 'boolean)
268
269 (defcustom gnus-thread-ignore-subject t
270   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
271 If nil, articles that have different subjects from their parents will
272 start separate threads."
273   :group 'gnus-thread
274   :type 'boolean)
275
276 (defcustom gnus-thread-operation-ignore-subject t
277   "*If non-nil, subjects will be ignored when doing thread commands.
278 This affects commands like `gnus-summary-kill-thread' and
279 `gnus-summary-lower-thread'.
280
281 If this variable is nil, articles in the same thread with different
282 subjects will not be included in the operation in question.  If this
283 variable is `fuzzy', only articles that have subjects that are fuzzily
284 equal will be included."
285   :group 'gnus-thread
286   :type '(choice (const :tag "off" nil)
287                  (const fuzzy)
288                  (sexp :tag "on" t)))
289
290 (defcustom gnus-thread-indent-level 4
291   "*Number that says how much each sub-thread should be indented."
292   :group 'gnus-thread
293   :type 'integer)
294
295 (defcustom gnus-auto-extend-newsgroup t
296   "*If non-nil, extend newsgroup forward and backward when requested."
297   :group 'gnus-summary-choose
298   :type 'boolean)
299
300 (defcustom gnus-auto-select-first t
301   "*If non-nil, select the article under point.
302 Which article this is is controlled by the `gnus-auto-select-subject'
303 variable.
304
305 If you want to prevent automatic selection of articles in some
306 newsgroups, set the variable to nil in `gnus-select-group-hook'."
307   :group 'gnus-group-select
308   :type '(choice (const :tag "none" nil)
309                  (sexp :menu-tag "first" t)))
310
311 (defcustom gnus-auto-select-subject 'unread
312   "*Says what subject to place under point when entering a group.
313
314 This variable can either be the symbols `first' (place point on the
315 first subject), `unread' (place point on the subject line of the first
316 unread article), `best' (place point on the subject line of the
317 higest-scored article), `unseen' (place point on the subject line of
318 the first unseen article), 'unseen-or-unread' (place point on the subject
319 line of the first unseen article or, if all article have been seen, on the
320 subject line of the first unread article), or a function to be called to
321 place point on some subject line."
322   :group 'gnus-group-select
323   :type '(choice (const best)
324                  (const unread)
325                  (const first)
326                  (const unseen)
327                  (const unseen-or-unread)))
328
329 (defcustom gnus-auto-select-next t
330   "*If non-nil, offer to go to the next group from the end of the previous.
331 If the value is t and the next newsgroup is empty, Gnus will exit
332 summary mode and go back to group mode.  If the value is neither nil
333 nor t, Gnus will select the following unread newsgroup.  In
334 particular, if the value is the symbol `quietly', the next unread
335 newsgroup will be selected without any confirmation, and if it is
336 `almost-quietly', the next group will be selected without any
337 confirmation if you are located on the last article in the group.
338 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
339 will go to the next group without confirmation."
340   :group 'gnus-summary-maneuvering
341   :type '(choice (const :tag "off" nil)
342                  (const quietly)
343                  (const almost-quietly)
344                  (const slightly-quietly)
345                  (sexp :menu-tag "on" t)))
346
347 (defcustom gnus-auto-select-same nil
348   "*If non-nil, select the next article with the same subject.
349 If there are no more articles with the same subject, go to
350 the first unread article."
351   :group 'gnus-summary-maneuvering
352   :type 'boolean)
353
354 (defcustom gnus-auto-goto-ignores 'unfetched
355   "*Says how to handle unfetched articles when maneuvering.
356
357 This variable can either be the symbols nil (maneuver to any
358 article), `undownloaded' (maneuvering while unplugged ignores articles
359 that have not been fetched), `always-undownloaded' (maneuvering always
360 ignores articles that have not been fetched), `unfetched' (maneuvering
361 ignores articles whose headers have not been fetched).
362
363 NOTE: The list of unfetched articles will always be nil when plugged
364 and, when unplugged, a subset of the undownloaded article list."
365   :group 'gnus-summary-maneuvering
366   :type '(choice (const :tag "None" nil)
367                  (const :tag "Undownloaded when unplugged" undownloaded)
368                  (const :tag "Undownloaded" always-undownloaded)
369                  (const :tag "Unfetched" unfetched)))
370
371 (defcustom gnus-summary-check-current nil
372   "*If non-nil, consider the current article when moving.
373 The \"unread\" movement commands will stay on the same line if the
374 current article is unread."
375   :group 'gnus-summary-maneuvering
376   :type 'boolean)
377
378 (defcustom gnus-auto-center-summary t
379   "*If non-nil, always center the current summary buffer.
380 In particular, if `vertical' do only vertical recentering.  If non-nil
381 and non-`vertical', do both horizontal and vertical recentering."
382   :group 'gnus-summary-maneuvering
383   :type '(choice (const :tag "none" nil)
384                  (const vertical)
385                  (integer :tag "height")
386                  (sexp :menu-tag "both" t)))
387
388 (defvar gnus-auto-center-group t
389   "*If non-nil, always center the group buffer.")
390
391 (defcustom gnus-show-all-headers nil
392   "*If non-nil, don't hide any headers."
393   :group 'gnus-article-hiding
394   :group 'gnus-article-headers
395   :type 'boolean)
396
397 (defcustom gnus-summary-ignore-duplicates nil
398   "*If non-nil, ignore articles with identical Message-ID headers."
399   :group 'gnus-summary
400   :type 'boolean)
401
402 (defcustom gnus-single-article-buffer t
403   "*If non-nil, display all articles in the same buffer.
404 If nil, each group will get its own article buffer."
405   :group 'gnus-article-various
406   :type 'boolean)
407
408 (defcustom gnus-break-pages t
409   "*If non-nil, do page breaking on articles.
410 The page delimiter is specified by the `gnus-page-delimiter'
411 variable."
412   :group 'gnus-article-various
413   :type 'boolean)
414
415 (defcustom gnus-move-split-methods nil
416   "*Variable used to suggest where articles are to be moved to.
417 It uses the same syntax as the `gnus-split-methods' variable.
418 However, whereas `gnus-split-methods' specifies file names as targets,
419 this variable specifies group names."
420   :group 'gnus-summary-mail
421   :type '(repeat (choice (list :value (fun) function)
422                          (cons :value ("" "") regexp (repeat string))
423                          (sexp :value nil))))
424
425 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
426   "Function used to compute default prefix for article move/copy/etc prompts.
427 The function should take one argument, a group name, and return a
428 string with the suggested prefix."
429   :group 'gnus-summary-mail
430   :type 'function)
431
432 (defcustom gnus-unread-mark ?           ;Whitespace
433   "*Mark used for unread articles."
434   :group 'gnus-summary-marks
435   :type 'character)
436
437 (defcustom gnus-ticked-mark ?!
438   "*Mark used for ticked articles."
439   :group 'gnus-summary-marks
440   :type 'character)
441
442 (defcustom gnus-dormant-mark ??
443   "*Mark used for dormant articles."
444   :group 'gnus-summary-marks
445   :type 'character)
446
447 (defcustom gnus-del-mark ?r
448   "*Mark used for del'd articles."
449   :group 'gnus-summary-marks
450   :type 'character)
451
452 (defcustom gnus-read-mark ?R
453   "*Mark used for read articles."
454   :group 'gnus-summary-marks
455   :type 'character)
456
457 (defcustom gnus-expirable-mark ?E
458   "*Mark used for expirable articles."
459   :group 'gnus-summary-marks
460   :type 'character)
461
462 (defcustom gnus-killed-mark ?K
463   "*Mark used for killed articles."
464   :group 'gnus-summary-marks
465   :type 'character)
466
467 (defcustom gnus-spam-mark ?$
468   "*Mark used for spam articles."
469   :group 'gnus-summary-marks
470   :type 'character)
471
472 (defcustom gnus-souped-mark ?F
473   "*Mark used for souped articles."
474   :group 'gnus-summary-marks
475   :type 'character)
476
477 (defcustom gnus-kill-file-mark ?X
478   "*Mark used for articles killed by kill files."
479   :group 'gnus-summary-marks
480   :type 'character)
481
482 (defcustom gnus-low-score-mark ?Y
483   "*Mark used for articles with a low score."
484   :group 'gnus-summary-marks
485   :type 'character)
486
487 (defcustom gnus-catchup-mark ?C
488   "*Mark used for articles that are caught up."
489   :group 'gnus-summary-marks
490   :type 'character)
491
492 (defcustom gnus-replied-mark ?A
493   "*Mark used for articles that have been replied to."
494   :group 'gnus-summary-marks
495   :type 'character)
496
497 (defcustom gnus-forwarded-mark ?F
498   "*Mark used for articles that have been forwarded."
499   :group 'gnus-summary-marks
500   :type 'character)
501
502 (defcustom gnus-recent-mark ?N
503   "*Mark used for articles that are recent."
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-cached-mark ?*
508   "*Mark used for articles that are in the cache."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-saved-mark ?S
513   "*Mark used for articles that have been saved."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-unseen-mark ?.
518   "*Mark used for articles that haven't been seen."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-no-mark ?               ;Whitespace
523   "*Mark used for articles that have no other secondary mark."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-ancient-mark ?O
528   "*Mark used for ancient articles."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-sparse-mark ?Q
533   "*Mark used for sparsely reffed articles."
534   :group 'gnus-summary-marks
535   :type 'character)
536
537 (defcustom gnus-canceled-mark ?G
538   "*Mark used for canceled articles."
539   :group 'gnus-summary-marks
540   :type 'character)
541
542 (defcustom gnus-duplicate-mark ?M
543   "*Mark used for duplicate articles."
544   :group 'gnus-summary-marks
545   :type 'character)
546
547 (defcustom gnus-undownloaded-mark ?-
548   "*Mark used for articles that weren't downloaded."
549   :group 'gnus-summary-marks
550   :type 'character)
551
552 (defcustom gnus-downloaded-mark ?+
553   "*Mark used for articles that were downloaded."
554   :group 'gnus-summary-marks
555   :type 'character)
556
557 (defcustom gnus-downloadable-mark ?%
558   "*Mark used for articles that are to be downloaded."
559   :group 'gnus-summary-marks
560   :type 'character)
561
562 (defcustom gnus-unsendable-mark ?=
563   "*Mark used for articles that won't be sent."
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-score-over-mark ?+
568   "*Score mark used for articles with high scores."
569   :group 'gnus-summary-marks
570   :type 'character)
571
572 (defcustom gnus-score-below-mark ?-
573   "*Score mark used for articles with low scores."
574   :group 'gnus-summary-marks
575   :type 'character)
576
577 (defcustom gnus-empty-thread-mark ?     ;Whitespace
578   "*There is no thread under the article."
579   :group 'gnus-summary-marks
580   :type 'character)
581
582 (defcustom gnus-not-empty-thread-mark ?=
583   "*There is a thread under the article."
584   :group 'gnus-summary-marks
585   :type 'character)
586
587 (defcustom gnus-view-pseudo-asynchronously nil
588   "*If non-nil, Gnus will view pseudo-articles asynchronously."
589   :group 'gnus-extract-view
590   :type 'boolean)
591
592 (defcustom gnus-auto-expirable-marks
593   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
594         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
595         gnus-souped-mark gnus-duplicate-mark)
596   "*The list of marks converted into expiration if a group is auto-expirable."
597   :version "21.1"
598   :group 'gnus-summary
599   :type '(repeat character))
600
601 (defcustom gnus-inhibit-user-auto-expire t
602   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
603   :version "21.1"
604   :group 'gnus-summary
605   :type 'boolean)
606
607 (defcustom gnus-view-pseudos nil
608   "*If `automatic', pseudo-articles will be viewed automatically.
609 If `not-confirm', pseudos will be viewed automatically, and the user
610 will not be asked to confirm the command."
611   :group 'gnus-extract-view
612   :type '(choice (const :tag "off" nil)
613                  (const automatic)
614                  (const not-confirm)))
615
616 (defcustom gnus-view-pseudos-separately t
617   "*If non-nil, one pseudo-article will be created for each file to be viewed.
618 If nil, all files that use the same viewing command will be given as a
619 list of parameters to that command."
620   :group 'gnus-extract-view
621   :type 'boolean)
622
623 (defcustom gnus-insert-pseudo-articles t
624   "*If non-nil, insert pseudo-articles when decoding articles."
625   :group 'gnus-extract-view
626   :type 'boolean)
627
628 (defcustom gnus-summary-dummy-line-format
629   "   %(:                             :%) %S\n"
630   "*The format specification for the dummy roots in the summary buffer.
631 It works along the same lines as a normal formatting string,
632 with some simple extensions.
633
634 %S  The subject
635
636 General format specifiers can also be used.
637 See `(gnus)Formatting Variables'."
638   :link '(custom-manual "(gnus)Formatting Variables")
639   :group 'gnus-threading
640   :type 'string)
641
642 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
643   "*The format specification for the summary mode line.
644 It works along the same lines as a normal formatting string,
645 with some simple extensions:
646
647 %G  Group name
648 %p  Unprefixed group name
649 %A  Current article number
650 %z  Current article score
651 %V  Gnus version
652 %U  Number of unread articles in the group
653 %e  Number of unselected articles in the group
654 %Z  A string with unread/unselected article counts
655 %g  Shortish group name
656 %S  Subject of the current article
657 %u  User-defined spec
658 %s  Current score file name
659 %d  Number of dormant articles
660 %r  Number of articles that have been marked as read in this session
661 %E  Number of articles expunged by the score files"
662   :group 'gnus-summary-format
663   :type 'string)
664
665 (defcustom gnus-list-identifiers nil
666   "Regexp that matches list identifiers to be removed from subject.
667 This can also be a list of regexps."
668   :version "21.1"
669   :group 'gnus-summary-format
670   :group 'gnus-article-hiding
671   :type '(choice (const :tag "none" nil)
672                  (regexp :value ".*")
673                  (repeat :value (".*") regexp)))
674
675 (defcustom gnus-summary-mark-below 0
676   "*Mark all articles with a score below this variable as read.
677 This variable is local to each summary buffer and usually set by the
678 score file."
679   :group 'gnus-score-default
680   :type 'integer)
681
682 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
683   "*List of functions used for sorting articles in the summary buffer.
684
685 Each function takes two articles and returns non-nil if the first
686 article should be sorted before the other.  If you use more than one
687 function, the primary sort function should be the last.  You should
688 probably always include `gnus-article-sort-by-number' in the list of
689 sorting functions -- preferably first.  Also note that sorting by date
690 is often much slower than sorting by number, and the sorting order is
691 very similar.  (Sorting by date means sorting by the time the message
692 was sent, sorting by number means sorting by arrival time.)
693
694 Ready-made functions include `gnus-article-sort-by-number',
695 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
696 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
697 and `gnus-article-sort-by-score'.
698
699 When threading is turned on, the variable `gnus-thread-sort-functions'
700 controls how articles are sorted."
701   :group 'gnus-summary-sort
702   :type '(repeat (choice (function-item gnus-article-sort-by-number)
703                          (function-item gnus-article-sort-by-author)
704                          (function-item gnus-article-sort-by-subject)
705                          (function-item gnus-article-sort-by-date)
706                          (function-item gnus-article-sort-by-score)
707                          (function-item gnus-article-sort-by-random)
708                          (function :tag "other"))))
709
710 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
711   "*List of functions used for sorting threads in the summary buffer.
712 By default, threads are sorted by article number.
713
714 Each function takes two threads and returns non-nil if the first
715 thread should be sorted before the other.  If you use more than one
716 function, the primary sort function should be the last.  You should
717 probably always include `gnus-thread-sort-by-number' in the list of
718 sorting functions -- preferably first.  Also note that sorting by date
719 is often much slower than sorting by number, and the sorting order is
720 very similar.  (Sorting by date means sorting by the time the message
721 was sent, sorting by number means sorting by arrival time.)
722
723 Ready-made functions include `gnus-thread-sort-by-number',
724 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
725 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
726 `gnus-thread-sort-by-most-recent-number',
727 `gnus-thread-sort-by-most-recent-date',
728 `gnus-thread-sort-by-random', and
729 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
730
731 When threading is turned off, the variable
732 `gnus-article-sort-functions' controls how articles are sorted."
733   :group 'gnus-summary-sort
734   :type '(repeat (choice (function-item gnus-thread-sort-by-number)
735                          (function-item gnus-thread-sort-by-author)
736                          (function-item gnus-thread-sort-by-subject)
737                          (function-item gnus-thread-sort-by-date)
738                          (function-item gnus-thread-sort-by-score)
739                          (function-item gnus-thread-sort-by-most-recent-number)
740                          (function-item gnus-thread-sort-by-most-recent-date)
741                          (function-item gnus-thread-sort-by-random)
742                          (function-item gnus-thread-sort-by-total-score)
743                          (function :tag "other"))))
744
745 (defcustom gnus-thread-score-function '+
746   "*Function used for calculating the total score of a thread.
747
748 The function is called with the scores of the article and each
749 subthread and should then return the score of the thread.
750
751 Some functions you can use are `+', `max', or `min'."
752   :group 'gnus-summary-sort
753   :type 'function)
754
755 (defcustom gnus-summary-expunge-below nil
756   "All articles that have a score less than this variable will be expunged.
757 This variable is local to the summary buffers."
758   :group 'gnus-score-default
759   :type '(choice (const :tag "off" nil)
760                  integer))
761
762 (defcustom gnus-thread-expunge-below nil
763   "All threads that have a total score less than this variable will be expunged.
764 See `gnus-thread-score-function' for en explanation of what a
765 \"thread score\" is.
766
767 This variable is local to the summary buffers."
768   :group 'gnus-threading
769   :group 'gnus-score-default
770   :type '(choice (const :tag "off" nil)
771                  integer))
772
773 (defcustom gnus-summary-mode-hook nil
774   "*A hook for Gnus summary mode.
775 This hook is run before any variables are set in the summary buffer."
776   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
777   :group 'gnus-summary-various
778   :type 'hook)
779
780 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
781 (when (featurep 'xemacs)
782   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
783   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
784   (add-hook 'gnus-summary-mode-hook
785             'gnus-xmas-switch-horizontal-scrollbar-off))
786
787 (defcustom gnus-summary-menu-hook nil
788   "*Hook run after the creation of the summary mode menu."
789   :group 'gnus-summary-visual
790   :type 'hook)
791
792 (defcustom gnus-summary-exit-hook nil
793   "*A hook called on exit from the summary buffer.
794 It will be called with point in the group buffer."
795   :group 'gnus-summary-exit
796   :type 'hook)
797
798 (defcustom gnus-summary-prepare-hook nil
799   "*A hook called after the summary buffer has been generated.
800 If you want to modify the summary buffer, you can use this hook."
801   :group 'gnus-summary-various
802   :type 'hook)
803
804 (defcustom gnus-summary-prepared-hook nil
805   "*A hook called as the last thing after the summary buffer has been generated."
806   :group 'gnus-summary-various
807   :type 'hook)
808
809 (defcustom gnus-summary-generate-hook nil
810   "*A hook run just before generating the summary buffer.
811 This hook is commonly used to customize threading variables and the
812 like."
813   :group 'gnus-summary-various
814   :type 'hook)
815
816 (defcustom gnus-select-group-hook nil
817   "*A hook called when a newsgroup is selected.
818
819 If you'd like to simplify subjects like the
820 `gnus-summary-next-same-subject' command does, you can use the
821 following hook:
822
823  (add-hook gnus-select-group-hook
824            (lambda ()
825              (mapcar (lambda (header)
826                        (mail-header-set-subject
827                         header
828                         (gnus-simplify-subject
829                          (mail-header-subject header) 're-only)))
830                      gnus-newsgroup-headers)))"
831   :group 'gnus-group-select
832   :type 'hook)
833
834 (defcustom gnus-select-article-hook nil
835   "*A hook called when an article is selected."
836   :group 'gnus-summary-choose
837   :options '(gnus-agent-fetch-selected-article)
838   :type 'hook)
839
840 (defcustom gnus-visual-mark-article-hook
841   (list 'gnus-highlight-selected-summary)
842   "*Hook run after selecting an article in the summary buffer.
843 It is meant to be used for highlighting the article in some way.  It
844 is not run if `gnus-visual' is nil."
845   :group 'gnus-summary-visual
846   :type 'hook)
847
848 (defcustom gnus-parse-headers-hook nil
849   "*A hook called before parsing the headers."
850   :group 'gnus-various
851   :type 'hook)
852
853 (defcustom gnus-exit-group-hook nil
854   "*A hook called when exiting summary mode.
855 This hook is not called from the non-updating exit commands like `Q'."
856   :group 'gnus-various
857   :type 'hook)
858
859 (defcustom gnus-summary-update-hook
860   (list 'gnus-summary-highlight-line)
861   "*A hook called when a summary line is changed.
862 The hook will not be called if `gnus-visual' is nil.
863
864 The default function `gnus-summary-highlight-line' will
865 highlight the line according to the `gnus-summary-highlight'
866 variable."
867   :group 'gnus-summary-visual
868   :type 'hook)
869
870 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
871   "*A hook called when an article is selected for the first time.
872 The hook is intended to mark an article as read (or unread)
873 automatically when it is selected."
874   :group 'gnus-summary-choose
875   :type 'hook)
876
877 (defcustom gnus-group-no-more-groups-hook nil
878   "*A hook run when returning to group mode having no more (unread) groups."
879   :group 'gnus-group-select
880   :type 'hook)
881
882 (defcustom gnus-ps-print-hook nil
883   "*A hook run before ps-printing something from Gnus."
884   :group 'gnus-summary
885   :type 'hook)
886
887 (defcustom gnus-summary-article-move-hook nil
888   "*A hook called after an article is moved, copied, respooled, or crossposted."
889   :group 'gnus-summary
890   :type 'hook)
891
892 (defcustom gnus-summary-article-delete-hook nil
893   "*A hook called after an article is deleted."
894   :group 'gnus-summary
895   :type 'hook)
896
897 (defcustom gnus-summary-article-expire-hook nil
898   "*A hook called after an article is expired."
899   :group 'gnus-summary
900   :type 'hook)
901
902 (defcustom gnus-summary-display-arrow
903   (and (fboundp 'display-graphic-p)
904        (display-graphic-p))
905   "*If non-nil, display an arrow highlighting the current article."
906   :version "21.1"
907   :group 'gnus-summary
908   :type 'boolean)
909
910 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
911   "Face used for highlighting the current article in the summary buffer."
912   :group 'gnus-summary-visual
913   :type 'face)
914
915 (defvar gnus-tmp-downloaded nil)
916
917 (defcustom gnus-summary-highlight
918   '(((eq mark gnus-canceled-mark)
919      . gnus-summary-cancelled-face)
920     ((and uncached (> score default-high))
921      . gnus-summary-high-undownloaded-face)
922     ((and uncached (< score default-low))
923      . gnus-summary-low-undownloaded-face)
924     (uncached
925      . gnus-summary-normal-undownloaded-face)
926     ((and (> score default-high)
927           (or (eq mark gnus-dormant-mark)
928               (eq mark gnus-ticked-mark)))
929      . gnus-summary-high-ticked-face)
930     ((and (< score default-low)
931           (or (eq mark gnus-dormant-mark)
932               (eq mark gnus-ticked-mark)))
933      . gnus-summary-low-ticked-face)
934     ((or (eq mark gnus-dormant-mark)
935          (eq mark gnus-ticked-mark))
936      . gnus-summary-normal-ticked-face)
937     ((and (> score default-high) (eq mark gnus-ancient-mark))
938      . gnus-summary-high-ancient-face)
939     ((and (< score default-low) (eq mark gnus-ancient-mark))
940      . gnus-summary-low-ancient-face)
941     ((eq mark gnus-ancient-mark)
942      . gnus-summary-normal-ancient-face)
943     ((and (> score default-high) (eq mark gnus-unread-mark))
944      . gnus-summary-high-unread-face)
945     ((and (< score default-low) (eq mark gnus-unread-mark))
946      . gnus-summary-low-unread-face)
947     ((eq mark gnus-unread-mark)
948      . gnus-summary-normal-unread-face)
949     ((> score default-high)
950      . gnus-summary-high-read-face)
951     ((< score default-low)
952      . gnus-summary-low-read-face)
953     (t
954      . gnus-summary-normal-read-face))
955   "*Controls the highlighting of summary buffer lines.
956
957 A list of (FORM . FACE) pairs.  When deciding how a a particular
958 summary line should be displayed, each form is evaluated.  The content
959 of the face field after the first true form is used.  You can change
960 how those summary lines are displayed, by editing the face field.
961
962 You can use the following variables in the FORM field.
963
964 score:        The article's score
965 default:      The default article score.
966 default-high: The default score for high scored articles.
967 default-low:  The default score for low scored articles.
968 below:        The score below which articles are automatically marked as read.
969 mark:         The article's mark.
970 uncached:     Non-nil if the article is uncached."
971   :group 'gnus-summary-visual
972   :type '(repeat (cons (sexp :tag "Form" nil)
973                        face)))
974
975 (defcustom gnus-alter-header-function nil
976   "Function called to allow alteration of article header structures.
977 The function is called with one parameter, the article header vector,
978 which it may alter in any way."
979   :type '(choice (const :tag "None" nil)
980                  function)
981   :group 'gnus-summary)
982
983 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
984   "Variable that says which function should be used to decode a string with encoded words.")
985
986 (defcustom gnus-extra-headers '(To Newsgroups)
987   "*Extra headers to parse."
988   :version "21.1"
989   :group 'gnus-summary
990   :type '(repeat symbol))
991
992 (defcustom gnus-ignored-from-addresses
993   (and user-mail-address (regexp-quote user-mail-address))
994   "*Regexp of From headers that may be suppressed in favor of To headers."
995   :version "21.1"
996   :group 'gnus-summary
997   :type 'regexp)
998
999 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1000   "List of charsets that should be ignored.
1001 When these charsets are used in the \"charset\" parameter, the
1002 default charset will be used instead."
1003   :version "21.1"
1004   :type '(repeat symbol)
1005   :group 'gnus-charset)
1006
1007 (gnus-define-group-parameter
1008  ignored-charsets
1009  :type list
1010  :function-document
1011  "Return the ignored charsets of GROUP."
1012  :variable gnus-group-ignored-charsets-alist
1013  :variable-default
1014  '(("alt\\.chinese\\.text" iso-8859-1))
1015  :variable-document
1016  "Alist of regexps (to match group names) and charsets that should be ignored.
1017 When these charsets are used in the \"charset\" parameter, the
1018 default charset will be used instead."
1019  :variable-group gnus-charset
1020  :variable-type '(repeat (cons (regexp :tag "Group")
1021                                (repeat symbol)))
1022  :parameter-type '(choice :tag "Ignored charsets"
1023                           :value nil
1024                           (repeat (symbol)))
1025  :parameter-document       "\
1026 List of charsets that should be ignored.
1027
1028 When these charsets are used in the \"charset\" parameter, the
1029 default charset will be used instead.")
1030
1031 (defcustom gnus-group-highlight-words-alist nil
1032   "Alist of group regexps and highlight regexps.
1033 This variable uses the same syntax as `gnus-emphasis-alist'."
1034   :version "21.1"
1035   :type '(repeat (cons (regexp :tag "Group")
1036                        (repeat (list (regexp :tag "Highlight regexp")
1037                                      (number :tag "Group for entire word" 0)
1038                                      (number :tag "Group for displayed part" 0)
1039                                      (symbol :tag "Face"
1040                                              gnus-emphasis-highlight-words)))))
1041   :group 'gnus-summary-visual)
1042
1043 (defcustom gnus-summary-show-article-charset-alist
1044   nil
1045   "Alist of number and charset.
1046 The article will be shown with the charset corresponding to the
1047 numbered argument.
1048 For example: ((1 . cn-gb-2312) (2 . big5))."
1049   :version "21.1"
1050   :type '(repeat (cons (number :tag "Argument" 1)
1051                        (symbol :tag "Charset")))
1052   :group 'gnus-charset)
1053
1054 (defcustom gnus-preserve-marks t
1055   "Whether marks are preserved when moving, copying and respooling messages."
1056   :version "21.1"
1057   :type 'boolean
1058   :group 'gnus-summary-marks)
1059
1060 (defcustom gnus-alter-articles-to-read-function nil
1061   "Function to be called to alter the list of articles to be selected."
1062   :type '(choice (const nil) function)
1063   :group 'gnus-summary)
1064
1065 (defcustom gnus-orphan-score nil
1066   "*All orphans get this score added.  Set in the score file."
1067   :group 'gnus-score-default
1068   :type '(choice (const nil)
1069                  integer))
1070
1071 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1072   "*A regexp to match MIME parts when saving multiple parts of a
1073 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1074 This regexp will be used by default when prompting the user for which
1075 type of files to save."
1076   :group 'gnus-summary
1077   :type 'regexp)
1078
1079 (defcustom gnus-read-all-available-headers nil
1080   "Whether Gnus should parse all headers made available to it.
1081 This is mostly relevant for slow back ends where the user may
1082 wish to widen the summary buffer to include all headers
1083 that were fetched.  Say, for nnultimate groups."
1084   :group 'gnus-summary
1085   :type '(choice boolean regexp))
1086
1087 (defcustom gnus-summary-muttprint-program "muttprint"
1088   "Command (and optional arguments) used to run Muttprint."
1089   :version "21.3"
1090   :group 'gnus-summary
1091   :type 'string)
1092
1093 (defcustom gnus-article-loose-mime nil
1094   "If non-nil, don't require MIME-Version header.
1095 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1096 supply the MIME-Version header or deliberately strip it From the mail.
1097 Set it to non-nil, Gnus will treat some articles as MIME even if
1098 the MIME-Version header is missed."
1099   :version "21.3"
1100   :type 'boolean
1101   :group 'gnus-article-mime)
1102
1103 (defcustom gnus-article-emulate-mime t
1104   "If non-nil, use MIME emulation for uuencode and the like.
1105 This means that Gnus will search message bodies for text that look
1106 like uuencoded bits, yEncoded bits, and so on, and present that using
1107 the normal Gnus MIME machinery."
1108   :type 'boolean
1109   :group 'gnus-article-mime)
1110
1111 ;;; Internal variables
1112
1113 (defvar gnus-summary-display-cache nil)
1114 (defvar gnus-article-mime-handles nil)
1115 (defvar gnus-article-decoded-p nil)
1116 (defvar gnus-article-charset nil)
1117 (defvar gnus-article-ignored-charsets nil)
1118 (defvar gnus-scores-exclude-files nil)
1119 (defvar gnus-page-broken nil)
1120
1121 (defvar gnus-original-article nil)
1122 (defvar gnus-article-internal-prepare-hook nil)
1123 (defvar gnus-newsgroup-process-stack nil)
1124
1125 (defvar gnus-thread-indent-array nil)
1126 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1127 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1128   "Function called to sort the articles within a thread after it has been gathered together.")
1129
1130 (defvar gnus-summary-save-parts-type-history nil)
1131 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1132
1133 ;; Avoid highlighting in kill files.
1134 (defvar gnus-summary-inhibit-highlight nil)
1135 (defvar gnus-newsgroup-selected-overlay nil)
1136 (defvar gnus-inhibit-limiting nil)
1137 (defvar gnus-newsgroup-adaptive-score-file nil)
1138 (defvar gnus-current-score-file nil)
1139 (defvar gnus-current-move-group nil)
1140 (defvar gnus-current-copy-group nil)
1141 (defvar gnus-current-crosspost-group nil)
1142 (defvar gnus-newsgroup-display nil)
1143
1144 (defvar gnus-newsgroup-dependencies nil)
1145 (defvar gnus-newsgroup-adaptive nil)
1146 (defvar gnus-summary-display-article-function nil)
1147 (defvar gnus-summary-highlight-line-function nil
1148   "Function called after highlighting a summary line.")
1149
1150 (defvar gnus-summary-line-format-alist
1151   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1152     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1153     (?s gnus-tmp-subject-or-nil ?s)
1154     (?n gnus-tmp-name ?s)
1155     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1156         ?s)
1157     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1158             gnus-tmp-from) ?s)
1159     (?F gnus-tmp-from ?s)
1160     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1161     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1162     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1163     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1164     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1165     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1166     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1167     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1168     (?L gnus-tmp-lines ?s)
1169     (?O gnus-tmp-downloaded ?c)
1170     (?I gnus-tmp-indentation ?s)
1171     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1172     (?R gnus-tmp-replied ?c)
1173     (?\[ gnus-tmp-opening-bracket ?c)
1174     (?\] gnus-tmp-closing-bracket ?c)
1175     (?\> (make-string gnus-tmp-level ? ) ?s)
1176     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1177     (?i gnus-tmp-score ?d)
1178     (?z gnus-tmp-score-char ?c)
1179     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1180     (?U gnus-tmp-unread ?c)
1181     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1182         ?s)
1183     (?t (gnus-summary-number-of-articles-in-thread
1184          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1185         ?d)
1186     (?e (gnus-summary-number-of-articles-in-thread
1187          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1188         ?c)
1189     (?u gnus-tmp-user-defined ?s)
1190     (?P (gnus-pick-line-number) ?d)
1191     (?B gnus-tmp-thread-tree-header-string ?s)
1192     (user-date (gnus-user-date
1193                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1194   "An alist of format specifications that can appear in summary lines.
1195 These are paired with what variables they correspond with, along with
1196 the type of the variable (string, integer, character, etc).")
1197
1198 (defvar gnus-summary-dummy-line-format-alist
1199   `((?S gnus-tmp-subject ?s)
1200     (?N gnus-tmp-number ?d)
1201     (?u gnus-tmp-user-defined ?s)))
1202
1203 (defvar gnus-summary-mode-line-format-alist
1204   `((?G gnus-tmp-group-name ?s)
1205     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1206     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1207     (?A gnus-tmp-article-number ?d)
1208     (?Z gnus-tmp-unread-and-unselected ?s)
1209     (?V gnus-version ?s)
1210     (?U gnus-tmp-unread-and-unticked ?d)
1211     (?S gnus-tmp-subject ?s)
1212     (?e gnus-tmp-unselected ?d)
1213     (?u gnus-tmp-user-defined ?s)
1214     (?d (length gnus-newsgroup-dormant) ?d)
1215     (?t (length gnus-newsgroup-marked) ?d)
1216     (?h (length gnus-newsgroup-spam-marked) ?d)
1217     (?r (length gnus-newsgroup-reads) ?d)
1218     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1219     (?E gnus-newsgroup-expunged-tally ?d)
1220     (?s (gnus-current-score-file-nondirectory) ?s)))
1221
1222 (defvar gnus-last-search-regexp nil
1223   "Default regexp for article search command.")
1224
1225 (defvar gnus-last-shell-command nil
1226   "Default shell command on article.")
1227
1228 (defvar gnus-newsgroup-agentized nil
1229   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1230 (defvar gnus-newsgroup-begin nil)
1231 (defvar gnus-newsgroup-end nil)
1232 (defvar gnus-newsgroup-last-rmail nil)
1233 (defvar gnus-newsgroup-last-mail nil)
1234 (defvar gnus-newsgroup-last-folder nil)
1235 (defvar gnus-newsgroup-last-file nil)
1236 (defvar gnus-newsgroup-auto-expire nil)
1237 (defvar gnus-newsgroup-active nil)
1238
1239 (defvar gnus-newsgroup-data nil)
1240 (defvar gnus-newsgroup-data-reverse nil)
1241 (defvar gnus-newsgroup-limit nil)
1242 (defvar gnus-newsgroup-limits nil)
1243 (defvar gnus-summary-use-undownloaded-faces nil)
1244
1245 (defvar gnus-newsgroup-unreads nil
1246   "Sorted list of unread articles in the current newsgroup.")
1247
1248 (defvar gnus-newsgroup-unselected nil
1249   "Sorted list of unselected unread articles in the current newsgroup.")
1250
1251 (defvar gnus-newsgroup-reads nil
1252   "Alist of read articles and article marks in the current newsgroup.")
1253
1254 (defvar gnus-newsgroup-expunged-tally nil)
1255
1256 (defvar gnus-newsgroup-marked nil
1257   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1258
1259 (defvar gnus-newsgroup-spam-marked nil
1260   "List of ranges of articles that have been marked as spam.")
1261
1262 (defvar gnus-newsgroup-killed nil
1263   "List of ranges of articles that have been through the scoring process.")
1264
1265 (defvar gnus-newsgroup-cached nil
1266   "Sorted list of articles that come from the article cache.")
1267
1268 (defvar gnus-newsgroup-saved nil
1269   "List of articles that have been saved.")
1270
1271 (defvar gnus-newsgroup-kill-headers nil)
1272
1273 (defvar gnus-newsgroup-replied nil
1274   "List of articles that have been replied to in the current newsgroup.")
1275
1276 (defvar gnus-newsgroup-forwarded nil
1277   "List of articles that have been forwarded in the current newsgroup.")
1278
1279 (defvar gnus-newsgroup-recent nil
1280   "List of articles that have are recent in the current newsgroup.")
1281
1282 (defvar gnus-newsgroup-expirable nil
1283   "Sorted list of articles in the current newsgroup that can be expired.")
1284
1285 (defvar gnus-newsgroup-processable nil
1286   "List of articles in the current newsgroup that can be processed.")
1287
1288 (defvar gnus-newsgroup-downloadable nil
1289   "Sorted list of articles in the current newsgroup that can be processed.")
1290
1291 (defvar gnus-newsgroup-unfetched nil
1292   "Sorted list of articles in the current newsgroup whose headers have
1293 not been fetched into the agent.
1294
1295 This list will always be a subset of gnus-newsgroup-undownloaded.")
1296
1297 (defvar gnus-newsgroup-undownloaded nil
1298   "List of articles in the current newsgroup that haven't been downloaded.")
1299
1300 (defvar gnus-newsgroup-unsendable nil
1301   "List of articles in the current newsgroup that won't be sent.")
1302
1303 (defvar gnus-newsgroup-bookmarks nil
1304   "List of articles in the current newsgroup that have bookmarks.")
1305
1306 (defvar gnus-newsgroup-dormant nil
1307   "Sorted list of dormant articles in the current newsgroup.")
1308
1309 (defvar gnus-newsgroup-unseen nil
1310   "List of unseen articles in the current newsgroup.")
1311
1312 (defvar gnus-newsgroup-seen nil
1313   "Range of seen articles in the current newsgroup.")
1314
1315 (defvar gnus-newsgroup-articles nil
1316   "List of articles in the current newsgroup.")
1317
1318 (defvar gnus-newsgroup-scored nil
1319   "List of scored articles in the current newsgroup.")
1320
1321 (defvar gnus-newsgroup-headers nil
1322   "List of article headers in the current newsgroup.")
1323
1324 (defvar gnus-newsgroup-threads nil)
1325
1326 (defvar gnus-newsgroup-prepared nil
1327   "Whether the current group has been prepared properly.")
1328
1329 (defvar gnus-newsgroup-ancient nil
1330   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1331
1332 (defvar gnus-newsgroup-sparse nil)
1333
1334 (defvar gnus-current-article nil)
1335 (defvar gnus-article-current nil)
1336 (defvar gnus-current-headers nil)
1337 (defvar gnus-have-all-headers nil)
1338 (defvar gnus-last-article nil)
1339 (defvar gnus-newsgroup-history nil)
1340 (defvar gnus-newsgroup-charset nil)
1341 (defvar gnus-newsgroup-ephemeral-charset nil)
1342 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1343
1344 (defvar gnus-article-before-search nil)
1345
1346 (defvar gnus-summary-local-variables
1347   '(gnus-newsgroup-name
1348     gnus-newsgroup-begin gnus-newsgroup-end
1349     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1350     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1351     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1352     gnus-newsgroup-unselected gnus-newsgroup-marked
1353     gnus-newsgroup-spam-marked
1354     gnus-newsgroup-reads gnus-newsgroup-saved
1355     gnus-newsgroup-replied gnus-newsgroup-forwarded
1356     gnus-newsgroup-recent
1357     gnus-newsgroup-expirable
1358     gnus-newsgroup-processable gnus-newsgroup-killed
1359     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1360     gnus-newsgroup-unfetched
1361     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1362     gnus-newsgroup-seen gnus-newsgroup-articles
1363     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1364     gnus-newsgroup-headers gnus-newsgroup-threads
1365     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1366     gnus-current-article gnus-current-headers gnus-have-all-headers
1367     gnus-last-article gnus-article-internal-prepare-hook
1368     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1369     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1370     gnus-thread-expunge-below
1371     gnus-score-alist gnus-current-score-file
1372     (gnus-summary-expunge-below . global)
1373     (gnus-summary-mark-below . global)
1374     (gnus-orphan-score . global)
1375     gnus-newsgroup-active gnus-scores-exclude-files
1376     gnus-newsgroup-history gnus-newsgroup-ancient
1377     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1378     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1379     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1380     (gnus-newsgroup-expunged-tally . 0)
1381     gnus-cache-removable-articles gnus-newsgroup-cached
1382     gnus-newsgroup-data gnus-newsgroup-data-reverse
1383     gnus-newsgroup-limit gnus-newsgroup-limits
1384     gnus-newsgroup-charset gnus-newsgroup-display
1385     gnus-summary-use-undownloaded-faces)
1386   "Variables that are buffer-local to the summary buffers.")
1387
1388 (defvar gnus-newsgroup-variables nil
1389   "A list of variables that have separate values in different newsgroups.
1390 A list of newsgroup (summary buffer) local variables, or cons of
1391 variables and their default values (when the default values are not
1392 nil), that should be made global while the summary buffer is active.
1393 These variables can be used to set variables in the group parameters
1394 while still allowing them to affect operations done in other
1395 buffers. For example:
1396
1397 \(setq gnus-newsgroup-variables
1398      '(message-use-followup-to
1399        (gnus-visible-headers .
1400          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1401 ")
1402
1403 ;; Byte-compiler warning.
1404 (eval-when-compile
1405   ;; Bind features so that require will believe that gnus-sum has
1406   ;; already been loaded (avoids infinite recursion)
1407   (let ((features (cons 'gnus-sum features)))
1408     ;; Several of the declarations in gnus-sum are needed to load the
1409     ;; following files. Right now, these definitions have been
1410     ;; compiled but not defined (evaluated).  We could either do a
1411     ;; eval-and-compile about all of the declarations or evaluate the
1412     ;; source file.
1413     (if (boundp 'gnus-newsgroup-variables)
1414         nil
1415       (load "gnus-sum.el" t t t))
1416     (require 'gnus)
1417     (require 'gnus-agent)
1418     (require 'gnus-art)))
1419
1420 ;; MIME stuff.
1421
1422 (defvar gnus-decode-encoded-word-methods
1423   '(mail-decode-encoded-word-string)
1424   "List of methods used to decode encoded words.
1425
1426 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1427 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1428 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1429 whose names match REGEXP.
1430
1431 For example:
1432 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1433  mail-decode-encoded-word-string
1434  (\"chinese\" . rfc1843-decode-string))")
1435
1436 (defvar gnus-decode-encoded-word-methods-cache nil)
1437
1438 (defun gnus-multi-decode-encoded-word-string (string)
1439   "Apply the functions from `gnus-encoded-word-methods' that match."
1440   (unless (and gnus-decode-encoded-word-methods-cache
1441                (eq gnus-newsgroup-name
1442                    (car gnus-decode-encoded-word-methods-cache)))
1443     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1444     (mapcar (lambda (x)
1445               (if (symbolp x)
1446                   (nconc gnus-decode-encoded-word-methods-cache (list x))
1447                 (if (and gnus-newsgroup-name
1448                          (string-match (car x) gnus-newsgroup-name))
1449                     (nconc gnus-decode-encoded-word-methods-cache
1450                            (list (cdr x))))))
1451             gnus-decode-encoded-word-methods))
1452   (let ((xlist gnus-decode-encoded-word-methods-cache))
1453     (pop xlist)
1454     (while xlist
1455       (setq string (funcall (pop xlist) string))))
1456   string)
1457
1458 ;; Subject simplification.
1459
1460 (defun gnus-simplify-whitespace (str)
1461   "Remove excessive whitespace from STR."
1462   ;; Multiple spaces.
1463   (while (string-match "[ \t][ \t]+" str)
1464     (setq str (concat (substring str 0 (match-beginning 0))
1465                         " "
1466                         (substring str (match-end 0)))))
1467   ;; Leading spaces.
1468   (when (string-match "^[ \t]+" str)
1469     (setq str (substring str (match-end 0))))
1470   ;; Trailing spaces.
1471   (when (string-match "[ \t]+$" str)
1472     (setq str (substring str 0 (match-beginning 0))))
1473   str)
1474
1475 (defun gnus-simplify-all-whitespace (str)
1476   "Remove all whitespace from STR."
1477   (while (string-match "[ \t\n]+" str)
1478     (setq str (replace-match "" nil nil str)))
1479   str)
1480
1481 (defsubst gnus-simplify-subject-re (subject)
1482   "Remove \"Re:\" from subject lines."
1483   (if (string-match message-subject-re-regexp subject)
1484       (substring subject (match-end 0))
1485     subject))
1486
1487 (defun gnus-simplify-subject (subject &optional re-only)
1488   "Remove `Re:' and words in parentheses.
1489 If RE-ONLY is non-nil, strip leading `Re:'s only."
1490   (let ((case-fold-search t))           ;Ignore case.
1491     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1492     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1493       (setq subject (substring subject (match-end 0))))
1494     ;; Remove uninteresting prefixes.
1495     (when (and (not re-only)
1496                gnus-simplify-ignored-prefixes
1497                (string-match gnus-simplify-ignored-prefixes subject))
1498       (setq subject (substring subject (match-end 0))))
1499     ;; Remove words in parentheses from end.
1500     (unless re-only
1501       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1502         (setq subject (substring subject 0 (match-beginning 0)))))
1503     ;; Return subject string.
1504     subject))
1505
1506 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1507 ;; all whitespace.
1508 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1509   (goto-char (point-min))
1510   (while (re-search-forward regexp nil t)
1511     (replace-match (or newtext ""))))
1512
1513 (defun gnus-simplify-buffer-fuzzy ()
1514   "Simplify string in the buffer fuzzily.
1515 The string in the accessible portion of the current buffer is simplified.
1516 It is assumed to be a single-line subject.
1517 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1518 matter is removed.  Additional things can be deleted by setting
1519 `gnus-simplify-subject-fuzzy-regexp'."
1520   (let ((case-fold-search t)
1521         (modified-tick))
1522     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1523
1524     (while (not (eq modified-tick (buffer-modified-tick)))
1525       (setq modified-tick (buffer-modified-tick))
1526       (cond
1527        ((listp gnus-simplify-subject-fuzzy-regexp)
1528         (mapcar 'gnus-simplify-buffer-fuzzy-step
1529                 gnus-simplify-subject-fuzzy-regexp))
1530        (gnus-simplify-subject-fuzzy-regexp
1531         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1532       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1533       (gnus-simplify-buffer-fuzzy-step
1534        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1535       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1536
1537     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1538     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1539     (gnus-simplify-buffer-fuzzy-step " $")
1540     (gnus-simplify-buffer-fuzzy-step "^ +")))
1541
1542 (defun gnus-simplify-subject-fuzzy (subject)
1543   "Simplify a subject string fuzzily.
1544 See `gnus-simplify-buffer-fuzzy' for details."
1545   (save-excursion
1546     (gnus-set-work-buffer)
1547     (let ((case-fold-search t))
1548       ;; Remove uninteresting prefixes.
1549       (when (and gnus-simplify-ignored-prefixes
1550                  (string-match gnus-simplify-ignored-prefixes subject))
1551         (setq subject (substring subject (match-end 0))))
1552       (insert subject)
1553       (inline (gnus-simplify-buffer-fuzzy))
1554       (buffer-string))))
1555
1556 (defsubst gnus-simplify-subject-fully (subject)
1557   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1558   (cond
1559    (gnus-simplify-subject-functions
1560     (gnus-map-function gnus-simplify-subject-functions subject))
1561    ((null gnus-summary-gather-subject-limit)
1562     (gnus-simplify-subject-re subject))
1563    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1564     (gnus-simplify-subject-fuzzy subject))
1565    ((numberp gnus-summary-gather-subject-limit)
1566     (gnus-limit-string (gnus-simplify-subject-re subject)
1567                        gnus-summary-gather-subject-limit))
1568    (t
1569     subject)))
1570
1571 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1572   "Check whether two subjects are equal.
1573 If optional argument SIMPLE-FIRST is t, first argument is already
1574 simplified."
1575   (cond
1576    ((null simple-first)
1577     (equal (gnus-simplify-subject-fully s1)
1578            (gnus-simplify-subject-fully s2)))
1579    (t
1580     (equal s1
1581            (gnus-simplify-subject-fully s2)))))
1582
1583 (defun gnus-summary-bubble-group ()
1584   "Increase the score of the current group.
1585 This is a handy function to add to `gnus-summary-exit-hook' to
1586 increase the score of each group you read."
1587   (gnus-group-add-score gnus-newsgroup-name))
1588
1589 \f
1590 ;;;
1591 ;;; Gnus summary mode
1592 ;;;
1593
1594 (put 'gnus-summary-mode 'mode-class 'special)
1595
1596 (defvar gnus-article-commands-menu)
1597
1598 ;; Non-orthogonal keys
1599
1600 (gnus-define-keys gnus-summary-mode-map
1601   " " gnus-summary-next-page
1602   "\177" gnus-summary-prev-page
1603   [delete] gnus-summary-prev-page
1604   [backspace] gnus-summary-prev-page
1605   "\r" gnus-summary-scroll-up
1606   "\M-\r" gnus-summary-scroll-down
1607   "n" gnus-summary-next-unread-article
1608   "p" gnus-summary-prev-unread-article
1609   "N" gnus-summary-next-article
1610   "P" gnus-summary-prev-article
1611   "\M-\C-n" gnus-summary-next-same-subject
1612   "\M-\C-p" gnus-summary-prev-same-subject
1613   "\M-n" gnus-summary-next-unread-subject
1614   "\M-p" gnus-summary-prev-unread-subject
1615   "." gnus-summary-first-unread-article
1616   "," gnus-summary-best-unread-article
1617   "\M-s" gnus-summary-search-article-forward
1618   "\M-r" gnus-summary-search-article-backward
1619   "<" gnus-summary-beginning-of-article
1620   ">" gnus-summary-end-of-article
1621   "j" gnus-summary-goto-article
1622   "^" gnus-summary-refer-parent-article
1623   "\M-^" gnus-summary-refer-article
1624   "u" gnus-summary-tick-article-forward
1625   "!" gnus-summary-tick-article-forward
1626   "U" gnus-summary-tick-article-backward
1627   "d" gnus-summary-mark-as-read-forward
1628   "D" gnus-summary-mark-as-read-backward
1629   "E" gnus-summary-mark-as-expirable
1630   "\M-u" gnus-summary-clear-mark-forward
1631   "\M-U" gnus-summary-clear-mark-backward
1632   "k" gnus-summary-kill-same-subject-and-select
1633   "\C-k" gnus-summary-kill-same-subject
1634   "\M-\C-k" gnus-summary-kill-thread
1635   "\M-\C-l" gnus-summary-lower-thread
1636   "e" gnus-summary-edit-article
1637   "#" gnus-summary-mark-as-processable
1638   "\M-#" gnus-summary-unmark-as-processable
1639   "\M-\C-t" gnus-summary-toggle-threads
1640   "\M-\C-s" gnus-summary-show-thread
1641   "\M-\C-h" gnus-summary-hide-thread
1642   "\M-\C-f" gnus-summary-next-thread
1643   "\M-\C-b" gnus-summary-prev-thread
1644   [(meta down)] gnus-summary-next-thread
1645   [(meta up)] gnus-summary-prev-thread
1646   "\M-\C-u" gnus-summary-up-thread
1647   "\M-\C-d" gnus-summary-down-thread
1648   "&" gnus-summary-execute-command
1649   "c" gnus-summary-catchup-and-exit
1650   "\C-w" gnus-summary-mark-region-as-read
1651   "\C-t" gnus-summary-toggle-truncation
1652   "?" gnus-summary-mark-as-dormant
1653   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1654   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1655   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1656   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1657   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1658   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1659   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1660   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1661   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1662   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1663   "=" gnus-summary-expand-window
1664   "\C-x\C-s" gnus-summary-reselect-current-group
1665   "\M-g" gnus-summary-rescan-group
1666   "w" gnus-summary-stop-page-breaking
1667   "\C-c\C-r" gnus-summary-caesar-message
1668   "f" gnus-summary-followup
1669   "F" gnus-summary-followup-with-original
1670   "C" gnus-summary-cancel-article
1671   "r" gnus-summary-reply
1672   "R" gnus-summary-reply-with-original
1673   "\C-c\C-f" gnus-summary-mail-forward
1674   "o" gnus-summary-save-article
1675   "\C-o" gnus-summary-save-article-mail
1676   "|" gnus-summary-pipe-output
1677   "\M-k" gnus-summary-edit-local-kill
1678   "\M-K" gnus-summary-edit-global-kill
1679   ;; "V" gnus-version
1680   "\C-c\C-d" gnus-summary-describe-group
1681   "q" gnus-summary-exit
1682   "Q" gnus-summary-exit-no-update
1683   "\C-c\C-i" gnus-info-find-node
1684   gnus-mouse-2 gnus-mouse-pick-article
1685   "m" gnus-summary-mail-other-window
1686   "a" gnus-summary-post-news
1687   "i" gnus-summary-news-other-window
1688   "x" gnus-summary-limit-to-unread
1689   "s" gnus-summary-isearch-article
1690   "t" gnus-summary-toggle-header
1691   "g" gnus-summary-show-article
1692   "l" gnus-summary-goto-last-article
1693   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1694   "\C-d" gnus-summary-enter-digest-group
1695   "\M-\C-d" gnus-summary-read-document
1696   "\M-\C-e" gnus-summary-edit-parameters
1697   "\M-\C-a" gnus-summary-customize-parameters
1698   "\C-c\C-b" gnus-bug
1699   "*" gnus-cache-enter-article
1700   "\M-*" gnus-cache-remove-article
1701   "\M-&" gnus-summary-universal-argument
1702   "\C-l" gnus-recenter
1703   "I" gnus-summary-increase-score
1704   "L" gnus-summary-lower-score
1705   "\M-i" gnus-symbolic-argument
1706   "h" gnus-summary-select-article-buffer
1707
1708   "b" gnus-article-view-part
1709   "\M-t" gnus-summary-toggle-display-buttonized
1710
1711   "V" gnus-summary-score-map
1712   "X" gnus-uu-extract-map
1713   "S" gnus-summary-send-map)
1714
1715 ;; Sort of orthogonal keymap
1716 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1717   "t" gnus-summary-tick-article-forward
1718   "!" gnus-summary-tick-article-forward
1719   "d" gnus-summary-mark-as-read-forward
1720   "r" gnus-summary-mark-as-read-forward
1721   "c" gnus-summary-clear-mark-forward
1722   " " gnus-summary-clear-mark-forward
1723   "e" gnus-summary-mark-as-expirable
1724   "x" gnus-summary-mark-as-expirable
1725   "?" gnus-summary-mark-as-dormant
1726   "b" gnus-summary-set-bookmark
1727   "B" gnus-summary-remove-bookmark
1728   "#" gnus-summary-mark-as-processable
1729   "\M-#" gnus-summary-unmark-as-processable
1730   "S" gnus-summary-limit-include-expunged
1731   "C" gnus-summary-catchup
1732   "H" gnus-summary-catchup-to-here
1733   "h" gnus-summary-catchup-from-here
1734   "\C-c" gnus-summary-catchup-all
1735   "k" gnus-summary-kill-same-subject-and-select
1736   "K" gnus-summary-kill-same-subject
1737   "P" gnus-uu-mark-map)
1738
1739 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1740   "c" gnus-summary-clear-above
1741   "u" gnus-summary-tick-above
1742   "m" gnus-summary-mark-above
1743   "k" gnus-summary-kill-below)
1744
1745 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1746   "/" gnus-summary-limit-to-subject
1747   "n" gnus-summary-limit-to-articles
1748   "w" gnus-summary-pop-limit
1749   "s" gnus-summary-limit-to-subject
1750   "a" gnus-summary-limit-to-author
1751   "u" gnus-summary-limit-to-unread
1752   "m" gnus-summary-limit-to-marks
1753   "M" gnus-summary-limit-exclude-marks
1754   "v" gnus-summary-limit-to-score
1755   "*" gnus-summary-limit-include-cached
1756   "D" gnus-summary-limit-include-dormant
1757   "T" gnus-summary-limit-include-thread
1758   "d" gnus-summary-limit-exclude-dormant
1759   "t" gnus-summary-limit-to-age
1760   "." gnus-summary-limit-to-unseen
1761   "x" gnus-summary-limit-to-extra
1762   "p" gnus-summary-limit-to-display-predicate
1763   "E" gnus-summary-limit-include-expunged
1764   "c" gnus-summary-limit-exclude-childless-dormant
1765   "C" gnus-summary-limit-mark-excluded-as-read
1766   "o" gnus-summary-insert-old-articles
1767   "N" gnus-summary-insert-new-articles
1768   "r" gnus-summary-limit-to-replied)
1769
1770 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1771   "n" gnus-summary-next-unread-article
1772   "p" gnus-summary-prev-unread-article
1773   "N" gnus-summary-next-article
1774   "P" gnus-summary-prev-article
1775   "\C-n" gnus-summary-next-same-subject
1776   "\C-p" gnus-summary-prev-same-subject
1777   "\M-n" gnus-summary-next-unread-subject
1778   "\M-p" gnus-summary-prev-unread-subject
1779   "f" gnus-summary-first-unread-article
1780   "b" gnus-summary-best-unread-article
1781   "j" gnus-summary-goto-article
1782   "g" gnus-summary-goto-subject
1783   "l" gnus-summary-goto-last-article
1784   "o" gnus-summary-pop-article)
1785
1786 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1787   "k" gnus-summary-kill-thread
1788   "l" gnus-summary-lower-thread
1789   "i" gnus-summary-raise-thread
1790   "T" gnus-summary-toggle-threads
1791   "t" gnus-summary-rethread-current
1792   "^" gnus-summary-reparent-thread
1793   "s" gnus-summary-show-thread
1794   "S" gnus-summary-show-all-threads
1795   "h" gnus-summary-hide-thread
1796   "H" gnus-summary-hide-all-threads
1797   "n" gnus-summary-next-thread
1798   "p" gnus-summary-prev-thread
1799   "u" gnus-summary-up-thread
1800   "o" gnus-summary-top-thread
1801   "d" gnus-summary-down-thread
1802   "#" gnus-uu-mark-thread
1803   "\M-#" gnus-uu-unmark-thread)
1804
1805 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1806   "g" gnus-summary-prepare
1807   "c" gnus-summary-insert-cached-articles
1808   "d" gnus-summary-insert-dormant-articles)
1809
1810 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1811   "c" gnus-summary-catchup-and-exit
1812   "C" gnus-summary-catchup-all-and-exit
1813   "E" gnus-summary-exit-no-update
1814   "Q" gnus-summary-exit
1815   "Z" gnus-summary-exit
1816   "n" gnus-summary-catchup-and-goto-next-group
1817   "R" gnus-summary-reselect-current-group
1818   "G" gnus-summary-rescan-group
1819   "N" gnus-summary-next-group
1820   "s" gnus-summary-save-newsrc
1821   "P" gnus-summary-prev-group)
1822
1823 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1824   " " gnus-summary-next-page
1825   "n" gnus-summary-next-page
1826   "\177" gnus-summary-prev-page
1827   [delete] gnus-summary-prev-page
1828   "p" gnus-summary-prev-page
1829   "\r" gnus-summary-scroll-up
1830   "\M-\r" gnus-summary-scroll-down
1831   "<" gnus-summary-beginning-of-article
1832   ">" gnus-summary-end-of-article
1833   "b" gnus-summary-beginning-of-article
1834   "e" gnus-summary-end-of-article
1835   "^" gnus-summary-refer-parent-article
1836   "r" gnus-summary-refer-parent-article
1837   "D" gnus-summary-enter-digest-group
1838   "R" gnus-summary-refer-references
1839   "T" gnus-summary-refer-thread
1840   "g" gnus-summary-show-article
1841   "s" gnus-summary-isearch-article
1842   "P" gnus-summary-print-article
1843   "M" gnus-mailing-list-insinuate
1844   "t" gnus-article-babel)
1845
1846 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1847   "b" gnus-article-add-buttons
1848   "B" gnus-article-add-buttons-to-head
1849   "o" gnus-article-treat-overstrike
1850   "e" gnus-article-emphasize
1851   "w" gnus-article-fill-cited-article
1852   "Q" gnus-article-fill-long-lines
1853   "C" gnus-article-capitalize-sentences
1854   "c" gnus-article-remove-cr
1855   "q" gnus-article-de-quoted-unreadable
1856   "6" gnus-article-de-base64-unreadable
1857   "Z" gnus-article-decode-HZ
1858   "A" gnus-article-treat-ansi-sequences
1859   "h" gnus-article-wash-html
1860   "u" gnus-article-unsplit-urls
1861   "s" gnus-summary-force-verify-and-decrypt
1862   "f" gnus-article-display-x-face
1863   "l" gnus-summary-stop-page-breaking
1864   "r" gnus-summary-caesar-message
1865   "m" gnus-summary-morse-message
1866   "t" gnus-summary-toggle-header
1867   "g" gnus-treat-smiley
1868   "v" gnus-summary-verbose-headers
1869   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1870   "p" gnus-article-verify-x-pgp-sig
1871   "d" gnus-article-treat-dumbquotes)
1872
1873 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1874   ;; mnemonic: deuglif*Y*
1875   "u" gnus-article-outlook-unwrap-lines
1876   "a" gnus-article-outlook-repair-attribution
1877   "c" gnus-article-outlook-rearrange-citation
1878   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1879
1880 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1881   "a" gnus-article-hide
1882   "h" gnus-article-hide-headers
1883   "b" gnus-article-hide-boring-headers
1884   "s" gnus-article-hide-signature
1885   "c" gnus-article-hide-citation
1886   "C" gnus-article-hide-citation-in-followups
1887   "l" gnus-article-hide-list-identifiers
1888   "B" gnus-article-strip-banner
1889   "P" gnus-article-hide-pem
1890   "\C-c" gnus-article-hide-citation-maybe)
1891
1892 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1893   "a" gnus-article-highlight
1894   "h" gnus-article-highlight-headers
1895   "c" gnus-article-highlight-citation
1896   "s" gnus-article-highlight-signature)
1897
1898 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1899   "f" gnus-article-treat-fold-headers
1900   "u" gnus-article-treat-unfold-headers
1901   "n" gnus-article-treat-fold-newsgroups)
1902
1903 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1904   "x" gnus-article-display-x-face
1905   "d" gnus-article-display-face
1906   "s" gnus-treat-smiley
1907   "D" gnus-article-remove-images
1908   "f" gnus-treat-from-picon
1909   "m" gnus-treat-mail-picon
1910   "n" gnus-treat-newsgroups-picon)
1911
1912 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
1913   "w" gnus-article-decode-mime-words
1914   "c" gnus-article-decode-charset
1915   "v" gnus-mime-view-all-parts
1916   "b" gnus-article-view-part)
1917
1918 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
1919   "z" gnus-article-date-ut
1920   "u" gnus-article-date-ut
1921   "l" gnus-article-date-local
1922   "p" gnus-article-date-english
1923   "e" gnus-article-date-lapsed
1924   "o" gnus-article-date-original
1925   "i" gnus-article-date-iso8601
1926   "s" gnus-article-date-user)
1927
1928 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
1929   "t" gnus-article-remove-trailing-blank-lines
1930   "l" gnus-article-strip-leading-blank-lines
1931   "m" gnus-article-strip-multiple-blank-lines
1932   "a" gnus-article-strip-blank-lines
1933   "A" gnus-article-strip-all-blank-lines
1934   "s" gnus-article-strip-leading-space
1935   "e" gnus-article-strip-trailing-space
1936   "w" gnus-article-remove-leading-whitespace)
1937
1938 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
1939   "v" gnus-version
1940   "f" gnus-summary-fetch-faq
1941   "d" gnus-summary-describe-group
1942   "h" gnus-summary-describe-briefly
1943   "i" gnus-info-find-node
1944   "c" gnus-group-fetch-charter
1945   "C" gnus-group-fetch-control)
1946
1947 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
1948   "e" gnus-summary-expire-articles
1949   "\M-\C-e" gnus-summary-expire-articles-now
1950   "\177" gnus-summary-delete-article
1951   [delete] gnus-summary-delete-article
1952   [backspace] gnus-summary-delete-article
1953   "m" gnus-summary-move-article
1954   "r" gnus-summary-respool-article
1955   "w" gnus-summary-edit-article
1956   "c" gnus-summary-copy-article
1957   "B" gnus-summary-crosspost-article
1958   "q" gnus-summary-respool-query
1959   "t" gnus-summary-respool-trace
1960   "i" gnus-summary-import-article
1961   "I" gnus-summary-create-article
1962   "p" gnus-summary-article-posted-p)
1963
1964 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
1965   "o" gnus-summary-save-article
1966   "m" gnus-summary-save-article-mail
1967   "F" gnus-summary-write-article-file
1968   "r" gnus-summary-save-article-rmail
1969   "f" gnus-summary-save-article-file
1970   "b" gnus-summary-save-article-body-file
1971   "h" gnus-summary-save-article-folder
1972   "v" gnus-summary-save-article-vm
1973   "p" gnus-summary-pipe-output
1974   "P" gnus-summary-muttprint
1975   "s" gnus-soup-add-article)
1976
1977 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
1978   "b" gnus-summary-display-buttonized
1979   "m" gnus-summary-repair-multipart
1980   "v" gnus-article-view-part
1981   "o" gnus-article-save-part
1982   "c" gnus-article-copy-part
1983   "C" gnus-article-view-part-as-charset
1984   "e" gnus-article-view-part-externally
1985   "E" gnus-article-encrypt-body
1986   "i" gnus-article-inline-part
1987   "|" gnus-article-pipe-part)
1988
1989 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
1990   "p" gnus-summary-mark-as-processable
1991   "u" gnus-summary-unmark-as-processable
1992   "U" gnus-summary-unmark-all-processable
1993   "v" gnus-uu-mark-over
1994   "s" gnus-uu-mark-series
1995   "r" gnus-uu-mark-region
1996   "g" gnus-uu-unmark-region
1997   "R" gnus-uu-mark-by-regexp
1998   "G" gnus-uu-unmark-by-regexp
1999   "t" gnus-uu-mark-thread
2000   "T" gnus-uu-unmark-thread
2001   "a" gnus-uu-mark-all
2002   "b" gnus-uu-mark-buffer
2003   "S" gnus-uu-mark-sparse
2004   "k" gnus-summary-kill-process-mark
2005   "y" gnus-summary-yank-process-mark
2006   "w" gnus-summary-save-process-mark
2007   "i" gnus-uu-invert-processable)
2008
2009 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2010   ;;"x" gnus-uu-extract-any
2011   "m" gnus-summary-save-parts
2012   "u" gnus-uu-decode-uu
2013   "U" gnus-uu-decode-uu-and-save
2014   "s" gnus-uu-decode-unshar
2015   "S" gnus-uu-decode-unshar-and-save
2016   "o" gnus-uu-decode-save
2017   "O" gnus-uu-decode-save
2018   "b" gnus-uu-decode-binhex
2019   "B" gnus-uu-decode-binhex
2020   "p" gnus-uu-decode-postscript
2021   "P" gnus-uu-decode-postscript-and-save)
2022
2023 (gnus-define-keys
2024     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2025   "u" gnus-uu-decode-uu-view
2026   "U" gnus-uu-decode-uu-and-save-view
2027   "s" gnus-uu-decode-unshar-view
2028   "S" gnus-uu-decode-unshar-and-save-view
2029   "o" gnus-uu-decode-save-view
2030   "O" gnus-uu-decode-save-view
2031   "b" gnus-uu-decode-binhex-view
2032   "B" gnus-uu-decode-binhex-view
2033   "p" gnus-uu-decode-postscript-view
2034   "P" gnus-uu-decode-postscript-and-save-view)
2035
2036 (defvar gnus-article-post-menu nil)
2037
2038 (defconst gnus-summary-menu-maxlen 20)
2039
2040 (defun gnus-summary-menu-split (menu)
2041   ;; If we have lots of elements, divide them into groups of 20
2042   ;; and make a pane (or submenu) for each one.
2043   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2044       (let ((menu menu) sublists next
2045             (i 1))
2046         (while menu
2047           ;; Pull off the next gnus-summary-menu-maxlen elements
2048           ;; and make them the next element of sublist.
2049           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2050           (if next
2051               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2052                       nil))
2053           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2054                                              (aref (car (last menu)) 0)) menu)
2055                                sublists))
2056           (setq i (1+ i))
2057           (setq menu next))
2058         (nreverse sublists))
2059     ;; Few elements--put them all in one pane.
2060     menu))
2061
2062 (defun gnus-summary-make-menu-bar ()
2063   (gnus-turn-off-edit-menu 'summary)
2064
2065   (unless (boundp 'gnus-summary-misc-menu)
2066
2067     (easy-menu-define
2068       gnus-summary-kill-menu gnus-summary-mode-map ""
2069       (cons
2070        "Score"
2071        (nconc
2072         (list
2073          ["Customize" gnus-score-customize t])
2074         (gnus-make-score-map 'increase)
2075         (gnus-make-score-map 'lower)
2076         '(("Mark"
2077            ["Kill below" gnus-summary-kill-below t]
2078            ["Mark above" gnus-summary-mark-above t]
2079            ["Tick above" gnus-summary-tick-above t]
2080            ["Clear above" gnus-summary-clear-above t])
2081           ["Current score" gnus-summary-current-score t]
2082           ["Set score" gnus-summary-set-score t]
2083           ["Switch current score file..." gnus-score-change-score-file t]
2084           ["Set mark below..." gnus-score-set-mark-below t]
2085           ["Set expunge below..." gnus-score-set-expunge-below t]
2086           ["Edit current score file" gnus-score-edit-current-scores t]
2087           ["Edit score file" gnus-score-edit-file t]
2088           ["Trace score" gnus-score-find-trace t]
2089           ["Find words" gnus-score-find-favourite-words t]
2090           ["Rescore buffer" gnus-summary-rescore t]
2091           ["Increase score..." gnus-summary-increase-score t]
2092           ["Lower score..." gnus-summary-lower-score t]))))
2093
2094     ;; Define both the Article menu in the summary buffer and the
2095     ;; equivalent Commands menu in the article buffer here for
2096     ;; consistency.
2097     (let ((innards
2098            `(("Hide"
2099               ["All" gnus-article-hide t]
2100               ["Headers" gnus-article-hide-headers t]
2101               ["Signature" gnus-article-hide-signature t]
2102               ["Citation" gnus-article-hide-citation t]
2103               ["List identifiers" gnus-article-hide-list-identifiers t]
2104               ["Banner" gnus-article-strip-banner t]
2105               ["Boring headers" gnus-article-hide-boring-headers t])
2106              ("Highlight"
2107               ["All" gnus-article-highlight t]
2108               ["Headers" gnus-article-highlight-headers t]
2109               ["Signature" gnus-article-highlight-signature t]
2110               ["Citation" gnus-article-highlight-citation t])
2111              ("MIME"
2112               ["Words" gnus-article-decode-mime-words t]
2113               ["Charset" gnus-article-decode-charset t]
2114               ["QP" gnus-article-de-quoted-unreadable t]
2115               ["Base64" gnus-article-de-base64-unreadable t]
2116               ["View MIME buttons" gnus-summary-display-buttonized t]
2117               ["View all" gnus-mime-view-all-parts t]
2118               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2119               ["Encrypt body" gnus-article-encrypt-body
2120                :active (not (gnus-group-read-only-p))
2121                ,@(if (featurep 'xemacs) nil
2122                    '(:help "Encrypt the message body on disk"))]
2123               ["Extract all parts..." gnus-summary-save-parts t]
2124               ("Multipart"
2125                ["Repair multipart" gnus-summary-repair-multipart t]
2126                ["Pipe part..." gnus-article-pipe-part t]
2127                ["Inline part" gnus-article-inline-part t]
2128                ["Encrypt body" gnus-article-encrypt-body
2129                 :active (not (gnus-group-read-only-p))
2130                ,@(if (featurep 'xemacs) nil
2131                    '(:help "Encrypt the message body on disk"))]
2132                ["View part externally" gnus-article-view-part-externally t]
2133                ["View part with charset..." gnus-article-view-part-as-charset t]
2134                ["Copy part" gnus-article-copy-part t]
2135                ["Save part..." gnus-article-save-part t]
2136                ["View part" gnus-article-view-part t]))
2137              ("Date"
2138               ["Local" gnus-article-date-local t]
2139               ["ISO8601" gnus-article-date-iso8601 t]
2140               ["UT" gnus-article-date-ut t]
2141               ["Original" gnus-article-date-original t]
2142               ["Lapsed" gnus-article-date-lapsed t]
2143               ["User-defined" gnus-article-date-user t])
2144              ("Display"
2145               ["Remove images" gnus-article-remove-images t]
2146               ["Toggle smiley" gnus-treat-smiley t]
2147               ["Show X-Face" gnus-article-display-x-face t]
2148               ["Show picons in From" gnus-treat-from-picon t]
2149               ["Show picons in mail headers" gnus-treat-mail-picon t]
2150               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2151               ("View as different encoding"
2152                ,@(gnus-summary-menu-split
2153                   (mapcar
2154                    (lambda (cs)
2155                      ;; Since easymenu under Emacs doesn't allow
2156                      ;; lambda forms for menu commands, we should
2157                      ;; provide intern'ed function symbols.
2158                      (let ((command (intern (format "\
2159 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2160                        (fset command
2161                              `(lambda ()
2162                                 (interactive)
2163                                 (let ((gnus-summary-show-article-charset-alist
2164                                        '((1 . ,cs))))
2165                                   (gnus-summary-show-article 1))))
2166                        `[,(symbol-name cs) ,command t]))
2167                    (sort (if (fboundp 'coding-system-list)
2168                              (coding-system-list)
2169                            (mapcar 'car mm-mime-mule-charset-alist))
2170                          'string<)))))
2171              ("Washing"
2172               ("Remove Blanks"
2173                ["Leading" gnus-article-strip-leading-blank-lines t]
2174                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2175                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2176                ["All of the above" gnus-article-strip-blank-lines t]
2177                ["All" gnus-article-strip-all-blank-lines t]
2178                ["Leading space" gnus-article-strip-leading-space t]
2179                ["Trailing space" gnus-article-strip-trailing-space t]
2180                ["Leading space in headers"
2181                 gnus-article-remove-leading-whitespace t])
2182               ["Overstrike" gnus-article-treat-overstrike t]
2183               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2184               ["Emphasis" gnus-article-emphasize t]
2185               ["Word wrap" gnus-article-fill-cited-article t]
2186               ["Fill long lines" gnus-article-fill-long-lines t]
2187               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2188               ["Remove CR" gnus-article-remove-cr t]
2189               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2190               ["Base64" gnus-article-de-base64-unreadable t]
2191               ["Rot 13" gnus-summary-caesar-message
2192                ,@(if (featurep 'xemacs) '(t)
2193                    '(:help "\"Caesar rotate\" article by 13"))]
2194               ["Morse decode" gnus-summary-morse-message t]
2195               ["Unix pipe..." gnus-summary-pipe-message t]
2196               ["Add buttons" gnus-article-add-buttons t]
2197               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2198               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2199               ["Verbose header" gnus-summary-verbose-headers t]
2200               ["Toggle header" gnus-summary-toggle-header t]
2201               ["Unfold headers" gnus-article-treat-unfold-headers t]
2202               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2203               ["Html" gnus-article-wash-html t]
2204               ["Unsplit URLs" gnus-article-unsplit-urls t]
2205               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2206               ["Decode HZ" gnus-article-decode-HZ t]
2207               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2208               ("(Outlook) Deuglify"
2209                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2210                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2211                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2212                ["Full (Outlook) deuglify"
2213                 gnus-article-outlook-deuglify-article t])
2214               )
2215              ("Output"
2216               ["Save in default format..." gnus-summary-save-article
2217                ,@(if (featurep 'xemacs) '(t)
2218                    '(:help "Save article using default method"))]
2219               ["Save in file..." gnus-summary-save-article-file
2220                ,@(if (featurep 'xemacs) '(t)
2221                    '(:help "Save article in file"))]
2222               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2223               ["Save in MH folder..." gnus-summary-save-article-folder t]
2224               ["Save in VM folder..." gnus-summary-save-article-vm t]
2225               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2226               ["Save body in file..." gnus-summary-save-article-body-file t]
2227               ["Pipe through a filter..." gnus-summary-pipe-output t]
2228               ["Add to SOUP packet" gnus-soup-add-article t]
2229               ["Print with Muttprint..." gnus-summary-muttprint t]
2230               ["Print" gnus-summary-print-article t])
2231              ("Backend"
2232               ["Respool article..." gnus-summary-respool-article t]
2233               ["Move article..." gnus-summary-move-article
2234                (gnus-check-backend-function
2235                 'request-move-article gnus-newsgroup-name)]
2236               ["Copy article..." gnus-summary-copy-article t]
2237               ["Crosspost article..." gnus-summary-crosspost-article
2238                (gnus-check-backend-function
2239                 'request-replace-article gnus-newsgroup-name)]
2240               ["Import file..." gnus-summary-import-article
2241                (gnus-check-backend-function
2242                 'request-accept-article gnus-newsgroup-name)]
2243               ["Create article..." gnus-summary-create-article
2244                (gnus-check-backend-function
2245                 'request-accept-article gnus-newsgroup-name)]
2246               ["Check if posted" gnus-summary-article-posted-p t]
2247               ["Edit article" gnus-summary-edit-article
2248                (not (gnus-group-read-only-p))]
2249               ["Delete article" gnus-summary-delete-article
2250                (gnus-check-backend-function
2251                 'request-expire-articles gnus-newsgroup-name)]
2252               ["Query respool" gnus-summary-respool-query t]
2253               ["Trace respool" gnus-summary-respool-trace t]
2254               ["Delete expirable articles" gnus-summary-expire-articles-now
2255                (gnus-check-backend-function
2256                 'request-expire-articles gnus-newsgroup-name)])
2257              ("Extract"
2258               ["Uudecode" gnus-uu-decode-uu
2259                ,@(if (featurep 'xemacs) '(t)
2260                    '(:help "Decode uuencoded article(s)"))]
2261               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2262               ["Unshar" gnus-uu-decode-unshar t]
2263               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2264               ["Save" gnus-uu-decode-save t]
2265               ["Binhex" gnus-uu-decode-binhex t]
2266               ["Postscript" gnus-uu-decode-postscript t]
2267               ["All MIME parts" gnus-summary-save-parts t])
2268              ("Cache"
2269               ["Enter article" gnus-cache-enter-article t]
2270               ["Remove article" gnus-cache-remove-article t])
2271              ["Translate" gnus-article-babel t]
2272              ["Select article buffer" gnus-summary-select-article-buffer t]
2273              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2274              ["Isearch article..." gnus-summary-isearch-article t]
2275              ["Beginning of the article" gnus-summary-beginning-of-article t]
2276              ["End of the article" gnus-summary-end-of-article t]
2277              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2278              ["Fetch referenced articles" gnus-summary-refer-references t]
2279              ["Fetch current thread" gnus-summary-refer-thread t]
2280              ["Fetch article with id..." gnus-summary-refer-article t]
2281              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2282              ["Redisplay" gnus-summary-show-article t]
2283              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2284       (easy-menu-define
2285         gnus-summary-article-menu gnus-summary-mode-map ""
2286         (cons "Article" innards))
2287
2288       (if (not (keymapp gnus-summary-article-menu))
2289           (easy-menu-define
2290             gnus-article-commands-menu gnus-article-mode-map ""
2291             (cons "Commands" innards))
2292         ;; in Emacs, don't share menu.
2293         (setq gnus-article-commands-menu
2294               (copy-keymap gnus-summary-article-menu))
2295         (define-key gnus-article-mode-map [menu-bar commands]
2296           (cons "Commands" gnus-article-commands-menu))))
2297
2298     (easy-menu-define
2299       gnus-summary-thread-menu gnus-summary-mode-map ""
2300       '("Threads"
2301         ["Find all messages in thread" gnus-summary-refer-thread t]
2302         ["Toggle threading" gnus-summary-toggle-threads t]
2303         ["Hide threads" gnus-summary-hide-all-threads t]
2304         ["Show threads" gnus-summary-show-all-threads t]
2305         ["Hide thread" gnus-summary-hide-thread t]
2306         ["Show thread" gnus-summary-show-thread t]
2307         ["Go to next thread" gnus-summary-next-thread t]
2308         ["Go to previous thread" gnus-summary-prev-thread t]
2309         ["Go down thread" gnus-summary-down-thread t]
2310         ["Go up thread" gnus-summary-up-thread t]
2311         ["Top of thread" gnus-summary-top-thread t]
2312         ["Mark thread as read" gnus-summary-kill-thread t]
2313         ["Lower thread score" gnus-summary-lower-thread t]
2314         ["Raise thread score" gnus-summary-raise-thread t]
2315         ["Rethread current" gnus-summary-rethread-current t]))
2316
2317     (easy-menu-define
2318       gnus-summary-post-menu gnus-summary-mode-map ""
2319       `("Post"
2320         ["Send a message (mail or news)" gnus-summary-post-news
2321          ,@(if (featurep 'xemacs) '(t)
2322              '(:help "Post an article"))]
2323         ["Followup" gnus-summary-followup
2324          ,@(if (featurep 'xemacs) '(t)
2325              '(:help "Post followup to this article"))]
2326         ["Followup and yank" gnus-summary-followup-with-original
2327          ,@(if (featurep 'xemacs) '(t)
2328              '(:help "Post followup to this article, quoting its contents"))]
2329         ["Supersede article" gnus-summary-supersede-article t]
2330         ["Cancel article" gnus-summary-cancel-article
2331          ,@(if (featurep 'xemacs) '(t)
2332              '(:help "Cancel an article you posted"))]
2333         ["Reply" gnus-summary-reply t]
2334         ["Reply and yank" gnus-summary-reply-with-original t]
2335         ["Wide reply" gnus-summary-wide-reply t]
2336         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2337          ,@(if (featurep 'xemacs) '(t)
2338              '(:help "Mail a reply, quoting this article"))]
2339         ["Very wide reply" gnus-summary-very-wide-reply t]
2340         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2341          ,@(if (featurep 'xemacs) '(t)
2342              '(:help "Mail a very wide reply, quoting this article"))]
2343         ["Mail forward" gnus-summary-mail-forward t]
2344         ["Post forward" gnus-summary-post-forward t]
2345         ["Digest and mail" gnus-uu-digest-mail-forward t]
2346         ["Digest and post" gnus-uu-digest-post-forward t]
2347         ["Resend message" gnus-summary-resend-message t]
2348         ["Resend message edit" gnus-summary-resend-message-edit t]
2349         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2350         ["Send a mail" gnus-summary-mail-other-window t]
2351         ["Create a local message" gnus-summary-news-other-window t]
2352         ["Uuencode and post" gnus-uu-post-news
2353          ,@(if (featurep 'xemacs) '(t)
2354              '(:help "Post a uuencoded article"))]
2355         ["Followup via news" gnus-summary-followup-to-mail t]
2356         ["Followup via news and yank"
2357          gnus-summary-followup-to-mail-with-original t]
2358         ;;("Draft"
2359         ;;["Send" gnus-summary-send-draft t]
2360         ;;["Send bounced" gnus-resend-bounced-mail t])
2361         ))
2362
2363     (cond
2364      ((not (keymapp gnus-summary-post-menu))
2365       (setq gnus-article-post-menu gnus-summary-post-menu))
2366      ((not gnus-article-post-menu)
2367       ;; Don't share post menu.
2368       (setq gnus-article-post-menu
2369             (copy-keymap gnus-summary-post-menu))))
2370     (define-key gnus-article-mode-map [menu-bar post]
2371       (cons "Post" gnus-article-post-menu))
2372
2373     (easy-menu-define
2374       gnus-summary-misc-menu gnus-summary-mode-map ""
2375       `("Gnus"
2376         ("Mark Read"
2377          ["Mark as read" gnus-summary-mark-as-read-forward t]
2378          ["Mark same subject and select"
2379           gnus-summary-kill-same-subject-and-select t]
2380          ["Mark same subject" gnus-summary-kill-same-subject t]
2381          ["Catchup" gnus-summary-catchup
2382           ,@(if (featurep 'xemacs) '(t)
2383               '(:help "Mark unread articles in this group as read"))]
2384          ["Catchup all" gnus-summary-catchup-all t]
2385          ["Catchup to here" gnus-summary-catchup-to-here t]
2386          ["Catchup from here" gnus-summary-catchup-from-here t]
2387          ["Catchup region" gnus-summary-mark-region-as-read
2388           (gnus-mark-active-p)]
2389          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2390         ("Mark Various"
2391          ["Tick" gnus-summary-tick-article-forward t]
2392          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2393          ["Remove marks" gnus-summary-clear-mark-forward t]
2394          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2395          ["Set bookmark" gnus-summary-set-bookmark t]
2396          ["Remove bookmark" gnus-summary-remove-bookmark t])
2397         ("Limit to"
2398          ["Marks..." gnus-summary-limit-to-marks t]
2399          ["Subject..." gnus-summary-limit-to-subject t]
2400          ["Author..." gnus-summary-limit-to-author t]
2401          ["Age..." gnus-summary-limit-to-age t]
2402          ["Extra..." gnus-summary-limit-to-extra t]
2403          ["Score..." gnus-summary-limit-to-score t]
2404          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2405          ["Unread" gnus-summary-limit-to-unread t]
2406          ["Unseen" gnus-summary-limit-to-unseen t]
2407          ["Replied" gnus-summary-limit-to-replied t]
2408          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2409          ["Next articles" gnus-summary-limit-to-articles t]
2410          ["Pop limit" gnus-summary-pop-limit t]
2411          ["Show dormant" gnus-summary-limit-include-dormant t]
2412          ["Hide childless dormant"
2413           gnus-summary-limit-exclude-childless-dormant t]
2414          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2415          ["Hide marked" gnus-summary-limit-exclude-marks t]
2416          ["Show expunged" gnus-summary-limit-include-expunged t])
2417         ("Process Mark"
2418          ["Set mark" gnus-summary-mark-as-processable t]
2419          ["Remove mark" gnus-summary-unmark-as-processable t]
2420          ["Remove all marks" gnus-summary-unmark-all-processable t]
2421          ["Mark above" gnus-uu-mark-over t]
2422          ["Mark series" gnus-uu-mark-series t]
2423          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2424          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2425          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2426          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2427          ["Mark all" gnus-uu-mark-all t]
2428          ["Mark buffer" gnus-uu-mark-buffer t]
2429          ["Mark sparse" gnus-uu-mark-sparse t]
2430          ["Mark thread" gnus-uu-mark-thread t]
2431          ["Unmark thread" gnus-uu-unmark-thread t]
2432          ("Process Mark Sets"
2433           ["Kill" gnus-summary-kill-process-mark t]
2434           ["Yank" gnus-summary-yank-process-mark
2435            gnus-newsgroup-process-stack]
2436           ["Save" gnus-summary-save-process-mark t]
2437           ["Run command on marked..." gnus-summary-universal-argument t]))
2438         ("Scroll article"
2439          ["Page forward" gnus-summary-next-page
2440           ,@(if (featurep 'xemacs) '(t)
2441               '(:help "Show next page of article"))]
2442          ["Page backward" gnus-summary-prev-page
2443           ,@(if (featurep 'xemacs) '(t)
2444               '(:help "Show previous page of article"))]
2445          ["Line forward" gnus-summary-scroll-up t])
2446         ("Move"
2447          ["Next unread article" gnus-summary-next-unread-article t]
2448          ["Previous unread article" gnus-summary-prev-unread-article t]
2449          ["Next article" gnus-summary-next-article t]
2450          ["Previous article" gnus-summary-prev-article t]
2451          ["Next unread subject" gnus-summary-next-unread-subject t]
2452          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2453          ["Next article same subject" gnus-summary-next-same-subject t]
2454          ["Previous article same subject" gnus-summary-prev-same-subject t]
2455          ["First unread article" gnus-summary-first-unread-article t]
2456          ["Best unread article" gnus-summary-best-unread-article t]
2457          ["Go to subject number..." gnus-summary-goto-subject t]
2458          ["Go to article number..." gnus-summary-goto-article t]
2459          ["Go to the last article" gnus-summary-goto-last-article t]
2460          ["Pop article off history" gnus-summary-pop-article t])
2461         ("Sort"
2462          ["Sort by number" gnus-summary-sort-by-number t]
2463          ["Sort by author" gnus-summary-sort-by-author t]
2464          ["Sort by subject" gnus-summary-sort-by-subject t]
2465          ["Sort by date" gnus-summary-sort-by-date t]
2466          ["Sort by score" gnus-summary-sort-by-score t]
2467          ["Sort by lines" gnus-summary-sort-by-lines t]
2468          ["Sort by characters" gnus-summary-sort-by-chars t]
2469          ["Randomize" gnus-summary-sort-by-random t]
2470          ["Original sort" gnus-summary-sort-by-original t])
2471         ("Help"
2472          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2473          ["Describe group" gnus-summary-describe-group t]
2474          ["Fetch charter" gnus-group-fetch-charter
2475           ,@(if (featurep 'xemacs) nil
2476               '(:help "Display the charter of the current group"))]
2477          ["Fetch control message" gnus-group-fetch-control
2478           ,@(if (featurep 'xemacs) nil
2479               '(:help "Display the archived control message for the current group"))]
2480          ["Read manual" gnus-info-find-node t])
2481         ("Modes"
2482          ["Pick and read" gnus-pick-mode t]
2483          ["Binary" gnus-binary-mode t])
2484         ("Regeneration"
2485          ["Regenerate" gnus-summary-prepare t]
2486          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2487          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2488          ["Toggle threading" gnus-summary-toggle-threads t])
2489         ["See old articles" gnus-summary-insert-old-articles t]
2490         ["See new articles" gnus-summary-insert-new-articles t]
2491         ["Filter articles..." gnus-summary-execute-command t]
2492         ["Run command on articles..." gnus-summary-universal-argument t]
2493         ["Search articles forward..." gnus-summary-search-article-forward t]
2494         ["Search articles backward..." gnus-summary-search-article-backward t]
2495         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2496         ["Expand window" gnus-summary-expand-window t]
2497         ["Expire expirable articles" gnus-summary-expire-articles
2498          (gnus-check-backend-function
2499           'request-expire-articles gnus-newsgroup-name)]
2500         ["Edit local kill file" gnus-summary-edit-local-kill t]
2501         ["Edit main kill file" gnus-summary-edit-global-kill t]
2502         ["Edit group parameters" gnus-summary-edit-parameters t]
2503         ["Customize group parameters" gnus-summary-customize-parameters t]
2504         ["Send a bug report" gnus-bug t]
2505         ("Exit"
2506          ["Catchup and exit" gnus-summary-catchup-and-exit
2507           ,@(if (featurep 'xemacs) '(t)
2508               '(:help "Mark unread articles in this group as read, then exit"))]
2509          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2510          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2511          ["Exit group" gnus-summary-exit
2512           ,@(if (featurep 'xemacs) '(t)
2513               '(:help "Exit current group, return to group selection mode"))]
2514          ["Exit group without updating" gnus-summary-exit-no-update t]
2515          ["Exit and goto next group" gnus-summary-next-group t]
2516          ["Exit and goto prev group" gnus-summary-prev-group t]
2517          ["Reselect group" gnus-summary-reselect-current-group t]
2518          ["Rescan group" gnus-summary-rescan-group t]
2519          ["Update dribble" gnus-summary-save-newsrc t])))
2520
2521     (gnus-run-hooks 'gnus-summary-menu-hook)))
2522
2523 (defvar gnus-summary-tool-bar-map nil)
2524
2525 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2526 (defun gnus-summary-make-tool-bar ()
2527   (if (and (fboundp 'tool-bar-add-item-from-menu)
2528            (default-value 'tool-bar-mode)
2529            (not gnus-summary-tool-bar-map))
2530       (setq gnus-summary-tool-bar-map
2531             (let ((tool-bar-map (make-sparse-keymap))
2532                   (load-path (mm-image-load-path)))
2533               (tool-bar-add-item-from-menu
2534                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2535               (tool-bar-add-item-from-menu
2536                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2537               (tool-bar-add-item-from-menu
2538                'gnus-summary-post-news "post" gnus-summary-mode-map)
2539               (tool-bar-add-item-from-menu
2540                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2541               (tool-bar-add-item-from-menu
2542                'gnus-summary-followup "followup" gnus-summary-mode-map)
2543               (tool-bar-add-item-from-menu
2544                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2545               (tool-bar-add-item-from-menu
2546                'gnus-summary-reply "reply" gnus-summary-mode-map)
2547               (tool-bar-add-item-from-menu
2548                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2549               (tool-bar-add-item-from-menu
2550                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2551               (tool-bar-add-item-from-menu
2552                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2553               (tool-bar-add-item-from-menu
2554                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2555               (tool-bar-add-item-from-menu
2556                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2557               (tool-bar-add-item-from-menu
2558                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2559               (tool-bar-add-item-from-menu
2560                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2561               (tool-bar-add-item-from-menu
2562                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2563               tool-bar-map)))
2564   (if gnus-summary-tool-bar-map
2565       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2566
2567 (defun gnus-score-set-default (var value)
2568   "A version of set that updates the GNU Emacs menu-bar."
2569   (set var value)
2570   ;; It is the message that forces the active status to be updated.
2571   (message ""))
2572
2573 (defun gnus-make-score-map (type)
2574   "Make a summary score map of type TYPE."
2575   (if t
2576       nil
2577     (let ((headers '(("author" "from" string)
2578                      ("subject" "subject" string)
2579                      ("article body" "body" string)
2580                      ("article head" "head" string)
2581                      ("xref" "xref" string)
2582                      ("extra header" "extra" string)
2583                      ("lines" "lines" number)
2584                      ("followups to author" "followup" string)))
2585           (types '((number ("less than" <)
2586                            ("greater than" >)
2587                            ("equal" =))
2588                    (string ("substring" s)
2589                            ("exact string" e)
2590                            ("fuzzy string" f)
2591                            ("regexp" r))))
2592           (perms '(("temporary" (current-time-string))
2593                    ("permanent" nil)
2594                    ("immediate" now)))
2595           header)
2596       (list
2597        (apply
2598         'nconc
2599         (list
2600          (if (eq type 'lower)
2601              "Lower score"
2602            "Increase score"))
2603         (let (outh)
2604           (while headers
2605             (setq header (car headers))
2606             (setq outh
2607                   (cons
2608                    (apply
2609                     'nconc
2610                     (list (car header))
2611                     (let ((ts (cdr (assoc (nth 2 header) types)))
2612                           outt)
2613                       (while ts
2614                         (setq outt
2615                               (cons
2616                                (apply
2617                                 'nconc
2618                                 (list (caar ts))
2619                                 (let ((ps perms)
2620                                       outp)
2621                                   (while ps
2622                                     (setq outp
2623                                           (cons
2624                                            (vector
2625                                             (caar ps)
2626                                             (list
2627                                              'gnus-summary-score-entry
2628                                              (nth 1 header)
2629                                              (if (or (string= (nth 1 header)
2630                                                               "head")
2631                                                      (string= (nth 1 header)
2632                                                               "body"))
2633                                                  ""
2634                                                (list 'gnus-summary-header
2635                                                      (nth 1 header)))
2636                                              (list 'quote (nth 1 (car ts)))
2637                                              (list 'gnus-score-delta-default
2638                                                    nil)
2639                                              (nth 1 (car ps))
2640                                              t)
2641                                             t)
2642                                            outp))
2643                                     (setq ps (cdr ps)))
2644                                   (list (nreverse outp))))
2645                                outt))
2646                         (setq ts (cdr ts)))
2647                       (list (nreverse outt))))
2648                    outh))
2649             (setq headers (cdr headers)))
2650           (list (nreverse outh))))))))
2651
2652 \f
2653
2654 (defun gnus-summary-mode (&optional group)
2655   "Major mode for reading articles.
2656
2657 All normal editing commands are switched off.
2658 \\<gnus-summary-mode-map>
2659 Each line in this buffer represents one article.  To read an
2660 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2661 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2662 respectively.
2663
2664 You can also post articles and send mail from this buffer.  To
2665 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2666 of an article, type `\\[gnus-summary-reply]'.
2667
2668 There are approx. one gazillion commands you can execute in this
2669 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2670
2671 The following commands are available:
2672
2673 \\{gnus-summary-mode-map}"
2674   (interactive)
2675   (kill-all-local-variables)
2676   (when (gnus-visual-p 'summary-menu 'menu)
2677     (gnus-summary-make-menu-bar)
2678     (gnus-summary-make-tool-bar))
2679   (gnus-summary-make-local-variables)
2680   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2681     (gnus-summary-make-local-variables))
2682   (gnus-make-thread-indent-array)
2683   (gnus-simplify-mode-line)
2684   (setq major-mode 'gnus-summary-mode)
2685   (setq mode-name "Summary")
2686   (make-local-variable 'minor-mode-alist)
2687   (use-local-map gnus-summary-mode-map)
2688   (buffer-disable-undo)
2689   (setq buffer-read-only t)             ;Disable modification
2690   (setq truncate-lines t)
2691   (setq selective-display t)
2692   (setq selective-display-ellipses t)   ;Display `...'
2693   (gnus-summary-set-display-table)
2694   (gnus-set-default-directory)
2695   (setq gnus-newsgroup-name group)
2696   (make-local-variable 'gnus-summary-line-format)
2697   (make-local-variable 'gnus-summary-line-format-spec)
2698   (make-local-variable 'gnus-summary-dummy-line-format)
2699   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2700   (make-local-variable 'gnus-summary-mark-positions)
2701   (gnus-make-local-hook 'pre-command-hook)
2702   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2703   (gnus-run-hooks 'gnus-summary-mode-hook)
2704   (turn-on-gnus-mailing-list-mode)
2705   (mm-enable-multibyte)
2706   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2707   (gnus-update-summary-mark-positions))
2708
2709 (defun gnus-summary-make-local-variables ()
2710   "Make all the local summary buffer variables."
2711   (let (global)
2712     (dolist (local gnus-summary-local-variables)
2713       (if (consp local)
2714           (progn
2715             (if (eq (cdr local) 'global)
2716                 ;; Copy the global value of the variable.
2717                 (setq global (symbol-value (car local)))
2718               ;; Use the value from the list.
2719               (setq global (eval (cdr local))))
2720             (set (make-local-variable (car local)) global))
2721         ;; Simple nil-valued local variable.
2722         (set (make-local-variable local) nil)))))
2723
2724 (defun gnus-summary-clear-local-variables ()
2725   (let ((locals gnus-summary-local-variables))
2726     (while locals
2727       (if (consp (car locals))
2728           (and (vectorp (caar locals))
2729                (set (caar locals) nil))
2730         (and (vectorp (car locals))
2731              (set (car locals) nil)))
2732       (setq locals (cdr locals)))))
2733
2734 ;; Summary data functions.
2735
2736 (defmacro gnus-data-number (data)
2737   `(car ,data))
2738
2739 (defmacro gnus-data-set-number (data number)
2740   `(setcar ,data ,number))
2741
2742 (defmacro gnus-data-mark (data)
2743   `(nth 1 ,data))
2744
2745 (defmacro gnus-data-set-mark (data mark)
2746   `(setcar (nthcdr 1 ,data) ,mark))
2747
2748 (defmacro gnus-data-pos (data)
2749   `(nth 2 ,data))
2750
2751 (defmacro gnus-data-set-pos (data pos)
2752   `(setcar (nthcdr 2 ,data) ,pos))
2753
2754 (defmacro gnus-data-header (data)
2755   `(nth 3 ,data))
2756
2757 (defmacro gnus-data-set-header (data header)
2758   `(setf (nth 3 ,data) ,header))
2759
2760 (defmacro gnus-data-level (data)
2761   `(nth 4 ,data))
2762
2763 (defmacro gnus-data-unread-p (data)
2764   `(= (nth 1 ,data) gnus-unread-mark))
2765
2766 (defmacro gnus-data-read-p (data)
2767   `(/= (nth 1 ,data) gnus-unread-mark))
2768
2769 (defmacro gnus-data-pseudo-p (data)
2770   `(consp (nth 3 ,data)))
2771
2772 (defmacro gnus-data-find (number)
2773   `(assq ,number gnus-newsgroup-data))
2774
2775 (defmacro gnus-data-find-list (number &optional data)
2776   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2777      (memq (assq ,number bdata)
2778            bdata)))
2779
2780 (defmacro gnus-data-make (number mark pos header level)
2781   `(list ,number ,mark ,pos ,header ,level))
2782
2783 (defun gnus-data-enter (after-article number mark pos header level offset)
2784   (let ((data (gnus-data-find-list after-article)))
2785     (unless data
2786       (error "No such article: %d" after-article))
2787     (setcdr data (cons (gnus-data-make number mark pos header level)
2788                        (cdr data)))
2789     (setq gnus-newsgroup-data-reverse nil)
2790     (gnus-data-update-list (cddr data) offset)))
2791
2792 (defun gnus-data-enter-list (after-article list &optional offset)
2793   (when list
2794     (let ((data (and after-article (gnus-data-find-list after-article)))
2795           (ilist list))
2796       (if (not (or data
2797                    after-article))
2798           (let ((odata gnus-newsgroup-data))
2799             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2800             (when offset
2801               (gnus-data-update-list odata offset)))
2802       ;; Find the last element in the list to be spliced into the main
2803         ;; list.
2804         (while (cdr list)
2805           (setq list (cdr list)))
2806         (if (not data)
2807             (progn
2808               (setcdr list gnus-newsgroup-data)
2809               (setq gnus-newsgroup-data ilist)
2810               (when offset
2811                 (gnus-data-update-list (cdr list) offset)))
2812           (setcdr list (cdr data))
2813           (setcdr data ilist)
2814           (when offset
2815             (gnus-data-update-list (cdr list) offset))))
2816       (setq gnus-newsgroup-data-reverse nil))))
2817
2818 (defun gnus-data-remove (article &optional offset)
2819   (let ((data gnus-newsgroup-data))
2820     (if (= (gnus-data-number (car data)) article)
2821         (progn
2822           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2823                 gnus-newsgroup-data-reverse nil)
2824           (when offset
2825             (gnus-data-update-list gnus-newsgroup-data offset)))
2826       (while (cdr data)
2827         (when (= (gnus-data-number (cadr data)) article)
2828           (setcdr data (cddr data))
2829           (when offset
2830             (gnus-data-update-list (cdr data) offset))
2831           (setq data nil
2832                 gnus-newsgroup-data-reverse nil))
2833         (setq data (cdr data))))))
2834
2835 (defmacro gnus-data-list (backward)
2836   `(if ,backward
2837        (or gnus-newsgroup-data-reverse
2838            (setq gnus-newsgroup-data-reverse
2839                  (reverse gnus-newsgroup-data)))
2840      gnus-newsgroup-data))
2841
2842 (defun gnus-data-update-list (data offset)
2843   "Add OFFSET to the POS of all data entries in DATA."
2844   (setq gnus-newsgroup-data-reverse nil)
2845   (while data
2846     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2847     (setq data (cdr data))))
2848
2849 (defun gnus-summary-article-pseudo-p (article)
2850   "Say whether this article is a pseudo article or not."
2851   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2852
2853 (defmacro gnus-summary-article-sparse-p (article)
2854   "Say whether this article is a sparse article or not."
2855   `(memq ,article gnus-newsgroup-sparse))
2856
2857 (defmacro gnus-summary-article-ancient-p (article)
2858   "Say whether this article is a sparse article or not."
2859   `(memq ,article gnus-newsgroup-ancient))
2860
2861 (defun gnus-article-parent-p (number)
2862   "Say whether this article is a parent or not."
2863   (let ((data (gnus-data-find-list number)))
2864     (and (cdr data)              ; There has to be an article after...
2865          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2866             (gnus-data-level (nth 1 data))))))
2867
2868 (defun gnus-article-children (number)
2869   "Return a list of all children to NUMBER."
2870   (let* ((data (gnus-data-find-list number))
2871          (level (gnus-data-level (car data)))
2872          children)
2873     (setq data (cdr data))
2874     (while (and data
2875                 (= (gnus-data-level (car data)) (1+ level)))
2876       (push (gnus-data-number (car data)) children)
2877       (setq data (cdr data)))
2878     children))
2879
2880 (defmacro gnus-summary-skip-intangible ()
2881   "If the current article is intangible, then jump to a different article."
2882   '(let ((to (get-text-property (point) 'gnus-intangible)))
2883      (and to (gnus-summary-goto-subject to))))
2884
2885 (defmacro gnus-summary-article-intangible-p ()
2886   "Say whether this article is intangible or not."
2887   '(get-text-property (point) 'gnus-intangible))
2888
2889 (defun gnus-article-read-p (article)
2890   "Say whether ARTICLE is read or not."
2891   (not (or (memq article gnus-newsgroup-marked)
2892            (memq article gnus-newsgroup-spam-marked)
2893            (memq article gnus-newsgroup-unreads)
2894            (memq article gnus-newsgroup-unselected)
2895            (memq article gnus-newsgroup-dormant))))
2896
2897 ;; Some summary mode macros.
2898
2899 (defmacro gnus-summary-article-number ()
2900   "The article number of the article on the current line.
2901 If there isn't an article number here, then we return the current
2902 article number."
2903   '(progn
2904      (gnus-summary-skip-intangible)
2905      (or (get-text-property (point) 'gnus-number)
2906          (gnus-summary-last-subject))))
2907
2908 (defmacro gnus-summary-article-header (&optional number)
2909   "Return the header of article NUMBER."
2910   `(gnus-data-header (gnus-data-find
2911                       ,(or number '(gnus-summary-article-number)))))
2912
2913 (defmacro gnus-summary-thread-level (&optional number)
2914   "Return the level of thread that starts with article NUMBER."
2915   `(if (and (eq gnus-summary-make-false-root 'dummy)
2916             (get-text-property (point) 'gnus-intangible))
2917        0
2918      (gnus-data-level (gnus-data-find
2919                        ,(or number '(gnus-summary-article-number))))))
2920
2921 (defmacro gnus-summary-article-mark (&optional number)
2922   "Return the mark of article NUMBER."
2923   `(gnus-data-mark (gnus-data-find
2924                     ,(or number '(gnus-summary-article-number)))))
2925
2926 (defmacro gnus-summary-article-pos (&optional number)
2927   "Return the position of the line of article NUMBER."
2928   `(gnus-data-pos (gnus-data-find
2929                    ,(or number '(gnus-summary-article-number)))))
2930
2931 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
2932 (defmacro gnus-summary-article-subject (&optional number)
2933   "Return current subject string or nil if nothing."
2934   `(let ((headers
2935           ,(if number
2936                `(gnus-data-header (assq ,number gnus-newsgroup-data))
2937              '(gnus-data-header (assq (gnus-summary-article-number)
2938                                       gnus-newsgroup-data)))))
2939      (and headers
2940           (vectorp headers)
2941           (mail-header-subject headers))))
2942
2943 (defmacro gnus-summary-article-score (&optional number)
2944   "Return current article score."
2945   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
2946                   gnus-newsgroup-scored))
2947        gnus-summary-default-score 0))
2948
2949 (defun gnus-summary-article-children (&optional number)
2950   "Return a list of article numbers that are children of article NUMBER."
2951   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
2952          (level (gnus-data-level (car data)))
2953          l children)
2954     (while (and (setq data (cdr data))
2955                 (> (setq l (gnus-data-level (car data))) level))
2956       (and (= (1+ level) l)
2957            (push (gnus-data-number (car data))
2958                  children)))
2959     (nreverse children)))
2960
2961 (defun gnus-summary-article-parent (&optional number)
2962   "Return the article number of the parent of article NUMBER."
2963   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
2964                                     (gnus-data-list t)))
2965          (level (gnus-data-level (car data))))
2966     (if (zerop level)
2967         ()                              ; This is a root.
2968       ;; We search until we find an article with a level less than
2969       ;; this one.  That function has to be the parent.
2970       (while (and (setq data (cdr data))
2971                   (not (< (gnus-data-level (car data)) level))))
2972       (and data (gnus-data-number (car data))))))
2973
2974 (defun gnus-unread-mark-p (mark)
2975   "Say whether MARK is the unread mark."
2976   (= mark gnus-unread-mark))
2977
2978 (defun gnus-read-mark-p (mark)
2979   "Say whether MARK is one of the marks that mark as read.
2980 This is all marks except unread, ticked, dormant, and expirable."
2981   (not (or (= mark gnus-unread-mark)
2982            (= mark gnus-ticked-mark)
2983            (= mark gnus-spam-mark)
2984            (= mark gnus-dormant-mark)
2985            (= mark gnus-expirable-mark))))
2986
2987 (defmacro gnus-article-mark (number)
2988   "Return the MARK of article NUMBER.
2989 This macro should only be used when computing the mark the \"first\"
2990 time; i.e., when generating the summary lines.  After that,
2991 `gnus-summary-article-mark' should be used to examine the
2992 marks of articles."
2993   `(cond
2994     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
2995     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
2996     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
2997     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
2998     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
2999     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3000     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3001     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3002            gnus-ancient-mark))))
3003
3004 ;; Saving hidden threads.
3005
3006 (defmacro gnus-save-hidden-threads (&rest forms)
3007   "Save hidden threads, eval FORMS, and restore the hidden threads."
3008   (let ((config (make-symbol "config")))
3009     `(let ((,config (gnus-hidden-threads-configuration)))
3010        (unwind-protect
3011            (save-excursion
3012              ,@forms)
3013          (gnus-restore-hidden-threads-configuration ,config)))))
3014 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3015 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3016
3017 (defun gnus-data-compute-positions ()
3018   "Compute the positions of all articles."
3019   (setq gnus-newsgroup-data-reverse nil)
3020   (let ((data gnus-newsgroup-data))
3021     (save-excursion
3022       (gnus-save-hidden-threads
3023         (gnus-summary-show-all-threads)
3024         (goto-char (point-min))
3025         (while data
3026           (while (get-text-property (point) 'gnus-intangible)
3027             (forward-line 1))
3028           (gnus-data-set-pos (car data) (+ (point) 3))
3029           (setq data (cdr data))
3030           (forward-line 1))))))
3031
3032 (defun gnus-hidden-threads-configuration ()
3033   "Return the current hidden threads configuration."
3034   (save-excursion
3035     (let (config)
3036       (goto-char (point-min))
3037       (while (search-forward "\r" nil t)
3038         (push (1- (point)) config))
3039       config)))
3040
3041 (defun gnus-restore-hidden-threads-configuration (config)
3042   "Restore hidden threads configuration from CONFIG."
3043   (save-excursion
3044     (let (point buffer-read-only)
3045       (while (setq point (pop config))
3046         (when (and (< point (point-max))
3047                    (goto-char point)
3048                    (eq (char-after) ?\n))
3049           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3050
3051 ;; Various summary mode internalish functions.
3052
3053 (defun gnus-mouse-pick-article (e)
3054   (interactive "e")
3055   (mouse-set-point e)
3056   (gnus-summary-next-page nil t))
3057
3058 (defun gnus-summary-set-display-table ()
3059   "Change the display table.
3060 Odd characters have a tendency to mess
3061 up nicely formatted displays - we make all possible glyphs
3062 display only a single character."
3063
3064   ;; We start from the standard display table, if any.
3065   (let ((table (or (copy-sequence standard-display-table)
3066                    (make-display-table)))
3067         (i 32))
3068     ;; Nix out all the control chars...
3069     (while (>= (setq i (1- i)) 0)
3070       (aset table i [??]))
3071    ;; ... but not newline and cr, of course.  (cr is necessary for the
3072     ;; selective display).
3073     (aset table ?\n nil)
3074     (aset table ?\r nil)
3075     ;; We keep TAB as well.
3076     (aset table ?\t nil)
3077     ;; We nix out any glyphs over 126 that are not set already.
3078     (let ((i 256))
3079       (while (>= (setq i (1- i)) 127)
3080         ;; Only modify if the entry is nil.
3081         (unless (aref table i)
3082           (aset table i [??]))))
3083     (setq buffer-display-table table)))
3084
3085 (defun gnus-summary-set-article-display-arrow (pos)
3086   "Update the overlay arrow to point to line at position POS."
3087   (when (and gnus-summary-display-arrow
3088              (boundp 'overlay-arrow-position)
3089              (boundp 'overlay-arrow-string))
3090     (save-excursion
3091       (goto-char pos)
3092       (beginning-of-line)
3093       (unless overlay-arrow-position
3094         (setq overlay-arrow-position (make-marker)))
3095       (setq overlay-arrow-string "=>"
3096             overlay-arrow-position (set-marker overlay-arrow-position
3097                                                (point)
3098                                                (current-buffer))))))
3099
3100 (defun gnus-summary-setup-buffer (group)
3101   "Initialize summary buffer."
3102   (let ((buffer (gnus-summary-buffer-name group))
3103         (dead-name (concat "*Dead Summary "
3104                            (gnus-group-decoded-name group) "*")))
3105     ;; If a dead summary buffer exists, we kill it.
3106     (when (gnus-buffer-live-p dead-name)
3107       (gnus-kill-buffer dead-name))
3108     (if (get-buffer buffer)
3109         (progn
3110           (set-buffer buffer)
3111           (setq gnus-summary-buffer (current-buffer))
3112           (not gnus-newsgroup-prepared))
3113       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3114       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3115       (gnus-summary-mode group)
3116       (when gnus-carpal
3117         (gnus-carpal-setup-buffer 'summary))
3118       (unless gnus-single-article-buffer
3119         (make-local-variable 'gnus-article-buffer)
3120         (make-local-variable 'gnus-article-current)
3121         (make-local-variable 'gnus-original-article-buffer))
3122       (setq gnus-newsgroup-name group)
3123       ;; Set any local variables in the group parameters.
3124       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3125       t)))
3126
3127 (defun gnus-set-global-variables ()
3128   "Set the global equivalents of the buffer-local variables.
3129 They are set to the latest values they had.  These reflect the summary
3130 buffer that was in action when the last article was fetched."
3131   (when (eq major-mode 'gnus-summary-mode)
3132     (setq gnus-summary-buffer (current-buffer))
3133     (let ((name gnus-newsgroup-name)
3134           (marked gnus-newsgroup-marked)
3135           (spam gnus-newsgroup-spam-marked)
3136           (unread gnus-newsgroup-unreads)
3137           (headers gnus-current-headers)
3138           (data gnus-newsgroup-data)
3139           (summary gnus-summary-buffer)
3140           (article-buffer gnus-article-buffer)
3141           (original gnus-original-article-buffer)
3142           (gac gnus-article-current)
3143           (reffed gnus-reffed-article-number)
3144           (score-file gnus-current-score-file)
3145           (default-charset gnus-newsgroup-charset)
3146           vlist)
3147       (let ((locals gnus-newsgroup-variables))
3148         (while locals
3149           (if (consp (car locals))
3150               (push (eval (caar locals)) vlist)
3151             (push (eval (car locals)) vlist))
3152           (setq locals (cdr locals)))
3153         (setq vlist (nreverse vlist)))
3154       (save-excursion
3155         (set-buffer gnus-group-buffer)
3156         (setq gnus-newsgroup-name name
3157               gnus-newsgroup-marked marked
3158               gnus-newsgroup-spam-marked spam
3159               gnus-newsgroup-unreads unread
3160               gnus-current-headers headers
3161               gnus-newsgroup-data data
3162               gnus-article-current gac
3163               gnus-summary-buffer summary
3164               gnus-article-buffer article-buffer
3165               gnus-original-article-buffer original
3166               gnus-reffed-article-number reffed
3167               gnus-current-score-file score-file
3168               gnus-newsgroup-charset default-charset)
3169         (let ((locals gnus-newsgroup-variables))
3170           (while locals
3171             (if (consp (car locals))
3172                 (set (caar locals) (pop vlist))
3173               (set (car locals) (pop vlist)))
3174             (setq locals (cdr locals))))
3175         ;; The article buffer also has local variables.
3176         (when (gnus-buffer-live-p gnus-article-buffer)
3177           (set-buffer gnus-article-buffer)
3178           (setq gnus-summary-buffer summary))))))
3179
3180 (defun gnus-summary-article-unread-p (article)
3181   "Say whether ARTICLE is unread or not."
3182   (memq article gnus-newsgroup-unreads))
3183
3184 (defun gnus-summary-first-article-p (&optional article)
3185   "Return whether ARTICLE is the first article in the buffer."
3186   (if (not (setq article (or article (gnus-summary-article-number))))
3187       nil
3188     (eq article (caar gnus-newsgroup-data))))
3189
3190 (defun gnus-summary-last-article-p (&optional article)
3191   "Return whether ARTICLE is the last article in the buffer."
3192   (if (not (setq article (or article (gnus-summary-article-number))))
3193       ;; All non-existent numbers are the last article.  :-)
3194       t
3195     (not (cdr (gnus-data-find-list article)))))
3196
3197 (defun gnus-make-thread-indent-array ()
3198   (let ((n 200))
3199     (unless (and gnus-thread-indent-array
3200                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3201       (setq gnus-thread-indent-array (make-vector 201 "")
3202             gnus-thread-indent-array-level gnus-thread-indent-level)
3203       (while (>= n 0)
3204         (aset gnus-thread-indent-array n
3205               (make-string (* n gnus-thread-indent-level) ? ))
3206         (setq n (1- n))))))
3207
3208 (defun gnus-update-summary-mark-positions ()
3209   "Compute where the summary marks are to go."
3210   (save-excursion
3211     (when (gnus-buffer-exists-p gnus-summary-buffer)
3212       (set-buffer gnus-summary-buffer))
3213     (let ((gnus-replied-mark 129)
3214           (gnus-score-below-mark 130)
3215           (gnus-score-over-mark 130)
3216           (gnus-undownloaded-mark 131)
3217           (spec gnus-summary-line-format-spec)
3218           gnus-visual pos)
3219       (save-excursion
3220         (gnus-set-work-buffer)
3221         (let ((gnus-summary-line-format-spec spec)
3222               (gnus-newsgroup-downloadable '(0)))
3223           (gnus-summary-insert-line
3224            [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil]
3225            0 nil t 128 t nil "" nil 1)
3226           (goto-char (point-min))
3227           (setq pos (list (cons 'unread (and (search-forward "\200" nil t)
3228                                              (- (point) (point-min) 1)))))
3229           (goto-char (point-min))
3230           (push (cons 'replied (and (search-forward "\201" nil t)
3231                                     (- (point) (point-min) 1)))
3232                 pos)
3233           (goto-char (point-min))
3234           (push (cons 'score (and (search-forward "\202" nil t)
3235                                   (- (point) (point-min) 1)))
3236                 pos)
3237           (goto-char (point-min))
3238           (push (cons 'download
3239                       (and (search-forward "\203" nil t)
3240                            (- (point) (point-min) 1)))
3241                 pos)))
3242       (setq gnus-summary-mark-positions pos))))
3243
3244 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3245   "Insert a dummy root in the summary buffer."
3246   (beginning-of-line)
3247   (gnus-add-text-properties
3248    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3249    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3250
3251 (defun gnus-summary-extract-address-component (from)
3252   (or (car (funcall gnus-extract-address-components from))
3253       from))
3254
3255 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3256   (let ((mail-parse-charset gnus-newsgroup-charset)
3257         ; Is it really necessary to do this next part for each summary line?
3258         ; Luckily, doesn't seem to slow things down much.
3259         (mail-parse-ignored-charsets
3260          (with-current-buffer gnus-summary-buffer
3261            gnus-newsgroup-ignored-charsets)))
3262     (or
3263      (and gnus-ignored-from-addresses
3264           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3265           (let ((extra-headers (mail-header-extra header))
3266                 to
3267                 newsgroups)
3268             (cond
3269              ((setq to (cdr (assq 'To extra-headers)))
3270               (concat "-> "
3271                       (inline
3272                         (gnus-summary-extract-address-component
3273                          (funcall gnus-decode-encoded-word-function to)))))
3274              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3275               (concat "=> " newsgroups)))))
3276      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3277
3278 (defun gnus-summary-insert-line (gnus-tmp-header
3279                                  gnus-tmp-level gnus-tmp-current
3280                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3281                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3282                                  &optional gnus-tmp-dummy gnus-tmp-score
3283                                  gnus-tmp-process)
3284   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3285          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3286          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3287          (gnus-tmp-score-char
3288           (if (or (null gnus-summary-default-score)
3289                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3290                       gnus-summary-zcore-fuzz))
3291               ?                         ;Whitespace
3292             (if (< gnus-tmp-score gnus-summary-default-score)
3293                 gnus-score-below-mark gnus-score-over-mark)))
3294          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3295          (gnus-tmp-replied
3296           (cond (gnus-tmp-process gnus-process-mark)
3297                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3298                  gnus-cached-mark)
3299                 (gnus-tmp-replied gnus-replied-mark)
3300                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3301                  gnus-forwarded-mark)
3302                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3303                  gnus-saved-mark)
3304                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3305                  gnus-recent-mark)
3306                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3307                  gnus-unseen-mark)
3308                 (t gnus-no-mark)))
3309          (gnus-tmp-downloaded
3310           (cond (undownloaded
3311                  gnus-undownloaded-mark)
3312                 (gnus-newsgroup-agentized
3313                  gnus-downloaded-mark)
3314                 (t
3315                  gnus-no-mark)))
3316          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3317          (gnus-tmp-name
3318           (cond
3319            ((string-match "<[^>]+> *$" gnus-tmp-from)
3320             (let ((beg (match-beginning 0)))
3321               (or (and (string-match "^\".+\"" gnus-tmp-from)
3322                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3323                   (substring gnus-tmp-from 0 beg))))
3324            ((string-match "(.+)" gnus-tmp-from)
3325             (substring gnus-tmp-from
3326                        (1+ (match-beginning 0)) (1- (match-end 0))))
3327            (t gnus-tmp-from)))
3328          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3329          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3330          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3331          (buffer-read-only nil))
3332     (when (string= gnus-tmp-name "")
3333       (setq gnus-tmp-name gnus-tmp-from))
3334     (unless (numberp gnus-tmp-lines)
3335       (setq gnus-tmp-lines -1))
3336     (if (= gnus-tmp-lines -1)
3337         (setq gnus-tmp-lines "?")
3338       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3339       (gnus-put-text-property
3340      (point)
3341      (progn (eval gnus-summary-line-format-spec) (point))
3342        'gnus-number gnus-tmp-number)
3343     (when (gnus-visual-p 'summary-highlight 'highlight)
3344       (forward-line -1)
3345       (gnus-run-hooks 'gnus-summary-update-hook)
3346       (forward-line 1))))
3347
3348 (defun gnus-summary-update-line (&optional dont-update)
3349   "Update summary line after change."
3350   (when (and gnus-summary-default-score
3351              (not gnus-summary-inhibit-highlight))
3352     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3353            (article (gnus-summary-article-number))
3354            (score (gnus-summary-article-score article)))
3355       (unless dont-update
3356         (if (and gnus-summary-mark-below
3357                  (< (gnus-summary-article-score)
3358                     gnus-summary-mark-below))
3359             ;; This article has a low score, so we mark it as read.
3360             (when (memq article gnus-newsgroup-unreads)
3361               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3362           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3363             ;; This article was previously marked as read on account
3364             ;; of a low score, but now it has risen, so we mark it as
3365             ;; unread.
3366             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3367         (gnus-summary-update-mark
3368          (if (or (null gnus-summary-default-score)
3369                  (<= (abs (- score gnus-summary-default-score))
3370                      gnus-summary-zcore-fuzz))
3371              ?                          ;Whitespace
3372            (if (< score gnus-summary-default-score)
3373                gnus-score-below-mark gnus-score-over-mark))
3374          'score))
3375       ;; Do visual highlighting.
3376       (when (gnus-visual-p 'summary-highlight 'highlight)
3377         (gnus-run-hooks 'gnus-summary-update-hook)))))
3378
3379 (defvar gnus-tmp-new-adopts nil)
3380
3381 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3382   "Return the number of articles in THREAD.
3383 This may be 0 in some cases -- if none of the articles in
3384 the thread are to be displayed."
3385   (let* ((number
3386          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3387           (cond
3388            ((not (listp thread))
3389             1)
3390            ((and (consp thread) (cdr thread))
3391             (apply
3392              '+ 1 (mapcar
3393                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3394            ((null thread)
3395             1)
3396            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3397             1)
3398            (t 0))))
3399     (when (and level (zerop level) gnus-tmp-new-adopts)
3400       (incf number
3401             (apply '+ (mapcar
3402                        'gnus-summary-number-of-articles-in-thread
3403                        gnus-tmp-new-adopts))))
3404     (if char
3405         (if (> number 1) gnus-not-empty-thread-mark
3406           gnus-empty-thread-mark)
3407       number)))
3408
3409 (defsubst gnus-summary-line-message-size (head)
3410   "Return pretty-printed version of message size.
3411 This function is intended to be used in
3412 `gnus-summary-line-format-alist'."
3413   (let ((c (or (mail-header-chars head) -1)))
3414     (cond ((< c 0) "n/a")               ; chars not available
3415           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3416           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3417           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3418           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3419
3420
3421 (defun gnus-summary-set-local-parameters (group)
3422   "Go through the local params of GROUP and set all variable specs in that list."
3423   (let ((params (gnus-group-find-parameter group))
3424         (vars '(quit-config))           ; Ignore quit-config.
3425         elem)
3426     (while params
3427       (setq elem (car params)
3428             params (cdr params))
3429       (and (consp elem)                 ; Has to be a cons.
3430            (consp (cdr elem))           ; The cdr has to be a list.
3431            (symbolp (car elem))         ; Has to be a symbol in there.
3432            (not (memq (car elem) vars))
3433            (ignore-errors               ; So we set it.
3434              (push (car elem) vars)
3435              (make-local-variable (car elem))
3436              (set (car elem) (eval (nth 1 elem))))))))
3437
3438 (defun gnus-summary-read-group (group &optional show-all no-article
3439                                       kill-buffer no-display backward
3440                                       select-articles)
3441   "Start reading news in newsgroup GROUP.
3442 If SHOW-ALL is non-nil, already read articles are also listed.
3443 If NO-ARTICLE is non-nil, no article is selected initially.
3444 If NO-DISPLAY, don't generate a summary buffer."
3445   (let (result)
3446     (while (and group
3447                 (null (setq result
3448                             (let ((gnus-auto-select-next nil))
3449                               (or (gnus-summary-read-group-1
3450                                    group show-all no-article
3451                                    kill-buffer no-display
3452                                    select-articles)
3453                                   (setq show-all nil
3454                                         select-articles nil)))))
3455                 (eq gnus-auto-select-next 'quietly))
3456       (set-buffer gnus-group-buffer)
3457       ;; The entry function called above goes to the next
3458       ;; group automatically, so we go two groups back
3459       ;; if we are searching for the previous group.
3460       (when backward
3461         (gnus-group-prev-unread-group 2))
3462       (if (not (equal group (gnus-group-group-name)))
3463           (setq group (gnus-group-group-name))
3464         (setq group nil)))
3465     result))
3466
3467 (defun gnus-summary-read-group-1 (group show-all no-article
3468                                         kill-buffer no-display
3469                                         &optional select-articles)
3470   ;; Killed foreign groups can't be entered.
3471   ;;  (when (and (not (gnus-group-native-p group))
3472   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3473   ;;    (error "Dead non-native groups can't be entered"))
3474   (gnus-message 5 "Retrieving newsgroup: %s..."
3475                 (gnus-group-decoded-name group))
3476   (let* ((new-group (gnus-summary-setup-buffer group))
3477          (quit-config (gnus-group-quit-config group))
3478          (did-select (and new-group (gnus-select-newsgroup
3479                                      group show-all select-articles))))
3480     (cond
3481      ;; This summary buffer exists already, so we just select it.
3482      ((not new-group)
3483       (gnus-set-global-variables)
3484       (when kill-buffer
3485         (gnus-kill-or-deaden-summary kill-buffer))
3486       (gnus-configure-windows 'summary 'force)
3487       (gnus-set-mode-line 'summary)
3488       (gnus-summary-position-point)
3489       (message "")
3490       t)
3491      ;; We couldn't select this group.
3492      ((null did-select)
3493       (when (and (eq major-mode 'gnus-summary-mode)
3494                  (not (equal (current-buffer) kill-buffer)))
3495         (kill-buffer (current-buffer))
3496         (if (not quit-config)
3497             (progn
3498               ;; Update the info -- marks might need to be removed,
3499               ;; for instance.
3500               (gnus-summary-update-info)
3501               (set-buffer gnus-group-buffer)
3502               (gnus-group-jump-to-group group)
3503               (gnus-group-next-unread-group 1))
3504           (gnus-handle-ephemeral-exit quit-config)))
3505       (let ((grpinfo (gnus-get-info group)))
3506         (if (null (gnus-info-read grpinfo))
3507             (gnus-message 3 "Group %s contains no messages"
3508                           (gnus-group-decoded-name group))
3509           (gnus-message 3 "Can't select group")))
3510       nil)
3511      ;; The user did a `C-g' while prompting for number of articles,
3512      ;; so we exit this group.
3513      ((eq did-select 'quit)
3514       (and (eq major-mode 'gnus-summary-mode)
3515            (not (equal (current-buffer) kill-buffer))
3516            (kill-buffer (current-buffer)))
3517       (when kill-buffer
3518         (gnus-kill-or-deaden-summary kill-buffer))
3519       (if (not quit-config)
3520           (progn
3521             (set-buffer gnus-group-buffer)
3522             (gnus-group-jump-to-group group)
3523             (gnus-group-next-unread-group 1)
3524             (gnus-configure-windows 'group 'force))
3525         (gnus-handle-ephemeral-exit quit-config))
3526       ;; Finally signal the quit.
3527       (signal 'quit nil))
3528      ;; The group was successfully selected.
3529      (t
3530       (gnus-set-global-variables)
3531       ;; Save the active value in effect when the group was entered.
3532       (setq gnus-newsgroup-active
3533             (gnus-copy-sequence
3534              (gnus-active gnus-newsgroup-name)))
3535       ;; You can change the summary buffer in some way with this hook.
3536       (gnus-run-hooks 'gnus-select-group-hook)
3537       (gnus-update-format-specifications
3538        nil 'summary 'summary-mode 'summary-dummy)
3539       (gnus-update-summary-mark-positions)
3540       ;; Do score processing.
3541       (when gnus-use-scoring
3542         (gnus-possibly-score-headers))
3543       ;; Check whether to fill in the gaps in the threads.
3544       (when gnus-build-sparse-threads
3545         (gnus-build-sparse-threads))
3546       ;; Find the initial limit.
3547       (if gnus-show-threads
3548           (if show-all
3549               (let ((gnus-newsgroup-dormant nil))
3550                 (gnus-summary-initial-limit show-all))
3551             (gnus-summary-initial-limit show-all))
3552         ;; When unthreaded, all articles are always shown.
3553         (setq gnus-newsgroup-limit
3554               (mapcar
3555                (lambda (header) (mail-header-number header))
3556                gnus-newsgroup-headers)))
3557       ;; Generate the summary buffer.
3558       (unless no-display
3559         (gnus-summary-prepare))
3560       (when gnus-use-trees
3561         (gnus-tree-open group)
3562         (setq gnus-summary-highlight-line-function
3563               'gnus-tree-highlight-article))
3564       ;; If the summary buffer is empty, but there are some low-scored
3565       ;; articles or some excluded dormants, we include these in the
3566       ;; buffer.
3567       (when (and (zerop (buffer-size))
3568                  (not no-display))
3569         (cond (gnus-newsgroup-dormant
3570                (gnus-summary-limit-include-dormant))
3571               ((and gnus-newsgroup-scored show-all)
3572                (gnus-summary-limit-include-expunged t))))
3573       ;; Function `gnus-apply-kill-file' must be called in this hook.
3574       (gnus-run-hooks 'gnus-apply-kill-hook)
3575       (if (and (zerop (buffer-size))
3576                (not no-display))
3577           (progn
3578             ;; This newsgroup is empty.
3579             (gnus-summary-catchup-and-exit nil t)
3580             (gnus-message 6 "No unread news")
3581             (when kill-buffer
3582               (gnus-kill-or-deaden-summary kill-buffer))
3583             ;; Return nil from this function.
3584             nil)
3585         ;; Hide conversation thread subtrees.  We cannot do this in
3586         ;; gnus-summary-prepare-hook since kill processing may not
3587         ;; work with hidden articles.
3588         (gnus-summary-maybe-hide-threads)
3589         (when kill-buffer
3590           (gnus-kill-or-deaden-summary kill-buffer))
3591         (gnus-summary-auto-select-subject)
3592         ;; Show first unread article if requested.
3593         (if (and (not no-article)
3594                  (not no-display)
3595                  gnus-newsgroup-unreads
3596                  gnus-auto-select-first)
3597             (progn
3598               (gnus-configure-windows 'summary)
3599               (let ((art (gnus-summary-article-number)))
3600                 (unless (and (not gnus-plugged)
3601                              (or (memq art gnus-newsgroup-undownloaded)
3602                                  (memq art gnus-newsgroup-downloadable)))
3603                   (gnus-summary-goto-article art))))
3604           ;; Don't select any articles.
3605           (gnus-summary-position-point)
3606           (gnus-configure-windows 'summary 'force)
3607           (gnus-set-mode-line 'summary))
3608         (when (and gnus-auto-center-group
3609                    (get-buffer-window gnus-group-buffer t))
3610           ;; Gotta use windows, because recenter does weird stuff if
3611           ;; the current buffer ain't the displayed window.
3612           (let ((owin (selected-window)))
3613             (select-window (get-buffer-window gnus-group-buffer t))
3614             (when (gnus-group-goto-group group)
3615               (recenter))
3616             (select-window owin)))
3617         ;; Mark this buffer as "prepared".
3618         (setq gnus-newsgroup-prepared t)
3619         (gnus-run-hooks 'gnus-summary-prepared-hook)
3620         (unless (gnus-ephemeral-group-p group)
3621           (gnus-group-update-group group))
3622         t)))))
3623
3624 (defun gnus-summary-auto-select-subject ()
3625   "Select the subject line on initial group entry."
3626   (goto-char (point-min))
3627   (cond
3628    ((eq gnus-auto-select-subject 'best)
3629     (gnus-summary-best-unread-subject))
3630    ((eq gnus-auto-select-subject 'unread)
3631     (gnus-summary-first-unread-subject))
3632    ((eq gnus-auto-select-subject 'unseen)
3633     (gnus-summary-first-unseen-subject))
3634    ((eq gnus-auto-select-subject 'unseen-or-unread)
3635     (gnus-summary-first-unseen-or-unread-subject))
3636    ((eq gnus-auto-select-subject 'first)
3637     ;; Do nothing.
3638     )
3639    ((functionp gnus-auto-select-subject)
3640     (funcall gnus-auto-select-subject))))
3641
3642 (defun gnus-summary-prepare ()
3643   "Generate the summary buffer."
3644   (interactive)
3645   (let ((buffer-read-only nil))
3646     (erase-buffer)
3647     (setq gnus-newsgroup-data nil
3648           gnus-newsgroup-data-reverse nil)
3649     (gnus-run-hooks 'gnus-summary-generate-hook)
3650     ;; Generate the buffer, either with threads or without.
3651     (when gnus-newsgroup-headers
3652       (gnus-summary-prepare-threads
3653        (if gnus-show-threads
3654            (gnus-sort-gathered-threads
3655             (funcall gnus-summary-thread-gathering-function
3656                      (gnus-sort-threads
3657                       (gnus-cut-threads (gnus-make-threads)))))
3658          ;; Unthreaded display.
3659          (gnus-sort-articles gnus-newsgroup-headers))))
3660     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3661     ;; Call hooks for modifying summary buffer.
3662     (goto-char (point-min))
3663     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3664
3665 (defsubst gnus-general-simplify-subject (subject)
3666   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3667   (setq subject
3668         (cond
3669          ;; Truncate the subject.
3670          (gnus-simplify-subject-functions
3671           (gnus-map-function gnus-simplify-subject-functions subject))
3672          ((numberp gnus-summary-gather-subject-limit)
3673           (setq subject (gnus-simplify-subject-re subject))
3674           (if (> (length subject) gnus-summary-gather-subject-limit)
3675               (substring subject 0 gnus-summary-gather-subject-limit)
3676             subject))
3677          ;; Fuzzily simplify it.
3678          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3679           (gnus-simplify-subject-fuzzy subject))
3680          ;; Just remove the leading "Re:".
3681          (t
3682           (gnus-simplify-subject-re subject))))
3683
3684   (if (and gnus-summary-gather-exclude-subject
3685            (string-match gnus-summary-gather-exclude-subject subject))
3686       nil                         ; This article shouldn't be gathered
3687     subject))
3688
3689 (defun gnus-summary-simplify-subject-query ()
3690   "Query where the respool algorithm would put this article."
3691   (interactive)
3692   (gnus-summary-select-article)
3693   (message (gnus-general-simplify-subject (gnus-summary-article-subject))))
3694
3695 (defun gnus-gather-threads-by-subject (threads)
3696   "Gather threads by looking at Subject headers."
3697   (if (not gnus-summary-make-false-root)
3698       threads
3699     (let ((hashtb (gnus-make-hashtable 1024))
3700           (prev threads)
3701           (result threads)
3702           subject hthread whole-subject)
3703       (while threads
3704         (setq subject (gnus-general-simplify-subject
3705                        (setq whole-subject (mail-header-subject
3706                                             (caar threads)))))
3707         (when subject
3708           (if (setq hthread (gnus-gethash subject hashtb))
3709               (progn
3710                 ;; We enter a dummy root into the thread, if we
3711                 ;; haven't done that already.
3712                 (unless (stringp (caar hthread))
3713                   (setcar hthread (list whole-subject (car hthread))))
3714                 ;; We add this new gathered thread to this gathered
3715                 ;; thread.
3716                 (setcdr (car hthread)
3717                         (nconc (cdar hthread) (list (car threads))))
3718                 ;; Remove it from the list of threads.
3719                 (setcdr prev (cdr threads))
3720                 (setq threads prev))
3721             ;; Enter this thread into the hash table.
3722             (gnus-sethash subject
3723                           (if gnus-summary-make-false-root-always
3724                               (progn
3725                                 ;; If you want a dummy root above all
3726                                 ;; threads...
3727                                 (setcar threads (list whole-subject
3728                                                       (car threads)))
3729                                 threads)
3730                             threads)
3731                           hashtb)))
3732         (setq prev threads)
3733         (setq threads (cdr threads)))
3734       result)))
3735
3736 (defun gnus-gather-threads-by-references (threads)
3737   "Gather threads by looking at References headers."
3738   (let ((idhashtb (gnus-make-hashtable 1024))
3739         (thhashtb (gnus-make-hashtable 1024))
3740         (prev threads)
3741         (result threads)
3742         ids references id gthread gid entered ref)
3743     (while threads
3744       (when (setq references (mail-header-references (caar threads)))
3745         (setq id (mail-header-id (caar threads))
3746               ids (inline (gnus-split-references references))
3747               entered nil)
3748         (while (setq ref (pop ids))
3749           (setq ids (delete ref ids))
3750           (if (not (setq gid (gnus-gethash ref idhashtb)))
3751               (progn
3752                 (gnus-sethash ref id idhashtb)
3753                 (gnus-sethash id threads thhashtb))
3754             (setq gthread (gnus-gethash gid thhashtb))
3755             (unless entered
3756               ;; We enter a dummy root into the thread, if we
3757               ;; haven't done that already.
3758               (unless (stringp (caar gthread))
3759                 (setcar gthread (list (mail-header-subject (caar gthread))
3760                                       (car gthread))))
3761               ;; We add this new gathered thread to this gathered
3762               ;; thread.
3763               (setcdr (car gthread)
3764                       (nconc (cdar gthread) (list (car threads)))))
3765             ;; Add it into the thread hash table.
3766             (gnus-sethash id gthread thhashtb)
3767             (setq entered t)
3768             ;; Remove it from the list of threads.
3769             (setcdr prev (cdr threads))
3770             (setq threads prev))))
3771       (setq prev threads)
3772       (setq threads (cdr threads)))
3773     result))
3774
3775 (defun gnus-sort-gathered-threads (threads)
3776   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3777   (let ((result threads))
3778     (while threads
3779       (when (stringp (caar threads))
3780         (setcdr (car threads)
3781                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3782       (setq threads (cdr threads)))
3783     result))
3784
3785 (defun gnus-thread-loop-p (root thread)
3786   "Say whether ROOT is in THREAD."
3787   (let ((stack (list thread))
3788         (infloop 0)
3789         th)
3790     (while (setq thread (pop stack))
3791       (setq th (cdr thread))
3792       (while (and th
3793                   (not (eq (caar th) root)))
3794         (pop th))
3795       (if th
3796           ;; We have found a loop.
3797           (let (ref-dep)
3798             (setcdr thread (delq (car th) (cdr thread)))
3799             (if (boundp (setq ref-dep (intern "none"
3800                                               gnus-newsgroup-dependencies)))
3801                 (setcdr (symbol-value ref-dep)
3802                         (nconc (cdr (symbol-value ref-dep))
3803                                (list (car th))))
3804               (set ref-dep (list nil (car th))))
3805             (setq infloop 1
3806                   stack nil))
3807         ;; Push all the subthreads onto the stack.
3808         (push (cdr thread) stack)))
3809     infloop))
3810
3811 (defun gnus-make-threads ()
3812   "Go through the dependency hashtb and find the roots.  Return all threads."
3813   (let (threads)
3814     (while (catch 'infloop
3815              (mapatoms
3816               (lambda (refs)
3817                 ;; Deal with self-referencing References loops.
3818                 (when (and (car (symbol-value refs))
3819                            (not (zerop
3820                                  (apply
3821                                   '+
3822                                   (mapcar
3823                                    (lambda (thread)
3824                                      (gnus-thread-loop-p
3825                                       (car (symbol-value refs)) thread))
3826                                    (cdr (symbol-value refs)))))))
3827                   (setq threads nil)
3828                   (throw 'infloop t))
3829                 (unless (car (symbol-value refs))
3830                   ;; These threads do not refer back to any other
3831                   ;; articles, so they're roots.
3832                   (setq threads (append (cdr (symbol-value refs)) threads))))
3833               gnus-newsgroup-dependencies)))
3834     threads))
3835
3836 ;; Build the thread tree.
3837 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3838   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3839
3840 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3841 if it was already present.
3842
3843 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3844 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3845 Message-IDs will be renamed to a unique Message-ID before being
3846 entered.
3847
3848 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3849   (let* ((id (mail-header-id header))
3850          (id-dep (and id (intern id dependencies)))
3851          parent-id ref ref-dep ref-header replaced)
3852     ;; Enter this `header' in the `dependencies' table.
3853     (cond
3854      ((not id-dep)
3855       (setq header nil))
3856      ;; The first two cases do the normal part: enter a new `header'
3857      ;; in the `dependencies' table.
3858      ((not (boundp id-dep))
3859       (set id-dep (list header)))
3860      ((null (car (symbol-value id-dep)))
3861       (setcar (symbol-value id-dep) header))
3862
3863      ;; From here the `header' was already present in the
3864      ;; `dependencies' table.
3865      (force-new
3866       ;; Overrides an existing entry;
3867       ;; just set the header part of the entry.
3868       (setcar (symbol-value id-dep) header)
3869       (setq replaced t))
3870
3871      ;; Renames the existing `header' to a unique Message-ID.
3872      ((not gnus-summary-ignore-duplicates)
3873       ;; An article with this Message-ID has already been seen.
3874       ;; We rename the Message-ID.
3875       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3876            (list header))
3877       (mail-header-set-id header id))
3878
3879      ;; The last case ignores an existing entry, except it adds any
3880      ;; additional Xrefs (in case the two articles came from different
3881      ;; servers.
3882      ;; Also sets `header' to `nil' meaning that the `dependencies'
3883      ;; table was *not* modified.
3884      (t
3885       (mail-header-set-xref
3886        (car (symbol-value id-dep))
3887        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3888                    "")
3889                (or (mail-header-xref header) "")))
3890       (setq header nil)))
3891
3892     (when (and header (not replaced))
3893       ;; First check that we are not creating a References loop.
3894       (setq parent-id (gnus-parent-id (mail-header-references header)))
3895       (setq ref parent-id)
3896       (while (and ref
3897                   (setq ref-dep (intern-soft ref dependencies))
3898                   (boundp ref-dep)
3899                   (setq ref-header (car (symbol-value ref-dep))))
3900         (if (string= id ref)
3901             ;; Yuk!  This is a reference loop.  Make the article be a
3902             ;; root article.
3903             (progn
3904               (mail-header-set-references (car (symbol-value id-dep)) "none")
3905               (setq ref nil)
3906               (setq parent-id nil))
3907           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
3908       (setq ref-dep (intern (or parent-id "none") dependencies))
3909       (if (boundp ref-dep)
3910           (setcdr (symbol-value ref-dep)
3911                   (nconc (cdr (symbol-value ref-dep))
3912                          (list (symbol-value id-dep))))
3913         (set ref-dep (list nil (symbol-value id-dep)))))
3914     header))
3915
3916 (defun gnus-extract-message-id-from-in-reply-to (string)
3917   (if (string-match "<[^>]+>" string)
3918       (substring string (match-beginning 0) (match-end 0))
3919     nil))
3920
3921 (defun gnus-build-sparse-threads ()
3922   (let ((headers gnus-newsgroup-headers)
3923         (mail-parse-charset gnus-newsgroup-charset)
3924         (gnus-summary-ignore-duplicates t)
3925         header references generation relations
3926         subject child end new-child date)
3927     ;; First we create an alist of generations/relations, where
3928     ;; generations is how much we trust the relation, and the relation
3929     ;; is parent/child.
3930     (gnus-message 7 "Making sparse threads...")
3931     (save-excursion
3932       (nnheader-set-temp-buffer " *gnus sparse threads*")
3933       (while (setq header (pop headers))
3934         (when (and (setq references (mail-header-references header))
3935                    (not (string= references "")))
3936           (insert references)
3937           (setq child (mail-header-id header)
3938                 subject (mail-header-subject header)
3939                 date (mail-header-date header)
3940                 generation 0)
3941           (while (search-backward ">" nil t)
3942             (setq end (1+ (point)))
3943             (when (search-backward "<" nil t)
3944               (setq new-child (buffer-substring (point) end))
3945               (push (list (incf generation)
3946                           child (setq child new-child)
3947                           subject date)
3948                     relations)))
3949           (when child
3950             (push (list (1+ generation) child nil subject) relations))
3951           (erase-buffer)))
3952       (kill-buffer (current-buffer)))
3953     ;; Sort over trustworthiness.
3954     (mapcar
3955      (lambda (relation)
3956        (when (gnus-dependencies-add-header
3957               (make-full-mail-header
3958                gnus-reffed-article-number
3959                (nth 3 relation) "" (or (nth 4 relation) "")
3960                (nth 1 relation)
3961                (or (nth 2 relation) "") 0 0 "")
3962               gnus-newsgroup-dependencies nil)
3963          (push gnus-reffed-article-number gnus-newsgroup-limit)
3964          (push gnus-reffed-article-number gnus-newsgroup-sparse)
3965          (push (cons gnus-reffed-article-number gnus-sparse-mark)
3966                gnus-newsgroup-reads)
3967          (decf gnus-reffed-article-number)))
3968      (sort relations 'car-less-than-car))
3969     (gnus-message 7 "Making sparse threads...done")))
3970
3971 (defun gnus-build-old-threads ()
3972   ;; Look at all the articles that refer back to old articles, and
3973   ;; fetch the headers for the articles that aren't there.  This will
3974   ;; build complete threads - if the roots haven't been expired by the
3975   ;; server, that is.
3976   (let ((mail-parse-charset gnus-newsgroup-charset)
3977         id heads)
3978     (mapatoms
3979      (lambda (refs)
3980        (when (not (car (symbol-value refs)))
3981          (setq heads (cdr (symbol-value refs)))
3982          (while heads
3983            (if (memq (mail-header-number (caar heads))
3984                      gnus-newsgroup-dormant)
3985                (setq heads (cdr heads))
3986              (setq id (symbol-name refs))
3987              (while (and (setq id (gnus-build-get-header id))
3988                          (not (car (gnus-id-to-thread id)))))
3989              (setq heads nil)))))
3990      gnus-newsgroup-dependencies)))
3991
3992 (defsubst gnus-remove-odd-characters (string)
3993   "Translate STRING into something that doesn't contain weird characters."
3994   (mm-subst-char-in-string
3995    ?\r ?\-
3996    (mm-subst-char-in-string ?\n ?\- string t) t))
3997
3998 ;; This function has to be called with point after the article number
3999 ;; on the beginning of the line.
4000 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4001   (let ((eol (point-at-eol))
4002         (buffer (current-buffer))
4003         header references in-reply-to)
4004
4005     ;; overview: [num subject from date id refs chars lines misc]
4006     (unwind-protect
4007         (let (x)
4008           (narrow-to-region (point) eol)
4009           (unless (eobp)
4010             (forward-char))
4011
4012           (setq header
4013                 (make-full-mail-header
4014                  number                 ; number
4015                  (condition-case ()     ; subject
4016                      (gnus-remove-odd-characters
4017                       (funcall gnus-decode-encoded-word-function
4018                                (setq x (nnheader-nov-field))))
4019                    (error x))
4020                  (condition-case ()     ; from
4021                      (gnus-remove-odd-characters
4022                       (funcall gnus-decode-encoded-word-function
4023                                (setq x (nnheader-nov-field))))
4024                    (error x))
4025                  (nnheader-nov-field)   ; date
4026                  (nnheader-nov-read-message-id) ; id
4027                  (setq references (nnheader-nov-field)) ; refs
4028                  (nnheader-nov-read-integer) ; chars
4029                  (nnheader-nov-read-integer) ; lines
4030                  (unless (eobp)
4031                    (if (looking-at "Xref: ")
4032                        (goto-char (match-end 0)))
4033                    (nnheader-nov-field)) ; Xref
4034                  (nnheader-nov-parse-extra)))) ; extra
4035
4036       (widen))
4037
4038     (when (and (string= references "")
4039                (setq in-reply-to (mail-header-extra header))
4040                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4041       (mail-header-set-references
4042        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4043
4044     (when gnus-alter-header-function
4045       (funcall gnus-alter-header-function header))
4046     (gnus-dependencies-add-header header dependencies force-new)))
4047
4048 (defun gnus-build-get-header (id)
4049   "Look through the buffer of NOV lines and find the header to ID.
4050 Enter this line into the dependencies hash table, and return
4051 the id of the parent article (if any)."
4052   (let ((deps gnus-newsgroup-dependencies)
4053         found header)
4054     (prog1
4055         (save-excursion
4056           (set-buffer nntp-server-buffer)
4057           (let ((case-fold-search nil))
4058             (goto-char (point-min))
4059             (while (and (not found)
4060                         (search-forward id nil t))
4061               (beginning-of-line)
4062               (setq found (looking-at
4063                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4064                                    (regexp-quote id))))
4065               (or found (beginning-of-line 2)))
4066             (when found
4067               (beginning-of-line)
4068               (and
4069                (setq header (gnus-nov-parse-line
4070                              (read (current-buffer)) deps))
4071                (gnus-parent-id (mail-header-references header))))))
4072       (when header
4073         (let ((number (mail-header-number header)))
4074           (push number gnus-newsgroup-limit)
4075           (push header gnus-newsgroup-headers)
4076           (if (memq number gnus-newsgroup-unselected)
4077               (progn
4078                 (setq gnus-newsgroup-unreads
4079                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4080                                                number))
4081                 (setq gnus-newsgroup-unselected
4082                       (delq number gnus-newsgroup-unselected)))
4083             (push number gnus-newsgroup-ancient)))))))
4084
4085 (defun gnus-build-all-threads ()
4086   "Read all the headers."
4087   (let ((gnus-summary-ignore-duplicates t)
4088         (mail-parse-charset gnus-newsgroup-charset)
4089         (dependencies gnus-newsgroup-dependencies)
4090         header article)
4091     (save-excursion
4092       (set-buffer nntp-server-buffer)
4093       (let ((case-fold-search nil))
4094         (goto-char (point-min))
4095         (while (not (eobp))
4096           (ignore-errors
4097             (setq article (read (current-buffer))
4098                   header (gnus-nov-parse-line article dependencies)))
4099           (when header
4100             (save-excursion
4101               (set-buffer gnus-summary-buffer)
4102               (push header gnus-newsgroup-headers)
4103               (if (memq (setq article (mail-header-number header))
4104                         gnus-newsgroup-unselected)
4105                   (progn
4106                     (setq gnus-newsgroup-unreads
4107                           (gnus-add-to-sorted-list
4108                            gnus-newsgroup-unreads article))
4109                     (setq gnus-newsgroup-unselected
4110                           (delq article gnus-newsgroup-unselected)))
4111                 (push article gnus-newsgroup-ancient)))
4112             (forward-line 1)))))))
4113
4114 (defun gnus-summary-update-article-line (article header)
4115   "Update the line for ARTICLE using HEADER."
4116   (let* ((id (mail-header-id header))
4117          (thread (gnus-id-to-thread id)))
4118     (unless thread
4119       (error "Article in no thread"))
4120     ;; Update the thread.
4121     (setcar thread header)
4122     (gnus-summary-goto-subject article)
4123     (let* ((datal (gnus-data-find-list article))
4124            (data (car datal))
4125            (buffer-read-only nil)
4126            (level (gnus-summary-thread-level)))
4127       (gnus-delete-line)
4128       (let ((inserted (- (point)
4129                          (progn
4130                            (gnus-summary-insert-line
4131                             header level nil
4132                             (memq article gnus-newsgroup-undownloaded)
4133                             (gnus-article-mark article)
4134                             (memq article gnus-newsgroup-replied)
4135                             (memq article gnus-newsgroup-expirable)
4136                             ;; Only insert the Subject string when it's different
4137                             ;; from the previous Subject string.
4138                             (if (and
4139                                  gnus-show-threads
4140                                  (gnus-subject-equal
4141                                   (condition-case ()
4142                                       (mail-header-subject
4143                                        (gnus-data-header
4144                                         (cadr
4145                                          (gnus-data-find-list
4146                                           article
4147                                           (gnus-data-list t)))))
4148                                     ;; Error on the side of excessive subjects.
4149                                     (error ""))
4150                                   (mail-header-subject header)))
4151                                 ""
4152                               (mail-header-subject header))
4153                             nil (cdr (assq article gnus-newsgroup-scored))
4154                             (memq article gnus-newsgroup-processable))
4155                            (point)))))
4156         (when (cdr datal)
4157           (gnus-data-update-list
4158            (cdr datal)
4159            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4160
4161 (defun gnus-summary-update-article (article &optional iheader)
4162   "Update ARTICLE in the summary buffer."
4163   (set-buffer gnus-summary-buffer)
4164   (let* ((header (gnus-summary-article-header article))
4165          (id (mail-header-id header))
4166          (data (gnus-data-find article))
4167          (thread (gnus-id-to-thread id))
4168          (references (mail-header-references header))
4169          (parent
4170           (gnus-id-to-thread
4171            (or (gnus-parent-id
4172                 (when (and references
4173                            (not (equal "" references)))
4174                   references))
4175                "none")))
4176          (buffer-read-only nil)
4177          (old (car thread)))
4178     (when thread
4179       (unless iheader
4180         (setcar thread nil)
4181         (when parent
4182           (delq thread parent)))
4183       (if (gnus-summary-insert-subject id header)
4184           ;; Set the (possibly) new article number in the data structure.
4185           (gnus-data-set-number data (gnus-id-to-article id))
4186         (setcar thread old)
4187         nil))))
4188
4189 (defun gnus-rebuild-thread (id &optional line)
4190   "Rebuild the thread containing ID.
4191 If LINE, insert the rebuilt thread starting on line LINE."
4192   (let ((buffer-read-only nil)
4193         old-pos current thread data)
4194     (if (not gnus-show-threads)
4195         (setq thread (list (car (gnus-id-to-thread id))))
4196       ;; Get the thread this article is part of.
4197       (setq thread (gnus-remove-thread id)))
4198     (setq old-pos (point-at-bol))
4199     (setq current (save-excursion
4200                     (and (re-search-backward "[\r\n]" nil t)
4201                          (gnus-summary-article-number))))
4202     ;; If this is a gathered thread, we have to go some re-gathering.
4203     (when (stringp (car thread))
4204       (let ((subject (car thread))
4205             roots thr)
4206         (setq thread (cdr thread))
4207         (while thread
4208           (unless (memq (setq thr (gnus-id-to-thread
4209                                    (gnus-root-id
4210                                     (mail-header-id (caar thread)))))
4211                         roots)
4212             (push thr roots))
4213           (setq thread (cdr thread)))
4214         ;; We now have all (unique) roots.
4215         (if (= (length roots) 1)
4216             ;; All the loose roots are now one solid root.
4217             (setq thread (car roots))
4218           (setq thread (cons subject (gnus-sort-threads roots))))))
4219     (let (threads)
4220       ;; We then insert this thread into the summary buffer.
4221       (when line
4222         (goto-char (point-min))
4223         (forward-line (1- line)))
4224       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4225         (if gnus-show-threads
4226             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4227           (gnus-summary-prepare-unthreaded thread))
4228         (setq data (nreverse gnus-newsgroup-data))
4229         (setq threads gnus-newsgroup-threads))
4230       ;; We splice the new data into the data structure.
4231       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4232       ;;!!! then we want to insert at the beginning of the buffer.
4233       ;;!!! That happens to be true with Gnus now, but that may
4234       ;;!!! change in the future.  Perhaps.
4235       (gnus-data-enter-list
4236        (if line nil current) data (- (point) old-pos))
4237       (setq gnus-newsgroup-threads
4238             (nconc threads gnus-newsgroup-threads))
4239       (gnus-data-compute-positions))))
4240
4241 (defun gnus-number-to-header (number)
4242   "Return the header for article NUMBER."
4243   (let ((headers gnus-newsgroup-headers))
4244     (while (and headers
4245                 (not (= number (mail-header-number (car headers)))))
4246       (pop headers))
4247     (when headers
4248       (car headers))))
4249
4250 (defun gnus-parent-headers (in-headers &optional generation)
4251   "Return the headers of the GENERATIONeth parent of HEADERS."
4252   (unless generation
4253     (setq generation 1))
4254   (let ((parent t)
4255         (headers in-headers)
4256         references)
4257     (while (and parent
4258                 (not (zerop generation))
4259                 (setq references (mail-header-references headers)))
4260       (setq headers (if (and references
4261                              (setq parent (gnus-parent-id references)))
4262                         (car (gnus-id-to-thread parent))
4263                       nil))
4264       (decf generation))
4265     (and (not (eq headers in-headers))
4266          headers)))
4267
4268 (defun gnus-id-to-thread (id)
4269   "Return the (sub-)thread where ID appears."
4270   (gnus-gethash id gnus-newsgroup-dependencies))
4271
4272 (defun gnus-id-to-article (id)
4273   "Return the article number of ID."
4274   (let ((thread (gnus-id-to-thread id)))
4275     (when (and thread
4276                (car thread))
4277       (mail-header-number (car thread)))))
4278
4279 (defun gnus-id-to-header (id)
4280   "Return the article headers of ID."
4281   (car (gnus-id-to-thread id)))
4282
4283 (defun gnus-article-displayed-root-p (article)
4284   "Say whether ARTICLE is a root(ish) article."
4285   (let ((level (gnus-summary-thread-level article))
4286         (refs (mail-header-references  (gnus-summary-article-header article)))
4287         particle)
4288     (cond
4289      ((null level) nil)
4290      ((zerop level) t)
4291      ((null refs) t)
4292      ((null (gnus-parent-id refs)) t)
4293      ((and (= 1 level)
4294            (null (setq particle (gnus-id-to-article
4295                                  (gnus-parent-id refs))))
4296            (null (gnus-summary-thread-level particle)))))))
4297
4298 (defun gnus-root-id (id)
4299   "Return the id of the root of the thread where ID appears."
4300   (let (last-id prev)
4301     (while (and id (setq prev (car (gnus-id-to-thread id))))
4302       (setq last-id id
4303             id (gnus-parent-id (mail-header-references prev))))
4304     last-id))
4305
4306 (defun gnus-articles-in-thread (thread)
4307   "Return the list of articles in THREAD."
4308   (cons (mail-header-number (car thread))
4309         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4310
4311 (defun gnus-remove-thread (id &optional dont-remove)
4312   "Remove the thread that has ID in it."
4313   (let (headers thread last-id)
4314     ;; First go up in this thread until we find the root.
4315     (setq last-id (gnus-root-id id)
4316           headers (message-flatten-list (gnus-id-to-thread last-id)))
4317     ;; We have now found the real root of this thread.  It might have
4318     ;; been gathered into some loose thread, so we have to search
4319     ;; through the threads to find the thread we wanted.
4320     (let ((threads gnus-newsgroup-threads)
4321           sub)
4322       (while threads
4323         (setq sub (car threads))
4324         (if (stringp (car sub))
4325             ;; This is a gathered thread, so we look at the roots
4326             ;; below it to find whether this article is in this
4327             ;; gathered root.
4328             (progn
4329               (setq sub (cdr sub))
4330               (while sub
4331                 (when (member (caar sub) headers)
4332                   (setq thread (car threads)
4333                         threads nil
4334                         sub nil))
4335                 (setq sub (cdr sub))))
4336           ;; It's an ordinary thread, so we check it.
4337           (when (eq (car sub) (car headers))
4338             (setq thread sub
4339                   threads nil)))
4340         (setq threads (cdr threads)))
4341       ;; If this article is in no thread, then it's a root.
4342       (if thread
4343           (unless dont-remove
4344             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4345         (setq thread (gnus-id-to-thread last-id)))
4346       (when thread
4347         (prog1
4348             thread                      ; We return this thread.
4349           (unless dont-remove
4350             (if (stringp (car thread))
4351                 (progn
4352                   ;; If we use dummy roots, then we have to remove the
4353                   ;; dummy root as well.
4354                   (when (eq gnus-summary-make-false-root 'dummy)
4355                     ;; We go to the dummy root by going to
4356                     ;; the first sub-"thread", and then one line up.
4357                     (gnus-summary-goto-article
4358                      (mail-header-number (caadr thread)))
4359                     (forward-line -1)
4360                     (gnus-delete-line)
4361                     (gnus-data-compute-positions))
4362                   (setq thread (cdr thread))
4363                   (while thread
4364                     (gnus-remove-thread-1 (car thread))
4365                     (setq thread (cdr thread))))
4366               (gnus-remove-thread-1 thread))))))))
4367
4368 (defun gnus-remove-thread-1 (thread)
4369   "Remove the thread THREAD recursively."
4370   (let ((number (mail-header-number (pop thread)))
4371         d)
4372     (setq thread (reverse thread))
4373     (while thread
4374       (gnus-remove-thread-1 (pop thread)))
4375     (when (setq d (gnus-data-find number))
4376       (goto-char (gnus-data-pos d))
4377       (gnus-summary-show-thread)
4378       (gnus-data-remove
4379        number
4380        (- (point-at-bol)
4381           (prog1
4382               (1+ (point-at-eol))
4383             (gnus-delete-line)))))))
4384
4385 (defun gnus-sort-threads-1 (threads func)
4386   (sort (mapcar (lambda (thread)
4387                   (cons (car thread)
4388                         (and (cdr thread)
4389                              (gnus-sort-threads-1 (cdr thread) func))))
4390                 threads) func))
4391
4392 (defun gnus-sort-threads (threads)
4393   "Sort THREADS."
4394   (if (not gnus-thread-sort-functions)
4395       threads
4396     (gnus-message 8 "Sorting threads...")
4397     (let ((max-lisp-eval-depth 5000))
4398       (prog1 (gnus-sort-threads-1
4399          threads
4400          (gnus-make-sort-function gnus-thread-sort-functions))
4401         (gnus-message 8 "Sorting threads...done")))))
4402
4403 (defun gnus-sort-articles (articles)
4404   "Sort ARTICLES."
4405   (when gnus-article-sort-functions
4406     (gnus-message 7 "Sorting articles...")
4407     (prog1
4408         (setq gnus-newsgroup-headers
4409               (sort articles (gnus-make-sort-function
4410                               gnus-article-sort-functions)))
4411       (gnus-message 7 "Sorting articles...done"))))
4412
4413 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4414 (defmacro gnus-thread-header (thread)
4415   "Return header of first article in THREAD.
4416 Note that THREAD must never, ever be anything else than a variable -
4417 using some other form will lead to serious barfage."
4418   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4419   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4420   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4421         (vector thread) 2))
4422
4423 (defsubst gnus-article-sort-by-number (h1 h2)
4424   "Sort articles by article number."
4425   (< (mail-header-number h1)
4426      (mail-header-number h2)))
4427
4428 (defun gnus-thread-sort-by-number (h1 h2)
4429   "Sort threads by root article number."
4430   (gnus-article-sort-by-number
4431    (gnus-thread-header h1) (gnus-thread-header h2)))
4432
4433 (defsubst gnus-article-sort-by-random (h1 h2)
4434   "Sort articles by article number."
4435   (zerop (random 2)))
4436
4437 (defun gnus-thread-sort-by-random (h1 h2)
4438   "Sort threads by root article number."
4439   (gnus-article-sort-by-random
4440    (gnus-thread-header h1) (gnus-thread-header h2)))
4441
4442 (defsubst gnus-article-sort-by-lines (h1 h2)
4443   "Sort articles by article Lines header."
4444   (< (mail-header-lines h1)
4445      (mail-header-lines h2)))
4446
4447 (defun gnus-thread-sort-by-lines (h1 h2)
4448   "Sort threads by root article Lines header."
4449   (gnus-article-sort-by-lines
4450    (gnus-thread-header h1) (gnus-thread-header h2)))
4451
4452 (defsubst gnus-article-sort-by-chars (h1 h2)
4453   "Sort articles by octet length."
4454   (< (mail-header-chars h1)
4455      (mail-header-chars h2)))
4456
4457 (defun gnus-thread-sort-by-chars (h1 h2)
4458   "Sort threads by root article octet length."
4459   (gnus-article-sort-by-chars
4460    (gnus-thread-header h1) (gnus-thread-header h2)))
4461
4462 (defsubst gnus-article-sort-by-author (h1 h2)
4463   "Sort articles by root author."
4464   (string-lessp
4465    (let ((extract (funcall
4466                    gnus-extract-address-components
4467                    (mail-header-from h1))))
4468      (or (car extract) (cadr extract) ""))
4469    (let ((extract (funcall
4470                    gnus-extract-address-components
4471                    (mail-header-from h2))))
4472      (or (car extract) (cadr extract) ""))))
4473
4474 (defun gnus-thread-sort-by-author (h1 h2)
4475   "Sort threads by root author."
4476   (gnus-article-sort-by-author
4477    (gnus-thread-header h1)  (gnus-thread-header h2)))
4478
4479 (defsubst gnus-article-sort-by-subject (h1 h2)
4480   "Sort articles by root subject."
4481   (string-lessp
4482    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4483    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4484
4485 (defun gnus-thread-sort-by-subject (h1 h2)
4486   "Sort threads by root subject."
4487   (gnus-article-sort-by-subject
4488    (gnus-thread-header h1) (gnus-thread-header h2)))
4489
4490 (defsubst gnus-article-sort-by-date (h1 h2)
4491   "Sort articles by root article date."
4492   (time-less-p
4493    (gnus-date-get-time (mail-header-date h1))
4494    (gnus-date-get-time (mail-header-date h2))))
4495
4496 (defun gnus-thread-sort-by-date (h1 h2)
4497   "Sort threads by root article date."
4498   (gnus-article-sort-by-date
4499    (gnus-thread-header h1) (gnus-thread-header h2)))
4500
4501 (defsubst gnus-article-sort-by-score (h1 h2)
4502   "Sort articles by root article score.
4503 Unscored articles will be counted as having a score of zero."
4504   (> (or (cdr (assq (mail-header-number h1)
4505                     gnus-newsgroup-scored))
4506          gnus-summary-default-score 0)
4507      (or (cdr (assq (mail-header-number h2)
4508                     gnus-newsgroup-scored))
4509          gnus-summary-default-score 0)))
4510
4511 (defun gnus-thread-sort-by-score (h1 h2)
4512   "Sort threads by root article score."
4513   (gnus-article-sort-by-score
4514    (gnus-thread-header h1) (gnus-thread-header h2)))
4515
4516 (defun gnus-thread-sort-by-total-score (h1 h2)
4517   "Sort threads by the sum of all scores in the thread.
4518 Unscored articles will be counted as having a score of zero."
4519   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4520
4521 (defun gnus-thread-total-score (thread)
4522   ;; This function find the total score of THREAD.
4523   (cond
4524    ((null thread)
4525     0)
4526    ((consp thread)
4527     (if (stringp (car thread))
4528         (apply gnus-thread-score-function 0
4529                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4530       (gnus-thread-total-score-1 thread)))
4531    (t
4532     (gnus-thread-total-score-1 (list thread)))))
4533
4534 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4535   "Sort threads such that the thread with the most recently arrived article comes first."
4536   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4537
4538 (defun gnus-thread-highest-number (thread)
4539   "Return the highest article number in THREAD."
4540   (apply 'max (mapcar (lambda (header)
4541                         (mail-header-number header))
4542                       (message-flatten-list thread))))
4543
4544 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4545   "Sort threads such that the thread with the most recently dated article comes first."
4546   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4547
4548 (defun gnus-thread-latest-date (thread)
4549   "Return the highest article date in THREAD."
4550   (let ((previous-time 0))
4551     (apply 'max
4552            (mapcar
4553             (lambda (header)
4554               (setq previous-time
4555                     (condition-case ()
4556                         (time-to-seconds (mail-header-parse-date
4557                                           (mail-header-date header)))
4558                       (error previous-time))))
4559             (sort
4560              (message-flatten-list thread)
4561              (lambda (h1 h2)
4562                (< (mail-header-number h1)
4563                   (mail-header-number h2))))))))
4564
4565 (defun gnus-thread-total-score-1 (root)
4566   ;; This function find the total score of the thread below ROOT.
4567   (setq root (car root))
4568   (apply gnus-thread-score-function
4569          (or (append
4570               (mapcar 'gnus-thread-total-score
4571                       (cdr (gnus-id-to-thread (mail-header-id root))))
4572               (when (> (mail-header-number root) 0)
4573                 (list (or (cdr (assq (mail-header-number root)
4574                                      gnus-newsgroup-scored))
4575                           gnus-summary-default-score 0))))
4576              (list gnus-summary-default-score)
4577              '(0))))
4578
4579 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4580 (defvar gnus-tmp-prev-subject nil)
4581 (defvar gnus-tmp-false-parent nil)
4582 (defvar gnus-tmp-root-expunged nil)
4583 (defvar gnus-tmp-dummy-line nil)
4584
4585 (eval-when-compile (defvar gnus-tmp-header))
4586 (defun gnus-extra-header (type &optional header)
4587   "Return the extra header of TYPE."
4588   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4589       ""))
4590
4591 (defvar gnus-tmp-thread-tree-header-string "")
4592
4593 (defcustom gnus-sum-thread-tree-root "> "
4594   "With %B spec, used for the root of a thread.
4595 If nil, use subject instead."
4596   :type '(radio (const :format "%v  " nil) (string :size 0))
4597   :group 'gnus-thread)
4598 (defcustom gnus-sum-thread-tree-false-root "> "
4599   "With %B spec, used for a false root of a thread.
4600 If nil, use subject instead."
4601   :type '(radio (const :format "%v  " nil) (string :size 0))
4602   :group 'gnus-thread)
4603 (defcustom gnus-sum-thread-tree-single-indent ""
4604   "With %B spec, used for a thread with just one message.
4605 If nil, use subject instead."
4606   :type '(radio (const :format "%v  " nil) (string :size 0))
4607   :group 'gnus-thread)
4608 (defcustom gnus-sum-thread-tree-vertical "| "
4609   "With %B spec, used for drawing a vertical line."
4610   :type 'string
4611   :group 'gnus-thread)
4612 (defcustom gnus-sum-thread-tree-indent "  "
4613   "With %B spec, used for indenting."
4614   :type 'string
4615   :group 'gnus-thread)
4616 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4617   "With %B spec, used for a leaf with brothers."
4618   :type 'string
4619   :group 'gnus-thread)
4620 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4621   "With %B spec, used for a leaf without brothers."
4622   :type 'string
4623   :group 'gnus-thread)
4624
4625 (defun gnus-summary-prepare-threads (threads)
4626   "Prepare summary buffer from THREADS and indentation LEVEL.
4627 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4628 or a straight list of headers."
4629   (gnus-message 7 "Generating summary...")
4630
4631   (setq gnus-newsgroup-threads threads)
4632   (beginning-of-line)
4633
4634   (let ((gnus-tmp-level 0)
4635         (default-score (or gnus-summary-default-score 0))
4636         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4637         (building-line-count gnus-summary-display-while-building)
4638         (building-count (integerp gnus-summary-display-while-building))
4639         thread number subject stack state gnus-tmp-gathered beg-match
4640         new-roots gnus-tmp-new-adopts thread-end simp-subject
4641         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4642         gnus-tmp-replied gnus-tmp-subject-or-nil
4643         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4644         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4645         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4646         tree-stack)
4647
4648     (setq gnus-tmp-prev-subject nil
4649           gnus-tmp-thread-tree-header-string "")
4650
4651     (if (vectorp (car threads))
4652         ;; If this is a straight (sic) list of headers, then a
4653         ;; threaded summary display isn't required, so we just create
4654         ;; an unthreaded one.
4655         (gnus-summary-prepare-unthreaded threads)
4656
4657       ;; Do the threaded display.
4658
4659       (if gnus-summary-display-while-building
4660           (switch-to-buffer (buffer-name)))
4661       (while (or threads stack gnus-tmp-new-adopts new-roots)
4662
4663         (if (and (= gnus-tmp-level 0)
4664                  (or (not stack)
4665                      (= (caar stack) 0))
4666                  (not gnus-tmp-false-parent)
4667                  (or gnus-tmp-new-adopts new-roots))
4668             (if gnus-tmp-new-adopts
4669                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4670                       thread (list (car gnus-tmp-new-adopts))
4671                       gnus-tmp-header (caar thread)
4672                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4673               (when new-roots
4674                 (setq thread (list (car new-roots))
4675                       gnus-tmp-header (caar thread)
4676                       new-roots (cdr new-roots))))
4677
4678           (if threads
4679               ;; If there are some threads, we do them before the
4680               ;; threads on the stack.
4681               (setq thread threads
4682                     gnus-tmp-header (caar thread))
4683             ;; There were no current threads, so we pop something off
4684             ;; the stack.
4685             (setq state (car stack)
4686                   gnus-tmp-level (car state)
4687                   tree-stack (cadr state)
4688                   thread (caddr state)
4689                   stack (cdr stack)
4690                   gnus-tmp-header (caar thread))))
4691
4692         (setq gnus-tmp-false-parent nil)
4693         (setq gnus-tmp-root-expunged nil)
4694         (setq thread-end nil)
4695
4696         (if (stringp gnus-tmp-header)
4697             ;; The header is a dummy root.
4698             (cond
4699              ((eq gnus-summary-make-false-root 'adopt)
4700               ;; We let the first article adopt the rest.
4701               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4702                                                (cddar thread)))
4703               (setq gnus-tmp-gathered
4704                     (nconc (mapcar
4705                             (lambda (h) (mail-header-number (car h)))
4706                             (cddar thread))
4707                            gnus-tmp-gathered))
4708               (setq thread (cons (list (caar thread)
4709                                        (cadar thread))
4710                                  (cdr thread)))
4711               (setq gnus-tmp-level -1
4712                     gnus-tmp-false-parent t))
4713              ((eq gnus-summary-make-false-root 'empty)
4714               ;; We print adopted articles with empty subject fields.
4715               (setq gnus-tmp-gathered
4716                     (nconc (mapcar
4717                             (lambda (h) (mail-header-number (car h)))
4718                             (cddar thread))
4719                            gnus-tmp-gathered))
4720               (setq gnus-tmp-level -1))
4721              ((eq gnus-summary-make-false-root 'dummy)
4722               ;; We remember that we probably want to output a dummy
4723               ;; root.
4724               (setq gnus-tmp-dummy-line gnus-tmp-header)
4725               (setq gnus-tmp-prev-subject gnus-tmp-header))
4726              (t
4727               ;; We do not make a root for the gathered
4728               ;; sub-threads at all.
4729               (setq gnus-tmp-level -1)))
4730
4731           (setq number (mail-header-number gnus-tmp-header)
4732                 subject (mail-header-subject gnus-tmp-header)
4733                 simp-subject (gnus-simplify-subject-fully subject))
4734
4735           (cond
4736            ;; If the thread has changed subject, we might want to make
4737            ;; this subthread into a root.
4738            ((and (null gnus-thread-ignore-subject)
4739                  (not (zerop gnus-tmp-level))
4740                  gnus-tmp-prev-subject
4741                  (not (string= gnus-tmp-prev-subject simp-subject)))
4742             (setq new-roots (nconc new-roots (list (car thread)))
4743                   thread-end t
4744                   gnus-tmp-header nil))
4745            ;; If the article lies outside the current limit,
4746            ;; then we do not display it.
4747            ((not (memq number gnus-newsgroup-limit))
4748             (setq gnus-tmp-gathered
4749                   (nconc (mapcar
4750                           (lambda (h) (mail-header-number (car h)))
4751                           (cdar thread))
4752                          gnus-tmp-gathered))
4753             (setq gnus-tmp-new-adopts (if (cdar thread)
4754                                           (append gnus-tmp-new-adopts
4755                                                   (cdar thread))
4756                                         gnus-tmp-new-adopts)
4757                   thread-end t
4758                   gnus-tmp-header nil)
4759             (when (zerop gnus-tmp-level)
4760               (setq gnus-tmp-root-expunged t)))
4761            ;; Perhaps this article is to be marked as read?
4762            ((and gnus-summary-mark-below
4763                  (< (or (cdr (assq number gnus-newsgroup-scored))
4764                         default-score)
4765                     gnus-summary-mark-below)
4766                  ;; Don't touch sparse articles.
4767                  (not (gnus-summary-article-sparse-p number))
4768                  (not (gnus-summary-article-ancient-p number)))
4769             (setq gnus-newsgroup-unreads
4770                   (delq number gnus-newsgroup-unreads))
4771             (if gnus-newsgroup-auto-expire
4772                 (setq gnus-newsgroup-expirable
4773                       (gnus-add-to-sorted-list
4774                        gnus-newsgroup-expirable number))
4775               (push (cons number gnus-low-score-mark)
4776                     gnus-newsgroup-reads))))
4777
4778           (when gnus-tmp-header
4779             ;; We may have an old dummy line to output before this
4780             ;; article.
4781             (when (and gnus-tmp-dummy-line
4782                        (gnus-subject-equal
4783                         gnus-tmp-dummy-line
4784                         (mail-header-subject gnus-tmp-header)))
4785               (gnus-summary-insert-dummy-line
4786                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4787               (setq gnus-tmp-dummy-line nil))
4788
4789             ;; Compute the mark.
4790             (setq gnus-tmp-unread (gnus-article-mark number))
4791
4792             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4793                                   gnus-tmp-header gnus-tmp-level)
4794                   gnus-newsgroup-data)
4795
4796             ;; Actually insert the line.
4797             (setq
4798              gnus-tmp-subject-or-nil
4799              (cond
4800               ((and gnus-thread-ignore-subject
4801                     gnus-tmp-prev-subject
4802                     (not (string= gnus-tmp-prev-subject simp-subject)))
4803                subject)
4804               ((zerop gnus-tmp-level)
4805                (if (and (eq gnus-summary-make-false-root 'empty)
4806                         (memq number gnus-tmp-gathered)
4807                         gnus-tmp-prev-subject
4808                         (string= gnus-tmp-prev-subject simp-subject))
4809                    gnus-summary-same-subject
4810                  subject))
4811               (t gnus-summary-same-subject)))
4812             (if (and (eq gnus-summary-make-false-root 'adopt)
4813                      (= gnus-tmp-level 1)
4814                      (memq number gnus-tmp-gathered))
4815                 (setq gnus-tmp-opening-bracket ?\<
4816                       gnus-tmp-closing-bracket ?\>)
4817               (setq gnus-tmp-opening-bracket ?\[
4818                     gnus-tmp-closing-bracket ?\]))
4819             (setq
4820              gnus-tmp-indentation
4821              (aref gnus-thread-indent-array gnus-tmp-level)
4822              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4823              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4824                                 gnus-summary-default-score 0)
4825              gnus-tmp-score-char
4826              (if (or (null gnus-summary-default-score)
4827                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4828                          gnus-summary-zcore-fuzz))
4829                  ?                      ;Whitespace
4830                (if (< gnus-tmp-score gnus-summary-default-score)
4831                    gnus-score-below-mark gnus-score-over-mark))
4832              gnus-tmp-replied
4833              (cond ((memq number gnus-newsgroup-processable)
4834                     gnus-process-mark)
4835                    ((memq number gnus-newsgroup-cached)
4836                     gnus-cached-mark)
4837                    ((memq number gnus-newsgroup-replied)
4838                     gnus-replied-mark)
4839                    ((memq number gnus-newsgroup-forwarded)
4840                     gnus-forwarded-mark)
4841                    ((memq number gnus-newsgroup-saved)
4842                     gnus-saved-mark)
4843                    ((memq number gnus-newsgroup-recent)
4844                     gnus-recent-mark)
4845                    ((memq number gnus-newsgroup-unseen)
4846                     gnus-unseen-mark)
4847                    (t gnus-no-mark))
4848              gnus-tmp-downloaded
4849              (cond ((memq number gnus-newsgroup-undownloaded)
4850                     gnus-undownloaded-mark)
4851                    (gnus-newsgroup-agentized
4852                     gnus-downloaded-mark)
4853                    (t
4854                     gnus-no-mark))
4855              gnus-tmp-from (mail-header-from gnus-tmp-header)
4856              gnus-tmp-name
4857              (cond
4858               ((string-match "<[^>]+> *$" gnus-tmp-from)
4859                (setq beg-match (match-beginning 0))
4860                (or (and (string-match "^\".+\"" gnus-tmp-from)
4861                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4862                    (substring gnus-tmp-from 0 beg-match)))
4863               ((string-match "(.+)" gnus-tmp-from)
4864                (substring gnus-tmp-from
4865                           (1+ (match-beginning 0)) (1- (match-end 0))))
4866               (t gnus-tmp-from))
4867
4868              ;; Do the %B string
4869              gnus-tmp-thread-tree-header-string
4870              (cond
4871               ((not gnus-show-threads) "")
4872               ((zerop gnus-tmp-level)
4873                (cond ((cdar thread)
4874                       (or gnus-sum-thread-tree-root subject))
4875                      (gnus-tmp-new-adopts
4876                       (or gnus-sum-thread-tree-false-root subject))
4877                      (t
4878                       (or gnus-sum-thread-tree-single-indent subject))))
4879               (t
4880                (concat (apply 'concat
4881                               (mapcar (lambda (item)
4882                                         (if (= item 1)
4883                                             gnus-sum-thread-tree-vertical
4884                                           gnus-sum-thread-tree-indent))
4885                                       (cdr (reverse tree-stack))))
4886                        (if (nth 1 thread)
4887                            gnus-sum-thread-tree-leaf-with-other
4888                          gnus-sum-thread-tree-single-leaf)))))
4889             (when (string= gnus-tmp-name "")
4890               (setq gnus-tmp-name gnus-tmp-from))
4891             (unless (numberp gnus-tmp-lines)
4892               (setq gnus-tmp-lines -1))
4893             (if (= gnus-tmp-lines -1)
4894                 (setq gnus-tmp-lines "?")
4895               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
4896               (gnus-put-text-property
4897              (point)
4898              (progn (eval gnus-summary-line-format-spec) (point))
4899                'gnus-number number)
4900             (when gnus-visual-p
4901               (forward-line -1)
4902               (gnus-run-hooks 'gnus-summary-update-hook)
4903               (forward-line 1))
4904
4905             (setq gnus-tmp-prev-subject simp-subject)))
4906
4907         (when (nth 1 thread)
4908           (push (list (max 0 gnus-tmp-level)
4909                       (copy-sequence tree-stack)
4910                       (nthcdr 1 thread))
4911                 stack))
4912         (push (if (nth 1 thread) 1 0) tree-stack)
4913         (incf gnus-tmp-level)
4914         (setq threads (if thread-end nil (cdar thread)))
4915         (if gnus-summary-display-while-building
4916             (if building-count
4917                 (progn
4918                   ;; use a set frequency
4919                   (setq building-line-count (1- building-line-count))
4920                   (when (= building-line-count 0)
4921                     (sit-for 0)
4922                     (setq building-line-count
4923                           gnus-summary-display-while-building)))
4924               ;; always
4925               (sit-for 0)))
4926         (unless threads
4927           (setq gnus-tmp-level 0)))))
4928   (gnus-message 7 "Generating summary...done"))
4929
4930 (defun gnus-summary-prepare-unthreaded (headers)
4931   "Generate an unthreaded summary buffer based on HEADERS."
4932   (let (header number mark)
4933
4934     (beginning-of-line)
4935
4936     (while headers
4937       ;; We may have to root out some bad articles...
4938       (when (memq (setq number (mail-header-number
4939                                 (setq header (pop headers))))
4940                   gnus-newsgroup-limit)
4941         ;; Mark article as read when it has a low score.
4942         (when (and gnus-summary-mark-below
4943                    (< (or (cdr (assq number gnus-newsgroup-scored))
4944                           gnus-summary-default-score 0)
4945                       gnus-summary-mark-below)
4946                    (not (gnus-summary-article-ancient-p number)))
4947           (setq gnus-newsgroup-unreads
4948                 (delq number gnus-newsgroup-unreads))
4949           (if gnus-newsgroup-auto-expire
4950               (push number gnus-newsgroup-expirable)
4951             (push (cons number gnus-low-score-mark)
4952                   gnus-newsgroup-reads)))
4953
4954         (setq mark (gnus-article-mark number))
4955         (push (gnus-data-make number mark (1+ (point)) header 0)
4956               gnus-newsgroup-data)
4957         (gnus-summary-insert-line
4958          header 0 number
4959          (memq number gnus-newsgroup-undownloaded)
4960          mark (memq number gnus-newsgroup-replied)
4961          (memq number gnus-newsgroup-expirable)
4962          (mail-header-subject header) nil
4963          (cdr (assq number gnus-newsgroup-scored))
4964          (memq number gnus-newsgroup-processable))))))
4965
4966 (defun gnus-summary-remove-list-identifiers ()
4967   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
4968   (let ((regexp (if (consp gnus-list-identifiers)
4969                     (mapconcat 'identity gnus-list-identifiers " *\\|")
4970                   gnus-list-identifiers))
4971         changed subject)
4972     (when regexp
4973       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
4974       (dolist (header gnus-newsgroup-headers)
4975         (setq subject (mail-header-subject header)
4976               changed nil)
4977         (while (string-match regexp subject)
4978           (setq subject
4979                 (concat (substring subject 0 (match-beginning 1))
4980                         (substring subject (match-end 0)))
4981                 changed t))
4982         (when changed
4983           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
4984             (setq subject
4985                   (concat (substring subject 0 (match-beginning 1))
4986                           (substring subject (match-end 1)))))
4987           (mail-header-set-subject header subject))))))
4988
4989 (defun gnus-fetch-headers (articles)
4990   "Fetch headers of ARTICLES."
4991   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
4992     (gnus-message 5 "Fetching headers for %s..." name)
4993     (prog1
4994         (if (eq 'nov
4995                 (setq gnus-headers-retrieved-by
4996                       (gnus-retrieve-headers
4997                        articles gnus-newsgroup-name
4998                        ;; We might want to fetch old headers, but
4999                        ;; not if there is only 1 article.
5000                        (and (or (and
5001                                  (not (eq gnus-fetch-old-headers 'some))
5002                                  (not (numberp gnus-fetch-old-headers)))
5003                                 (> (length articles) 1))
5004                             gnus-fetch-old-headers))))
5005             (gnus-get-newsgroup-headers-xover
5006              articles nil nil gnus-newsgroup-name t)
5007           (gnus-get-newsgroup-headers))
5008       (gnus-message 5 "Fetching headers for %s...done" name))))
5009
5010 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5011   "Select newsgroup GROUP.
5012 If READ-ALL is non-nil, all articles in the group are selected.
5013 If SELECT-ARTICLES, only select those articles from GROUP."
5014   (let* ((entry (gnus-group-entry group))
5015          ;;!!! Dirty hack; should be removed.
5016          (gnus-summary-ignore-duplicates
5017           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5018               t
5019             gnus-summary-ignore-duplicates))
5020          (info (nth 2 entry))
5021          articles fetched-articles cached)
5022
5023     (unless (gnus-check-server
5024              (set (make-local-variable 'gnus-current-select-method)
5025                   (gnus-find-method-for-group group)))
5026       (error "Couldn't open server"))
5027
5028     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5029         (gnus-activate-group group)     ; Or we can activate it...
5030         (progn                          ; Or we bug out.
5031           (when (equal major-mode 'gnus-summary-mode)
5032             (gnus-kill-buffer (current-buffer)))
5033           (error "Couldn't activate group %s: %s"
5034                  group (gnus-status-message group))))
5035
5036     (unless (gnus-request-group group t)
5037       (when (equal major-mode 'gnus-summary-mode)
5038         (gnus-kill-buffer (current-buffer)))
5039       (error "Couldn't request group %s: %s"
5040              group (gnus-status-message group)))
5041
5042     (when gnus-agent
5043       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5044       
5045       (setq gnus-summary-use-undownloaded-faces
5046             (gnus-agent-find-parameter
5047              group
5048              'agent-enable-undownloaded-faces)))
5049
5050     (setq gnus-newsgroup-name group
5051           gnus-newsgroup-unselected nil
5052           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5053
5054     (let ((display (gnus-group-find-parameter group 'display)))
5055       (setq gnus-newsgroup-display
5056             (cond
5057              ((not (zerop (or (car-safe read-all) 0)))
5058               ;; The user entered the group with C-u SPC/RET, let's show
5059               ;; all articles.
5060               'gnus-not-ignore)
5061              ((eq display 'all)
5062               'gnus-not-ignore)
5063              ((arrayp display)
5064               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5065              ((numberp display)
5066               ;; The following is probably the "correct" solution, but
5067               ;; it makes Gnus fetch all headers and then limit the
5068               ;; articles (which is slow), so instead we hack the
5069               ;; select-articles parameter instead. -- Simon Josefsson
5070               ;; <jas@kth.se>
5071               ;;
5072               ;; (gnus-byte-compile
5073               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5074               ;;                         display)))))
5075               (setq select-articles
5076                     (gnus-uncompress-range
5077                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5078                              (if (> tmp 0)
5079                                  tmp
5080                                1))
5081                            (cdr (gnus-active group)))))
5082               nil)
5083              (t
5084               nil))))
5085
5086     (gnus-summary-setup-default-charset)
5087
5088     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5089     (when (gnus-virtual-group-p group)
5090       (setq cached gnus-newsgroup-cached))
5091
5092     (setq gnus-newsgroup-unreads
5093           (gnus-sorted-ndifference
5094            (gnus-sorted-ndifference gnus-newsgroup-unreads
5095                                     gnus-newsgroup-marked)
5096            gnus-newsgroup-dormant))
5097
5098     (setq gnus-newsgroup-processable nil)
5099
5100     (gnus-update-read-articles group gnus-newsgroup-unreads)
5101
5102     ;; Adjust and set lists of article marks.
5103     (when info
5104       (gnus-adjust-marked-articles info))
5105     (if (setq articles select-articles)
5106         (setq gnus-newsgroup-unselected
5107               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5108       (setq articles (gnus-articles-to-read group read-all)))
5109
5110     (cond
5111      ((null articles)
5112       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5113       'quit)
5114      ((eq articles 0) nil)
5115      (t
5116       ;; Init the dependencies hash table.
5117       (setq gnus-newsgroup-dependencies
5118             (gnus-make-hashtable (length articles)))
5119       (gnus-set-global-variables)
5120       ;; Retrieve the headers and read them in.
5121
5122       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5123
5124       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5125       (when cached
5126         (setq gnus-newsgroup-cached cached))
5127
5128       ;; Suppress duplicates?
5129       (when gnus-suppress-duplicates
5130         (gnus-dup-suppress-articles))
5131
5132       ;; Set the initial limit.
5133       (setq gnus-newsgroup-limit (copy-sequence articles))
5134       ;; Remove canceled articles from the list of unread articles.
5135       (setq fetched-articles
5136             (mapcar (lambda (headers) (mail-header-number headers))
5137                     gnus-newsgroup-headers))
5138       (setq gnus-newsgroup-articles fetched-articles)
5139       (setq gnus-newsgroup-unreads
5140             (gnus-sorted-nintersection
5141              gnus-newsgroup-unreads fetched-articles))
5142       (gnus-compute-unseen-list)
5143
5144       ;; Removed marked articles that do not exist.
5145       (gnus-update-missing-marks
5146        (gnus-sorted-difference articles fetched-articles))
5147       ;; We might want to build some more threads first.
5148       (when (and gnus-fetch-old-headers
5149                  (eq gnus-headers-retrieved-by 'nov))
5150         (if (eq gnus-fetch-old-headers 'invisible)
5151             (gnus-build-all-threads)
5152           (gnus-build-old-threads)))
5153       ;; Let the Gnus agent mark articles as read.
5154       (when gnus-agent
5155         (gnus-agent-get-undownloaded-list))
5156       ;; Remove list identifiers from subject
5157       (when gnus-list-identifiers
5158         (gnus-summary-remove-list-identifiers))
5159       ;; Check whether auto-expire is to be done in this group.
5160       (setq gnus-newsgroup-auto-expire
5161             (gnus-group-auto-expirable-p group))
5162       ;; Set up the article buffer now, if necessary.
5163       (unless gnus-single-article-buffer
5164         (gnus-article-setup-buffer))
5165       ;; First and last article in this newsgroup.
5166       (when gnus-newsgroup-headers
5167         (setq gnus-newsgroup-begin
5168               (mail-header-number (car gnus-newsgroup-headers))
5169               gnus-newsgroup-end
5170               (mail-header-number
5171                (gnus-last-element gnus-newsgroup-headers))))
5172       ;; GROUP is successfully selected.
5173       (or gnus-newsgroup-headers t)))))
5174
5175 (defun gnus-compute-unseen-list ()
5176   ;; The `seen' marks are treated specially.
5177   (if (not gnus-newsgroup-seen)
5178       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5179     (setq gnus-newsgroup-unseen
5180           (gnus-inverse-list-range-intersection
5181            gnus-newsgroup-articles gnus-newsgroup-seen))))
5182
5183 (defun gnus-summary-display-make-predicate (display)
5184   (require 'gnus-agent)
5185   (when (= (length display) 1)
5186     (setq display (car display)))
5187   (unless gnus-summary-display-cache
5188     (dolist (elem (append '((unread . unread)
5189                             (read . read)
5190                             (unseen . unseen))
5191                           gnus-article-mark-lists))
5192       (push (cons (cdr elem)
5193                   (gnus-byte-compile
5194                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5195             gnus-summary-display-cache)))
5196   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5197         (gnus-category-predicate-cache gnus-summary-display-cache))
5198     (gnus-get-predicate display)))
5199
5200 ;; Uses the dynamically bound `number' variable.
5201 (eval-when-compile
5202   (defvar number))
5203 (defun gnus-article-marked-p (type &optional article)
5204   (let ((article (or article number)))
5205     (cond
5206      ((eq type 'tick)
5207       (memq article gnus-newsgroup-marked))
5208      ((eq type 'spam)
5209       (memq article gnus-newsgroup-spam-marked))
5210      ((eq type 'unsend)
5211       (memq article gnus-newsgroup-unsendable))
5212      ((eq type 'undownload)
5213       (memq article gnus-newsgroup-undownloaded))
5214      ((eq type 'download)
5215       (memq article gnus-newsgroup-downloadable))
5216      ((eq type 'unread)
5217       (memq article gnus-newsgroup-unreads))
5218      ((eq type 'read)
5219       (memq article gnus-newsgroup-reads))
5220      ((eq type 'dormant)
5221       (memq article gnus-newsgroup-dormant) )
5222      ((eq type 'expire)
5223       (memq article gnus-newsgroup-expirable))
5224      ((eq type 'reply)
5225       (memq article gnus-newsgroup-replied))
5226      ((eq type 'killed)
5227       (memq article gnus-newsgroup-killed))
5228      ((eq type 'bookmark)
5229       (assq article gnus-newsgroup-bookmarks))
5230      ((eq type 'score)
5231       (assq article gnus-newsgroup-scored))
5232      ((eq type 'save)
5233       (memq article gnus-newsgroup-saved))
5234      ((eq type 'cache)
5235       (memq article gnus-newsgroup-cached))
5236      ((eq type 'forward)
5237       (memq article gnus-newsgroup-forwarded))
5238      ((eq type 'seen)
5239       (not (memq article gnus-newsgroup-unseen)))
5240      ((eq type 'recent)
5241       (memq article gnus-newsgroup-recent))
5242      (t t))))
5243
5244 (defun gnus-articles-to-read (group &optional read-all)
5245   "Find out what articles the user wants to read."
5246   (let* ((display (gnus-group-find-parameter group 'display))
5247          (articles
5248           ;; Select all articles if `read-all' is non-nil, or if there
5249           ;; are no unread articles.
5250           (if (or read-all
5251                   (and (zerop (length gnus-newsgroup-marked))
5252                        (zerop (length gnus-newsgroup-unreads)))
5253                   ;; Fetch all if the predicate is non-nil.
5254                   gnus-newsgroup-display)
5255               ;; We want to select the headers for all the articles in
5256               ;; the group, so we select either all the active
5257               ;; articles in the group, or (if that's nil), the
5258               ;; articles in the cache.
5259               (or
5260                (gnus-uncompress-range (gnus-active group))
5261                (gnus-cache-articles-in-group group))
5262             ;; Select only the "normal" subset of articles.
5263             (gnus-sorted-nunion
5264              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5265              gnus-newsgroup-unreads)))
5266          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5267          (scored (length scored-list))
5268          (number (length articles))
5269          (marked (+ (length gnus-newsgroup-marked)
5270                     (length gnus-newsgroup-dormant)))
5271          (select
5272           (cond
5273            ((numberp read-all)
5274             read-all)
5275            ((numberp gnus-newsgroup-display)
5276             gnus-newsgroup-display)
5277            (t
5278             (condition-case ()
5279                 (cond
5280                  ((and (or (<= scored marked) (= scored number))
5281                        (numberp gnus-large-newsgroup)
5282                        (> number gnus-large-newsgroup))
5283                   (let* ((cursor-in-echo-area nil)
5284                          (initial (gnus-parameter-large-newsgroup-initial
5285                                    gnus-newsgroup-name))
5286                          (input
5287                           (read-string
5288                            (format
5289                             "How many articles from %s (%s %d): "
5290                             (gnus-limit-string
5291                              (gnus-group-decoded-name gnus-newsgroup-name)
5292                              35)
5293                             (if initial "max" "default")
5294                             number)
5295                            (if initial
5296                                (cons (number-to-string initial)
5297                                      0)))))
5298                     (if (string-match "^[ \t]*$" input) number input)))
5299                  ((and (> scored marked) (< scored number)
5300                        (> (- scored number) 20))
5301                   (let ((input
5302                          (read-string
5303                           (format "%s %s (%d scored, %d total): "
5304                                   "How many articles from"
5305                                   (gnus-group-decoded-name group)
5306                                   scored number))))
5307                     (if (string-match "^[ \t]*$" input)
5308                         number input)))
5309                  (t number))
5310               (quit
5311                (message "Quit getting the articles to read")
5312                nil))))))
5313     (setq select (if (stringp select) (string-to-number select) select))
5314     (if (or (null select) (zerop select))
5315         select
5316       (if (and (not (zerop scored)) (<= (abs select) scored))
5317           (progn
5318             (setq articles (sort scored-list '<))
5319             (setq number (length articles)))
5320         (setq articles (copy-sequence articles)))
5321
5322       (when (< (abs select) number)
5323         (if (< select 0)
5324             ;; Select the N oldest articles.
5325             (setcdr (nthcdr (1- (abs select)) articles) nil)
5326           ;; Select the N most recent articles.
5327           (setq articles (nthcdr (- number select) articles))))
5328       (setq gnus-newsgroup-unselected
5329             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5330       (when gnus-alter-articles-to-read-function
5331         (setq articles
5332               (sort
5333                (funcall gnus-alter-articles-to-read-function
5334                         gnus-newsgroup-name articles)
5335                '<)))
5336       articles)))
5337
5338 (defun gnus-killed-articles (killed articles)
5339   (let (out)
5340     (while articles
5341       (when (inline (gnus-member-of-range (car articles) killed))
5342         (push (car articles) out))
5343       (setq articles (cdr articles)))
5344     out))
5345
5346 (defun gnus-uncompress-marks (marks)
5347   "Uncompress the mark ranges in MARKS."
5348   (let ((uncompressed '(score bookmark))
5349         out)
5350     (while marks
5351       (if (memq (caar marks) uncompressed)
5352           (push (car marks) out)
5353         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5354       (setq marks (cdr marks)))
5355     out))
5356
5357 (defun gnus-article-mark-to-type (mark)
5358   "Return the type of MARK."
5359   (or (cadr (assq mark gnus-article-special-mark-lists))
5360       'list))
5361
5362 (defun gnus-article-unpropagatable-p (mark)
5363   "Return whether MARK should be propagated to back end."
5364   (memq mark gnus-article-unpropagated-mark-lists))
5365
5366 (defun gnus-adjust-marked-articles (info)
5367   "Set all article lists and remove all marks that are no longer valid."
5368   (let* ((marked-lists (gnus-info-marks info))
5369          (active (gnus-active (gnus-info-group info)))
5370          (min (car active))
5371          (max (cdr active))
5372          (types gnus-article-mark-lists)
5373          marks var articles article mark mark-type
5374          bgn end)
5375
5376     (dolist (marks marked-lists)
5377       (setq mark (car marks)
5378             mark-type (gnus-article-mark-to-type mark)
5379             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5380
5381       ;; We set the variable according to the type of the marks list,
5382       ;; and then adjust the marks to a subset of the active articles.
5383       (cond
5384        ;; Adjust "simple" lists - compressed yet unsorted
5385        ((eq mark-type 'list)
5386         ;; Simultaneously uncompress and clip to active range
5387         ;; See gnus-uncompress-range for a description of possible marks
5388         (let (l lh)
5389           (if (not (cadr marks))
5390               (set var nil)
5391             (setq articles (if (numberp (cddr marks))
5392                                (list (cdr marks))
5393                              (cdr marks))
5394                   lh (cons nil nil)
5395                   l lh)
5396
5397             (while (setq article (pop articles))
5398               (cond ((consp article)
5399                      (setq bgn (max (car article) min)
5400                            end (min (cdr article) max))
5401                      (while (<= bgn end)
5402                        (setq l (setcdr l (cons bgn nil))
5403                              bgn (1+ bgn))))
5404                     ((and (<= min article)
5405                           (>= max article))
5406                      (setq l (setcdr l (cons article nil))))))
5407             (set var (cdr lh)))))
5408        ;; Adjust assocs.
5409        ((eq mark-type 'tuple)
5410         (set var (setq articles (cdr marks)))
5411         (when (not (listp (cdr (symbol-value var))))
5412           (set var (list (symbol-value var))))
5413         (when (not (listp (cdr articles)))
5414           (setq articles (list articles)))
5415         (while articles
5416           (when (or (not (consp (setq article (pop articles))))
5417                     (< (car article) min)
5418                     (> (car article) max))
5419             (set var (delq article (symbol-value var))))))
5420        ;; Adjust ranges (sloppily).
5421        ((eq mark-type 'range)
5422         (cond
5423          ((eq mark 'seen)
5424           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5425           ;; It should be (seen (NUM1 . NUM2)).
5426           (when (numberp (cddr marks))
5427             (setcdr marks (list (cdr marks))))
5428           (setq articles (cdr marks))
5429           (while (and articles
5430                       (or (and (consp (car articles))
5431                                (> min (cdar articles)))
5432                           (and (numberp (car articles))
5433                                (> min (car articles)))))
5434             (pop articles))
5435           (set var articles))))))))
5436
5437 (defun gnus-update-missing-marks (missing)
5438   "Go through the list of MISSING articles and remove them from the mark lists."
5439   (when missing
5440     (let (var m)
5441       ;; Go through all types.
5442       (dolist (elem gnus-article-mark-lists)
5443         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5444           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5445           (when (symbol-value var)
5446             ;; This list has articles.  So we delete all missing
5447             ;; articles from it.
5448             (setq m missing)
5449             (while m
5450               (set var (delq (pop m) (symbol-value var))))))))))
5451
5452 (defun gnus-update-marks ()
5453   "Enter the various lists of marked articles into the newsgroup info list."
5454   (let ((types gnus-article-mark-lists)
5455         (info (gnus-get-info gnus-newsgroup-name))
5456         type list newmarked symbol delta-marks)
5457     (when info
5458       ;; Add all marks lists to the list of marks lists.
5459       (while (setq type (pop types))
5460         (setq list (symbol-value
5461                     (setq symbol
5462                           (intern (format "gnus-newsgroup-%s" (car type))))))
5463
5464         (when list
5465           ;; Get rid of the entries of the articles that have the
5466           ;; default score.
5467           (when (and (eq (cdr type) 'score)
5468                      gnus-save-score
5469                      list)
5470             (let* ((arts list)
5471                    (prev (cons nil list))
5472                    (all prev))
5473               (while arts
5474                 (if (or (not (consp (car arts)))
5475                         (= (cdar arts) gnus-summary-default-score))
5476                     (setcdr prev (cdr arts))
5477                   (setq prev arts))
5478                 (setq arts (cdr arts)))
5479               (setq list (cdr all)))))
5480
5481         (when (eq (cdr type) 'seen)
5482           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5483
5484         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5485           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5486
5487         (when (and (gnus-check-backend-function
5488                     'request-set-mark gnus-newsgroup-name)
5489                    (not (gnus-article-unpropagatable-p (cdr type))))
5490           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5491                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5492                  (add (gnus-remove-from-range
5493                        (gnus-copy-sequence list) old)))
5494             (when add
5495               (push (list add 'add (list (cdr type))) delta-marks))
5496             (when del
5497               (push (list del 'del (list (cdr type))) delta-marks))))
5498
5499         (when list
5500           (push (cons (cdr type) list) newmarked)))
5501
5502       (when delta-marks
5503         (unless (gnus-check-group gnus-newsgroup-name)
5504           (error "Can't open server for %s" gnus-newsgroup-name))
5505         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5506
5507       ;; Enter these new marks into the info of the group.
5508       (if (nthcdr 3 info)
5509           (setcar (nthcdr 3 info) newmarked)
5510         ;; Add the marks lists to the end of the info.
5511         (when newmarked
5512           (setcdr (nthcdr 2 info) (list newmarked))))
5513
5514       ;; Cut off the end of the info if there's nothing else there.
5515       (let ((i 5))
5516         (while (and (> i 2)
5517                     (not (nth i info)))
5518           (when (nthcdr (decf i) info)
5519             (setcdr (nthcdr i info) nil)))))))
5520
5521 (defun gnus-set-mode-line (where)
5522   "Set the mode line of the article or summary buffers.
5523 If WHERE is `summary', the summary mode line format will be used."
5524   ;; Is this mode line one we keep updated?
5525   (when (and (memq where gnus-updated-mode-lines)
5526              (symbol-value
5527               (intern (format "gnus-%s-mode-line-format-spec" where))))
5528     (let (mode-string)
5529       (save-excursion
5530         ;; We evaluate this in the summary buffer since these
5531         ;; variables are buffer-local to that buffer.
5532         (set-buffer gnus-summary-buffer)
5533        ;; We bind all these variables that are used in the `eval' form
5534         ;; below.
5535         (let* ((mformat (symbol-value
5536                          (intern
5537                           (format "gnus-%s-mode-line-format-spec" where))))
5538                (gnus-tmp-group-name (gnus-group-decoded-name
5539                                      gnus-newsgroup-name))
5540                (gnus-tmp-article-number (or gnus-current-article 0))
5541                (gnus-tmp-unread gnus-newsgroup-unreads)
5542                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5543                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5544                (gnus-tmp-unread-and-unselected
5545                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5546                             (zerop gnus-tmp-unselected))
5547                        "")
5548                       ((zerop gnus-tmp-unselected)
5549                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5550                       (t (format "{%d(+%d) more}"
5551                                  gnus-tmp-unread-and-unticked
5552                                  gnus-tmp-unselected))))
5553                (gnus-tmp-subject
5554                 (if (and gnus-current-headers
5555                          (vectorp gnus-current-headers))
5556                     (gnus-mode-string-quote
5557                      (mail-header-subject gnus-current-headers))
5558                   ""))
5559                bufname-length max-len
5560                gnus-tmp-header) ;; passed as argument to any user-format-funcs
5561           (setq mode-string (eval mformat))
5562           (setq bufname-length (if (string-match "%b" mode-string)
5563                                    (- (length
5564                                        (buffer-name
5565                                         (if (eq where 'summary)
5566                                             nil
5567                                           (get-buffer gnus-article-buffer))))
5568                                       2)
5569                                  0))
5570           (setq max-len (max 4 (if gnus-mode-non-string-length
5571                                    (- (window-width)
5572                                       gnus-mode-non-string-length
5573                                       bufname-length)
5574                                  (length mode-string))))
5575           ;; We might have to chop a bit of the string off...
5576           (when (> (length mode-string) max-len)
5577             (setq mode-string
5578                   (concat (truncate-string-to-width mode-string (- max-len 3))
5579                           "...")))
5580           ;; Pad the mode string a bit.
5581           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5582       ;; Update the mode line.
5583       (setq mode-line-buffer-identification
5584             (gnus-mode-line-buffer-identification (list mode-string)))
5585       (set-buffer-modified-p t))))
5586
5587 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5588   "Go through the HEADERS list and add all Xrefs to a hash table.
5589 The resulting hash table is returned, or nil if no Xrefs were found."
5590   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5591          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5592          (xref-hashtb (gnus-make-hashtable))
5593          start group entry number xrefs header)
5594     (while headers
5595       (setq header (pop headers))
5596       (when (and (setq xrefs (mail-header-xref header))
5597                  (not (memq (setq number (mail-header-number header))
5598                             unreads)))
5599         (setq start 0)
5600         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5601           (setq start (match-end 0))
5602           (setq group (if prefix
5603                           (concat prefix (substring xrefs (match-beginning 1)
5604                                                     (match-end 1)))
5605                         (substring xrefs (match-beginning 1) (match-end 1))))
5606           (setq number
5607                 (string-to-int (substring xrefs (match-beginning 2)
5608                                           (match-end 2))))
5609           (if (setq entry (gnus-gethash group xref-hashtb))
5610               (setcdr entry (cons number (cdr entry)))
5611             (gnus-sethash group (cons number nil) xref-hashtb)))))
5612     (and start xref-hashtb)))
5613
5614 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5615   "Look through all the headers and mark the Xrefs as read."
5616   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5617         name info xref-hashtb idlist method nth4)
5618     (save-excursion
5619       (set-buffer gnus-group-buffer)
5620       (when (setq xref-hashtb
5621                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5622         (mapatoms
5623          (lambda (group)
5624            (unless (string= from-newsgroup (setq name (symbol-name group)))
5625              (setq idlist (symbol-value group))
5626              ;; Dead groups are not updated.
5627              (and (prog1
5628                       (setq info (gnus-get-info name))
5629                     (when (stringp (setq nth4 (gnus-info-method info)))
5630                       (setq nth4 (gnus-server-to-method nth4))))
5631                   ;; Only do the xrefs if the group has the same
5632                   ;; select method as the group we have just read.
5633                   (or (gnus-methods-equal-p
5634                        nth4 (gnus-find-method-for-group from-newsgroup))
5635                       virtual
5636                       (equal nth4 (setq method (gnus-find-method-for-group
5637                                                 from-newsgroup)))
5638                       (and (equal (car nth4) (car method))
5639                            (equal (nth 1 nth4) (nth 1 method))))
5640                   gnus-use-cross-reference
5641                   (or (not (eq gnus-use-cross-reference t))
5642                       virtual
5643                       ;; Only do cross-references on subscribed
5644                       ;; groups, if that is what is wanted.
5645                       (<= (gnus-info-level info) gnus-level-subscribed))
5646                   (gnus-group-make-articles-read name idlist))))
5647          xref-hashtb)))))
5648
5649 (defun gnus-compute-read-articles (group articles)
5650   (let* ((entry (gnus-group-entry group))
5651          (info (nth 2 entry))
5652          (active (gnus-active group))
5653          ninfo)
5654     (when entry
5655       ;; First peel off all invalid article numbers.
5656       (when active
5657         (let ((ids articles)
5658               id first)
5659           (while (setq id (pop ids))
5660             (when (and first (> id (cdr active)))
5661               ;; We'll end up in this situation in one particular
5662               ;; obscure situation.  If you re-scan a group and get
5663               ;; a new article that is cross-posted to a different
5664               ;; group that has not been re-scanned, you might get
5665               ;; crossposted article that has a higher number than
5666               ;; Gnus believes possible.  So we re-activate this
5667               ;; group as well.  This might mean doing the
5668               ;; crossposting thingy will *increase* the number
5669               ;; of articles in some groups.  Tsk, tsk.
5670               (setq active (or (gnus-activate-group group) active)))
5671             (when (or (> id (cdr active))
5672                       (< id (car active)))
5673               (setq articles (delq id articles))))))
5674       ;; If the read list is nil, we init it.
5675       (if (and active
5676                (null (gnus-info-read info))
5677                (> (car active) 1))
5678           (setq ninfo (cons 1 (1- (car active))))
5679         (setq ninfo (gnus-info-read info)))
5680       ;; Then we add the read articles to the range.
5681       (gnus-add-to-range
5682        ninfo (setq articles (sort articles '<))))))
5683
5684 (defun gnus-group-make-articles-read (group articles)
5685   "Update the info of GROUP to say that ARTICLES are read."
5686   (let* ((num 0)
5687          (entry (gnus-group-entry group))
5688          (info (nth 2 entry))
5689          (active (gnus-active group))
5690          range)
5691     (when entry
5692       (setq range (gnus-compute-read-articles group articles))
5693       (with-current-buffer gnus-group-buffer
5694         (gnus-undo-register
5695           `(progn
5696              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5697              (gnus-info-set-read ',info ',(gnus-info-read info))
5698              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5699              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5700              (gnus-group-update-group ,group t))))
5701       ;; Add the read articles to the range.
5702       (gnus-info-set-read info range)
5703       (gnus-request-set-mark group (list (list range 'add '(read))))
5704       ;; Then we have to re-compute how many unread
5705       ;; articles there are in this group.
5706       (when active
5707         (cond
5708          ((not range)
5709           (setq num (- (1+ (cdr active)) (car active))))
5710          ((not (listp (cdr range)))
5711           (setq num (- (cdr active) (- (1+ (cdr range))
5712                                        (car range)))))
5713          (t
5714           (while range
5715             (if (numberp (car range))
5716                 (setq num (1+ num))
5717               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5718             (setq range (cdr range)))
5719           (setq num (- (cdr active) num))))
5720         ;; Update the number of unread articles.
5721         (setcar entry num)
5722         ;; Update the group buffer.
5723         (unless (gnus-ephemeral-group-p group)
5724           (gnus-group-update-group group t))))))
5725
5726 (defvar gnus-newsgroup-none-id 0)
5727
5728 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5729   (let ((cur nntp-server-buffer)
5730         (dependencies
5731          (or dependencies
5732              (save-excursion (set-buffer gnus-summary-buffer)
5733                              gnus-newsgroup-dependencies)))
5734         headers id end ref
5735         (mail-parse-charset gnus-newsgroup-charset)
5736         (mail-parse-ignored-charsets
5737          (save-excursion (condition-case nil
5738                              (set-buffer gnus-summary-buffer)
5739                            (error))
5740                          gnus-newsgroup-ignored-charsets)))
5741     (save-excursion
5742       (set-buffer nntp-server-buffer)
5743       ;; Translate all TAB characters into SPACE characters.
5744       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5745       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5746       (ietf-drums-unfold-fws)
5747       (gnus-run-hooks 'gnus-parse-headers-hook)
5748       (let ((case-fold-search t)
5749             in-reply-to header p lines chars)
5750         (goto-char (point-min))
5751         ;; Search to the beginning of the next header.  Error messages
5752         ;; do not begin with 2 or 3.
5753         (while (re-search-forward "^[23][0-9]+ " nil t)
5754           (setq id nil
5755                 ref nil)
5756           ;; This implementation of this function, with nine
5757           ;; search-forwards instead of the one re-search-forward and
5758           ;; a case (which basically was the old function) is actually
5759           ;; about twice as fast, even though it looks messier.  You
5760           ;; can't have everything, I guess.  Speed and elegance
5761           ;; doesn't always go hand in hand.
5762           (setq
5763            header
5764            (vector
5765             ;; Number.
5766             (prog1
5767                 (read cur)
5768               (end-of-line)
5769               (setq p (point))
5770               (narrow-to-region (point)
5771                                 (or (and (search-forward "\n.\n" nil t)
5772                                          (- (point) 2))
5773                                     (point))))
5774             ;; Subject.
5775             (progn
5776               (goto-char p)
5777               (if (search-forward "\nsubject:" nil t)
5778                   (funcall gnus-decode-encoded-word-function
5779                            (nnheader-header-value))
5780                 "(none)"))
5781             ;; From.
5782             (progn
5783               (goto-char p)
5784               (if (search-forward "\nfrom:" nil t)
5785                   (funcall gnus-decode-encoded-word-function
5786                            (nnheader-header-value))
5787                 "(nobody)"))
5788             ;; Date.
5789             (progn
5790               (goto-char p)
5791               (if (search-forward "\ndate:" nil t)
5792                   (nnheader-header-value) ""))
5793             ;; Message-ID.
5794             (progn
5795               (goto-char p)
5796               (setq id (if (re-search-forward
5797                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5798                            ;; We do it this way to make sure the Message-ID
5799                            ;; is (somewhat) syntactically valid.
5800                            (buffer-substring (match-beginning 1)
5801                                              (match-end 1))
5802                          ;; If there was no message-id, we just fake one
5803                          ;; to make subsequent routines simpler.
5804                          (nnheader-generate-fake-message-id))))
5805             ;; References.
5806             (progn
5807               (goto-char p)
5808               (if (search-forward "\nreferences:" nil t)
5809                   (progn
5810                     (setq end (point))
5811                     (prog1
5812                         (nnheader-header-value)
5813                       (setq ref
5814                             (buffer-substring
5815                              (progn
5816                                (end-of-line)
5817                                (search-backward ">" end t)
5818                                (1+ (point)))
5819                              (progn
5820                                (search-backward "<" end t)
5821                                (point))))))
5822                 ;; Get the references from the in-reply-to header if there
5823                 ;; were no references and the in-reply-to header looks
5824                 ;; promising.
5825                 (if (and (search-forward "\nin-reply-to:" nil t)
5826                          (setq in-reply-to (nnheader-header-value))
5827                          (string-match "<[^>]+>" in-reply-to))
5828                     (let (ref2)
5829                       (setq ref (substring in-reply-to (match-beginning 0)
5830                                            (match-end 0)))
5831                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5832                         (setq ref2 (substring in-reply-to (match-beginning 0)
5833                                               (match-end 0)))
5834                         (when (> (length ref2) (length ref))
5835                           (setq ref ref2)))
5836                       ref)
5837                   (setq ref nil))))
5838             ;; Chars.
5839             (progn
5840               (goto-char p)
5841               (if (search-forward "\nchars: " nil t)
5842                   (if (numberp (setq chars (ignore-errors (read cur))))
5843                       chars -1)
5844                 -1))
5845             ;; Lines.
5846             (progn
5847               (goto-char p)
5848               (if (search-forward "\nlines: " nil t)
5849                   (if (numberp (setq lines (ignore-errors (read cur))))
5850                       lines -1)
5851                 -1))
5852             ;; Xref.
5853             (progn
5854               (goto-char p)
5855               (and (search-forward "\nxref:" nil t)
5856                    (nnheader-header-value)))
5857             ;; Extra.
5858             (when gnus-extra-headers
5859               (let ((extra gnus-extra-headers)
5860                     out)
5861                 (while extra
5862                   (goto-char p)
5863                   (when (search-forward
5864                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5865                     (push (cons (car extra) (nnheader-header-value))
5866                           out))
5867                   (pop extra))
5868                 out))))
5869           (when (equal id ref)
5870             (setq ref nil))
5871
5872           (when gnus-alter-header-function
5873             (funcall gnus-alter-header-function header)
5874             (setq id (mail-header-id header)
5875                   ref (gnus-parent-id (mail-header-references header))))
5876
5877           (when (setq header
5878                       (gnus-dependencies-add-header
5879                        header dependencies force-new))
5880             (push header headers))
5881           (goto-char (point-max))
5882           (widen))
5883         (nreverse headers)))))
5884
5885 ;; Goes through the xover lines and returns a list of vectors
5886 (defun gnus-get-newsgroup-headers-xover (sequence &optional
5887                                                   force-new dependencies
5888                                                   group also-fetch-heads)
5889   "Parse the news overview data in the server buffer.
5890 Return a list of headers that match SEQUENCE (see
5891 `nntp-retrieve-headers')."
5892   ;; Get the Xref when the users reads the articles since most/some
5893   ;; NNTP servers do not include Xrefs when using XOVER.
5894   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
5895   (let ((mail-parse-charset gnus-newsgroup-charset)
5896         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
5897         (cur nntp-server-buffer)
5898         (dependencies (or dependencies gnus-newsgroup-dependencies))
5899         (allp (cond
5900                ((eq gnus-read-all-available-headers t)
5901                 t)
5902                ((stringp gnus-read-all-available-headers)
5903                 (string-match gnus-read-all-available-headers group))
5904                (t
5905                 nil)))
5906         number headers header)
5907     (save-excursion
5908       (set-buffer nntp-server-buffer)
5909       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5910       ;; Allow the user to mangle the headers before parsing them.
5911       (gnus-run-hooks 'gnus-parse-headers-hook)
5912       (goto-char (point-min))
5913       (gnus-parse-without-error
5914         (while (and (or sequence allp)
5915                     (not (eobp)))
5916           (setq number (read cur))
5917           (when (not allp)
5918             (while (and sequence
5919                         (< (car sequence) number))
5920               (setq sequence (cdr sequence))))
5921           (when (and (or allp
5922                          (and sequence
5923                               (eq number (car sequence))))
5924                      (progn
5925                        (setq sequence (cdr sequence))
5926                        (setq header (inline
5927                                       (gnus-nov-parse-line
5928                                        number dependencies force-new)))))
5929             (push header headers))
5930           (forward-line 1)))
5931       ;; A common bug in inn is that if you have posted an article and
5932       ;; then retrieves the active file, it will answer correctly --
5933       ;; the new article is included.  However, a NOV entry for the
5934       ;; article may not have been generated yet, so this may fail.
5935       ;; We work around this problem by retrieving the last few
5936       ;; headers using HEAD.
5937       (if (or (not also-fetch-heads)
5938               (not sequence))
5939           ;; We (probably) got all the headers.
5940           (nreverse headers)
5941         (let ((gnus-nov-is-evil t))
5942           (nconc
5943            (nreverse headers)
5944            (when (eq (gnus-retrieve-headers sequence group) 'headers)
5945              (gnus-get-newsgroup-headers))))))))
5946
5947 (defun gnus-article-get-xrefs ()
5948   "Fill in the Xref value in `gnus-current-headers', if necessary.
5949 This is meant to be called in `gnus-article-internal-prepare-hook'."
5950   (let ((headers (save-excursion (set-buffer gnus-summary-buffer)
5951                                  gnus-current-headers)))
5952     (or (not gnus-use-cross-reference)
5953         (not headers)
5954         (and (mail-header-xref headers)
5955              (not (string= (mail-header-xref headers) "")))
5956         (let ((case-fold-search t)
5957               xref)
5958           (save-restriction
5959             (nnheader-narrow-to-headers)
5960             (goto-char (point-min))
5961             (when (or (and (not (eobp))
5962                            (eq (downcase (char-after)) ?x)
5963                            (looking-at "Xref:"))
5964                       (search-forward "\nXref:" nil t))
5965               (goto-char (1+ (match-end 0)))
5966               (setq xref (buffer-substring (point) (point-at-eol)))
5967               (mail-header-set-xref headers xref)))))))
5968
5969 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
5970   "Find article ID and insert the summary line for that article.
5971 OLD-HEADER can either be a header or a line number to insert
5972 the subject line on."
5973   (let* ((line (and (numberp old-header) old-header))
5974          (old-header (and (vectorp old-header) old-header))
5975          (header (cond ((and old-header use-old-header)
5976                         old-header)
5977                        ((and (numberp id)
5978                              (gnus-number-to-header id))
5979                         (gnus-number-to-header id))
5980                        (t
5981                         (gnus-read-header id))))
5982          (number (and (numberp id) id))
5983          d)
5984     (when header
5985       ;; Rebuild the thread that this article is part of and go to the
5986       ;; article we have fetched.
5987       (when (and (not gnus-show-threads)
5988                  old-header)
5989         (when (and number
5990                    (setq d (gnus-data-find (mail-header-number old-header))))
5991           (goto-char (gnus-data-pos d))
5992           (gnus-data-remove
5993            number
5994            (- (point-at-bol)
5995               (prog1
5996                   (1+ (point-at-eol))
5997                 (gnus-delete-line))))))
5998       (when old-header
5999         (mail-header-set-number header (mail-header-number old-header)))
6000       (setq gnus-newsgroup-sparse
6001             (delq (setq number (mail-header-number header))
6002                   gnus-newsgroup-sparse))
6003       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6004       (push number gnus-newsgroup-limit)
6005       (gnus-rebuild-thread (mail-header-id header) line)
6006       (gnus-summary-goto-subject number nil t))
6007     (when (and (numberp number)
6008                (> number 0))
6009       ;; We have to update the boundaries even if we can't fetch the
6010       ;; article if ID is a number -- so that the next `P' or `N'
6011       ;; command will fetch the previous (or next) article even
6012       ;; if the one we tried to fetch this time has been canceled.
6013       (when (> number gnus-newsgroup-end)
6014         (setq gnus-newsgroup-end number))
6015       (when (< number gnus-newsgroup-begin)
6016         (setq gnus-newsgroup-begin number))
6017       (setq gnus-newsgroup-unselected
6018             (delq number gnus-newsgroup-unselected)))
6019     ;; Report back a success?
6020     (and header (mail-header-number header))))
6021
6022 ;;; Process/prefix in the summary buffer
6023
6024 (defun gnus-summary-work-articles (n)
6025   "Return a list of articles to be worked upon.
6026 The prefix argument, the list of process marked articles, and the
6027 current article will be taken into consideration."
6028   (save-excursion
6029     (set-buffer gnus-summary-buffer)
6030     (cond
6031      (n
6032       ;; A numerical prefix has been given.
6033       (setq n (prefix-numeric-value n))
6034       (let ((backward (< n 0))
6035             (n (abs (prefix-numeric-value n)))
6036             articles article)
6037         (save-excursion
6038           (while
6039               (and (> n 0)
6040                    (push (setq article (gnus-summary-article-number))
6041                          articles)
6042                    (if backward
6043                        (gnus-summary-find-prev nil article)
6044                      (gnus-summary-find-next nil article)))
6045             (decf n)))
6046         (nreverse articles)))
6047      ((and (gnus-region-active-p) (mark))
6048       (message "region active")
6049       ;; Work on the region between point and mark.
6050       (let ((max (max (point) (mark)))
6051             articles article)
6052         (save-excursion
6053           (goto-char (min (min (point) (mark))))
6054           (while
6055               (and
6056                (push (setq article (gnus-summary-article-number)) articles)
6057                (gnus-summary-find-next nil article)
6058                (< (point) max)))
6059           (nreverse articles))))
6060      (gnus-newsgroup-processable
6061       ;; There are process-marked articles present.
6062       ;; Save current state.
6063       (gnus-summary-save-process-mark)
6064       ;; Return the list.
6065       (reverse gnus-newsgroup-processable))
6066      (t
6067       ;; Just return the current article.
6068       (list (gnus-summary-article-number))))))
6069
6070 (defmacro gnus-summary-iterate (arg &rest forms)
6071   "Iterate over the process/prefixed articles and do FORMS.
6072 ARG is the interactive prefix given to the command.  FORMS will be
6073 executed with point over the summary line of the articles."
6074   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6075     `(let ((,articles (gnus-summary-work-articles ,arg)))
6076        (while ,articles
6077          (gnus-summary-goto-subject (car ,articles))
6078          ,@forms
6079          (pop ,articles)))))
6080
6081 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6082 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6083
6084 (defun gnus-summary-save-process-mark ()
6085   "Push the current set of process marked articles on the stack."
6086   (interactive)
6087   (push (copy-sequence gnus-newsgroup-processable)
6088         gnus-newsgroup-process-stack))
6089
6090 (defun gnus-summary-kill-process-mark ()
6091   "Push the current set of process marked articles on the stack and unmark."
6092   (interactive)
6093   (gnus-summary-save-process-mark)
6094   (gnus-summary-unmark-all-processable))
6095
6096 (defun gnus-summary-yank-process-mark ()
6097   "Pop the last process mark state off the stack and restore it."
6098   (interactive)
6099   (unless gnus-newsgroup-process-stack
6100     (error "Empty mark stack"))
6101   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6102
6103 (defun gnus-summary-process-mark-set (set)
6104   "Make SET into the current process marked articles."
6105   (gnus-summary-unmark-all-processable)
6106   (while set
6107     (gnus-summary-set-process-mark (pop set))))
6108
6109 ;;; Searching and stuff
6110
6111 (defun gnus-summary-search-group (&optional backward use-level)
6112   "Search for next unread newsgroup.
6113 If optional argument BACKWARD is non-nil, search backward instead."
6114   (save-excursion
6115     (set-buffer gnus-group-buffer)
6116     (when (gnus-group-search-forward
6117            backward nil (if use-level (gnus-group-group-level) nil))
6118       (gnus-group-group-name))))
6119
6120 (defun gnus-summary-best-group (&optional exclude-group)
6121   "Find the name of the best unread group.
6122 If EXCLUDE-GROUP, do not go to this group."
6123   (save-excursion
6124     (set-buffer gnus-group-buffer)
6125     (save-excursion
6126       (gnus-group-best-unread-group exclude-group))))
6127
6128 (defun gnus-summary-find-next (&optional unread article backward)
6129   (if backward
6130       (gnus-summary-find-prev unread article)
6131     (let* ((dummy (gnus-summary-article-intangible-p))
6132            (article (or article (gnus-summary-article-number)))
6133            (data (gnus-data-find-list article))
6134            result)
6135       (when (and (not dummy)
6136                  (or (not gnus-summary-check-current)
6137                      (not unread)
6138                      (not (gnus-data-unread-p (car data)))))
6139         (setq data (cdr data)))
6140       (when (setq result
6141                   (if unread
6142                       (progn
6143                         (while data
6144                           (unless (memq (gnus-data-number (car data))
6145                                         (cond
6146                                          ((eq gnus-auto-goto-ignores
6147                                               'always-undownloaded)
6148                                           gnus-newsgroup-undownloaded)
6149                                          (gnus-plugged
6150                                           nil)
6151                                          ((eq gnus-auto-goto-ignores
6152                                               'unfetched)
6153                                           gnus-newsgroup-unfetched)
6154                                          ((eq gnus-auto-goto-ignores
6155                                               'undownloaded)
6156                                           gnus-newsgroup-undownloaded)))
6157                             (when (gnus-data-unread-p (car data))
6158                               (setq result (car data)
6159                                     data nil)))
6160                           (setq data (cdr data)))
6161                         result)
6162                     (car data)))
6163         (goto-char (gnus-data-pos result))
6164         (gnus-data-number result)))))
6165
6166 (defun gnus-summary-find-prev (&optional unread article)
6167   (let* ((eobp (eobp))
6168          (article (or article (gnus-summary-article-number)))
6169          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6170          result)
6171     (when (and (not eobp)
6172                (or (not gnus-summary-check-current)
6173                    (not unread)
6174                    (not (gnus-data-unread-p (car data)))))
6175       (setq data (cdr data)))
6176     (when (setq result
6177                 (if unread
6178                     (progn
6179                       (while data
6180                         (unless (memq (gnus-data-number (car data))
6181                                       (cond
6182                                        ((eq gnus-auto-goto-ignores
6183                                             'always-undownloaded)
6184                                         gnus-newsgroup-undownloaded)
6185                                        (gnus-plugged
6186                                         nil)
6187                                        ((eq gnus-auto-goto-ignores
6188                                             'unfetched)
6189                                         gnus-newsgroup-unfetched)
6190                                        ((eq gnus-auto-goto-ignores
6191                                             'undownloaded)
6192                                         gnus-newsgroup-undownloaded)))
6193                           (when (gnus-data-unread-p (car data))
6194                             (setq result (car data)
6195                                   data nil)))
6196                         (setq data (cdr data)))
6197                       result)
6198                   (car data)))
6199       (goto-char (gnus-data-pos result))
6200       (gnus-data-number result))))
6201
6202 (defun gnus-summary-find-subject (subject &optional unread backward article)
6203   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6204          (article (or article (gnus-summary-article-number)))
6205          (articles (gnus-data-list backward))
6206          (arts (gnus-data-find-list article articles))
6207          result)
6208     (when (or (not gnus-summary-check-current)
6209               (not unread)
6210               (not (gnus-data-unread-p (car arts))))
6211       (setq arts (cdr arts)))
6212     (while arts
6213       (and (or (not unread)
6214                (gnus-data-unread-p (car arts)))
6215            (vectorp (gnus-data-header (car arts)))
6216            (gnus-subject-equal
6217             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6218            (setq result (car arts)
6219                  arts nil))
6220       (setq arts (cdr arts)))
6221     (and result
6222          (goto-char (gnus-data-pos result))
6223          (gnus-data-number result))))
6224
6225 (defun gnus-summary-search-forward (&optional unread subject backward)
6226   "Search forward for an article.
6227 If UNREAD, look for unread articles.  If SUBJECT, look for
6228 articles with that subject.  If BACKWARD, search backward instead."
6229   (cond (subject (gnus-summary-find-subject subject unread backward))
6230         (backward (gnus-summary-find-prev unread))
6231         (t (gnus-summary-find-next unread))))
6232
6233 (defun gnus-recenter (&optional n)
6234   "Center point in window and redisplay frame.
6235 Also do horizontal recentering."
6236   (interactive "P")
6237   (when (and gnus-auto-center-summary
6238              (not (eq gnus-auto-center-summary 'vertical)))
6239     (gnus-horizontal-recenter))
6240   (recenter n))
6241
6242 (defun gnus-summary-recenter ()
6243   "Center point in the summary window.
6244 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6245 displayed, no centering will be performed."
6246   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6247   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6248   (interactive)
6249   ;; The user has to want it.
6250   (when gnus-auto-center-summary
6251     (let* ((top (cond ((< (window-height) 4) 0)
6252                       ((< (window-height) 7) 1)
6253                       (t (if (numberp gnus-auto-center-summary)
6254                              gnus-auto-center-summary
6255                            2))))
6256            (height (1- (window-height)))
6257            (bottom (save-excursion (goto-char (point-max))
6258                                    (forward-line (- height))
6259                                    (point)))
6260            (window (get-buffer-window (current-buffer))))
6261       (when (get-buffer-window gnus-article-buffer)
6262         ;; Only do recentering when the article buffer is displayed,
6263         ;; Set the window start to either `bottom', which is the biggest
6264         ;; possible valid number, or the second line from the top,
6265         ;; whichever is the least.
6266         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6267           (if (> bottom top-pos)
6268               ;; Keep the second line from the top visible
6269               (set-window-start window top-pos t)
6270             ;; Try to keep the bottom line visible; if it's partially
6271             ;; obscured, either scroll one more line to make it fully
6272             ;; visible, or revert to using TOP-POS.
6273             (save-excursion
6274               (goto-char (point-max))
6275               (forward-line -1)
6276               (let ((last-line-start (point)))
6277                 (goto-char bottom)
6278                 (set-window-start window (point) t)
6279                 (when (not (pos-visible-in-window-p last-line-start window))
6280                   (forward-line 1)
6281                   (set-window-start window (min (point) top-pos) t)))))))
6282       ;; Do horizontal recentering while we're at it.
6283       (when (and (get-buffer-window (current-buffer) t)
6284                  (not (eq gnus-auto-center-summary 'vertical)))
6285         (let ((selected (selected-window)))
6286           (select-window (get-buffer-window (current-buffer) t))
6287           (gnus-summary-position-point)
6288           (gnus-horizontal-recenter)
6289           (select-window selected))))))
6290
6291 (defun gnus-summary-jump-to-group (newsgroup)
6292   "Move point to NEWSGROUP in group mode buffer."
6293   ;; Keep update point of group mode buffer if visible.
6294   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6295       (save-window-excursion
6296         ;; Take care of tree window mode.
6297         (when (get-buffer-window gnus-group-buffer)
6298           (pop-to-buffer gnus-group-buffer))
6299         (gnus-group-jump-to-group newsgroup))
6300     (save-excursion
6301       ;; Take care of tree window mode.
6302       (if (get-buffer-window gnus-group-buffer)
6303           (pop-to-buffer gnus-group-buffer)
6304         (set-buffer gnus-group-buffer))
6305       (gnus-group-jump-to-group newsgroup))))
6306
6307 ;; This function returns a list of article numbers based on the
6308 ;; difference between the ranges of read articles in this group and
6309 ;; the range of active articles.
6310 (defun gnus-list-of-unread-articles (group)
6311   (let* ((read (gnus-info-read (gnus-get-info group)))
6312          (active (or (gnus-active group) (gnus-activate-group group)))
6313          (last (cdr active))
6314          first nlast unread)
6315     ;; If none are read, then all are unread.
6316     (if (not read)
6317         (setq first (car active))
6318       ;; If the range of read articles is a single range, then the
6319       ;; first unread article is the article after the last read
6320       ;; article.  Sounds logical, doesn't it?
6321       (if (and (not (listp (cdr read)))
6322                (or (< (car read) (car active))
6323                    (progn (setq read (list read))
6324                           nil)))
6325           (setq first (max (car active) (1+ (cdr read))))
6326         ;; `read' is a list of ranges.
6327         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6328                                   (caar read)))
6329                   1)
6330           (setq first (car active)))
6331         (while read
6332           (when first
6333             (while (< first nlast)
6334               (setq unread (cons first unread)
6335                     first (1+ first))))
6336           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6337           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6338           (setq read (cdr read)))))
6339     ;; And add the last unread articles.
6340     (while (<= first last)
6341       (setq unread (cons first unread)
6342             first (1+ first)))
6343     ;; Return the list of unread articles.
6344     (delq 0 (nreverse unread))))
6345
6346 (defun gnus-list-of-read-articles (group)
6347   "Return a list of unread, unticked and non-dormant articles."
6348   (let* ((info (gnus-get-info group))
6349          (marked (gnus-info-marks info))
6350          (active (gnus-active group)))
6351     (and info active
6352          (gnus-list-range-difference
6353           (gnus-list-range-difference
6354            (gnus-sorted-complement
6355             (gnus-uncompress-range active)
6356             (gnus-list-of-unread-articles group))
6357            (cdr (assq 'dormant marked)))
6358           (cdr (assq 'tick marked))))))
6359
6360 ;; This function returns a sequence of article numbers based on the
6361 ;; difference between the ranges of read articles in this group and
6362 ;; the range of active articles.
6363 (defun gnus-sequence-of-unread-articles (group)
6364   (let* ((read (gnus-info-read (gnus-get-info group)))
6365          (active (or (gnus-active group) (gnus-activate-group group)))
6366          (last (cdr active))
6367          first nlast unread)
6368     ;; If none are read, then all are unread.
6369     (if (not read)
6370         (setq first (car active))
6371       ;; If the range of read articles is a single range, then the
6372       ;; first unread article is the article after the last read
6373       ;; article.  Sounds logical, doesn't it?
6374       (if (and (not (listp (cdr read)))
6375                (or (< (car read) (car active))
6376                    (progn (setq read (list read))
6377                           nil)))
6378           (setq first (max (car active) (1+ (cdr read))))
6379         ;; `read' is a list of ranges.
6380         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6381                                   (caar read)))
6382                   1)
6383           (setq first (car active)))
6384         (while read
6385           (when first
6386             (push (cons first nlast) unread))
6387           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6388           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6389           (setq read (cdr read)))))
6390     ;; And add the last unread articles.
6391     (cond ((< first last)
6392            (push (cons first last) unread))
6393           ((= first last)
6394            (push first unread)))
6395     ;; Return the sequence of unread articles.
6396     (delq 0 (nreverse unread))))
6397
6398 ;; Various summary commands
6399
6400 (defun gnus-summary-select-article-buffer ()
6401   "Reconfigure windows to show article buffer."
6402   (interactive)
6403   (if (not (gnus-buffer-live-p gnus-article-buffer))
6404       (error "There is no article buffer for this summary buffer")
6405     (gnus-configure-windows 'article)
6406     (select-window (get-buffer-window gnus-article-buffer))))
6407
6408 (defun gnus-summary-universal-argument (arg)
6409   "Perform any operation on all articles that are process/prefixed."
6410   (interactive "P")
6411   (let ((articles (gnus-summary-work-articles arg))
6412         func article)
6413     (if (eq
6414          (setq
6415           func
6416           (key-binding
6417            (read-key-sequence
6418             (substitute-command-keys
6419              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6420          'undefined)
6421         (gnus-error 1 "Undefined key")
6422       (save-excursion
6423         (while articles
6424           (gnus-summary-goto-subject (setq article (pop articles)))
6425           (let (gnus-newsgroup-processable)
6426             (command-execute func))
6427           (gnus-summary-remove-process-mark article)))))
6428   (gnus-summary-position-point))
6429
6430 (defun gnus-summary-toggle-truncation (&optional arg)
6431   "Toggle truncation of summary lines.
6432 With ARG, turn line truncation on if ARG is positive."
6433   (interactive "P")
6434   (setq truncate-lines
6435         (if (null arg) (not truncate-lines)
6436           (> (prefix-numeric-value arg) 0)))
6437   (redraw-display))
6438
6439 (defun gnus-summary-find-for-reselect ()
6440   "Return the number of an article to stay on across a reselect.
6441 The current article is considered, then following articles, then previous
6442 articles.  An article is sought which is not cancelled and isn't a temporary
6443 insertion from another group.  If there's no such then return a dummy 0."
6444   (let (found)
6445     (dolist (rev '(nil t))
6446       (unless found      ; don't demand the reverse list if we don't need it
6447         (let ((data (gnus-data-find-list
6448                      (gnus-summary-article-number) (gnus-data-list rev))))
6449           (while (and data (not found))
6450             (if (and (< 0 (gnus-data-number (car data)))
6451                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6452                 (setq found (gnus-data-number (car data))))
6453             (setq data (cdr data))))))
6454     (or found 0)))
6455
6456 (defun gnus-summary-reselect-current-group (&optional all rescan)
6457   "Exit and then reselect the current newsgroup.
6458 The prefix argument ALL means to select all articles."
6459   (interactive "P")
6460   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6461     (error "Ephemeral groups can't be reselected"))
6462   (let ((current-subject (gnus-summary-find-for-reselect))
6463         (group gnus-newsgroup-name))
6464     (setq gnus-newsgroup-begin nil)
6465     (gnus-summary-exit nil 'leave-hidden)
6466     ;; We have to adjust the point of group mode buffer because
6467     ;; point was moved to the next unread newsgroup by exiting.
6468     (gnus-summary-jump-to-group group)
6469     (when rescan
6470       (save-excursion
6471         (gnus-group-get-new-news-this-group 1)))
6472     (gnus-group-read-group all t)
6473     (gnus-summary-goto-subject current-subject nil t)))
6474
6475 (defun gnus-summary-rescan-group (&optional all)
6476   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6477   (interactive "P")
6478   (gnus-summary-reselect-current-group all t))
6479
6480 (defun gnus-summary-update-info (&optional non-destructive)
6481   (save-excursion
6482     (let ((group gnus-newsgroup-name))
6483       (when group
6484         (when gnus-newsgroup-kill-headers
6485           (setq gnus-newsgroup-killed
6486                 (gnus-compress-sequence
6487                  (gnus-sorted-union
6488                   (gnus-list-range-intersection
6489                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6490                   gnus-newsgroup-unreads)
6491                  t)))
6492         (unless (listp (cdr gnus-newsgroup-killed))
6493           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6494         (let ((headers gnus-newsgroup-headers))
6495           ;; Set the new ranges of read articles.
6496           (save-excursion
6497             (set-buffer gnus-group-buffer)
6498             (gnus-undo-force-boundary))
6499           (gnus-update-read-articles
6500            group (gnus-sorted-union
6501                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6502           ;; Set the current article marks.
6503           (let ((gnus-newsgroup-scored
6504                  (if (and (not gnus-save-score)
6505                           (not non-destructive))
6506                      nil
6507                    gnus-newsgroup-scored)))
6508             (save-excursion
6509               (gnus-update-marks)))
6510           ;; Do the cross-ref thing.
6511           (when gnus-use-cross-reference
6512             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6513           ;; Do not switch windows but change the buffer to work.
6514           (set-buffer gnus-group-buffer)
6515           (unless (gnus-ephemeral-group-p group)
6516             (gnus-group-update-group group)))))))
6517
6518 (defun gnus-summary-save-newsrc (&optional force)
6519   "Save the current number of read/marked articles in the dribble buffer.
6520 The dribble buffer will then be saved.
6521 If FORCE (the prefix), also save the .newsrc file(s)."
6522   (interactive "P")
6523   (gnus-summary-update-info t)
6524   (if force
6525       (gnus-save-newsrc-file)
6526     (gnus-dribble-save)))
6527
6528 (defun gnus-summary-exit (&optional temporary leave-hidden)
6529   "Exit reading current newsgroup, and then return to group selection mode.
6530 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6531   (interactive)
6532   (gnus-set-global-variables)
6533   (when (gnus-buffer-live-p gnus-article-buffer)
6534     (save-excursion
6535       (set-buffer gnus-article-buffer)
6536       (mm-destroy-parts gnus-article-mime-handles)
6537       ;; Set it to nil for safety reason.
6538       (setq gnus-article-mime-handle-alist nil)
6539       (setq gnus-article-mime-handles nil)))
6540   (gnus-kill-save-kill-buffer)
6541   (gnus-async-halt-prefetch)
6542   (let* ((group gnus-newsgroup-name)
6543          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6544          (gnus-group-is-exiting-p t)
6545          (mode major-mode)
6546          (group-point nil)
6547          (buf (current-buffer)))
6548     (unless quit-config
6549       ;; Do adaptive scoring, and possibly save score files.
6550       (when gnus-newsgroup-adaptive
6551         (gnus-score-adaptive))
6552       (when gnus-use-scoring
6553         (gnus-score-save)))
6554     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6555     ;; If we have several article buffers, we kill them at exit.
6556     (unless gnus-single-article-buffer
6557       (gnus-kill-buffer gnus-original-article-buffer)
6558       (setq gnus-article-current nil))
6559     (when gnus-use-cache
6560       (gnus-cache-possibly-remove-articles)
6561       (gnus-cache-save-buffers))
6562     (gnus-async-prefetch-remove-group group)
6563     (when gnus-suppress-duplicates
6564       (gnus-dup-enter-articles))
6565     (when gnus-use-trees
6566       (gnus-tree-close group))
6567     (when gnus-use-cache
6568       (gnus-cache-write-active))
6569     ;; Remove entries for this group.
6570     (nnmail-purge-split-history (gnus-group-real-name group))
6571     ;; Make all changes in this group permanent.
6572     (unless quit-config
6573       (gnus-run-hooks 'gnus-exit-group-hook)
6574       (gnus-summary-update-info))
6575     (gnus-close-group group)
6576     ;; Make sure where we were, and go to next newsgroup.
6577     (set-buffer gnus-group-buffer)
6578     (unless quit-config
6579       (gnus-group-jump-to-group group))
6580     (gnus-run-hooks 'gnus-summary-exit-hook)
6581     (unless (or quit-config
6582                 ;; If this group has disappeared from the summary
6583                 ;; buffer, don't skip forwards.
6584                 (not (string= group (gnus-group-group-name))))
6585       (gnus-group-next-unread-group 1))
6586     (setq group-point (point))
6587     (if temporary
6588         nil                             ;Nothing to do.
6589       ;; If we have several article buffers, we kill them at exit.
6590       (unless gnus-single-article-buffer
6591         (gnus-kill-buffer gnus-article-buffer)
6592         (gnus-kill-buffer gnus-original-article-buffer)
6593         (setq gnus-article-current nil))
6594       (set-buffer buf)
6595       (if (not gnus-kill-summary-on-exit)
6596           (progn
6597             (gnus-deaden-summary)
6598             (setq mode nil))
6599         ;; We set all buffer-local variables to nil.  It is unclear why
6600         ;; this is needed, but if we don't, buffer-local variables are
6601         ;; not garbage-collected, it seems.  This would the lead to en
6602         ;; ever-growing Emacs.
6603         (gnus-summary-clear-local-variables)
6604         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6605           (gnus-summary-clear-local-variables))
6606         (when (get-buffer gnus-article-buffer)
6607           (bury-buffer gnus-article-buffer))
6608         ;; We clear the global counterparts of the buffer-local
6609         ;; variables as well, just to be on the safe side.
6610         (set-buffer gnus-group-buffer)
6611         (gnus-summary-clear-local-variables)
6612         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6613           (gnus-summary-clear-local-variables))
6614         ;; Return to group mode buffer.
6615         (when (eq mode 'gnus-summary-mode)
6616           (gnus-kill-buffer buf)))
6617       (setq gnus-current-select-method gnus-select-method)
6618       (if leave-hidden
6619           (set-buffer gnus-group-buffer)
6620         (pop-to-buffer gnus-group-buffer))
6621       (if (not quit-config)
6622           (progn
6623             (goto-char group-point)
6624             (unless leave-hidden
6625               (gnus-configure-windows 'group 'force)))
6626         (gnus-handle-ephemeral-exit quit-config))
6627       ;; Clear the current group name.
6628       (unless quit-config
6629         (setq gnus-newsgroup-name nil)))))
6630
6631 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6632 (defun gnus-summary-exit-no-update (&optional no-questions)
6633   "Quit reading current newsgroup without updating read article info."
6634   (interactive)
6635   (let* ((group gnus-newsgroup-name)
6636          (gnus-group-is-exiting-p t)
6637          (gnus-group-is-exiting-without-update-p t)
6638          (quit-config (gnus-group-quit-config group)))
6639     (when (or no-questions
6640               gnus-expert-user
6641               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6642       (gnus-async-halt-prefetch)
6643       (run-hooks 'gnus-summary-prepare-exit-hook)
6644       (when (gnus-buffer-live-p gnus-article-buffer)
6645         (save-excursion
6646           (set-buffer gnus-article-buffer)
6647           (mm-destroy-parts gnus-article-mime-handles)
6648           ;; Set it to nil for safety reason.
6649           (setq gnus-article-mime-handle-alist nil)
6650           (setq gnus-article-mime-handles nil)))
6651       ;; If we have several article buffers, we kill them at exit.
6652       (unless gnus-single-article-buffer
6653         (gnus-kill-buffer gnus-article-buffer)
6654         (gnus-kill-buffer gnus-original-article-buffer)
6655         (setq gnus-article-current nil))
6656       (if (not gnus-kill-summary-on-exit)
6657           (gnus-deaden-summary)
6658         (gnus-close-group group)
6659         (gnus-summary-clear-local-variables)
6660         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6661           (gnus-summary-clear-local-variables))
6662         (set-buffer gnus-group-buffer)
6663         (gnus-summary-clear-local-variables)
6664         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6665           (gnus-summary-clear-local-variables))
6666         (gnus-kill-buffer gnus-summary-buffer))
6667       (unless gnus-single-article-buffer
6668         (setq gnus-article-current nil))
6669       (when gnus-use-trees
6670         (gnus-tree-close group))
6671       (gnus-async-prefetch-remove-group group)
6672       (when (get-buffer gnus-article-buffer)
6673         (bury-buffer gnus-article-buffer))
6674       ;; Return to the group buffer.
6675       (gnus-configure-windows 'group 'force)
6676       ;; Clear the current group name.
6677       (setq gnus-newsgroup-name nil)
6678       (unless (gnus-ephemeral-group-p group)
6679         (gnus-group-update-group group))
6680       (when (equal (gnus-group-group-name) group)
6681         (gnus-group-next-unread-group 1))
6682       (when quit-config
6683         (gnus-handle-ephemeral-exit quit-config)))))
6684
6685 (defun gnus-handle-ephemeral-exit (quit-config)
6686   "Handle movement when leaving an ephemeral group.
6687 The state which existed when entering the ephemeral is reset."
6688   (if (not (buffer-name (car quit-config)))
6689       (gnus-configure-windows 'group 'force)
6690     (set-buffer (car quit-config))
6691     (cond ((eq major-mode 'gnus-summary-mode)
6692            (gnus-set-global-variables))
6693           ((eq major-mode 'gnus-article-mode)
6694            (save-excursion
6695              ;; The `gnus-summary-buffer' variable may point
6696              ;; to the old summary buffer when using a single
6697              ;; article buffer.
6698              (unless (gnus-buffer-live-p gnus-summary-buffer)
6699                (set-buffer gnus-group-buffer))
6700              (set-buffer gnus-summary-buffer)
6701              (gnus-set-global-variables))))
6702     (if (or (eq (cdr quit-config) 'article)
6703             (eq (cdr quit-config) 'pick))
6704         (progn
6705           ;; The current article may be from the ephemeral group
6706           ;; thus it is best that we reload this article
6707           ;;
6708           ;; If we're exiting from a large digest, this can be
6709           ;; extremely slow.  So, it's better not to reload it. -- jh.
6710           ;;(gnus-summary-show-article)
6711           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6712               (gnus-configure-windows 'pick 'force)
6713             (gnus-configure-windows (cdr quit-config) 'force)))
6714       (gnus-configure-windows (cdr quit-config) 'force))
6715     (when (eq major-mode 'gnus-summary-mode)
6716       (gnus-summary-next-subject 1 nil t)
6717       (gnus-summary-recenter)
6718       (gnus-summary-position-point))))
6719
6720 ;;; Dead summaries.
6721
6722 (defvar gnus-dead-summary-mode-map nil)
6723
6724 (unless gnus-dead-summary-mode-map
6725   (setq gnus-dead-summary-mode-map (make-keymap))
6726   (suppress-keymap gnus-dead-summary-mode-map)
6727   (substitute-key-definition
6728    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6729   (dolist (key '("\C-d" "\r" "\177" [delete]))
6730     (define-key gnus-dead-summary-mode-map
6731       key 'gnus-summary-wake-up-the-dead))
6732   (dolist (key '("q" "Q"))
6733     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6734
6735 (defvar gnus-dead-summary-mode nil
6736   "Minor mode for Gnus summary buffers.")
6737
6738 (defun gnus-dead-summary-mode (&optional arg)
6739   "Minor mode for Gnus summary buffers."
6740   (interactive "P")
6741   (when (eq major-mode 'gnus-summary-mode)
6742     (make-local-variable 'gnus-dead-summary-mode)
6743     (setq gnus-dead-summary-mode
6744           (if (null arg) (not gnus-dead-summary-mode)
6745             (> (prefix-numeric-value arg) 0)))
6746     (when gnus-dead-summary-mode
6747       (add-minor-mode
6748        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6749
6750 (defun gnus-deaden-summary ()
6751   "Make the current summary buffer into a dead summary buffer."
6752   ;; Kill any previous dead summary buffer.
6753   (when (and gnus-dead-summary
6754              (buffer-name gnus-dead-summary))
6755     (save-excursion
6756       (set-buffer gnus-dead-summary)
6757       (when gnus-dead-summary-mode
6758         (kill-buffer (current-buffer)))))
6759   ;; Make this the current dead summary.
6760   (setq gnus-dead-summary (current-buffer))
6761   (gnus-dead-summary-mode 1)
6762   (let ((name (buffer-name)))
6763     (when (string-match "Summary" name)
6764       (rename-buffer
6765        (concat (substring name 0 (match-beginning 0)) "Dead "
6766                (substring name (match-beginning 0)))
6767        t)
6768       (bury-buffer))))
6769
6770 (defun gnus-kill-or-deaden-summary (buffer)
6771   "Kill or deaden the summary BUFFER."
6772   (save-excursion
6773     (when (and (buffer-name buffer)
6774                (not gnus-single-article-buffer))
6775       (save-excursion
6776         (set-buffer buffer)
6777         (gnus-kill-buffer gnus-article-buffer)
6778         (gnus-kill-buffer gnus-original-article-buffer)))
6779     (cond
6780      ;; Kill the buffer.
6781      (gnus-kill-summary-on-exit
6782       (when (and gnus-use-trees
6783                  (gnus-buffer-exists-p buffer))
6784         (save-excursion
6785           (set-buffer buffer)
6786           (gnus-tree-close gnus-newsgroup-name)))
6787       (gnus-kill-buffer buffer))
6788      ;; Deaden the buffer.
6789      ((gnus-buffer-exists-p buffer)
6790       (save-excursion
6791         (set-buffer buffer)
6792         (gnus-deaden-summary))))))
6793
6794 (defun gnus-summary-wake-up-the-dead (&rest args)
6795   "Wake up the dead summary buffer."
6796   (interactive)
6797   (gnus-dead-summary-mode -1)
6798   (let ((name (buffer-name)))
6799     (when (string-match "Dead " name)
6800       (rename-buffer
6801        (concat (substring name 0 (match-beginning 0))
6802                (substring name (match-end 0)))
6803        t)))
6804   (gnus-message 3 "This dead summary is now alive again"))
6805
6806 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6807 (defun gnus-summary-fetch-faq (&optional faq-dir)
6808   "Fetch the FAQ for the current group.
6809 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6810 in."
6811   (interactive
6812    (list
6813     (when current-prefix-arg
6814       (completing-read
6815        "FAQ dir: " (and (listp gnus-group-faq-directory)
6816                         (mapcar (lambda (file) (list file))
6817                                 gnus-group-faq-directory))))))
6818   (let (gnus-faq-buffer)
6819     (when (setq gnus-faq-buffer
6820                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6821       (gnus-configure-windows 'summary-faq))))
6822
6823 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6824 (defun gnus-summary-describe-group (&optional force)
6825   "Describe the current newsgroup."
6826   (interactive "P")
6827   (gnus-group-describe-group force gnus-newsgroup-name))
6828
6829 (defun gnus-summary-describe-briefly ()
6830   "Describe summary mode commands briefly."
6831   (interactive)
6832   (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")))
6833
6834 ;; Walking around group mode buffer from summary mode.
6835
6836 (defun gnus-summary-next-group (&optional no-article target-group backward)
6837   "Exit current newsgroup and then select next unread newsgroup.
6838 If prefix argument NO-ARTICLE is non-nil, no article is selected
6839 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6840 previous group instead."
6841   (interactive "P")
6842   ;; Stop pre-fetching.
6843   (gnus-async-halt-prefetch)
6844   (let ((current-group gnus-newsgroup-name)
6845         (current-buffer (current-buffer))
6846         entered)
6847     ;; First we semi-exit this group to update Xrefs and all variables.
6848     ;; We can't do a real exit, because the window conf must remain
6849     ;; the same in case the user is prompted for info, and we don't
6850     ;; want the window conf to change before that...
6851     (gnus-summary-exit t)
6852     (while (not entered)
6853       ;; Then we find what group we are supposed to enter.
6854       (set-buffer gnus-group-buffer)
6855       (gnus-group-jump-to-group current-group)
6856       (setq target-group
6857             (or target-group
6858                 (if (eq gnus-keep-same-level 'best)
6859                     (gnus-summary-best-group gnus-newsgroup-name)
6860                   (gnus-summary-search-group backward gnus-keep-same-level))))
6861       (if (not target-group)
6862           ;; There are no further groups, so we return to the group
6863           ;; buffer.
6864           (progn
6865             (gnus-message 5 "Returning to the group buffer")
6866             (setq entered t)
6867             (when (gnus-buffer-live-p current-buffer)
6868               (set-buffer current-buffer)
6869               (gnus-summary-exit))
6870             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6871         ;; We try to enter the target group.
6872         (gnus-group-jump-to-group target-group)
6873         (let ((unreads (gnus-group-group-unread)))
6874           (if (and (or (eq t unreads)
6875                        (and unreads (not (zerop unreads))))
6876                    (gnus-summary-read-group
6877                     target-group nil no-article
6878                     (and (buffer-name current-buffer) current-buffer)
6879                     nil backward))
6880               (setq entered t)
6881             (setq current-group target-group
6882                   target-group nil)))))))
6883
6884 (defun gnus-summary-prev-group (&optional no-article)
6885   "Exit current newsgroup and then select previous unread newsgroup.
6886 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
6887   (interactive "P")
6888   (gnus-summary-next-group no-article nil t))
6889
6890 ;; Walking around summary lines.
6891
6892 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
6893   "Go to the first subject satisfying any non-nil constraint.
6894 If UNREAD is non-nil, the article should be unread.
6895 If UNDOWNLOADED is non-nil, the article should be undownloaded.
6896 If UNSEEN is non-nil, the article should be unseen.
6897 Returns the article selected or nil if there are no matching articles."
6898   (interactive "P")
6899   (cond
6900    ;; Empty summary.
6901    ((null gnus-newsgroup-data)
6902     (gnus-message 3 "No articles in the group")
6903     nil)
6904    ;; Pick the first article.
6905    ((not (or unread undownloaded unseen))
6906     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
6907     (gnus-data-number (car gnus-newsgroup-data)))
6908    ;; Find the first unread article.
6909    (t
6910     (let ((data gnus-newsgroup-data))
6911       (while (and data
6912                   (let ((num (gnus-data-number (car data))))
6913                     (or (memq num gnus-newsgroup-unfetched)
6914                         (not (or (and unread
6915                                       (memq num gnus-newsgroup-unreads))
6916                                  (and undownloaded
6917                                       (memq num gnus-newsgroup-undownloaded))
6918                                  (and unseen
6919                                       (memq num gnus-newsgroup-unseen)))))))
6920         (setq data (cdr data)))
6921       (prog1
6922           (if data
6923               (progn
6924                 (goto-char (gnus-data-pos (car data)))
6925                 (gnus-data-number (car data)))
6926             (gnus-message 3 "No more%s articles"
6927                           (let* ((r (when unread " unread"))
6928                                  (d (when undownloaded " undownloaded"))
6929                                  (s (when unseen " unseen"))
6930                                  (l (delq nil (list r d s))))
6931                             (cond ((= 3 (length l))
6932                                    (concat r "," d ", or" s))
6933                                   ((= 2 (length l))
6934                                    (concat (car l) ", or" (cadr l)))
6935                                   ((= 1 (length l))
6936                                    (car l))
6937                                   (t
6938                                    ""))))
6939             nil
6940             )
6941         (gnus-summary-position-point))))))
6942
6943 (defun gnus-summary-next-subject (n &optional unread dont-display)
6944   "Go to next N'th summary line.
6945 If N is negative, go to the previous N'th subject line.
6946 If UNREAD is non-nil, only unread articles are selected.
6947 The difference between N and the actual number of steps taken is
6948 returned."
6949   (interactive "p")
6950   (let ((backward (< n 0))
6951         (n (abs n)))
6952     (while (and (> n 0)
6953                 (if backward
6954                     (gnus-summary-find-prev unread)
6955                   (gnus-summary-find-next unread)))
6956       (unless (zerop (setq n (1- n)))
6957         (gnus-summary-show-thread)))
6958     (when (/= 0 n)
6959       (gnus-message 7 "No more%s articles"
6960                     (if unread " unread" "")))
6961     (unless dont-display
6962       (gnus-summary-recenter)
6963       (gnus-summary-position-point))
6964     n))
6965
6966 (defun gnus-summary-next-unread-subject (n)
6967   "Go to next N'th unread summary line."
6968   (interactive "p")
6969   (gnus-summary-next-subject n t))
6970
6971 (defun gnus-summary-prev-subject (n &optional unread)
6972   "Go to previous N'th summary line.
6973 If optional argument UNREAD is non-nil, only unread article is selected."
6974   (interactive "p")
6975   (gnus-summary-next-subject (- n) unread))
6976
6977 (defun gnus-summary-prev-unread-subject (n)
6978   "Go to previous N'th unread summary line."
6979   (interactive "p")
6980   (gnus-summary-next-subject (- n) t))
6981
6982 (defun gnus-summary-goto-subjects (articles)
6983   "Insert the subject header for ARTICLES in the current buffer."
6984   (save-excursion
6985     (dolist (article articles)
6986       (gnus-summary-goto-subject article t)))
6987   (gnus-summary-limit (append articles gnus-newsgroup-limit))
6988   (gnus-summary-position-point))
6989  
6990 (defun gnus-summary-goto-subject (article &optional force silent)
6991   "Go the subject line of ARTICLE.
6992 If FORCE, also allow jumping to articles not currently shown."
6993   (interactive "nArticle number: ")
6994   (unless (numberp article)
6995     (error "Article %s is not a number" article))
6996   (let ((b (point))
6997         (data (gnus-data-find article)))
6998     ;; We read in the article if we have to.
6999     (and (not data)
7000          force
7001          (gnus-summary-insert-subject
7002           article
7003           (if (or (numberp force) (vectorp force)) force)
7004           t)
7005          (setq data (gnus-data-find article)))
7006     (goto-char b)
7007     (if (not data)
7008         (progn
7009           (unless silent
7010             (gnus-message 3 "Can't find article %d" article))
7011           nil)
7012       (let ((pt (gnus-data-pos data)))
7013         (goto-char pt)
7014         (gnus-summary-set-article-display-arrow pt))
7015       (gnus-summary-position-point)
7016       article)))
7017
7018 ;; Walking around summary lines with displaying articles.
7019
7020 (defun gnus-summary-expand-window (&optional arg)
7021   "Make the summary buffer take up the entire Emacs frame.
7022 Given a prefix, will force an `article' buffer configuration."
7023   (interactive "P")
7024   (if arg
7025       (gnus-configure-windows 'article 'force)
7026     (gnus-configure-windows 'summary 'force)))
7027
7028 (defun gnus-summary-display-article (article &optional all-header)
7029   "Display ARTICLE in article buffer."
7030   (when (gnus-buffer-live-p gnus-article-buffer)
7031     (with-current-buffer gnus-article-buffer
7032       (mm-enable-multibyte)))
7033   (gnus-set-global-variables)
7034   (when (gnus-buffer-live-p gnus-article-buffer)
7035     (with-current-buffer gnus-article-buffer
7036       (setq gnus-article-charset gnus-newsgroup-charset)
7037       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7038       (mm-enable-multibyte)))
7039   (if (null article)
7040       nil
7041     (prog1
7042         (if gnus-summary-display-article-function
7043             (funcall gnus-summary-display-article-function article all-header)
7044           (gnus-article-prepare article all-header))
7045       (gnus-run-hooks 'gnus-select-article-hook)
7046       (when (and gnus-current-article
7047                  (not (zerop gnus-current-article)))
7048         (gnus-summary-goto-subject gnus-current-article))
7049       (gnus-summary-recenter)
7050       (when (and gnus-use-trees gnus-show-threads)
7051         (gnus-possibly-generate-tree article)
7052         (gnus-highlight-selected-tree article))
7053       ;; Successfully display article.
7054       (gnus-article-set-window-start
7055        (cdr (assq article gnus-newsgroup-bookmarks))))))
7056
7057 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7058   "Select the current article.
7059 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7060 non-nil, the article will be re-fetched even if it already present in
7061 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7062 be displayed."
7063   ;; Make sure we are in the summary buffer to work around bbdb bug.
7064   (unless (eq major-mode 'gnus-summary-mode)
7065     (set-buffer gnus-summary-buffer))
7066   (let ((article (or article (gnus-summary-article-number)))
7067         (all-headers (not (not all-headers))) ;Must be t or nil.
7068         gnus-summary-display-article-function)
7069     (and (not pseudo)
7070          (gnus-summary-article-pseudo-p article)
7071          (error "This is a pseudo-article"))
7072     (save-excursion
7073       (set-buffer gnus-summary-buffer)
7074       (if (or (and gnus-single-article-buffer
7075                    (or (null gnus-current-article)
7076                        (null gnus-article-current)
7077                        (null (get-buffer gnus-article-buffer))
7078                        (not (eq article (cdr gnus-article-current)))
7079                        (not (equal (car gnus-article-current)
7080                                    gnus-newsgroup-name))))
7081               (and (not gnus-single-article-buffer)
7082                    (or (null gnus-current-article)
7083                        (not (eq gnus-current-article article))))
7084               force)
7085           ;; The requested article is different from the current article.
7086           (progn
7087             (gnus-summary-display-article article all-headers)
7088             (when (gnus-buffer-live-p gnus-article-buffer)
7089               (with-current-buffer gnus-article-buffer
7090                 (if (not gnus-article-decoded-p) ;; a local variable
7091                     (mm-disable-multibyte))))
7092             (gnus-article-set-window-start
7093              (cdr (assq article gnus-newsgroup-bookmarks)))
7094             article)
7095         'old))))
7096
7097 (defun gnus-summary-force-verify-and-decrypt ()
7098   "Display buttons for signed/encrypted parts and verify/decrypt them."
7099   (interactive)
7100   (let ((mm-verify-option 'known)
7101         (mm-decrypt-option 'known)
7102         (gnus-article-emulate-mime t)
7103         (gnus-buttonized-mime-types (append (list "multipart/signed"
7104                                                   "multipart/encrypted")
7105                                             gnus-buttonized-mime-types)))
7106     (gnus-summary-select-article nil 'force)))
7107
7108 (defun gnus-summary-set-current-mark (&optional current-mark)
7109   "Obsolete function."
7110   nil)
7111
7112 (defun gnus-summary-next-article (&optional unread subject backward push)
7113   "Select the next article.
7114 If UNREAD, only unread articles are selected.
7115 If SUBJECT, only articles with SUBJECT are selected.
7116 If BACKWARD, the previous article is selected instead of the next."
7117   (interactive "P")
7118   (cond
7119    ;; Is there such an article?
7120    ((and (gnus-summary-search-forward unread subject backward)
7121          (or (gnus-summary-display-article (gnus-summary-article-number))
7122              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7123     (gnus-summary-position-point))
7124    ;; If not, we try the first unread, if that is wanted.
7125    ((and subject
7126          gnus-auto-select-same
7127          (gnus-summary-first-unread-article))
7128     (gnus-summary-position-point)
7129     (gnus-message 6 "Wrapped"))
7130    ;; Try to get next/previous article not displayed in this group.
7131    ((and gnus-auto-extend-newsgroup
7132          (not unread) (not subject))
7133     (gnus-summary-goto-article
7134      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7135      nil (count-lines (point-min) (point))))
7136    ;; Go to next/previous group.
7137    (t
7138     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7139       (gnus-summary-jump-to-group gnus-newsgroup-name))
7140     (let ((cmd last-command-char)
7141           (point
7142            (save-excursion
7143              (set-buffer gnus-group-buffer)
7144              (point)))
7145           (group
7146            (if (eq gnus-keep-same-level 'best)
7147                (gnus-summary-best-group gnus-newsgroup-name)
7148              (gnus-summary-search-group backward gnus-keep-same-level))))
7149       ;; For some reason, the group window gets selected.  We change
7150       ;; it back.
7151       (select-window (get-buffer-window (current-buffer)))
7152       ;; Select next unread newsgroup automagically.
7153       (cond
7154        ((or (not gnus-auto-select-next)
7155             (not cmd))
7156         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7157        ((or (eq gnus-auto-select-next 'quietly)
7158             (and (eq gnus-auto-select-next 'slightly-quietly)
7159                  push)
7160             (and (eq gnus-auto-select-next 'almost-quietly)
7161                  (gnus-summary-last-article-p)))
7162         ;; Select quietly.
7163         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7164             (gnus-summary-exit)
7165           (gnus-message 7 "No more%s articles (%s)..."
7166                         (if unread " unread" "")
7167                         (if group (concat "selecting " group)
7168                           "exiting"))
7169           (gnus-summary-next-group nil group backward)))
7170        (t
7171         (when (gnus-key-press-event-p last-input-event)
7172           (gnus-summary-walk-group-buffer
7173            gnus-newsgroup-name cmd unread backward point))))))))
7174
7175 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7176   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7177                       (?\C-p (gnus-group-prev-unread-group 1))))
7178         (cursor-in-echo-area t)
7179         keve key group ended prompt)
7180     (save-excursion
7181       (set-buffer gnus-group-buffer)
7182       (goto-char start)
7183       (setq group
7184             (if (eq gnus-keep-same-level 'best)
7185                 (gnus-summary-best-group gnus-newsgroup-name)
7186               (gnus-summary-search-group backward gnus-keep-same-level))))
7187     (while (not ended)
7188       (setq prompt
7189             (format
7190              "No more%s articles%s " (if unread " unread" "")
7191              (if (and group
7192                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7193                  (format " (Type %s for %s [%s])"
7194                          (single-key-description cmd) group
7195                          (gnus-group-unread group))
7196                (format " (Type %s to exit %s)"
7197                        (single-key-description cmd)
7198                        gnus-newsgroup-name))))
7199       ;; Confirm auto selection.
7200       (setq key (car (setq keve (gnus-read-event-char prompt)))
7201             ended t)
7202       (cond
7203        ((assq key keystrokes)
7204         (let ((obuf (current-buffer)))
7205           (switch-to-buffer gnus-group-buffer)
7206           (when group
7207             (gnus-group-jump-to-group group))
7208           (eval (cadr (assq key keystrokes)))
7209           (setq group (gnus-group-group-name))
7210           (switch-to-buffer obuf))
7211         (setq ended nil))
7212        ((equal key cmd)
7213         (if (or (not group)
7214                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7215             (gnus-summary-exit)
7216           (gnus-summary-next-group nil group backward)))
7217        (t
7218         (push (cdr keve) unread-command-events))))))
7219
7220 (defun gnus-summary-next-unread-article ()
7221   "Select unread article after current one."
7222   (interactive)
7223   (gnus-summary-next-article
7224    (or (not (eq gnus-summary-goto-unread 'never))
7225        (gnus-summary-last-article-p (gnus-summary-article-number)))
7226    (and gnus-auto-select-same
7227         (gnus-summary-article-subject))))
7228
7229 (defun gnus-summary-prev-article (&optional unread subject)
7230   "Select the article after the current one.
7231 If UNREAD is non-nil, only unread articles are selected."
7232   (interactive "P")
7233   (gnus-summary-next-article unread subject t))
7234
7235 (defun gnus-summary-prev-unread-article ()
7236   "Select unread article before current one."
7237   (interactive)
7238   (gnus-summary-prev-article
7239    (or (not (eq gnus-summary-goto-unread 'never))
7240        (gnus-summary-first-article-p (gnus-summary-article-number)))
7241    (and gnus-auto-select-same
7242         (gnus-summary-article-subject))))
7243
7244 (defun gnus-summary-next-page (&optional lines circular stop)
7245   "Show next page of the selected article.
7246 If at the end of the current article, select the next article.
7247 LINES says how many lines should be scrolled up.
7248
7249 If CIRCULAR is non-nil, go to the start of the article instead of
7250 selecting the next article when reaching the end of the current
7251 article.
7252
7253 If STOP is non-nil, just stop when reaching the end of the message.
7254
7255 Also see the variable `gnus-article-skip-boring'."
7256   (interactive "P")
7257   (setq gnus-summary-buffer (current-buffer))
7258   (gnus-set-global-variables)
7259   (let ((article (gnus-summary-article-number))
7260         (article-window (get-buffer-window gnus-article-buffer t))
7261         endp)
7262     ;; If the buffer is empty, we have no article.
7263     (unless article
7264       (error "No article to select"))
7265     (gnus-configure-windows 'article)
7266     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7267         (if (and (eq gnus-summary-goto-unread 'never)
7268                  (not (gnus-summary-last-article-p article)))
7269             (gnus-summary-next-article)
7270           (gnus-summary-next-unread-article))
7271       (if (or (null gnus-current-article)
7272               (null gnus-article-current)
7273               (/= article (cdr gnus-article-current))
7274               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7275           ;; Selected subject is different from current article's.
7276           (gnus-summary-display-article article)
7277         (when article-window
7278           (gnus-eval-in-buffer-window gnus-article-buffer
7279             (setq endp (or (gnus-article-next-page lines)
7280                            (gnus-article-only-boring-p))))
7281           (when endp
7282             (cond (stop
7283                    (gnus-message 3 "End of message"))
7284                   (circular
7285                    (gnus-summary-beginning-of-article))
7286                   (lines
7287                    (gnus-message 3 "End of message"))
7288                   ((null lines)
7289                    (if (and (eq gnus-summary-goto-unread 'never)
7290                             (not (gnus-summary-last-article-p article)))
7291                        (gnus-summary-next-article)
7292                      (gnus-summary-next-unread-article))))))))
7293     (gnus-summary-recenter)
7294     (gnus-summary-position-point)))
7295
7296 (defun gnus-summary-prev-page (&optional lines move)
7297   "Show previous page of selected article.
7298 Argument LINES specifies lines to be scrolled down.
7299 If MOVE, move to the previous unread article if point is at
7300 the beginning of the buffer."
7301   (interactive "P")
7302   (let ((article (gnus-summary-article-number))
7303         (article-window (get-buffer-window gnus-article-buffer t))
7304         endp)
7305     (gnus-configure-windows 'article)
7306     (if (or (null gnus-current-article)
7307             (null gnus-article-current)
7308             (/= article (cdr gnus-article-current))
7309             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7310         ;; Selected subject is different from current article's.
7311         (gnus-summary-display-article article)
7312       (gnus-summary-recenter)
7313       (when article-window
7314         (gnus-eval-in-buffer-window gnus-article-buffer
7315           (setq endp (gnus-article-prev-page lines)))
7316         (when (and move endp)
7317           (cond (lines
7318                  (gnus-message 3 "Beginning of message"))
7319                 ((null lines)
7320                  (if (and (eq gnus-summary-goto-unread 'never)
7321                           (not (gnus-summary-first-article-p article)))
7322                      (gnus-summary-prev-article)
7323                    (gnus-summary-prev-unread-article))))))))
7324   (gnus-summary-position-point))
7325
7326 (defun gnus-summary-prev-page-or-article (&optional lines)
7327   "Show previous page of selected article.
7328 Argument LINES specifies lines to be scrolled down.
7329 If at the beginning of the article, go to the next article."
7330   (interactive "P")
7331   (gnus-summary-prev-page lines t))
7332
7333 (defun gnus-summary-scroll-up (lines)
7334   "Scroll up (or down) one line current article.
7335 Argument LINES specifies lines to be scrolled up (or down if negative)."
7336   (interactive "p")
7337   (gnus-configure-windows 'article)
7338   (gnus-summary-show-thread)
7339   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7340     (gnus-eval-in-buffer-window gnus-article-buffer
7341       (cond ((> lines 0)
7342              (when (gnus-article-next-page lines)
7343                (gnus-message 3 "End of message")))
7344             ((< lines 0)
7345              (gnus-article-prev-page (- lines))))))
7346   (gnus-summary-recenter)
7347   (gnus-summary-position-point))
7348
7349 (defun gnus-summary-scroll-down (lines)
7350   "Scroll down (or up) one line current article.
7351 Argument LINES specifies lines to be scrolled down (or up if negative)."
7352   (interactive "p")
7353   (gnus-summary-scroll-up (- lines)))
7354
7355 (defun gnus-summary-next-same-subject ()
7356   "Select next article which has the same subject as current one."
7357   (interactive)
7358   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7359
7360 (defun gnus-summary-prev-same-subject ()
7361   "Select previous article which has the same subject as current one."
7362   (interactive)
7363   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7364
7365 (defun gnus-summary-next-unread-same-subject ()
7366   "Select next unread article which has the same subject as current one."
7367   (interactive)
7368   (gnus-summary-next-article t (gnus-summary-article-subject)))
7369
7370 (defun gnus-summary-prev-unread-same-subject ()
7371   "Select previous unread article which has the same subject as current one."
7372   (interactive)
7373   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7374
7375 (defun gnus-summary-first-unread-article ()
7376   "Select the first unread article.
7377 Return nil if there are no unread articles."
7378   (interactive)
7379   (prog1
7380       (when (gnus-summary-first-subject t)
7381         (gnus-summary-show-thread)
7382         (gnus-summary-first-subject t)
7383         (gnus-summary-display-article (gnus-summary-article-number)))
7384     (gnus-summary-position-point)))
7385
7386 (defun gnus-summary-first-unread-subject ()
7387   "Place the point on the subject line of the first unread article.
7388 Return nil if there are no unread articles."
7389   (interactive)
7390   (prog1
7391       (when (gnus-summary-first-subject t)
7392         (gnus-summary-show-thread)
7393         (gnus-summary-first-subject t))
7394     (gnus-summary-position-point)))
7395
7396 (defun gnus-summary-first-unseen-subject ()
7397   "Place the point on the subject line of the first unseen article.
7398 Return nil if there are no unseen articles."
7399   (interactive)
7400   (prog1
7401       (when (gnus-summary-first-subject nil nil t)
7402         (gnus-summary-show-thread)
7403         (gnus-summary-first-subject nil nil t))
7404     (gnus-summary-position-point)))
7405
7406 (defun gnus-summary-first-unseen-or-unread-subject ()
7407   "Place the point on the subject line of the first unseen article or,
7408 if all article have been seen, on the subject line of the first unread
7409 article."
7410   (interactive)
7411   (prog1
7412       (unless (when (gnus-summary-first-subject nil nil t)
7413                 (gnus-summary-show-thread)
7414                 (gnus-summary-first-subject nil nil t))
7415         (when (gnus-summary-first-subject t)
7416           (gnus-summary-show-thread)
7417           (gnus-summary-first-subject t)))
7418     (gnus-summary-position-point)))
7419
7420 (defun gnus-summary-first-article ()
7421   "Select the first article.
7422 Return nil if there are no articles."
7423   (interactive)
7424   (prog1
7425       (when (gnus-summary-first-subject)
7426         (gnus-summary-show-thread)
7427         (gnus-summary-first-subject)
7428         (gnus-summary-display-article (gnus-summary-article-number)))
7429     (gnus-summary-position-point)))
7430
7431 (defun gnus-summary-best-unread-article (&optional arg)
7432   "Select the unread article with the highest score.
7433 If given a prefix argument, select the next unread article that has a
7434 score higher than the default score."
7435   (interactive "P")
7436   (let ((article (if arg
7437                      (gnus-summary-better-unread-subject)
7438                    (gnus-summary-best-unread-subject))))
7439     (if article
7440         (gnus-summary-goto-article article)
7441       (error "No unread articles"))))
7442
7443 (defun gnus-summary-best-unread-subject ()
7444   "Select the unread subject with the highest score."
7445   (interactive)
7446   (let ((best -1000000)
7447         (data gnus-newsgroup-data)
7448         article score)
7449     (while data
7450       (and (gnus-data-unread-p (car data))
7451            (> (setq score
7452                     (gnus-summary-article-score (gnus-data-number (car data))))
7453               best)
7454            (setq best score
7455                  article (gnus-data-number (car data))))
7456       (setq data (cdr data)))
7457     (when article
7458       (gnus-summary-goto-subject article))
7459     (gnus-summary-position-point)
7460     article))
7461
7462 (defun gnus-summary-better-unread-subject ()
7463   "Select the first unread subject that has a score over the default score."
7464   (interactive)
7465   (let ((data gnus-newsgroup-data)
7466         article score)
7467     (while (and (setq article (gnus-data-number (car data)))
7468                 (or (gnus-data-read-p (car data))
7469                     (not (> (gnus-summary-article-score article)
7470                             gnus-summary-default-score))))
7471       (setq data (cdr data)))
7472     (when article
7473       (gnus-summary-goto-subject article))
7474     (gnus-summary-position-point)
7475     article))
7476
7477 (defun gnus-summary-last-subject ()
7478   "Go to the last displayed subject line in the group."
7479   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7480     (when article
7481       (gnus-summary-goto-subject article))))
7482
7483 (defun gnus-summary-goto-article (article &optional all-headers force)
7484   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7485 If ALL-HEADERS is non-nil, no header lines are hidden.
7486 If FORCE, go to the article even if it isn't displayed.  If FORCE
7487 is a number, it is the line the article is to be displayed on."
7488   (interactive
7489    (list
7490     (completing-read
7491      "Article number or Message-ID: "
7492      (mapcar (lambda (number) (list (int-to-string number)))
7493              gnus-newsgroup-limit))
7494     current-prefix-arg
7495     t))
7496   (prog1
7497       (if (and (stringp article)
7498                (string-match "@\\|%40" article))
7499           (gnus-summary-refer-article article)
7500         (when (stringp article)
7501           (setq article (string-to-number article)))
7502         (if (gnus-summary-goto-subject article force)
7503             (gnus-summary-display-article article all-headers)
7504           (gnus-message 4 "Couldn't go to article %s" article) nil))
7505     (gnus-summary-position-point)))
7506
7507 (defun gnus-summary-goto-last-article ()
7508   "Go to the previously read article."
7509   (interactive)
7510   (prog1
7511       (when gnus-last-article
7512         (gnus-summary-goto-article gnus-last-article nil t))
7513     (gnus-summary-position-point)))
7514
7515 (defun gnus-summary-pop-article (number)
7516   "Pop one article off the history and go to the previous.
7517 NUMBER articles will be popped off."
7518   (interactive "p")
7519   (let (to)
7520     (setq gnus-newsgroup-history
7521           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7522     (if to
7523         (gnus-summary-goto-article (car to) nil t)
7524       (error "Article history empty")))
7525   (gnus-summary-position-point))
7526
7527 ;; Summary commands and functions for limiting the summary buffer.
7528
7529 (defun gnus-summary-limit-to-articles (n)
7530   "Limit the summary buffer to the next N articles.
7531 If not given a prefix, use the process marked articles instead."
7532   (interactive "P")
7533   (prog1
7534       (let ((articles (gnus-summary-work-articles n)))
7535         (setq gnus-newsgroup-processable nil)
7536         (gnus-summary-limit articles))
7537     (gnus-summary-position-point)))
7538
7539 (defun gnus-summary-pop-limit (&optional total)
7540   "Restore the previous limit.
7541 If given a prefix, remove all limits."
7542   (interactive "P")
7543   (when total
7544     (setq gnus-newsgroup-limits
7545           (list (mapcar (lambda (h) (mail-header-number h))
7546                         gnus-newsgroup-headers))))
7547   (unless gnus-newsgroup-limits
7548     (error "No limit to pop"))
7549   (prog1
7550       (gnus-summary-limit nil 'pop)
7551     (gnus-summary-position-point)))
7552
7553 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7554   "Limit the summary buffer to articles that have subjects that match a regexp.
7555 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7556   (interactive
7557    (list (read-string (if current-prefix-arg
7558                           "Exclude subject (regexp): "
7559                         "Limit to subject (regexp): "))
7560          nil current-prefix-arg))
7561   (unless header
7562     (setq header "subject"))
7563   (when (not (equal "" subject))
7564     (prog1
7565         (let ((articles (gnus-summary-find-matching
7566                          (or header "subject") subject 'all nil nil
7567                          not-matching)))
7568           (unless articles
7569             (error "Found no matches for \"%s\"" subject))
7570           (gnus-summary-limit articles))
7571       (gnus-summary-position-point))))
7572
7573 (defun gnus-summary-limit-to-author (from &optional not-matching)
7574   "Limit the summary buffer to articles that have authors that match a regexp.
7575 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7576   (interactive
7577    (list (read-string (if current-prefix-arg
7578                           "Exclude author (regexp): "
7579                         "Limit to author (regexp): "))
7580          current-prefix-arg))
7581   (gnus-summary-limit-to-subject from "from" not-matching))
7582
7583 (defun gnus-summary-limit-to-age (age &optional younger-p)
7584   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7585 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7586 articles that are younger than AGE days."
7587   (interactive
7588    (let ((younger current-prefix-arg)
7589          (days-got nil)
7590          days)
7591      (while (not days-got)
7592        (setq days (if younger
7593                       (read-string "Limit to articles younger than (in days, older when negative): ")
7594                     (read-string
7595                      "Limit to articles older than (in days, younger when negative): ")))
7596        (when (> (length days) 0)
7597          (setq days (read days)))
7598        (if (numberp days)
7599            (progn
7600              (setq days-got t)
7601              (when (< days 0)
7602                (setq younger (not younger))
7603                (setq days (* days -1))))
7604          (message "Please enter a number.")
7605          (sleep-for 1)))
7606      (list days younger)))
7607   (prog1
7608       (let ((data gnus-newsgroup-data)
7609             (cutoff (days-to-time age))
7610             articles d date is-younger)
7611         (while (setq d (pop data))
7612           (when (and (vectorp (gnus-data-header d))
7613                      (setq date (mail-header-date (gnus-data-header d))))
7614             (setq is-younger (time-less-p
7615                               (time-since (condition-case ()
7616                                               (date-to-time date)
7617                                             (error '(0 0))))
7618                               cutoff))
7619             (when (if younger-p
7620                       is-younger
7621                     (not is-younger))
7622               (push (gnus-data-number d) articles))))
7623         (gnus-summary-limit (nreverse articles)))
7624     (gnus-summary-position-point)))
7625
7626 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7627   "Limit the summary buffer to articles that match an 'extra' header."
7628   (interactive
7629    (let ((header
7630           (intern
7631            (gnus-completing-read-with-default
7632             (symbol-name (car gnus-extra-headers))
7633             (if current-prefix-arg
7634                 "Exclude extra header:"
7635               "Limit extra header:")
7636             (mapcar (lambda (x)
7637                       (cons (symbol-name x) x))
7638                     gnus-extra-headers)
7639             nil
7640             t))))
7641      (list header
7642            (read-string (format "%s header %s (regexp): "
7643                                 (if current-prefix-arg "Exclude" "Limit to")
7644                                 header))
7645            current-prefix-arg)))
7646   (when (not (equal "" regexp))
7647     (prog1
7648         (let ((articles (gnus-summary-find-matching
7649                          (cons 'extra header) regexp 'all nil nil
7650                          not-matching)))
7651           (unless articles
7652             (error "Found no matches for \"%s\"" regexp))
7653           (gnus-summary-limit articles))
7654       (gnus-summary-position-point))))
7655
7656 (defun gnus-summary-limit-to-display-predicate ()
7657   "Limit the summary buffer to the predicated in the `display' group parameter."
7658   (interactive)
7659   (unless gnus-newsgroup-display
7660     (error "There is no `display' group parameter"))
7661   (let (articles)
7662     (dolist (number gnus-newsgroup-articles)
7663       (when (funcall gnus-newsgroup-display)
7664         (push number articles)))
7665     (gnus-summary-limit articles))
7666   (gnus-summary-position-point))
7667
7668 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7669 (make-obsolete
7670  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7671
7672 (defun gnus-summary-limit-to-unread (&optional all)
7673   "Limit the summary buffer to articles that are not marked as read.
7674 If ALL is non-nil, limit strictly to unread articles."
7675   (interactive "P")
7676   (if all
7677       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7678     (gnus-summary-limit-to-marks
7679      ;; Concat all the marks that say that an article is read and have
7680      ;; those removed.
7681      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7682            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7683            gnus-low-score-mark gnus-expirable-mark
7684            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7685            gnus-duplicate-mark gnus-souped-mark)
7686      'reverse)))
7687
7688 (defun gnus-summary-limit-to-replied (&optional unreplied)
7689   "Limit the summary buffer to replied articles.
7690 If UNREPLIED (the prefix), limit to unreplied articles."
7691   (interactive "P")
7692   (if unreplied
7693       (gnus-summary-limit
7694        (gnus-set-difference gnus-newsgroup-articles
7695         gnus-newsgroup-replied))
7696     (gnus-summary-limit gnus-newsgroup-replied))
7697   (gnus-summary-position-point))
7698
7699 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7700 (make-obsolete 'gnus-summary-delete-marked-with
7701                'gnus-summary-limit-exclude-marks)
7702
7703 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7704   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7705 If REVERSE, limit the summary buffer to articles that are marked
7706 with MARKS.  MARKS can either be a string of marks or a list of marks.
7707 Returns how many articles were removed."
7708   (interactive "sMarks: ")
7709   (gnus-summary-limit-to-marks marks t))
7710
7711 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7712   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7713 If REVERSE (the prefix), limit the summary buffer to articles that are
7714 not marked with MARKS.  MARKS can either be a string of marks or a
7715 list of marks.
7716 Returns how many articles were removed."
7717   (interactive "sMarks: \nP")
7718   (prog1
7719       (let ((data gnus-newsgroup-data)
7720             (marks (if (listp marks) marks
7721                      (append marks nil))) ; Transform to list.
7722             articles)
7723         (while data
7724           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7725                   (memq (gnus-data-mark (car data)) marks))
7726             (push (gnus-data-number (car data)) articles))
7727           (setq data (cdr data)))
7728         (gnus-summary-limit articles))
7729     (gnus-summary-position-point)))
7730
7731 (defun gnus-summary-limit-to-score (score)
7732   "Limit to articles with score at or above SCORE."
7733   (interactive "NLimit to articles with score of at least: ")
7734   (let ((data gnus-newsgroup-data)
7735         articles)
7736     (while data
7737       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7738                 score)
7739         (push (gnus-data-number (car data)) articles))
7740       (setq data (cdr data)))
7741     (prog1
7742         (gnus-summary-limit articles)
7743       (gnus-summary-position-point))))
7744
7745 (defun gnus-summary-limit-to-unseen ()
7746   "Limit to unseen articles."
7747   (interactive)
7748   (prog1
7749       (gnus-summary-limit gnus-newsgroup-unseen)
7750     (gnus-summary-position-point)))
7751
7752 (defun gnus-summary-limit-include-thread (id)
7753   "Display all the hidden articles that is in the thread with ID in it.
7754 When called interactively, ID is the Message-ID of the current
7755 article."
7756   (interactive (list (mail-header-id (gnus-summary-article-header))))
7757   (let ((articles (gnus-articles-in-thread
7758                    (gnus-id-to-thread (gnus-root-id id)))))
7759     (prog1
7760         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7761       (gnus-summary-limit-include-matching-articles
7762        "subject"
7763        (regexp-quote (gnus-simplify-subject-re
7764                       (mail-header-subject (gnus-id-to-header id)))))
7765       (gnus-summary-position-point))))
7766
7767 (defun gnus-summary-limit-include-matching-articles (header regexp)
7768   "Display all the hidden articles that have HEADERs that match REGEXP."
7769   (interactive (list (read-string "Match on header: ")
7770                      (read-string "Regexp: ")))
7771   (let ((articles (gnus-find-matching-articles header regexp)))
7772     (prog1
7773         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7774       (gnus-summary-position-point))))
7775
7776 (defun gnus-summary-insert-dormant-articles ()
7777   "Insert all the dormant articles for this group into the current buffer."
7778   (interactive)
7779   (let ((gnus-verbose (max 6 gnus-verbose)))
7780     (if (not gnus-newsgroup-dormant)
7781         (gnus-message 3 "No cached articles for this group")
7782       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7783
7784 (defun gnus-summary-limit-include-dormant ()
7785   "Display all the hidden articles that are marked as dormant.
7786 Note that this command only works on a subset of the articles currently
7787 fetched for this group."
7788   (interactive)
7789   (unless gnus-newsgroup-dormant
7790     (error "There are no dormant articles in this group"))
7791   (prog1
7792       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7793     (gnus-summary-position-point)))
7794
7795 (defun gnus-summary-limit-exclude-dormant ()
7796   "Hide all dormant articles."
7797   (interactive)
7798   (prog1
7799       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7800     (gnus-summary-position-point)))
7801
7802 (defun gnus-summary-limit-exclude-childless-dormant ()
7803   "Hide all dormant articles that have no children."
7804   (interactive)
7805   (let ((data (gnus-data-list t))
7806         articles d children)
7807     ;; Find all articles that are either not dormant or have
7808     ;; children.
7809     (while (setq d (pop data))
7810       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7811                 (and (setq children
7812                            (gnus-article-children (gnus-data-number d)))
7813                      (let (found)
7814                        (while children
7815                          (when (memq (car children) articles)
7816                            (setq children nil
7817                                  found t))
7818                          (pop children))
7819                        found)))
7820         (push (gnus-data-number d) articles)))
7821     ;; Do the limiting.
7822     (prog1
7823         (gnus-summary-limit articles)
7824       (gnus-summary-position-point))))
7825
7826 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7827   "Mark all unread excluded articles as read.
7828 If ALL, mark even excluded ticked and dormants as read."
7829   (interactive "P")
7830   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7831   (let ((articles (gnus-sorted-ndifference
7832                    (sort
7833                     (mapcar (lambda (h) (mail-header-number h))
7834                             gnus-newsgroup-headers)
7835                     '<)
7836                    gnus-newsgroup-limit))
7837         article)
7838     (setq gnus-newsgroup-unreads
7839           (gnus-sorted-intersection gnus-newsgroup-unreads
7840                                     gnus-newsgroup-limit))
7841     (if all
7842         (setq gnus-newsgroup-dormant nil
7843               gnus-newsgroup-marked nil
7844               gnus-newsgroup-reads
7845               (nconc
7846                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
7847                gnus-newsgroup-reads))
7848       (while (setq article (pop articles))
7849         (unless (or (memq article gnus-newsgroup-dormant)
7850                     (memq article gnus-newsgroup-marked))
7851           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
7852
7853 (defun gnus-summary-limit (articles &optional pop)
7854   (if pop
7855       ;; We pop the previous limit off the stack and use that.
7856       (setq articles (car gnus-newsgroup-limits)
7857             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
7858     ;; We use the new limit, so we push the old limit on the stack.
7859     (push gnus-newsgroup-limit gnus-newsgroup-limits))
7860   ;; Set the limit.
7861   (setq gnus-newsgroup-limit articles)
7862   (let ((total (length gnus-newsgroup-data))
7863         (data (gnus-data-find-list (gnus-summary-article-number)))
7864         (gnus-summary-mark-below nil)   ; Inhibit this.
7865         found)
7866     ;; This will do all the work of generating the new summary buffer
7867     ;; according to the new limit.
7868     (gnus-summary-prepare)
7869     ;; Hide any threads, possibly.
7870     (gnus-summary-maybe-hide-threads)
7871     ;; Try to return to the article you were at, or one in the
7872     ;; neighborhood.
7873     (when data
7874       ;; We try to find some article after the current one.
7875       (while data
7876         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
7877           (setq data nil
7878                 found t))
7879         (setq data (cdr data))))
7880     (unless found
7881       ;; If there is no data, that means that we were after the last
7882       ;; article.  The same goes when we can't find any articles
7883       ;; after the current one.
7884       (goto-char (point-max))
7885       (gnus-summary-find-prev))
7886     (gnus-set-mode-line 'summary)
7887     ;; We return how many articles were removed from the summary
7888     ;; buffer as a result of the new limit.
7889     (- total (length gnus-newsgroup-data))))
7890
7891 (defsubst gnus-invisible-cut-children (threads)
7892   (let ((num 0))
7893     (while threads
7894       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
7895         (incf num))
7896       (pop threads))
7897     (< num 2)))
7898
7899 (defsubst gnus-cut-thread (thread)
7900   "Go forwards in the thread until we find an article that we want to display."
7901   (when (or (eq gnus-fetch-old-headers 'some)
7902             (eq gnus-fetch-old-headers 'invisible)
7903             (numberp gnus-fetch-old-headers)
7904             (eq gnus-build-sparse-threads 'some)
7905             (eq gnus-build-sparse-threads 'more))
7906     ;; Deal with old-fetched headers and sparse threads.
7907     (while (and
7908             thread
7909             (or
7910              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
7911              (gnus-summary-article-ancient-p
7912               (mail-header-number (car thread))))
7913             (if (or (<= (length (cdr thread)) 1)
7914                     (eq gnus-fetch-old-headers 'invisible))
7915                 (setq gnus-newsgroup-limit
7916                       (delq (mail-header-number (car thread))
7917                             gnus-newsgroup-limit)
7918                       thread (cadr thread))
7919               (when (gnus-invisible-cut-children (cdr thread))
7920                 (let ((th (cdr thread)))
7921                   (while th
7922                     (if (memq (mail-header-number (caar th))
7923                               gnus-newsgroup-limit)
7924                         (setq thread (car th)
7925                               th nil)
7926                       (setq th (cdr th))))))))))
7927   thread)
7928
7929 (defun gnus-cut-threads (threads)
7930   "Cut off all uninteresting articles from the beginning of THREADS."
7931   (when (or (eq gnus-fetch-old-headers 'some)
7932             (eq gnus-fetch-old-headers 'invisible)
7933             (numberp gnus-fetch-old-headers)
7934             (eq gnus-build-sparse-threads 'some)
7935             (eq gnus-build-sparse-threads 'more))
7936     (let ((th threads))
7937       (while th
7938         (setcar th (gnus-cut-thread (car th)))
7939         (setq th (cdr th)))))
7940   ;; Remove nixed out threads.
7941   (delq nil threads))
7942
7943 (defun gnus-summary-initial-limit (&optional show-if-empty)
7944   "Figure out what the initial limit is supposed to be on group entry.
7945 This entails weeding out unwanted dormants, low-scored articles,
7946 fetch-old-headers verbiage, and so on."
7947   ;; Most groups have nothing to remove.
7948   (if (or gnus-inhibit-limiting
7949           (and (null gnus-newsgroup-dormant)
7950                (eq gnus-newsgroup-display 'gnus-not-ignore)
7951                (not (eq gnus-fetch-old-headers 'some))
7952                (not (numberp gnus-fetch-old-headers))
7953                (not (eq gnus-fetch-old-headers 'invisible))
7954                (null gnus-summary-expunge-below)
7955                (not (eq gnus-build-sparse-threads 'some))
7956                (not (eq gnus-build-sparse-threads 'more))
7957                (null gnus-thread-expunge-below)
7958                (not gnus-use-nocem)))
7959       ()                                ; Do nothing.
7960     (push gnus-newsgroup-limit gnus-newsgroup-limits)
7961     (setq gnus-newsgroup-limit nil)
7962     (mapatoms
7963      (lambda (node)
7964        (unless (car (symbol-value node))
7965          ;; These threads have no parents -- they are roots.
7966          (let ((nodes (cdr (symbol-value node)))
7967                thread)
7968            (while nodes
7969              (if (and gnus-thread-expunge-below
7970                       (< (gnus-thread-total-score (car nodes))
7971                          gnus-thread-expunge-below))
7972                  (gnus-expunge-thread (pop nodes))
7973                (setq thread (pop nodes))
7974                (gnus-summary-limit-children thread))))))
7975      gnus-newsgroup-dependencies)
7976     ;; If this limitation resulted in an empty group, we might
7977     ;; pop the previous limit and use it instead.
7978     (when (and (not gnus-newsgroup-limit)
7979                show-if-empty)
7980       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
7981     gnus-newsgroup-limit))
7982
7983 (defun gnus-summary-limit-children (thread)
7984   "Return 1 if this subthread is visible and 0 if it is not."
7985   ;; First we get the number of visible children to this thread.  This
7986   ;; is done by recursing down the thread using this function, so this
7987   ;; will really go down to a leaf article first, before slowly
7988   ;; working its way up towards the root.
7989   (when thread
7990     (let* ((max-lisp-eval-depth 5000)
7991            (children
7992            (if (cdr thread)
7993                (apply '+ (mapcar 'gnus-summary-limit-children
7994                                  (cdr thread)))
7995              0))
7996           (number (mail-header-number (car thread)))
7997           score)
7998       (if (and
7999            (not (memq number gnus-newsgroup-marked))
8000            (or
8001             ;; If this article is dormant and has absolutely no visible
8002             ;; children, then this article isn't visible.
8003             (and (memq number gnus-newsgroup-dormant)
8004                  (zerop children))
8005             ;; If this is "fetch-old-headered" and there is no
8006             ;; visible children, then we don't want this article.
8007             (and (or (eq gnus-fetch-old-headers 'some)
8008                      (numberp gnus-fetch-old-headers))
8009                  (gnus-summary-article-ancient-p number)
8010                  (zerop children))
8011             ;; If this is "fetch-old-headered" and `invisible', then
8012             ;; we don't want this article.
8013             (and (eq gnus-fetch-old-headers 'invisible)
8014                  (gnus-summary-article-ancient-p number))
8015             ;; If this is a sparsely inserted article with no children,
8016             ;; we don't want it.
8017             (and (eq gnus-build-sparse-threads 'some)
8018                  (gnus-summary-article-sparse-p number)
8019                  (zerop children))
8020             ;; If we use expunging, and this article is really
8021             ;; low-scored, then we don't want this article.
8022             (when (and gnus-summary-expunge-below
8023                        (< (setq score
8024                                 (or (cdr (assq number gnus-newsgroup-scored))
8025                                     gnus-summary-default-score))
8026                           gnus-summary-expunge-below))
8027               ;; We increase the expunge-tally here, but that has
8028               ;; nothing to do with the limits, really.
8029               (incf gnus-newsgroup-expunged-tally)
8030               ;; We also mark as read here, if that's wanted.
8031               (when (and gnus-summary-mark-below
8032                          (< score gnus-summary-mark-below))
8033                 (setq gnus-newsgroup-unreads
8034                       (delq number gnus-newsgroup-unreads))
8035                 (if gnus-newsgroup-auto-expire
8036                     (push number gnus-newsgroup-expirable)
8037                   (push (cons number gnus-low-score-mark)
8038                         gnus-newsgroup-reads)))
8039               t)
8040             ;; Do the `display' group parameter.
8041             (and gnus-newsgroup-display
8042                  (not (funcall gnus-newsgroup-display)))
8043             ;; Check NoCeM things.
8044             (when (and gnus-use-nocem
8045                        (gnus-nocem-unwanted-article-p
8046                         (mail-header-id (car thread))))
8047               (setq gnus-newsgroup-unreads
8048                     (delq number gnus-newsgroup-unreads))
8049               t)))
8050           ;; Nope, invisible article.
8051           0
8052         ;; Ok, this article is to be visible, so we add it to the limit
8053         ;; and return 1.
8054         (push number gnus-newsgroup-limit)
8055         1))))
8056
8057 (defun gnus-expunge-thread (thread)
8058   "Mark all articles in THREAD as read."
8059   (let* ((number (mail-header-number (car thread))))
8060     (incf gnus-newsgroup-expunged-tally)
8061     ;; We also mark as read here, if that's wanted.
8062     (setq gnus-newsgroup-unreads
8063           (delq number gnus-newsgroup-unreads))
8064     (if gnus-newsgroup-auto-expire
8065         (push number gnus-newsgroup-expirable)
8066       (push (cons number gnus-low-score-mark)
8067             gnus-newsgroup-reads)))
8068   ;; Go recursively through all subthreads.
8069   (mapcar 'gnus-expunge-thread (cdr thread)))
8070
8071 ;; Summary article oriented commands
8072
8073 (defun gnus-summary-refer-parent-article (n)
8074   "Refer parent article N times.
8075 If N is negative, go to ancestor -N instead.
8076 The difference between N and the number of articles fetched is returned."
8077   (interactive "p")
8078   (let ((skip 1)
8079         error header ref)
8080     (when (not (natnump n))
8081       (setq skip (abs n)
8082             n 1))
8083     (while (and (> n 0)
8084                 (not error))
8085       (setq header (gnus-summary-article-header))
8086       (if (and (eq (mail-header-number header)
8087                    (cdr gnus-article-current))
8088                (equal gnus-newsgroup-name
8089                       (car gnus-article-current)))
8090           ;; If we try to find the parent of the currently
8091           ;; displayed article, then we take a look at the actual
8092           ;; References header, since this is slightly more
8093           ;; reliable than the References field we got from the
8094           ;; server.
8095           (save-excursion
8096             (set-buffer gnus-original-article-buffer)
8097             (nnheader-narrow-to-headers)
8098             (unless (setq ref (message-fetch-field "references"))
8099               (when (setq ref (message-fetch-field "in-reply-to"))
8100                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8101             (widen))
8102         (setq ref
8103               ;; It's not the current article, so we take a bet on
8104               ;; the value we got from the server.
8105               (mail-header-references header)))
8106       (if (and ref
8107                (not (equal ref "")))
8108           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8109             (gnus-message 1 "Couldn't find parent"))
8110         (gnus-message 1 "No references in article %d"
8111                       (gnus-summary-article-number))
8112         (setq error t))
8113       (decf n))
8114     (gnus-summary-position-point)
8115     n))
8116
8117 (defun gnus-summary-refer-references ()
8118   "Fetch all articles mentioned in the References header.
8119 Return the number of articles fetched."
8120   (interactive)
8121   (let ((ref (mail-header-references (gnus-summary-article-header)))
8122         (current (gnus-summary-article-number))
8123         (n 0))
8124     (if (or (not ref)
8125             (equal ref ""))
8126         (error "No References in the current article")
8127       ;; For each Message-ID in the References header...
8128       (while (string-match "<[^>]*>" ref)
8129         (incf n)
8130         ;; ... fetch that article.
8131         (gnus-summary-refer-article
8132          (prog1 (match-string 0 ref)
8133            (setq ref (substring ref (match-end 0))))))
8134       (gnus-summary-goto-subject current)
8135       (gnus-summary-position-point)
8136       n)))
8137
8138 (defun gnus-summary-refer-thread (&optional limit)
8139   "Fetch all articles in the current thread.
8140 If LIMIT (the numerical prefix), fetch that many old headers instead
8141 of what's specified by the `gnus-refer-thread-limit' variable."
8142   (interactive "P")
8143   (let ((id (mail-header-id (gnus-summary-article-header)))
8144         (limit (if limit (prefix-numeric-value limit)
8145                  gnus-refer-thread-limit)))
8146     (unless (eq gnus-fetch-old-headers 'invisible)
8147       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8148       ;; Retrieve the headers and read them in.
8149       (if (eq (if (numberp limit)
8150                   (gnus-retrieve-headers
8151                    (list (min
8152                           (+ (mail-header-number
8153                               (gnus-summary-article-header))
8154                              limit)
8155                           gnus-newsgroup-end))
8156                    gnus-newsgroup-name (* limit 2))
8157                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8158                 ;; headers.
8159                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8160                                        gnus-newsgroup-name limit))
8161               'nov)
8162           (gnus-build-all-threads)
8163         (error "Can't fetch thread from back ends that don't support NOV"))
8164       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8165     (gnus-summary-limit-include-thread id)))
8166
8167 (defun gnus-summary-refer-article (message-id)
8168   "Fetch an article specified by MESSAGE-ID."
8169   (interactive "sMessage-ID: ")
8170   (when (and (stringp message-id)
8171              (not (zerop (length message-id))))
8172     (setq message-id (gnus-replace-in-string message-id " " ""))
8173     ;; Construct the correct Message-ID if necessary.
8174     ;; Suggested by tale@pawl.rpi.edu.
8175     (unless (string-match "^<" message-id)
8176       (setq message-id (concat "<" message-id)))
8177     (unless (string-match ">$" message-id)
8178       (setq message-id (concat message-id ">")))
8179     ;; People often post MIDs from URLs, so unhex it:
8180     (unless (string-match "@" message-id)
8181       (setq message-id (gnus-url-unhex-string message-id)))
8182     (let* ((header (gnus-id-to-header message-id))
8183            (sparse (and header
8184                         (gnus-summary-article-sparse-p
8185                          (mail-header-number header))
8186                         (memq (mail-header-number header)
8187                               gnus-newsgroup-limit)))
8188            number)
8189       (cond
8190        ;; If the article is present in the buffer we just go to it.
8191        ((and header
8192              (or (not (gnus-summary-article-sparse-p
8193                        (mail-header-number header)))
8194                  sparse))
8195         (prog1
8196             (gnus-summary-goto-article
8197              (mail-header-number header) nil t)
8198           (when sparse
8199             (gnus-summary-update-article (mail-header-number header)))))
8200        (t
8201         ;; We fetch the article.
8202         (catch 'found
8203           (dolist (gnus-override-method (gnus-refer-article-methods))
8204             (when (and (gnus-check-server gnus-override-method)
8205                        ;; Fetch the header,
8206                        (setq number (gnus-summary-insert-subject message-id)))
8207               ;; and display the article.
8208               (gnus-summary-select-article nil nil nil number)
8209               (throw 'found t)))
8210           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8211
8212 (defun gnus-refer-article-methods ()
8213   "Return a list of referable methods."
8214   (cond
8215    ;; No method, so we default to current and native.
8216    ((null gnus-refer-article-method)
8217     (list gnus-current-select-method gnus-select-method))
8218    ;; Current.
8219    ((eq 'current gnus-refer-article-method)
8220     (list gnus-current-select-method))
8221    ;; List of select methods.
8222    ((not (and (symbolp (car gnus-refer-article-method))
8223               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8224     (let (out)
8225       (dolist (method gnus-refer-article-method)
8226         (push (if (eq 'current method)
8227                   gnus-current-select-method
8228                 method)
8229               out))
8230       (nreverse out)))
8231    ;; One single select method.
8232    (t
8233     (list gnus-refer-article-method))))
8234
8235 (defun gnus-summary-edit-parameters ()
8236   "Edit the group parameters of the current group."
8237   (interactive)
8238   (gnus-group-edit-group gnus-newsgroup-name 'params))
8239
8240 (defun gnus-summary-customize-parameters ()
8241   "Customize the group parameters of the current group."
8242   (interactive)
8243   (gnus-group-customize gnus-newsgroup-name))
8244
8245 (defun gnus-summary-enter-digest-group (&optional force)
8246   "Enter an nndoc group based on the current article.
8247 If FORCE, force a digest interpretation.  If not, try
8248 to guess what the document format is."
8249   (interactive "P")
8250   (let ((conf gnus-current-window-configuration))
8251     (save-window-excursion
8252       (save-excursion
8253         (let (gnus-article-prepare-hook
8254               gnus-display-mime-function
8255               gnus-break-pages)
8256           (gnus-summary-select-article))))
8257     (setq gnus-current-window-configuration conf)
8258     (let* ((name (format "%s-%d"
8259                          (gnus-group-prefixed-name
8260                           gnus-newsgroup-name (list 'nndoc ""))
8261                          (save-excursion
8262                            (set-buffer gnus-summary-buffer)
8263                            gnus-current-article)))
8264            (ogroup gnus-newsgroup-name)
8265            (params (append (gnus-info-params (gnus-get-info ogroup))
8266                            (list (cons 'to-group ogroup))
8267                            (list (cons 'parent-group ogroup))
8268                            (list (cons 'save-article-group ogroup))))
8269            (case-fold-search t)
8270            (buf (current-buffer))
8271            dig to-address)
8272       (save-excursion
8273         (set-buffer gnus-original-article-buffer)
8274         ;; Have the digest group inherit the main mail address of
8275         ;; the parent article.
8276         (when (setq to-address (or (gnus-fetch-field "reply-to")
8277                                    (gnus-fetch-field "from")))
8278           (setq params (append
8279                         (list (cons 'to-address
8280                                     (funcall gnus-decode-encoded-word-function
8281                                              to-address))))))
8282         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8283         (insert-buffer-substring gnus-original-article-buffer)
8284         ;; Remove lines that may lead nndoc to misinterpret the
8285         ;; document type.
8286         (narrow-to-region
8287          (goto-char (point-min))
8288          (or (search-forward "\n\n" nil t) (point)))
8289         (goto-char (point-min))
8290         (delete-matching-lines "^Path:\\|^From ")
8291         (widen))
8292       (unwind-protect
8293           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8294                     (gnus-newsgroup-ephemeral-ignored-charsets
8295                      gnus-newsgroup-ignored-charsets))
8296                 (gnus-group-read-ephemeral-group
8297                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8298                               (nndoc-article-type
8299                                ,(if force 'mbox 'guess)))
8300                  t nil nil nil
8301                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8302                                                         "ADAPT")))))
8303               ;; Make all postings to this group go to the parent group.
8304               (nconc (gnus-info-params (gnus-get-info name))
8305                      params)
8306             ;; Couldn't select this doc group.
8307             (switch-to-buffer buf)
8308             (gnus-set-global-variables)
8309             (gnus-configure-windows 'summary)
8310             (gnus-message 3 "Article couldn't be entered?"))
8311         (kill-buffer dig)))))
8312
8313 (defun gnus-summary-read-document (n)
8314   "Open a new group based on the current article(s).
8315 This will allow you to read digests and other similar
8316 documents as newsgroups.
8317 Obeys the standard process/prefix convention."
8318   (interactive "P")
8319   (let* ((articles (gnus-summary-work-articles n))
8320          (ogroup gnus-newsgroup-name)
8321          (params (append (gnus-info-params (gnus-get-info ogroup))
8322                          (list (cons 'to-group ogroup))))
8323          article group egroup groups vgroup)
8324     (while (setq article (pop articles))
8325       (setq group (format "%s-%d" gnus-newsgroup-name article))
8326       (gnus-summary-remove-process-mark article)
8327       (when (gnus-summary-display-article article)
8328         (save-excursion
8329           (with-temp-buffer
8330             (insert-buffer-substring gnus-original-article-buffer)
8331             ;; Remove some headers that may lead nndoc to make
8332             ;; the wrong guess.
8333             (message-narrow-to-head)
8334             (goto-char (point-min))
8335             (delete-matching-lines "^Path:\\|^From ")
8336             (widen)
8337             (if (setq egroup
8338                       (gnus-group-read-ephemeral-group
8339                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8340                                      (nndoc-article-type guess))
8341                        t nil t))
8342                 (progn
8343             ;; Make all postings to this group go to the parent group.
8344                   (nconc (gnus-info-params (gnus-get-info egroup))
8345                          params)
8346                   (push egroup groups))
8347               ;; Couldn't select this doc group.
8348               (gnus-error 3 "Article couldn't be entered"))))))
8349     ;; Now we have selected all the documents.
8350     (cond
8351      ((not groups)
8352       (error "None of the articles could be interpreted as documents"))
8353      ((gnus-group-read-ephemeral-group
8354        (setq vgroup (format
8355                      "nnvirtual:%s-%s" gnus-newsgroup-name
8356                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8357        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8358        t
8359        (cons (current-buffer) 'summary)))
8360      (t
8361       (error "Couldn't select virtual nndoc group")))))
8362
8363 (defun gnus-summary-isearch-article (&optional regexp-p)
8364   "Do incremental search forward on the current article.
8365 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8366   (interactive "P")
8367   (gnus-summary-select-article)
8368   (gnus-configure-windows 'article)
8369   (gnus-eval-in-buffer-window gnus-article-buffer
8370     (save-restriction
8371       (widen)
8372       (isearch-forward regexp-p))))
8373
8374 (defun gnus-summary-search-article-forward (regexp &optional backward)
8375   "Search for an article containing REGEXP forward.
8376 If BACKWARD, search backward instead."
8377   (interactive
8378    (list (read-string
8379           (format "Search article %s (regexp%s): "
8380                   (if current-prefix-arg "backward" "forward")
8381                   (if gnus-last-search-regexp
8382                       (concat ", default " gnus-last-search-regexp)
8383                     "")))
8384          current-prefix-arg))
8385   (if (string-equal regexp "")
8386       (setq regexp (or gnus-last-search-regexp ""))
8387     (setq gnus-last-search-regexp regexp)
8388     (setq gnus-article-before-search gnus-current-article))
8389   ;; Intentionally set gnus-last-article.
8390   (setq gnus-last-article gnus-article-before-search)
8391   (let ((gnus-last-article gnus-last-article))
8392     (if (gnus-summary-search-article regexp backward)
8393         (gnus-summary-show-thread)
8394       (error "Search failed: \"%s\"" regexp))))
8395
8396 (defun gnus-summary-search-article-backward (regexp)
8397   "Search for an article containing REGEXP backward."
8398   (interactive
8399    (list (read-string
8400           (format "Search article backward (regexp%s): "
8401                   (if gnus-last-search-regexp
8402                       (concat ", default " gnus-last-search-regexp)
8403                     "")))))
8404   (gnus-summary-search-article-forward regexp 'backward))
8405
8406 (defun gnus-summary-search-article (regexp &optional backward)
8407   "Search for an article containing REGEXP.
8408 Optional argument BACKWARD means do search for backward.
8409 `gnus-select-article-hook' is not called during the search."
8410   ;; We have to require this here to make sure that the following
8411   ;; dynamic binding isn't shadowed by autoloading.
8412   (require 'gnus-async)
8413   (require 'gnus-art)
8414   (let ((gnus-select-article-hook nil)  ;Disable hook.
8415         (gnus-article-prepare-hook nil)
8416         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8417         (gnus-use-article-prefetch nil)
8418         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8419         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8420         (gnus-visual nil)
8421         (gnus-keep-backlog nil)
8422         (gnus-break-pages nil)
8423         (gnus-summary-display-arrow nil)
8424         (gnus-updated-mode-lines nil)
8425         (gnus-auto-center-summary nil)
8426         (sum (current-buffer))
8427         (gnus-display-mime-function nil)
8428         (found nil)
8429         point)
8430     (gnus-save-hidden-threads
8431       (gnus-summary-select-article)
8432       (set-buffer gnus-article-buffer)
8433       (goto-char (window-point (get-buffer-window (current-buffer))))
8434       (when backward
8435         (forward-line -1))
8436       (while (not found)
8437         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8438         (if (if backward
8439                 (re-search-backward regexp nil t)
8440               (re-search-forward regexp nil t))
8441             ;; We found the regexp.
8442             (progn
8443               (setq found 'found)
8444               (beginning-of-line)
8445               (set-window-start
8446                (get-buffer-window (current-buffer))
8447                (point))
8448               (forward-line 1)
8449               (set-window-point
8450                (get-buffer-window (current-buffer))
8451                (point))
8452               (set-buffer sum)
8453               (setq point (point)))
8454           ;; We didn't find it, so we go to the next article.
8455           (set-buffer sum)
8456           (setq found 'not)
8457           (while (eq found 'not)
8458             (if (not (if backward (gnus-summary-find-prev)
8459                        (gnus-summary-find-next)))
8460                 ;; No more articles.
8461                 (setq found t)
8462               ;; Select the next article and adjust point.
8463               (unless (gnus-summary-article-sparse-p
8464                        (gnus-summary-article-number))
8465                 (setq found nil)
8466                 (gnus-summary-select-article)
8467                 (set-buffer gnus-article-buffer)
8468                 (widen)
8469                 (goto-char (if backward (point-max) (point-min))))))))
8470       (gnus-message 7 ""))
8471     ;; Return whether we found the regexp.
8472     (when (eq found 'found)
8473       (goto-char point)
8474       (gnus-summary-show-thread)
8475       (gnus-summary-goto-subject gnus-current-article)
8476       (gnus-summary-position-point)
8477       t)))
8478
8479 (defun gnus-find-matching-articles (header regexp)
8480   "Return a list of all articles that match REGEXP on HEADER.
8481 This search includes all articles in the current group that Gnus has
8482 fetched headers for, whether they are displayed or not."
8483   (let ((articles nil)
8484         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8485         (case-fold-search t))
8486     (dolist (header gnus-newsgroup-headers)
8487       (when (string-match regexp (funcall func header))
8488         (push (mail-header-number header) articles)))
8489     (nreverse articles)))
8490
8491 (defun gnus-summary-find-matching (header regexp &optional backward unread
8492                                           not-case-fold not-matching)
8493   "Return a list of all articles that match REGEXP on HEADER.
8494 The search stars on the current article and goes forwards unless
8495 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8496 If UNREAD is non-nil, only unread articles will
8497 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8498 in the comparisons. If NOT-MATCHING, return a list of all articles that
8499 not match REGEXP on HEADER."
8500   (let ((case-fold-search (not not-case-fold))
8501         articles d func)
8502     (if (consp header)
8503         (if (eq (car header) 'extra)
8504             (setq func
8505                   `(lambda (h)
8506                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8507                          "")))
8508           (error "%s is an invalid header" header))
8509       (unless (fboundp (intern (concat "mail-header-" header)))
8510         (error "%s is not a valid header" header))
8511       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8512     (dolist (d (if (eq backward 'all)
8513                    gnus-newsgroup-data
8514                  (gnus-data-find-list
8515                   (gnus-summary-article-number)
8516                   (gnus-data-list backward))))
8517       (when (and (or (not unread)       ; We want all articles...
8518                      (gnus-data-unread-p d)) ; Or just unreads.
8519                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8520                  (if not-matching
8521                      (not (string-match
8522                            regexp
8523                            (funcall func (gnus-data-header d))))
8524                    (string-match regexp
8525                                  (funcall func (gnus-data-header d)))))
8526         (push (gnus-data-number d) articles))) ; Success!
8527     (nreverse articles)))
8528
8529 (defun gnus-summary-execute-command (header regexp command &optional backward)
8530   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8531 If HEADER is an empty string (or nil), the match is done on the entire
8532 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8533   (interactive
8534    (list (let ((completion-ignore-case t))
8535            (completing-read
8536             "Header name: "
8537             (mapcar (lambda (header) (list (format "%s" header)))
8538                     (append
8539                      '("Number" "Subject" "From" "Lines" "Date"
8540                        "Message-ID" "Xref" "References" "Body")
8541                      gnus-extra-headers))
8542             nil 'require-match))
8543          (read-string "Regexp: ")
8544          (read-key-sequence "Command: ")
8545          current-prefix-arg))
8546   (when (equal header "Body")
8547     (setq header ""))
8548   ;; Hidden thread subtrees must be searched as well.
8549   (gnus-summary-show-all-threads)
8550   ;; We don't want to change current point nor window configuration.
8551   (save-excursion
8552     (save-window-excursion
8553       (let (gnus-visual
8554             gnus-treat-strip-trailing-blank-lines
8555             gnus-treat-strip-leading-blank-lines
8556             gnus-treat-strip-multiple-blank-lines
8557             gnus-treat-hide-boring-headers
8558             gnus-treat-fold-newsgroups
8559             gnus-article-prepare-hook)
8560         (gnus-message 6 "Executing %s..." (key-description command))
8561         ;; We'd like to execute COMMAND interactively so as to give arguments.
8562         (gnus-execute header regexp
8563                       `(call-interactively ',(key-binding command))
8564                       backward)
8565         (gnus-message 6 "Executing %s...done" (key-description command))))))
8566
8567 (defun gnus-summary-beginning-of-article ()
8568   "Scroll the article back to the beginning."
8569   (interactive)
8570   (gnus-summary-select-article)
8571   (gnus-configure-windows 'article)
8572   (gnus-eval-in-buffer-window gnus-article-buffer
8573     (widen)
8574     (goto-char (point-min))
8575     (when gnus-break-pages
8576       (gnus-narrow-to-page))))
8577
8578 (defun gnus-summary-end-of-article ()
8579   "Scroll to the end of the article."
8580   (interactive)
8581   (gnus-summary-select-article)
8582   (gnus-configure-windows 'article)
8583   (gnus-eval-in-buffer-window gnus-article-buffer
8584     (widen)
8585     (goto-char (point-max))
8586     (recenter -3)
8587     (when gnus-break-pages
8588       (when (re-search-backward page-delimiter nil t)
8589         (narrow-to-region (match-end 0) (point-max)))
8590       (gnus-narrow-to-page))))
8591
8592 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8593   "Truncate to LEN and quote all \"(\"'s in STRING."
8594   (gnus-replace-in-string (if (and len (> (length string) len))
8595                               (substring string 0 len)
8596                             string)
8597                           "[()]" "\\\\\\&"))
8598
8599 (defun gnus-summary-print-article (&optional filename n)
8600   "Generate and print a PostScript image of the process-marked (mail) articles.
8601
8602 If used interactively, print the current article if none are
8603 process-marked.  With prefix arg, prompt the user for the name of the
8604 file to save in.
8605
8606 When used from Lisp, accept two optional args FILENAME and N.  N means
8607 to print the next N articles.  If N is negative, print the N previous
8608 articles.  If N is nil and articles have been marked with the process
8609 mark, print these instead.
8610
8611 If the optional first argument FILENAME is nil, send the image to the
8612 printer.  If FILENAME is a string, save the PostScript image in a file with
8613 that name.  If FILENAME is a number, prompt the user for the name of the file
8614 to save in."
8615   (interactive (list (ps-print-preprint current-prefix-arg)))
8616   (dolist (article (gnus-summary-work-articles n))
8617     (gnus-summary-select-article nil nil 'pseudo article)
8618     (gnus-eval-in-buffer-window gnus-article-buffer
8619       (gnus-print-buffer))
8620     (gnus-summary-remove-process-mark article))
8621   (ps-despool filename))
8622
8623 (defun gnus-print-buffer ()
8624   (let ((buffer (generate-new-buffer " *print*")))
8625     (unwind-protect
8626         (progn
8627           (copy-to-buffer buffer (point-min) (point-max))
8628           (set-buffer buffer)
8629           (gnus-remove-text-with-property 'gnus-decoration)
8630           (when (gnus-visual-p 'article-highlight 'highlight)
8631             ;; Copy-to-buffer doesn't copy overlay.  So redo
8632             ;; highlight.
8633             (let ((gnus-article-buffer buffer))
8634               (gnus-article-highlight-citation t)
8635               (gnus-article-highlight-signature)
8636               (gnus-article-emphasize)
8637               (gnus-article-delete-invisible-text)))
8638           (let ((ps-left-header
8639                  (list
8640                   (concat "("
8641                           (gnus-summary-print-truncate-and-quote
8642                            (mail-header-subject gnus-current-headers)
8643                            66) ")")
8644                   (concat "("
8645                           (gnus-summary-print-truncate-and-quote
8646                            (mail-header-from gnus-current-headers)
8647                            45) ")")))
8648                 (ps-right-header
8649                  (list
8650                   "/pagenumberstring load"
8651                   (concat "("
8652                           (mail-header-date gnus-current-headers) ")"))))
8653             (gnus-run-hooks 'gnus-ps-print-hook)
8654             (save-excursion
8655               (if window-system
8656                   (ps-spool-buffer-with-faces)
8657                 (ps-spool-buffer)))))
8658       (kill-buffer buffer))))
8659
8660 (defun gnus-summary-show-article (&optional arg)
8661   "Force redisplaying of the current article.
8662 If ARG (the prefix) is a number, show the article with the charset
8663 defined in `gnus-summary-show-article-charset-alist', or the charset
8664 input.
8665 If ARG (the prefix) is non-nil and not a number, show the raw article
8666 without any article massaging functions being run.  Normally, the key
8667 strokes are `C-u g'."
8668   (interactive "P")
8669   (cond
8670    ((numberp arg)
8671     (gnus-summary-show-article t)
8672     (let ((gnus-newsgroup-charset
8673            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8674                (mm-read-coding-system
8675                 "View as charset: " ;; actually it is coding system.
8676                 (save-excursion
8677                   (set-buffer gnus-article-buffer)
8678                   (mm-detect-coding-region (point) (point-max))))))
8679           (gnus-newsgroup-ignored-charsets 'gnus-all))
8680       (gnus-summary-select-article nil 'force)
8681       (let ((deps gnus-newsgroup-dependencies)
8682             head header lines)
8683         (save-excursion
8684           (set-buffer gnus-original-article-buffer)
8685           (save-restriction
8686             (message-narrow-to-head)
8687             (setq head (buffer-string))
8688             (goto-char (point-min))
8689             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8690               (goto-char (point-max))
8691               (widen)
8692               (setq lines (1- (count-lines (point) (point-max))))))
8693           (with-temp-buffer
8694             (insert (format "211 %d Article retrieved.\n"
8695                             (cdr gnus-article-current)))
8696             (insert head)
8697             (if lines (insert (format "Lines: %d\n" lines)))
8698             (insert ".\n")
8699             (let ((nntp-server-buffer (current-buffer)))
8700               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8701         (gnus-data-set-header
8702          (gnus-data-find (cdr gnus-article-current))
8703          header)
8704         (gnus-summary-update-article-line
8705          (cdr gnus-article-current) header)
8706         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8707           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8708    ((not arg)
8709     ;; Select the article the normal way.
8710     (gnus-summary-select-article nil 'force))
8711    (t
8712     ;; We have to require this here to make sure that the following
8713     ;; dynamic binding isn't shadowed by autoloading.
8714     (require 'gnus-async)
8715     (require 'gnus-art)
8716     ;; Bind the article treatment functions to nil.
8717     (let ((gnus-have-all-headers t)
8718           gnus-article-prepare-hook
8719           gnus-article-decode-hook
8720           gnus-display-mime-function
8721           gnus-break-pages)
8722       ;; Destroy any MIME parts.
8723       (when (gnus-buffer-live-p gnus-article-buffer)
8724         (save-excursion
8725           (set-buffer gnus-article-buffer)
8726           (mm-destroy-parts gnus-article-mime-handles)
8727           ;; Set it to nil for safety reason.
8728           (setq gnus-article-mime-handle-alist nil)
8729           (setq gnus-article-mime-handles nil)))
8730       (gnus-summary-select-article nil 'force))))
8731   (gnus-summary-goto-subject gnus-current-article)
8732   (gnus-summary-position-point))
8733
8734 (defun gnus-summary-show-raw-article ()
8735   "Show the raw article without any article massaging functions being run."
8736   (interactive)
8737   (gnus-summary-show-article t))
8738
8739 (defun gnus-summary-verbose-headers (&optional arg)
8740   "Toggle permanent full header display.
8741 If ARG is a positive number, turn header display on.
8742 If ARG is a negative number, turn header display off."
8743   (interactive "P")
8744   (setq gnus-show-all-headers
8745         (cond ((or (not (numberp arg))
8746                    (zerop arg))
8747                (not gnus-show-all-headers))
8748               ((natnump arg)
8749                t)))
8750   (gnus-summary-show-article))
8751
8752 (defun gnus-summary-toggle-header (&optional arg)
8753   "Show the headers if they are hidden, or hide them if they are shown.
8754 If ARG is a positive number, show the entire header.
8755 If ARG is a negative number, hide the unwanted header lines."
8756   (interactive "P")
8757   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
8758                      (get-buffer-window gnus-article-buffer t))))
8759     (with-current-buffer gnus-article-buffer
8760       (widen)
8761       (article-narrow-to-head)
8762       (let* ((buffer-read-only nil)
8763              (inhibit-point-motion-hooks t)
8764              (hidden (if (numberp arg)
8765                          (>= arg 0)
8766                        (gnus-article-hidden-text-p 'headers)))
8767              s e)
8768         (delete-region (point-min) (point-max))
8769         (with-current-buffer gnus-original-article-buffer
8770           (goto-char (setq s (point-min)))
8771           (setq e (if (search-forward "\n\n" nil t)
8772                       (1- (point))
8773                     (point-max))))
8774         (insert-buffer-substring gnus-original-article-buffer s e)
8775         (run-hooks 'gnus-article-decode-hook)
8776         (if hidden
8777             (let ((gnus-treat-hide-headers nil)
8778                   (gnus-treat-hide-boring-headers nil))
8779               (gnus-delete-wash-type 'headers)
8780               (gnus-treat-article 'head))
8781           (gnus-treat-article 'head))
8782         (widen)
8783         (if window
8784             (set-window-start window (goto-char (point-min))))
8785         (if gnus-break-pages
8786             (gnus-narrow-to-page)
8787           (when (gnus-visual-p 'page-marker)
8788             (let ((buffer-read-only nil))
8789               (gnus-remove-text-with-property 'gnus-prev)
8790               (gnus-remove-text-with-property 'gnus-next))))
8791         (gnus-set-mode-line 'article)))))
8792
8793 (defun gnus-summary-show-all-headers ()
8794   "Make all header lines visible."
8795   (interactive)
8796   (gnus-summary-toggle-header 1))
8797
8798 (defun gnus-summary-caesar-message (&optional arg)
8799   "Caesar rotate the current article by 13.
8800 The numerical prefix specifies how many places to rotate each letter
8801 forward."
8802   (interactive "P")
8803   (gnus-summary-select-article)
8804   (let ((mail-header-separator ""))
8805     (gnus-eval-in-buffer-window gnus-article-buffer
8806       (save-restriction
8807         (widen)
8808         (let ((start (window-start))
8809               buffer-read-only)
8810           (message-caesar-buffer-body arg)
8811           (set-window-start (get-buffer-window (current-buffer)) start))))))
8812
8813 (autoload 'unmorse-region "morse"
8814   "Convert morse coded text in region to ordinary ASCII text."
8815   t)
8816
8817 (defun gnus-summary-morse-message (&optional arg)
8818   "Morse decode the current article."
8819   (interactive "P")
8820   (gnus-summary-select-article)
8821   (let ((mail-header-separator ""))
8822     (gnus-eval-in-buffer-window gnus-article-buffer
8823       (save-excursion
8824         (save-restriction
8825           (widen)
8826           (let ((pos (window-start))
8827                 buffer-read-only)
8828             (goto-char (point-min))
8829             (when (message-goto-body)
8830               (gnus-narrow-to-body))
8831             (goto-char (point-min))
8832             (while (re-search-forward "·" (point-max) t)
8833               (replace-match "."))
8834             (unmorse-region (point-min) (point-max))
8835             (widen)
8836             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
8837
8838 (defun gnus-summary-stop-page-breaking ()
8839   "Stop page breaking in the current article."
8840   (interactive)
8841   (gnus-summary-select-article)
8842   (gnus-eval-in-buffer-window gnus-article-buffer
8843     (widen)
8844     (when (gnus-visual-p 'page-marker)
8845       (let ((buffer-read-only nil))
8846         (gnus-remove-text-with-property 'gnus-prev)
8847         (gnus-remove-text-with-property 'gnus-next))
8848       (setq gnus-page-broken nil))))
8849
8850 (defun gnus-summary-move-article (&optional n to-newsgroup
8851                                             select-method action)
8852   "Move the current article to a different newsgroup.
8853 If N is a positive number, move the N next articles.
8854 If N is a negative number, move the N previous articles.
8855 If N is nil and any articles have been marked with the process mark,
8856 move those articles instead.
8857 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
8858 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
8859 re-spool using this method.
8860
8861 When called interactively with TO-NEWSGROUP being nil, the value of
8862 the variable `gnus-move-split-methods' is used for finding a default
8863 for the target newsgroup.
8864
8865 For this function to work, both the current newsgroup and the
8866 newsgroup that you want to move to have to support the `request-move'
8867 and `request-accept' functions.
8868
8869 ACTION can be either `move' (the default), `crosspost' or `copy'."
8870   (interactive "P")
8871   (unless action
8872     (setq action 'move))
8873   ;; Check whether the source group supports the required functions.
8874   (cond ((and (eq action 'move)
8875               (not (gnus-check-backend-function
8876                     'request-move-article gnus-newsgroup-name)))
8877          (error "The current group does not support article moving"))
8878         ((and (eq action 'crosspost)
8879               (not (gnus-check-backend-function
8880                     'request-replace-article gnus-newsgroup-name)))
8881          (error "The current group does not support article editing")))
8882   (let ((articles (gnus-summary-work-articles n))
8883         (prefix (if (gnus-check-backend-function
8884                      'request-move-article gnus-newsgroup-name)
8885                     (funcall gnus-move-group-prefix-function
8886                              gnus-newsgroup-name)
8887                   ""))
8888         (names '((move "Move" "Moving")
8889                  (copy "Copy" "Copying")
8890                  (crosspost "Crosspost" "Crossposting")))
8891         (copy-buf (save-excursion
8892                     (nnheader-set-temp-buffer " *copy article*")))
8893         art-group to-method new-xref article to-groups)
8894     (unless (assq action names)
8895       (error "Unknown action %s" action))
8896     ;; Read the newsgroup name.
8897     (when (and (not to-newsgroup)
8898                (not select-method))
8899       (if (and gnus-move-split-methods
8900                (not
8901                 (and (memq gnus-current-article articles)
8902                      (gnus-buffer-live-p gnus-original-article-buffer))))
8903           ;; When `gnus-move-split-methods' is non-nil, we have to
8904           ;; select an article to give `gnus-read-move-group-name' an
8905           ;; opportunity to suggest an appropriate default.  However,
8906           ;; we needn't render or mark the article.
8907           (let ((gnus-display-mime-function nil)
8908                 (gnus-article-prepare-hook nil)
8909                 (gnus-mark-article-hook nil))
8910             (gnus-summary-select-article nil nil nil (car articles))))
8911       (setq to-newsgroup
8912             (gnus-read-move-group-name
8913              (cadr (assq action names))
8914              (symbol-value (intern (format "gnus-current-%s-group" action)))
8915              articles prefix))
8916       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
8917     (setq to-method (or select-method
8918                         (gnus-server-to-method
8919                          (gnus-group-method to-newsgroup))))
8920     ;; Check the method we are to move this article to...
8921     (unless (gnus-check-backend-function
8922              'request-accept-article (car to-method))
8923       (error "%s does not support article copying" (car to-method)))
8924     (unless (gnus-check-server to-method)
8925       (error "Can't open server %s" (car to-method)))
8926     (gnus-message 6 "%s to %s: %s..."
8927                   (caddr (assq action names))
8928                   (or (car select-method) to-newsgroup) articles)
8929     (while articles
8930       (setq article (pop articles))
8931       (setq
8932        art-group
8933        (cond
8934         ;; Move the article.
8935         ((eq action 'move)
8936          ;; Remove this article from future suppression.
8937          (gnus-dup-unsuppress-article article)
8938          (gnus-request-move-article
8939           article                       ; Article to move
8940           gnus-newsgroup-name           ; From newsgroup
8941           (nth 1 (gnus-find-method-for-group
8942                   gnus-newsgroup-name)) ; Server
8943           (list 'gnus-request-accept-article
8944                 to-newsgroup (list 'quote select-method)
8945                 (not articles) t)       ; Accept form
8946           (not articles)))              ; Only save nov last time
8947         ;; Copy the article.
8948         ((eq action 'copy)
8949          (save-excursion
8950            (set-buffer copy-buf)
8951            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
8952              (gnus-request-accept-article
8953               to-newsgroup select-method (not articles) t))))
8954         ;; Crosspost the article.
8955         ((eq action 'crosspost)
8956          (let ((xref (message-tokenize-header
8957                       (mail-header-xref (gnus-summary-article-header article))
8958                       " ")))
8959            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
8960                                   ":" (number-to-string article)))
8961            (unless xref
8962              (setq xref (list (system-name))))
8963            (setq new-xref
8964                  (concat
8965                   (mapconcat 'identity
8966                              (delete "Xref:" (delete new-xref xref))
8967                              " ")
8968                   " " new-xref))
8969            (save-excursion
8970              (set-buffer copy-buf)
8971              ;; First put the article in the destination group.
8972              (gnus-request-article-this-buffer article gnus-newsgroup-name)
8973              (when (consp (setq art-group
8974                                 (gnus-request-accept-article
8975                                  to-newsgroup select-method (not articles))))
8976                (setq new-xref (concat new-xref " " (car art-group)
8977                                       ":"
8978                                       (number-to-string (cdr art-group))))
8979                ;; Now we have the new Xrefs header, so we insert
8980                ;; it and replace the new article.
8981                (nnheader-replace-header "Xref" new-xref)
8982                (gnus-request-replace-article
8983                 (cdr art-group) to-newsgroup (current-buffer))
8984                art-group))))))
8985       (cond
8986        ((not art-group)
8987         (gnus-message 1 "Couldn't %s article %s: %s"
8988                       (cadr (assq action names)) article
8989                       (nnheader-get-report (car to-method))))
8990        ((eq art-group 'junk)
8991         (when (eq action 'move)
8992           (gnus-summary-mark-article article gnus-canceled-mark)
8993           (gnus-message 4 "Deleted article %s" article)
8994           ;; run the delete hook
8995           (run-hook-with-args 'gnus-summary-article-delete-hook
8996                               action
8997                               (gnus-data-header
8998                                (assoc article (gnus-data-list nil)))
8999                               gnus-newsgroup-name nil
9000                               select-method)))
9001        (t
9002         (let* ((pto-group (gnus-group-prefixed-name
9003                            (car art-group) to-method))
9004                (info (gnus-get-info pto-group))
9005                (to-group (gnus-info-group info))
9006                to-marks)
9007           ;; Update the group that has been moved to.
9008           (when (and info
9009                      (memq action '(move copy)))
9010             (unless (member to-group to-groups)
9011               (push to-group to-groups))
9012
9013             (unless (memq article gnus-newsgroup-unreads)
9014               (push 'read to-marks)
9015               (gnus-info-set-read
9016                info (gnus-add-to-range (gnus-info-read info)
9017                                        (list (cdr art-group)))))
9018
9019             ;; See whether the article is to be put in the cache.
9020             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9021                              gnus-article-mark-lists
9022                            (delete '(expirable . expire)
9023                                    (copy-sequence gnus-article-mark-lists))))
9024                   (to-article (cdr art-group)))
9025
9026               ;; Enter the article into the cache in the new group,
9027               ;; if that is required.
9028               (when gnus-use-cache
9029                 (gnus-cache-possibly-enter-article
9030                  to-group to-article
9031                  (memq article gnus-newsgroup-marked)
9032                  (memq article gnus-newsgroup-dormant)
9033                  (memq article gnus-newsgroup-unreads)))
9034
9035               (when gnus-preserve-marks
9036                 ;; Copy any marks over to the new group.
9037                 (when (and (equal to-group gnus-newsgroup-name)
9038                            (not (memq article gnus-newsgroup-unreads)))
9039                   ;; Mark this article as read in this group.
9040                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9041                   (setcdr (gnus-active to-group) to-article)
9042                   (setcdr gnus-newsgroup-active to-article))
9043
9044                 (while marks
9045                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9046                     (when (memq article (symbol-value
9047                                          (intern (format "gnus-newsgroup-%s"
9048                                                          (caar marks)))))
9049                       (push (cdar marks) to-marks)
9050                       ;; If the other group is the same as this group,
9051                       ;; then we have to add the mark to the list.
9052                       (when (equal to-group gnus-newsgroup-name)
9053                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9054                              (cons to-article
9055                                    (symbol-value
9056                                     (intern (format "gnus-newsgroup-%s"
9057                                                     (caar marks)))))))
9058                       ;; Copy the marks to other group.
9059                       (gnus-add-marked-articles
9060                        to-group (cdar marks) (list to-article) info)))
9061                   (setq marks (cdr marks)))
9062
9063                 (gnus-request-set-mark
9064                  to-group (list (list (list to-article) 'add to-marks))))
9065
9066               (gnus-dribble-enter
9067                (concat "(gnus-group-set-info '"
9068                        (gnus-prin1-to-string (gnus-get-info to-group))
9069                        ")"))))
9070
9071           ;; Update the Xref header in this article to point to
9072           ;; the new crossposted article we have just created.
9073           (when (eq action 'crosspost)
9074             (save-excursion
9075               (set-buffer copy-buf)
9076               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9077               (nnheader-replace-header "Xref" new-xref)
9078               (gnus-request-replace-article
9079                article gnus-newsgroup-name (current-buffer))))
9080
9081           ;; run the move/copy/crosspost/respool hook
9082           (run-hook-with-args 'gnus-summary-article-move-hook
9083                               action
9084                               (gnus-data-header
9085                                (assoc article (gnus-data-list nil)))
9086                               gnus-newsgroup-name
9087                               to-newsgroup
9088                               select-method))
9089
9090         ;;;!!!Why is this necessary?
9091         (set-buffer gnus-summary-buffer)
9092         
9093         (gnus-summary-goto-subject article)
9094         (when (eq action 'move)
9095           (gnus-summary-mark-article article gnus-canceled-mark))))
9096       (gnus-summary-remove-process-mark article))
9097     ;; Re-activate all groups that have been moved to.
9098     (save-excursion
9099       (set-buffer gnus-group-buffer)
9100       (let ((gnus-group-marked to-groups))
9101         (gnus-group-get-new-news-this-group nil t)))
9102
9103     (gnus-kill-buffer copy-buf)
9104     (gnus-summary-position-point)
9105     (gnus-set-mode-line 'summary)))
9106
9107 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9108   "Move the current article to a different newsgroup.
9109 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9110 When called interactively, if TO-NEWSGROUP is nil, use the value of
9111 the variable `gnus-move-split-methods' for finding a default target
9112 newsgroup.
9113 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9114 re-spool using this method."
9115   (interactive "P")
9116   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9117
9118 (defun gnus-summary-crosspost-article (&optional n)
9119   "Crosspost the current article to some other group."
9120   (interactive "P")
9121   (gnus-summary-move-article n nil nil 'crosspost))
9122
9123 (defcustom gnus-summary-respool-default-method nil
9124   "Default method type for respooling an article.
9125 If nil, use to the current newsgroup method."
9126   :type 'symbol
9127   :group 'gnus-summary-mail)
9128
9129 (defcustom gnus-summary-display-while-building nil
9130   "If non-nil, show and update the summary buffer as it's being built.
9131 If the value is t, update the buffer after every line is inserted.  If
9132 the value is an integer (N), update the display every N lines."
9133   :group 'gnus-thread
9134   :type '(choice (const :tag "off" nil)
9135                  number
9136                  (const :tag "frequently" t)))
9137
9138 (defun gnus-summary-respool-article (&optional n method)
9139   "Respool the current article.
9140 The article will be squeezed through the mail spooling process again,
9141 which means that it will be put in some mail newsgroup or other
9142 depending on `nnmail-split-methods'.
9143 If N is a positive number, respool the N next articles.
9144 If N is a negative number, respool the N previous articles.
9145 If N is nil and any articles have been marked with the process mark,
9146 respool those articles instead.
9147
9148 Respooling can be done both from mail groups and \"real\" newsgroups.
9149 In the former case, the articles in question will be moved from the
9150 current group into whatever groups they are destined to.  In the
9151 latter case, they will be copied into the relevant groups."
9152   (interactive
9153    (list current-prefix-arg
9154          (let* ((methods (gnus-methods-using 'respool))
9155                 (methname
9156                  (symbol-name (or gnus-summary-respool-default-method
9157                                   (car (gnus-find-method-for-group
9158                                         gnus-newsgroup-name)))))
9159                 (method
9160                  (gnus-completing-read-with-default
9161                   methname "What backend do you want to use when respooling?"
9162                   methods nil t nil 'gnus-mail-method-history))
9163                 ms)
9164            (cond
9165             ((zerop (length (setq ms (gnus-servers-using-backend
9166                                       (intern method)))))
9167              (list (intern method) ""))
9168             ((= 1 (length ms))
9169              (car ms))
9170             (t
9171              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9172                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9173                            ms-alist))))))))
9174   (unless method
9175     (error "No method given for respooling"))
9176   (if (assoc (symbol-name
9177               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9178              (gnus-methods-using 'respool))
9179       (gnus-summary-move-article n nil method)
9180     (gnus-summary-copy-article n nil method)))
9181
9182 (defun gnus-summary-import-article (file &optional edit)
9183   "Import an arbitrary file into a mail newsgroup."
9184   (interactive "fImport file: \nP")
9185   (let ((group gnus-newsgroup-name)
9186         (now (current-time))
9187         atts lines group-art)
9188     (unless (gnus-check-backend-function 'request-accept-article group)
9189       (error "%s does not support article importing" group))
9190     (or (file-readable-p file)
9191         (not (file-regular-p file))
9192         (error "Can't read %s" file))
9193     (save-excursion
9194       (set-buffer (gnus-get-buffer-create " *import file*"))
9195       (erase-buffer)
9196       (nnheader-insert-file-contents file)
9197       (goto-char (point-min))
9198       (if (nnheader-article-p)
9199           (save-restriction
9200             (goto-char (point-min))
9201             (search-forward "\n\n" nil t)
9202             (narrow-to-region (point-min) (1- (point)))
9203             (goto-char (point-min))
9204             (unless (re-search-forward "^date:" nil t)
9205               (goto-char (point-max))
9206               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9207        ;; This doesn't look like an article, so we fudge some headers.
9208         (setq atts (file-attributes file)
9209               lines (count-lines (point-min) (point-max)))
9210         (insert "From: " (read-string "From: ") "\n"
9211                 "Subject: " (read-string "Subject: ") "\n"
9212                 "Date: " (message-make-date (nth 5 atts)) "\n"
9213                 "Message-ID: " (message-make-message-id) "\n"
9214                 "Lines: " (int-to-string lines) "\n"
9215                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9216       (setq group-art (gnus-request-accept-article group nil t))
9217       (kill-buffer (current-buffer)))
9218     (setq gnus-newsgroup-active (gnus-activate-group group))
9219     (forward-line 1)
9220     (gnus-summary-goto-article (cdr group-art) nil t)
9221     (when edit
9222       (gnus-summary-edit-article))))
9223
9224 (defun gnus-summary-create-article ()
9225   "Create an article in a mail newsgroup."
9226   (interactive)
9227   (let ((group gnus-newsgroup-name)
9228         (now (current-time))
9229         group-art)
9230     (unless (gnus-check-backend-function 'request-accept-article group)
9231       (error "%s does not support article importing" group))
9232     (save-excursion
9233       (set-buffer (gnus-get-buffer-create " *import file*"))
9234       (erase-buffer)
9235       (goto-char (point-min))
9236       ;; This doesn't look like an article, so we fudge some headers.
9237       (insert "From: " (read-string "From: ") "\n"
9238               "Subject: " (read-string "Subject: ") "\n"
9239               "Date: " (message-make-date now) "\n"
9240               "Message-ID: " (message-make-message-id) "\n")
9241       (setq group-art (gnus-request-accept-article group nil t))
9242       (kill-buffer (current-buffer)))
9243     (setq gnus-newsgroup-active (gnus-activate-group group))
9244     (forward-line 1)
9245     (gnus-summary-goto-article (cdr group-art) nil t)
9246     (gnus-summary-edit-article)))
9247
9248 (defun gnus-summary-article-posted-p ()
9249   "Say whether the current (mail) article is available from news as well.
9250 This will be the case if the article has both been mailed and posted."
9251   (interactive)
9252   (let ((id (mail-header-references (gnus-summary-article-header)))
9253         (gnus-override-method (car (gnus-refer-article-methods))))
9254     (if (gnus-request-head id "")
9255         (gnus-message 2 "The current message was found on %s"
9256                       gnus-override-method)
9257       (gnus-message 2 "The current message couldn't be found on %s"
9258                     gnus-override-method)
9259       nil)))
9260
9261 (defun gnus-summary-expire-articles (&optional now)
9262   "Expire all articles that are marked as expirable in the current group."
9263   (interactive)
9264   (when (and (not gnus-group-is-exiting-without-update-p)
9265              (gnus-check-backend-function
9266               'request-expire-articles gnus-newsgroup-name))
9267     ;; This backend supports expiry.
9268     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9269            (expirable (if total
9270                           (progn
9271                             ;; We need to update the info for
9272                             ;; this group for `gnus-list-of-read-articles'
9273                             ;; to give us the right answer.
9274                             (gnus-run-hooks 'gnus-exit-group-hook)
9275                             (gnus-summary-update-info)
9276                             (gnus-list-of-read-articles gnus-newsgroup-name))
9277                         (setq gnus-newsgroup-expirable
9278                               (sort gnus-newsgroup-expirable '<))))
9279            (expiry-wait (if now 'immediate
9280                           (gnus-group-find-parameter
9281                            gnus-newsgroup-name 'expiry-wait)))
9282            (nnmail-expiry-target
9283             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9284                 nnmail-expiry-target))
9285            es)
9286       (when expirable
9287         ;; There are expirable articles in this group, so we run them
9288         ;; through the expiry process.
9289         (gnus-message 6 "Expiring articles...")
9290         (unless (gnus-check-group gnus-newsgroup-name)
9291           (error "Can't open server for %s" gnus-newsgroup-name))
9292         ;; The list of articles that weren't expired is returned.
9293         (save-excursion
9294           (if expiry-wait
9295               (let ((nnmail-expiry-wait-function nil)
9296                     (nnmail-expiry-wait expiry-wait))
9297                 (setq es (gnus-request-expire-articles
9298                           expirable gnus-newsgroup-name)))
9299             (setq es (gnus-request-expire-articles
9300                       expirable gnus-newsgroup-name)))
9301           (unless total
9302             (setq gnus-newsgroup-expirable es))
9303           ;; We go through the old list of expirable, and mark all
9304           ;; really expired articles as nonexistent.
9305           (unless (eq es expirable) ;If nothing was expired, we don't mark.
9306             (let ((gnus-use-cache nil))
9307               (dolist (article expirable)
9308                 (when (and (not (memq article es))
9309                            (gnus-data-find article))
9310                   (gnus-summary-mark-article article gnus-canceled-mark)
9311                   (run-hook-with-args 'gnus-summary-article-expire-hook
9312                                       'delete
9313                                       (gnus-data-header
9314                                        (assoc article (gnus-data-list nil)))
9315                                       gnus-newsgroup-name
9316                                       nil
9317                                       nil))))))
9318         (gnus-message 6 "Expiring articles...done")))))
9319
9320 (defun gnus-summary-expire-articles-now ()
9321   "Expunge all expirable articles in the current group.
9322 This means that *all* articles that are marked as expirable will be
9323 deleted forever, right now."
9324   (interactive)
9325   (or gnus-expert-user
9326       (gnus-yes-or-no-p
9327        "Are you really, really, really sure you want to delete all these messages? ")
9328       (error "Phew!"))
9329   (gnus-summary-expire-articles t))
9330
9331 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9332 (defun gnus-summary-delete-article (&optional n)
9333   "Delete the N next (mail) articles.
9334 This command actually deletes articles.  This is not a marking
9335 command.  The article will disappear forever from your life, never to
9336 return.
9337
9338 If N is negative, delete backwards.
9339 If N is nil and articles have been marked with the process mark,
9340 delete these instead.
9341
9342 If `gnus-novice-user' is non-nil you will be asked for
9343 confirmation before the articles are deleted."
9344   (interactive "P")
9345   (unless (gnus-check-backend-function 'request-expire-articles
9346                                        gnus-newsgroup-name)
9347     (error "The current newsgroup does not support article deletion"))
9348   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9349     (error "Couldn't open server"))
9350   ;; Compute the list of articles to delete.
9351   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9352         (nnmail-expiry-target 'delete)
9353         not-deleted)
9354     (if (and gnus-novice-user
9355              (not (gnus-yes-or-no-p
9356                    (format "Do you really want to delete %s forever? "
9357                            (if (> (length articles) 1)
9358                                (format "these %s articles" (length articles))
9359                              "this article")))))
9360         ()
9361       ;; Delete the articles.
9362       (setq not-deleted (gnus-request-expire-articles
9363                          articles gnus-newsgroup-name 'force))
9364       (while articles
9365         (gnus-summary-remove-process-mark (car articles))
9366         ;; The backend might not have been able to delete the article
9367         ;; after all.
9368         (unless (memq (car articles) not-deleted)
9369           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9370         (let* ((article (car articles))
9371                (id (mail-header-id (gnus-data-header
9372                                     (assoc article (gnus-data-list nil))))))
9373           (run-hook-with-args 'gnus-summary-article-delete-hook
9374                               'delete id gnus-newsgroup-name nil
9375                               nil))
9376         (setq articles (cdr articles)))
9377       (when not-deleted
9378         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9379     (gnus-summary-position-point)
9380     (gnus-set-mode-line 'summary)
9381     not-deleted))
9382
9383 (defun gnus-summary-edit-article (&optional arg)
9384   "Edit the current article.
9385 This will have permanent effect only in mail groups.
9386 If ARG is nil, edit the decoded articles.
9387 If ARG is 1, edit the raw articles.
9388 If ARG is 2, edit the raw articles even in read-only groups.
9389 If ARG is 3, edit the articles with the current handles.
9390 Otherwise, allow editing of articles even in read-only
9391 groups."
9392   (interactive "P")
9393   (let (force raw current-handles)
9394     (cond
9395      ((null arg))
9396      ((eq arg 1)
9397       (setq raw t))
9398      ((eq arg 2)
9399       (setq raw t
9400             force t))
9401      ((eq arg 3)
9402       (setq current-handles
9403             (and (gnus-buffer-live-p gnus-article-buffer)
9404                  (with-current-buffer gnus-article-buffer
9405                    (prog1
9406                        gnus-article-mime-handles
9407                      (setq gnus-article-mime-handles nil))))))
9408      (t
9409       (setq force t)))
9410     (when (and raw (not force)
9411                (member gnus-newsgroup-name '("nndraft:delayed"
9412                                              "nndraft:drafts"
9413                                              "nndraft:queue")))
9414       (error "Can't edit the raw article in group %s"
9415              gnus-newsgroup-name))
9416     (save-excursion
9417       (set-buffer gnus-summary-buffer)
9418       (let ((mail-parse-charset gnus-newsgroup-charset)
9419             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9420         (gnus-set-global-variables)
9421         (when (and (not force)
9422                    (gnus-group-read-only-p))
9423           (error "The current newsgroup does not support article editing"))
9424         (gnus-summary-show-article t)
9425         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
9426           (with-current-buffer gnus-article-buffer
9427             (mm-enable-multibyte)))
9428         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
9429             (setq raw t))
9430         (gnus-article-edit-article
9431          (if raw 'ignore
9432            `(lambda ()
9433               (let ((mbl mml-buffer-list))
9434                 (setq mml-buffer-list nil)
9435                 (mime-to-mml ,'current-handles)
9436                 (let ((mbl1 mml-buffer-list))
9437                   (setq mml-buffer-list mbl)
9438                   (set (make-local-variable 'mml-buffer-list) mbl1))
9439                 (gnus-make-local-hook 'kill-buffer-hook)
9440                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
9441          `(lambda (no-highlight)
9442             (let ((mail-parse-charset ',gnus-newsgroup-charset)
9443                   (message-options message-options)
9444                   (message-options-set-recipient)
9445                   (mail-parse-ignored-charsets
9446                    ',gnus-newsgroup-ignored-charsets))
9447               ,(if (not raw) '(progn
9448                                 (mml-to-mime)
9449                                 (mml-destroy-buffers)
9450                                 (remove-hook 'kill-buffer-hook
9451                                              'mml-destroy-buffers t)
9452                                 (kill-local-variable 'mml-buffer-list)))
9453               (gnus-summary-edit-article-done
9454                ,(or (mail-header-references gnus-current-headers) "")
9455                ,(gnus-group-read-only-p)
9456                ,gnus-summary-buffer no-highlight))))))))
9457
9458 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9459
9460 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9461                                                  no-highlight)
9462   "Make edits to the current article permanent."
9463   (interactive)
9464   (save-excursion
9465    ;; The buffer restriction contains the entire article if it exists.
9466     (when (article-goto-body)
9467       (let ((lines (count-lines (point) (point-max)))
9468             (length (- (point-max) (point)))
9469             (case-fold-search t)
9470             (body (copy-marker (point))))
9471         (goto-char (point-min))
9472         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9473           (delete-region (match-beginning 1) (match-end 1))
9474           (insert (number-to-string length)))
9475         (goto-char (point-min))
9476         (when (re-search-forward
9477                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9478           (delete-region (match-beginning 1) (match-end 1))
9479           (insert (number-to-string length)))
9480         (goto-char (point-min))
9481         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9482           (delete-region (match-beginning 1) (match-end 1))
9483           (insert (number-to-string lines))))))
9484   ;; Replace the article.
9485   (let ((buf (current-buffer)))
9486     (with-temp-buffer
9487       (insert-buffer-substring buf)
9488
9489       (if (and (not read-only)
9490                (not (gnus-request-replace-article
9491                      (cdr gnus-article-current) (car gnus-article-current)
9492                      (current-buffer) t)))
9493           (error "Couldn't replace article")
9494         ;; Update the summary buffer.
9495         (if (and references
9496                  (equal (message-tokenize-header references " ")
9497                         (message-tokenize-header
9498                          (or (message-fetch-field "references") "") " ")))
9499             ;; We only have to update this line.
9500             (save-excursion
9501               (save-restriction
9502                 (message-narrow-to-head)
9503                 (let ((head (buffer-string))
9504                       header)
9505                   (with-temp-buffer
9506                     (insert (format "211 %d Article retrieved.\n"
9507                                     (cdr gnus-article-current)))
9508                     (insert head)
9509                     (insert ".\n")
9510                     (let ((nntp-server-buffer (current-buffer)))
9511                       (setq header (car (gnus-get-newsgroup-headers
9512                                          nil t))))
9513                     (save-excursion
9514                       (set-buffer gnus-summary-buffer)
9515                       (gnus-data-set-header
9516                        (gnus-data-find (cdr gnus-article-current))
9517                        header)
9518                       (gnus-summary-update-article-line
9519                        (cdr gnus-article-current) header)
9520                       (if (gnus-summary-goto-subject
9521                            (cdr gnus-article-current) nil t)
9522                           (gnus-summary-update-secondary-mark
9523                            (cdr gnus-article-current))))))))
9524           ;; Update threads.
9525           (set-buffer (or buffer gnus-summary-buffer))
9526           (gnus-summary-update-article (cdr gnus-article-current))
9527           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9528               (gnus-summary-update-secondary-mark
9529                (cdr gnus-article-current))))
9530         ;; Prettify the article buffer again.
9531         (unless no-highlight
9532           (save-excursion
9533             (set-buffer gnus-article-buffer)
9534             ;;;!!! Fix this -- article should be rehighlighted.
9535             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9536             (set-buffer gnus-original-article-buffer)
9537             (gnus-request-article
9538              (cdr gnus-article-current)
9539              (car gnus-article-current) (current-buffer))))
9540         ;; Prettify the summary buffer line.
9541         (when (gnus-visual-p 'summary-highlight 'highlight)
9542           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9543
9544 (defun gnus-summary-edit-wash (key)
9545   "Perform editing command KEY in the article buffer."
9546   (interactive
9547    (list
9548     (progn
9549       (message "%s" (concat (this-command-keys) "- "))
9550       (read-char))))
9551   (message "")
9552   (gnus-summary-edit-article)
9553   (execute-kbd-macro (concat (this-command-keys) key))
9554   (gnus-article-edit-done))
9555
9556 ;;; Respooling
9557
9558 (defun gnus-summary-respool-query (&optional silent trace)
9559   "Query where the respool algorithm would put this article."
9560   (interactive)
9561   (let (gnus-mark-article-hook)
9562     (gnus-summary-select-article)
9563     (save-excursion
9564       (set-buffer gnus-original-article-buffer)
9565       (let ((groups (nnmail-article-group 'identity trace)))
9566         (unless silent
9567           (if groups
9568               (message "This message would go to %s"
9569                        (mapconcat 'car groups ", "))
9570             (message "This message would go to no groups"))
9571           groups)))))
9572
9573 (defun gnus-summary-respool-trace ()
9574   "Trace where the respool algorithm would put this article.
9575 Display a buffer showing all fancy splitting patterns which matched."
9576   (interactive)
9577   (gnus-summary-respool-query nil t))
9578
9579 ;; Summary marking commands.
9580
9581 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9582   "Mark articles which has the same subject as read, and then select the next.
9583 If UNMARK is positive, remove any kind of mark.
9584 If UNMARK is negative, tick articles."
9585   (interactive "P")
9586   (when unmark
9587     (setq unmark (prefix-numeric-value unmark)))
9588   (let ((count
9589          (gnus-summary-mark-same-subject
9590           (gnus-summary-article-subject) unmark)))
9591     ;; Select next unread article.  If auto-select-same mode, should
9592     ;; select the first unread article.
9593     (gnus-summary-next-article t (and gnus-auto-select-same
9594                                       (gnus-summary-article-subject)))
9595     (gnus-message 7 "%d article%s marked as %s"
9596                   count (if (= count 1) " is" "s are")
9597                   (if unmark "unread" "read"))))
9598
9599 (defun gnus-summary-kill-same-subject (&optional unmark)
9600   "Mark articles which has the same subject as read.
9601 If UNMARK is positive, remove any kind of mark.
9602 If UNMARK is negative, tick articles."
9603   (interactive "P")
9604   (when unmark
9605     (setq unmark (prefix-numeric-value unmark)))
9606   (let ((count
9607          (gnus-summary-mark-same-subject
9608           (gnus-summary-article-subject) unmark)))
9609     ;; If marked as read, go to next unread subject.
9610     (when (null unmark)
9611       ;; Go to next unread subject.
9612       (gnus-summary-next-subject 1 t))
9613     (gnus-message 7 "%d articles are marked as %s"
9614                   count (if unmark "unread" "read"))))
9615
9616 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9617   "Mark articles with same SUBJECT as read, and return marked number.
9618 If optional argument UNMARK is positive, remove any kinds of marks.
9619 If optional argument UNMARK is negative, mark articles as unread instead."
9620   (let ((count 1))
9621     (save-excursion
9622       (cond
9623        ((null unmark)                   ; Mark as read.
9624         (while (and
9625                 (progn
9626                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9627                   (gnus-summary-show-thread) t)
9628                 (gnus-summary-find-subject subject))
9629           (setq count (1+ count))))
9630        ((> unmark 0)                    ; Tick.
9631         (while (and
9632                 (progn
9633                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9634                   (gnus-summary-show-thread) t)
9635                 (gnus-summary-find-subject subject))
9636           (setq count (1+ count))))
9637        (t                               ; Mark as unread.
9638         (while (and
9639                 (progn
9640                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9641                   (gnus-summary-show-thread) t)
9642                 (gnus-summary-find-subject subject))
9643           (setq count (1+ count)))))
9644       (gnus-set-mode-line 'summary)
9645       ;; Return the number of marked articles.
9646       count)))
9647
9648 (defun gnus-summary-mark-as-processable (n &optional unmark)
9649   "Set the process mark on the next N articles.
9650 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9651 the process mark instead.  The difference between N and the actual
9652 number of articles marked is returned."
9653   (interactive "P")
9654   (if (and (null n) (gnus-region-active-p))
9655       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9656     (setq n (prefix-numeric-value n))
9657     (let ((backward (< n 0))
9658           (n (abs n)))
9659       (while (and
9660               (> n 0)
9661               (if unmark
9662                   (gnus-summary-remove-process-mark
9663                    (gnus-summary-article-number))
9664                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9665               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9666         (setq n (1- n)))
9667       (when (/= 0 n)
9668         (gnus-message 7 "No more articles"))
9669       (gnus-summary-recenter)
9670       (gnus-summary-position-point)
9671       n)))
9672
9673 (defun gnus-summary-unmark-as-processable (n)
9674   "Remove the process mark from the next N articles.
9675 If N is negative, unmark backward instead.  The difference between N and
9676 the actual number of articles unmarked is returned."
9677   (interactive "P")
9678   (gnus-summary-mark-as-processable n t))
9679
9680 (defun gnus-summary-unmark-all-processable ()
9681   "Remove the process mark from all articles."
9682   (interactive)
9683   (save-excursion
9684     (while gnus-newsgroup-processable
9685       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9686   (gnus-summary-position-point))
9687
9688 (defun gnus-summary-add-mark (article type)
9689   "Mark ARTICLE with a mark of TYPE."
9690   (let ((vtype (car (assq type gnus-article-mark-lists)))
9691         var)
9692     (if (not vtype)
9693         (error "No such mark type: %s" type)
9694       (setq var (intern (format "gnus-newsgroup-%s" type)))
9695       (set var (cons article (symbol-value var)))
9696       (if (memq type '(processable cached replied forwarded recent saved))
9697           (gnus-summary-update-secondary-mark article)
9698         ;;; !!! This is bogus.  We should find out what primary
9699         ;;; !!! mark we want to set.
9700         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9701
9702 (defun gnus-summary-mark-as-expirable (n)
9703   "Mark N articles forward as expirable.
9704 If N is negative, mark backward instead.  The difference between N and
9705 the actual number of articles marked is returned."
9706   (interactive "p")
9707   (gnus-summary-mark-forward n gnus-expirable-mark))
9708
9709 (defun gnus-summary-mark-as-spam (n)
9710   "Mark N articles forward as spam.
9711 If N is negative, mark backward instead.  The difference between N and
9712 the actual number of articles marked is returned."
9713   (interactive "p")
9714   (gnus-summary-mark-forward n gnus-spam-mark))
9715
9716 (defun gnus-summary-mark-article-as-replied (article)
9717   "Mark ARTICLE as replied to and update the summary line.
9718 ARTICLE can also be a list of articles."
9719   (interactive (list (gnus-summary-article-number)))
9720   (let ((articles (if (listp article) article (list article))))
9721     (dolist (article articles)
9722       (unless (numberp article)
9723         (error "%s is not a number" article))
9724       (push article gnus-newsgroup-replied)
9725       (let ((buffer-read-only nil))
9726         (when (gnus-summary-goto-subject article nil t)
9727           (gnus-summary-update-secondary-mark article))))))
9728
9729 (defun gnus-summary-mark-article-as-forwarded (article)
9730   "Mark ARTICLE as forwarded and update the summary line.
9731 ARTICLE can also be a list of articles."
9732   (let ((articles (if (listp article) article (list article))))
9733     (dolist (article articles)
9734       (push article gnus-newsgroup-forwarded)
9735       (let ((buffer-read-only nil))
9736         (when (gnus-summary-goto-subject article nil t)
9737           (gnus-summary-update-secondary-mark article))))))
9738
9739 (defun gnus-summary-set-bookmark (article)
9740   "Set a bookmark in current article."
9741   (interactive (list (gnus-summary-article-number)))
9742   (when (or (not (get-buffer gnus-article-buffer))
9743             (not gnus-current-article)
9744             (not gnus-article-current)
9745             (not (equal gnus-newsgroup-name (car gnus-article-current))))
9746     (error "No current article selected"))
9747   ;; Remove old bookmark, if one exists.
9748   (gnus-pull article gnus-newsgroup-bookmarks)
9749   ;; Set the new bookmark, which is on the form
9750   ;; (article-number . line-number-in-body).
9751   (push
9752    (cons article
9753          (save-excursion
9754            (set-buffer gnus-article-buffer)
9755            (count-lines
9756             (min (point)
9757                  (save-excursion
9758                    (article-goto-body)
9759                    (point)))
9760             (point))))
9761    gnus-newsgroup-bookmarks)
9762   (gnus-message 6 "A bookmark has been added to the current article."))
9763
9764 (defun gnus-summary-remove-bookmark (article)
9765   "Remove the bookmark from the current article."
9766   (interactive (list (gnus-summary-article-number)))
9767   ;; Remove old bookmark, if one exists.
9768   (if (not (assq article gnus-newsgroup-bookmarks))
9769       (gnus-message 6 "No bookmark in current article.")
9770     (gnus-pull article gnus-newsgroup-bookmarks)
9771     (gnus-message 6 "Removed bookmark.")))
9772
9773 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
9774 (defun gnus-summary-mark-as-dormant (n)
9775   "Mark N articles forward as dormant.
9776 If N is negative, mark backward instead.  The difference between N and
9777 the actual number of articles marked is returned."
9778   (interactive "p")
9779   (gnus-summary-mark-forward n gnus-dormant-mark))
9780
9781 (defun gnus-summary-set-process-mark (article)
9782   "Set the process mark on ARTICLE and update the summary line."
9783   (setq gnus-newsgroup-processable
9784         (cons article
9785               (delq article gnus-newsgroup-processable)))
9786   (when (gnus-summary-goto-subject article)
9787     (gnus-summary-show-thread)
9788     (gnus-summary-goto-subject article)
9789     (gnus-summary-update-secondary-mark article)))
9790
9791 (defun gnus-summary-remove-process-mark (article)
9792   "Remove the process mark from ARTICLE and update the summary line."
9793   (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
9794   (when (gnus-summary-goto-subject article)
9795     (gnus-summary-show-thread)
9796     (gnus-summary-goto-subject article)
9797     (gnus-summary-update-secondary-mark article)))
9798
9799 (defun gnus-summary-set-saved-mark (article)
9800   "Set the process mark on ARTICLE and update the summary line."
9801   (push article gnus-newsgroup-saved)
9802   (when (gnus-summary-goto-subject article)
9803     (gnus-summary-update-secondary-mark article)))
9804
9805 (defun gnus-summary-mark-forward (n &optional mark no-expire)
9806   "Mark N articles as read forwards.
9807 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
9808 The difference between N and the actual number of articles marked is
9809 returned.
9810 If NO-EXPIRE, auto-expiry will be inhibited."
9811   (interactive "p")
9812   (gnus-summary-show-thread)
9813   (let ((backward (< n 0))
9814         (gnus-summary-goto-unread
9815          (and gnus-summary-goto-unread
9816               (not (eq gnus-summary-goto-unread 'never))
9817               (not (memq mark (list gnus-unread-mark gnus-spam-mark
9818                                     gnus-ticked-mark gnus-dormant-mark)))))
9819         (n (abs n))
9820         (mark (or mark gnus-del-mark)))
9821     (while (and (> n 0)
9822                 (gnus-summary-mark-article nil mark no-expire)
9823                 (zerop (gnus-summary-next-subject
9824                         (if backward -1 1)
9825                         (and gnus-summary-goto-unread
9826                              (not (eq gnus-summary-goto-unread 'never)))
9827                         t)))
9828       (setq n (1- n)))
9829     (when (/= 0 n)
9830       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
9831     (gnus-summary-recenter)
9832     (gnus-summary-position-point)
9833     (gnus-set-mode-line 'summary)
9834     n))
9835
9836 (defun gnus-summary-mark-article-as-read (mark)
9837   "Mark the current article quickly as read with MARK."
9838   (let ((article (gnus-summary-article-number)))
9839     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
9840     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9841     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
9842     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9843     (push (cons article mark) gnus-newsgroup-reads)
9844     ;; Possibly remove from cache, if that is used.
9845     (when gnus-use-cache
9846       (gnus-cache-enter-remove-article article))
9847     ;; Allow the backend to change the mark.
9848     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9849     ;; Check for auto-expiry.
9850     (when (and gnus-newsgroup-auto-expire
9851                (memq mark gnus-auto-expirable-marks))
9852       (setq mark gnus-expirable-mark)
9853       ;; Let the backend know about the mark change.
9854       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9855       (push article gnus-newsgroup-expirable))
9856     ;; Set the mark in the buffer.
9857     (gnus-summary-update-mark mark 'unread)
9858     t))
9859
9860 (defun gnus-summary-mark-article-as-unread (mark)
9861   "Mark the current article quickly as unread with MARK."
9862   (let* ((article (gnus-summary-article-number))
9863          (old-mark (gnus-summary-article-mark article)))
9864     ;; Allow the backend to change the mark.
9865     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9866     (if (eq mark old-mark)
9867         t
9868       (if (<= article 0)
9869           (progn
9870             (gnus-error 1 "Can't mark negative article numbers")
9871             nil)
9872         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
9873         (setq gnus-newsgroup-spam-marked
9874               (delq article gnus-newsgroup-spam-marked))
9875         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
9876         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
9877         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
9878         (cond ((= mark gnus-ticked-mark)
9879                (setq gnus-newsgroup-marked
9880                      (gnus-add-to-sorted-list gnus-newsgroup-marked
9881                                               article)))
9882               ((= mark gnus-spam-mark)
9883                (setq gnus-newsgroup-spam-marked
9884                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
9885                                               article)))
9886               ((= mark gnus-dormant-mark)
9887                (setq gnus-newsgroup-dormant
9888                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
9889                                               article)))
9890               (t
9891                (setq gnus-newsgroup-unreads
9892                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
9893                                               article))))
9894         (gnus-pull article gnus-newsgroup-reads)
9895
9896         ;; See whether the article is to be put in the cache.
9897         (and gnus-use-cache
9898              (vectorp (gnus-summary-article-header article))
9899              (save-excursion
9900                (gnus-cache-possibly-enter-article
9901                 gnus-newsgroup-name article
9902                 (= mark gnus-ticked-mark)
9903                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9904
9905         ;; Fix the mark.
9906         (gnus-summary-update-mark mark 'unread)
9907         t))))
9908
9909 (defun gnus-summary-mark-article (&optional article mark no-expire)
9910   "Mark ARTICLE with MARK.  MARK can be any character.
9911 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
9912 `??' (dormant) and `?E' (expirable).
9913 If MARK is nil, then the default character `?r' is used.
9914 If ARTICLE is nil, then the article on the current line will be
9915 marked.
9916 If NO-EXPIRE, auto-expiry will be inhibited."
9917   ;; The mark might be a string.
9918   (when (stringp mark)
9919     (setq mark (aref mark 0)))
9920   ;; If no mark is given, then we check auto-expiring.
9921   (when (null mark)
9922     (setq mark gnus-del-mark))
9923   (when (and (not no-expire)
9924              gnus-newsgroup-auto-expire
9925              (memq mark gnus-auto-expirable-marks))
9926     (setq mark gnus-expirable-mark))
9927   (let ((article (or article (gnus-summary-article-number)))
9928         (old-mark (gnus-summary-article-mark article)))
9929     ;; Allow the backend to change the mark.
9930     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
9931     (if (eq mark old-mark)
9932         t
9933       (unless article
9934         (error "No article on current line"))
9935       (if (not (if (or (= mark gnus-unread-mark)
9936                        (= mark gnus-ticked-mark)
9937                        (= mark gnus-spam-mark)
9938                        (= mark gnus-dormant-mark))
9939                    (gnus-mark-article-as-unread article mark)
9940                  (gnus-mark-article-as-read article mark)))
9941           t
9942         ;; See whether the article is to be put in the cache.
9943         (and gnus-use-cache
9944              (not (= mark gnus-canceled-mark))
9945              (vectorp (gnus-summary-article-header article))
9946              (save-excursion
9947                (gnus-cache-possibly-enter-article
9948                 gnus-newsgroup-name article
9949                 (= mark gnus-ticked-mark)
9950                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
9951
9952         (when (gnus-summary-goto-subject article nil t)
9953           (let ((buffer-read-only nil))
9954             (gnus-summary-show-thread)
9955             ;; Fix the mark.
9956             (gnus-summary-update-mark mark 'unread)
9957             t))))))
9958
9959 (defun gnus-summary-update-secondary-mark (article)
9960   "Update the secondary (read, process, cache) mark."
9961   (gnus-summary-update-mark
9962    (cond ((memq article gnus-newsgroup-processable)
9963           gnus-process-mark)
9964          ((memq article gnus-newsgroup-cached)
9965           gnus-cached-mark)
9966          ((memq article gnus-newsgroup-replied)
9967           gnus-replied-mark)
9968          ((memq article gnus-newsgroup-forwarded)
9969           gnus-forwarded-mark)
9970          ((memq article gnus-newsgroup-saved)
9971           gnus-saved-mark)
9972          ((memq article gnus-newsgroup-recent)
9973           gnus-recent-mark)
9974          ((memq article gnus-newsgroup-unseen)
9975           gnus-unseen-mark)
9976          (t gnus-no-mark))
9977    'replied)
9978   (when (gnus-visual-p 'summary-highlight 'highlight)
9979     (gnus-run-hooks 'gnus-summary-update-hook))
9980   t)
9981
9982 (defun gnus-summary-update-download-mark (article)
9983   "Update the download mark."
9984   (gnus-summary-update-mark
9985    (cond ((memq article gnus-newsgroup-undownloaded)
9986           gnus-undownloaded-mark)
9987          (gnus-newsgroup-agentized
9988           gnus-downloaded-mark)
9989          (t
9990           gnus-no-mark))
9991    'download)
9992   (gnus-summary-update-line t)
9993   t)
9994
9995 (defun gnus-summary-update-mark (mark type)
9996   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
9997         (buffer-read-only nil))
9998     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
9999     (when forward
10000       (when (looking-at "\r")
10001         (incf forward))
10002       (when (<= (+ forward (point)) (point-max))
10003         ;; Go to the right position on the line.
10004         (goto-char (+ forward (point)))
10005         ;; Replace the old mark with the new mark.
10006         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10007         ;; Optionally update the marks by some user rule.
10008         (when (eq type 'unread)
10009           (gnus-data-set-mark
10010            (gnus-data-find (gnus-summary-article-number)) mark)
10011           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10012
10013 (defun gnus-mark-article-as-read (article &optional mark)
10014   "Enter ARTICLE in the pertinent lists and remove it from others."
10015   ;; Make the article expirable.
10016   (let ((mark (or mark gnus-del-mark)))
10017     (setq gnus-newsgroup-expirable
10018           (if (= mark gnus-expirable-mark)
10019               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10020             (delq article gnus-newsgroup-expirable)))
10021     ;; Remove from unread and marked lists.
10022     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10023     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10024     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10025     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10026     (push (cons article mark) gnus-newsgroup-reads)
10027     ;; Possibly remove from cache, if that is used.
10028     (when gnus-use-cache
10029       (gnus-cache-enter-remove-article article))
10030     t))
10031
10032 (defun gnus-mark-article-as-unread (article &optional mark)
10033   "Enter ARTICLE in the pertinent lists and remove it from others."
10034   (let ((mark (or mark gnus-ticked-mark)))
10035     (if (<= article 0)
10036         (progn
10037           (gnus-error 1 "Can't mark negative article numbers")
10038           nil)
10039       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10040             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10041             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10042             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10043             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10044
10045       ;; Unsuppress duplicates?
10046       (when gnus-suppress-duplicates
10047         (gnus-dup-unsuppress-article article))
10048
10049       (cond ((= mark gnus-ticked-mark)
10050              (setq gnus-newsgroup-marked
10051                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10052             ((= mark gnus-spam-mark)
10053              (setq gnus-newsgroup-spam-marked
10054                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10055                                             article)))
10056             ((= mark gnus-dormant-mark)
10057              (setq gnus-newsgroup-dormant
10058                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10059             (t
10060              (setq gnus-newsgroup-unreads
10061                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10062       (gnus-pull article gnus-newsgroup-reads)
10063       t)))
10064
10065 (defalias 'gnus-summary-mark-as-unread-forward
10066   'gnus-summary-tick-article-forward)
10067 (make-obsolete 'gnus-summary-mark-as-unread-forward
10068                'gnus-summary-tick-article-forward)
10069 (defun gnus-summary-tick-article-forward (n)
10070   "Tick N articles forwards.
10071 If N is negative, tick backwards instead.
10072 The difference between N and the number of articles ticked is returned."
10073   (interactive "p")
10074   (gnus-summary-mark-forward n gnus-ticked-mark))
10075
10076 (defalias 'gnus-summary-mark-as-unread-backward
10077   'gnus-summary-tick-article-backward)
10078 (make-obsolete 'gnus-summary-mark-as-unread-backward
10079                'gnus-summary-tick-article-backward)
10080 (defun gnus-summary-tick-article-backward (n)
10081   "Tick N articles backwards.
10082 The difference between N and the number of articles ticked is returned."
10083   (interactive "p")
10084   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10085
10086 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10087 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10088 (defun gnus-summary-tick-article (&optional article clear-mark)
10089   "Mark current article as unread.
10090 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10091 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10092   (interactive)
10093   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10094                                        gnus-ticked-mark)))
10095
10096 (defun gnus-summary-mark-as-read-forward (n)
10097   "Mark N articles as read forwards.
10098 If N is negative, mark backwards instead.
10099 The difference between N and the actual number of articles marked is
10100 returned."
10101   (interactive "p")
10102   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10103
10104 (defun gnus-summary-mark-as-read-backward (n)
10105   "Mark the N articles as read backwards.
10106 The difference between N and the actual number of articles marked is
10107 returned."
10108   (interactive "p")
10109   (gnus-summary-mark-forward
10110    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10111
10112 (defun gnus-summary-mark-as-read (&optional article mark)
10113   "Mark current article as read.
10114 ARTICLE specifies the article to be marked as read.
10115 MARK specifies a string to be inserted at the beginning of the line."
10116   (gnus-summary-mark-article article mark))
10117
10118 (defun gnus-summary-clear-mark-forward (n)
10119   "Clear marks from N articles forward.
10120 If N is negative, clear backward instead.
10121 The difference between N and the number of marks cleared is returned."
10122   (interactive "p")
10123   (gnus-summary-mark-forward n gnus-unread-mark))
10124
10125 (defun gnus-summary-clear-mark-backward (n)
10126   "Clear marks from N articles backward.
10127 The difference between N and the number of marks cleared is returned."
10128   (interactive "p")
10129   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10130
10131 (defun gnus-summary-mark-unread-as-read ()
10132   "Intended to be used by `gnus-summary-mark-article-hook'."
10133   (when (memq gnus-current-article gnus-newsgroup-unreads)
10134     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10135
10136 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10137   "Intended to be used by `gnus-summary-mark-article-hook'."
10138   (let ((mark (gnus-summary-article-mark)))
10139     (when (or (gnus-unread-mark-p mark)
10140               (gnus-read-mark-p mark))
10141       (gnus-summary-mark-article gnus-current-article
10142                                  (or new-mark gnus-read-mark)))))
10143
10144 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10145   "Intended to be used by `gnus-summary-mark-article-hook'."
10146   (let ((mark (gnus-summary-article-mark)))
10147     (when (or (gnus-unread-mark-p mark)
10148               (gnus-read-mark-p mark))
10149       (gnus-summary-mark-article (gnus-summary-article-number)
10150                                  (or new-mark gnus-read-mark)))))
10151
10152 (defun gnus-summary-mark-unread-as-ticked ()
10153   "Intended to be used by `gnus-summary-mark-article-hook'."
10154   (when (memq gnus-current-article gnus-newsgroup-unreads)
10155     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10156
10157 (defun gnus-summary-mark-region-as-read (point mark all)
10158   "Mark all unread articles between point and mark as read.
10159 If given a prefix, mark all articles between point and mark as read,
10160 even ticked and dormant ones."
10161   (interactive "r\nP")
10162   (save-excursion
10163     (let (article)
10164       (goto-char point)
10165       (beginning-of-line)
10166       (while (and
10167               (< (point) mark)
10168               (progn
10169                 (when (or all
10170                           (memq (setq article (gnus-summary-article-number))
10171                                 gnus-newsgroup-unreads))
10172                   (gnus-summary-mark-article article gnus-del-mark))
10173                 t)
10174               (gnus-summary-find-next))))))
10175
10176 (defun gnus-summary-mark-below (score mark)
10177   "Mark articles with score less than SCORE with MARK."
10178   (interactive "P\ncMark: ")
10179   (setq score (if score
10180                   (prefix-numeric-value score)
10181                 (or gnus-summary-default-score 0)))
10182   (save-excursion
10183     (set-buffer gnus-summary-buffer)
10184     (goto-char (point-min))
10185     (while
10186         (progn
10187           (and (< (gnus-summary-article-score) score)
10188                (gnus-summary-mark-article nil mark))
10189           (gnus-summary-find-next)))))
10190
10191 (defun gnus-summary-kill-below (&optional score)
10192   "Mark articles with score below SCORE as read."
10193   (interactive "P")
10194   (gnus-summary-mark-below score gnus-killed-mark))
10195
10196 (defun gnus-summary-clear-above (&optional score)
10197   "Clear all marks from articles with score above SCORE."
10198   (interactive "P")
10199   (gnus-summary-mark-above score gnus-unread-mark))
10200
10201 (defun gnus-summary-tick-above (&optional score)
10202   "Tick all articles with score above SCORE."
10203   (interactive "P")
10204   (gnus-summary-mark-above score gnus-ticked-mark))
10205
10206 (defun gnus-summary-mark-above (score mark)
10207   "Mark articles with score over SCORE with MARK."
10208   (interactive "P\ncMark: ")
10209   (setq score (if score
10210                   (prefix-numeric-value score)
10211                 (or gnus-summary-default-score 0)))
10212   (save-excursion
10213     (set-buffer gnus-summary-buffer)
10214     (goto-char (point-min))
10215     (while (and (progn
10216                   (when (> (gnus-summary-article-score) score)
10217                     (gnus-summary-mark-article nil mark))
10218                   t)
10219                 (gnus-summary-find-next)))))
10220
10221 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10222 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10223 (defun gnus-summary-limit-include-expunged (&optional no-error)
10224   "Display all the hidden articles that were expunged for low scores."
10225   (interactive)
10226   (let ((buffer-read-only nil))
10227     (let ((scored gnus-newsgroup-scored)
10228           headers h)
10229       (while scored
10230         (unless (gnus-summary-article-header (caar scored))
10231           (and (setq h (gnus-number-to-header (caar scored)))
10232                (< (cdar scored) gnus-summary-expunge-below)
10233                (push h headers)))
10234         (setq scored (cdr scored)))
10235       (if (not headers)
10236           (when (not no-error)
10237             (error "No expunged articles hidden"))
10238         (goto-char (point-min))
10239         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10240         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10241         (mapcar (lambda (x) (push (mail-header-number x)
10242                                   gnus-newsgroup-limit))
10243                 headers)
10244         (gnus-summary-prepare-unthreaded (nreverse headers))
10245         (goto-char (point-min))
10246         (gnus-summary-position-point)
10247         t))))
10248
10249 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10250   "Mark all unread articles in this newsgroup as read.
10251 If prefix argument ALL is non-nil, ticked and dormant articles will
10252 also be marked as read.
10253 If QUIETLY is non-nil, no questions will be asked.
10254
10255 If TO-HERE is non-nil, it should be a point in the buffer.  All
10256 articles before (after, if REVERSE is set) this point will be marked
10257 as read.
10258
10259 Note that this function will only catch up the unread article
10260 in the current summary buffer limitation.
10261
10262 The number of articles marked as read is returned."
10263   (interactive "P")
10264   (prog1
10265       (save-excursion
10266         (when (or quietly
10267                   (not gnus-interactive-catchup) ;Without confirmation?
10268                   gnus-expert-user
10269                   (gnus-y-or-n-p
10270                    (if all
10271                        "Mark absolutely all articles as read? "
10272                      "Mark all unread articles as read? ")))
10273           (if (and not-mark
10274                    (not gnus-newsgroup-adaptive)
10275                    (not gnus-newsgroup-auto-expire)
10276                    (not gnus-suppress-duplicates)
10277                    (or (not gnus-use-cache)
10278                        (eq gnus-use-cache 'passive)))
10279               (progn
10280                 (when all
10281                   (setq gnus-newsgroup-marked nil
10282                         gnus-newsgroup-spam-marked nil
10283                         gnus-newsgroup-dormant nil))
10284                 (setq gnus-newsgroup-unreads
10285                       (gnus-sorted-nunion
10286                        (gnus-intersection gnus-newsgroup-unreads
10287                                           gnus-newsgroup-downloadable)
10288                        gnus-newsgroup-unfetched)))
10289             ;; We actually mark all articles as canceled, which we
10290             ;; have to do when using auto-expiry or adaptive scoring.
10291             (gnus-summary-show-all-threads)
10292             (if (and to-here reverse)
10293                 (progn
10294                   (goto-char to-here)
10295                   (gnus-summary-mark-current-read-and-unread-as-read
10296                    gnus-catchup-mark)
10297                   (while (gnus-summary-find-next (not all))
10298                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10299               (when (gnus-summary-first-subject (not all))
10300                 (while (and
10301                         (if to-here (< (point) to-here) t)
10302                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10303                         (gnus-summary-find-next (not all))))))
10304             (gnus-set-mode-line 'summary))
10305           t))
10306     (gnus-summary-position-point)))
10307
10308 (defun gnus-summary-catchup-to-here (&optional all)
10309   "Mark all unticked articles before the current one as read.
10310 If ALL is non-nil, also mark ticked and dormant articles as read."
10311   (interactive "P")
10312   (save-excursion
10313     (gnus-save-hidden-threads
10314       (let ((beg (point)))
10315         ;; We check that there are unread articles.
10316         (when (or all (gnus-summary-find-prev))
10317           (gnus-summary-catchup all t beg)))))
10318   (gnus-summary-position-point))
10319
10320 (defun gnus-summary-catchup-from-here (&optional all)
10321   "Mark all unticked articles after (and including) the current one as read.
10322 If ALL is non-nil, also mark ticked and dormant articles as read."
10323   (interactive "P")
10324   (save-excursion
10325     (gnus-save-hidden-threads
10326       (let ((beg (point)))
10327         ;; We check that there are unread articles.
10328         (when (or all (gnus-summary-find-next))
10329           (gnus-summary-catchup all t beg nil t)))))
10330   (gnus-summary-position-point))
10331
10332 (defun gnus-summary-catchup-all (&optional quietly)
10333   "Mark all articles in this newsgroup as read.
10334 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10335 instead, which marks only unread articles as read."
10336   (interactive "P")
10337   (gnus-summary-catchup t quietly))
10338
10339 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10340   "Mark all unread articles in this group as read, then exit.
10341 If prefix argument ALL is non-nil, all articles are marked as read.
10342 If QUIETLY is non-nil, no questions will be asked."
10343   (interactive "P")
10344   (when (gnus-summary-catchup all quietly nil 'fast)
10345     ;; Select next newsgroup or exit.
10346     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10347              (eq gnus-auto-select-next 'quietly))
10348         (gnus-summary-next-group nil)
10349       (gnus-summary-exit))))
10350
10351 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10352   "Mark all articles in this newsgroup as read, and then exit.
10353 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10354 instead, which marks only unread articles as read."
10355   (interactive "P")
10356   (gnus-summary-catchup-and-exit t quietly))
10357
10358 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10359   "Mark all articles in this group as read and select the next group.
10360 If given a prefix, mark all articles, unread as well as ticked, as
10361 read."
10362   (interactive "P")
10363   (save-excursion
10364     (gnus-summary-catchup all))
10365   (gnus-summary-next-group))
10366
10367 ;;;
10368 ;;; with article
10369 ;;;
10370
10371 (defmacro gnus-with-article (article &rest forms)
10372   "Select ARTICLE and perform FORMS in the original article buffer.
10373 Then replace the article with the result."
10374   `(progn
10375      ;; We don't want the article to be marked as read.
10376      (let (gnus-mark-article-hook)
10377        (gnus-summary-select-article t t nil ,article))
10378      (set-buffer gnus-original-article-buffer)
10379      ,@forms
10380      (if (not (gnus-check-backend-function
10381                'request-replace-article (car gnus-article-current)))
10382          (gnus-message 5 "Read-only group; not replacing")
10383        (unless (gnus-request-replace-article
10384                 ,article (car gnus-article-current)
10385                 (current-buffer) t)
10386          (error "Couldn't replace article")))
10387      ;; The cache and backlog have to be flushed somewhat.
10388      (when gnus-keep-backlog
10389        (gnus-backlog-remove-article
10390         (car gnus-article-current) (cdr gnus-article-current)))
10391      (when gnus-use-cache
10392        (gnus-cache-update-article
10393         (car gnus-article-current) (cdr gnus-article-current)))))
10394
10395 (put 'gnus-with-article 'lisp-indent-function 1)
10396 (put 'gnus-with-article 'edebug-form-spec '(form body))
10397
10398 ;; Thread-based commands.
10399
10400 (defun gnus-summary-articles-in-thread (&optional article)
10401   "Return a list of all articles in the current thread.
10402 If ARTICLE is non-nil, return all articles in the thread that starts
10403 with that article."
10404   (let* ((article (or article (gnus-summary-article-number)))
10405          (data (gnus-data-find-list article))
10406          (top-level (gnus-data-level (car data)))
10407          (top-subject
10408           (cond ((null gnus-thread-operation-ignore-subject)
10409                  (gnus-simplify-subject-re
10410                   (mail-header-subject (gnus-data-header (car data)))))
10411                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10412                  (gnus-simplify-subject-fuzzy
10413                   (mail-header-subject (gnus-data-header (car data)))))
10414                 (t nil)))
10415          (end-point (save-excursion
10416                       (if (gnus-summary-go-to-next-thread)
10417                           (point) (point-max))))
10418          articles)
10419     (while (and data
10420                 (< (gnus-data-pos (car data)) end-point))
10421       (when (or (not top-subject)
10422                 (string= top-subject
10423                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10424                              (gnus-simplify-subject-fuzzy
10425                               (mail-header-subject
10426                                (gnus-data-header (car data))))
10427                            (gnus-simplify-subject-re
10428                             (mail-header-subject
10429                              (gnus-data-header (car data)))))))
10430         (push (gnus-data-number (car data)) articles))
10431       (unless (and (setq data (cdr data))
10432                    (> (gnus-data-level (car data)) top-level))
10433         (setq data nil)))
10434     ;; Return the list of articles.
10435     (nreverse articles)))
10436
10437 (defun gnus-summary-rethread-current ()
10438   "Rethread the thread the current article is part of."
10439   (interactive)
10440   (let* ((gnus-show-threads t)
10441          (article (gnus-summary-article-number))
10442          (id (mail-header-id (gnus-summary-article-header)))
10443          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10444     (unless id
10445       (error "No article on the current line"))
10446     (gnus-rebuild-thread id)
10447     (gnus-summary-goto-subject article)))
10448
10449 (defun gnus-summary-reparent-thread ()
10450   "Make the current article child of the marked (or previous) article.
10451
10452 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10453 is non-nil or the Subject: of both articles are the same."
10454   (interactive)
10455   (unless (not (gnus-group-read-only-p))
10456     (error "The current newsgroup does not support article editing"))
10457   (unless (<= (length gnus-newsgroup-processable) 1)
10458     (error "No more than one article may be marked"))
10459   (save-window-excursion
10460     (let ((gnus-article-buffer " *reparent*")
10461           (current-article (gnus-summary-article-number))
10462           ;; First grab the marked article, otherwise one line up.
10463           (parent-article (if (not (null gnus-newsgroup-processable))
10464                               (car gnus-newsgroup-processable)
10465                             (save-excursion
10466                               (if (eq (forward-line -1) 0)
10467                                   (gnus-summary-article-number)
10468                                 (error "Beginning of summary buffer"))))))
10469       (unless (not (eq current-article parent-article))
10470         (error "An article may not be self-referential"))
10471       (let ((message-id (mail-header-id
10472                          (gnus-summary-article-header parent-article))))
10473         (unless (and message-id (not (equal message-id "")))
10474           (error "No message-id in desired parent"))
10475         (gnus-with-article current-article
10476           (save-restriction
10477             (goto-char (point-min))
10478             (message-narrow-to-head)
10479             (if (re-search-forward "^References: " nil t)
10480                 (progn
10481                   (re-search-forward "^[^ \t]" nil t)
10482                   (forward-line -1)
10483                   (end-of-line)
10484                   (insert " " message-id))
10485               (insert "References: " message-id "\n"))))
10486         (set-buffer gnus-summary-buffer)
10487         (gnus-summary-unmark-all-processable)
10488         (gnus-summary-update-article current-article)
10489         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10490             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10491         (gnus-summary-rethread-current)
10492         (gnus-message 3 "Article %d is now the child of article %d"
10493                       current-article parent-article)))))
10494
10495 (defun gnus-summary-toggle-threads (&optional arg)
10496   "Toggle showing conversation threads.
10497 If ARG is positive number, turn showing conversation threads on."
10498   (interactive "P")
10499   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10500     (setq gnus-show-threads
10501           (if (null arg) (not gnus-show-threads)
10502             (> (prefix-numeric-value arg) 0)))
10503     (gnus-summary-prepare)
10504     (gnus-summary-goto-subject current)
10505     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10506     (gnus-summary-position-point)))
10507
10508 (defun gnus-summary-show-all-threads ()
10509   "Show all threads."
10510   (interactive)
10511   (save-excursion
10512     (let ((buffer-read-only nil))
10513       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10514   (gnus-summary-position-point))
10515
10516 (defun gnus-summary-show-thread ()
10517   "Show thread subtrees.
10518 Returns nil if no thread was there to be shown."
10519   (interactive)
10520   (let ((buffer-read-only nil)
10521         (orig (point))
10522         (end (point-at-eol))
10523         ;; Leave point at bol
10524         (beg (progn (beginning-of-line) (point))))
10525     (prog1
10526         ;; Any hidden lines here?
10527         (search-forward "\r" end t)
10528       (subst-char-in-region beg end ?\^M ?\n t)
10529       (goto-char orig)
10530       (gnus-summary-position-point))))
10531
10532 (defun gnus-summary-maybe-hide-threads ()
10533   "If requested, hide the threads that should be hidden."
10534   (when (and gnus-show-threads
10535              gnus-thread-hide-subtree)
10536     (gnus-summary-hide-all-threads
10537      (if (or (consp gnus-thread-hide-subtree)
10538              (functionp gnus-thread-hide-subtree))
10539          (gnus-make-predicate gnus-thread-hide-subtree)
10540        nil))))
10541
10542 ;;; Hiding predicates.
10543
10544 (defun gnus-article-unread-p (header)
10545   (memq (mail-header-number header) gnus-newsgroup-unreads))
10546
10547 (defun gnus-article-unseen-p (header)
10548   (memq (mail-header-number header) gnus-newsgroup-unseen))
10549
10550 (defun gnus-map-articles (predicate articles)
10551   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10552   (apply 'gnus-or (mapcar predicate
10553                           (mapcar 'gnus-summary-article-header articles))))
10554
10555 (defun gnus-summary-hide-all-threads (&optional predicate)
10556   "Hide all thread subtrees.
10557 If PREDICATE is supplied, threads that satisfy this predicate
10558 will not be hidden."
10559   (interactive)
10560   (save-excursion
10561     (goto-char (point-min))
10562     (let ((end nil))
10563       (while (not end)
10564         (when (or (not predicate)
10565                   (gnus-map-articles
10566                    predicate (gnus-summary-article-children)))
10567             (gnus-summary-hide-thread))
10568         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10569   (gnus-summary-position-point))
10570
10571 (defun gnus-summary-hide-thread ()
10572   "Hide thread subtrees.
10573 If PREDICATE is supplied, threads that satisfy this predicate
10574 will not be hidden.
10575 Returns nil if no threads were there to be hidden."
10576   (interactive)
10577   (let ((buffer-read-only nil)
10578         (start (point))
10579         (article (gnus-summary-article-number)))
10580     (goto-char start)
10581     ;; Go forward until either the buffer ends or the subthread
10582     ;; ends.
10583     (when (and (not (eobp))
10584                (or (zerop (gnus-summary-next-thread 1 t))
10585                    (goto-char (point-max))))
10586       (prog1
10587           (if (and (> (point) start)
10588                    (search-backward "\n" start t))
10589               (progn
10590                 (subst-char-in-region start (point) ?\n ?\^M)
10591                 (gnus-summary-goto-subject article))
10592             (goto-char start)
10593             nil)))))
10594
10595 (defun gnus-summary-go-to-next-thread (&optional previous)
10596   "Go to the same level (or less) next thread.
10597 If PREVIOUS is non-nil, go to previous thread instead.
10598 Return the article number moved to, or nil if moving was impossible."
10599   (let ((level (gnus-summary-thread-level))
10600         (way (if previous -1 1))
10601         (beg (point)))
10602     (forward-line way)
10603     (while (and (not (eobp))
10604                 (< level (gnus-summary-thread-level)))
10605       (forward-line way))
10606     (if (eobp)
10607         (progn
10608           (goto-char beg)
10609           nil)
10610       (setq beg (point))
10611       (prog1
10612           (gnus-summary-article-number)
10613         (goto-char beg)))))
10614
10615 (defun gnus-summary-next-thread (n &optional silent)
10616   "Go to the same level next N'th thread.
10617 If N is negative, search backward instead.
10618 Returns the difference between N and the number of skips actually
10619 done.
10620
10621 If SILENT, don't output messages."
10622   (interactive "p")
10623   (let ((backward (< n 0))
10624         (n (abs n)))
10625     (while (and (> n 0)
10626                 (gnus-summary-go-to-next-thread backward))
10627       (decf n))
10628     (unless silent
10629       (gnus-summary-position-point))
10630     (when (and (not silent) (/= 0 n))
10631       (gnus-message 7 "No more threads"))
10632     n))
10633
10634 (defun gnus-summary-prev-thread (n)
10635   "Go to the same level previous N'th thread.
10636 Returns the difference between N and the number of skips actually
10637 done."
10638   (interactive "p")
10639   (gnus-summary-next-thread (- n)))
10640
10641 (defun gnus-summary-go-down-thread ()
10642   "Go down one level in the current thread."
10643   (let ((children (gnus-summary-article-children)))
10644     (when children
10645       (gnus-summary-goto-subject (car children)))))
10646
10647 (defun gnus-summary-go-up-thread ()
10648   "Go up one level in the current thread."
10649   (let ((parent (gnus-summary-article-parent)))
10650     (when parent
10651       (gnus-summary-goto-subject parent))))
10652
10653 (defun gnus-summary-down-thread (n)
10654   "Go down thread N steps.
10655 If N is negative, go up instead.
10656 Returns the difference between N and how many steps down that were
10657 taken."
10658   (interactive "p")
10659   (let ((up (< n 0))
10660         (n (abs n)))
10661     (while (and (> n 0)
10662                 (if up (gnus-summary-go-up-thread)
10663                   (gnus-summary-go-down-thread)))
10664       (setq n (1- n)))
10665     (gnus-summary-position-point)
10666     (when (/= 0 n)
10667       (gnus-message 7 "Can't go further"))
10668     n))
10669
10670 (defun gnus-summary-up-thread (n)
10671   "Go up thread N steps.
10672 If N is negative, go down instead.
10673 Returns the difference between N and how many steps down that were
10674 taken."
10675   (interactive "p")
10676   (gnus-summary-down-thread (- n)))
10677
10678 (defun gnus-summary-top-thread ()
10679   "Go to the top of the thread."
10680   (interactive)
10681   (while (gnus-summary-go-up-thread))
10682   (gnus-summary-article-number))
10683
10684 (defun gnus-summary-kill-thread (&optional unmark)
10685   "Mark articles under current thread as read.
10686 If the prefix argument is positive, remove any kinds of marks.
10687 If the prefix argument is negative, tick articles instead."
10688   (interactive "P")
10689   (when unmark
10690     (setq unmark (prefix-numeric-value unmark)))
10691   (let ((articles (gnus-summary-articles-in-thread)))
10692     (save-excursion
10693       ;; Expand the thread.
10694       (gnus-summary-show-thread)
10695       ;; Mark all the articles.
10696       (while articles
10697         (gnus-summary-goto-subject (car articles))
10698         (cond ((null unmark)
10699                (gnus-summary-mark-article-as-read gnus-killed-mark))
10700               ((> unmark 0)
10701                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10702               (t
10703                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10704         (setq articles (cdr articles))))
10705     ;; Hide killed subtrees.
10706     (and (null unmark)
10707          gnus-thread-hide-killed
10708          (gnus-summary-hide-thread))
10709     ;; If marked as read, go to next unread subject.
10710     (when (null unmark)
10711       ;; Go to next unread subject.
10712       (gnus-summary-next-subject 1 t)))
10713   (gnus-set-mode-line 'summary))
10714
10715 ;; Summary sorting commands
10716
10717 (defun gnus-summary-sort-by-number (&optional reverse)
10718   "Sort the summary buffer by article number.
10719 Argument REVERSE means reverse order."
10720   (interactive "P")
10721   (gnus-summary-sort 'number reverse))
10722
10723 (defun gnus-summary-sort-by-random (&optional reverse)
10724   "Randomize the order in the summary buffer.
10725 Argument REVERSE means to randomize in reverse order."
10726   (interactive "P")
10727   (gnus-summary-sort 'random reverse))
10728
10729 (defun gnus-summary-sort-by-author (&optional reverse)
10730   "Sort the summary buffer by author name alphabetically.
10731 If `case-fold-search' is non-nil, case of letters is ignored.
10732 Argument REVERSE means reverse order."
10733   (interactive "P")
10734   (gnus-summary-sort 'author reverse))
10735
10736 (defun gnus-summary-sort-by-subject (&optional reverse)
10737   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
10738 If `case-fold-search' is non-nil, case of letters is ignored.
10739 Argument REVERSE means reverse order."
10740   (interactive "P")
10741   (gnus-summary-sort 'subject reverse))
10742
10743 (defun gnus-summary-sort-by-date (&optional reverse)
10744   "Sort the summary buffer by date.
10745 Argument REVERSE means reverse order."
10746   (interactive "P")
10747   (gnus-summary-sort 'date reverse))
10748
10749 (defun gnus-summary-sort-by-score (&optional reverse)
10750   "Sort the summary buffer by score.
10751 Argument REVERSE means reverse order."
10752   (interactive "P")
10753   (gnus-summary-sort 'score reverse))
10754
10755 (defun gnus-summary-sort-by-lines (&optional reverse)
10756   "Sort the summary buffer by the number of lines.
10757 Argument REVERSE means reverse order."
10758   (interactive "P")
10759   (gnus-summary-sort 'lines reverse))
10760
10761 (defun gnus-summary-sort-by-chars (&optional reverse)
10762   "Sort the summary buffer by article length.
10763 Argument REVERSE means reverse order."
10764   (interactive "P")
10765   (gnus-summary-sort 'chars reverse))
10766
10767 (defun gnus-summary-sort-by-original (&optional reverse)
10768   "Sort the summary buffer using the default sorting method.
10769 Argument REVERSE means reverse order."
10770   (interactive "P")
10771   (let* ((buffer-read-only)
10772          (gnus-summary-prepare-hook nil))
10773     ;; We do the sorting by regenerating the threads.
10774     (gnus-summary-prepare)
10775     ;; Hide subthreads if needed.
10776     (gnus-summary-maybe-hide-threads)))
10777
10778 (defun gnus-summary-sort (predicate reverse)
10779   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
10780   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
10781          (article (intern (format "gnus-article-sort-by-%s" predicate)))
10782          (gnus-thread-sort-functions
10783           (if (not reverse)
10784               thread
10785             `(lambda (t1 t2)
10786                (,thread t2 t1))))
10787          (gnus-sort-gathered-threads-function
10788           gnus-thread-sort-functions)
10789          (gnus-article-sort-functions
10790           (if (not reverse)
10791               article
10792             `(lambda (t1 t2)
10793                (,article t2 t1))))
10794          (buffer-read-only)
10795          (gnus-summary-prepare-hook nil))
10796     ;; We do the sorting by regenerating the threads.
10797     (gnus-summary-prepare)
10798     ;; Hide subthreads if needed.
10799     (gnus-summary-maybe-hide-threads)))
10800
10801 ;; Summary saving commands.
10802
10803 (defun gnus-summary-save-article (&optional n not-saved)
10804   "Save the current article using the default saver function.
10805 If N is a positive number, save the N next articles.
10806 If N is a negative number, save the N previous articles.
10807 If N is nil and any articles have been marked with the process mark,
10808 save those articles instead.
10809 The variable `gnus-default-article-saver' specifies the saver function."
10810   (interactive "P")
10811   (let* ((articles (gnus-summary-work-articles n))
10812          (save-buffer (save-excursion
10813                         (nnheader-set-temp-buffer " *Gnus Save*")))
10814          (num (length articles))
10815          header file)
10816     (dolist (article articles)
10817       (setq header (gnus-summary-article-header article))
10818       (if (not (vectorp header))
10819           ;; This is a pseudo-article.
10820           (if (assq 'name header)
10821               (gnus-copy-file (cdr (assq 'name header)))
10822             (gnus-message 1 "Article %d is unsaveable" article))
10823         ;; This is a real article.
10824         (save-window-excursion
10825           (let ((gnus-display-mime-function nil)
10826                 (gnus-article-prepare-hook nil))
10827             (gnus-summary-select-article t nil nil article)))
10828         (save-excursion
10829           (set-buffer save-buffer)
10830           (erase-buffer)
10831           (insert-buffer-substring gnus-original-article-buffer))
10832         (setq file (gnus-article-save save-buffer file num))
10833         (gnus-summary-remove-process-mark article)
10834         (unless not-saved
10835           (gnus-summary-set-saved-mark article))))
10836     (gnus-kill-buffer save-buffer)
10837     (gnus-summary-position-point)
10838     (gnus-set-mode-line 'summary)
10839     n))
10840
10841 (defun gnus-summary-pipe-output (&optional arg headers)
10842   "Pipe the current article to a subprocess.
10843 If N is a positive number, pipe the N next articles.
10844 If N is a negative number, pipe the N previous articles.
10845 If N is nil and any articles have been marked with the process mark,
10846 pipe those articles instead.
10847 If HEADERS (the symbolic prefix), include the headers, too."
10848   (interactive (gnus-interactive "P\ny"))
10849   (require 'gnus-art)
10850   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
10851         (gnus-save-all-headers (or headers gnus-save-all-headers)))
10852     (gnus-summary-save-article arg t))
10853   (let ((buffer (get-buffer "*Shell Command Output*")))
10854     (when (and buffer
10855                (not (zerop (buffer-size buffer))))
10856       (gnus-configure-windows 'pipe))))
10857
10858 (defun gnus-summary-save-article-mail (&optional arg)
10859   "Append the current article to an mail file.
10860 If N is a positive number, save the N next articles.
10861 If N is a negative number, save the N previous articles.
10862 If N is nil and any articles have been marked with the process mark,
10863 save those articles instead."
10864   (interactive "P")
10865   (require 'gnus-art)
10866   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
10867     (gnus-summary-save-article arg)))
10868
10869 (defun gnus-summary-save-article-rmail (&optional arg)
10870   "Append the current article to an rmail file.
10871 If N is a positive number, save the N next articles.
10872 If N is a negative number, save the N previous articles.
10873 If N is nil and any articles have been marked with the process mark,
10874 save those articles instead."
10875   (interactive "P")
10876   (require 'gnus-art)
10877   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
10878     (gnus-summary-save-article arg)))
10879
10880 (defun gnus-summary-save-article-file (&optional arg)
10881   "Append the current article to a file.
10882 If N is a positive number, save the N next articles.
10883 If N is a negative number, save the N previous articles.
10884 If N is nil and any articles have been marked with the process mark,
10885 save those articles instead."
10886   (interactive "P")
10887   (require 'gnus-art)
10888   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
10889     (gnus-summary-save-article arg)))
10890
10891 (defun gnus-summary-write-article-file (&optional arg)
10892   "Write the current article to a file, deleting the previous file.
10893 If N is a positive number, save the N next articles.
10894 If N is a negative number, save the N previous articles.
10895 If N is nil and any articles have been marked with the process mark,
10896 save those articles instead."
10897   (interactive "P")
10898   (require 'gnus-art)
10899   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
10900     (gnus-summary-save-article arg)))
10901
10902 (defun gnus-summary-save-article-body-file (&optional arg)
10903   "Append the current article body to a file.
10904 If N is a positive number, save the N next articles.
10905 If N is a negative number, save the N previous articles.
10906 If N is nil and any articles have been marked with the process mark,
10907 save those articles instead."
10908   (interactive "P")
10909   (require 'gnus-art)
10910   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
10911     (gnus-summary-save-article arg)))
10912
10913 (defun gnus-summary-muttprint (&optional arg)
10914   "Print the current article using Muttprint.
10915 If N is a positive number, save the N next articles.
10916 If N is a negative number, save the N previous articles.
10917 If N is nil and any articles have been marked with the process mark,
10918 save those articles instead."
10919   (interactive "P")
10920   (require 'gnus-art)
10921   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
10922     (gnus-summary-save-article arg t)))
10923
10924 (defun gnus-summary-pipe-message (program)
10925   "Pipe the current article through PROGRAM."
10926   (interactive "sProgram: ")
10927   (gnus-summary-select-article)
10928   (let ((mail-header-separator ""))
10929     (gnus-eval-in-buffer-window gnus-article-buffer
10930       (save-restriction
10931         (widen)
10932         (let ((start (window-start))
10933               buffer-read-only)
10934           (message-pipe-buffer-body program)
10935           (set-window-start (get-buffer-window (current-buffer)) start))))))
10936
10937 (defun gnus-get-split-value (methods)
10938   "Return a value based on the split METHODS."
10939   (let (split-name method result match)
10940     (when methods
10941       (save-excursion
10942         (set-buffer gnus-original-article-buffer)
10943         (save-restriction
10944           (nnheader-narrow-to-headers)
10945           (while (and methods (not split-name))
10946             (goto-char (point-min))
10947             (setq method (pop methods))
10948             (setq match (car method))
10949             (when (cond
10950                    ((stringp match)
10951                     ;; Regular expression.
10952                     (ignore-errors
10953                       (re-search-forward match nil t)))
10954                    ((functionp match)
10955                     ;; Function.
10956                     (save-restriction
10957                       (widen)
10958                       (setq result (funcall match gnus-newsgroup-name))))
10959                    ((consp match)
10960                     ;; Form.
10961                     (save-restriction
10962                       (widen)
10963                       (setq result (eval match)))))
10964               (setq split-name (cdr method))
10965               (cond ((stringp result)
10966                      (push (expand-file-name
10967                             result gnus-article-save-directory)
10968                            split-name))
10969                     ((consp result)
10970                      (setq split-name (append result split-name)))))))))
10971     (nreverse split-name)))
10972
10973 (defun gnus-valid-move-group-p (group)
10974   (and (boundp group)
10975        (symbol-name group)
10976        (symbol-value group)
10977        (gnus-get-function (gnus-find-method-for-group
10978                            (symbol-name group)) 'request-accept-article t)))
10979
10980 (defun gnus-read-move-group-name (prompt default articles prefix)
10981   "Read a group name."
10982   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
10983          (minibuffer-confirm-incomplete nil) ; XEmacs
10984          (prom
10985           (format "%s %s to:"
10986                   prompt
10987                   (if (> (length articles) 1)
10988                       (format "these %d articles" (length articles))
10989                     "this article")))
10990          (to-newsgroup
10991           (cond
10992            ((null split-name)
10993             (gnus-completing-read-with-default
10994              default prom
10995              gnus-active-hashtb
10996              'gnus-valid-move-group-p
10997              nil prefix
10998              'gnus-group-history))
10999            ((= 1 (length split-name))
11000             (gnus-completing-read-with-default
11001              (car split-name) prom
11002              gnus-active-hashtb
11003              'gnus-valid-move-group-p
11004              nil nil
11005              'gnus-group-history))
11006            (t
11007             (gnus-completing-read-with-default
11008              nil prom
11009              (mapcar (lambda (el) (list el))
11010                      (nreverse split-name))
11011              nil nil nil
11012              'gnus-group-history))))
11013          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11014     (when to-newsgroup
11015       (if (or (string= to-newsgroup "")
11016               (string= to-newsgroup prefix))
11017           (setq to-newsgroup default))
11018       (unless to-newsgroup
11019         (error "No group name entered"))
11020       (or (gnus-active to-newsgroup)
11021           (gnus-activate-group to-newsgroup nil nil to-method)
11022           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11023                                      to-newsgroup))
11024               (or (and (gnus-request-create-group to-newsgroup to-method)
11025                        (gnus-activate-group
11026                         to-newsgroup nil nil to-method)
11027                        (gnus-subscribe-group to-newsgroup))
11028                   (error "Couldn't create group %s" to-newsgroup)))
11029           (error "No such group: %s" to-newsgroup)))
11030     to-newsgroup))
11031
11032 (defun gnus-summary-save-parts (type dir n &optional reverse)
11033   "Save parts matching TYPE to DIR.
11034 If REVERSE, save parts that do not match TYPE."
11035   (interactive
11036    (list (read-string "Save parts of type: "
11037                       (or (car gnus-summary-save-parts-type-history)
11038                           gnus-summary-save-parts-default-mime)
11039                       'gnus-summary-save-parts-type-history)
11040          (setq gnus-summary-save-parts-last-directory
11041                (read-file-name "Save to directory: "
11042                                gnus-summary-save-parts-last-directory
11043                                nil t))
11044          current-prefix-arg))
11045   (gnus-summary-iterate n
11046     (let ((gnus-display-mime-function nil)
11047           (gnus-inhibit-treatment t))
11048       (gnus-summary-select-article))
11049     (save-excursion
11050       (set-buffer gnus-article-buffer)
11051       (let ((handles (or gnus-article-mime-handles
11052                          (mm-dissect-buffer nil gnus-article-loose-mime)
11053                          (and gnus-article-emulate-mime
11054                               (mm-uu-dissect)))))
11055         (when handles
11056           (gnus-summary-save-parts-1 type dir handles reverse)
11057           (unless gnus-article-mime-handles ;; Don't destroy this case.
11058             (mm-destroy-parts handles)))))))
11059
11060 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11061   (if (stringp (car handle))
11062       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11063               (cdr handle))
11064     (when (if reverse
11065               (not (string-match type (mm-handle-media-type handle)))
11066             (string-match type (mm-handle-media-type handle)))
11067       (let ((file (expand-file-name
11068                    (gnus-map-function
11069                     mm-file-name-rewrite-functions
11070                     (file-name-nondirectory
11071                      (or
11072                       (mail-content-type-get
11073                        (mm-handle-disposition handle) 'filename)
11074                       (mail-content-type-get
11075                        (mm-handle-type handle) 'name)
11076                       (concat gnus-newsgroup-name
11077                               "." (number-to-string
11078                                    (cdr gnus-article-current))))))
11079                    dir)))
11080         (unless (file-exists-p file)
11081           (mm-save-part-to-file handle file))))))
11082
11083 ;; Summary extract commands
11084
11085 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11086   (let ((buffer-read-only nil)
11087         (article (gnus-summary-article-number))
11088         after-article b e)
11089     (unless (gnus-summary-goto-subject article)
11090       (error "No such article: %d" article))
11091     (gnus-summary-position-point)
11092     ;; If all commands are to be bunched up on one line, we collect
11093     ;; them here.
11094     (unless gnus-view-pseudos-separately
11095       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11096             files action)
11097         (while ps
11098           (setq action (cdr (assq 'action (car ps))))
11099           (setq files (list (cdr (assq 'name (car ps)))))
11100           (while (and ps (cdr ps)
11101                       (string= (or action "1")
11102                                (or (cdr (assq 'action (cadr ps))) "2")))
11103             (push (cdr (assq 'name (cadr ps))) files)
11104             (setcdr ps (cddr ps)))
11105           (when files
11106             (when (not (string-match "%s" action))
11107               (push " " files))
11108             (push " " files)
11109             (when (assq 'execute (car ps))
11110               (setcdr (assq 'execute (car ps))
11111                       (funcall (if (string-match "%s" action)
11112                                    'format 'concat)
11113                                action
11114                                (mapconcat
11115                                 (lambda (f)
11116                                   (if (equal f " ")
11117                                       f
11118                                     (shell-quote-argument f)))
11119                                 files " ")))))
11120           (setq ps (cdr ps)))))
11121     (if (and gnus-view-pseudos (not not-view))
11122         (while pslist
11123           (when (assq 'execute (car pslist))
11124             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11125                                   (eq gnus-view-pseudos 'not-confirm)))
11126           (setq pslist (cdr pslist)))
11127       (save-excursion
11128         (while pslist
11129           (setq after-article (or (cdr (assq 'article (car pslist)))
11130                                   (gnus-summary-article-number)))
11131           (gnus-summary-goto-subject after-article)
11132           (forward-line 1)
11133           (setq b (point))
11134           (insert "    " (file-name-nondirectory
11135                           (cdr (assq 'name (car pslist))))
11136                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11137           (setq e (point))
11138           (forward-line -1)             ; back to `b'
11139           (gnus-add-text-properties
11140            b (1- e) (list 'gnus-number gnus-reffed-article-number
11141                           gnus-mouse-face-prop gnus-mouse-face))
11142           (gnus-data-enter
11143            after-article gnus-reffed-article-number
11144            gnus-unread-mark b (car pslist) 0 (- e b))
11145           (setq gnus-newsgroup-unreads
11146                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11147                                          gnus-reffed-article-number))
11148           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11149           (setq pslist (cdr pslist)))))))
11150
11151 (defun gnus-pseudos< (p1 p2)
11152   (let ((c1 (cdr (assq 'action p1)))
11153         (c2 (cdr (assq 'action p2))))
11154     (and c1 c2 (string< c1 c2))))
11155
11156 (defun gnus-request-pseudo-article (props)
11157   (cond ((assq 'execute props)
11158          (gnus-execute-command (cdr (assq 'execute props)))))
11159   (let ((gnus-current-article (gnus-summary-article-number)))
11160     (gnus-run-hooks 'gnus-mark-article-hook)))
11161
11162 (defun gnus-execute-command (command &optional automatic)
11163   (save-excursion
11164     (gnus-article-setup-buffer)
11165     (set-buffer gnus-article-buffer)
11166     (setq buffer-read-only nil)
11167     (let ((command (if automatic command
11168                      (read-string "Command: " (cons command 0)))))
11169       (erase-buffer)
11170       (insert "$ " command "\n\n")
11171       (if gnus-view-pseudo-asynchronously
11172           (start-process "gnus-execute" (current-buffer) shell-file-name
11173                          shell-command-switch command)
11174         (call-process shell-file-name nil t nil
11175                       shell-command-switch command)))))
11176
11177 ;; Summary kill commands.
11178
11179 (defun gnus-summary-edit-global-kill (article)
11180   "Edit the \"global\" kill file."
11181   (interactive (list (gnus-summary-article-number)))
11182   (gnus-group-edit-global-kill article))
11183
11184 (defun gnus-summary-edit-local-kill ()
11185   "Edit a local kill file applied to the current newsgroup."
11186   (interactive)
11187   (setq gnus-current-headers (gnus-summary-article-header))
11188   (gnus-group-edit-local-kill
11189    (gnus-summary-article-number) gnus-newsgroup-name))
11190
11191 ;;; Header reading.
11192
11193 (defun gnus-read-header (id &optional header)
11194   "Read the headers of article ID and enter them into the Gnus system."
11195   (let ((group gnus-newsgroup-name)
11196         (gnus-override-method
11197          (or
11198           gnus-override-method
11199           (and (gnus-news-group-p gnus-newsgroup-name)
11200                (car (gnus-refer-article-methods)))))
11201         where)
11202     ;; First we check to see whether the header in question is already
11203     ;; fetched.
11204     (if (stringp id)
11205         ;; This is a Message-ID.
11206         (setq header (or header (gnus-id-to-header id)))
11207       ;; This is an article number.
11208       (setq header (or header (gnus-summary-article-header id))))
11209     (if (and header
11210              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11211         ;; We have found the header.
11212         header
11213       ;; If this is a sparse article, we have to nix out its
11214       ;; previous entry in the thread hashtb.
11215       (when (and header
11216                  (gnus-summary-article-sparse-p (mail-header-number header)))
11217         (let* ((parent (gnus-parent-id (mail-header-references header)))
11218                (thread (and parent (gnus-id-to-thread parent))))
11219           (when thread
11220             (delq (assq header thread) thread))))
11221       ;; We have to really fetch the header to this article.
11222       (save-excursion
11223         (set-buffer nntp-server-buffer)
11224         (when (setq where (gnus-request-head id group))
11225           (nnheader-fold-continuation-lines)
11226           (goto-char (point-max))
11227           (insert ".\n")
11228           (goto-char (point-min))
11229           (insert "211 ")
11230           (princ (cond
11231                   ((numberp id) id)
11232                   ((cdr where) (cdr where))
11233                   (header (mail-header-number header))
11234                   (t gnus-reffed-article-number))
11235                  (current-buffer))
11236           (insert " Article retrieved.\n"))
11237         (if (or (not where)
11238                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11239             ()                          ; Malformed head.
11240           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11241             (when (and (stringp id)
11242                        (not (string= (gnus-group-real-name group)
11243                                      (car where))))
11244               ;; If we fetched by Message-ID and the article came
11245               ;; from a different group, we fudge some bogus article
11246               ;; numbers for this article.
11247               (mail-header-set-number header gnus-reffed-article-number))
11248             (save-excursion
11249               (set-buffer gnus-summary-buffer)
11250               (decf gnus-reffed-article-number)
11251               (gnus-remove-header (mail-header-number header))
11252               (push header gnus-newsgroup-headers)
11253               (setq gnus-current-headers header)
11254               (push (mail-header-number header) gnus-newsgroup-limit)))
11255           header)))))
11256
11257 (defun gnus-remove-header (number)
11258   "Remove header NUMBER from `gnus-newsgroup-headers'."
11259   (if (and gnus-newsgroup-headers
11260            (= number (mail-header-number (car gnus-newsgroup-headers))))
11261       (pop gnus-newsgroup-headers)
11262     (let ((headers gnus-newsgroup-headers))
11263       (while (and (cdr headers)
11264                   (not (= number (mail-header-number (cadr headers)))))
11265         (pop headers))
11266       (when (cdr headers)
11267         (setcdr headers (cddr headers))))))
11268
11269 ;;;
11270 ;;; summary highlights
11271 ;;;
11272
11273 (defun gnus-highlight-selected-summary ()
11274   "Highlight selected article in summary buffer."
11275   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11276   (when gnus-summary-selected-face
11277     (save-excursion
11278       (let* ((beg (point-at-bol))
11279              (end (point-at-eol))
11280              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11281              (from (if (get-text-property beg gnus-mouse-face-prop)
11282                        beg
11283                      (or (next-single-property-change
11284                           beg gnus-mouse-face-prop nil end)
11285                          beg)))
11286              (to
11287               (if (= from end)
11288                   (- from 2)
11289                 (or (next-single-property-change
11290                      from gnus-mouse-face-prop nil end)
11291                     end))))
11292         ;; If no mouse-face prop on line we will have to = from = end,
11293         ;; so we highlight the entire line instead.
11294         (when (= (+ to 2) from)
11295           (setq from beg)
11296           (setq to end))
11297         (if gnus-newsgroup-selected-overlay
11298             ;; Move old overlay.
11299             (gnus-move-overlay
11300              gnus-newsgroup-selected-overlay from to (current-buffer))
11301           ;; Create new overlay.
11302           (gnus-overlay-put
11303            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11304            'face gnus-summary-selected-face))))))
11305
11306 (defvar gnus-summary-highlight-line-cached nil)
11307 (defvar gnus-summary-highlight-line-trigger nil)
11308
11309 (defun gnus-summary-highlight-line-0 ()
11310   (if (and (eq gnus-summary-highlight-line-trigger
11311                gnus-summary-highlight)
11312            gnus-summary-highlight-line-cached)
11313       gnus-summary-highlight-line-cached
11314     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11315           gnus-summary-highlight-line-cached
11316           (let* ((cond (list 'cond))
11317                  (c cond)
11318                  (list gnus-summary-highlight))
11319             (while list
11320               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11321                               nil))
11322               (setq c (cdr c)
11323                     list (cdr list)))
11324             (gnus-byte-compile (list 'lambda nil cond))))))
11325
11326 (defun gnus-summary-highlight-line ()
11327   "Highlight current line according to `gnus-summary-highlight'."
11328   (let* ((beg (point-at-bol))
11329          (article (or (gnus-summary-article-number) gnus-current-article))
11330          (score (or (cdr (assq article
11331                                gnus-newsgroup-scored))
11332                     gnus-summary-default-score 0))
11333          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11334          (inhibit-read-only t)
11335          (default gnus-summary-default-score)
11336          (default-high gnus-summary-default-high-score)
11337          (default-low gnus-summary-default-low-score)
11338          (uncached (and gnus-summary-use-undownloaded-faces
11339                         (memq article gnus-newsgroup-undownloaded)
11340                         (not (memq article gnus-newsgroup-cached)))))
11341     (let ((face (funcall (gnus-summary-highlight-line-0))))
11342       (unless (eq face (get-text-property beg 'face))
11343         (gnus-put-text-property-excluding-characters-with-faces
11344          beg (point-at-eol) 'face
11345          (setq face (if (boundp face) (symbol-value face) face)))
11346         (when gnus-summary-highlight-line-function
11347           (funcall gnus-summary-highlight-line-function article face))))))
11348
11349 (defun gnus-update-read-articles (group unread &optional compute)
11350   "Update the list of read articles in GROUP.
11351 UNREAD is a sorted list."
11352   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11353         (info (gnus-get-info group))
11354         (prev 1)
11355         read)
11356     (if (or (not info) (not active))
11357         ;; There is no info on this group if it was, in fact,
11358         ;; killed.  Gnus stores no information on killed groups, so
11359         ;; there's nothing to be done.
11360         ;; One could store the information somewhere temporarily,
11361         ;; perhaps...  Hmmm...
11362         ()
11363       ;; Remove any negative articles numbers.
11364       (while (and unread (< (car unread) 0))
11365         (setq unread (cdr unread)))
11366       ;; Remove any expired article numbers
11367       (while (and unread (< (car unread) (car active)))
11368         (setq unread (cdr unread)))
11369       ;; Compute the ranges of read articles by looking at the list of
11370       ;; unread articles.
11371       (while unread
11372         (when (/= (car unread) prev)
11373           (push (if (= prev (1- (car unread))) prev
11374                   (cons prev (1- (car unread))))
11375                 read))
11376         (setq prev (1+ (car unread)))
11377         (setq unread (cdr unread)))
11378       (when (<= prev (cdr active))
11379         (push (cons prev (cdr active)) read))
11380       (setq read (if (> (length read) 1) (nreverse read) read))
11381       (if compute
11382           read
11383         (save-excursion
11384           (let (setmarkundo)
11385             ;; Propagate the read marks to the backend.
11386             (when (gnus-check-backend-function 'request-set-mark group)
11387               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11388                     (add (gnus-remove-from-range read (gnus-info-read info))))
11389                 (when (or add del)
11390                   (unless (gnus-check-group group)
11391                     (error "Can't open server for %s" group))
11392                   (gnus-request-set-mark
11393                    group (delq nil (list (if add (list add 'add '(read)))
11394                                          (if del (list del 'del '(read))))))
11395                   (setq setmarkundo
11396                         `(gnus-request-set-mark
11397                           ,group
11398                           ',(delq nil (list
11399                                        (if del (list del 'add '(read)))
11400                                        (if add (list add 'del '(read))))))))))
11401             (set-buffer gnus-group-buffer)
11402             (gnus-undo-register
11403               `(progn
11404                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11405                  (gnus-info-set-read ',info ',(gnus-info-read info))
11406                  (gnus-get-unread-articles-in-group ',info
11407                                                     (gnus-active ,group))
11408                  (gnus-group-update-group ,group t)
11409                  ,setmarkundo))))
11410         ;; Enter this list into the group info.
11411         (gnus-info-set-read info read)
11412         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11413         (gnus-get-unread-articles-in-group info (gnus-active group))
11414         t))))
11415
11416 (defun gnus-offer-save-summaries ()
11417   "Offer to save all active summary buffers."
11418   (let (buffers)
11419     ;; Go through all buffers and find all summaries.
11420     (dolist (buffer (buffer-list))
11421       (when (and (setq buffer (buffer-name buffer))
11422                  (string-match "Summary" buffer)
11423                  (save-excursion
11424                    (set-buffer buffer)
11425                    ;; We check that this is, indeed, a summary buffer.
11426                    (and (eq major-mode 'gnus-summary-mode)
11427                         ;; Also make sure this isn't bogus.
11428                         gnus-newsgroup-prepared
11429                         ;; Also make sure that this isn't a
11430                         ;; dead summary buffer.
11431                         (not gnus-dead-summary-mode))))
11432         (push buffer buffers)))
11433     ;; Go through all these summary buffers and offer to save them.
11434     (when buffers
11435       (save-excursion
11436         (map-y-or-n-p
11437          "Update summary buffer %s? "
11438          (lambda (buf)
11439            (switch-to-buffer buf)
11440            (gnus-summary-exit))
11441          buffers)))))
11442
11443 (defun gnus-summary-setup-default-charset ()
11444   "Setup newsgroup default charset."
11445   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11446       (setq gnus-newsgroup-charset nil)
11447     (let* ((ignored-charsets
11448             (or gnus-newsgroup-ephemeral-ignored-charsets
11449                 (append
11450                  (and gnus-newsgroup-name
11451                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11452                  gnus-newsgroup-ignored-charsets))))
11453       (setq gnus-newsgroup-charset
11454             (or gnus-newsgroup-ephemeral-charset
11455                 (and gnus-newsgroup-name
11456                      (gnus-parameter-charset gnus-newsgroup-name))
11457                 gnus-default-charset))
11458       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11459            ignored-charsets))))
11460
11461 ;;;
11462 ;;; Mime Commands
11463 ;;;
11464
11465 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11466   "Display the current article buffer fully MIME-buttonized.
11467 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11468 treated as multipart/mixed."
11469   (interactive "P")
11470   (require 'gnus-art)
11471   (let ((gnus-unbuttonized-mime-types nil)
11472         (gnus-mime-display-multipart-as-mixed show-all-parts))
11473     (gnus-summary-show-article)))
11474
11475 (defun gnus-summary-repair-multipart (article)
11476   "Add a Content-Type header to a multipart article without one."
11477   (interactive (list (gnus-summary-article-number)))
11478   (gnus-with-article article
11479     (message-narrow-to-head)
11480     (message-remove-header "Mime-Version")
11481     (goto-char (point-max))
11482     (insert "Mime-Version: 1.0\n")
11483     (widen)
11484     (when (search-forward "\n--" nil t)
11485       (let ((separator (buffer-substring (point) (point-at-eol))))
11486         (message-narrow-to-head)
11487         (message-remove-header "Content-Type")
11488         (goto-char (point-max))
11489         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11490                         separator))
11491         (widen))))
11492   (let (gnus-mark-article-hook)
11493     (gnus-summary-select-article t t nil article)))
11494
11495 (defun gnus-summary-toggle-display-buttonized ()
11496   "Toggle the buttonizing of the article buffer."
11497   (interactive)
11498   (require 'gnus-art)
11499   (if (setq gnus-inhibit-mime-unbuttonizing
11500             (not gnus-inhibit-mime-unbuttonizing))
11501       (let ((gnus-unbuttonized-mime-types nil))
11502         (gnus-summary-show-article))
11503     (gnus-summary-show-article)))
11504
11505 ;;;
11506 ;;; Generic summary marking commands
11507 ;;;
11508
11509 (defvar gnus-summary-marking-alist
11510   '((read gnus-del-mark "d")
11511     (unread gnus-unread-mark "u")
11512     (ticked gnus-ticked-mark "!")
11513     (dormant gnus-dormant-mark "?")
11514     (expirable gnus-expirable-mark "e"))
11515   "An alist of names/marks/keystrokes.")
11516
11517 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
11518 (defvar gnus-summary-mark-map)
11519
11520 (defun gnus-summary-make-all-marking-commands ()
11521   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
11522   (dolist (elem gnus-summary-marking-alist)
11523     (apply 'gnus-summary-make-marking-command elem)))
11524
11525 (defun gnus-summary-make-marking-command (name mark keystroke)
11526   (let ((map (make-sparse-keymap)))
11527     (define-key gnus-summary-generic-mark-map keystroke map)
11528     (dolist (lway `((next "next" next nil "n")
11529                     (next-unread "next unread" next t "N")
11530                     (prev "previous" prev nil "p")
11531                     (prev-unread "previous unread" prev t "P")
11532                     (nomove "" nil nil ,keystroke)))
11533       (let ((func (gnus-summary-make-marking-command-1
11534                    mark (car lway) lway name)))
11535         (setq func (eval func))
11536         (define-key map (nth 4 lway) func)))))
11537
11538 (defun gnus-summary-make-marking-command-1 (mark way lway name)
11539   `(defun ,(intern
11540             (format "gnus-summary-put-mark-as-%s%s"
11541                     name (if (eq way 'nomove)
11542                              ""
11543                            (concat "-" (symbol-name way)))))
11544      (n)
11545      ,(format
11546        "Mark the current article as %s%s.
11547 If N, the prefix, then repeat N times.
11548 If N is negative, move in reverse order.
11549 The difference between N and the actual number of articles marked is
11550 returned."
11551        name (cadr lway))
11552      (interactive "p")
11553      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
11554
11555 (defun gnus-summary-generic-mark (n mark move unread)
11556   "Mark N articles with MARK."
11557   (unless (eq major-mode 'gnus-summary-mode)
11558     (error "This command can only be used in the summary buffer"))
11559   (gnus-summary-show-thread)
11560   (let ((nummove
11561          (cond
11562           ((eq move 'next) 1)
11563           ((eq move 'prev) -1)
11564           (t 0))))
11565     (if (zerop nummove)
11566         (setq n 1)
11567       (when (< n 0)
11568         (setq n (abs n)
11569               nummove (* -1 nummove))))
11570     (while (and (> n 0)
11571                 (gnus-summary-mark-article nil mark)
11572                 (zerop (gnus-summary-next-subject nummove unread t)))
11573       (setq n (1- n)))
11574     (when (/= 0 n)
11575       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
11576     (gnus-summary-recenter)
11577     (gnus-summary-position-point)
11578     (gnus-set-mode-line 'summary)
11579     n))
11580
11581 (defun gnus-summary-insert-articles (articles)
11582   (when (setq articles
11583               (gnus-sorted-difference articles
11584                                       (mapcar (lambda (h)
11585                                                 (mail-header-number h))
11586                                               gnus-newsgroup-headers)))
11587     (setq gnus-newsgroup-headers
11588           (gnus-merge 'list
11589                       gnus-newsgroup-headers
11590                       (gnus-fetch-headers articles)
11591                       'gnus-article-sort-by-number))
11592     ;; Suppress duplicates?
11593     (when gnus-suppress-duplicates
11594       (gnus-dup-suppress-articles))
11595
11596     ;; We might want to build some more threads first.
11597     (when (and gnus-fetch-old-headers
11598                (eq gnus-headers-retrieved-by 'nov))
11599       (if (eq gnus-fetch-old-headers 'invisible)
11600           (gnus-build-all-threads)
11601         (gnus-build-old-threads)))
11602     ;; Let the Gnus agent mark articles as read.
11603     (when gnus-agent
11604       (gnus-agent-get-undownloaded-list))
11605     ;; Remove list identifiers from subject
11606     (when gnus-list-identifiers
11607       (gnus-summary-remove-list-identifiers))
11608     ;; First and last article in this newsgroup.
11609     (when gnus-newsgroup-headers
11610       (setq gnus-newsgroup-begin
11611             (mail-header-number (car gnus-newsgroup-headers))
11612             gnus-newsgroup-end
11613             (mail-header-number
11614              (gnus-last-element gnus-newsgroup-headers))))
11615     (when gnus-use-scoring
11616       (gnus-possibly-score-headers))))
11617
11618 (defun gnus-summary-insert-old-articles (&optional all)
11619   "Insert all old articles in this group.
11620 If ALL is non-nil, already read articles become readable.
11621 If ALL is a number, fetch this number of articles."
11622   (interactive "P")
11623   (prog1
11624       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11625             older len)
11626         (setq older
11627               ;; Some nntp servers lie about their active range.  When
11628               ;; this happens, the active range can be in the millions.
11629               ;; Use a compressed range to avoid creating a huge list.
11630               (gnus-range-difference (list gnus-newsgroup-active) old))
11631         (setq len (gnus-range-length older))
11632         (cond
11633          ((null older) nil)
11634          ((numberp all)
11635           (if (< all len)
11636               (let ((older-range (nreverse older)))
11637                 (setq older nil)
11638
11639                 (while (> all 0)
11640                   (let* ((r (pop older-range))
11641                          (min (if (numberp r) r (car r)))
11642                          (max (if (numberp r) r (cdr r))))
11643                     (while (and (<= min max)
11644                                 (> all 0))
11645                       (push max older)
11646                       (setq all (1- all)
11647                             max (1- max))))))
11648             (setq older (gnus-uncompress-range older))))
11649          (all
11650           (setq older (gnus-uncompress-range older)))
11651          (t
11652           (when (and (numberp gnus-large-newsgroup)
11653                    (> len gnus-large-newsgroup))
11654               (let* ((cursor-in-echo-area nil)
11655                      (initial (gnus-parameter-large-newsgroup-initial
11656                                gnus-newsgroup-name))
11657                      (input
11658                       (read-string
11659                        (format
11660                         "How many articles from %s (%s %d): "
11661                         (gnus-limit-string
11662                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
11663                         (if initial "max" "default")
11664                         len)
11665                        (if initial
11666                            (cons (number-to-string initial)
11667                                  0)))))
11668                 (unless (string-match "^[ \t]*$" input)
11669                   (setq all (string-to-number input))
11670                   (if (< all len)
11671                       (let ((older-range (nreverse older)))
11672                         (setq older nil)
11673
11674                         (while (> all 0)
11675                           (let* ((r (pop older-range))
11676                                  (min (if (numberp r) r (car r)))
11677                                  (max (if (numberp r) r (cdr r))))
11678                             (while (and (<= min max)
11679                                         (> all 0))
11680                               (push max older)
11681                               (setq all (1- all)
11682                                     max (1- max))))))))))
11683           (setq older (gnus-uncompress-range older))))
11684         (if (not older)
11685             (message "No old news.")
11686           (gnus-summary-insert-articles older)
11687           (gnus-summary-limit (gnus-sorted-nunion old older))))
11688     (gnus-summary-position-point)))
11689
11690 (defun gnus-summary-insert-new-articles ()
11691   "Insert all new articles in this group."
11692   (interactive)
11693   (prog1
11694       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
11695             (old-active gnus-newsgroup-active)
11696             (nnmail-fetched-sources (list t))
11697             i new)
11698         (setq gnus-newsgroup-active
11699               (gnus-activate-group gnus-newsgroup-name 'scan))
11700         (setq i (cdr gnus-newsgroup-active))
11701         (while (> i (cdr old-active))
11702           (push i new)
11703           (decf i))
11704         (if (not new)
11705             (message "No gnus is bad news")
11706           (gnus-summary-insert-articles new)
11707           (setq gnus-newsgroup-unreads
11708                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
11709           (gnus-summary-limit (gnus-sorted-nunion old new))))
11710     (gnus-summary-position-point)))
11711
11712 (gnus-summary-make-all-marking-commands)
11713
11714 (gnus-ems-redefine)
11715
11716 (provide 'gnus-sum)
11717
11718 (run-hooks 'gnus-sum-load-hook)
11719
11720 ;; Local Variables:
11721 ;; coding: iso-8859-1
11722 ;; End:
11723
11724 ;;; gnus-sum.el ends here